]> git.lizzy.rs Git - minetest.git/blob - src/guiEngine.h
Decoration: Handle facedir and wallmounted param2types with schematic rotation
[minetest.git] / src / guiEngine.h
1 /*
2 Minetest
3 Copyright (C) 2013 sapier
4
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.
9
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.
14
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.
18 */
19
20 #ifndef GUI_ENGINE_H_
21 #define GUI_ENGINE_H_
22
23 /******************************************************************************/
24 /* Includes                                                                   */
25 /******************************************************************************/
26 #include "irrlichttypes.h"
27 #include "modalMenu.h"
28 #include "clouds.h"
29 #include "guiLuaApi.h"
30 #include "guiFormSpecMenu.h"
31
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)
38
39 /** texture layer ids */
40 typedef enum {
41         TEX_LAYER_BACKGROUND = 0,
42         TEX_LAYER_OVERLAY,
43         TEX_LAYER_HEADER,
44         TEX_LAYER_FOOTER,
45         TEX_LAYER_MAX
46 } texture_layer;
47
48 /******************************************************************************/
49 /* forward declarations                                                       */
50 /******************************************************************************/
51 class GUIEngine;
52 struct MainMenuData;
53
54 /******************************************************************************/
55 /* declarations                                                               */
56 /******************************************************************************/
57
58 /** GUIEngine specific implementation of TextDest used within guiFormSpecMenu */
59 class TextDestGuiEngine : public TextDest
60 {
61 public:
62         /**
63          * default constructor
64          * @param engine the engine data is transmitted for further processing
65          */
66         TextDestGuiEngine(GUIEngine* engine);
67         /**
68          * receive fields transmitted by guiFormSpecMenu
69          * @param fields map containing formspec field elements currently active
70          */
71         void gotText(std::map<std::string, std::string> fields);
72
73         /**
74          * receive text/events transmitted by guiFormSpecMenu
75          * @param text textual representation of event
76          */
77         void gotText(std::wstring text);
78 private:
79         /** target to transmit data to */
80         GUIEngine* m_engine;
81 };
82
83
84 /** implementation of main menu based uppon formspecs */
85 class GUIEngine {
86 public:
87         /** TextDestGuiEngine needs to transfer data to engine */
88         friend class TextDestGuiEngine;
89         /** guiLuaApi is used to initialize contained stack */
90         friend class guiLuaApi;
91
92         /**
93          * default constructor
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
99          */
100         GUIEngine(      irr::IrrlichtDevice* dev,
101                                 gui::IGUIElement* parent,
102                                 IMenuManager *menumgr,
103                                 scene::ISceneManager* smgr,
104                                 MainMenuData* data);
105
106         /** default destructor */
107         virtual ~GUIEngine();
108
109 protected:
110         /**
111          * process field data recieved from formspec
112          * @param fields data in field format
113          */
114         void handleButtons(std::map<std::string, std::string> fields);
115         /**
116          * process events received from formspec
117          * @param text events in textual form
118          */
119         void handleEvent(std::string text);
120
121         /**
122          * return dir of current menuscript
123          */
124         std::string getScriptDir() {
125                 return m_scriptdir;
126         }
127
128 private:
129
130         /* run main menu loop */
131         void run();
132
133         /** handler to limit frame rate within main menu */
134         void limitFrameRate();
135
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;
146
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;
153
154         /** variable used to abort menu and return back to main game handling */
155         bool                                    m_startgame;
156
157         /**
158          * initialize lua stack
159          * @param L stack to initialize
160          */
161         void initalize_api(lua_State * L);
162
163         /**
164          * run a lua script
165          * @param script full path to script to run
166          */
167         bool runScript(std::string script);
168
169         /**
170          * script error handler to process errors within lua
171          */
172         void scriptError(const char *fmt, ...);
173
174         /** lua stack */
175         lua_State*                              m_engineluastack;
176         /** lua internal stack number of error handler*/
177         int                                             m_luaerrorhandler;
178
179         /** script basefolder */
180         std::string                             m_scriptdir;
181
182         /**
183          * draw background layer
184          * @param driver to use for drawing
185          */
186         void drawBackground(video::IVideoDriver* driver);
187         /**
188          * draw overlay layer
189          * @param driver to use for drawing
190          */
191         void drawOverlay(video::IVideoDriver* driver);
192         /**
193          * draw header layer
194          * @param driver to use for drawing
195          */
196         void drawHeader(video::IVideoDriver* driver);
197         /**
198          * draw footer layer
199          * @param driver to use for drawing
200          */
201         void drawFooter(video::IVideoDriver* driver);
202
203         /**
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
207          */
208         bool setTexture(texture_layer layer,std::string texturepath);
209
210         /**
211          * download a file using curl
212          * @param url url to download
213          * @param target file to store to
214          */
215         bool downloadFile(std::string url,std::string target);
216
217         /** array containing pointers to current specified texture layers */
218         video::ITexture*                m_textures[TEX_LAYER_MAX];
219
220         /** draw version string in topleft corner */
221         void drawVersion();
222
223         /**
224          * specify text to be appended to version string
225          * @param text to set
226          */
227         void setTopleftText(std::string append);
228
229         /** pointer to gui element shown at topleft corner */
230         irr::gui::IGUIStaticText*       m_irr_toplefttext;
231
232         /** initialize cloud subsystem */
233         void cloudInit();
234         /** do preprocessing for cloud subsystem */
235         void cloudPreProcess();
236         /** do postprocessing for cloud subsystem */
237         void cloudPostProcess();
238
239         /** internam data required for drawing clouds */
240         struct clouddata {
241                 /** delta time since last cloud processing */
242                 f32             dtime;
243                 /** absolute time of last cloud processing */
244                 u32             lasttime;
245                 /** pointer to cloud class */
246                 Clouds* clouds;
247                 /** camera required for drawing clouds */
248                 scene::ICameraSceneNode* camera;
249         };
250
251         /** is drawing of clouds enabled atm */
252         bool                                    m_clouds_enabled;
253         /** data used to draw clouds */
254         clouddata                               m_cloud;
255
256 };
257
258
259
260 #endif /* GUI_ENGINE_H_ */