mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-07-14 00:13:46 +00:00
IGUIObject ScriptEventi: optional return value for signalling if the event has been handled
Comments by: badosu, elexis Differential Revision: https://code.wildfiregames.com/D2727 This was SVN commit r23652.
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
|
||||
#include "gui/CGUI.h"
|
||||
#include "gui/CGUISetting.h"
|
||||
#include "js/Conversions.h"
|
||||
#include "ps/CLogger.h"
|
||||
#include "ps/GameSetup/Config.h"
|
||||
#include "ps/Profile.h"
|
||||
@@ -396,21 +397,31 @@ InReaction IGUIObject::SendMouseEvent(EGUIMessageType type, const CStr& eventNam
|
||||
}
|
||||
|
||||
void IGUIObject::ScriptEvent(const CStr& eventName)
|
||||
{
|
||||
ScriptEventWithReturn(eventName);
|
||||
}
|
||||
|
||||
bool IGUIObject::ScriptEventWithReturn(const CStr& eventName)
|
||||
{
|
||||
if (m_ScriptHandlers.find(eventName) == m_ScriptHandlers.end())
|
||||
return;
|
||||
return false;
|
||||
|
||||
JSContext* cx = m_pGUI.GetScriptInterface()->GetContext();
|
||||
JSAutoRequest rq(cx);
|
||||
JS::AutoValueVector paramData(cx);
|
||||
ScriptEvent(eventName, paramData);
|
||||
return ScriptEventWithReturn(eventName, paramData);
|
||||
}
|
||||
|
||||
void IGUIObject::ScriptEvent(const CStr& eventName, const JS::HandleValueArray& paramData)
|
||||
{
|
||||
ScriptEventWithReturn(eventName, paramData);
|
||||
}
|
||||
|
||||
bool IGUIObject::ScriptEventWithReturn(const CStr& eventName, const JS::HandleValueArray& paramData)
|
||||
{
|
||||
std::map<CStr, JS::Heap<JSObject*> >::iterator it = m_ScriptHandlers.find(eventName);
|
||||
if (it == m_ScriptHandlers.end())
|
||||
return;
|
||||
return false;
|
||||
|
||||
JSContext* cx = m_pGUI.GetScriptInterface()->GetContext();
|
||||
JSAutoRequest rq(cx);
|
||||
@@ -419,7 +430,11 @@ void IGUIObject::ScriptEvent(const CStr& eventName, const JS::HandleValueArray&
|
||||
JS::RootedValue result(cx);
|
||||
|
||||
if (!JS_CallFunctionValue(cx, obj, handlerVal, paramData, &result))
|
||||
{
|
||||
JS_ReportError(cx, "Errors executing script event \"%s\"", eventName.c_str());
|
||||
return false;
|
||||
}
|
||||
return JS::ToBoolean(result);
|
||||
}
|
||||
|
||||
void IGUIObject::CreateJSObject()
|
||||
|
||||
Reference in New Issue
Block a user