mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 05:13:58 -07:00
Remove Engine.SwitchGuiPage from gamesetup
This commit is contained in:
parent
2f1bf9531b
commit
3edda64566
5 changed files with 42 additions and 23 deletions
|
|
@ -3,10 +3,12 @@
|
|||
*/
|
||||
class GameSettingsController
|
||||
{
|
||||
constructor(setupWindow, netMessages, playerAssignmentsController, mapCache, isSavedGame)
|
||||
constructor(setupWindow, netMessages, playerAssignmentsController, mapCache, closePageCallback,
|
||||
isSavedGame)
|
||||
{
|
||||
this.setupWindow = setupWindow;
|
||||
this.mapCache = mapCache;
|
||||
this.closePageCallback = closePageCallback;
|
||||
this.isSavedGame = isSavedGame;
|
||||
this.persistentMatchSettings = new PersistentMatchSettings(g_IsNetworked);
|
||||
|
||||
|
|
@ -306,10 +308,13 @@ class GameSettingsController
|
|||
|
||||
switchToLoadingPage(attributes)
|
||||
{
|
||||
Engine.SwitchGuiPage("page_loading.xml", {
|
||||
"attribs": attributes?.initAttributes || g_GameSettings.finalizedAttributes,
|
||||
"playerAssignments": g_PlayerAssignments
|
||||
});
|
||||
this.closePageCallback({ [Engine.openRequest]: {
|
||||
"page": "page_loading.xml",
|
||||
"argument": {
|
||||
"attribs": attributes?.initAttributes || g_GameSettings.finalizedAttributes,
|
||||
"playerAssignments": g_PlayerAssignments
|
||||
}
|
||||
} });
|
||||
}
|
||||
|
||||
onClose()
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
*/
|
||||
SetupWindowPages.GameSetupPage = class
|
||||
{
|
||||
constructor(setupWindow, isSavedGame)
|
||||
constructor(setupWindow, isSavedGame, cancelCallback)
|
||||
{
|
||||
Engine.ProfileStart("GameSetupPage");
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ SetupWindowPages.GameSetupPage = class
|
|||
"civInfoButton": new CivInfoButton(),
|
||||
"lobbyButton": new LobbyButton(),
|
||||
"savedGameLabel": new SavedGameLabel(isSavedGame),
|
||||
"cancelButton": new CancelButton(setupWindow, startGameButton, readyButton),
|
||||
"cancelButton": new CancelButton(startGameButton, readyButton, cancelCallback),
|
||||
"readyButton": readyButton,
|
||||
"startGameButton": startGameButton
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,15 +1,13 @@
|
|||
class CancelButton
|
||||
{
|
||||
constructor(setupWindow, startGameButton, readyButton)
|
||||
constructor(startGameButton, readyButton, cancelCallback)
|
||||
{
|
||||
this.setupWindow = setupWindow;
|
||||
|
||||
this.buttonPositions = Engine.GetGUIObjectByName("bottomRightPanel").children;
|
||||
|
||||
this.cancelButton = Engine.GetGUIObjectByName("cancelButton");
|
||||
this.cancelButton.caption = this.Caption;
|
||||
this.cancelButton.tooltip = Engine.HasXmppClient() ? this.TooltipLobby : this.TooltipMenu;
|
||||
this.cancelButton.onPress = setupWindow.closePage.bind(setupWindow);
|
||||
this.cancelButton.onPress = cancelCallback;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class SetupWindowPages
|
|||
*/
|
||||
class SetupWindow
|
||||
{
|
||||
constructor(initData, hotloadData)
|
||||
constructor(initData, hotloadData, closePageCallback)
|
||||
{
|
||||
if (!g_Settings)
|
||||
return;
|
||||
|
|
@ -38,7 +38,7 @@ class SetupWindow
|
|||
const playerAssignmentsController =
|
||||
new PlayerAssignmentsController(this, netMessages, isSavedGame);
|
||||
const gameSettingsController = new GameSettingsController(this, netMessages,
|
||||
playerAssignmentsController, mapCache, isSavedGame);
|
||||
playerAssignmentsController, mapCache, closePageCallback, isSavedGame);
|
||||
const readyController = new ReadyController(netMessages, gameSettingsController, playerAssignmentsController);
|
||||
const lobbyGameRegistrationController = g_IsController && Engine.HasXmppClient() &&
|
||||
new LobbyGameRegistrationController(initData, this, netMessages, mapCache, playerAssignmentsController);
|
||||
|
|
@ -57,7 +57,10 @@ class SetupWindow
|
|||
// These are the pages within the setup window that may use the controls defined above
|
||||
this.pages = {};
|
||||
for (const name in SetupWindowPages)
|
||||
this.pages[name] = new SetupWindowPages[name](this, isSavedGame);
|
||||
{
|
||||
this.pages[name] = new SetupWindowPages[name](this, isSavedGame,
|
||||
this.closePage.bind(this, closePageCallback));
|
||||
}
|
||||
|
||||
netMessages.registerNetMessageHandler("netwarn", addNetworkWarning);
|
||||
setTimeout(displayGamestateNotifications, 1000);
|
||||
|
|
@ -113,7 +116,7 @@ class SetupWindow
|
|||
updateTimers();
|
||||
}
|
||||
|
||||
closePage()
|
||||
closePage(closePageCallback)
|
||||
{
|
||||
for (const handler of this.closePageHandlers)
|
||||
handler();
|
||||
|
|
@ -121,10 +124,22 @@ class SetupWindow
|
|||
Engine.DisconnectNetworkGame();
|
||||
|
||||
if (this.backPage)
|
||||
Engine.SwitchGuiPage(this.backPage.page, this.backPage?.data);
|
||||
else if (Engine.HasXmppClient())
|
||||
Engine.SwitchGuiPage("page_lobby.xml", { "dialog": false });
|
||||
else
|
||||
Engine.SwitchGuiPage("page_pregame.xml");
|
||||
{
|
||||
closePageCallback({ [Engine.openRequest]: {
|
||||
"page": this.backPage.page,
|
||||
"argument": this.backPage?.data
|
||||
} });
|
||||
}
|
||||
if (Engine.HasXmppClient())
|
||||
{
|
||||
closePageCallback({ [Engine.openRequest]: {
|
||||
"page": "page_lobby.xml",
|
||||
"argument": { "dialog": false }
|
||||
} });
|
||||
}
|
||||
closePageCallback({ [Engine.openRequest]: {
|
||||
"page": "page_pregame.xml"
|
||||
} });
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,9 +43,10 @@ var g_SetupWindow;
|
|||
|
||||
function init(initData, hotloadData)
|
||||
{
|
||||
g_SetupWindow = new SetupWindow(initData, hotloadData);
|
||||
return g_IsNetworked ? g_SetupWindow.controls.netMessages.pollPendingMessages() :
|
||||
new Promise(() => {});
|
||||
return Promise.race([new Promise(closePageCallback =>
|
||||
{
|
||||
g_SetupWindow = new SetupWindow(initData, hotloadData, closePageCallback);
|
||||
}), ...(g_IsNetworked ? [g_SetupWindow.controls.netMessages.pollPendingMessages()] : [])]);
|
||||
}
|
||||
|
||||
function getHotloadData()
|
||||
|
|
|
|||
Loading…
Reference in a new issue