mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-07-04 05:55:47 -07:00
Cleanup summary screen init.
First fill all global helper variables before pushing the data to the GUI (IPO model). init should always be the first function declaration in a file. Split and rename init functions. Fill g_ScorePanelsData from init so that it becomes independent from the file include order. Include all files of the summary directory instead of each file individually, as in D619. This was SVN commit r20538.
This commit is contained in:
parent
63522189a0
commit
2b31ebad0d
3 changed files with 28 additions and 22 deletions
|
|
@ -1,4 +1,4 @@
|
|||
var g_ScorePanelsData = {
|
||||
var getScorePanelsData = () => ({
|
||||
"score": {
|
||||
"caption": translate("Score"),
|
||||
"headings": [
|
||||
|
|
@ -208,7 +208,7 @@ var g_ScorePanelsData = {
|
|||
],
|
||||
"teamCounterFn": calculateMiscellaneousTeam
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
function getColoredTypeTranslation(type)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
const g_CivData = loadCivData(false, false);
|
||||
|
||||
var g_ScorePanelsData;
|
||||
|
||||
var g_MaxHeadingTitle = 9;
|
||||
var g_LongHeadingWidth = 250;
|
||||
var g_PlayerBoxYSize = 40;
|
||||
var g_PlayerBoxGap = 2;
|
||||
var g_PlayerBoxAlpha = " 50";
|
||||
var g_PlayerBoxAlpha = 50;
|
||||
var g_TeamsBoxYStart = 40;
|
||||
|
||||
var g_TypeColors = {
|
||||
|
|
@ -125,6 +127,21 @@ var g_SelectedChart = {
|
|||
"type": [0, 0]
|
||||
};
|
||||
|
||||
function init(data)
|
||||
{
|
||||
// Fill globals
|
||||
g_GameData = data;
|
||||
g_ScorePanelsData = getScorePanelsData();
|
||||
initTeamData();
|
||||
calculateTeamCounterDataHelper();
|
||||
|
||||
// Output globals
|
||||
initPlayerBoxPositions();
|
||||
initGUICharts();
|
||||
initGUILabelsAndButtons();
|
||||
selectPanel(Engine.GetGUIObjectByName("scorePanelButton"));
|
||||
}
|
||||
|
||||
function selectPanel(panel)
|
||||
{
|
||||
// TODO: move panel buttons to a custom parent object
|
||||
|
|
@ -148,7 +165,7 @@ function selectPanel(panel)
|
|||
[0, 1].forEach(updateCategoryDropdown);
|
||||
}
|
||||
|
||||
function initCharts()
|
||||
function initGUICharts()
|
||||
{
|
||||
let player_colors = [];
|
||||
for (let i = 1; i <= g_PlayerCount; ++i)
|
||||
|
|
@ -161,9 +178,8 @@ function initCharts()
|
|||
);
|
||||
}
|
||||
|
||||
[0, 1].forEach(i => {
|
||||
for (let i = 0; i < 2; ++i)
|
||||
Engine.GetGUIObjectByName("chart[" + i + "]").series_color = player_colors;
|
||||
});
|
||||
|
||||
let chartLegend = Engine.GetGUIObjectByName("chartLegend");
|
||||
chartLegend.caption = g_GameData.sim.playerStates.slice(1).map(
|
||||
|
|
@ -343,7 +359,7 @@ function updatePanelData(panelInfo)
|
|||
|
||||
let rowPlayerObject = Engine.GetGUIObjectByName(rowPlayer);
|
||||
rowPlayerObject.hidden = false;
|
||||
rowPlayerObject.sprite = colorString + g_PlayerBoxAlpha;
|
||||
rowPlayerObject.sprite = colorString + " " + g_PlayerBoxAlpha;
|
||||
|
||||
let boxSize = rowPlayerObject.size;
|
||||
boxSize.right = rowPlayerObjectWidth;
|
||||
|
|
@ -419,9 +435,8 @@ function startReplay()
|
|||
});
|
||||
}
|
||||
|
||||
function init(data)
|
||||
function initGUILabelsAndButtons()
|
||||
{
|
||||
g_GameData = data;
|
||||
let assignedState = g_GameData.sim.playerStates[g_GameData.gui.assignedPlayer || -1];
|
||||
|
||||
Engine.GetGUIObjectByName("summaryText").caption =
|
||||
|
|
@ -439,8 +454,6 @@ function init(data)
|
|||
translate("You have been defeated...") :
|
||||
translate("You have abandoned the game.");
|
||||
|
||||
initPlayerBoxPositions();
|
||||
|
||||
Engine.GetGUIObjectByName("timeElapsed").caption = sprintf(
|
||||
translate("Game time elapsed: %(time)s"), {
|
||||
"time": timeToString(g_GameData.sim.timeElapsed)
|
||||
|
|
@ -456,7 +469,10 @@ function init(data)
|
|||
});
|
||||
|
||||
Engine.GetGUIObjectByName("replayButton").hidden = g_GameData.gui.isInGame || !g_GameData.gui.replayDirectory;
|
||||
}
|
||||
|
||||
function initTeamData()
|
||||
{
|
||||
// Panels
|
||||
g_PlayerCount = g_GameData.sim.playerStates.length - 1;
|
||||
|
||||
|
|
@ -481,9 +497,4 @@ function init(data)
|
|||
if (!g_Teams)
|
||||
for (let p = 0; p < g_PlayerCount; ++p)
|
||||
g_GameData.sim.playerStates[p+1].team = -1;
|
||||
|
||||
calculateTeamCounterDataHelper();
|
||||
|
||||
initCharts();
|
||||
selectPanel(Engine.GetGUIObjectByName("scorePanelButton"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,12 +3,7 @@
|
|||
<objects>
|
||||
|
||||
<script directory="gui/common/"/>
|
||||
|
||||
<script file="gui/summary/counters.js"/>
|
||||
<script file="gui/summary/summary.js"/>
|
||||
|
||||
<!-- Needs the colors from summary.js -->
|
||||
<script file="gui/summary/layout.js"/>
|
||||
<script directory="gui/summary/"/>
|
||||
|
||||
<object name="summaryWindow"
|
||||
type="image"
|
||||
|
|
|
|||
Loading…
Reference in a new issue