]> git.lizzy.rs Git - minetest.git/blob - src/guiEngine.h
Fix selectionbox not honoring anaglyph mode 3d distortion
[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 "guiFormSpecMenu.h"
30 #include "sound.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 class MainMenuScripting;
53 struct MainMenuData;
54 struct SimpleSoundSpec;
55
56 /******************************************************************************/
57 /* declarations                                                               */
58 /******************************************************************************/
59
60 /** GUIEngine specific implementation of TextDest used within guiFormSpecMenu */
61 class TextDestGuiEngine : public TextDest
62 {
63 public:
64         /**
65          * default constructor
66          * @param engine the engine data is transmitted for further processing
67          */
68         TextDestGuiEngine(GUIEngine* engine);
69         /**
70          * receive fields transmitted by guiFormSpecMenu
71          * @param fields map containing formspec field elements currently active
72          */
73         void gotText(std::map<std::string, std::string> fields);
74
75         /**
76          * receive text/events transmitted by guiFormSpecMenu
77          * @param text textual representation of event
78          */
79         void gotText(std::wstring text);
80 private:
81         /** target to transmit data to */
82         GUIEngine* m_engine;
83 };
84
85 class MenuMusicFetcher: public OnDemandSoundFetcher
86 {
87         std::set<std::string> m_fetched;
88 public:
89         void fetchSounds(const std::string &name,
90                         std::set<std::string> &dst_paths,
91                         std::set<std::string> &dst_datas);
92 };
93
94 /** implementation of main menu based uppon formspecs */
95 class GUIEngine {
96         /** grant ModApiMainMenu access to private members */
97         friend class ModApiMainMenu;
98
99 public:
100         /**
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
107          */
108         GUIEngine(      irr::IrrlichtDevice* dev,
109                                 gui::IGUIElement* parent,
110                                 IMenuManager *menumgr,
111                                 scene::ISceneManager* smgr,
112                                 MainMenuData* data,
113                                 bool& kill);
114
115         /** default destructor */
116         virtual ~GUIEngine();
117
118         /**
119          * return MainMenuScripting interface
120          */
121         MainMenuScripting* getScriptIface() {
122                 return m_script;
123         }
124
125         /**
126          * return dir of current menuscript
127          */
128         std::string getScriptDir() {
129                 return m_scriptdir;
130         }
131
132 private:
133
134         /** find and run the main menu script */
135         bool loadMainMenuScript();
136
137         /** run main menu loop */
138         void run();
139
140         /** handler to limit frame rate within main menu */
141         void limitFrameRate();
142
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;
155
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;
162
163         /** reference to kill variable managed by SIGINT handler */
164         bool&                                   m_kill;
165
166         /** variable used to abort menu and return back to main game handling */
167         bool                                    m_startgame;
168
169         /** scripting interface */
170         MainMenuScripting*                      m_script;
171
172         /** script basefolder */
173         std::string                             m_scriptdir;
174
175         /**
176          * draw background layer
177          * @param driver to use for drawing
178          */
179         void drawBackground(video::IVideoDriver* driver);
180         /**
181          * draw overlay layer
182          * @param driver to use for drawing
183          */
184         void drawOverlay(video::IVideoDriver* driver);
185         /**
186          * draw header layer
187          * @param driver to use for drawing
188          */
189         void drawHeader(video::IVideoDriver* driver);
190         /**
191          * draw footer layer
192          * @param driver to use for drawing
193          */
194         void drawFooter(video::IVideoDriver* driver);
195
196         /**
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
200          */
201         bool setTexture(texture_layer layer,std::string texturepath);
202
203         /**
204          * download a file using curl
205          * @param url url to download
206          * @param target file to store to
207          */
208         bool downloadFile(std::string url,std::string target);
209
210         /** array containing pointers to current specified texture layers */
211         video::ITexture*                m_textures[TEX_LAYER_MAX];
212
213         /** draw version string in topleft corner */
214         void drawVersion();
215
216         /**
217          * specify text to be appended to version string
218          * @param text to set
219          */
220         void setTopleftText(std::string append);
221
222         /** pointer to gui element shown at topleft corner */
223         irr::gui::IGUIStaticText*       m_irr_toplefttext;
224
225         /** initialize cloud subsystem */
226         void cloudInit();
227         /** do preprocessing for cloud subsystem */
228         void cloudPreProcess();
229         /** do postprocessing for cloud subsystem */
230         void cloudPostProcess();
231
232         /** internam data required for drawing clouds */
233         struct clouddata {
234                 /** delta time since last cloud processing */
235                 f32             dtime;
236                 /** absolute time of last cloud processing */
237                 u32             lasttime;
238                 /** pointer to cloud class */
239                 Clouds* clouds;
240                 /** camera required for drawing clouds */
241                 scene::ICameraSceneNode* camera;
242         };
243
244         /** is drawing of clouds enabled atm */
245         bool                                    m_clouds_enabled;
246         /** data used to draw clouds */
247         clouddata                               m_cloud;
248
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);
253
254
255 };
256
257
258
259 #endif /* GUI_ENGINE_H_ */