Fix use of unitialized variables in mouse button handling
[oweals/minetest.git] / src / mainmenumanager.h
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 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
40 extern gui::IGUIEnvironment* guienv;
41 extern gui::IGUIStaticText *guiroot;
42
43 // Handler for the modal menus
44
45 class MainMenuManager : public IMenuManager
46 {
47 public:
48         virtual void createdMenu(GUIModalMenu *menu)
49         {
50                 for(std::list<GUIModalMenu*>::iterator
51                                 i = m_stack.begin();
52                                 i != m_stack.end(); ++i)
53                 {
54                         assert(*i != menu);
55                 }
56
57                 if(m_stack.size() != 0)
58                         m_stack.back()->setVisible(false);
59                 m_stack.push_back(menu);
60         }
61
62         virtual void deletingMenu(GUIModalMenu *menu)
63         {
64                 // Remove all entries if there are duplicates
65                 bool removed_entry;
66                 do{
67                         removed_entry = false;
68                         for(std::list<GUIModalMenu*>::iterator
69                                         i = m_stack.begin();
70                                         i != m_stack.end(); ++i)
71                         {
72                                 if(*i == menu)
73                                 {
74                                         m_stack.erase(i);
75                                         removed_entry = true;
76                                         break;
77                                 }
78                         }
79                 }while(removed_entry);
80
81                 /*core::list<GUIModalMenu*>::Iterator i = m_stack.getLast();
82                 assert(*i == menu);
83                 m_stack.erase(i);*/
84                 
85                 if(m_stack.size() != 0)
86                         m_stack.back()->setVisible(true);
87         }
88
89         // Returns true to prevent further processing
90         virtual bool preprocessEvent(const SEvent& event)
91         {
92                 if(m_stack.size() != 0)
93                         return m_stack.back()->preprocessEvent(event);
94                 else
95                         return false;
96         }
97
98         u32 menuCount()
99         {
100                 return m_stack.size();
101         }
102
103         bool pausesGame()
104         {
105                 for(std::list<GUIModalMenu*>::iterator
106                                 i = m_stack.begin(); i != m_stack.end(); ++i)
107                 {
108                         if((*i)->pausesGame())
109                                 return true;
110                 }
111                 return false;
112         }
113
114         std::list<GUIModalMenu*> m_stack;
115 };
116
117 extern MainMenuManager g_menumgr;
118
119 extern bool noMenuActive();
120
121 class MainGameCallback : public IGameCallback
122 {
123 public:
124         MainGameCallback(IrrlichtDevice *a_device):
125                 disconnect_requested(false),
126                 changepassword_requested(false),
127                 changevolume_requested(false),
128                 keyconfig_requested(false),
129                 shutdown_requested(false),
130                 device(a_device)
131         {
132         }
133
134         virtual void exitToOS()
135         {
136                 shutdown_requested = true;
137 #ifndef __ANDROID__
138                 device->closeDevice();
139 #endif
140         }
141
142         virtual void disconnect()
143         {
144                 disconnect_requested = true;
145         }
146
147         virtual void changePassword()
148         {
149                 changepassword_requested = true;
150         }
151
152         virtual void changeVolume()
153         {
154                 changevolume_requested = true;
155         }
156
157         virtual void keyConfig()
158         {
159                 keyconfig_requested = true;
160         }
161
162         
163         bool disconnect_requested;
164         bool changepassword_requested;
165         bool changevolume_requested;
166         bool keyconfig_requested;
167         bool shutdown_requested;
168         IrrlichtDevice *device;
169 };
170
171 extern MainGameCallback *g_gamecallback;
172
173 #endif
174