1
0
forked from mirrors/0ad

Remove Engine.SwitchGuiPage from replay menu

This commit is contained in:
phosit
2025-04-23 19:17:34 +02:00
parent d842a134f9
commit 2f1bf9531b
3 changed files with 87 additions and 49 deletions
@@ -37,17 +37,30 @@ function createReplaySelectionData(selectedDirectory)
/** /**
* Starts the selected visual replay, or shows an error message in case of incompatibility. * Starts the selected visual replay, or shows an error message in case of incompatibility.
*/ */
function startReplay() function startReplayHandler()
{ {
var selected = Engine.GetGUIObjectByName("replaySelection").selected; return new Promise(resolve =>
if (selected == -1) {
return; const startReplay = () =>
{
const selected = Engine.GetGUIObjectByName("replaySelection").selected;
if (selected == -1)
return;
var replay = g_ReplaysFiltered[selected]; const replay = g_ReplaysFiltered[selected];
if (isReplayCompatible(replay)) if (!isReplayCompatible(replay))
reallyStartVisualReplay(replay.directory); {
else displayReplayCompatibilityError(replay);
displayReplayCompatibilityError(replay); return;
}
const ret = reallyStartVisualReplay(replay.directory);
if (ret !== undefined)
resolve(ret);
};
Engine.GetGUIObjectByName("startReplayButton").onPress = startReplay;
Engine.GetGUIObjectByName("replaySelection").onMouseLeftDoubleClickItem = startReplay;
});
} }
/** /**
@@ -60,20 +73,23 @@ function reallyStartVisualReplay(replayDirectory)
if (!Engine.StartVisualReplay(replayDirectory)) if (!Engine.StartVisualReplay(replayDirectory))
{ {
warn('Replay "' + escapeText(Engine.GetReplayDirectoryName(replayDirectory)) + '" not found! Please click on reload cache.'); warn('Replay "' + escapeText(Engine.GetReplayDirectoryName(replayDirectory)) + '" not found! Please click on reload cache.');
return; return undefined;
} }
Engine.SwitchGuiPage("page_loading.xml", { return {
"attribs": Engine.GetReplayAttributes(replayDirectory), "page": "page_loading.xml",
"playerAssignments": { "argument": {
"local": { "attribs": Engine.GetReplayAttributes(replayDirectory),
"name": singleplayerName(), "playerAssignments": {
"player": -1 "local": {
} "name": singleplayerName(),
}, "player": -1
"savedGUIData": "", }
"replaySelectionData": createReplaySelectionData(replayDirectory) },
}); "savedGUIData": "",
"replaySelectionData": createReplaySelectionData(replayDirectory)
}
};
} }
/** /**
@@ -106,15 +122,26 @@ function displayReplayCompatibilityError(replay)
*/ */
function showReplaySummary() function showReplaySummary()
{ {
const selected = Engine.GetGUIObjectByName("replaySelection").selected; return new Promise(closePageCallback =>
if (selected == -1) {
return; Engine.GetGUIObjectByName("summaryButton").onPress = () =>
{
const selected = Engine.GetGUIObjectByName("replaySelection").selected;
if (selected == -1)
return;
const replay = g_ReplaysFiltered[selected]; const replay = g_ReplaysFiltered[selected];
if (isReplayCompatible(replay)) if (!isReplayCompatible(replay))
reallyShowReplaySummary(replay.directory); {
else displayReplayCompatibilityError(replay);
displayReplayCompatibilityError(replay); return;
}
const ret = reallyShowReplaySummary(replay.directory);
if (ret !== undefined)
closePageCallback(ret);
};
});
} }
function reallyShowReplaySummary(directory) function reallyShowReplaySummary(directory)
@@ -125,19 +152,22 @@ function reallyShowReplaySummary(directory)
if (!simData) if (!simData)
{ {
messageBox(500, 200, translate("No summary data available."), translate("Error")); messageBox(500, 200, translate("No summary data available."), translate("Error"));
return; return undefined;
} }
Engine.SwitchGuiPage("page_summary.xml", { return {
"sim": simData, "page": "page_summary.xml",
"gui": { "argument": {
"dialog": false, "sim": simData,
"isReplay": true, "gui": {
"replayDirectory": directory, "dialog": false,
"replaySelectionData": createReplaySelectionData(directory), "isReplay": true,
"summarySelection": g_SummarySelection "replayDirectory": directory,
"replaySelectionData": createReplaySelectionData(directory),
"summarySelection": g_SummarySelection
}
} }
}); };
} }
function reloadCache() function reloadCache()
@@ -58,12 +58,13 @@ var g_MapCache = new MapCache();
/** /**
* Initializes globals, loads replays and displays the list. * Initializes globals, loads replays and displays the list.
*/ */
function init(data) async function init(data)
{ {
if (!g_Settings) if (!g_Settings)
{ {
Engine.SwitchGuiPage("page_pregame.xml"); return { [Engine.openRequest]: {
return; "page": "page_pregame.xml"
} };
} }
g_SummarySelection = data && data.summarySelection; g_SummarySelection = data && data.summarySelection;
@@ -72,12 +73,23 @@ function init(data)
if (!g_Replays) if (!g_Replays)
{ {
Engine.SwitchGuiPage("page_pregame.xml"); return { [Engine.openRequest]: {
return; "page": "page_pregame.xml"
} };
} }
initHotkeyTooltips(); initHotkeyTooltips();
displayReplayList(); displayReplayList();
const closePromise = new Promise(closePageCallback =>
{
Engine.GetGUIObjectByName("mainMenu").onPress = closePageCallback.bind(undefined, {
"page": "page_pregame.xml"
});
});
const ret = await Promise.race([ closePromise, startReplayHandler(), showReplaySummary() ]);
return { [Engine.openRequest]: ret };
} }
/** /**
@@ -64,7 +64,6 @@
<action on="SelectionChange">displayReplayDetails();</action> <action on="SelectionChange">displayReplayDetails();</action>
<action on="SelectionColumnChange">displayReplayList();</action> <action on="SelectionColumnChange">displayReplayList();</action>
<action on="MouseLeftDoubleClickItem">startReplay();</action>
<!-- Columns --> <!-- Columns -->
<column id="months" textcolor="172 172 212" width="12%"> <column id="months" textcolor="172 172 212" width="12%">
@@ -224,9 +223,8 @@
<object name="bottomPanel" size="25 100%-56 100%-5 100%-24" > <object name="bottomPanel" size="25 100%-56 100%-5 100%-24" >
<!-- Main Menu Button --> <!-- Main Menu Button -->
<object type="button" style="StoneButton" size="0 0 19% 100%"> <object name="mainMenu" type="button" style="StoneButton" size="0 0 19% 100%">
<translatableAttribute id="caption">Main Menu</translatableAttribute> <translatableAttribute id="caption">Main Menu</translatableAttribute>
<action on="Press">Engine.SwitchGuiPage("page_pregame.xml");</action>
</object> </object>
<!-- Delete Button --> <!-- Delete Button -->
@@ -245,13 +243,11 @@
<!-- Summary Button --> <!-- Summary Button -->
<object name="summaryButton" type="button" style="StoneButton" size="60% 0 79% 100%" hotkey="summary"> <object name="summaryButton" type="button" style="StoneButton" size="60% 0 79% 100%" hotkey="summary">
<translatableAttribute id="caption">Summary</translatableAttribute> <translatableAttribute id="caption">Summary</translatableAttribute>
<action on="Press">showReplaySummary();</action>
</object> </object>
<!-- Start Replay Button --> <!-- Start Replay Button -->
<object name="startReplayButton" type="button" style="StoneButton" size="80% 0 99% 100%"> <object name="startReplayButton" type="button" style="StoneButton" size="80% 0 99% 100%">
<translatableAttribute id="caption">Start Replay</translatableAttribute> <translatableAttribute id="caption">Start Replay</translatableAttribute>
<action on="Press">startReplay();</action>
</object> </object>
</object> </object>