Rename PushGuiPage to OpenChildPage

There is no `PopGuiPage` anymore. For symmetry there should also be no
`PushGuiPage`.
This commit is contained in:
phosit 2024-10-30 18:56:33 +01:00 committed by phosit
parent d0ab2cb783
commit df5fee6103
32 changed files with 71 additions and 87 deletions

View file

@ -1,4 +1,4 @@
function init()
{
return Engine.PushGuiPage("regainFocus/page_emptyPage.xml");
return Engine.OpenChildPage("regainFocus/page_emptyPage.xml");
}

View file

@ -1,5 +1,5 @@
async function init()
{
await Engine.PushGuiPage("regainFocus/page_emptyPage.xml");
await Engine.PushGuiPage("regainFocus/page_emptyPage.xml");
await Engine.OpenChildPage("regainFocus/page_emptyPage.xml");
await Engine.OpenChildPage("regainFocus/page_emptyPage.xml");
}

View file

@ -1,6 +1,6 @@
function messageBox(width, height, message, title, buttonCaptions)
{
return Engine.PushGuiPage(
return Engine.OpenChildPage(
"page_msgbox.xml",
{
"width": width,
@ -13,7 +13,7 @@ function messageBox(width, height, message, title, buttonCaptions)
function timedConfirmation(width, height, message, timeParameter, timeout, title, buttonCaptions)
{
return Engine.PushGuiPage(
return Engine.OpenChildPage(
"page_timedconfirmation.xml",
{
"width": width,

View file

@ -7,7 +7,7 @@ function initTerms(terms)
async function openTerms(page)
{
const data = await Engine.PushGuiPage(
const data = await Engine.OpenChildPage(
"page_termsdialog.xml",
{
"file": g_Terms[page].file,

View file

@ -84,7 +84,7 @@ function init(data, hotloadData)
initMods();
initGUIButtons(data);
if (g_HasIncompatibleMods)
Engine.PushGuiPage("page_incompatible_mods.xml", {});
Engine.OpenChildPage("page_incompatible_mods.xml", {});
}
function initMods()

View file

@ -200,7 +200,7 @@
<object type="button" style="ModernButtonRed" size="100%-748 100%-44 100%-568 100%-16">
<translatableAttribute id="caption">Help</translatableAttribute>
<action on="Press">Engine.PushGuiPage("page_modhelp.xml");</action>
<action on="Press">Engine.OpenChildPage("page_modhelp.xml");</action>
</object>
<object type="button" style="ModernButtonRed" size="100%-564 100%-44 100%-384 100%-16">

View file

@ -28,6 +28,6 @@ async function openModIo(data)
if (!data.accepted)
return;
await Engine.PushGuiPage("page_modio.xml");
await Engine.OpenChildPage("page_modio.xml");
initMods();
}

View file

@ -7,7 +7,7 @@
Engine.HasXmppClient = () => false;
Engine.SetRankedGame = () => {};
Engine.TextureExists = () => false;
Engine.PushGuiPage = () => {};
Engine.OpenChildPage = () => {};
Engine.SwitchGuiPage = () => {};
var translateObjectKeys = () => {}

View file

@ -28,7 +28,7 @@ class CampaignMenu extends AutoWatcher
async loadSavegame()
{
const gameId = await Engine.PushGuiPage(
const gameId = await Engine.OpenChildPage(
'page_loadgame.xml',
{
"campaignRun": this.run.filename

View file

@ -12,13 +12,13 @@ class CampaignSetupPage extends AutoWatcher
this.templates = CampaignTemplate.getAvailableTemplates();
Engine.GetGUIObjectByName("mainMenuButton").onPress = () => Engine.SwitchGuiPage("page_pregame.xml");
Engine.GetGUIObjectByName("startCampButton").onPress = () => Engine.PushGuiPage("campaigns/new_modal/page.xml", this.selectedTemplate);
Engine.GetGUIObjectByName("startCampButton").onPress = () => Engine.OpenChildPage("campaigns/new_modal/page.xml", this.selectedTemplate);
this.campaignSelection = Engine.GetGUIObjectByName("campaignSelection");
this.campaignSelection.onMouseLeftDoubleClickItem = () => {
if (this.selectedIndex === -1)
return;
Engine.PushGuiPage("campaigns/new_modal/page.xml", this.selectedTemplate);
Engine.OpenChildPage("campaigns/new_modal/page.xml", this.selectedTemplate);
};
this.campaignSelection.onSelectionChange = () => {
this.selectedIndex = this.campaignSelection.selected;

View file

@ -46,7 +46,7 @@ function cancelOnLoadGameError(msg)
Engine.SwitchGuiPage("page_pregame.xml");
if (msg)
Engine.PushGuiPage("page_msgbox.xml", {
Engine.OpenChildPage("page_msgbox.xml", {
"width": 500,
"height": 200,
"message": msg,

View file

@ -302,7 +302,7 @@ async function pageLoop(page, args)
{
let completionValue = { "nextPage": page, "args": args };
while (completionValue?.nextPage != null)
completionValue = await Engine.PushGuiPage(completionValue.nextPage, completionValue.args);
completionValue = await Engine.OpenChildPage(completionValue.nextPage, completionValue.args);
return completionValue;
}

View file

@ -11,7 +11,7 @@ class LobbyButton
onPress()
{
if (Engine.HasXmppClient())
Engine.PushGuiPage("page_lobby.xml", { "dialog": true });
Engine.OpenChildPage("page_lobby.xml", { "dialog": true });
}
}

View file

@ -348,7 +348,7 @@ async function handleAuthenticated(message, loadSavedGame)
}
g_IsConnecting = false;
const savegameID = loadSavedGame ? await Engine.PushGuiPage("page_loadgame.xml") : undefined;
const savegameID = loadSavedGame ? await Engine.OpenChildPage("page_loadgame.xml") : undefined;
if (loadSavedGame && !savegameID)
{

View file

@ -22,7 +22,7 @@ class HostButton
onPress(loadSavedGame)
{
Engine.PushGuiPage("page_gamesetup_mp.xml", {
Engine.OpenChildPage("page_gamesetup_mp.xml", {
"loadSavedGame": loadSavedGame,
"multiplayerGameType": "host",
"name": g_Nickname,

View file

@ -70,7 +70,7 @@ class JoinButton
if (this.joinButton.hidden)
return;
Engine.PushGuiPage("page_gamesetup_mp.xml", {
Engine.OpenChildPage("page_gamesetup_mp.xml", {
"multiplayerGameType": "join",
"name": g_Nickname,
"rating": this.getRejoinRating(stanza),

View file

@ -46,7 +46,7 @@ function languageSelectionChanged()
async function openAdvancedMenu()
{
let localeText = Engine.GetGUIObjectByName("localeText");
const locale = await Engine.PushGuiPage("page_locale_advanced.xml", { "locale": localeText.caption });
const locale = await Engine.OpenChildPage("page_locale_advanced.xml", { "locale": localeText.caption });
if (!locale)
return;

View file

@ -81,7 +81,7 @@ var g_OptionType = {
},
"initGUI": (option, control) => {
control.children[2].onPress = async() => {
const color = await Engine.PushGuiPage("page_colormixer.xml", control.caption);
const color = await Engine.OpenChildPage("page_colormixer.xml", control.caption);
if (color != control.caption)
{

View file

@ -6,9 +6,7 @@ var g_MainMenuItems = [
{
"caption": translate("Manual"),
"tooltip": translate("Open the 0 A.D. Game Manual."),
"onPress": () => {
Engine.PushGuiPage("page_manual.xml");
}
"onPress": Engine.OpenChildPage.bind(null, "page_manual.xml")
},
{
"caption": translate("Tutorial"),
@ -35,9 +33,9 @@ var g_MainMenuItems = [
{
"caption": translate("Tips and Tricks"),
"tooltip": translate("Discover simple tips, tricks, and game mechanics."),
"onPress": () => {
Engine.PushGuiPage("page_tips.xml", { "tipScrolling": true });
}
"onPress": Engine.OpenChildPage.bind(null, "page_tips.xml", {
"tipScrolling": true
})
},
{
"caption": translate("Structure Tree"),
@ -54,16 +52,12 @@ var g_MainMenuItems = [
{
"caption": translate("Catafalque Overview"),
"tooltip": translate("Compare the bonuses of catafalques featured in 0 A.D."),
"onPress": () => {
Engine.PushGuiPage("page_catafalque.xml");
}
"onPress": Engine.OpenChildPage.bind(null, "page_catafalque.xml")
},
{
"caption": translate("Map Overview"),
"tooltip": translate("View the different maps featured in 0 A.D."),
"onPress": () => {
Engine.PushGuiPage("page_mapbrowser.xml");
},
"onPress": Engine.OpenChildPage.bind(null, "page_mapbrowser.xml")
}
]
},
@ -98,7 +92,7 @@ var g_MainMenuItems = [
"caption": translate("Load Game"),
"tooltip": translate("Load a saved game."),
"onPress": async() => {
const gameId = await Engine.PushGuiPage("page_loadgame.xml");
const gameId = await Engine.OpenChildPage("page_loadgame.xml");
if (!gameId)
return;
@ -185,23 +179,21 @@ var g_MainMenuItems = [
"hotkey": "lobby",
"onPress": () => {
if (Engine.StartXmppClient)
Engine.PushGuiPage("page_prelobby_entrance.xml");
Engine.OpenChildPage("page_prelobby_entrance.xml");
}
},
{
// Translation: Join a game by specifying the host's IP address.
"caption": translate("Join Game"),
"tooltip": translate("Joining an existing multiplayer game."),
"onPress": () => {
Engine.PushGuiPage("page_gamesetup_mp.xml", {
"onPress": Engine.OpenChildPage.bind(null, "page_gamesetup_mp.xml", {
"multiplayerGameType": "join"
});
}
})
},
{
"caption": translate("Host New Game"),
"tooltip": translate("Host a new multiplayer game."),
"onPress": Engine.PushGuiPage.bind(null, "page_gamesetup_mp.xml", {
"onPress": Engine.OpenChildPage.bind(null, "page_gamesetup_mp.xml", {
"multiplayerGameType": "host",
"loadSavedGame": false
})
@ -209,7 +201,7 @@ var g_MainMenuItems = [
{
"caption": translate("Host Saved Game"),
"tooltip": translate("Continue playing a game from a savegame."),
"onPress": Engine.PushGuiPage.bind(null, "page_gamesetup_mp.xml", {
"onPress": Engine.OpenChildPage.bind(null, "page_gamesetup_mp.xml", {
"multiplayerGameType": "host",
"loadSavedGame": true
})
@ -237,22 +229,18 @@ var g_MainMenuItems = [
"caption": translate("Options"),
"tooltip": translate("Adjust game settings."),
"onPress": async() => {
fireConfigChangeHandlers(await Engine.PushGuiPage("page_options.xml"));
fireConfigChangeHandlers(await Engine.OpenChildPage("page_options.xml"));
}
},
{
"caption": translate("Hotkeys"),
"tooltip": translate("Adjust hotkeys."),
"onPress": () => {
Engine.PushGuiPage("hotkeys/page_hotkeys.xml");
}
"onPress": Engine.OpenChildPage.bind(null, "hotkeys/page_hotkeys.xml")
},
{
"caption": translate("Language"),
"tooltip": translate("Choose the language of the game."),
"onPress": () => {
Engine.PushGuiPage("page_locale.xml");
}
"onPress": Engine.OpenChildPage.bind(null, "page_locale.xml")
},
{
"caption": translate("Mod Selection"),
@ -264,9 +252,7 @@ var g_MainMenuItems = [
{
"caption": translate("Welcome Screen"),
"tooltip": translate("Show the Welcome Screen again. Useful if you hid it by mistake."),
"onPress": () => {
Engine.PushGuiPage("page_splashscreen.xml");
}
"onPress": Engine.OpenChildPage.bind(null, "page_splashscreen.xml")
}
]
},
@ -296,9 +282,7 @@ var g_MainMenuItems = [
{
"caption": translate("Credits"),
"tooltip": translate("Show the 0 A.D. credits."),
"onPress": () => {
Engine.PushGuiPage("page_credits.xml");
}
"onPress": Engine.OpenChildPage.bind(null, "page_credits.xml")
},
{
"caption": translate("Exit"),

View file

@ -31,7 +31,9 @@ class SplashScreenHandler
this.showSplashScreen = false;
if (Engine.ConfigDB_GetValue("user", "gui.splashscreen.enable") === "true" ||
Engine.ConfigDB_GetValue("user", "gui.splashscreen.version") !== Engine.CalculateMD5(Engine.ReadFile("gui/splashscreen/splashscreen.xml")))
Engine.PushGuiPage("page_splashscreen.xml", {});
Engine.ConfigDB_GetValue("user", "gui.splashscreen.version") !== Engine.CalculateMD5(Engine.ReadFile("gui/splashscreen/splashscreen.xml")))
{
Engine.OpenChildPage("page_splashscreen.xml", {});
}
}
}

View file

@ -10,10 +10,10 @@ function init()
function loginButton()
{
Engine.PushGuiPage("page_prelobby_login.xml");
Engine.OpenChildPage("page_prelobby_login.xml");
}
function registerButton()
{
Engine.PushGuiPage("page_prelobby_register.xml");
Engine.OpenChildPage("page_prelobby_register.xml");
}

View file

@ -41,5 +41,5 @@ async function onRegistered()
Engine.StopXmppClient();
Engine.PushGuiPage("page_prelobby_login.xml");
Engine.OpenChildPage("page_prelobby_login.xml");
}

View file

@ -10,12 +10,10 @@ class EntityBox
static setViewerOnPress(guiObject, templateName, civCode)
{
let viewerFunc = () => {
Engine.PushGuiPage("page_viewer.xml", {
let viewerFunc = Engine.OpenChildPage.bind(null, "page_viewer.xml", {
"templateName": templateName,
"civ": civCode
});
};
guiObject.onPress = viewerFunc;
guiObject.onPressRight = viewerFunc;
}

View file

@ -20,7 +20,7 @@ MenuButtons.prototype.Manual = class
{
closeOpenDialogs();
this.pauseControl.implicitPause();
await Engine.PushGuiPage("page_manual.xml");
await Engine.OpenChildPage("page_manual.xml");
resumeGame();
}
};
@ -60,7 +60,7 @@ MenuButtons.prototype.Save = class
closeOpenDialogs();
this.pauseControl.implicitPause();
await Engine.PushGuiPage(
await Engine.OpenChildPage(
"page_loadgame.xml",
{
"savedGameData": getSavedGameData(),
@ -103,7 +103,7 @@ MenuButtons.prototype.Summary = class
// Allows players to see their own summary.
// If they have shared ally vision researched, they are able to see the summary of there allies too.
let simState = Engine.GuiInterfaceCall("GetExtendedSimulationState");
const data = await Engine.PushGuiPage(
const data = await Engine.OpenChildPage(
"page_summary.xml",
{
"sim": {
@ -149,7 +149,7 @@ MenuButtons.prototype.Lobby = class
if (!Engine.HasXmppClient())
return;
closeOpenDialogs();
Engine.PushGuiPage("page_lobby.xml", { "dialog": true });
Engine.OpenChildPage("page_lobby.xml", { "dialog": true });
}
};
@ -167,7 +167,7 @@ MenuButtons.prototype.Options = class
closeOpenDialogs();
this.pauseControl.implicitPause();
fireConfigChangeHandlers(await Engine.PushGuiPage("page_options.xml"));
fireConfigChangeHandlers(await Engine.OpenChildPage("page_options.xml"));
resumeGame();
}
};
@ -186,7 +186,7 @@ MenuButtons.prototype.Hotkeys = class
closeOpenDialogs();
this.pauseControl.implicitPause();
await Engine.PushGuiPage("hotkeys/page_hotkeys.xml");
await Engine.OpenChildPage("hotkeys/page_hotkeys.xml");
resumeGame();
}
};

View file

@ -9,7 +9,7 @@ class SessionMessageBox
closeOpenDialogs();
g_PauseControl.implicitPause();
const buttonId = await Engine.PushGuiPage(
const buttonId = await Engine.OpenChildPage(
"page_msgbox.xml",
{
"width": this.Width,

View file

@ -23,7 +23,7 @@ class CampaignSession
this.endGameData.won = won;
// Run the endgame script.
Engine.PushGuiPage(this.getEndGame(), this.endGameData);
Engine.OpenChildPage(this.getEndGame(), this.endGameData);
closePageCallback();
}

View file

@ -1269,7 +1269,7 @@ async function showTemplateDetails(templateName, civCode)
return;
g_PauseControl.implicitPause();
await Engine.PushGuiPage(
await Engine.OpenChildPage(
"page_viewer.xml",
{
"templateName": templateName,

View file

@ -172,7 +172,7 @@
>
<action on="Press">
if (Engine.HasXmppClient())
Engine.PushGuiPage("page_lobby.xml", { "dialog": true });
Engine.OpenChildPage("page_lobby.xml", { "dialog": true });
</action>
</object>

View file

@ -113,10 +113,10 @@ void CGUIManager::SwitchPage(const CStrW& pageName, const ScriptInterface* srcSc
m_PageStack.clear();
}
PushPage(pageName, initDataClone);
OpenChildPage(pageName, initDataClone);
}
JS::Value CGUIManager::PushPage(const CStrW& pageName, Script::StructuredClone initData)
JS::Value CGUIManager::OpenChildPage(const CStrW& pageName, Script::StructuredClone initData)
{
// Store the callback handler in the current GUI page before opening the new one
JS::RootedValue promise{m_ScriptInterface.GetGeneralJSContext(), [&]
@ -130,8 +130,8 @@ JS::Value CGUIManager::PushPage(const CStrW& pageName, Script::StructuredClone i
return m_PageStack.back().ReplacePromise(*currentPage.GetScriptInterface());
}()};
// Push the page prior to loading its contents, because that may push
// another GUI page on init which should be pushed on top of this new page.
// Emplace the page prior to loading its contents, because that may open
// another GUI page on init which should be emplaced on top of this new page.
m_PageStack.emplace_back(pageName, initData);
m_PageStack.back().LoadPage(m_ScriptContext);

View file

@ -71,7 +71,7 @@ public:
* user inputs.
* The returned promise will be fulfilled once the pushed page is closed.
*/
JS::Value PushPage(const CStrW& pageName, Script::StructuredClone initData);
JS::Value OpenChildPage(const CStrW& pageName, Script::StructuredClone initData);
/**
* Called when a file has been modified, to hotload changes.

View file

@ -33,9 +33,9 @@ namespace JSI_GUIManager
// Note that the initData argument may only contain clonable data.
// Functions aren't supported for example!
// It returns a promise.
JS::Value PushGuiPage(const ScriptRequest& rq, const std::wstring& name, JS::HandleValue initData)
JS::Value OpenChildPage(const ScriptRequest& rq, const std::wstring& name, JS::HandleValue initData)
{
return g_GUI->PushPage(name, Script::WriteStructuredClone(rq, initData));
return g_GUI->OpenChildPage(name, Script::WriteStructuredClone(rq, initData));
}
void SwitchGuiPage(const ScriptInterface& scriptInterface, const std::wstring& name, JS::HandleValue initData)
@ -66,7 +66,7 @@ CParamNode GetTemplate(const std::string& templateName)
void RegisterScriptFunctions(const ScriptRequest& rq)
{
ScriptFunction::Register<&PushGuiPage>(rq, "PushGuiPage");
ScriptFunction::Register<&OpenChildPage>(rq, "OpenChildPage");
ScriptFunction::Register<&SwitchGuiPage>(rq, "SwitchGuiPage");
ScriptFunction::Register<&SetCursor>(rq, "SetCursor");
ScriptFunction::Register<&ResetCursor>(rq, "ResetCursor");

View file

@ -83,7 +83,7 @@ public:
Script::CreateObject(rq, &val);
Script::StructuredClone data = Script::WriteStructuredClone(rq, JS::NullHandleValue);
g_GUI->PushPage(L"event/page_event.xml", data);
g_GUI->OpenChildPage(L"event/page_event.xml", data);
const ScriptInterface& pageScriptInterface = *(g_GUI->GetActiveGUI()->GetScriptInterface());
ScriptRequest prq(pageScriptInterface);
@ -146,7 +146,7 @@ public:
Script::CreateObject(rq, &val);
Script::StructuredClone data = Script::WriteStructuredClone(rq, JS::NullHandleValue);
g_GUI->PushPage(L"hotkey/page_hotkey.xml", data);
g_GUI->OpenChildPage(L"hotkey/page_hotkey.xml", data);
// Press 'a'.
SDL_Event_ hotkeyNotification;
@ -228,11 +228,11 @@ public:
Script::WriteStructuredClone(rq, JS::UndefinedHandleValue)};
TS_ASSERT_EQUALS(g_GUI->GetPageCount(), 0);
g_GUI->PushPage(L"regainFocus/page_emptyPage.xml", undefined);
g_GUI->OpenChildPage(L"regainFocus/page_emptyPage.xml", undefined);
TS_ASSERT_EQUALS(g_GUI->GetPageCount(), 1);
// This page instantly pushes an empty page with a callback that pops another page again.
g_GUI->PushPage(L"regainFocus/page_pushWithPopOnInit.xml", undefined);
g_GUI->OpenChildPage(L"regainFocus/page_pushWithPopOnInit.xml", undefined);
TS_ASSERT_EQUALS(g_GUI->GetPageCount(), 3);
// Pop the empty page and execute the continuation.
@ -254,7 +254,7 @@ public:
const Script::StructuredClone undefined{
Script::WriteStructuredClone(rq, JS::UndefinedHandleValue)};
g_GUI->PushPage(L"regainFocus/page_emptyPage.xml", undefined);
g_GUI->OpenChildPage(L"regainFocus/page_emptyPage.xml", undefined);
for (const auto& [reject, result] : testSteps)
@ -263,7 +263,7 @@ public:
const Script::StructuredClone clonedValue{Script::WriteStructuredClone(rq, value)};
const JS::RootedValue promise{rq.cx,
g_GUI->PushPage(L"resolveReject/page_resolveReject.xml", clonedValue)};
g_GUI->OpenChildPage(L"resolveReject/page_resolveReject.xml", clonedValue)};
// Check whether promises are settled in the page stack and flush the stack.
g_GUI->TickObjects();
@ -277,7 +277,7 @@ public:
const ScriptRequest rq{g_GUI->GetScriptInterface()};
const Script::StructuredClone undefined{
Script::WriteStructuredClone(rq, JS::UndefinedHandleValue)};
g_GUI->PushPage(L"sequential/page_sequential.xml", undefined);
g_GUI->OpenChildPage(L"sequential/page_sequential.xml", undefined);
TS_ASSERT_EQUALS(g_GUI->GetPageCount(), 2);
CloseTopmostPage();
TS_ASSERT_EQUALS(g_GUI->GetPageCount(), 2);