Index: binaries/data/mods/public/gui/pregame/MainMenuPage.js =================================================================== --- binaries/data/mods/public/gui/pregame/MainMenuPage.js +++ binaries/data/mods/public/gui/pregame/MainMenuPage.js @@ -9,6 +9,46 @@ this.menuHandler = new MainMenuItemHandler(mainMenuItems); this.splashScreenHandler = new SplashScreenHandler(data, hotloadData && hotloadData.splashScreenHandler); + let toto = Engine.GetGUIObjectByName("mainMenuPage"); + let doText = (caption, size) => ({ + "@type": "text", + "@size": size, + "@style": "ModernLabelText", + "@caption": caption, + }); + let added = toto.createChild({ + "@type": "image", + "@size": "200 200 500 500", + "@style": "ModernDialog", + "@z": 200, + "object": [ + doText("turlututu", "0 0 200 200"), + { + "@type": "text", + "@size": "0 200 200 400", + "@style": "ModernLabelText", + "@caption": "ChapoPointu", + "object": { + "@type": "image", + "@size": "600 300 100% 600+40", + "@style": "ModernDialog", + "@z": 250, + } + }] + }); + added.deleteChild(added.children[0].name); + + toto.createChild({ + "script": { + "@file": "not_a_file.js", + }, + }); + + + toto.createChild({ + "script": "warn('Hey you')", + }); + new MusicHandler(); new ProjectInformationHandler(projectInformation); new CommunityButtonHandler(communityButtons); Index: source/gui/CGUI.h =================================================================== --- source/gui/CGUI.h +++ source/gui/CGUI.h @@ -43,6 +43,7 @@ class CGUISpriteInstance; class CGUISprite; +class CParamNode; class IGUIObject; struct SGUIImageEffects; struct SGUIScrollBarStyle; @@ -251,6 +252,18 @@ shared_ptr GetScriptInterface() { return m_ScriptInterface; }; + /** + * The CGUI creates the object and adds it as a child to parent. + * To the created object, this is the same as being created on page open (same events, etc.) + */ + IGUIObject* CreateChildFromParamNode(const CParamNode& paramNode, IGUIObject* parent, std::vector>& nameSubst, u32 depth); + + /** + * Detach the object from its parent and delete it. + * The object must have a parent - use PopPage to delete the root page object. + */ + void DetachAndDeleteChild(IGUIObject* child); + private: /** * The CGUI takes ownership of the child object and links the parent with the child. @@ -349,16 +362,12 @@ // Read Roots /** - * Reads in the root element \ (the DOMElement). + * Reads in the "objects" root element * - * @param Element The Xeromyces object that represents - * the objects-tag. - * @param pFile The Xeromyces object for the file being read - * @param Paths Collects the set of all XML/JS files that are loaded - * - * @see LoadXmlFile() + * @param paramNode input data. + * @param Paths Collects the set of all files that are loaded */ - void Xeromyces_ReadRootObjects(XMBElement Element, CXeromyces* pFile, std::unordered_set& Paths); + void ReadRootObjects(const CParamNode& paramNode, std::unordered_set& Paths); /** * Reads in the root element \ (the DOMElement). @@ -417,7 +426,7 @@ * * @see LoadXmlFile() */ - void Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObject* pParent, std::vector >& NameSubst, std::unordered_set& Paths, u32 nesting_depth); + IGUIObject* ReadObject(const CParamNode& paramNode, IGUIObject* pParent, std::vector >& NameSubst, std::unordered_set& Paths, u32 nesting_depth); /** * Reads in the element \, which repeats its child \s @@ -425,7 +434,7 @@ * 'var' enclosed in square brackets) in its descendants' names with "[0]", * "[1]", etc. */ - void Xeromyces_ReadRepeat(XMBElement Element, CXeromyces* pFile, IGUIObject* pParent, std::vector >& NameSubst, std::unordered_set& Paths, u32 nesting_depth); + void ReadRepeat(const CParamNode& paramNode, IGUIObject* pParent, std::vector >& NameSubst, std::unordered_set& Paths, u32 nesting_depth); /** * Reads in the element \ (the XMBElement) and executes @@ -438,7 +447,7 @@ * * @see LoadXmlFile() */ - void Xeromyces_ReadScript(XMBElement Element, CXeromyces* pFile, std::unordered_set& Paths); + void ReadScript(const CParamNode& paramNode, std::unordered_set& Paths); /** * Reads in the element \ (the XMBElement) and stores the Index: source/gui/CGUI.cpp =================================================================== --- source/gui/CGUI.cpp +++ source/gui/CGUI.cpp @@ -41,6 +41,7 @@ #include "renderer/Renderer.h" #include "scriptinterface/ScriptContext.h" #include "scriptinterface/ScriptInterface.h" +#include "simulation2/system/ParamNode.h" #include #include @@ -331,6 +332,36 @@ return (*it->second)(*this); } + +IGUIObject* CGUI::CreateChildFromParamNode(const CParamNode& paramNode, IGUIObject* parent, std::vector>& nameSubst, u32 depth) +{ + std::unordered_set paths; + IGUIObject* child = ReadObject(paramNode, parent, nameSubst, paths, depth); + if (!child) + return nullptr; + + child->RecurseObject(nullptr, &IGUIObject::UpdateCachedSize); + SGUIMessage msg(GUIM_LOAD); + child->RecurseObject(nullptr, &IGUIObject::HandleMessage, msg); + child->ScriptEvent(EventNameLoad); + + return child; +} + +void CGUI::DetachAndDeleteChild(IGUIObject* child) +{ + if (!child) + return; + if (!child->m_pParent) + { + LOGERROR("Cannot delete the root object of a page"); + return; + } + child->m_pParent->RemoveChild(*child); + m_pAllObjects.erase(child->m_Name); + delete child; +} + bool CGUI::AddObject(IGUIObject& parent, IGUIObject& child) { if (child.m_Name.empty()) @@ -491,16 +522,19 @@ if (XeroFile.Load(g_VFS, Filename, "gui") != PSRETURN_OK) return; + CParamNode paramNode; + CParamNode::LoadXML(paramNode, XeroFile); + XMBElement node = XeroFile.GetRoot(); CStr root_name(XeroFile.GetElementString(node.GetNodeName())); - if (root_name == "objects") - Xeromyces_ReadRootObjects(node, &XeroFile, Paths); - else if (root_name == "sprites") + if (paramNode.GetChild("objects").IsOk()) + ReadRootObjects(paramNode.GetChild("objects"), Paths); + else if (paramNode.GetChild("sprites").IsOk()) Xeromyces_ReadRootSprites(node, &XeroFile); - else if (root_name == "styles") + else if (paramNode.GetChild("styles").IsOk()) Xeromyces_ReadRootStyles(node, &XeroFile); - else if (root_name == "setup") + else if (paramNode.GetChild("setup").IsOk()) Xeromyces_ReadRootSetup(node, &XeroFile); else LOGERROR("CGUI::LoadXmlFile encountered an unknown XML root node type: %s", root_name.c_str()); @@ -520,22 +554,23 @@ // XML Reading Xeromyces Specific Sub-Routines //=================================================================== -void CGUI::Xeromyces_ReadRootObjects(XMBElement Element, CXeromyces* pFile, std::unordered_set& Paths) +void CGUI::ReadRootObjects(const CParamNode& paramNode, std::unordered_set& Paths) { - int el_script = pFile->GetElementID("script"); + std::vector> subst; - std::vector > subst; - - // Iterate main children - // they should all be or