Index: ps/trunk/source/gui/CGUI.cpp =================================================================== --- ps/trunk/source/gui/CGUI.cpp +++ ps/trunk/source/gui/CGUI.cpp @@ -282,6 +282,8 @@ : m_MouseButtons(0), m_FocusedObject(NULL), m_InternalNameNumber(0) { m_ScriptInterface.reset(new ScriptInterface("Engine", "GUIPage", runtime)); + m_ScriptInterface->SetCallbackData(this); + GuiScriptingInit(*m_ScriptInterface); m_ScriptInterface->LoadGlobalScripts(); m_BaseObject = new CGUIDummyObject; Index: ps/trunk/source/gui/GUIManager.h =================================================================== --- ps/trunk/source/gui/GUIManager.h +++ ps/trunk/source/gui/GUIManager.h @@ -108,11 +108,6 @@ bool GetPreDefinedColor(const CStr& name, CColor& output) const; /** - * See CGUI::FindObjectByName; applies to the currently active page. - */ - IGUIObject* FindObjectByName(const CStr& name) const; - - /** * See CGUI::SendEventToAll; applies to the currently active page. */ void SendEventToAll(const CStr& eventName) const; @@ -166,7 +161,6 @@ shared_ptr top() const; - shared_ptr m_CurrentGUI; // used to latch state during TickObjects/LoadPage (this is kind of ugly) shared_ptr m_ScriptRuntime; shared_ptr m_ScriptInterface; Index: ps/trunk/source/gui/GUIManager.cpp =================================================================== --- ps/trunk/source/gui/GUIManager.cpp +++ ps/trunk/source/gui/GUIManager.cpp @@ -231,10 +231,6 @@ } } - // Remember this GUI page, in case the scripts call FindObjectByName - shared_ptr oldGUI = m_CurrentGUI; - m_CurrentGUI = page.gui; - page.gui->SendEventToAll("load"); shared_ptr scriptInterface = page.gui->GetScriptInterface(); @@ -254,8 +250,6 @@ if (scriptInterface->HasProperty(global, "init") && !scriptInterface->CallFunctionVoid(global, "init", initDataVal, hotloadDataVal)) LOGERROR("GUI page '%s': Failed to call init() function", utf8_from_wstring(page.name)); - - m_CurrentGUI = oldGUI; } Status CGUIManager::ReloadChangedFile(const VfsPath& path) @@ -358,16 +352,6 @@ return top()->GetPreDefinedColor(name, output); } -IGUIObject* CGUIManager::FindObjectByName(const CStr& name) const -{ - // This can be called from scripts run by TickObjects, - // and we want to return it the same GUI page as is being ticked - if (m_CurrentGUI) - return m_CurrentGUI->FindObjectByName(name); - else - return top()->FindObjectByName(name); -} - void CGUIManager::SendEventToAll(const CStr& eventName) const { top()->SendEventToAll(eventName); @@ -385,11 +369,7 @@ PageStackType pageStack = m_PageStack; for (const SGUIPage& p : pageStack) - { - m_CurrentGUI = p.gui; p.gui->TickObjects(); - } - m_CurrentGUI.reset(); } void CGUIManager::Draw() @@ -407,11 +387,9 @@ for (const SGUIPage& p : pageStack) { - m_CurrentGUI = p.gui; p.gui->UpdateResolution(); p.gui->SendEventToAll("WindowResized"); } - m_CurrentGUI.reset(); } bool CGUIManager::TemplateExists(const std::string& templateName) const Index: ps/trunk/source/gui/scripting/JSInterface_GUIManager.cpp =================================================================== --- ps/trunk/source/gui/scripting/JSInterface_GUIManager.cpp +++ ps/trunk/source/gui/scripting/JSInterface_GUIManager.cpp @@ -19,6 +19,7 @@ #include "JSInterface_GUIManager.h" +#include "gui/CGUI.h" #include "gui/GUIManager.h" #include "gui/IGUIObject.h" #include "ps/GameSetup/Config.h" @@ -46,9 +47,11 @@ g_GUI->PopPageCB(pCxPrivate->pScriptInterface->WriteStructuredClone(args)); } -JS::Value JSI_GUIManager::GetGUIObjectByName(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::string& name) +JS::Value JSI_GUIManager::GetGUIObjectByName(ScriptInterface::CxPrivate* pCxPrivate, const std::string& name) { - IGUIObject* guiObj = g_GUI->FindObjectByName(name); + CGUI* guiPage = static_cast(pCxPrivate->pCBData); + + IGUIObject* guiObj = guiPage->FindObjectByName(name); if (!guiObj) return JS::UndefinedValue();