3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
20 #include "guiPauseMenu.h"
22 #include "serialization.h"
27 #include <IGUICheckBox.h>
28 #include <IGUIEditBox.h>
29 #include <IGUIButton.h>
30 #include <IGUIStaticText.h>
33 #include "util/string.h"
35 GUIPauseMenu::GUIPauseMenu(gui::IGUIEnvironment* env,
36 gui::IGUIElement* parent, s32 id,
37 IGameCallback *gamecallback,
38 IMenuManager *menumgr,
39 bool simple_singleplayer_mode):
40 GUIModalMenu(env, parent, id, menumgr),
41 m_gamecallback(gamecallback),
42 m_simple_singleplayer_mode(simple_singleplayer_mode)
46 GUIPauseMenu::~GUIPauseMenu()
51 void GUIPauseMenu::removeChildren()
54 gui::IGUIElement *e = getElementFromId(256);
59 gui::IGUIElement *e = getElementFromId(257);
64 gui::IGUIElement *e = getElementFromId(258);
69 gui::IGUIElement *e = getElementFromId(259);
74 gui::IGUIElement *e = getElementFromId(260);
79 gui::IGUIElement *e = getElementFromId(261);
84 gui::IGUIElement *e = getElementFromId(262);
90 void GUIPauseMenu::regenerateGui(v2u32 screensize)
98 Calculate new sizes and positions
100 core::rect<s32> rect(
101 screensize.X/2 - 580/2,
102 screensize.Y/2 - 300/2,
103 screensize.X/2 + 580/2,
104 screensize.Y/2 + 300/2
108 recalculateAbsolutePosition(false);
110 v2s32 size = rect.getSize();
115 const s32 btn_height = 30;
116 const s32 btn_gap = 20;
117 const s32 btn_num = m_simple_singleplayer_mode ? 4 : 5;
118 s32 btn_y = size.Y/2-((btn_num*btn_height+(btn_num-1)*btn_gap))/2;
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,
127 btn_y += btn_height + btn_gap;
128 if(!m_simple_singleplayer_mode)
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,
138 btn_y += btn_height + btn_gap;
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,
148 btn_y += btn_height + btn_gap;
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,
157 btn_y += btn_height + btn_gap;
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,
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"
172 "- Space: jump/climb\n"
173 "- Shift: sneak/go down\n"
176 "- Mouse: turn/look\n"
177 "- Mouse left: dig/punch\n"
178 "- Mouse right: place/use\n"
179 "- Mouse wheel: select item\n"
182 Environment->addStaticText(text, rect, false, true, this, 258);
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);
190 v2u32 max_texture_size;
192 video::IVideoDriver* driver = Environment->getVideoDriver();
193 max_texture_size = driver->getMaxTextureSize();
196 std::ostringstream os;
198 os<<minetest_build_info<<"\n";
199 os<<"path_user = "<<wrap_rows(porting::path_user, 20)<<"\n";
201 Environment->addStaticText(narrow_to_wide(os.str()).c_str(), rect, false, true, this, 259);
205 void GUIPauseMenu::drawMenu()
207 gui::IGUISkin* skin = Environment->getSkin();
210 video::IVideoDriver* driver = Environment->getVideoDriver();
212 video::SColor bgcolor(140,0,0,0);
213 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
215 gui::IGUIElement::draw();
218 bool GUIPauseMenu::OnEvent(const SEvent& event)
221 if(event.EventType==EET_KEY_INPUT_EVENT)
223 if(event.KeyInput.PressedDown)
225 if(event.KeyInput.Key==KEY_ESCAPE)
230 else if(event.KeyInput.Key==KEY_RETURN)
237 if(event.EventType==EET_GUI_EVENT)
239 if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
242 if(!canTakeFocus(event.GUIEvent.Element))
244 dstream<<"GUIPauseMenu: Not allowing focus change."
246 // Returning true disables focus change
250 if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
252 switch(event.GUIEvent.Caller->getID())
254 case 256: // continue
256 // ALWAYS return immediately after quitMenu()
260 m_gamecallback->changePassword();
264 m_gamecallback->changeVolume();
266 case 260: // disconnect
267 m_gamecallback->disconnect();
271 m_gamecallback->exitToOS();
278 return Parent ? Parent->OnEvent(event) : false;