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"
29 #include "guiFormSpecMenu.h"
32 /******************************************************************************/
33 /* Typedefs and macros */
34 /******************************************************************************/
35 #define MAX_MENUBAR_BTN_COUNT 10
36 #define MAX_MENUBAR_BTN_ID 256
37 #define MIN_MENUBAR_BTN_ID (MAX_MENUBAR_BTN_ID - MAX_MENUBAR_BTN_COUNT)
39 /** texture layer ids */
41 TEX_LAYER_BACKGROUND = 0,
48 /******************************************************************************/
49 /* forward declarations */
50 /******************************************************************************/
52 class MainMenuScripting;
54 struct SimpleSoundSpec;
56 /******************************************************************************/
58 /******************************************************************************/
60 /** GUIEngine specific implementation of TextDest used within guiFormSpecMenu */
61 class TextDestGuiEngine : public TextDest
66 * @param engine the engine data is transmitted for further processing
68 TextDestGuiEngine(GUIEngine* engine);
70 * receive fields transmitted by guiFormSpecMenu
71 * @param fields map containing formspec field elements currently active
73 void gotText(std::map<std::string, std::string> fields);
76 * receive text/events transmitted by guiFormSpecMenu
77 * @param text textual representation of event
79 void gotText(std::wstring text);
81 /** target to transmit data to */
85 class MenuMusicFetcher: public OnDemandSoundFetcher
87 std::set<std::string> m_fetched;
89 void fetchSounds(const std::string &name,
90 std::set<std::string> &dst_paths,
91 std::set<std::string> &dst_datas);
94 /** implementation of main menu based uppon formspecs */
96 /** grant ModApiMainMenu access to private members */
97 friend class ModApiMainMenu;
101 * default constructor
102 * @param dev device to draw at
103 * @param parent parent gui element
104 * @param menumgr manager to add menus to
105 * @param smgr scene manager to add scene elements to
106 * @param data struct to transfer data to main game handling
108 GUIEngine( irr::IrrlichtDevice* dev,
109 gui::IGUIElement* parent,
110 IMenuManager *menumgr,
111 scene::ISceneManager* smgr,
114 /** default destructor */
115 virtual ~GUIEngine();
118 * return MainMenuScripting interface
120 MainMenuScripting* getScriptIface() {
125 * return dir of current menuscript
127 std::string getScriptDir() {
133 /** find and run the main menu script */
134 bool loadMainMenuScript();
136 /** run main menu loop */
139 /** handler to limit frame rate within main menu */
140 void limitFrameRate();
142 /** device to draw at */
143 irr::IrrlichtDevice* m_device;
144 /** parent gui element */
145 gui::IGUIElement* m_parent;
146 /** manager to add menus to */
147 IMenuManager* m_menumanager;
148 /** scene manager to add scene elements to */
149 scene::ISceneManager* m_smgr;
150 /** pointer to data beeing transfered back to main game handling */
151 MainMenuData* m_data;
152 /** pointer to soundmanager*/
153 ISoundManager* m_sound_manager;
155 /** representation of form source to be used in mainmenu formspec */
156 FormspecFormSource* m_formspecgui;
157 /** formspec input receiver */
158 TextDestGuiEngine* m_buttonhandler;
159 /** the formspec menu */
160 GUIFormSpecMenu* m_menu;
162 /** variable used to abort menu and return back to main game handling */
165 /** scripting interface */
166 MainMenuScripting* m_script;
168 /** script basefolder */
169 std::string m_scriptdir;
172 * draw background layer
173 * @param driver to use for drawing
175 void drawBackground(video::IVideoDriver* driver);
178 * @param driver to use for drawing
180 void drawOverlay(video::IVideoDriver* driver);
183 * @param driver to use for drawing
185 void drawHeader(video::IVideoDriver* driver);
188 * @param driver to use for drawing
190 void drawFooter(video::IVideoDriver* driver);
193 * load a texture for a specified layer
194 * @param layer draw layer to specify texture
195 * @param texturepath full path of texture to load
197 bool setTexture(texture_layer layer,std::string texturepath);
200 * download a file using curl
201 * @param url url to download
202 * @param target file to store to
204 bool downloadFile(std::string url,std::string target);
206 /** array containing pointers to current specified texture layers */
207 video::ITexture* m_textures[TEX_LAYER_MAX];
209 /** draw version string in topleft corner */
213 * specify text to be appended to version string
216 void setTopleftText(std::string append);
218 /** pointer to gui element shown at topleft corner */
219 irr::gui::IGUIStaticText* m_irr_toplefttext;
221 /** initialize cloud subsystem */
223 /** do preprocessing for cloud subsystem */
224 void cloudPreProcess();
225 /** do postprocessing for cloud subsystem */
226 void cloudPostProcess();
228 /** internam data required for drawing clouds */
230 /** delta time since last cloud processing */
232 /** absolute time of last cloud processing */
234 /** pointer to cloud class */
236 /** camera required for drawing clouds */
237 scene::ICameraSceneNode* camera;
240 /** is drawing of clouds enabled atm */
241 bool m_clouds_enabled;
242 /** data used to draw clouds */
245 /** start playing a sound and return handle */
246 s32 playSound(SimpleSoundSpec spec, bool looped);
247 /** stop playing a sound started with playSound() */
248 void stopSound(s32 handle);
255 #endif /* GUI_ENGINE_H_ */