]> git.lizzy.rs Git - dragonfireclient.git/blob - src/mainmenumanager.h
clientmap, clientmedia: code modernization
[dragonfireclient.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         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 class MainMenuManager : public IMenuManager
48 {
49 public:
50         virtual void createdMenu(gui::IGUIElement *menu)
51         {
52                 for(std::list<gui::IGUIElement*>::iterator
53                                 i = m_stack.begin();
54                                 i != m_stack.end(); ++i)
55                 {
56                         assert(*i != menu);
57                 }
58
59                 if(!m_stack.empty())
60                         m_stack.back()->setVisible(false);
61                 m_stack.push_back(menu);
62         }
63
64         virtual void deletingMenu(gui::IGUIElement *menu)
65         {
66                 // Remove all entries if there are duplicates
67                 bool removed_entry;
68                 do{
69                         removed_entry = false;
70                         for(std::list<gui::IGUIElement*>::iterator
71                                         i = m_stack.begin();
72                                         i != m_stack.end(); ++i)
73                         {
74                                 if(*i == menu)
75                                 {
76                                         m_stack.erase(i);
77                                         removed_entry = true;
78                                         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                 if(!m_stack.empty())
88                         m_stack.back()->setVisible(true);
89         }
90
91         // Returns true to prevent further processing
92         virtual bool preprocessEvent(const SEvent& event)
93         {
94                 if (m_stack.empty())
95                         return false;
96                 GUIModalMenu *mm = dynamic_cast<GUIModalMenu*>(m_stack.back());
97                 return mm && mm->preprocessEvent(event);
98         }
99
100         u32 menuCount()
101         {
102                 return m_stack.size();
103         }
104
105         bool pausesGame()
106         {
107                 for(std::list<gui::IGUIElement*>::iterator
108                                 i = m_stack.begin(); i != m_stack.end(); ++i)
109                 {
110                         GUIModalMenu *mm = dynamic_cast<GUIModalMenu*>(*i);
111                         if (mm && mm->pausesGame())
112                                 return true;
113                 }
114                 return false;
115         }
116
117         std::list<gui::IGUIElement*> m_stack;
118 };
119
120 extern MainMenuManager g_menumgr;
121
122 extern bool isMenuActive();
123
124 class MainGameCallback : public IGameCallback
125 {
126 public:
127         MainGameCallback() {}
128         virtual ~MainGameCallback() {}
129
130         virtual void exitToOS()
131         {
132                 shutdown_requested = true;
133         }
134
135         virtual void disconnect()
136         {
137                 disconnect_requested = true;
138         }
139
140         virtual void changePassword()
141         {
142                 changepassword_requested = true;
143         }
144
145         virtual void changeVolume()
146         {
147                 changevolume_requested = true;
148         }
149
150         virtual void keyConfig()
151         {
152                 keyconfig_requested = true;
153         }
154
155         virtual void signalKeyConfigChange()
156         {
157                 keyconfig_changed = true;
158         }
159
160
161         bool disconnect_requested = false;
162         bool changepassword_requested = false;
163         bool changevolume_requested = false;
164         bool keyconfig_requested = false;
165         bool shutdown_requested = false;
166
167         bool keyconfig_changed = false;
168 };
169
170 extern MainGameCallback *g_gamecallback;
171
172 #endif
173