Remove Engine.SwitchGuiPage from prelobby

This commit is contained in:
phosit 2025-04-23 15:52:31 +02:00
parent c1a50c7012
commit 4ff3abf203
No known key found for this signature in database
GPG key ID: C9430B600671C268
7 changed files with 42 additions and 25 deletions

View file

@ -222,10 +222,13 @@ export const mainMenuItems = [
(Engine.StartXmppClient ? "" : translate("Launch the multiplayer lobby. \\[DISABLED BY BUILD]")),
"enabled": () => !!Engine.StartXmppClient,
"hotkey": "lobby",
"onPress": () =>
"onPress": async(closePageCallback) =>
{
if (Engine.StartXmppClient)
Engine.OpenChildPage("page_prelobby_entrance.xml");
if (!Engine.StartXmppClient)
return;
const ret = await Engine.OpenChildPage("page_prelobby_entrance.xml");
if (ret)
closePageCallback({ [Engine.openRequest]: ret });
}
},
{

View file

@ -1,17 +1,30 @@
function init()
{
if (Engine.ConfigDB_GetValue("user", "lobby.login"))
loginButton();
return Promise.race([loginButton(), cancelHandler()]);
}
function cancelHandler()
{
return new Promise(closePageCallback =>
{
Engine.GetGUIObjectByName("cancel").onPress = closePageCallback;
});
}
function loginButton()
async function loginButton()
{
Engine.OpenChildPage("page_prelobby_login.xml");
let skipEntrance = Engine.ConfigDB_GetValue("user", "lobby.login");
while (true)
{
if (!skipEntrance)
await new Promise(resolve => { Engine.GetGUIObjectByName("login").onPress = resolve; });
const ret = await Engine.OpenChildPage("page_prelobby_login.xml");
if (ret)
return ret;
skipEntrance = false;
}
}
async function registerButton()

View file

@ -21,9 +21,8 @@
<action on="Press">registerButton();</action>
</object>
<object type="button" size="50%-140 50 50%+140 78" style="ModernButtonRed">
<object name="login" type="button" size="50%-140 50 50%+140 78" style="ModernButtonRed">
<translatableAttribute id="caption">Login to an existing account</translatableAttribute>
<action on="Press">loginButton();</action>
</object>
<object name="cancel" type="button" size="18 100%-46 50%-5 100%-18" style="ModernButtonRed" hotkey="cancel">

View file

@ -1,7 +1,5 @@
function init()
{
g_LobbyMessages.connected = onLogin;
Engine.GetGUIObjectByName("continue").caption = translate("Connect");
// Shorten the displayed password for visual reasons only
@ -14,7 +12,7 @@ function init()
updateFeedback();
return cancelButton();
return Promise.race([ onLoggedin(), cancelButton() ]);
}
function updateFeedback()
@ -42,15 +40,19 @@ function continueButton()
Engine.ConnectXmppClient();
}
/**
* The data from Engine.SendGetBoardList() is used for the leaderboard, but also for autocompletion in the profile player search field.
*/
function onLogin(message)
async function onLoggedin()
{
await new Promise(resolve => { g_LobbyMessages.connected = resolve; });
saveCredentials();
Engine.SwitchGuiPage("page_lobby.xml", {
"dialog": false
});
// The data from Engine.SendGetBoardList() is used for the leaderboard, but also for
// autocompletion in the profile player search field.
Engine.SendGetBoardList();
return {
"page": "page_lobby.xml",
"argument": {
"dialog": false
}
};
}

View file

@ -25,12 +25,12 @@ class CivInfoPage extends ReferencePage
switchToStructreePage()
{
this.closePageCallback({ [Engine.openRequest] : {
this.closePageCallback({ [Engine.openRequest]: {
"page": "page_structree.xml",
"argument": {
"civ": this.activeCiv
}
}});
} });
}
closePage()

View file

@ -12,12 +12,12 @@ class CivInfoButton
onPress()
{
this.parentPage.closePageCallback({ [Engine.openRequest] : {
this.parentPage.closePageCallback({ [Engine.openRequest]: {
"page": "page_civinfo.xml",
"argument": {
"civ": this.parentPage.activeCiv
}
}});
} });
}
}

View file

@ -12,12 +12,12 @@ class StructreeButton
onPress()
{
this.parentPage.closePageCallback({ [Engine.openRequest] : {
this.parentPage.closePageCallback({ [Engine.openRequest]: {
"page": "page_structree.xml",
"argument": {
"civ": this.parentPage.activeCiv
}
}});
} });
}
}