Remove Engine.SwitchGuiPage from locale

This commit is contained in:
phosit 2025-04-24 16:57:15 +02:00
parent 340a4d64ca
commit 3126a249d2
No known key found for this signature in database
GPG key ID: C9430B600671C268
3 changed files with 26 additions and 13 deletions

View file

@ -19,22 +19,31 @@ function init()
var localeText = Engine.GetGUIObjectByName("localeText");
localeText.caption = currentLocale;
return new Promise(closePageCallback =>
const cancel = new Promise(closePageCallback =>
{
Engine.GetGUIObjectByName("cancelButton").onPress = closePageCallback;
Engine.GetGUIObjectByName("cancelButton").onPress = closePageCallback.bind(undefined, false);
});
return Promise.race([ cancel, applySelectedLocale() ]);
}
function applySelectedLocale()
{
var localeText = Engine.GetGUIObjectByName("localeText");
if (!Engine.SaveLocale(localeText.caption))
return new Promise(closePageCallback =>
{
warn("Selected locale could not be saved in the configuration!");
return;
}
Engine.ReevaluateCurrentLocaleAndReload();
Engine.SwitchGuiPage("page_pregame.xml");
Engine.GetGUIObjectByName("apply").onPress = () =>
{
var localeText = Engine.GetGUIObjectByName("localeText");
if (!Engine.SaveLocale(localeText.caption))
{
warn("Selected locale could not be saved in the configuration!");
return;
}
Engine.ReevaluateCurrentLocaleAndReload();
closePageCallback(true);
};
});
}
function languageSelectionChanged()

View file

@ -41,9 +41,8 @@
<action on="Press">openAdvancedMenu();</action>
</object>
<object type="button" style="ModernButtonRed" size="66%+5 100%-60 100% 100%-32">
<object name="apply" type="button" style="ModernButtonRed" size="66%+5 100%-60 100% 100%-32">
<translatableAttribute id="caption">Accept</translatableAttribute>
<action on="Press">applySelectedLocale();</action>
</object>
</object>
</object>

View file

@ -312,9 +312,14 @@ export const mainMenuItems = [
{
"caption": translate("Language"),
"tooltip": translate("Choose the language of the game."),
"onPress": () =>
"onPress": async(closePageCallback) =>
{
Engine.OpenChildPage("page_locale.xml");
if (!await Engine.OpenChildPage("page_locale.xml"))
return;
closePageCallback({ [Engine.openRequest]: {
"page": "page_pregame.xml"
} });
}
},
{