Quit Engine by closing the root page

When the root page gets closed the engine quits instead or crashing.
The root pages are changed to use that mechanism to quit the engine.
This removes the need of `Engine.Exit` for the GUI.
This commit is contained in:
phosit
2024-10-28 21:34:20 +01:00
committed by phosit
parent 71f78eb2ce
commit 40762c257d
8 changed files with 20 additions and 18 deletions
@@ -85,6 +85,10 @@ function init(data, hotloadData)
initGUIButtons(data);
if (g_HasIncompatibleMods)
Engine.OpenChildPage("page_incompatible_mods.xml", {});
return new Promise(closePageCallback => {
Engine.GetGUIObjectByName("quitButton").onPress = closePageCallback;
});
}
function initMods()
@@ -190,7 +190,6 @@
<!-- BUTTONS -->
<object name="quitButton" type="button" style="ModernButtonRed" size="100%-932 100%-44 100%-752 100%-16">
<translatableAttribute id="caption">Quit</translatableAttribute>
<action on="Press">Engine.Exit();</action>
</object>
<object name="cancelButton" type="button" style="ModernButtonRed" size="100%-932 100%-44 100%-752 100%-16" hotkey="cancel">
@@ -4,8 +4,9 @@
*/
class MainMenuItemHandler
{
constructor(menuItems)
constructor(closePageCallback, menuItems)
{
this.closePageCallback = closePageCallback;
this.menuItems = menuItems;
this.lastTickTime = Date.now();
@@ -74,7 +75,7 @@ class MainMenuItemHandler
this.lastOpenItem = item;
if (item.onPress)
item.onPress();
item.onPress(this.closePageCallback);
else
this.openSubmenu(i);
}
@@ -287,7 +287,7 @@ var g_MainMenuItems = [
{
"caption": translate("Exit"),
"tooltip": translate("Exit the game."),
"onPress": async() => {
"onPress": async(closePageCallback) => {
const buttonIndex = await messageBox(
400, 200,
translate("Are you sure you want to quit 0 A.D.?"),
@@ -295,7 +295,7 @@ var g_MainMenuItems = [
[translate("No"), translate("Yes")]);
if (buttonIndex === 1)
Engine.Exit();
closePageCallback();
}
}
];
@@ -3,10 +3,11 @@
*/
class MainMenuPage
{
constructor(data, hotloadData, mainMenuItems, backgroundLayerData, projectInformation, communityButtons)
constructor(closePageCallback, data, hotloadData, mainMenuItems, backgroundLayerData,
projectInformation, communityButtons)
{
this.backgroundHandler = new BackgroundHandler(pickRandom(backgroundLayerData));
this.menuHandler = new MainMenuItemHandler(mainMenuItems);
this.menuHandler = new MainMenuItemHandler(closePageCallback, mainMenuItems);
this.splashScreenHandler = new SplashScreenHandler(data, hotloadData && hotloadData.splashScreenHandler);
new MusicHandler();
@@ -10,14 +10,16 @@ var g_MainMenuPage;
function init(data, hotloadData)
{
g_MainMenuPage =
new MainMenuPage(
return new Promise(closePageCallback => {
g_MainMenuPage = new MainMenuPage(
closePageCallback,
data,
hotloadData,
g_MainMenuItems,
g_BackgroundLayerData,
g_ProjectInformation,
g_CommunityButtons);
});
}
function getHotloadData()
+3 -1
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2024 Wildfire Games.
/* Copyright (C) 2025 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -431,6 +431,8 @@ static void Frame(RL::Interface* rlInterface)
g_NetClient->Poll();
g_GUI->TickObjects();
if (g_GUI->GetPageCount() == 0)
QuitEngine();
if (rlInterface)
rlInterface->TryApplyMessage();
+1 -8
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2022 Wildfire Games.
/* Copyright (C) 2025 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -34,16 +34,10 @@
#include "scriptinterface/FunctionWrapper.h"
#include "tools/atlas/GameInterface/GameLoop.h"
extern void QuitEngine();
extern void StartAtlas();
namespace JSI_Main
{
void QuitEngine()
{
::QuitEngine();
}
void StartAtlas()
{
::StartAtlas();
@@ -126,7 +120,6 @@ std::string CalculateMD5(const std::string& input)
void RegisterScriptFunctions(const ScriptRequest& rq)
{
ScriptFunction::Register<&QuitEngine>(rq, "Exit");
ScriptFunction::Register<&StartAtlas>(rq, "RestartInAtlas");
ScriptFunction::Register<&AtlasIsAvailable>(rq, "AtlasIsAvailable");
ScriptFunction::Register<&IsAtlasRunning>(rq, "IsAtlasRunning");