mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-07-04 05:55:47 -07:00
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.
This commit is contained in:
parent
92f2a21ac5
commit
80ea90ec4b
3 changed files with 67 additions and 59 deletions
|
|
@ -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()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@
|
|||
<script file="gui/summary/layout.js"/>
|
||||
<script file="gui/summary/summary.js"/>
|
||||
|
||||
<object type="image"
|
||||
<object name="summaryWindow"
|
||||
type="image"
|
||||
style="ModernWindow"
|
||||
size="0 0 100% 100%"
|
||||
>
|
||||
|
|
@ -60,42 +61,42 @@
|
|||
<object name="tabDividerRight" type="image" sprite="TabSpacer" size="328 120 330 122"/>
|
||||
|
||||
<object name="scorePanelButton" type="button" sprite="ForegroundTab" size="20 92 136 120">
|
||||
<action on="Press">selectPanel(0);</action>
|
||||
<action on="Press">selectPanel(this);</action>
|
||||
<object type="text" style="ModernLabelText" ghost="true">
|
||||
<translatableAttribute id="caption">Score</translatableAttribute>
|
||||
</object>
|
||||
</object>
|
||||
|
||||
<object name="buildingsPanelButton" type="button" sprite="BackgroundTab" size="142 92 260 120">
|
||||
<action on="Press">selectPanel(1);</action>
|
||||
<action on="Press">selectPanel(this);</action>
|
||||
<object type="text" style="ModernLabelText" ghost="true">
|
||||
<translatableAttribute id="caption">Buildings</translatableAttribute>
|
||||
</object>
|
||||
</object>
|
||||
|
||||
<object name="unitsPanelButton" type="button" sprite="BackgroundTab" size="266 92 384 120">
|
||||
<action on="Press">selectPanel(2);</action>
|
||||
<action on="Press">selectPanel(this);</action>
|
||||
<object type="text" style="ModernLabelText" ghost="true">
|
||||
<translatableAttribute id="caption">Units</translatableAttribute>
|
||||
</object>
|
||||
</object>
|
||||
|
||||
<object name="resourcesPanelButton" type="button" sprite="BackgroundTab" size="390 92 508 120">
|
||||
<action on="Press">selectPanel(3);</action>
|
||||
<action on="Press">selectPanel(this);</action>
|
||||
<object type="text" style="ModernLabelText" ghost="true">
|
||||
<translatableAttribute id="caption">Resources</translatableAttribute>
|
||||
</object>
|
||||
</object>
|
||||
|
||||
<object name="marketPanelButton" type="button" sprite="BackgroundTab" size="514 92 632 120">
|
||||
<action on="Press">selectPanel(4);</action>
|
||||
<action on="Press">selectPanel(this);</action>
|
||||
<object type="text" style="ModernLabelText" ghost="true">
|
||||
<translatableAttribute id="caption">Market</translatableAttribute>
|
||||
</object>
|
||||
</object>
|
||||
|
||||
<object name="miscPanelButton" type="button" sprite="BackgroundTab" size="638 92 756 120">
|
||||
<action on="Press">selectPanel(5);</action>
|
||||
<action on="Press">selectPanel(this);</action>
|
||||
<object type="text" style="ModernLabelText" ghost="true">
|
||||
<translatableAttribute id="caption">Miscellaneous</translatableAttribute>
|
||||
</object>
|
||||
|
|
|
|||
Loading…
Reference in a new issue