3 Copyright (C) 2013 sapier
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 /******************************************************************************/
25 /******************************************************************************/
26 #include "irrlichttypes.h"
27 #include "modalMenu.h"
28 #include "guiFormSpecMenu.h"
32 /******************************************************************************/
33 /* Typedefs and macros */
34 /******************************************************************************/
35 /** texture layer ids */
37 TEX_LAYER_BACKGROUND = 0,
44 /******************************************************************************/
45 /* forward declarations */
46 /******************************************************************************/
48 class MainMenuScripting;
52 /******************************************************************************/
54 /******************************************************************************/
56 /** GUIEngine specific implementation of TextDest used within guiFormSpecMenu */
57 class TextDestGuiEngine : public TextDest
62 * @param engine the engine data is transmitted for further processing
64 TextDestGuiEngine(GUIEngine* engine);
67 * receive fields transmitted by guiFormSpecMenu
68 * @param fields map containing formspec field elements currently active
70 void gotText(std::map<std::string, std::string> fields);
73 * receive text/events transmitted by guiFormSpecMenu
74 * @param text textual representation of event
76 void gotText(std::wstring text);
79 /** target to transmit data to */
83 /** GUIEngine specific implementation of ISimpleTextureSource */
84 class MenuTextureSource : public ISimpleTextureSource
89 * @param driver the video driver to load textures from
91 MenuTextureSource(video::IVideoDriver *driver);
94 * destructor, removes all loaded textures
96 virtual ~MenuTextureSource();
99 * get a texture, loading it if required
100 * @param name path to the texture
101 * @param id receives the texture ID, always 0 in this implementation
103 video::ITexture* getTexture(const std::string &name, u32 *id = NULL);
106 /** driver to get textures from */
107 video::IVideoDriver *m_driver;
108 /** set of texture names to delete */
109 std::set<std::string> m_to_delete;
112 /** GUIEngine specific implementation of OnDemandSoundFetcher */
113 class MenuMusicFetcher: public OnDemandSoundFetcher
117 * get sound file paths according to sound name
118 * @param name sound name
119 * @param dst_paths receives possible paths to sound files
120 * @param dst_datas receives binary sound data (not used here)
122 void fetchSounds(const std::string &name,
123 std::set<std::string> &dst_paths,
124 std::set<std::string> &dst_datas);
127 /** set of fetched sound names */
128 std::set<std::string> m_fetched;
131 /** implementation of main menu based uppon formspecs */
133 /** grant ModApiMainMenu access to private members */
134 friend class ModApiMainMenu;
138 * default constructor
139 * @param dev device to draw at
140 * @param parent parent gui element
141 * @param menumgr manager to add menus to
142 * @param smgr scene manager to add scene elements to
143 * @param data struct to transfer data to main game handling
145 GUIEngine( irr::IrrlichtDevice* dev,
146 gui::IGUIElement* parent,
147 IMenuManager *menumgr,
148 scene::ISceneManager* smgr,
152 /** default destructor */
153 virtual ~GUIEngine();
156 * return MainMenuScripting interface
158 MainMenuScripting* getScriptIface() {
163 * return dir of current menuscript
165 std::string getScriptDir() {
169 /** pass async callback to scriptengine **/
170 unsigned int DoAsync(std::string serialized_fct,std::string serialized_params);
174 /** find and run the main menu script */
175 bool loadMainMenuScript();
177 /** run main menu loop */
180 /** handler to limit frame rate within main menu */
181 void limitFrameRate();
183 /** device to draw at */
184 irr::IrrlichtDevice* m_device;
185 /** parent gui element */
186 gui::IGUIElement* m_parent;
187 /** manager to add menus to */
188 IMenuManager* m_menumanager;
189 /** scene manager to add scene elements to */
190 scene::ISceneManager* m_smgr;
191 /** pointer to data beeing transfered back to main game handling */
192 MainMenuData* m_data;
193 /** pointer to texture source */
194 ISimpleTextureSource* m_texture_source;
195 /** pointer to soundmanager*/
196 ISoundManager* m_sound_manager;
198 /** representation of form source to be used in mainmenu formspec */
199 FormspecFormSource* m_formspecgui;
200 /** formspec input receiver */
201 TextDestGuiEngine* m_buttonhandler;
202 /** the formspec menu */
203 GUIFormSpecMenu* m_menu;
205 /** reference to kill variable managed by SIGINT handler */
208 /** variable used to abort menu and return back to main game handling */
211 /** scripting interface */
212 MainMenuScripting* m_script;
214 /** script basefolder */
215 std::string m_scriptdir;
218 * draw background layer
219 * @param driver to use for drawing
221 void drawBackground(video::IVideoDriver* driver);
224 * @param driver to use for drawing
226 void drawOverlay(video::IVideoDriver* driver);
229 * @param driver to use for drawing
231 void drawHeader(video::IVideoDriver* driver);
234 * @param driver to use for drawing
236 void drawFooter(video::IVideoDriver* driver);
239 * load a texture for a specified layer
240 * @param layer draw layer to specify texture
241 * @param texturepath full path of texture to load
243 bool setTexture(texture_layer layer,std::string texturepath);
246 * download a file using curl
247 * @param url url to download
248 * @param target file to store to
250 static bool downloadFile(std::string url,std::string target);
252 /** array containing pointers to current specified texture layers */
253 video::ITexture* m_textures[TEX_LAYER_MAX];
255 /** draw version string in topleft corner */
259 * specify text to be appended to version string
262 void setTopleftText(std::string append);
264 /** pointer to gui element shown at topleft corner */
265 irr::gui::IGUIStaticText* m_irr_toplefttext;
267 /** initialize cloud subsystem */
269 /** do preprocessing for cloud subsystem */
270 void cloudPreProcess();
271 /** do postprocessing for cloud subsystem */
272 void cloudPostProcess();
274 /** internam data required for drawing clouds */
276 /** delta time since last cloud processing */
278 /** absolute time of last cloud processing */
280 /** pointer to cloud class */
282 /** camera required for drawing clouds */
283 scene::ICameraSceneNode* camera;
286 /** is drawing of clouds enabled atm */
287 bool m_clouds_enabled;
288 /** data used to draw clouds */
291 /** start playing a sound and return handle */
292 s32 playSound(SimpleSoundSpec spec, bool looped);
293 /** stop playing a sound started with playSound() */
294 void stopSound(s32 handle);
301 #endif /* GUI_ENGINE_H_ */