1 /* Copyright (C) 2017 Wildfire Games.
2 * This file is part of 0 A.D.
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
18 #include "precompiled.h"
20 #include "JSInterface_GUIManager.h"
22 #include "gui/GUIManager.h"
23 #include "gui/IGUIObject.h"
24 #include "scriptinterface/ScriptInterface.h"
25 #include "ps/GameSetup/Config.h"
27 // Note that the initData argument may only contain clonable data.
28 // Functions aren't supported for example!
29 void JSI_GUIManager::PushGuiPage(ScriptInterface::CxPrivate
* pCxPrivate
, const std::wstring
& name
, JS::HandleValue initData
)
31 g_GUI
->PushPage(name
, pCxPrivate
->pScriptInterface
->WriteStructuredClone(initData
));
34 void JSI_GUIManager::SwitchGuiPage(ScriptInterface::CxPrivate
* pCxPrivate
, const std::wstring
& name
, JS::HandleValue initData
)
36 g_GUI
->SwitchPage(name
, pCxPrivate
->pScriptInterface
, initData
);
39 void JSI_GUIManager::PopGuiPage(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
))
44 void JSI_GUIManager::PopGuiPageCB(ScriptInterface::CxPrivate
* pCxPrivate
, JS::HandleValue args
)
46 g_GUI
->PopPageCB(pCxPrivate
->pScriptInterface
->WriteStructuredClone(args
));
49 JS::Value
JSI_GUIManager::GetGUIObjectByName(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
), const std::string
& name
)
51 IGUIObject
* guiObj
= g_GUI
->FindObjectByName(name
);
53 return JS::UndefinedValue();
55 return JS::ObjectValue(*guiObj
->GetJSObject());
58 std::wstring
JSI_GUIManager::SetCursor(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
), const std::wstring
& name
)
60 std::wstring old
= g_CursorName
;
65 void JSI_GUIManager::ResetCursor(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
))
70 bool JSI_GUIManager::TemplateExists(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
), const std::string
& templateName
)
72 return g_GUI
->TemplateExists(templateName
);
75 CParamNode
JSI_GUIManager::GetTemplate(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
), const std::string
& templateName
)
77 return g_GUI
->GetTemplate(templateName
);
80 void JSI_GUIManager::RegisterScriptFunctions(const ScriptInterface
& scriptInterface
)
82 scriptInterface
.RegisterFunction
<void, std::wstring
, JS::HandleValue
, &PushGuiPage
>("PushGuiPage");
83 scriptInterface
.RegisterFunction
<void, std::wstring
, JS::HandleValue
, &SwitchGuiPage
>("SwitchGuiPage");
84 scriptInterface
.RegisterFunction
<void, &PopGuiPage
>("PopGuiPage");
85 scriptInterface
.RegisterFunction
<void, JS::HandleValue
, &PopGuiPageCB
>("PopGuiPageCB");
86 scriptInterface
.RegisterFunction
<JS::Value
, std::string
, &GetGUIObjectByName
>("GetGUIObjectByName");
87 scriptInterface
.RegisterFunction
<std::wstring
, std::wstring
, &SetCursor
>("SetCursor");
88 scriptInterface
.RegisterFunction
<void, &ResetCursor
>("ResetCursor");
89 scriptInterface
.RegisterFunction
<bool, std::string
, &TemplateExists
>("TemplateExists");
90 scriptInterface
.RegisterFunction
<CParamNode
, std::string
, &GetTemplate
>("GetTemplate");