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;
121 core::rect<s32> rect(0, 0, 140, btn_height);
122 rect = rect + v2s32(size.X/2-140/2, btn_y);
123 wchar_t* text = wgettext("Continue");
124 Environment->addButton(rect, this, 256,
128 btn_y += btn_height + btn_gap;
129 if(!m_simple_singleplayer_mode)
132 core::rect<s32> rect(0, 0, 140, btn_height);
133 rect = rect + v2s32(size.X/2-140/2, btn_y);
134 wchar_t* text = wgettext("Change Password");
135 Environment->addButton(rect, this, 261,
139 btn_y += btn_height + btn_gap;
142 core::rect<s32> rect(0, 0, 140, btn_height);
143 rect = rect + v2s32(size.X/2-140/2, btn_y);
144 wchar_t* text = wgettext("Sound Volume");
145 Environment->addButton(rect, this, 262,
149 btn_y += btn_height + btn_gap;
151 core::rect<s32> rect(0, 0, 140, btn_height);
152 rect = rect + v2s32(size.X/2-140/2, btn_y);
153 wchar_t* text = wgettext("Exit to Menu");
154 Environment->addButton(rect, this, 260,
158 btn_y += btn_height + btn_gap;
160 core::rect<s32> rect(0, 0, 140, btn_height);
161 rect = rect + v2s32(size.X/2-140/2, btn_y);
162 wchar_t* text = wgettext("Exit to OS");
163 Environment->addButton(rect, this, 257,
169 core::rect<s32> rect(0, 0, 180, 240);
170 rect = rect + v2s32(size.X/2 + 90, size.Y/2-rect.getHeight()/2);
171 wchar_t* text = wgettext("Default Controls:\n"
173 "- Space: jump/climb\n"
174 "- Shift: sneak/go down\n"
177 "- Mouse: turn/look\n"
178 "- Mouse left: dig/punch\n"
179 "- Mouse right: place/use\n"
180 "- Mouse wheel: select item\n"
183 Environment->addStaticText(text, rect, false, true, this, 258);
188 core::rect<s32> rect(0, 0, 180, 220);
189 rect = rect + v2s32(size.X/2 - 90 - rect.getWidth(), size.Y/2-rect.getHeight()/2);
191 v2u32 max_texture_size;
193 video::IVideoDriver* driver = Environment->getVideoDriver();
194 max_texture_size = driver->getMaxTextureSize();
197 std::ostringstream os;
199 os<<minetest_build_info<<"\n";
200 os<<"path_user = "<<wrap_rows(porting::path_user, 20)<<"\n";
202 Environment->addStaticText(narrow_to_wide(os.str()).c_str(), rect, false, true, this, 259);
207 void GUIPauseMenu::drawMenu()
209 gui::IGUISkin* skin = Environment->getSkin();
212 video::IVideoDriver* driver = Environment->getVideoDriver();
214 video::SColor bgcolor(140,0,0,0);
215 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
217 gui::IGUIElement::draw();
220 bool GUIPauseMenu::OnEvent(const SEvent& event)
223 if(event.EventType==EET_KEY_INPUT_EVENT)
225 if(event.KeyInput.PressedDown)
227 if(event.KeyInput.Key==KEY_ESCAPE)
232 else if(event.KeyInput.Key==KEY_RETURN)
239 if(event.EventType==EET_GUI_EVENT)
241 if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
244 if(!canTakeFocus(event.GUIEvent.Element))
246 dstream<<"GUIPauseMenu: Not allowing focus change."
248 // Returning true disables focus change
252 if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
254 switch(event.GUIEvent.Caller->getID())
256 case 256: // continue
258 // ALWAYS return immediately after quitMenu()
262 m_gamecallback->changePassword();
266 m_gamecallback->changeVolume();
268 case 260: // disconnect
269 m_gamecallback->disconnect();
273 m_gamecallback->exitToOS();
280 return Parent ? Parent->OnEvent(event) : false;