Line data Source code
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 : #ifndef MAINMENUMANAGER_HEADER
21 : #define MAINMENUMANAGER_HEADER
22 :
23 : /*
24 : All kinds of stuff that needs to be exposed from main.cpp
25 : */
26 : #include "debug.h" // assert
27 : #include "modalMenu.h"
28 : #include <list>
29 :
30 1 : class IGameCallback
31 : {
32 : public:
33 : virtual void exitToOS() = 0;
34 : virtual void keyConfig() = 0;
35 : virtual void disconnect() = 0;
36 : virtual void changePassword() = 0;
37 : virtual void changeVolume() = 0;
38 :
39 : virtual void signalKeyConfigChange() = 0;
40 : };
41 :
42 : extern gui::IGUIEnvironment *guienv;
43 : extern gui::IGUIStaticText *guiroot;
44 :
45 : // Handler for the modal menus
46 :
47 1 : class MainMenuManager : public IMenuManager
48 : {
49 : public:
50 2 : virtual void createdMenu(GUIModalMenu *menu)
51 : {
52 4 : for(std::list<GUIModalMenu*>::iterator
53 2 : i = m_stack.begin();
54 4 : i != m_stack.end(); ++i)
55 : {
56 : assert(*i != menu);
57 : }
58 :
59 2 : if(!m_stack.empty())
60 0 : m_stack.back()->setVisible(false);
61 2 : m_stack.push_back(menu);
62 2 : }
63 :
64 6 : virtual void deletingMenu(GUIModalMenu *menu)
65 : {
66 : // Remove all entries if there are duplicates
67 : bool removed_entry;
68 6 : do{
69 6 : removed_entry = false;
70 12 : for(std::list<GUIModalMenu*>::iterator
71 6 : i = m_stack.begin();
72 12 : i != m_stack.end(); ++i)
73 : {
74 2 : if(*i == menu)
75 : {
76 2 : m_stack.erase(i);
77 2 : removed_entry = true;
78 2 : break;
79 : }
80 : }
81 : }while(removed_entry);
82 :
83 : /*core::list<GUIModalMenu*>::Iterator i = m_stack.getLast();
84 : assert(*i == menu);
85 : m_stack.erase(i);*/
86 :
87 4 : if(!m_stack.empty())
88 0 : m_stack.back()->setVisible(true);
89 4 : }
90 :
91 : // Returns true to prevent further processing
92 140 : virtual bool preprocessEvent(const SEvent& event)
93 : {
94 140 : if(!m_stack.empty())
95 140 : return m_stack.back()->preprocessEvent(event);
96 : else
97 0 : return false;
98 : }
99 :
100 9248 : u32 menuCount()
101 : {
102 9248 : return m_stack.size();
103 : }
104 :
105 1193 : bool pausesGame()
106 : {
107 2386 : for(std::list<GUIModalMenu*>::iterator
108 2386 : i = m_stack.begin(); i != m_stack.end(); ++i)
109 : {
110 19 : if((*i)->pausesGame())
111 19 : return true;
112 : }
113 1174 : return false;
114 : }
115 :
116 : std::list<GUIModalMenu*> m_stack;
117 : };
118 :
119 : extern MainMenuManager g_menumgr;
120 :
121 : extern bool noMenuActive();
122 :
123 : class MainGameCallback : public IGameCallback
124 : {
125 : public:
126 1 : MainGameCallback(IrrlichtDevice *a_device):
127 : disconnect_requested(false),
128 : changepassword_requested(false),
129 : changevolume_requested(false),
130 : keyconfig_requested(false),
131 : shutdown_requested(false),
132 : keyconfig_changed(false),
133 1 : device(a_device)
134 : {
135 1 : }
136 :
137 1 : virtual void exitToOS()
138 : {
139 1 : shutdown_requested = true;
140 : #ifndef __ANDROID__
141 1 : device->closeDevice();
142 : #endif
143 1 : }
144 :
145 0 : virtual void disconnect()
146 : {
147 0 : disconnect_requested = true;
148 0 : }
149 :
150 0 : virtual void changePassword()
151 : {
152 0 : changepassword_requested = true;
153 0 : }
154 :
155 0 : virtual void changeVolume()
156 : {
157 0 : changevolume_requested = true;
158 0 : }
159 :
160 0 : virtual void keyConfig()
161 : {
162 0 : keyconfig_requested = true;
163 0 : }
164 :
165 0 : virtual void signalKeyConfigChange()
166 : {
167 0 : keyconfig_changed = true;
168 0 : }
169 :
170 :
171 : bool disconnect_requested;
172 : bool changepassword_requested;
173 : bool changevolume_requested;
174 : bool keyconfig_requested;
175 : bool shutdown_requested;
176 :
177 : bool keyconfig_changed;
178 :
179 : IrrlichtDevice *device;
180 : };
181 :
182 : extern MainGameCallback *g_gamecallback;
183 :
184 : #endif
185 :
|