2026-03-23 11:32:18 -07:00
|
|
|
/* Copyright (C) 2026 Wildfire Games.
|
2023-12-02 16:30:12 -08:00
|
|
|
* This file is part of 0 A.D.
|
2017-09-11 17:54:49 -07:00
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2017-09-11 17:54:49 -07:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2017-09-11 17:54:49 -07:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2023-12-02 16:30:12 -08:00
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2017-09-11 17:54:49 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
|
|
|
|
#include "JSInterface_GUIManager.h"
|
|
|
|
|
|
2019-04-20 08:49:42 -07:00
|
|
|
#include "gui/CGUI.h"
|
2017-09-11 17:54:49 -07:00
|
|
|
#include "gui/GUIManager.h"
|
2025-08-12 11:29:24 -07:00
|
|
|
#include "ps/CStr.h"
|
2021-09-21 15:44:46 -07:00
|
|
|
#include "ps/VideoMode.h"
|
2021-03-02 12:01:14 -08:00
|
|
|
#include "scriptinterface/FunctionWrapper.h"
|
2021-05-15 06:54:58 -07:00
|
|
|
#include "scriptinterface/ScriptInterface.h"
|
2021-05-10 04:51:32 -07:00
|
|
|
#include "scriptinterface/StructuredClone.h"
|
2025-08-12 11:29:24 -07:00
|
|
|
#include "simulation2/system/Component.h"
|
|
|
|
|
|
2025-06-19 15:06:41 -07:00
|
|
|
#include <js/RootingAPI.h>
|
|
|
|
|
#include <js/TypeDecls.h>
|
|
|
|
|
#include <js/Value.h>
|
|
|
|
|
#include <string>
|
2017-09-11 17:54:49 -07:00
|
|
|
|
2021-03-02 12:01:14 -08:00
|
|
|
namespace JSI_GUIManager
|
|
|
|
|
{
|
2017-09-11 17:54:49 -07:00
|
|
|
// Note that the initData argument may only contain clonable data.
|
|
|
|
|
// Functions aren't supported for example!
|
2024-07-08 12:07:04 -07:00
|
|
|
// It returns a promise.
|
2024-10-30 10:56:33 -07:00
|
|
|
JS::Value OpenChildPage(const ScriptRequest& rq, const std::wstring& name, JS::HandleValue initData)
|
2017-09-11 17:54:49 -07:00
|
|
|
{
|
2024-10-30 10:56:33 -07:00
|
|
|
return g_GUI->OpenChildPage(name, Script::WriteStructuredClone(rq, initData));
|
2017-09-11 17:54:49 -07:00
|
|
|
}
|
|
|
|
|
|
2021-09-21 15:44:46 -07:00
|
|
|
void SetCursor(const std::wstring& name)
|
2017-09-11 17:54:49 -07:00
|
|
|
{
|
2021-09-21 15:44:46 -07:00
|
|
|
g_VideoMode.SetCursor(name);
|
2017-09-11 17:54:49 -07:00
|
|
|
}
|
|
|
|
|
|
2021-03-02 12:01:14 -08:00
|
|
|
void ResetCursor()
|
2017-09-11 17:54:49 -07:00
|
|
|
{
|
2021-09-21 15:44:46 -07:00
|
|
|
g_VideoMode.ResetCursor();
|
2017-09-11 17:54:49 -07:00
|
|
|
}
|
|
|
|
|
|
2021-03-02 12:01:14 -08:00
|
|
|
bool TemplateExists(const std::string& templateName)
|
2017-09-11 17:54:49 -07:00
|
|
|
{
|
|
|
|
|
return g_GUI->TemplateExists(templateName);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 12:01:14 -08:00
|
|
|
CParamNode GetTemplate(const std::string& templateName)
|
2017-09-11 17:54:49 -07:00
|
|
|
{
|
|
|
|
|
return g_GUI->GetTemplate(templateName);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 12:01:14 -08:00
|
|
|
|
|
|
|
|
void RegisterScriptFunctions(const ScriptRequest& rq)
|
2017-09-11 17:54:49 -07:00
|
|
|
{
|
2024-10-30 10:56:33 -07:00
|
|
|
ScriptFunction::Register<&OpenChildPage>(rq, "OpenChildPage");
|
2021-03-02 12:01:14 -08:00
|
|
|
ScriptFunction::Register<&SetCursor>(rq, "SetCursor");
|
|
|
|
|
ScriptFunction::Register<&ResetCursor>(rq, "ResetCursor");
|
|
|
|
|
ScriptFunction::Register<&TemplateExists>(rq, "TemplateExists");
|
|
|
|
|
ScriptFunction::Register<&GetTemplate>(rq, "GetTemplate");
|
|
|
|
|
|
2025-07-25 14:40:42 -07:00
|
|
|
ScriptFunction::Register<&CGUI::TryFindObjectByName, &ScriptInterface::ObjectFromCBData<CGUI>>(rq, "TryGetGUIObjectByName");
|
2021-05-15 06:54:58 -07:00
|
|
|
ScriptFunction::Register<&CGUI::FindObjectByName, &ScriptInterface::ObjectFromCBData<CGUI>>(rq, "GetGUIObjectByName");
|
|
|
|
|
ScriptFunction::Register<&CGUI::SetGlobalHotkey, &ScriptInterface::ObjectFromCBData<CGUI>>(rq, "SetGlobalHotkey");
|
|
|
|
|
ScriptFunction::Register<&CGUI::UnsetGlobalHotkey, &ScriptInterface::ObjectFromCBData<CGUI>>(rq, "UnsetGlobalHotkey");
|
2021-03-02 12:01:14 -08:00
|
|
|
}
|
2017-09-11 17:54:49 -07:00
|
|
|
}
|