Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/gui/GUIManager.h
/* Copyright (C) 2019 Wildfire Games. | /* Copyright (C) 2020 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | public: | ||||
void SwitchPage(const CStrW& name, ScriptInterface* srcScriptInterface, JS::HandleValue initData); | void SwitchPage(const CStrW& name, ScriptInterface* srcScriptInterface, JS::HandleValue initData); | ||||
/** | /** | ||||
* Load a new GUI page and make it active. All current pages will be retained, | * Load a new GUI page and make it active. All current pages will be retained, | ||||
* and will still be drawn and receive tick events, but will not receive | * and will still be drawn and receive tick events, but will not receive | ||||
* user inputs. | * user inputs. | ||||
* If given, the callbackHandler function will be executed once this page is closed. | * If given, the callbackHandler function will be executed once this page is closed. | ||||
*/ | */ | ||||
void PushPage(const CStrW& pageName, shared_ptr<ScriptInterface::StructuredClone> initData, JS::HandleValue callbackFunc); | void PushPage(const CStrW& pageName, ScriptInterface::StructuredClone initData, JS::HandleValue callbackFunc); | ||||
/** | /** | ||||
* Unload the currently active GUI page, and make the previous page active. | * Unload the currently active GUI page, and make the previous page active. | ||||
* (There must be at least two pages when you call this.) | * (There must be at least two pages when you call this.) | ||||
*/ | */ | ||||
void PopPage(shared_ptr<ScriptInterface::StructuredClone> args); | void PopPage(ScriptInterface::StructuredClone args); | ||||
/** | /** | ||||
* Called when a file has been modified, to hotload changes. | * Called when a file has been modified, to hotload changes. | ||||
*/ | */ | ||||
Status ReloadChangedFile(const VfsPath& path); | Status ReloadChangedFile(const VfsPath& path); | ||||
/** | /** | ||||
* Called when we should reload all pages (e.g. translation hotloading update). | * Called when we should reload all pages (e.g. translation hotloading update). | ||||
Show All 40 Lines | private: | ||||
struct SGUIPage | struct SGUIPage | ||||
{ | { | ||||
// COPYABLE, because event handlers may invalidate page stack iterators by open or close pages, | // COPYABLE, because event handlers may invalidate page stack iterators by open or close pages, | ||||
// and event handlers need to be called for the entire stack. | // and event handlers need to be called for the entire stack. | ||||
/** | /** | ||||
* Initializes the data that will be used to create the CGUI page one or multiple times (hotloading). | * Initializes the data that will be used to create the CGUI page one or multiple times (hotloading). | ||||
*/ | */ | ||||
SGUIPage(const CStrW& pageName, const shared_ptr<ScriptInterface::StructuredClone> initData); | SGUIPage(const CStrW& pageName, const ScriptInterface::StructuredClone initData); | ||||
/** | /** | ||||
* Create the CGUI with it's own ScriptInterface. Deletes the previous CGUI if it existed. | * Create the CGUI with it's own ScriptInterface. Deletes the previous CGUI if it existed. | ||||
*/ | */ | ||||
void LoadPage(shared_ptr<ScriptContext> scriptContext); | void LoadPage(shared_ptr<ScriptContext> scriptContext); | ||||
/** | /** | ||||
* Sets the callback handler when a new page is opened that will be performed when the page is closed. | * Sets the callback handler when a new page is opened that will be performed when the page is closed. | ||||
*/ | */ | ||||
void SetCallbackFunction(ScriptInterface& scriptInterface, JS::HandleValue callbackFunc); | void SetCallbackFunction(ScriptInterface& scriptInterface, JS::HandleValue callbackFunc); | ||||
/** | /** | ||||
* Execute the stored callback function with the given arguments. | * Execute the stored callback function with the given arguments. | ||||
*/ | */ | ||||
void PerformCallbackFunction(shared_ptr<ScriptInterface::StructuredClone> args); | void PerformCallbackFunction(ScriptInterface::StructuredClone args); | ||||
CStrW name; | CStrW name; | ||||
std::unordered_set<VfsPath> inputs; // for hotloading | std::unordered_set<VfsPath> inputs; // for hotloading | ||||
shared_ptr<ScriptInterface::StructuredClone> initData; // data to be passed to the init() function | ScriptInterface::StructuredClone initData; // data to be passed to the init() function | ||||
shared_ptr<CGUI> gui; // the actual GUI page | shared_ptr<CGUI> gui; // the actual GUI page | ||||
/** | /** | ||||
* Function executed by this parent GUI page when the child GUI page it pushed is popped. | * Function executed by this parent GUI page when the child GUI page it pushed is popped. | ||||
* Notice that storing it in the SGUIPage instead of CGUI means that it will survive the hotloading CGUI reset. | * Notice that storing it in the SGUIPage instead of CGUI means that it will survive the hotloading CGUI reset. | ||||
*/ | */ | ||||
shared_ptr<JS::PersistentRootedValue> callbackFunction; | shared_ptr<JS::PersistentRootedValue> callbackFunction; | ||||
}; | }; | ||||
Show All 19 Lines |
Wildfire Games · Phabricator