diff --git a/source/gui/scripting/JSInterface_GUIManager.cpp b/source/gui/scripting/JSInterface_GUIManager.cpp
new file mode 100644
index 0000000000..f80c1568c3
--- /dev/null
+++ b/source/gui/scripting/JSInterface_GUIManager.cpp
@@ -0,0 +1,91 @@
+/* Copyright (C) 2017 Wildfire Games.
+ * This file is part of 0 A.D.
+ *
+ * 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
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 0 A.D. is distributed in the hope that it will be useful,
+ * 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
+ * along with 0 A.D. If not, see .
+ */
+
+#include "precompiled.h"
+
+#include "JSInterface_GUIManager.h"
+
+#include "gui/GUIManager.h"
+#include "gui/IGUIObject.h"
+#include "scriptinterface/ScriptInterface.h"
+#include "ps/GameSetup/Config.h"
+
+// Note that the initData argument may only contain clonable data.
+// Functions aren't supported for example!
+void JSI_GUIManager::PushGuiPage(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& name, JS::HandleValue initData)
+{
+ g_GUI->PushPage(name, pCxPrivate->pScriptInterface->WriteStructuredClone(initData));
+}
+
+void JSI_GUIManager::SwitchGuiPage(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& name, JS::HandleValue initData)
+{
+ g_GUI->SwitchPage(name, pCxPrivate->pScriptInterface, initData);
+}
+
+void JSI_GUIManager::PopGuiPage(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
+{
+ g_GUI->PopPage();
+}
+
+void JSI_GUIManager::PopGuiPageCB(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue args)
+{
+ g_GUI->PopPageCB(pCxPrivate->pScriptInterface->WriteStructuredClone(args));
+}
+
+JS::Value JSI_GUIManager::GetGUIObjectByName(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::string& name)
+{
+ IGUIObject* guiObj = g_GUI->FindObjectByName(name);
+ if (!guiObj)
+ return JS::UndefinedValue();
+
+ return JS::ObjectValue(*guiObj->GetJSObject());
+}
+
+std::wstring JSI_GUIManager::SetCursor(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& name)
+{
+ std::wstring old = g_CursorName;
+ g_CursorName = name;
+ return old;
+}
+
+void JSI_GUIManager::ResetCursor(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
+{
+ g_GUI->ResetCursor();
+}
+
+bool JSI_GUIManager::TemplateExists(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::string& templateName)
+{
+ return g_GUI->TemplateExists(templateName);
+}
+
+CParamNode JSI_GUIManager::GetTemplate(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::string& templateName)
+{
+ return g_GUI->GetTemplate(templateName);
+}
+
+void JSI_GUIManager::RegisterScriptFunctions(const ScriptInterface& scriptInterface)
+{
+ scriptInterface.RegisterFunction("PushGuiPage");
+ scriptInterface.RegisterFunction("SwitchGuiPage");
+ scriptInterface.RegisterFunction("PopGuiPage");
+ scriptInterface.RegisterFunction("PopGuiPageCB");
+ scriptInterface.RegisterFunction("GetGUIObjectByName");
+ scriptInterface.RegisterFunction("SetCursor");
+ scriptInterface.RegisterFunction("ResetCursor");
+ scriptInterface.RegisterFunction("TemplateExists");
+ scriptInterface.RegisterFunction("GetTemplate");
+}
diff --git a/source/gui/scripting/JSInterface_GUIManager.h b/source/gui/scripting/JSInterface_GUIManager.h
new file mode 100644
index 0000000000..9e7b4105be
--- /dev/null
+++ b/source/gui/scripting/JSInterface_GUIManager.h
@@ -0,0 +1,39 @@
+/* Copyright (C) 2017 Wildfire Games.
+ * This file is part of 0 A.D.
+ *
+ * 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
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 0 A.D. is distributed in the hope that it will be useful,
+ * 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
+ * along with 0 A.D. If not, see .
+ */
+
+#ifndef INCLUDED_JSI_GUIMANAGER
+#define INCLUDED_JSI_GUIMANAGER
+
+#include "scriptinterface/ScriptInterface.h"
+#include "simulation2/system/ParamNode.h"
+
+namespace JSI_GUIManager
+{
+ void PushGuiPage(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& name, JS::HandleValue initData);
+ void SwitchGuiPage(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& name, JS::HandleValue initData);
+ void PopGuiPage(ScriptInterface::CxPrivate* pCxPrivate);
+ void PopGuiPageCB(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue args);
+ JS::Value GetGUIObjectByName(ScriptInterface::CxPrivate* pCxPrivate, const std::string& name);
+ std::wstring SetCursor(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& name);
+ void ResetCursor(ScriptInterface::CxPrivate* pCxPrivate);
+ bool TemplateExists(ScriptInterface::CxPrivate* pCxPrivate, const std::string& templateName);
+ CParamNode GetTemplate(ScriptInterface::CxPrivate* pCxPrivate, const std::string& templateName);
+
+ void RegisterScriptFunctions(const ScriptInterface& scriptInterface);
+}
+
+#endif
diff --git a/source/gui/scripting/ScriptFunctions.cpp b/source/gui/scripting/ScriptFunctions.cpp
index 12c73ad425..18f046f32c 100644
--- a/source/gui/scripting/ScriptFunctions.cpp
+++ b/source/gui/scripting/ScriptFunctions.cpp
@@ -23,9 +23,8 @@
#include "graphics/GameView.h"
#include "graphics/MapReader.h"
#include "graphics/scripting/JSInterface_GameView.h"
-#include "gui/GUI.h"
-#include "gui/GUIManager.h"
#include "gui/IGUIObject.h"
+#include "gui/scripting/JSInterface_GUIManager.h"
#include "gui/scripting/JSInterface_GUITypes.h"
#include "i18n/L10n.h"
#include "i18n/scripting/JSInterface_L10n.h"
@@ -84,37 +83,6 @@ extern void kill_mainloop();
namespace {
-// Note that the initData argument may only contain clonable data.
-// Functions aren't supported for example!
-// TODO: Use LOGERROR to print a friendly error message when the requirements aren't met instead of failing with debug_warn when cloning.
-void PushGuiPage(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& name, JS::HandleValue initData)
-{
- g_GUI->PushPage(name, pCxPrivate->pScriptInterface->WriteStructuredClone(initData));
-}
-
-void SwitchGuiPage(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& name, JS::HandleValue initData)
-{
- g_GUI->SwitchPage(name, pCxPrivate->pScriptInterface, initData);
-}
-
-void PopGuiPage(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
-{
- g_GUI->PopPage();
-}
-
-// Note that the args argument may only contain clonable data.
-// Functions aren't supported for example!
-// TODO: Use LOGERROR to print a friendly error message when the requirements aren't met instead of failing with debug_warn when cloning.
-void PopGuiPageCB(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue args)
-{
- g_GUI->PopPageCB(pCxPrivate->pScriptInterface->WriteStructuredClone(args));
-}
-
-void ResetCursor(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
-{
- g_GUI->ResetCursor();
-}
-
JS::Value GuiInterfaceCall(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& name, JS::HandleValue data)
{
if (!g_Game)
@@ -178,13 +146,6 @@ std::vector PickSimilarPlayerEntities(ScriptInterface::CxPrivate* U
return EntitySelection::PickSimilarEntities(*g_Game->GetSimulation2(), *g_Game->GetView()->GetCamera(), templateName, g_Game->GetViewedPlayerID(), includeOffScreen, matchRank, false, allowFoundations);
}
-std::wstring SetCursor(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& name)
-{
- std::wstring old = g_CursorName;
- g_CursorName = name;
- return old;
-}
-
bool IsVisualReplay(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
{
if (!g_Game)
@@ -468,15 +429,6 @@ int GetFps(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
return freq;
}
-JS::Value GetGUIObjectByName(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const CStr& name)
-{
- IGUIObject* guiObj = g_GUI->FindObjectByName(name);
- if (guiObj)
- return JS::ObjectValue(*guiObj->GetJSObject());
- else
- return JS::UndefinedValue();
-}
-
// Return the date/time at which the current executable was compiled.
// params: mode OR an integer specifying
// what to display: -1 for "date time (svn revision)", 0 for date, 1 for time, 2 for svn revision
@@ -541,16 +493,6 @@ std::wstring GetBuildTimestamp(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), i
return wstring_from_utf8(buf);
}
-bool TemplateExists(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::string& templateName)
-{
- return g_GUI->TemplateExists(templateName);
-}
-
-CParamNode GetTemplate(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::string& templateName)
-{
- return g_GUI->GetTemplate(templateName);
-}
-
int GetTextWidth(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const CStr& fontName, const CStrW& text)
{
int width = 0;
@@ -580,6 +522,7 @@ void GuiScriptingInit(ScriptInterface& scriptInterface)
JSI_Renderer::RegisterScriptFunctions(scriptInterface);
JSI_Console::RegisterScriptFunctions(scriptInterface);
JSI_ConfigDB::RegisterScriptFunctions(scriptInterface);
+ JSI_GUIManager::RegisterScriptFunctions(scriptInterface);
JSI_Mod::RegisterScriptFunctions(scriptInterface);
JSI_Network::RegisterScriptFunctions(scriptInterface);
JSI_SavedGame::RegisterScriptFunctions(scriptInterface);
@@ -589,14 +532,6 @@ void GuiScriptingInit(ScriptInterface& scriptInterface)
JSI_VFS::RegisterScriptFunctions(scriptInterface);
JSI_VisualReplay::RegisterScriptFunctions(scriptInterface);
- // GUI manager functions:
- scriptInterface.RegisterFunction("PushGuiPage");
- scriptInterface.RegisterFunction("SwitchGuiPage");
- scriptInterface.RegisterFunction("PopGuiPage");
- scriptInterface.RegisterFunction("PopGuiPageCB");
- scriptInterface.RegisterFunction("GetGUIObjectByName");
- scriptInterface.RegisterFunction("ResetCursor");
-
// Simulation<->GUI interface functions:
scriptInterface.RegisterFunction("GuiInterfaceCall");
scriptInterface.RegisterFunction("PostNetworkCommand");
@@ -613,7 +548,6 @@ void GuiScriptingInit(ScriptInterface& scriptInterface)
scriptInterface.RegisterFunction("GetAIs");
// Misc functions
- scriptInterface.RegisterFunction("SetCursor");
scriptInterface.RegisterFunction("IsVisualReplay");
scriptInterface.RegisterFunction("GetCurrentReplayDirectory");
scriptInterface.RegisterFunction("GetPlayerID");
@@ -635,8 +569,6 @@ void GuiScriptingInit(ScriptInterface& scriptInterface)
scriptInterface.RegisterFunction("SetPaused");
scriptInterface.RegisterFunction("GetFPS");
scriptInterface.RegisterFunction("GetBuildTimestamp");
- scriptInterface.RegisterFunction("TemplateExists");
- scriptInterface.RegisterFunction("GetTemplate");
scriptInterface.RegisterFunction("GetTextWidth");
// User report functions