forked from mirrors/0ad
Remove Engine.SwitchGuiPage from gamesetup
This commit is contained in:
@@ -3,10 +3,12 @@
|
|||||||
*/
|
*/
|
||||||
class GameSettingsController
|
class GameSettingsController
|
||||||
{
|
{
|
||||||
constructor(setupWindow, netMessages, playerAssignmentsController, mapCache, isSavedGame)
|
constructor(setupWindow, netMessages, playerAssignmentsController, mapCache, closePageCallback,
|
||||||
|
isSavedGame)
|
||||||
{
|
{
|
||||||
this.setupWindow = setupWindow;
|
this.setupWindow = setupWindow;
|
||||||
this.mapCache = mapCache;
|
this.mapCache = mapCache;
|
||||||
|
this.closePageCallback = closePageCallback;
|
||||||
this.isSavedGame = isSavedGame;
|
this.isSavedGame = isSavedGame;
|
||||||
this.persistentMatchSettings = new PersistentMatchSettings(g_IsNetworked);
|
this.persistentMatchSettings = new PersistentMatchSettings(g_IsNetworked);
|
||||||
|
|
||||||
@@ -306,10 +308,13 @@ class GameSettingsController
|
|||||||
|
|
||||||
switchToLoadingPage(attributes)
|
switchToLoadingPage(attributes)
|
||||||
{
|
{
|
||||||
Engine.SwitchGuiPage("page_loading.xml", {
|
this.closePageCallback({ [Engine.openRequest]: {
|
||||||
"attribs": attributes?.initAttributes || g_GameSettings.finalizedAttributes,
|
"page": "page_loading.xml",
|
||||||
"playerAssignments": g_PlayerAssignments
|
"argument": {
|
||||||
});
|
"attribs": attributes?.initAttributes || g_GameSettings.finalizedAttributes,
|
||||||
|
"playerAssignments": g_PlayerAssignments
|
||||||
|
}
|
||||||
|
} });
|
||||||
}
|
}
|
||||||
|
|
||||||
onClose()
|
onClose()
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
SetupWindowPages.GameSetupPage = class
|
SetupWindowPages.GameSetupPage = class
|
||||||
{
|
{
|
||||||
constructor(setupWindow, isSavedGame)
|
constructor(setupWindow, isSavedGame, cancelCallback)
|
||||||
{
|
{
|
||||||
Engine.ProfileStart("GameSetupPage");
|
Engine.ProfileStart("GameSetupPage");
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ SetupWindowPages.GameSetupPage = class
|
|||||||
"civInfoButton": new CivInfoButton(),
|
"civInfoButton": new CivInfoButton(),
|
||||||
"lobbyButton": new LobbyButton(),
|
"lobbyButton": new LobbyButton(),
|
||||||
"savedGameLabel": new SavedGameLabel(isSavedGame),
|
"savedGameLabel": new SavedGameLabel(isSavedGame),
|
||||||
"cancelButton": new CancelButton(setupWindow, startGameButton, readyButton),
|
"cancelButton": new CancelButton(startGameButton, readyButton, cancelCallback),
|
||||||
"readyButton": readyButton,
|
"readyButton": readyButton,
|
||||||
"startGameButton": startGameButton
|
"startGameButton": startGameButton
|
||||||
};
|
};
|
||||||
|
|||||||
+2
-4
@@ -1,15 +1,13 @@
|
|||||||
class CancelButton
|
class CancelButton
|
||||||
{
|
{
|
||||||
constructor(setupWindow, startGameButton, readyButton)
|
constructor(startGameButton, readyButton, cancelCallback)
|
||||||
{
|
{
|
||||||
this.setupWindow = setupWindow;
|
|
||||||
|
|
||||||
this.buttonPositions = Engine.GetGUIObjectByName("bottomRightPanel").children;
|
this.buttonPositions = Engine.GetGUIObjectByName("bottomRightPanel").children;
|
||||||
|
|
||||||
this.cancelButton = Engine.GetGUIObjectByName("cancelButton");
|
this.cancelButton = Engine.GetGUIObjectByName("cancelButton");
|
||||||
this.cancelButton.caption = this.Caption;
|
this.cancelButton.caption = this.Caption;
|
||||||
this.cancelButton.tooltip = Engine.HasXmppClient() ? this.TooltipLobby : this.TooltipMenu;
|
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
|
class SetupWindow
|
||||||
{
|
{
|
||||||
constructor(initData, hotloadData)
|
constructor(initData, hotloadData, closePageCallback)
|
||||||
{
|
{
|
||||||
if (!g_Settings)
|
if (!g_Settings)
|
||||||
return;
|
return;
|
||||||
@@ -38,7 +38,7 @@ class SetupWindow
|
|||||||
const playerAssignmentsController =
|
const playerAssignmentsController =
|
||||||
new PlayerAssignmentsController(this, netMessages, isSavedGame);
|
new PlayerAssignmentsController(this, netMessages, isSavedGame);
|
||||||
const gameSettingsController = new GameSettingsController(this, netMessages,
|
const gameSettingsController = new GameSettingsController(this, netMessages,
|
||||||
playerAssignmentsController, mapCache, isSavedGame);
|
playerAssignmentsController, mapCache, closePageCallback, isSavedGame);
|
||||||
const readyController = new ReadyController(netMessages, gameSettingsController, playerAssignmentsController);
|
const readyController = new ReadyController(netMessages, gameSettingsController, playerAssignmentsController);
|
||||||
const lobbyGameRegistrationController = g_IsController && Engine.HasXmppClient() &&
|
const lobbyGameRegistrationController = g_IsController && Engine.HasXmppClient() &&
|
||||||
new LobbyGameRegistrationController(initData, this, netMessages, mapCache, playerAssignmentsController);
|
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
|
// These are the pages within the setup window that may use the controls defined above
|
||||||
this.pages = {};
|
this.pages = {};
|
||||||
for (const name in SetupWindowPages)
|
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);
|
netMessages.registerNetMessageHandler("netwarn", addNetworkWarning);
|
||||||
setTimeout(displayGamestateNotifications, 1000);
|
setTimeout(displayGamestateNotifications, 1000);
|
||||||
@@ -113,7 +116,7 @@ class SetupWindow
|
|||||||
updateTimers();
|
updateTimers();
|
||||||
}
|
}
|
||||||
|
|
||||||
closePage()
|
closePage(closePageCallback)
|
||||||
{
|
{
|
||||||
for (const handler of this.closePageHandlers)
|
for (const handler of this.closePageHandlers)
|
||||||
handler();
|
handler();
|
||||||
@@ -121,10 +124,22 @@ class SetupWindow
|
|||||||
Engine.DisconnectNetworkGame();
|
Engine.DisconnectNetworkGame();
|
||||||
|
|
||||||
if (this.backPage)
|
if (this.backPage)
|
||||||
Engine.SwitchGuiPage(this.backPage.page, this.backPage?.data);
|
{
|
||||||
else if (Engine.HasXmppClient())
|
closePageCallback({ [Engine.openRequest]: {
|
||||||
Engine.SwitchGuiPage("page_lobby.xml", { "dialog": false });
|
"page": this.backPage.page,
|
||||||
else
|
"argument": this.backPage?.data
|
||||||
Engine.SwitchGuiPage("page_pregame.xml");
|
} });
|
||||||
|
}
|
||||||
|
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)
|
function init(initData, hotloadData)
|
||||||
{
|
{
|
||||||
g_SetupWindow = new SetupWindow(initData, hotloadData);
|
return Promise.race([new Promise(closePageCallback =>
|
||||||
return g_IsNetworked ? g_SetupWindow.controls.netMessages.pollPendingMessages() :
|
{
|
||||||
new Promise(() => {});
|
g_SetupWindow = new SetupWindow(initData, hotloadData, closePageCallback);
|
||||||
|
}), ...(g_IsNetworked ? [g_SetupWindow.controls.netMessages.pollPendingMessages()] : [])]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getHotloadData()
|
function getHotloadData()
|
||||||
|
|||||||
Reference in New Issue
Block a user