Minetest  5.4.0
mainmenumanager.h
Go to the documentation of this file.
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
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  All kinds of stuff that needs to be exposed from main.cpp
24 */
25 #include "modalMenu.h"
26 #include <cassert>
27 #include <list>
28 
30 {
31 public:
32  virtual void exitToOS() = 0;
33  virtual void keyConfig() = 0;
34  virtual void disconnect() = 0;
35  virtual void changePassword() = 0;
36  virtual void changeVolume() = 0;
37 
38  virtual void signalKeyConfigChange() = 0;
39 };
40 
41 extern gui::IGUIEnvironment *guienv;
42 extern gui::IGUIStaticText *guiroot;
43 
44 // Handler for the modal menus
45 
47 {
48 public:
49  virtual void createdMenu(gui::IGUIElement *menu)
50  {
51 #ifndef NDEBUG
52  for (gui::IGUIElement *i : m_stack) {
53  assert(i != menu);
54  }
55 #endif
56 
57  if(!m_stack.empty())
58  m_stack.back()->setVisible(false);
59  m_stack.push_back(menu);
60  }
61 
62  virtual void deletingMenu(gui::IGUIElement *menu)
63  {
64  // Remove all entries if there are duplicates
65  m_stack.remove(menu);
66 
67  /*core::list<GUIModalMenu*>::Iterator i = m_stack.getLast();
68  assert(*i == menu);
69  m_stack.erase(i);*/
70 
71  if(!m_stack.empty())
72  m_stack.back()->setVisible(true);
73  }
74 
75  // Returns true to prevent further processing
76  virtual bool preprocessEvent(const SEvent& event)
77  {
78  if (m_stack.empty())
79  return false;
80  GUIModalMenu *mm = dynamic_cast<GUIModalMenu*>(m_stack.back());
81  return mm && mm->preprocessEvent(event);
82  }
83 
84  u32 menuCount()
85  {
86  return m_stack.size();
87  }
88 
89  bool pausesGame()
90  {
91  for (gui::IGUIElement *i : m_stack) {
92  GUIModalMenu *mm = dynamic_cast<GUIModalMenu*>(i);
93  if (mm && mm->pausesGame())
94  return true;
95  }
96  return false;
97  }
98 
99  std::list<gui::IGUIElement*> m_stack;
100 };
101 
103 
104 extern bool isMenuActive();
105 
107 {
108 public:
109  MainGameCallback() = default;
110  virtual ~MainGameCallback() = default;
111 
112  virtual void exitToOS()
113  {
114  shutdown_requested = true;
115  }
116 
117  virtual void disconnect()
118  {
119  disconnect_requested = true;
120  }
121 
122  virtual void changePassword()
123  {
125  }
126 
127  virtual void changeVolume()
128  {
129  changevolume_requested = true;
130  }
131 
132  virtual void keyConfig()
133  {
134  keyconfig_requested = true;
135  }
136 
137  virtual void signalKeyConfigChange()
138  {
139  keyconfig_changed = true;
140  }
141 
142 
143  bool disconnect_requested = false;
146  bool keyconfig_requested = false;
147  bool shutdown_requested = false;
148 
149  bool keyconfig_changed = false;
150 };
151 
Definition: modalMenu.h:40
virtual bool preprocessEvent(const SEvent &event)
Definition: modalMenu.cpp:244
virtual bool pausesGame()
Definition: modalMenu.h:56
Definition: mainmenumanager.h:30
virtual void exitToOS()=0
virtual void changePassword()=0
virtual void signalKeyConfigChange()=0
virtual void disconnect()=0
virtual void changeVolume()=0
virtual void keyConfig()=0
Definition: modalMenu.h:29
Definition: mainmenumanager.h:107
bool keyconfig_changed
Definition: mainmenumanager.h:149
bool keyconfig_requested
Definition: mainmenumanager.h:146
virtual void signalKeyConfigChange()
Definition: mainmenumanager.h:137
MainGameCallback()=default
bool shutdown_requested
Definition: mainmenumanager.h:147
bool disconnect_requested
Definition: mainmenumanager.h:143
virtual void changePassword()
Definition: mainmenumanager.h:122
virtual void disconnect()
Definition: mainmenumanager.h:117
virtual void changeVolume()
Definition: mainmenumanager.h:127
virtual ~MainGameCallback()=default
virtual void keyConfig()
Definition: mainmenumanager.h:132
virtual void exitToOS()
Definition: mainmenumanager.h:112
bool changevolume_requested
Definition: mainmenumanager.h:145
bool changepassword_requested
Definition: mainmenumanager.h:144
Definition: mainmenumanager.h:47
virtual bool preprocessEvent(const SEvent &event)
Definition: mainmenumanager.h:76
bool pausesGame()
Definition: mainmenumanager.h:89
virtual void createdMenu(gui::IGUIElement *menu)
Definition: mainmenumanager.h:49
u32 menuCount()
Definition: mainmenumanager.h:84
std::list< gui::IGUIElement * > m_stack
Definition: mainmenumanager.h:99
virtual void deletingMenu(gui::IGUIElement *menu)
Definition: mainmenumanager.h:62
MainMenuManager g_menumgr
Definition: clientlauncher.cpp:49
gui::IGUIEnvironment * guienv
Definition: clientlauncher.cpp:47
bool isMenuActive()
Definition: clientlauncher.cpp:51
MainGameCallback * g_gamecallback
Definition: clientlauncher.cpp:57
gui::IGUIStaticText * guiroot
Definition: clientlauncher.cpp:48