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.
22 /******************************************************************************/
24 /******************************************************************************/
25 #include "irrlichttypes.h"
26 #include "guiFormSpecMenu.h"
27 #include "client/sound.h"
28 #include "client/tile.h"
29 #include "util/enriched_string.h"
31 /******************************************************************************/
32 /* Structs and macros */
33 /******************************************************************************/
34 /** texture layer ids */
36 TEX_LAYER_BACKGROUND = 0,
43 struct image_definition {
44 video::ITexture *texture = nullptr;
49 /******************************************************************************/
50 /* forward declarations */
51 /******************************************************************************/
53 class MainMenuScripting;
57 /******************************************************************************/
59 /******************************************************************************/
61 /** GUIEngine specific implementation of TextDest used within guiFormSpecMenu */
62 class TextDestGuiEngine : public TextDest
67 * @param engine the engine data is transmitted for further processing
69 TextDestGuiEngine(GUIEngine* engine) : m_engine(engine) {};
72 * receive fields transmitted by guiFormSpecMenu
73 * @param fields map containing formspec field elements currently active
75 void gotText(const StringMap &fields);
78 * receive text/events transmitted by guiFormSpecMenu
79 * @param text textual representation of event
81 void gotText(const std::wstring &text);
84 /** target to transmit data to */
85 GUIEngine *m_engine = nullptr;
88 /** GUIEngine specific implementation of ISimpleTextureSource */
89 class MenuTextureSource : public ISimpleTextureSource
94 * @param driver the video driver to load textures from
96 MenuTextureSource(video::IVideoDriver *driver) : m_driver(driver) {};
99 * destructor, removes all loaded textures
101 virtual ~MenuTextureSource();
104 * get a texture, loading it if required
105 * @param name path to the texture
106 * @param id receives the texture ID, always 0 in this implementation
108 video::ITexture *getTexture(const std::string &name, u32 *id = NULL);
111 /** driver to get textures from */
112 video::IVideoDriver *m_driver = nullptr;
113 /** set of texture names to delete */
114 std::set<std::string> m_to_delete;
117 /** GUIEngine specific implementation of OnDemandSoundFetcher */
118 class MenuMusicFetcher: public OnDemandSoundFetcher
122 * get sound file paths according to sound name
123 * @param name sound name
124 * @param dst_paths receives possible paths to sound files
125 * @param dst_datas receives binary sound data (not used here)
127 void fetchSounds(const std::string &name,
128 std::set<std::string> &dst_paths,
129 std::set<std::string> &dst_datas);
132 /** set of fetched sound names */
133 std::set<std::string> m_fetched;
136 /** implementation of main menu based uppon formspecs */
138 /** grant ModApiMainMenu access to private members */
139 friend class ModApiMainMenu;
140 friend class ModApiSound;
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(JoystickController *joystick,
152 gui::IGUIElement *parent,
153 IMenuManager *menumgr,
157 /** default destructor */
158 virtual ~GUIEngine();
161 * return MainMenuScripting interface
163 MainMenuScripting *getScriptIface()
169 * return dir of current menuscript
171 std::string getScriptDir()
176 /** pass async callback to scriptengine **/
177 unsigned int queueAsync(const std::string &serialized_fct,
178 const std::string &serialized_params);
182 /** find and run the main menu script */
183 bool loadMainMenuScript();
185 /** run main menu loop */
188 /** update size of topleftext element */
189 void updateTopLeftTextSize();
191 /** parent gui element */
192 gui::IGUIElement *m_parent = nullptr;
193 /** manager to add menus to */
194 IMenuManager *m_menumanager = nullptr;
195 /** scene manager to add scene elements to */
196 scene::ISceneManager *m_smgr = nullptr;
197 /** pointer to data beeing transfered back to main game handling */
198 MainMenuData *m_data = nullptr;
199 /** pointer to texture source */
200 ISimpleTextureSource *m_texture_source = nullptr;
201 /** pointer to soundmanager*/
202 ISoundManager *m_sound_manager = nullptr;
204 /** representation of form source to be used in mainmenu formspec */
205 FormspecFormSource *m_formspecgui = nullptr;
206 /** formspec input receiver */
207 TextDestGuiEngine *m_buttonhandler = nullptr;
208 /** the formspec menu */
209 GUIFormSpecMenu *m_menu = nullptr;
211 /** reference to kill variable managed by SIGINT handler */
214 /** variable used to abort menu and return back to main game handling */
215 bool m_startgame = false;
217 /** scripting interface */
218 MainMenuScripting *m_script = nullptr;
220 /** script basefolder */
221 std::string m_scriptdir = "";
223 void setFormspecPrepend(const std::string &fs);
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, const 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(const std::string &url, const std::string &target);
261 /** array containing pointers to current specified texture layers */
262 image_definition m_textures[TEX_LAYER_MAX];
265 * specify text to appear as top left string
268 void setTopleftText(const std::string &text);
270 /** pointer to gui element shown at topleft corner */
271 irr::gui::IGUIStaticText *m_irr_toplefttext = nullptr;
272 /** and text that is in it */
273 EnrichedString m_toplefttext;
275 /** initialize cloud subsystem */
277 /** do preprocessing for cloud subsystem */
278 void cloudPreProcess();
279 /** do postprocessing for cloud subsystem */
280 void cloudPostProcess(u32 frametime_min, IrrlichtDevice *device);
282 /** internam data required for drawing clouds */
284 /** delta time since last cloud processing */
286 /** absolute time of last cloud processing */
288 /** pointer to cloud class */
289 Clouds *clouds = nullptr;
290 /** camera required for drawing clouds */
291 scene::ICameraSceneNode *camera = nullptr;
294 /** is drawing of clouds enabled atm */
295 bool m_clouds_enabled = true;
296 /** data used to draw clouds */
299 /** start playing a sound and return handle */
300 s32 playSound(const SimpleSoundSpec &spec, bool looped);
301 /** stop playing a sound started with playSound() */
302 void stopSound(s32 handle);