]> git.lizzy.rs Git - dragonfireclient.git/blob - src/mainmenumanager.h
Update Copyright Years
[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 "guiPauseMenu.h" //For IGameCallback
29
30 extern gui::IGUIEnvironment* guienv;
31 extern gui::IGUIStaticText *guiroot;
32
33 // Handler for the modal menus
34
35 class MainMenuManager : public IMenuManager
36 {
37 public:
38         virtual void createdMenu(GUIModalMenu *menu)
39         {
40                 for(core::list<GUIModalMenu*>::Iterator
41                                 i = m_stack.begin();
42                                 i != m_stack.end(); i++)
43                 {
44                         assert(*i != menu);
45                 }
46
47                 if(m_stack.size() != 0)
48                         (*m_stack.getLast())->setVisible(false);
49                 m_stack.push_back(menu);
50         }
51
52         virtual void deletingMenu(GUIModalMenu *menu)
53         {
54                 // Remove all entries if there are duplicates
55                 bool removed_entry;
56                 do{
57                         removed_entry = false;
58                         for(core::list<GUIModalMenu*>::Iterator
59                                         i = m_stack.begin();
60                                         i != m_stack.end(); i++)
61                         {
62                                 if(*i == menu)
63                                 {
64                                         m_stack.erase(i);
65                                         removed_entry = true;
66                                         break;
67                                 }
68                         }
69                 }while(removed_entry);
70
71                 /*core::list<GUIModalMenu*>::Iterator i = m_stack.getLast();
72                 assert(*i == menu);
73                 m_stack.erase(i);*/
74                 
75                 if(m_stack.size() != 0)
76                         (*m_stack.getLast())->setVisible(true);
77         }
78
79         u32 menuCount()
80         {
81                 return m_stack.size();
82         }
83
84         core::list<GUIModalMenu*> m_stack;
85 };
86
87 extern MainMenuManager g_menumgr;
88
89 extern bool noMenuActive();
90
91 class MainGameCallback : public IGameCallback
92 {
93 public:
94         MainGameCallback(IrrlichtDevice *a_device):
95                 disconnect_requested(false),
96                 changepassword_requested(false),
97                 changevolume_requested(false),
98                 device(a_device)
99         {
100         }
101
102         virtual void exitToOS()
103         {
104                 device->closeDevice();
105         }
106
107         virtual void disconnect()
108         {
109                 disconnect_requested = true;
110         }
111
112         virtual void changePassword()
113         {
114                 changepassword_requested = true;
115         }
116
117         virtual void changeVolume()
118         {
119                 changevolume_requested = true;
120         }
121         
122         bool disconnect_requested;
123         bool changepassword_requested;
124         bool changevolume_requested;
125         IrrlichtDevice *device;
126 };
127
128 extern MainGameCallback *g_gamecallback;
129
130 #endif
131