]> git.lizzy.rs Git - dragonfireclient.git/blob - src/guiPauseMenu.cpp
Remove debug output
[dragonfireclient.git] / src / guiPauseMenu.cpp
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 #include "guiPauseMenu.h"
21 #include "debug.h"
22 #include "serialization.h"
23 #include "porting.h"
24 #include "config.h"
25 #include "main.h"
26 #include <IGUICheckBox.h>
27 #include <IGUIEditBox.h>
28 #include <IGUIButton.h>
29 #include <IGUIStaticText.h>
30 #include <IGUIFont.h>
31 #include "gettext.h"
32 #include "util/string.h"
33
34 GUIPauseMenu::GUIPauseMenu(gui::IGUIEnvironment* env,
35                 gui::IGUIElement* parent, s32 id,
36                 IGameCallback *gamecallback,
37                 IMenuManager *menumgr,
38                 bool simple_singleplayer_mode):
39         GUIModalMenu(env, parent, id, menumgr),
40         m_gamecallback(gamecallback),
41         m_simple_singleplayer_mode(simple_singleplayer_mode)
42 {
43 }
44
45 GUIPauseMenu::~GUIPauseMenu()
46 {
47         removeChildren();
48 }
49
50 void GUIPauseMenu::removeChildren()
51 {
52         {
53                 gui::IGUIElement *e = getElementFromId(256);
54                 if(e != NULL)
55                         e->remove();
56         }
57         {
58                 gui::IGUIElement *e = getElementFromId(257);
59                 if(e != NULL)
60                         e->remove();
61         }
62         {
63                 gui::IGUIElement *e = getElementFromId(258);
64                 if(e != NULL)
65                         e->remove();
66         }
67         {
68                 gui::IGUIElement *e = getElementFromId(259);
69                 if(e != NULL)
70                         e->remove();
71         }
72         {
73                 gui::IGUIElement *e = getElementFromId(260);
74                 if(e != NULL)
75                         e->remove();
76         }
77         {
78                 gui::IGUIElement *e = getElementFromId(261);
79                 if(e != NULL)
80                         e->remove();
81         }
82         {
83                 gui::IGUIElement *e = getElementFromId(262);
84                 if(e != NULL)
85                         e->remove();
86         }
87 }
88
89 void GUIPauseMenu::regenerateGui(v2u32 screensize)
90 {
91         /*
92                 Remove stuff
93         */
94         removeChildren();
95         
96         /*
97                 Calculate new sizes and positions
98         */
99         core::rect<s32> rect(
100                         screensize.X/2 - 580/2,
101                         screensize.Y/2 - 300/2,
102                         screensize.X/2 + 580/2,
103                         screensize.Y/2 + 300/2
104         );
105         
106         DesiredRect = rect;
107         recalculateAbsolutePosition(false);
108
109         v2s32 size = rect.getSize();
110
111         /*
112                 Add stuff
113         */
114         const s32 btn_height = 30;
115         const s32 btn_gap = 20;
116         const s32 btn_num = m_simple_singleplayer_mode ? 4 : 5;
117         s32 btn_y = size.Y/2-((btn_num*btn_height+(btn_num-1)*btn_gap))/2;
118         changeCtype("");
119         {
120                 core::rect<s32> rect(0, 0, 140, btn_height);
121                 rect = rect + v2s32(size.X/2-140/2, btn_y);
122                 wchar_t* text = wgettext("Continue");
123                 Environment->addButton(rect, this, 256,
124                         text);
125                 delete[] text;
126         }
127         btn_y += btn_height + btn_gap;
128         if(!m_simple_singleplayer_mode)
129         {
130                 {
131                         core::rect<s32> rect(0, 0, 140, btn_height);
132                         rect = rect + v2s32(size.X/2-140/2, btn_y);
133                         wchar_t* text = wgettext("Change Password");
134                         Environment->addButton(rect, this, 261,
135                                 text);
136                         delete[] text;
137                 }
138                 btn_y += btn_height + btn_gap;
139         }
140         {
141                 core::rect<s32> rect(0, 0, 140, btn_height);
142                 rect = rect + v2s32(size.X/2-140/2, btn_y);
143                 wchar_t* text = wgettext("Sound Volume");
144                 Environment->addButton(rect, this, 262,
145                         text);
146                 delete[] text;
147         }
148         btn_y += btn_height + btn_gap;
149         {
150                 core::rect<s32> rect(0, 0, 140, btn_height);
151                 rect = rect + v2s32(size.X/2-140/2, btn_y);
152                 wchar_t* text = wgettext("Exit to Menu");
153                 Environment->addButton(rect, this, 260,
154                         text);
155                 delete[] text;
156         }
157         btn_y += btn_height + btn_gap;
158         {
159                 core::rect<s32> rect(0, 0, 140, btn_height);
160                 rect = rect + v2s32(size.X/2-140/2, btn_y);
161                 wchar_t* text = wgettext("Exit to OS");
162                 Environment->addButton(rect, this, 257,
163                         text);
164                 delete[] text;
165         }
166
167         {
168                 core::rect<s32> rect(0, 0, 180, 240);
169                 rect = rect + v2s32(size.X/2 + 90, size.Y/2-rect.getHeight()/2);
170                 wchar_t* text = wgettext("Default Controls:\n"
171                                 "- WASD: move\n"
172                                 "- Space: jump/climb\n"
173                                 "- Shift: sneak/go down\n"
174                                 "- Q: drop item\n"
175                                 "- I: inventory\n"
176                                 "- Mouse: turn/look\n"
177                                 "- Mouse left: dig/punch\n"
178                                 "- Mouse right: place/use\n"
179                                 "- Mouse wheel: select item\n"
180                                 "- T: chat\n"
181                                 );
182                 Environment->addStaticText(text, rect, false, true, this, 258);
183                 delete[] text;
184
185         }
186         {
187                 core::rect<s32> rect(0, 0, 180, 220);
188                 rect = rect + v2s32(size.X/2 - 90 - rect.getWidth(), size.Y/2-rect.getHeight()/2);
189         
190                 v2u32 max_texture_size;
191                 {
192                         video::IVideoDriver* driver = Environment->getVideoDriver();
193                         max_texture_size = driver->getMaxTextureSize();
194                 }
195
196                 std::ostringstream os;
197                 os<<"Minetest\n";
198                 os<<BUILD_INFO<<"\n";
199                 os<<"path_user = "<<wrap_rows(porting::path_user, 20)<<"\n";
200         
201                 Environment->addStaticText(narrow_to_wide(os.str()).c_str(), rect, false, true, this, 259);
202         }
203         changeCtype("C");
204 }
205
206 void GUIPauseMenu::drawMenu()
207 {
208         gui::IGUISkin* skin = Environment->getSkin();
209         if (!skin)
210                 return;
211         video::IVideoDriver* driver = Environment->getVideoDriver();
212         
213         video::SColor bgcolor(140,0,0,0);
214         driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
215
216         gui::IGUIElement::draw();
217 }
218
219 bool GUIPauseMenu::OnEvent(const SEvent& event)
220 {
221
222         if(event.EventType==EET_KEY_INPUT_EVENT)
223         {
224                 if(event.KeyInput.PressedDown)
225                 {
226                         if(event.KeyInput.Key==KEY_ESCAPE)
227                         {
228                                 quitMenu();
229                                 return true;
230                         }
231                         else if(event.KeyInput.Key==KEY_RETURN)
232                         {
233                                 quitMenu();
234                                 return true;
235                         }
236                 }
237         }
238         if(event.EventType==EET_GUI_EVENT)
239         {
240                 if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
241                                 && isVisible())
242                 {
243                         if(!canTakeFocus(event.GUIEvent.Element))
244                         {
245                                 dstream<<"GUIPauseMenu: Not allowing focus change."
246                                                 <<std::endl;
247                                 // Returning true disables focus change
248                                 return true;
249                         }
250                 }
251                 if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
252                 {
253                         switch(event.GUIEvent.Caller->getID())
254                         {
255                         case 256: // continue
256                                 quitMenu();
257                                 // ALWAYS return immediately after quitMenu()
258                                 return true;
259                         case 261:
260                                 quitMenu();
261                                 m_gamecallback->changePassword();
262                                 return true;
263                         case 262:
264                                 quitMenu();
265                                 m_gamecallback->changeVolume();
266                                 return true;
267                         case 260: // disconnect
268                                 m_gamecallback->disconnect();
269                                 quitMenu();
270                                 return true;
271                         case 257: // exit
272                                 m_gamecallback->exitToOS();
273                                 quitMenu();
274                                 return true;
275                         }
276                 }
277         }
278         
279         return Parent ? Parent->OnEvent(event) : false;
280 }
281