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,
115 /** default destructor */
116 virtual ~GUIEngine();
119 * return MainMenuScripting interface
121 MainMenuScripting* getScriptIface() {
126 * return dir of current menuscript
128 std::string getScriptDir() {
134 /** find and run the main menu script */
135 bool loadMainMenuScript();
137 /** run main menu loop */
140 /** handler to limit frame rate within main menu */
141 void limitFrameRate();
143 /** device to draw at */
144 irr::IrrlichtDevice* m_device;
145 /** parent gui element */
146 gui::IGUIElement* m_parent;
147 /** manager to add menus to */
148 IMenuManager* m_menumanager;
149 /** scene manager to add scene elements to */
150 scene::ISceneManager* m_smgr;
151 /** pointer to data beeing transfered back to main game handling */
152 MainMenuData* m_data;
153 /** pointer to soundmanager*/
154 ISoundManager* m_sound_manager;
156 /** representation of form source to be used in mainmenu formspec */
157 FormspecFormSource* m_formspecgui;
158 /** formspec input receiver */
159 TextDestGuiEngine* m_buttonhandler;
160 /** the formspec menu */
161 GUIFormSpecMenu* m_menu;
163 /** reference to kill variable managed by SIGINT handler */
166 /** variable used to abort menu and return back to main game handling */
169 /** scripting interface */
170 MainMenuScripting* m_script;
172 /** script basefolder */
173 std::string m_scriptdir;
176 * draw background layer
177 * @param driver to use for drawing
179 void drawBackground(video::IVideoDriver* driver);
182 * @param driver to use for drawing
184 void drawOverlay(video::IVideoDriver* driver);
187 * @param driver to use for drawing
189 void drawHeader(video::IVideoDriver* driver);
192 * @param driver to use for drawing
194 void drawFooter(video::IVideoDriver* driver);
197 * load a texture for a specified layer
198 * @param layer draw layer to specify texture
199 * @param texturepath full path of texture to load
201 bool setTexture(texture_layer layer,std::string texturepath);
204 * download a file using curl
205 * @param url url to download
206 * @param target file to store to
208 bool downloadFile(std::string url,std::string target);
210 /** array containing pointers to current specified texture layers */
211 video::ITexture* m_textures[TEX_LAYER_MAX];
213 /** draw version string in topleft corner */
217 * specify text to be appended to version string
220 void setTopleftText(std::string append);
222 /** pointer to gui element shown at topleft corner */
223 irr::gui::IGUIStaticText* m_irr_toplefttext;
225 /** initialize cloud subsystem */
227 /** do preprocessing for cloud subsystem */
228 void cloudPreProcess();
229 /** do postprocessing for cloud subsystem */
230 void cloudPostProcess();
232 /** internam data required for drawing clouds */
234 /** delta time since last cloud processing */
236 /** absolute time of last cloud processing */
238 /** pointer to cloud class */
240 /** camera required for drawing clouds */
241 scene::ICameraSceneNode* camera;
244 /** is drawing of clouds enabled atm */
245 bool m_clouds_enabled;
246 /** data used to draw clouds */
249 /** start playing a sound and return handle */
250 s32 playSound(SimpleSoundSpec spec, bool looped);
251 /** stop playing a sound started with playSound() */
252 void stopSound(s32 handle);
259 #endif /* GUI_ENGINE_H_ */