Minetest  5.4.0
guiEngine.h
Go to the documentation of this file.
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 #pragma once
21 
22 /******************************************************************************/
23 /* Includes */
24 /******************************************************************************/
25 #include "irrlichttypes.h"
26 #include "guiFormSpecMenu.h"
27 #include "client/sound.h"
28 #include "client/tile.h"
29 #include "util/enriched_string.h"
30 
31 /******************************************************************************/
32 /* Structs and macros */
33 /******************************************************************************/
41 };
42 
44  video::ITexture *texture = nullptr;
45  bool tile;
46  unsigned int minsize;
47 };
48 
49 /******************************************************************************/
50 /* forward declarations */
51 /******************************************************************************/
52 class GUIEngine;
53 class MainMenuScripting;
54 class Clouds;
55 struct MainMenuData;
56 
57 /******************************************************************************/
58 /* declarations */
59 /******************************************************************************/
60 
63 {
64 public:
69  TextDestGuiEngine(GUIEngine* engine) : m_engine(engine) {};
70 
75  void gotText(const StringMap &fields);
76 
81  void gotText(const std::wstring &text);
82 
83 private:
85  GUIEngine *m_engine = nullptr;
86 };
87 
90 {
91 public:
96  MenuTextureSource(video::IVideoDriver *driver) : m_driver(driver) {};
97 
101  virtual ~MenuTextureSource();
102 
108  video::ITexture *getTexture(const std::string &name, u32 *id = NULL);
109 
110 private:
112  video::IVideoDriver *m_driver = nullptr;
114  std::set<std::string> m_to_delete;
115 };
116 
119 {
120 public:
127  void fetchSounds(const std::string &name,
128  std::set<std::string> &dst_paths,
129  std::set<std::string> &dst_datas);
130 
131 private:
133  std::set<std::string> m_fetched;
134 };
135 
137 class GUIEngine {
139  friend class ModApiMainMenu;
140  friend class ModApiSound;
141 
142 public:
151  GUIEngine(JoystickController *joystick,
152  gui::IGUIElement *parent,
153  IMenuManager *menumgr,
154  MainMenuData *data,
155  bool &kill);
156 
158  virtual ~GUIEngine();
159 
164  {
165  return m_script;
166  }
167 
171  std::string getScriptDir()
172  {
173  return m_scriptdir;
174  }
175 
177  unsigned int queueAsync(const std::string &serialized_fct,
178  const std::string &serialized_params);
179 
180 private:
181 
183  bool loadMainMenuScript();
184 
186  void run();
187 
189  void updateTopLeftTextSize();
190 
192  gui::IGUIElement *m_parent = nullptr;
196  scene::ISceneManager *m_smgr = nullptr;
198  MainMenuData *m_data = nullptr;
203 
210 
212  bool &m_kill;
213 
215  bool m_startgame = false;
216 
219 
221  std::string m_scriptdir = "";
222 
223  void setFormspecPrepend(const std::string &fs);
224 
229  void drawBackground(video::IVideoDriver *driver);
234  void drawOverlay(video::IVideoDriver *driver);
239  void drawHeader(video::IVideoDriver *driver);
244  void drawFooter(video::IVideoDriver *driver);
245 
251  bool setTexture(texture_layer layer, const std::string &texturepath,
252  bool tile_image, unsigned int minsize);
253 
259  static bool downloadFile(const std::string &url, const std::string &target);
260 
263 
268  void setTopleftText(const std::string &text);
269 
271  irr::gui::IGUIStaticText *m_irr_toplefttext = nullptr;
274 
276  void cloudInit();
278  void cloudPreProcess();
280  void cloudPostProcess(u32 frametime_min, IrrlichtDevice *device);
281 
283  struct clouddata {
285  f32 dtime;
287  u32 lasttime;
289  Clouds *clouds = nullptr;
291  scene::ICameraSceneNode *camera = nullptr;
292  };
293 
295  bool m_clouds_enabled = true;
298 
300  s32 playSound(const SimpleSoundSpec &spec, bool looped);
302  void stopSound(s32 handle);
303 
304 
305 };
Definition: clouds.h:36
Definition: enriched_string.h:26
Definition: guiFormSpecMenu.h:469
implementation of main menu based uppon formspecs
Definition: guiEngine.h:137
bool m_startgame
variable used to abort menu and return back to main game handling
Definition: guiEngine.h:215
scene::ISceneManager * m_smgr
scene manager to add scene elements to
Definition: guiEngine.h:196
bool m_clouds_enabled
is drawing of clouds enabled atm
Definition: guiEngine.h:295
void run()
run main menu loop
Definition: guiEngine.cpp:231
GUIEngine(JoystickController *joystick, gui::IGUIElement *parent, IMenuManager *menumgr, MainMenuData *data, bool &kill)
default constructor
Definition: guiEngine.cpp:122
ISoundManager * m_sound_manager
pointer to soundmanager
Definition: guiEngine.h:202
FormspecFormSource * m_formspecgui
representation of form source to be used in mainmenu formspec
Definition: guiEngine.h:205
virtual ~GUIEngine()
default destructor
Definition: guiEngine.cpp:318
void drawOverlay(video::IVideoDriver *driver)
draw overlay layer
Definition: guiEngine.cpp:445
void drawBackground(video::IVideoDriver *driver)
draw background layer
Definition: guiEngine.cpp:403
void updateTopLeftTextSize()
update size of topleftext element
Definition: guiEngine.cpp:591
image_definition m_textures[TEX_LAYER_MAX]
array containing pointers to current specified texture layers
Definition: guiEngine.h:262
bool setTexture(texture_layer layer, const std::string &texturepath, bool tile_image, unsigned int minsize)
load a texture for a specified layer
Definition: guiEngine.cpp:528
void setTopleftText(const std::string &text)
specify text to appear as top left string
Definition: guiEngine.cpp:583
void cloudPreProcess()
do preprocessing for cloud subsystem
Definition: guiEngine.cpp:357
MainMenuData * m_data
pointer to data beeing transfered back to main game handling
Definition: guiEngine.h:198
ISimpleTextureSource * m_texture_source
pointer to texture source
Definition: guiEngine.h:200
void drawHeader(video::IVideoDriver *driver)
draw header layer
Definition: guiEngine.cpp:464
clouddata m_cloud
data used to draw clouds
Definition: guiEngine.h:297
EnrichedString m_toplefttext
and text that is in it
Definition: guiEngine.h:273
bool loadMainMenuScript()
find and run the main menu script
Definition: guiEngine.cpp:208
s32 playSound(const SimpleSoundSpec &spec, bool looped)
start playing a sound and return handle
Definition: guiEngine.cpp:603
unsigned int queueAsync(const std::string &serialized_fct, const std::string &serialized_params)
pass async callback to scriptengine
Definition: guiEngine.cpp:616
void drawFooter(video::IVideoDriver *driver)
draw footer layer
Definition: guiEngine.cpp:496
void cloudInit()
initialize cloud subsystem
Definition: guiEngine.cpp:343
static bool downloadFile(const std::string &url, const std::string &target)
download a file using curl
Definition: guiEngine.cpp:554
irr::gui::IGUIStaticText * m_irr_toplefttext
pointer to gui element shown at topleft corner
Definition: guiEngine.h:271
IMenuManager * m_menumanager
manager to add menus to
Definition: guiEngine.h:194
MainMenuScripting * m_script
scripting interface
Definition: guiEngine.h:218
TextDestGuiEngine * m_buttonhandler
formspec input receiver
Definition: guiEngine.h:207
void setFormspecPrepend(const std::string &fs)
Definition: guiEngine.cpp:394
gui::IGUIElement * m_parent
parent gui element
Definition: guiEngine.h:192
void stopSound(s32 handle)
stop playing a sound started with playSound()
Definition: guiEngine.cpp:610
std::string getScriptDir()
return dir of current menuscript
Definition: guiEngine.h:171
GUIFormSpecMenu * m_menu
the formspec menu
Definition: guiEngine.h:209
void cloudPostProcess(u32 frametime_min, IrrlichtDevice *device)
do postprocessing for cloud subsystem
Definition: guiEngine.cpp:374
bool & m_kill
reference to kill variable managed by SIGINT handler
Definition: guiEngine.h:212
std::string m_scriptdir
script basefolder
Definition: guiEngine.h:221
MainMenuScripting * getScriptIface()
return MainMenuScripting interface
Definition: guiEngine.h:163
Definition: guiFormSpecMenu.h:85
Definition: modalMenu.h:29
Definition: tile.h:75
Definition: sound.h:36
Definition: joystick_controller.h:102
Definition: scripting_mainmenu.h:33
GUIEngine specific implementation of OnDemandSoundFetcher.
Definition: guiEngine.h:119
std::set< std::string > m_fetched
set of fetched sound names
Definition: guiEngine.h:133
void fetchSounds(const std::string &name, std::set< std::string > &dst_paths, std::set< std::string > &dst_datas)
get sound file paths according to sound name
Definition: guiEngine.cpp:100
GUIEngine specific implementation of ISimpleTextureSource.
Definition: guiEngine.h:90
MenuTextureSource(video::IVideoDriver *driver)
default constructor
Definition: guiEngine.h:96
virtual ~MenuTextureSource()
destructor, removes all loaded textures
Definition: guiEngine.cpp:60
video::IVideoDriver * m_driver
driver to get textures from
Definition: guiEngine.h:112
video::ITexture * getTexture(const std::string &name, u32 *id=NULL)
get a texture, loading it if required
Definition: guiEngine.cpp:70
std::set< std::string > m_to_delete
set of texture names to delete
Definition: guiEngine.h:114
Implementation of lua api support for mainmenu.
Definition: l_mainmenu.h:28
Definition: l_sound.h:26
Definition: sound.h:28
GUIEngine specific implementation of TextDest used within guiFormSpecMenu.
Definition: guiEngine.h:63
TextDestGuiEngine(GUIEngine *engine)
default constructor
Definition: guiEngine.h:69
GUIEngine * m_engine
target to transmit data to
Definition: guiEngine.h:85
void gotText(const StringMap &fields)
receive fields transmitted by guiFormSpecMenu
Definition: guiEngine.cpp:48
texture_layer
texture layer ids
Definition: guiEngine.h:35
@ TEX_LAYER_BACKGROUND
Definition: guiEngine.h:36
@ TEX_LAYER_OVERLAY
Definition: guiEngine.h:37
@ TEX_LAYER_HEADER
Definition: guiEngine.h:38
@ TEX_LAYER_MAX
Definition: guiEngine.h:40
@ TEX_LAYER_FOOTER
Definition: guiEngine.h:39
Definition: filesys.cpp:32
std::unordered_map< std::string, std::string > StringMap
Definition: string.h:60
internam data required for drawing clouds
Definition: guiEngine.h:283
scene::ICameraSceneNode * camera
camera required for drawing clouds
Definition: guiEngine.h:291
f32 dtime
delta time since last cloud processing
Definition: guiEngine.h:285
u32 lasttime
absolute time of last cloud processing
Definition: guiEngine.h:287
Clouds * clouds
pointer to cloud class
Definition: guiEngine.h:289
Definition: guiMainMenu.h:35
Definition: sound.h:28
Definition: guiFormSpecMenu.h:65
Definition: guiEngine.h:43
bool tile
Definition: guiEngine.h:45
unsigned int minsize
Definition: guiEngine.h:46
video::ITexture * texture
Definition: guiEngine.h:44