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"
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 /******************************************************************************/
54 /******************************************************************************/
56 /******************************************************************************/
58 /** GUIEngine specific implementation of TextDest used within guiFormSpecMenu */
59 class TextDestGuiEngine : public TextDest
64 * @param engine the engine data is transmitted for further processing
66 TextDestGuiEngine(GUIEngine* engine);
68 * receive fields transmitted by guiFormSpecMenu
69 * @param fields map containing formspec field elements currently active
71 void gotText(std::map<std::string, std::string> fields);
74 * receive text/events transmitted by guiFormSpecMenu
75 * @param text textual representation of event
77 void gotText(std::wstring text);
79 /** target to transmit data to */
84 /** implementation of main menu based uppon formspecs */
87 /** TextDestGuiEngine needs to transfer data to engine */
88 friend class TextDestGuiEngine;
89 /** guiLuaApi is used to initialize contained stack */
90 friend class guiLuaApi;
94 * @param dev device to draw at
95 * @param parent parent gui element
96 * @param menumgr manager to add menus to
97 * @param smgr scene manager to add scene elements to
98 * @param data struct to transfer data to main game handling
100 GUIEngine( irr::IrrlichtDevice* dev,
101 gui::IGUIElement* parent,
102 IMenuManager *menumgr,
103 scene::ISceneManager* smgr,
106 /** default destructor */
107 virtual ~GUIEngine();
111 * process field data recieved from formspec
112 * @param fields data in field format
114 void handleButtons(std::map<std::string, std::string> fields);
116 * process events received from formspec
117 * @param text events in textual form
119 void handleEvent(std::string text);
122 * return dir of current menuscript
124 std::string getScriptDir() {
130 /* run main menu loop */
133 /** handler to limit frame rate within main menu */
134 void limitFrameRate();
136 /** device to draw at */
137 irr::IrrlichtDevice* m_device;
138 /** parent gui element */
139 gui::IGUIElement* m_parent;
140 /** manager to add menus to */
141 IMenuManager* m_menumanager;
142 /** scene manager to add scene elements to */
143 scene::ISceneManager* m_smgr;
144 /** pointer to data beeing transfered back to main game handling */
145 MainMenuData* m_data;
147 /** representation of form source to be used in mainmenu formspec */
148 FormspecFormSource* m_formspecgui;
149 /** formspec input receiver */
150 TextDestGuiEngine* m_buttonhandler;
151 /** the formspec menu */
152 GUIFormSpecMenu* m_menu;
154 /** variable used to abort menu and return back to main game handling */
158 * initialize lua stack
159 * @param L stack to initialize
161 void initalize_api(lua_State * L);
165 * @param script full path to script to run
167 bool runScript(std::string script);
170 * script error handler to process errors within lua
172 void scriptError(const char *fmt, ...);
175 lua_State* m_engineluastack;
176 /** lua internal stack number of error handler*/
177 int m_luaerrorhandler;
179 /** script basefolder */
180 std::string m_scriptdir;
183 * draw background layer
184 * @param driver to use for drawing
186 void drawBackground(video::IVideoDriver* driver);
189 * @param driver to use for drawing
191 void drawOverlay(video::IVideoDriver* driver);
194 * @param driver to use for drawing
196 void drawHeader(video::IVideoDriver* driver);
199 * @param driver to use for drawing
201 void drawFooter(video::IVideoDriver* driver);
204 * load a texture for a specified layer
205 * @param layer draw layer to specify texture
206 * @param texturepath full path of texture to load
208 bool setTexture(texture_layer layer,std::string texturepath);
211 * download a file using curl
212 * @param url url to download
213 * @param target file to store to
215 bool downloadFile(std::string url,std::string target);
217 /** array containing pointers to current specified texture layers */
218 video::ITexture* m_textures[TEX_LAYER_MAX];
220 /** draw version string in topleft corner */
224 * specify text to be appended to version string
227 void setTopleftText(std::string append);
229 /** pointer to gui element shown at topleft corner */
230 irr::gui::IGUIStaticText* m_irr_toplefttext;
232 /** initialize cloud subsystem */
234 /** do preprocessing for cloud subsystem */
235 void cloudPreProcess();
236 /** do postprocessing for cloud subsystem */
237 void cloudPostProcess();
239 /** internam data required for drawing clouds */
241 /** delta time since last cloud processing */
243 /** absolute time of last cloud processing */
245 /** pointer to cloud class */
247 /** camera required for drawing clouds */
248 scene::ICameraSceneNode* camera;
251 /** is drawing of clouds enabled atm */
252 bool m_clouds_enabled;
253 /** data used to draw clouds */
260 #endif /* GUI_ENGINE_H_ */