Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/gui/Scripting/JSInterface_GUIManager.cpp
Show All 21 Lines | |||||
#include "gui/CGUI.h" | #include "gui/CGUI.h" | ||||
#include "gui/GUIManager.h" | #include "gui/GUIManager.h" | ||||
#include "gui/ObjectBases/IGUIObject.h" | #include "gui/ObjectBases/IGUIObject.h" | ||||
#include "ps/GameSetup/Config.h" | #include "ps/GameSetup/Config.h" | ||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
// Note that the initData argument may only contain clonable data. | // Note that the initData argument may only contain clonable data. | ||||
// Functions aren't supported for example! | // Functions aren't supported for example! | ||||
void JSI_GUIManager::PushGuiPage(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& name, JS::HandleValue initData, JS::HandleValue callbackFunction) | void JSI_GUIManager::PushGuiPage(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& name, JS::HandleValue initData, JS::HandleValue callbackFunction) | ||||
{ | { | ||||
g_GUI->PushPage(name, pCxPrivate->pScriptInterface->WriteStructuredClone(initData), callbackFunction); | g_GUI->PushPage(name, pCmptPrivate->pScriptInterface->WriteStructuredClone(initData), callbackFunction); | ||||
} | } | ||||
void JSI_GUIManager::SwitchGuiPage(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& name, JS::HandleValue initData) | void JSI_GUIManager::SwitchGuiPage(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& name, JS::HandleValue initData) | ||||
{ | { | ||||
g_GUI->SwitchPage(name, pCxPrivate->pScriptInterface, initData); | g_GUI->SwitchPage(name, pCmptPrivate->pScriptInterface, initData); | ||||
} | } | ||||
void JSI_GUIManager::PopGuiPage(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue args) | void JSI_GUIManager::PopGuiPage(ScriptInterface::CmptPrivate* pCmptPrivate, JS::HandleValue args) | ||||
{ | { | ||||
if (g_GUI->GetPageCount() < 2) | if (g_GUI->GetPageCount() < 2) | ||||
{ | { | ||||
ScriptInterface::Request rq(pCxPrivate); | ScriptInterface::Request rq(pCmptPrivate); | ||||
JS_ReportError(rq.cx, "Can't pop GUI pages when less than two pages are opened!"); | JS_ReportError(rq.cx, "Can't pop GUI pages when less than two pages are opened!"); | ||||
return; | return; | ||||
} | } | ||||
g_GUI->PopPage(pCxPrivate->pScriptInterface->WriteStructuredClone(args)); | g_GUI->PopPage(pCmptPrivate->pScriptInterface->WriteStructuredClone(args)); | ||||
} | } | ||||
JS::Value JSI_GUIManager::GetGUIObjectByName(ScriptInterface::CxPrivate* pCxPrivate, const std::string& name) | JS::Value JSI_GUIManager::GetGUIObjectByName(ScriptInterface::CmptPrivate* pCmptPrivate, const std::string& name) | ||||
{ | { | ||||
CGUI* guiPage = static_cast<CGUI*>(pCxPrivate->pCBData); | CGUI* guiPage = static_cast<CGUI*>(pCmptPrivate->pCBData); | ||||
IGUIObject* guiObj = guiPage->FindObjectByName(name); | IGUIObject* guiObj = guiPage->FindObjectByName(name); | ||||
if (!guiObj) | if (!guiObj) | ||||
return JS::UndefinedValue(); | return JS::UndefinedValue(); | ||||
return JS::ObjectValue(*guiObj->GetJSObject()); | return JS::ObjectValue(*guiObj->GetJSObject()); | ||||
} | } | ||||
void JSI_GUIManager::SetGlobalHotkey(ScriptInterface::CxPrivate* pCxPrivate, const std::string& hotkeyTag, const std::string& eventName, JS::HandleValue function) | void JSI_GUIManager::SetGlobalHotkey(ScriptInterface::CmptPrivate* pCmptPrivate, const std::string& hotkeyTag, const std::string& eventName, JS::HandleValue function) | ||||
{ | { | ||||
CGUI* guiPage = static_cast<CGUI*>(pCxPrivate->pCBData); | CGUI* guiPage = static_cast<CGUI*>(pCmptPrivate->pCBData); | ||||
guiPage->SetGlobalHotkey(hotkeyTag, eventName, function); | guiPage->SetGlobalHotkey(hotkeyTag, eventName, function); | ||||
} | } | ||||
void JSI_GUIManager::UnsetGlobalHotkey(ScriptInterface::CxPrivate* pCxPrivate, const std::string& hotkeyTag, const std::string& eventName) | void JSI_GUIManager::UnsetGlobalHotkey(ScriptInterface::CmptPrivate* pCmptPrivate, const std::string& hotkeyTag, const std::string& eventName) | ||||
{ | { | ||||
CGUI* guiPage = static_cast<CGUI*>(pCxPrivate->pCBData); | CGUI* guiPage = static_cast<CGUI*>(pCmptPrivate->pCBData); | ||||
guiPage->UnsetGlobalHotkey(hotkeyTag, eventName); | guiPage->UnsetGlobalHotkey(hotkeyTag, eventName); | ||||
} | } | ||||
std::wstring JSI_GUIManager::SetCursor(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& name) | std::wstring JSI_GUIManager::SetCursor(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate), const std::wstring& name) | ||||
{ | { | ||||
std::wstring old = g_CursorName; | std::wstring old = g_CursorName; | ||||
g_CursorName = name; | g_CursorName = name; | ||||
return old; | return old; | ||||
} | } | ||||
void JSI_GUIManager::ResetCursor(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) | void JSI_GUIManager::ResetCursor(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate)) | ||||
{ | { | ||||
g_CursorName = g_DefaultCursor; | g_CursorName = g_DefaultCursor; | ||||
} | } | ||||
bool JSI_GUIManager::TemplateExists(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::string& templateName) | bool JSI_GUIManager::TemplateExists(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate), const std::string& templateName) | ||||
{ | { | ||||
return g_GUI->TemplateExists(templateName); | return g_GUI->TemplateExists(templateName); | ||||
} | } | ||||
CParamNode JSI_GUIManager::GetTemplate(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::string& templateName) | CParamNode JSI_GUIManager::GetTemplate(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate), const std::string& templateName) | ||||
{ | { | ||||
return g_GUI->GetTemplate(templateName); | return g_GUI->GetTemplate(templateName); | ||||
} | } | ||||
void JSI_GUIManager::RegisterScriptFunctions(const ScriptInterface& scriptInterface) | void JSI_GUIManager::RegisterScriptFunctions(const ScriptInterface& scriptInterface) | ||||
{ | { | ||||
scriptInterface.RegisterFunction<void, std::wstring, JS::HandleValue, JS::HandleValue, &PushGuiPage>("PushGuiPage"); | scriptInterface.RegisterFunction<void, std::wstring, JS::HandleValue, JS::HandleValue, &PushGuiPage>("PushGuiPage"); | ||||
scriptInterface.RegisterFunction<void, std::wstring, JS::HandleValue, &SwitchGuiPage>("SwitchGuiPage"); | scriptInterface.RegisterFunction<void, std::wstring, JS::HandleValue, &SwitchGuiPage>("SwitchGuiPage"); | ||||
Show All 9 Lines |
Wildfire Games · Phabricator