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