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 "modalMenu.h"
27 #include "guiFormSpecMenu.h"
28 #include "client/sound.h"
29 #include "client/tile.h"
30 #include "util/enriched_string.h"
32 /******************************************************************************/
33 /* Typedefs and macros */
34 /******************************************************************************/
35 /** texture layer ids */
37 TEX_LAYER_BACKGROUND = 0,
45 video::ITexture *texture = nullptr;
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) : m_engine(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(const std::wstring &text);
85 /** target to transmit data to */
86 GUIEngine *m_engine = nullptr;
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) : m_driver(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 = nullptr;
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;
141 friend class ModApiSound;
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(JoystickController *joystick,
153 gui::IGUIElement *parent,
154 IMenuManager *menumgr,
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(const std::string &serialized_fct,
179 const std::string &serialized_params);
183 /** find and run the main menu script */
184 bool loadMainMenuScript();
186 /** run main menu loop */
189 /** update size of topleftext element */
190 void updateTopLeftTextSize();
192 /** parent gui element */
193 gui::IGUIElement *m_parent = nullptr;
194 /** manager to add menus to */
195 IMenuManager *m_menumanager = nullptr;
196 /** scene manager to add scene elements to */
197 scene::ISceneManager *m_smgr = nullptr;
198 /** pointer to data beeing transfered back to main game handling */
199 MainMenuData *m_data = nullptr;
200 /** pointer to texture source */
201 ISimpleTextureSource *m_texture_source = nullptr;
202 /** pointer to soundmanager*/
203 ISoundManager *m_sound_manager = nullptr;
205 /** representation of form source to be used in mainmenu formspec */
206 FormspecFormSource *m_formspecgui = nullptr;
207 /** formspec input receiver */
208 TextDestGuiEngine *m_buttonhandler = nullptr;
209 /** the formspec menu */
210 GUIFormSpecMenu *m_menu = nullptr;
212 /** reference to kill variable managed by SIGINT handler */
215 /** variable used to abort menu and return back to main game handling */
216 bool m_startgame = false;
218 /** scripting interface */
219 MainMenuScripting *m_script = nullptr;
221 /** script basefolder */
222 std::string m_scriptdir = "";
225 * draw background layer
226 * @param driver to use for drawing
228 void drawBackground(video::IVideoDriver *driver);
231 * @param driver to use for drawing
233 void drawOverlay(video::IVideoDriver *driver);
236 * @param driver to use for drawing
238 void drawHeader(video::IVideoDriver *driver);
241 * @param driver to use for drawing
243 void drawFooter(video::IVideoDriver *driver);
246 * load a texture for a specified layer
247 * @param layer draw layer to specify texture
248 * @param texturepath full path of texture to load
250 bool setTexture(texture_layer layer, std::string texturepath,
251 bool tile_image, unsigned int minsize);
254 * download a file using curl
255 * @param url url to download
256 * @param target file to store to
258 static bool downloadFile(const std::string &url, const std::string &target);
260 /** array containing pointers to current specified texture layers */
261 image_definition m_textures[TEX_LAYER_MAX];
264 * specify text to appear as top left string
267 void setTopleftText(const std::string &text);
269 /** pointer to gui element shown at topleft corner */
270 irr::gui::IGUIStaticText *m_irr_toplefttext = nullptr;
271 /** and text that is in it */
272 EnrichedString m_toplefttext;
274 /** initialize cloud subsystem */
276 /** do preprocessing for cloud subsystem */
277 void cloudPreProcess();
278 /** do postprocessing for cloud subsystem */
279 void cloudPostProcess();
281 /** internam data required for drawing clouds */
283 /** delta time since last cloud processing */
285 /** absolute time of last cloud processing */
287 /** pointer to cloud class */
288 Clouds *clouds = nullptr;
289 /** camera required for drawing clouds */
290 scene::ICameraSceneNode *camera = nullptr;
293 /** is drawing of clouds enabled atm */
294 bool m_clouds_enabled = true;
295 /** data used to draw clouds */
298 /** start playing a sound and return handle */
299 s32 playSound(SimpleSoundSpec spec, bool looped);
300 /** stop playing a sound started with playSound() */
301 void stopSound(s32 handle);