3 Copyright (C) 2010 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"
26 #include <IGUICheckBox.h>
27 #include <IGUIEditBox.h>
28 #include <IGUIButton.h>
29 #include <IGUIStaticText.h>
32 #include "util/string.h"
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)
45 GUIPauseMenu::~GUIPauseMenu()
50 void GUIPauseMenu::removeChildren()
53 gui::IGUIElement *e = getElementFromId(256);
58 gui::IGUIElement *e = getElementFromId(257);
63 gui::IGUIElement *e = getElementFromId(258);
68 gui::IGUIElement *e = getElementFromId(259);
73 gui::IGUIElement *e = getElementFromId(260);
78 gui::IGUIElement *e = getElementFromId(261);
84 void GUIPauseMenu::regenerateGui(v2u32 screensize)
92 Calculate new sizes and positions
95 screensize.X/2 - 580/2,
96 screensize.Y/2 - 300/2,
97 screensize.X/2 + 580/2,
98 screensize.Y/2 + 300/2
102 recalculateAbsolutePosition(false);
104 v2s32 size = rect.getSize();
109 const s32 btn_height = 30;
110 const s32 btn_gap = 20;
111 const s32 btn_num = m_simple_singleplayer_mode ? 3 : 4;
112 s32 btn_y = size.Y/2-((btn_num*btn_height+(btn_num-1)*btn_gap))/2;
115 core::rect<s32> rect(0, 0, 140, btn_height);
116 rect = rect + v2s32(size.X/2-140/2, btn_y);
117 Environment->addButton(rect, this, 256,
118 wgettext("Continue"));
120 btn_y += btn_height + btn_gap;
121 if(!m_simple_singleplayer_mode)
124 core::rect<s32> rect(0, 0, 140, btn_height);
125 rect = rect + v2s32(size.X/2-140/2, btn_y);
126 Environment->addButton(rect, this, 261,
127 wgettext("Change Password"));
129 btn_y += btn_height + btn_gap;
132 core::rect<s32> rect(0, 0, 140, btn_height);
133 rect = rect + v2s32(size.X/2-140/2, btn_y);
134 Environment->addButton(rect, this, 260,
135 wgettext("Exit to Menu"));
137 btn_y += btn_height + btn_gap;
139 core::rect<s32> rect(0, 0, 140, btn_height);
140 rect = rect + v2s32(size.X/2-140/2, btn_y);
141 Environment->addButton(rect, this, 257,
142 wgettext("Exit to OS"));
146 core::rect<s32> rect(0, 0, 180, 240);
147 rect = rect + v2s32(size.X/2 + 90, size.Y/2-rect.getHeight()/2);
148 Environment->addStaticText(chartowchar_t(gettext(
149 "Default Controls:\n"
151 "- Mouse left: dig/hit\n"
152 "- Mouse right: place/use\n"
153 "- Mouse wheel: select item\n"
154 "- 0...9: select item\n"
156 "- R: Toggle viewing all loaded chunks\n"
157 "- I: Inventory menu\n"
160 )), rect, false, true, this, 258);
163 core::rect<s32> rect(0, 0, 180, 220);
164 rect = rect + v2s32(size.X/2 - 90 - rect.getWidth(), size.Y/2-rect.getHeight()/2);
166 v2u32 max_texture_size;
168 video::IVideoDriver* driver = Environment->getVideoDriver();
169 max_texture_size = driver->getMaxTextureSize();
172 std::ostringstream os;
174 os<<BUILD_INFO<<"\n";
175 os<<"path_user = "<<wrap_rows(porting::path_user, 20)<<"\n";
177 Environment->addStaticText(narrow_to_wide(os.str()).c_str(), rect, false, true, this, 259);
182 void GUIPauseMenu::drawMenu()
184 gui::IGUISkin* skin = Environment->getSkin();
187 video::IVideoDriver* driver = Environment->getVideoDriver();
189 video::SColor bgcolor(140,0,0,0);
190 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
192 gui::IGUIElement::draw();
195 bool GUIPauseMenu::OnEvent(const SEvent& event)
198 if(event.EventType==EET_KEY_INPUT_EVENT)
200 if(event.KeyInput.PressedDown)
202 if(event.KeyInput.Key==KEY_ESCAPE)
207 else if(event.KeyInput.Key==KEY_RETURN)
214 if(event.EventType==EET_GUI_EVENT)
216 if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
219 if(!canTakeFocus(event.GUIEvent.Element))
221 dstream<<"GUIPauseMenu: Not allowing focus change."
223 // Returning true disables focus change
227 if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
229 switch(event.GUIEvent.Caller->getID())
231 case 256: // continue
233 // ALWAYS return immediately after quitMenu()
237 m_gamecallback->changePassword();
239 case 260: // disconnect
240 m_gamecallback->disconnect();
244 m_gamecallback->exitToOS();
251 return Parent ? Parent->OnEvent(event) : false;