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 "guiLuaApi.h"
30 #include "guiFormSpecMenu.h"
33 /******************************************************************************/
34 /* Typedefs and macros */
35 /******************************************************************************/
36 #define MAX_MENUBAR_BTN_COUNT 10
37 #define MAX_MENUBAR_BTN_ID 256
38 #define MIN_MENUBAR_BTN_ID (MAX_MENUBAR_BTN_ID - MAX_MENUBAR_BTN_COUNT)
40 /** texture layer ids */
42 TEX_LAYER_BACKGROUND = 0,
49 /******************************************************************************/
50 /* forward declarations */
51 /******************************************************************************/
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;
90 void fetchSounds(const std::string &name,
91 std::set<std::string> &dst_paths,
92 std::set<std::string> &dst_datas)
94 if(m_fetched.count(name))
96 m_fetched.insert(name);
98 base = porting::path_share + DIR_DELIM + "sounds";
99 dst_paths.insert(base + DIR_DELIM + name + ".ogg");
102 dst_paths.insert(base + DIR_DELIM + name + "."+itos(i)+".ogg");
103 base = porting::path_user + DIR_DELIM + "sounds";
104 dst_paths.insert(base + DIR_DELIM + name + ".ogg");
106 dst_paths.insert(base + DIR_DELIM + name + "."+itos(i)+".ogg");
110 /** implementation of main menu based uppon formspecs */
113 /** TextDestGuiEngine needs to transfer data to engine */
114 friend class TextDestGuiEngine;
115 /** guiLuaApi is used to initialize contained stack */
116 friend class guiLuaApi;
119 * default constructor
120 * @param dev device to draw at
121 * @param parent parent gui element
122 * @param menumgr manager to add menus to
123 * @param smgr scene manager to add scene elements to
124 * @param data struct to transfer data to main game handling
126 GUIEngine( irr::IrrlichtDevice* dev,
127 gui::IGUIElement* parent,
128 IMenuManager *menumgr,
129 scene::ISceneManager* smgr,
132 /** default destructor */
133 virtual ~GUIEngine();
135 s32 playSound(SimpleSoundSpec spec, bool looped);
136 void stopSound(s32 handle);
140 * process field data recieved from formspec
141 * @param fields data in field format
143 void handleButtons(std::map<std::string, std::string> fields);
145 * process events received from formspec
146 * @param text events in textual form
148 void handleEvent(std::string text);
151 * return dir of current menuscript
153 std::string getScriptDir() {
159 /* run main menu loop */
162 /** handler to limit frame rate within main menu */
163 void limitFrameRate();
165 /** device to draw at */
166 irr::IrrlichtDevice* m_device;
167 /** parent gui element */
168 gui::IGUIElement* m_parent;
169 /** manager to add menus to */
170 IMenuManager* m_menumanager;
171 /** scene manager to add scene elements to */
172 scene::ISceneManager* m_smgr;
173 /** pointer to data beeing transfered back to main game handling */
174 MainMenuData* m_data;
175 /** pointer to soundmanager*/
176 ISoundManager* m_sound_manager;
178 /** representation of form source to be used in mainmenu formspec */
179 FormspecFormSource* m_formspecgui;
180 /** formspec input receiver */
181 TextDestGuiEngine* m_buttonhandler;
182 /** the formspec menu */
183 GUIFormSpecMenu* m_menu;
185 /** variable used to abort menu and return back to main game handling */
189 * initialize lua stack
190 * @param L stack to initialize
192 void initalize_api(lua_State * L);
196 * @param script full path to script to run
198 bool runScript(std::string script);
201 * script error handler to process errors within lua
203 void scriptError(const char *fmt, ...);
206 lua_State* m_engineluastack;
207 /** lua internal stack number of error handler*/
208 int m_luaerrorhandler;
210 /** script basefolder */
211 std::string m_scriptdir;
214 * draw background layer
215 * @param driver to use for drawing
217 void drawBackground(video::IVideoDriver* driver);
220 * @param driver to use for drawing
222 void drawOverlay(video::IVideoDriver* driver);
225 * @param driver to use for drawing
227 void drawHeader(video::IVideoDriver* driver);
230 * @param driver to use for drawing
232 void drawFooter(video::IVideoDriver* driver);
235 * load a texture for a specified layer
236 * @param layer draw layer to specify texture
237 * @param texturepath full path of texture to load
239 bool setTexture(texture_layer layer,std::string texturepath);
242 * download a file using curl
243 * @param url url to download
244 * @param target file to store to
246 bool downloadFile(std::string url,std::string target);
248 /** array containing pointers to current specified texture layers */
249 video::ITexture* m_textures[TEX_LAYER_MAX];
251 /** draw version string in topleft corner */
255 * specify text to be appended to version string
258 void setTopleftText(std::string append);
260 /** pointer to gui element shown at topleft corner */
261 irr::gui::IGUIStaticText* m_irr_toplefttext;
263 /** initialize cloud subsystem */
265 /** do preprocessing for cloud subsystem */
266 void cloudPreProcess();
267 /** do postprocessing for cloud subsystem */
268 void cloudPostProcess();
270 /** internam data required for drawing clouds */
272 /** delta time since last cloud processing */
274 /** absolute time of last cloud processing */
276 /** pointer to cloud class */
278 /** camera required for drawing clouds */
279 scene::ICameraSceneNode* camera;
282 /** is drawing of clouds enabled atm */
283 bool m_clouds_enabled;
284 /** data used to draw clouds */
291 #endif /* GUI_ENGINE_H_ */