Remove Engine.SwitchGuiPage from gamesetup_mp

This commit is contained in:
phosit 2025-04-23 16:23:20 +02:00
parent 4ff3abf203
commit 5b5a7f9dc8
No known key found for this signature in database
GPG key ID: C9430B600671C268
4 changed files with 63 additions and 38 deletions

View file

@ -50,7 +50,7 @@ async function waitOnEvent(loadSavedGame, joinFromLobby)
if (continueResult === cancelTag)
{
if (cancelSetup())
return;
return undefined;
continue;
}
try
@ -60,7 +60,7 @@ async function waitOnEvent(loadSavedGame, joinFromLobby)
catch(e)
{
if (cancelSetup())
return;
return undefined;
continue;
}
}
@ -70,11 +70,16 @@ async function waitOnEvent(loadSavedGame, joinFromLobby)
{
Engine.GetGUIObjectByName("multiplayerPages").onTick = resolve;
}));
if (tickResult === cancelTag || await onTick(loadSavedGame))
if (tickResult === cancelTag)
break;
const result = await onTick(loadSavedGame);
if (typeof result === "object")
return result;
if (result)
break;
}
if (cancelSetup())
return;
return undefined;
}
}
@ -100,7 +105,7 @@ async function init(attribs)
Engine.GetGUIObjectByName("confirmPasswordButton").onPress = resolve;
}));
if (passwordResult === cancelTag)
return;
return undefined;
}
try
{
@ -111,7 +116,7 @@ async function init(attribs)
catch(e)
{
if (cancelSetup())
return;
return undefined;
}
break;
}
@ -134,7 +139,7 @@ async function init(attribs)
break;
}
await waitOnEvent(attribs.loadSavedGame,
return waitOnEvent(attribs.loadSavedGame,
attribs.multiplayerGameType === "join" && Engine.HasXmppClient());
}
@ -293,14 +298,14 @@ async function pollAndHandleNetworkClient(loadSavedGame)
break;
case "start":
Engine.SwitchGuiPage("page_loading.xml", {
"attribs": message.initAttributes,
"isRejoining": g_IsRejoining,
"playerAssignments": g_PlayerAssignments
});
// Process further pending netmessages in the session page
return false;
return {
"page": "page_loading.xml",
"argument": {
"attribs": message.initAttributes,
"isRejoining": g_IsRejoining,
"playerAssignments": g_PlayerAssignments
}
};
case "chat":
break;
@ -384,12 +389,14 @@ async function handleAuthenticated(message, loadSavedGame)
return true;
}
Engine.SwitchGuiPage("page_gamesetup.xml", {
"savedGame": savegameID, // Undefined or the savegame ID
"serverName": g_ServerName,
"hasPassword": g_ServerHasPassword
});
return false; // don't process any more messages - leave them for the game GUI loop
return {
"page": "page_gamesetup.xml",
"argument": {
"savedGame": savegameID, // Undefined or the savegame ID
"serverName": g_ServerName,
"hasPassword": g_ServerHasPassword
}
};
}
function switchSetupPage(newPage)

View file

@ -3,10 +3,10 @@
*/
class HostButton
{
constructor(dialog, xmppMessages, button, loadSavedGame)
constructor(closePageCallback, dialog, xmppMessages, button, loadSavedGame)
{
this.hostButton = button;
this.hostButton.onPress = this.onPress.bind(this, loadSavedGame);
this.hostButton.onPress = this.onPress.bind(this, closePageCallback, loadSavedGame);
this.hostButton.hidden = dialog;
const onConnectionStatusChange = this.onConnectionStatusChange.bind(this);
@ -20,13 +20,16 @@ class HostButton
this.hostButton.enabled = Engine.IsXmppClientConnected();
}
onPress(loadSavedGame)
async onPress(closePageCallback, loadSavedGame)
{
Engine.OpenChildPage("page_gamesetup_mp.xml", {
const ret = await Engine.OpenChildPage("page_gamesetup_mp.xml", {
"loadSavedGame": loadSavedGame,
"multiplayerGameType": "host",
"name": g_Nickname,
"rating": Engine.LobbyGetPlayerRating(g_Nickname)
});
if (ret !== undefined)
closePageCallback({ [Engine.openRequest]: ret });
}
}

View file

@ -19,9 +19,9 @@ class LobbyPage
"buddyButton": buddyButton,
"accountSettingsButton": accountSettingsButton,
"joinButton": new JoinButton(dialog, gameList),
"hostButton": new HostButton(dialog, xmppMessages,
"hostButton": new HostButton(closePageCallback, dialog, xmppMessages,
Engine.GetGUIObjectByName("hostButton"), false),
"hostSavedGameButton": new HostButton(dialog, xmppMessages,
"hostSavedGameButton": new HostButton(closePageCallback, dialog, xmppMessages,
Engine.GetGUIObjectByName("hostSavedGameButton"), true),
"leaderboardButton": new LeaderboardButton(xmppMessages, leaderboardPage),
"profileButton": new ProfileButton(xmppMessages, profilePage),

View file

@ -235,25 +235,40 @@ export const mainMenuItems = [
// Translation: Join a game by specifying the host's IP address.
"caption": translate("Connect by IP"),
"tooltip": translate("Joining an existing multiplayer game at a given IP address."),
"onPress": Engine.OpenChildPage.bind(null, "page_gamesetup_mp.xml", {
"multiplayerGameType": "join"
})
"onPress": async(closePageCallback) =>
{
const ret = await Engine.OpenChildPage("page_gamesetup_mp.xml", {
"multiplayerGameType": "join"
});
if (ret !== undefined)
closePageCallback({ [Engine.openRequest]: ret });
}
},
{
"caption": translate("Host New Game"),
"tooltip": translate("Host a new multiplayer game. Other players can connect directly to you via your IP address."),
"onPress": Engine.OpenChildPage.bind(null, "page_gamesetup_mp.xml", {
"multiplayerGameType": "host",
"loadSavedGame": false
})
"onPress": async(closePageCallback) =>
{
const ret = await Engine.OpenChildPage("page_gamesetup_mp.xml", {
"multiplayerGameType": "host",
"loadSavedGame": false
});
if (ret !== undefined)
closePageCallback({ [Engine.openRequest]: ret });
}
},
{
"caption": translate("Host Saved Game"),
"tooltip": translate("Continue playing a game from a savegame."),
"onPress": Engine.OpenChildPage.bind(null, "page_gamesetup_mp.xml", {
"multiplayerGameType": "host",
"loadSavedGame": true
})
"onPress": async(closePageCallback) =>
{
const ret = await Engine.OpenChildPage("page_gamesetup_mp.xml", {
"multiplayerGameType": "host",
"loadSavedGame": true
});
if (ret !== undefined)
closePageCallback({ [Engine.openRequest]: ret });
}
},
{
"caption": translate("Replays"),