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() {
171 /** find and run the main menu script */
172 bool loadMainMenuScript();
174 /** run main menu loop */
177 /** handler to limit frame rate within main menu */
178 void limitFrameRate();
180 /** device to draw at */
181 irr::IrrlichtDevice* m_device;
182 /** parent gui element */
183 gui::IGUIElement* m_parent;
184 /** manager to add menus to */
185 IMenuManager* m_menumanager;
186 /** scene manager to add scene elements to */
187 scene::ISceneManager* m_smgr;
188 /** pointer to data beeing transfered back to main game handling */
189 MainMenuData* m_data;
190 /** pointer to texture source */
191 ISimpleTextureSource* m_texture_source;
192 /** pointer to soundmanager*/
193 ISoundManager* m_sound_manager;
195 /** representation of form source to be used in mainmenu formspec */
196 FormspecFormSource* m_formspecgui;
197 /** formspec input receiver */
198 TextDestGuiEngine* m_buttonhandler;
199 /** the formspec menu */
200 GUIFormSpecMenu* m_menu;
202 /** reference to kill variable managed by SIGINT handler */
205 /** variable used to abort menu and return back to main game handling */
208 /** scripting interface */
209 MainMenuScripting* m_script;
211 /** script basefolder */
212 std::string m_scriptdir;
215 * draw background layer
216 * @param driver to use for drawing
218 void drawBackground(video::IVideoDriver* driver);
221 * @param driver to use for drawing
223 void drawOverlay(video::IVideoDriver* driver);
226 * @param driver to use for drawing
228 void drawHeader(video::IVideoDriver* driver);
231 * @param driver to use for drawing
233 void drawFooter(video::IVideoDriver* driver);
236 * load a texture for a specified layer
237 * @param layer draw layer to specify texture
238 * @param texturepath full path of texture to load
240 bool setTexture(texture_layer layer,std::string texturepath);
243 * download a file using curl
244 * @param url url to download
245 * @param target file to store to
247 bool downloadFile(std::string url,std::string target);
249 /** array containing pointers to current specified texture layers */
250 video::ITexture* m_textures[TEX_LAYER_MAX];
252 /** draw version string in topleft corner */
256 * specify text to be appended to version string
259 void setTopleftText(std::string append);
261 /** pointer to gui element shown at topleft corner */
262 irr::gui::IGUIStaticText* m_irr_toplefttext;
264 /** initialize cloud subsystem */
266 /** do preprocessing for cloud subsystem */
267 void cloudPreProcess();
268 /** do postprocessing for cloud subsystem */
269 void cloudPostProcess();
271 /** internam data required for drawing clouds */
273 /** delta time since last cloud processing */
275 /** absolute time of last cloud processing */
277 /** pointer to cloud class */
279 /** camera required for drawing clouds */
280 scene::ICameraSceneNode* camera;
283 /** is drawing of clouds enabled atm */
284 bool m_clouds_enabled;
285 /** data used to draw clouds */
288 /** start playing a sound and return handle */
289 s32 playSound(SimpleSoundSpec spec, bool looped);
290 /** stop playing a sound started with playSound() */
291 void stopSound(s32 handle);
298 #endif /* GUI_ENGINE_H_ */