Changeset View
Standalone View
source/gui/GUIManager.h
Show First 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | public: | ||||
* Load a new GUI page and make it active. All current pages will be destroyed. | * Load a new GUI page and make it active. All current pages will be destroyed. | ||||
*/ | */ | ||||
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. | |||||
*/ | */ | ||||
void PushPage(const CStrW& pageName, shared_ptr<ScriptInterface::StructuredClone> initData); | void PushPage(const CStrW& pageName, ScriptInterface* srcScriptInterface, shared_ptr<ScriptInterface::StructuredClone> initData, JS::HandleValue callbackFunction); | ||||
/** | /** | ||||
* 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(); | void PopPage(shared_ptr<ScriptInterface::StructuredClone> args); | ||||
void PopPageCB(shared_ptr<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); | ||||
/** | /** | ||||
* Sets the default mouse pointer. | * Sets the default mouse pointer. | ||||
*/ | */ | ||||
void ResetCursor(); | void ResetCursor(); | ||||
/** | /** | ||||
* Called when we should reload all pages (e.g. translation hotloading update). | * Called when we should reload all pages (e.g. translation hotloading update). | ||||
*/ | */ | ||||
Status ReloadAllPages(); | Status ReloadAllPages(); | ||||
/** | /** | ||||
* Pass input events to the currently active GUI page. | * Pass input events to the currently active GUI page. | ||||
*/ | */ | ||||
InReaction HandleEvent(const SDL_Event_* ev); | InReaction HandleEvent(const SDL_Event_* ev); | ||||
/** | /** | ||||
* See CGUI::GetPreDefinedColor; applies to the currently active page. | |||||
*/ | |||||
bool GetPreDefinedColor(const CStr& name, CColor& output) const; | |||||
/** | |||||
* See CGUI::SendEventToAll; applies to the currently active page. | * See CGUI::SendEventToAll; applies to the currently active page. | ||||
*/ | */ | ||||
void SendEventToAll(const CStr& eventName) const; | void SendEventToAll(const CStr& eventName) const; | ||||
void SendEventToAll(const CStr& eventName, JS::HandleValueArray paramData) const; | void SendEventToAll(const CStr& eventName, JS::HandleValueArray paramData) const; | ||||
/** | /** | ||||
* See CGUI::TickObjects; applies to @em all loaded pages. | * See CGUI::TickObjects; applies to @em all loaded pages. | ||||
*/ | */ | ||||
Show All 21 Lines | public: | ||||
*/ | */ | ||||
bool TemplateExists(const std::string& templateName) const; | bool TemplateExists(const std::string& templateName) const; | ||||
/** | /** | ||||
* Retrieve the requested template, used for displaying faction specificities. | * Retrieve the requested template, used for displaying faction specificities. | ||||
*/ | */ | ||||
const CParamNode& GetTemplate(const std::string& templateName); | const CParamNode& GetTemplate(const std::string& templateName); | ||||
private: | class SGUIPage | ||||
struct SGUIPage | |||||
{ | { | ||||
public: | |||||
SGUIPage(const CStrW& pageName, const shared_ptr<ScriptInterface::StructuredClone> initData, shared_ptr<ScriptRuntime> scriptRuntime); | |||||
void LoadPage(shared_ptr<ScriptRuntime> scriptRuntime); | |||||
CStrW name; | CStrW name; | ||||
boost::unordered_set<VfsPath> inputs; // for hotloading | boost::unordered_set<VfsPath> inputs; // for hotloading | ||||
shared_ptr<ScriptInterface::StructuredClone> initData; // data to be passed to the init() function | shared_ptr<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 | ||||
vladislavbelov: Does it mean that function can't be changed then? Because before the patch someone could change… | |||||
Done Inline ActionsRead the patch again to see how callbackPageName was used previously. elexis: Read the patch again to see how `callbackPageName` was used previously. | |||||
Not Done Inline ActionsI didn't ask how it's used in JS. I'm worrying about flexibility/constraints on the C++ part. Before the patch someone may change a callback after the push. vladislavbelov: I didn't ask how it's used in JS. I'm worrying about flexibility/constraints on the C++ part. | |||||
Done Inline ActionsThe variable was never used, but the data was stored in initData without this patch. elexis: The variable was never used, but the data was stored in `initData` without this patch.
To me it… | |||||
Not Done Inline ActionsI'm guessing if one does Thus I think this callback can't be changed from JS code once passed wraitii: I'm guessing if one does
`Engine.PushGUiPage({}, SomeFunction)` then does 'someFunction = () =>… | |||||
Done Inline ActionsEngine.PushGUiPage(..., candy ? candyHandler : whateverHandler) and seems much cleaner to me than changing it inretrospect, because it means the reader discovers the callback functions when he first reads the line, rather than being misled to believe that the whateverHandler is going to be the one when it's somewhere else in the code replaced with candyHandler. elexis: `Engine.PushGUiPage(..., candy ? candyHandler : whateverHandler)` and seems much cleaner to me… | |||||
Not Done Inline ActionsOh I completely agree I was just trying to clarify things. wraitii: Oh I completely agree I was just trying to clarify things. | |||||
// Function executed by the parent GUI page when this GUI page is closed | |||||
JS::PersistentRootedValue callbackFunction; | |||||
elexisAuthorUnsubmitted Done Inline ActionsNotice that SGUIPage is copied around for fun & nonprofit each tick. Using shared_ptr in the updated version. Notice that storing it in the SGUIPage instead of CGUI means that it will survive the hotloading gui reset. elexis: Notice that `SGUIPage` is copied around for fun & nonprofit each tick. Using shared_ptr in the… | |||||
}; | }; | ||||
void LoadPage(SGUIPage& page); | private: | ||||
shared_ptr<CGUI> top() const; | shared_ptr<CGUI> top() const; | ||||
shared_ptr<ScriptRuntime> m_ScriptRuntime; | shared_ptr<ScriptRuntime> m_ScriptRuntime; | ||||
shared_ptr<ScriptInterface> m_ScriptInterface; | shared_ptr<ScriptInterface> m_ScriptInterface; | ||||
typedef std::vector<SGUIPage> PageStackType; | typedef std::vector<SGUIPage> PageStackType; | ||||
PageStackType m_PageStack; | PageStackType m_PageStack; | ||||
Show All 9 Lines |
Does it mean that function can't be changed then? Because before the patch someone could change the function.