Changeset View
Changeset View
Standalone View
Standalone View
source/gui/Scripting/JSInterface_GUIManager.cpp
/* Copyright (C) 2020 Wildfire Games. | /* Copyright (C) 2021 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
Show All 9 Lines | |||||
#include "JSInterface_GUIManager.h" | #include "JSInterface_GUIManager.h" | ||||
#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/FunctionWrapper.h" | #include "scriptinterface/FunctionWrapper.h" | ||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/StructuredClone.h" | ||||
namespace JSI_GUIManager | namespace JSI_GUIManager | ||||
{ | { | ||||
// 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 PushGuiPage(const ScriptInterface& scriptInterface, const std::wstring& name, JS::HandleValue initData, JS::HandleValue callbackFunction) | void PushGuiPage(const ScriptRequest& rq, const std::wstring& name, JS::HandleValue initData, JS::HandleValue callbackFunction) | ||||
{ | { | ||||
g_GUI->PushPage(name, scriptInterface.WriteStructuredClone(initData), callbackFunction); | g_GUI->PushPage(name, Script::WriteStructuredClone(rq, initData), callbackFunction); | ||||
} | } | ||||
void SwitchGuiPage(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& name, JS::HandleValue initData) | void SwitchGuiPage(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& name, JS::HandleValue initData) | ||||
{ | { | ||||
g_GUI->SwitchPage(name, pCmptPrivate->pScriptInterface, initData); | g_GUI->SwitchPage(name, pCmptPrivate->pScriptInterface, initData); | ||||
} | } | ||||
void PopGuiPage(ScriptInterface::CmptPrivate* pCmptPrivate, JS::HandleValue args) | void PopGuiPage(const ScriptRequest& rq, JS::HandleValue args) | ||||
{ | { | ||||
if (g_GUI->GetPageCount() < 2) | if (g_GUI->GetPageCount() < 2) | ||||
{ | { | ||||
ScriptRequest rq(pCmptPrivate->pScriptInterface); | |||||
ScriptException::Raise(rq, "Can't pop GUI pages when less than two pages are opened!"); | ScriptException::Raise(rq, "Can't pop GUI pages when less than two pages are opened!"); | ||||
return; | return; | ||||
} | } | ||||
g_GUI->PopPage(pCmptPrivate->pScriptInterface->WriteStructuredClone(args)); | g_GUI->PopPage(Script::WriteStructuredClone(rq, args)); | ||||
} | } | ||||
std::wstring SetCursor(const std::wstring& name) | std::wstring SetCursor(const std::wstring& name) | ||||
{ | { | ||||
std::wstring old = g_CursorName; | std::wstring old = g_CursorName; | ||||
g_CursorName = name; | g_CursorName = name; | ||||
return old; | return old; | ||||
} | } | ||||
Show All 32 Lines |
Wildfire Games · Phabricator