Remove workaround in GetGUIObjectByName
f0d9806b3f
added a problem: Engine.GetGuiObjectByName is unaware of the caller GUI page. So GUI pages in the background that still run the onTick and other event code tried to look on the topmost GUI page, rather than their own GUI page.9674c3c0fe
added a workaround that has to be copied to any place that can call JS code. If developers don't know about the reason for this workaround and add a new place that can call JS code (#5369), they won't be able to implement anything. This removes this workaround by passing the pointer to the correct GUI page as callback data. Patch By: elexis Reviewed By: wraitii Refs #5369 Trac Tickets: #5369 Differential Revision: https://code.wildfiregames.com/D1701 This was SVN commit r22200.
This commit is contained in:
parent
6225377c4d
commit
f9b529f2fb
@ -282,6 +282,8 @@ CGUI::CGUI(const shared_ptr<ScriptRuntime>& runtime)
|
||||
: 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;
|
||||
|
@ -231,10 +231,6 @@ void CGUIManager::LoadPage(SGUIPage& page)
|
||||
}
|
||||
}
|
||||
|
||||
// Remember this GUI page, in case the scripts call FindObjectByName
|
||||
shared_ptr<CGUI> oldGUI = m_CurrentGUI;
|
||||
m_CurrentGUI = page.gui;
|
||||
|
||||
page.gui->SendEventToAll("load");
|
||||
|
||||
shared_ptr<ScriptInterface> scriptInterface = page.gui->GetScriptInterface();
|
||||
@ -254,8 +250,6 @@ void CGUIManager::LoadPage(SGUIPage& page)
|
||||
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 @@ bool CGUIManager::GetPreDefinedColor(const CStr& name, CColor& output) const
|
||||
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 @@ void CGUIManager::TickObjects()
|
||||
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 @@ void CGUIManager::UpdateResolution()
|
||||
|
||||
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
|
||||
|
@ -107,11 +107,6 @@ public:
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
@ -166,7 +161,6 @@ private:
|
||||
|
||||
shared_ptr<CGUI> top() const;
|
||||
|
||||
shared_ptr<CGUI> m_CurrentGUI; // used to latch state during TickObjects/LoadPage (this is kind of ugly)
|
||||
shared_ptr<ScriptRuntime> m_ScriptRuntime;
|
||||
shared_ptr<ScriptInterface> m_ScriptInterface;
|
||||
|
||||
|
@ -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 @@ void JSI_GUIManager::PopGuiPageCB(ScriptInterface::CxPrivate* pCxPrivate, JS::Ha
|
||||
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<CGUI*>(pCxPrivate->pCBData);
|
||||
|
||||
IGUIObject* guiObj = guiPage->FindObjectByName(name);
|
||||
if (!guiObj)
|
||||
return JS::UndefinedValue();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user