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"
30 #include "client/tile.h"
31 #include "util/enriched_string.h"
33 /******************************************************************************/
34 /* Typedefs and macros */
35 /******************************************************************************/
36 /** texture layer ids */
38 TEX_LAYER_BACKGROUND = 0,
46 video::ITexture* texture;
51 /******************************************************************************/
52 /* forward declarations */
53 /******************************************************************************/
55 class MainMenuScripting;
59 /******************************************************************************/
61 /******************************************************************************/
63 /** GUIEngine specific implementation of TextDest used within guiFormSpecMenu */
64 class TextDestGuiEngine : public TextDest
69 * @param engine the engine data is transmitted for further processing
71 TextDestGuiEngine(GUIEngine* engine);
74 * receive fields transmitted by guiFormSpecMenu
75 * @param fields map containing formspec field elements currently active
77 void gotText(const StringMap &fields);
80 * receive text/events transmitted by guiFormSpecMenu
81 * @param text textual representation of event
83 void gotText(std::wstring text);
86 /** target to transmit data to */
90 /** GUIEngine specific implementation of ISimpleTextureSource */
91 class MenuTextureSource : public ISimpleTextureSource
96 * @param driver the video driver to load textures from
98 MenuTextureSource(video::IVideoDriver *driver);
101 * destructor, removes all loaded textures
103 virtual ~MenuTextureSource();
106 * get a texture, loading it if required
107 * @param name path to the texture
108 * @param id receives the texture ID, always 0 in this implementation
110 video::ITexture* getTexture(const std::string &name, u32 *id = NULL);
113 /** driver to get textures from */
114 video::IVideoDriver *m_driver;
115 /** set of texture names to delete */
116 std::set<std::string> m_to_delete;
119 /** GUIEngine specific implementation of OnDemandSoundFetcher */
120 class MenuMusicFetcher: public OnDemandSoundFetcher
124 * get sound file paths according to sound name
125 * @param name sound name
126 * @param dst_paths receives possible paths to sound files
127 * @param dst_datas receives binary sound data (not used here)
129 void fetchSounds(const std::string &name,
130 std::set<std::string> &dst_paths,
131 std::set<std::string> &dst_datas);
134 /** set of fetched sound names */
135 std::set<std::string> m_fetched;
138 /** implementation of main menu based uppon formspecs */
140 /** grant ModApiMainMenu access to private members */
141 friend class ModApiMainMenu;
145 * default constructor
146 * @param dev device to draw at
147 * @param parent parent gui element
148 * @param menumgr manager to add menus to
149 * @param smgr scene manager to add scene elements to
150 * @param data struct to transfer data to main game handling
152 GUIEngine( irr::IrrlichtDevice* dev,
153 gui::IGUIElement* parent,
154 IMenuManager *menumgr,
155 scene::ISceneManager* smgr,
159 /** default destructor */
160 virtual ~GUIEngine();
163 * return MainMenuScripting interface
165 MainMenuScripting* getScriptIface()
171 * return dir of current menuscript
173 std::string getScriptDir()
178 /** pass async callback to scriptengine **/
179 unsigned int queueAsync(std::string serialized_fct,std::string serialized_params);
183 /** find and run the main menu script */
184 bool loadMainMenuScript();
186 /** run main menu loop */
189 /** handler to limit frame rate within main menu */
190 void limitFrameRate();
192 /** update size of topleftext element */
193 void updateTopLeftTextSize();
195 /** device to draw at */
196 irr::IrrlichtDevice* m_device;
197 /** parent gui element */
198 gui::IGUIElement* m_parent;
199 /** manager to add menus to */
200 IMenuManager* m_menumanager;
201 /** scene manager to add scene elements to */
202 scene::ISceneManager* m_smgr;
203 /** pointer to data beeing transfered back to main game handling */
204 MainMenuData* m_data;
205 /** pointer to texture source */
206 ISimpleTextureSource* m_texture_source;
207 /** pointer to soundmanager*/
208 ISoundManager* m_sound_manager;
210 /** representation of form source to be used in mainmenu formspec */
211 FormspecFormSource* m_formspecgui;
212 /** formspec input receiver */
213 TextDestGuiEngine* m_buttonhandler;
214 /** the formspec menu */
215 GUIFormSpecMenu* m_menu;
217 /** reference to kill variable managed by SIGINT handler */
220 /** variable used to abort menu and return back to main game handling */
223 /** scripting interface */
224 MainMenuScripting* m_script;
226 /** script basefolder */
227 std::string m_scriptdir;
230 * draw background layer
231 * @param driver to use for drawing
233 void drawBackground(video::IVideoDriver* driver);
236 * @param driver to use for drawing
238 void drawOverlay(video::IVideoDriver* driver);
241 * @param driver to use for drawing
243 void drawHeader(video::IVideoDriver* driver);
246 * @param driver to use for drawing
248 void drawFooter(video::IVideoDriver* driver);
251 * load a texture for a specified layer
252 * @param layer draw layer to specify texture
253 * @param texturepath full path of texture to load
255 bool setTexture(texture_layer layer, std::string texturepath,
256 bool tile_image, unsigned int minsize);
259 * download a file using curl
260 * @param url url to download
261 * @param target file to store to
263 static bool downloadFile(std::string url,std::string target);
265 /** array containing pointers to current specified texture layers */
266 image_definition m_textures[TEX_LAYER_MAX];
268 /** draw version string in topleft corner */
272 * specify text to be appended to version string
275 void setTopleftText(std::string append);
277 /** pointer to gui element shown at topleft corner */
278 irr::gui::IGUIStaticText* m_irr_toplefttext;
279 /** and text that is in it */
280 EnrichedString m_toplefttext;
282 /** initialize cloud subsystem */
284 /** do preprocessing for cloud subsystem */
285 void cloudPreProcess();
286 /** do postprocessing for cloud subsystem */
287 void cloudPostProcess();
289 /** internam data required for drawing clouds */
291 /** delta time since last cloud processing */
293 /** absolute time of last cloud processing */
295 /** pointer to cloud class */
297 /** camera required for drawing clouds */
298 scene::ICameraSceneNode* camera;
301 /** is drawing of clouds enabled atm */
302 bool m_clouds_enabled;
303 /** data used to draw clouds */
306 /** start playing a sound and return handle */
307 s32 playSound(SimpleSoundSpec spec, bool looped);
308 /** stop playing a sound started with playSound() */
309 void stopSound(s32 handle);
316 #endif /* GUI_ENGINE_H_ */