From 80ea90ec4b8dd285e76358bf83a7f0cee8fffb44 Mon Sep 17 00:00:00 2001 From: elexis Date: Fri, 3 Jun 2016 16:22:02 +0000 Subject: [PATCH] Summary screen cleanup. Use 8b30273a50 to remove hardcoding of the available panels. Access the summary panels by name instead of numerical index. Move nested function to global scope. Add newlines. Remove unneeded comments. Use join(" ") to construct the size property. This was SVN commit r18314. --- .../data/mods/public/gui/summary/layout.js | 40 +++++------ .../data/mods/public/gui/summary/summary.js | 71 ++++++++++--------- .../data/mods/public/gui/summary/summary.xml | 15 ++-- 3 files changed, 67 insertions(+), 59 deletions(-) diff --git a/binaries/data/mods/public/gui/summary/layout.js b/binaries/data/mods/public/gui/summary/layout.js index 9ed33b969d..e987340852 100644 --- a/binaries/data/mods/public/gui/summary/layout.js +++ b/binaries/data/mods/public/gui/summary/layout.js @@ -1,6 +1,6 @@ -var g_ScorePanelsData = [ - { // Scores panel - "headings": [ // headings on score panel +var g_ScorePanelsData = { + "score": { + "headings": [ { "caption": translate("Player name"), "yStart": 26, "width": 200 }, { "caption": translate("Economy score"), "yStart": 16, "width": 100 }, { "caption": translate("Military score"), "yStart": 16, "width": 100 }, @@ -8,7 +8,7 @@ var g_ScorePanelsData = [ { "caption": translate("Total score"), "yStart": 16, "width": 100 } ], "titleHeadings": [], - "counters": [ // counters on score panel + "counters": [ { "width": 100, "fn": calculateEconomyScore }, { "width": 100, "fn": calculateMilitaryScore }, { "width": 100, "fn": calculateExplorationScore }, @@ -16,8 +16,8 @@ var g_ScorePanelsData = [ ], "teamCounterFn": calculateScoreTeam }, - { // buildings panel - "headings": [ // headings on buildings panel + "buildings": { + "headings": [ { "caption": translate("Player name"), "yStart": 26, "width": 200 }, { "caption": translate("Total"), "yStart": 34, "width": 105 }, { "caption": translate("Houses"), "yStart": 34, "width": 85 }, @@ -31,7 +31,7 @@ var g_ScorePanelsData = [ "titleHeadings": [ { "caption": translate("Buildings Statistics (Constructed / Lost / Destroyed)"), "yStart": 16, "width": (85 * 7 + 105) }, // width = 700 ], - "counters": [ // counters on buildings panel + "counters": [ { "width": 105, "fn": calculateBuildings }, { "width": 85, "fn": calculateBuildings }, { "width": 85, "fn": calculateBuildings }, @@ -43,8 +43,8 @@ var g_ScorePanelsData = [ ], "teamCounterFn": calculateColorsTeam }, - { // units panel - "headings": [ // headings on units panel + "units": { + "headings": [ { "caption": translate("Player name"), "yStart": 26, "width": 200 }, { "caption": translate("Total"), "yStart": 34, "width": 120 }, { "caption": translate("Infantry"), "yStart": 34, "width": 100 }, @@ -58,7 +58,7 @@ var g_ScorePanelsData = [ "titleHeadings": [ { "caption": translate("Units Statistics (Trained / Lost / Killed)"), "yStart": 16, "width": (100 * 7 + 120) }, // width = 820 ], - "counters": [ // counters on units panel + "counters": [ { "width": 120, "fn": calculateUnits }, { "width": 100, "fn": calculateUnits }, { "width": 100, "fn": calculateUnits }, @@ -70,8 +70,8 @@ var g_ScorePanelsData = [ ], "teamCounterFn": calculateColorsTeam }, - { // resources panel - "headings": [ // headings on resources panel + "resources": { + "headings": [ { "caption": translate("Player name"), "yStart": 26, "width": 200 }, { "caption": translate("Food"), "yStart": 34, "width": 100 }, { "caption": translate("Wood"), "yStart": 34, "width": 100 }, @@ -85,7 +85,7 @@ var g_ScorePanelsData = [ "titleHeadings": [ { "caption": translate("Resource Statistics (Gathered / Used)"), "yStart": 16, "width": (100 * 4 + 110) }, // width = 510 ], - "counters": [ // counters on resources panel + "counters": [ { "width": 100, "fn": calculateResources }, { "width": 100, "fn": calculateResources }, { "width": 100, "fn": calculateResources }, @@ -97,8 +97,8 @@ var g_ScorePanelsData = [ ], "teamCounterFn": calculateResourcesTeam }, - { // market panel - "headings": [ // headings on market panel + "market": { + "headings": [ { "caption": translate("Player name"), "yStart": 26, "width": 200 }, { "caption": translate("Food exchanged"), "yStart": 16, "width": 100 }, { "caption": translate("Wood exchanged"), "yStart": 16, "width": 100 }, @@ -108,7 +108,7 @@ var g_ScorePanelsData = [ { "caption": translate("Trade income"), "yStart": 16, "width": 100 } ], "titleHeadings": [], - "counters": [ // counters on market panel + "counters": [ { "width": 100, "fn": calculateResourceExchanged }, { "width": 100, "fn": calculateResourceExchanged }, { "width": 100, "fn": calculateResourceExchanged }, @@ -118,8 +118,8 @@ var g_ScorePanelsData = [ ], "teamCounterFn": calculateMarketTeam }, - { // miscellaneous panel - "headings": [ // headings on miscellaneous panel + "misc": { + "headings": [ { "caption": translate("Player name"), "yStart": 26, "width": 200 }, { "caption": translate("Vegetarian\nratio"), "yStart": 16, "width": 100 }, { "caption": translate("Feminization"), "yStart": 16, "width": 100 }, @@ -131,7 +131,7 @@ var g_ScorePanelsData = [ "titleHeadings": [ { "caption": translate("Map control"), "xOffset": 400, "yStart": 16, "width": 200 } ], - "counters": [ // counters on miscellaneous panel + "counters": [ { "width": 100, "fn": calculateVegetarianRatio }, { "width": 100, "fn": calculateFeminization }, { "width": 100, "fn": calculateKillDeathRatio }, @@ -141,7 +141,7 @@ var g_ScorePanelsData = [ ], "teamCounterFn": calculateMiscellaneous } -]; +}; function resetGeneralPanel() { diff --git a/binaries/data/mods/public/gui/summary/summary.js b/binaries/data/mods/public/gui/summary/summary.js index 2f302b8a49..3a3a09e39d 100644 --- a/binaries/data/mods/public/gui/summary/summary.js +++ b/binaries/data/mods/public/gui/summary/summary.js @@ -2,16 +2,13 @@ const g_MaxHeadingTitle= 8; // const for filtering long collective headings const g_LongHeadingWidth = 250; -// Vertical size of player box + const g_PlayerBoxYSize = 30; -// Gap between players boxes const g_PlayerBoxGap = 2; -// Alpha for player box const g_PlayerBoxAlpha = " 32"; -// Alpha for player color box const g_PlayerColorBoxAlpha = " 255"; -// yStart value for spacing teams boxes (and noTeamsBox) const g_TeamsBoxYStart = 65; + // Colors used for units and buildings const g_TrainedColor = '[color="201 255 200"]'; const g_LostColor = '[color="255 213 213"]'; @@ -25,40 +22,51 @@ const g_ResourcesTypes = [ "food", "wood", "stone", "metal" ]; const g_IncomeColor = '[color="201 255 200"]'; const g_OutcomeColor = '[color="255 213 213"]'; -const g_DefaultDecimal = "0.00"; const g_InfiniteSymbol = "\u221E"; -// Load data + var g_CivData = loadCivData(); var g_Teams = []; + // TODO set g_PlayerCount as playerCounters.length var g_PlayerCount = 0; + // Count players without team (or all if teams are not displayed) var g_WithoutTeam = 0; var g_GameData; -/** - * Select active panel - * @param panelNumber Number of panel, which should get active state (integer) - */ -function selectPanel(panelNumber) +function selectPanel(panel) { - let panelNames = [ 'scorePanel', 'buildingsPanel', 'unitsPanel', 'resourcesPanel', 'marketPanel', 'miscPanel' ]; + // TODO: move panel buttons to a custom parent object - function adjustTabDividers(tabSize) - { - let leftSpacer = Engine.GetGUIObjectByName("tabDividerLeft"); - let rightSpacer = Engine.GetGUIObjectByName("tabDividerRight"); - leftSpacer.size = "20 " + leftSpacer.size.top + " " + (tabSize.left + 2) + " " + leftSpacer.size.bottom; - rightSpacer.size = (tabSize.right - 2) + " " + rightSpacer.size.top + " 100%-20 " + rightSpacer.size.bottom; - } + for (let button of Engine.GetGUIObjectByName("summaryWindow").children) + if (button.name.endsWith("PanelButton")) + button.sprite = "BackgroundTab"; - for (let i = 0; i < panelNames.length; ++i) - Engine.GetGUIObjectByName(panelNames[i] + 'Button').sprite = "BackgroundTab"; + panel.sprite = "ForegroundTab"; - Engine.GetGUIObjectByName(panelNames[panelNumber] + 'Button').sprite = "ForegroundTab"; - adjustTabDividers(Engine.GetGUIObjectByName(panelNames[panelNumber] + 'Button').size); + adjustTabDividers(panel.size); - updatePanelData(g_ScorePanelsData[panelNumber]); + updatePanelData(g_ScorePanelsData[panel.name.substr(0, panel.name.length - "PanelButton".length)]); +} + +function adjustTabDividers(tabSize) +{ + let leftSpacer = Engine.GetGUIObjectByName("tabDividerLeft"); + let rightSpacer = Engine.GetGUIObjectByName("tabDividerRight"); + + leftSpacer.size = [ + 20, + leftSpacer.size.top, + tabSize.left + 2, + leftSpacer.size.bottom + ].join(" "); + + rightSpacer.size = [ + tabSize.right - 2, + rightSpacer.size.top, + "100%-20", + rightSpacer.size.bottom + ].join(" "); } function updatePanelData(panelInfo) @@ -104,6 +112,7 @@ function updatePanelData(panelInfo) let rowPlayerObject = Engine.GetGUIObjectByName(rowPlayer); rowPlayerObject.hidden = false; rowPlayerObject.sprite = colorString + g_PlayerBoxAlpha; + let boxSize = rowPlayerObject.size; boxSize.right = rowPlayerObjectWidth; rowPlayerObject.size = boxSize; @@ -114,16 +123,14 @@ function updatePanelData(panelInfo) Engine.GetGUIObjectByName(playerNameColumn).caption = g_GameData.players[i+1].name; let civIcon = Engine.GetGUIObjectByName(playerCivicBoxColumn); - civIcon.sprite = "stretched:"+g_CivData[playerState.civ].Emblem; + civIcon.sprite = "stretched:" + g_CivData[playerState.civ].Emblem; civIcon.tooltip = g_CivData[playerState.civ].Name; - // Update counters updateCountersPlayer(playerState, panelInfo.counters, playerCounterValue); - // Calculate g_TeamHelperData calculateTeamCounters(playerState); } - // Update team counters + let teamCounterFn = panelInfo.teamCounterFn; if (g_Teams && teamCounterFn) teamCounterFn(panelInfo.counters); @@ -176,7 +183,7 @@ function init(data) // Panels g_PlayerCount = data.playerStates.length - 1; - if (data.mapSettings.LockTeams) // teams ARE locked + if (data.mapSettings.LockTeams) { // Count teams for (let t = 0; t < g_PlayerCount; ++t) @@ -188,7 +195,7 @@ function init(data) if (g_Teams.length == g_PlayerCount) g_Teams = false; // Each player has his own team. Displaying teams makes no sense. } - else // teams are NOT locked + else g_Teams = false; // Erase teams data if teams are not displayed @@ -206,5 +213,5 @@ function init(data) g_WithoutTeam -= g_Teams[i] ? g_Teams[i] : 0; } - selectPanel(0); + selectPanel(Engine.GetGUIObjectByName("scorePanelButton")); } diff --git a/binaries/data/mods/public/gui/summary/summary.xml b/binaries/data/mods/public/gui/summary/summary.xml index 48e69f6656..4a77ea6e0e 100644 --- a/binaries/data/mods/public/gui/summary/summary.xml +++ b/binaries/data/mods/public/gui/summary/summary.xml @@ -17,7 +17,8 @@