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,
45 video::ITexture* texture;
50 /******************************************************************************/
51 /* forward declarations */
52 /******************************************************************************/
54 class MainMenuScripting;
58 /******************************************************************************/
60 /******************************************************************************/
62 /** GUIEngine specific implementation of TextDest used within guiFormSpecMenu */
63 class TextDestGuiEngine : public TextDest
68 * @param engine the engine data is transmitted for further processing
70 TextDestGuiEngine(GUIEngine* engine);
73 * receive fields transmitted by guiFormSpecMenu
74 * @param fields map containing formspec field elements currently active
76 void gotText(std::map<std::string, std::string> fields);
79 * receive text/events transmitted by guiFormSpecMenu
80 * @param text textual representation of event
82 void gotText(std::wstring text);
85 /** target to transmit data to */
89 /** GUIEngine specific implementation of ISimpleTextureSource */
90 class MenuTextureSource : public ISimpleTextureSource
95 * @param driver the video driver to load textures from
97 MenuTextureSource(video::IVideoDriver *driver);
100 * destructor, removes all loaded textures
102 virtual ~MenuTextureSource();
105 * get a texture, loading it if required
106 * @param name path to the texture
107 * @param id receives the texture ID, always 0 in this implementation
109 video::ITexture* getTexture(const std::string &name, u32 *id = NULL);
112 /** driver to get textures from */
113 video::IVideoDriver *m_driver;
114 /** set of texture names to delete */
115 std::set<std::string> m_to_delete;
118 /** GUIEngine specific implementation of OnDemandSoundFetcher */
119 class MenuMusicFetcher: public OnDemandSoundFetcher
123 * get sound file paths according to sound name
124 * @param name sound name
125 * @param dst_paths receives possible paths to sound files
126 * @param dst_datas receives binary sound data (not used here)
128 void fetchSounds(const std::string &name,
129 std::set<std::string> &dst_paths,
130 std::set<std::string> &dst_datas);
133 /** set of fetched sound names */
134 std::set<std::string> m_fetched;
137 /** implementation of main menu based uppon formspecs */
139 /** grant ModApiMainMenu access to private members */
140 friend class ModApiMainMenu;
144 * default constructor
145 * @param dev device to draw at
146 * @param parent parent gui element
147 * @param menumgr manager to add menus to
148 * @param smgr scene manager to add scene elements to
149 * @param data struct to transfer data to main game handling
151 GUIEngine( irr::IrrlichtDevice* dev,
152 gui::IGUIElement* parent,
153 IMenuManager *menumgr,
154 scene::ISceneManager* smgr,
158 /** default destructor */
159 virtual ~GUIEngine();
162 * return MainMenuScripting interface
164 MainMenuScripting* getScriptIface()
170 * return dir of current menuscript
172 std::string getScriptDir()
177 /** pass async callback to scriptengine **/
178 unsigned int queueAsync(std::string serialized_fct,std::string serialized_params);
182 /** find and run the main menu script */
183 bool loadMainMenuScript();
185 /** run main menu loop */
188 /** handler to limit frame rate within main menu */
189 void limitFrameRate();
191 /** device to draw at */
192 irr::IrrlichtDevice* m_device;
193 /** parent gui element */
194 gui::IGUIElement* m_parent;
195 /** manager to add menus to */
196 IMenuManager* m_menumanager;
197 /** scene manager to add scene elements to */
198 scene::ISceneManager* m_smgr;
199 /** pointer to data beeing transfered back to main game handling */
200 MainMenuData* m_data;
201 /** pointer to texture source */
202 ISimpleTextureSource* m_texture_source;
203 /** pointer to soundmanager*/
204 ISoundManager* m_sound_manager;
206 /** representation of form source to be used in mainmenu formspec */
207 FormspecFormSource* m_formspecgui;
208 /** formspec input receiver */
209 TextDestGuiEngine* m_buttonhandler;
210 /** the formspec menu */
211 GUIFormSpecMenu* m_menu;
213 /** reference to kill variable managed by SIGINT handler */
216 /** variable used to abort menu and return back to main game handling */
219 /** scripting interface */
220 MainMenuScripting* m_script;
222 /** script basefolder */
223 std::string m_scriptdir;
226 * draw background layer
227 * @param driver to use for drawing
229 void drawBackground(video::IVideoDriver* driver);
232 * @param driver to use for drawing
234 void drawOverlay(video::IVideoDriver* driver);
237 * @param driver to use for drawing
239 void drawHeader(video::IVideoDriver* driver);
242 * @param driver to use for drawing
244 void drawFooter(video::IVideoDriver* driver);
247 * load a texture for a specified layer
248 * @param layer draw layer to specify texture
249 * @param texturepath full path of texture to load
251 bool setTexture(texture_layer layer, std::string texturepath,
252 bool tile_image, unsigned int minsize);
255 * download a file using curl
256 * @param url url to download
257 * @param target file to store to
259 static bool downloadFile(std::string url,std::string target);
261 /** array containing pointers to current specified texture layers */
262 image_definition m_textures[TEX_LAYER_MAX];
264 /** draw version string in topleft corner */
268 * specify text to be appended to version string
271 void setTopleftText(std::string append);
273 /** pointer to gui element shown at topleft corner */
274 irr::gui::IGUIStaticText* m_irr_toplefttext;
276 /** initialize cloud subsystem */
278 /** do preprocessing for cloud subsystem */
279 void cloudPreProcess();
280 /** do postprocessing for cloud subsystem */
281 void cloudPostProcess();
283 /** internam data required for drawing clouds */
285 /** delta time since last cloud processing */
287 /** absolute time of last cloud processing */
289 /** pointer to cloud class */
291 /** camera required for drawing clouds */
292 scene::ICameraSceneNode* camera;
295 /** is drawing of clouds enabled atm */
296 bool m_clouds_enabled;
297 /** data used to draw clouds */
300 /** start playing a sound and return handle */
301 s32 playSound(SimpleSoundSpec spec, bool looped);
302 /** stop playing a sound started with playSound() */
303 void stopSound(s32 handle);
310 #endif /* GUI_ENGINE_H_ */