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"
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(const StringMap &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 /** update size of topleftext element */
192 void updateTopLeftTextSize();
194 /** device to draw at */
195 irr::IrrlichtDevice* m_device;
196 /** parent gui element */
197 gui::IGUIElement* m_parent;
198 /** manager to add menus to */
199 IMenuManager* m_menumanager;
200 /** scene manager to add scene elements to */
201 scene::ISceneManager* m_smgr;
202 /** pointer to data beeing transfered back to main game handling */
203 MainMenuData* m_data;
204 /** pointer to texture source */
205 ISimpleTextureSource* m_texture_source;
206 /** pointer to soundmanager*/
207 ISoundManager* m_sound_manager;
209 /** representation of form source to be used in mainmenu formspec */
210 FormspecFormSource* m_formspecgui;
211 /** formspec input receiver */
212 TextDestGuiEngine* m_buttonhandler;
213 /** the formspec menu */
214 GUIFormSpecMenu* m_menu;
216 /** reference to kill variable managed by SIGINT handler */
219 /** variable used to abort menu and return back to main game handling */
222 /** scripting interface */
223 MainMenuScripting* m_script;
225 /** script basefolder */
226 std::string m_scriptdir;
229 * draw background layer
230 * @param driver to use for drawing
232 void drawBackground(video::IVideoDriver* driver);
235 * @param driver to use for drawing
237 void drawOverlay(video::IVideoDriver* driver);
240 * @param driver to use for drawing
242 void drawHeader(video::IVideoDriver* driver);
245 * @param driver to use for drawing
247 void drawFooter(video::IVideoDriver* driver);
250 * load a texture for a specified layer
251 * @param layer draw layer to specify texture
252 * @param texturepath full path of texture to load
254 bool setTexture(texture_layer layer, std::string texturepath,
255 bool tile_image, unsigned int minsize);
258 * download a file using curl
259 * @param url url to download
260 * @param target file to store to
262 static bool downloadFile(std::string url,std::string target);
264 /** array containing pointers to current specified texture layers */
265 image_definition m_textures[TEX_LAYER_MAX];
267 /** draw version string in topleft corner */
271 * specify text to be appended to version string
274 void setTopleftText(std::string append);
276 /** pointer to gui element shown at topleft corner */
277 irr::gui::IGUIStaticText* m_irr_toplefttext;
279 /** initialize cloud subsystem */
281 /** do preprocessing for cloud subsystem */
282 void cloudPreProcess();
283 /** do postprocessing for cloud subsystem */
284 void cloudPostProcess();
286 /** internam data required for drawing clouds */
288 /** delta time since last cloud processing */
290 /** absolute time of last cloud processing */
292 /** pointer to cloud class */
294 /** camera required for drawing clouds */
295 scene::ICameraSceneNode* camera;
298 /** is drawing of clouds enabled atm */
299 bool m_clouds_enabled;
300 /** data used to draw clouds */
303 /** start playing a sound and return handle */
304 s32 playSound(SimpleSoundSpec spec, bool looped);
305 /** stop playing a sound started with playSound() */
306 void stopSound(s32 handle);
313 #endif /* GUI_ENGINE_H_ */