]> git.lizzy.rs Git - dragonfireclient.git/blob - src/guiEngine.h
Omnicleanup: header cleanup, add ModApiUtil shared between game and mainmenu
[dragonfireclient.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
114         /** default destructor */
115         virtual ~GUIEngine();
116
117         /**
118          * return MainMenuScripting interface
119          */
120         MainMenuScripting* getScriptIface() {
121                 return m_script;
122         }
123
124         /**
125          * return dir of current menuscript
126          */
127         std::string getScriptDir() {
128                 return m_scriptdir;
129         }
130
131 private:
132
133         /** find and run the main menu script */
134         bool loadMainMenuScript();
135
136         /** run main menu loop */
137         void run();
138
139         /** handler to limit frame rate within main menu */
140         void limitFrameRate();
141
142         /** device to draw at */
143         irr::IrrlichtDevice*    m_device;
144         /** parent gui element */
145         gui::IGUIElement*               m_parent;
146         /** manager to add menus to */
147         IMenuManager*                   m_menumanager;
148         /** scene manager to add scene elements to */
149         scene::ISceneManager*   m_smgr;
150         /** pointer to data beeing transfered back to main game handling */
151         MainMenuData*                   m_data;
152         /** pointer to soundmanager*/
153         ISoundManager*                  m_sound_manager;
154
155         /** representation of form source to be used in mainmenu formspec */
156         FormspecFormSource*             m_formspecgui;
157         /** formspec input receiver */
158         TextDestGuiEngine*              m_buttonhandler;
159         /** the formspec menu */
160         GUIFormSpecMenu*                m_menu;
161
162         /** variable used to abort menu and return back to main game handling */
163         bool                                    m_startgame;
164
165         /** scripting interface */
166         MainMenuScripting*                      m_script;
167
168         /** script basefolder */
169         std::string                             m_scriptdir;
170
171         /**
172          * draw background layer
173          * @param driver to use for drawing
174          */
175         void drawBackground(video::IVideoDriver* driver);
176         /**
177          * draw overlay layer
178          * @param driver to use for drawing
179          */
180         void drawOverlay(video::IVideoDriver* driver);
181         /**
182          * draw header layer
183          * @param driver to use for drawing
184          */
185         void drawHeader(video::IVideoDriver* driver);
186         /**
187          * draw footer layer
188          * @param driver to use for drawing
189          */
190         void drawFooter(video::IVideoDriver* driver);
191
192         /**
193          * load a texture for a specified layer
194          * @param layer draw layer to specify texture
195          * @param texturepath full path of texture to load
196          */
197         bool setTexture(texture_layer layer,std::string texturepath);
198
199         /**
200          * download a file using curl
201          * @param url url to download
202          * @param target file to store to
203          */
204         bool downloadFile(std::string url,std::string target);
205
206         /** array containing pointers to current specified texture layers */
207         video::ITexture*                m_textures[TEX_LAYER_MAX];
208
209         /** draw version string in topleft corner */
210         void drawVersion();
211
212         /**
213          * specify text to be appended to version string
214          * @param text to set
215          */
216         void setTopleftText(std::string append);
217
218         /** pointer to gui element shown at topleft corner */
219         irr::gui::IGUIStaticText*       m_irr_toplefttext;
220
221         /** initialize cloud subsystem */
222         void cloudInit();
223         /** do preprocessing for cloud subsystem */
224         void cloudPreProcess();
225         /** do postprocessing for cloud subsystem */
226         void cloudPostProcess();
227
228         /** internam data required for drawing clouds */
229         struct clouddata {
230                 /** delta time since last cloud processing */
231                 f32             dtime;
232                 /** absolute time of last cloud processing */
233                 u32             lasttime;
234                 /** pointer to cloud class */
235                 Clouds* clouds;
236                 /** camera required for drawing clouds */
237                 scene::ICameraSceneNode* camera;
238         };
239
240         /** is drawing of clouds enabled atm */
241         bool                                    m_clouds_enabled;
242         /** data used to draw clouds */
243         clouddata                               m_cloud;
244
245         /** start playing a sound and return handle */
246         s32 playSound(SimpleSoundSpec spec, bool looped);
247         /** stop playing a sound started with playSound() */
248         void stopSound(s32 handle);
249
250
251 };
252
253
254
255 #endif /* GUI_ENGINE_H_ */