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