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 #ifndef INCLUDED_GUIMANAGER
19 #define INCLUDED_GUIMANAGER
21 #include <boost/unordered_set.hpp>
24 #include "lib/input.h"
25 #include "lib/file/vfs/vfs_path.h"
26 #include "ps/CLogger.h"
28 #include "ps/TemplateLoader.h"
29 #include "scriptinterface/ScriptVal.h"
30 #include "scriptinterface/ScriptInterface.h"
39 * External interface to the GUI system.
41 * The GUI consists of a set of pages. Each page is constructed from a
42 * series of XML files, and is independent from any other page.
43 * Only one page is active at a time. All events and render requests etc
44 * will go to the active page. This lets the GUI switch between pre-game menu
49 NONCOPYABLE(CGUIManager
);
54 shared_ptr
<ScriptInterface
> GetScriptInterface()
56 return m_ScriptInterface
;
58 shared_ptr
<ScriptRuntime
> GetRuntime() { return m_ScriptRuntime
; }
59 shared_ptr
<CGUI
> GetActiveGUI() { return top(); }
62 * Returns whether there are any current pages.
67 * Load a new GUI page and make it active. All current pages will be destroyed.
69 void SwitchPage(const CStrW
& name
, ScriptInterface
* srcScriptInterface
, JS::HandleValue initData
);
72 * Load a new GUI page and make it active. All current pages will be retained,
73 * and will still be drawn and receive tick events, but will not receive
76 void PushPage(const CStrW
& pageName
, shared_ptr
<ScriptInterface::StructuredClone
> initData
);
79 * Unload the currently active GUI page, and make the previous page active.
80 * (There must be at least two pages when you call this.)
83 void PopPageCB(shared_ptr
<ScriptInterface::StructuredClone
> args
);
86 * Display a modal message box with an "OK" button.
88 void DisplayMessageBox(int width
, int height
, const CStrW
& title
, const CStrW
& message
);
91 * Called when a file has been modified, to hotload changes.
93 Status
ReloadChangedFile(const VfsPath
& path
);
96 * Sets the default mouse pointer.
101 * Called when we should reload all pages (e.g. translation hotloading update).
103 Status
ReloadAllPages();
106 * Pass input events to the currently active GUI page.
108 InReaction
HandleEvent(const SDL_Event_
* ev
);
111 * See CGUI::GetPreDefinedColor; applies to the currently active page.
113 bool GetPreDefinedColor(const CStr
& name
, CColor
& output
) const;
116 * See CGUI::FindObjectByName; applies to the currently active page.
118 IGUIObject
* FindObjectByName(const CStr
& name
) const;
121 * See CGUI::SendEventToAll; applies to the currently active page.
123 void SendEventToAll(const CStr
& eventName
) const;
126 * See CGUI::TickObjects; applies to @em all loaded pages.
131 * See CGUI::Draw; applies to @em all loaded pages.
136 * See CGUI::UpdateResolution; applies to @em all loaded pages.
138 void UpdateResolution();
141 * Calls the current page's script function getSavedGameData() and returns the result.
143 std::string
GetSavedGameData();
145 void RestoreSavedGameData(const std::string
& jsonData
);
148 * Check if a template with this name exists
150 bool TemplateExists(const std::string
& templateName
) const;
153 * Retrieve the requested template, used for displaying faction specificities.
155 const CParamNode
& GetTemplate(const std::string
& templateName
);
161 boost::unordered_set
<VfsPath
> inputs
; // for hotloading
164 shared_ptr
<ScriptInterface::StructuredClone
> initData
; // data to be passed to the init() function
165 CStrW callbackPageName
;
167 shared_ptr
<CGUI
> gui
; // the actual GUI page
170 void LoadPage(SGUIPage
& page
);
172 shared_ptr
<CGUI
> top() const;
174 shared_ptr
<CGUI
> m_CurrentGUI
; // used to latch state during TickObjects/LoadPage (this is kind of ugly)
175 shared_ptr
<ScriptRuntime
> m_ScriptRuntime
;
176 shared_ptr
<ScriptInterface
> m_ScriptInterface
;
178 typedef std::vector
<SGUIPage
> PageStackType
;
179 PageStackType m_PageStack
;
181 CTemplateLoader m_TemplateLoader
;
184 extern CGUIManager
* g_GUI
;
186 extern InReaction
gui_handler(const SDL_Event_
* ev
);
188 #endif // INCLUDED_GUIMANAGER