Moved some scoreboard logic

This commit is contained in:
Vortrex
2021-01-09 22:33:37 -06:00
parent 99fb47e93d
commit 2a8ae5052b

View File

@@ -4,90 +4,80 @@
// Copyright (c) 2020 Asshat-Gaming (https://asshatgaming.com) // Copyright (c) 2020 Asshat-Gaming (https://asshatgaming.com)
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// FILE: scoreboard.js // FILE: scoreboard.js
// DESC: Provides scoreboard feature and rendering // DESC: Provides scoreboard features and rendering
// TYPE: Client (JavaScript) // TYPE: Client (JavaScript)
// =========================================================================== // ===========================================================================
let titleFont = null; let scoreBoardTitleFont = null;
let listFont = null; let scoreBoardListFont = null;
let pausedColour = COLOUR_RED; let pausedColour = COLOUR_RED;
let scoreboardKey = SDLK_TAB;
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
bindEventHandler("OnResourceReady", thisResource, function(event, resource) { bindEventHandler("OnResourceReady", thisResource, function(event, resource) {
titleFont = lucasFont.createDefaultFont(22.0, "Roboto", "Regular"); scoreBoardTitleFont = lucasFont.createDefaultFont(22.0, "Roboto", "Regular");
listFont = lucasFont.createDefaultFont(12.0, "Roboto", "Light"); scoreBoardListFont = lucasFont.createDefaultFont(12.0, "Roboto", "Light");
}); });
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
addEventHandler("OnDrawnHUD", function (event) { function renderScoreboard() {
if(!renderHUD) { if(scoreBoardListFont != null && scoreBoardTitleFont != null) {
return false; let scoreboardStart = (game.height/2)-(Math.floor(getClients().length/2)*20);
} let titleSize = scoreBoardTitleFont.measure("PLAYERS", game.width, 0.0, 1.0, 10, false, false);
scoreBoardTitleFont.render("PLAYERS", [game.width/2, scoreboardStart-50], 0, 0.5, 0.0, scoreBoardTitleFont.size, COLOUR_WHITE, false, false, false, true);
if(!renderScoreboard) { titleSize = scoreBoardTitleFont.measure("____________________________", game.width, 0.0, 1.0, 10, false, false);
return false; scoreBoardTitleFont.render("____________________________", [game.width/2, scoreboardStart-35], 0, 0.5, 0.0, scoreBoardTitleFont.size, COLOUR_WHITE, false, false, false, true);
}
if(localPlayer != null) { let clients = getClients();
if(isKeyDown(SDLK_TAB)) { for(let i in clients) {
if(listFont != null && titleFont != null) { if(!clients[i].console) {
let scoreboardStart = (game.height/2)-(Math.floor(getClients().length/2)*20); let name = clients[i].name;
let titleSize = titleFont.measure("PLAYERS", game.width, 0.0, 1.0, 10, false, false); let colour = COLOUR_WHITE;
titleFont.render("PLAYERS", [game.width/2, scoreboardStart-50], 0, 0.5, 0.0, titleFont.size, COLOUR_WHITE, false, false, false, true); let paused = false;
let ping = "-1";
titleSize = titleFont.measure("____________________________", game.width, 0.0, 1.0, 10, false, false); if(typeof playerNames[clients[i].name] != "undefined") {
titleFont.render("____________________________", [game.width/2, scoreboardStart-35], 0, 0.5, 0.0, titleFont.size, COLOUR_WHITE, false, false, false, true); name = playerNames[clients[i].name];
}
let clients = getClients(); if(typeof playerPaused[clients[i].name] != "undefined") {
for(let i in clients) { paused = playerPaused[clients[i].name];
if(!clients[i].console) { }
let name = clients[i].name;
let colour = COLOUR_WHITE;
let paused = false;
let ping = "-1";
if(typeof playerNames[clients[i].name] != "undefined") { if(typeof playerColours[clients[i].name] != "undefined") {
name = playerNames[clients[i].name]; colour = playerColours[clients[i].name];
} }
if(typeof playerPaused[clients[i].name] != "undefined") { if(typeof playerPing[clients[i].name] != "undefined") {
paused = playerPaused[clients[i].name]; ping = toString(playerPing[clients[i].name]);
} }
if(typeof playerColours[clients[i].name] != "undefined") { // Player ID
colour = playerColours[clients[i].name]; let text = String(clients[i].index);
} let size = scoreBoardListFont.measure(text, 75, 0.0, 1.0, 10, false, false);
scoreBoardListFont.render(text, [game.width/2-100, scoreboardStart + (i*20)], 0, 0.5, 0.0, scoreBoardListFont.size, COLOUR_WHITE, false, false, false, true);
if(typeof playerPing[clients[i].name] != "undefined") { // Player Name
ping = toString(playerPing[clients[i].name]); text = name;
} size = scoreBoardListFont.measure(text, 100, 0.0, 1.0, 10, false, false);
scoreBoardListFont.render(text, [game.width/2, scoreboardStart + (i*20)], 0, 0.5, 0.0, scoreBoardListFont.size, colour, false, false, false, true);
// Player ID // Ping
let text = String(clients[i].index); text = ping;
let size = listFont.measure(text, 75, 0.0, 1.0, 10, false, false); size = scoreBoardListFont.measure(ping, 75, 0.0, 1.0, 10, false, false);
listFont.render(text, [game.width/2-100, scoreboardStart + (i*20)], 0, 0.5, 0.0, listFont.size, COLOUR_WHITE, false, false, false, true); scoreBoardListFont.render(ping, [game.width/2+100, scoreboardStart + (i*20)], 0, 0.5, 0.0, scoreBoardListFont.size, COLOUR_WHITE, false, false, false, true);
// Player Name // PAUSED Status (depends on resource "afk")
text = name; if(paused == true) {
size = listFont.measure(text, 100, 0.0, 1.0, 10, false, false); size = scoreBoardListFont.measure("PAUSED", 100, 0.0, 1.0, 10, false, false);
listFont.render(text, [game.width/2, scoreboardStart + (i*20)], 0, 0.5, 0.0, listFont.size, colour, false, false, false, true); scoreBoardListFont.render("PAUSED", [game.width/2+200, scoreboardStart + (i*20)], 0, 0.5, 0.0, scoreBoardListFont.size, pausedColour, false, false, false, true);
// Ping
text = ping;
size = listFont.measure(ping, 75, 0.0, 1.0, 10, false, false);
listFont.render(ping, [game.width/2+100, scoreboardStart + (i*20)], 0, 0.5, 0.0, listFont.size, COLOUR_WHITE, false, false, false, true);
// PAUSED Status (depends on resource "afk")
if(paused == true) {
size = listFont.measure("PAUSED", 100, 0.0, 1.0, 10, false, false);
listFont.render("PAUSED", [game.width/2+200, scoreboardStart + (i*20)], 0, 0.5, 0.0, listFont.size, pausedColour, false, false, false, true);
}
}
} }
} }
} }
} }
}); }