-/*\r
-Minetest-c55\r
-Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>\r
-\r
-This program is free software; you can redistribute it and/or modify\r
-it under the terms of the GNU Lesser General Public License as published by\r
-the Free Software Foundation; either version 2.1 of the License, or\r
-(at your option) any later version.\r
-\r
-This program is distributed in the hope that it will be useful,\r
-but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-GNU Lesser General Public License for more details.\r
-\r
-You should have received a copy of the GNU Lesser General Public License along\r
-with this program; if not, write to the Free Software Foundation, Inc.,\r
-51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
-*/\r
-\r
-#include "guiPauseMenu.h"\r
-#include "debug.h"\r
-#include "serialization.h"\r
-#include "porting.h"\r
-#include "config.h"\r
-#include "main.h"\r
-#include <IGUICheckBox.h>\r
-#include <IGUIEditBox.h>\r
-#include <IGUIButton.h>\r
-#include <IGUIStaticText.h>\r
-#include <IGUIFont.h>\r
-\r
-#include "gettext.h"\r
-\r
-GUIPauseMenu::GUIPauseMenu(gui::IGUIEnvironment* env,\r
- gui::IGUIElement* parent, s32 id,\r
- IGameCallback *gamecallback,\r
- IMenuManager *menumgr,\r
- bool simple_singleplayer_mode):\r
- GUIModalMenu(env, parent, id, menumgr),\r
- m_gamecallback(gamecallback),\r
- m_simple_singleplayer_mode(simple_singleplayer_mode)\r
-{\r
-}\r
-\r
-GUIPauseMenu::~GUIPauseMenu()\r
-{\r
- removeChildren();\r
-}\r
-\r
-void GUIPauseMenu::removeChildren()\r
-{\r
- {\r
- gui::IGUIElement *e = getElementFromId(256);\r
- if(e != NULL)\r
- e->remove();\r
- }\r
- {\r
- gui::IGUIElement *e = getElementFromId(257);\r
- if(e != NULL)\r
- e->remove();\r
- }\r
- {\r
- gui::IGUIElement *e = getElementFromId(258);\r
- if(e != NULL)\r
- e->remove();\r
- }\r
- {\r
- gui::IGUIElement *e = getElementFromId(259);\r
- if(e != NULL)\r
- e->remove();\r
- }\r
- {\r
- gui::IGUIElement *e = getElementFromId(260);\r
- if(e != NULL)\r
- e->remove();\r
- }\r
- {\r
- gui::IGUIElement *e = getElementFromId(261);\r
- if(e != NULL)\r
- e->remove();\r
- }\r
-}\r
-\r
-void GUIPauseMenu::regenerateGui(v2u32 screensize)\r
-{\r
- /*\r
- Remove stuff\r
- */\r
- removeChildren();\r
- \r
- /*\r
- Calculate new sizes and positions\r
- */\r
- core::rect<s32> rect(\r
- screensize.X/2 - 580/2,\r
- screensize.Y/2 - 300/2,\r
- screensize.X/2 + 580/2,\r
- screensize.Y/2 + 300/2\r
- );\r
- \r
- DesiredRect = rect;\r
- recalculateAbsolutePosition(false);\r
-\r
- v2s32 size = rect.getSize();\r
-\r
- /*\r
- Add stuff\r
- */\r
- const s32 btn_height = 30;\r
- const s32 btn_gap = 20;\r
- const s32 btn_num = m_simple_singleplayer_mode ? 3 : 4;\r
- s32 btn_y = size.Y/2-((btn_num*btn_height+(btn_num-1)*btn_gap))/2;\r
- changeCtype("");\r
- {\r
- core::rect<s32> rect(0, 0, 140, btn_height);\r
- rect = rect + v2s32(size.X/2-140/2, btn_y);\r
- Environment->addButton(rect, this, 256,\r
- wgettext("Continue"));\r
- }\r
- btn_y += btn_height + btn_gap;\r
- if(!m_simple_singleplayer_mode)\r
- {\r
- {\r
- core::rect<s32> rect(0, 0, 140, btn_height);\r
- rect = rect + v2s32(size.X/2-140/2, btn_y);\r
- Environment->addButton(rect, this, 261,\r
- wgettext("Change Password"));\r
- }\r
- btn_y += btn_height + btn_gap;\r
- }\r
- {\r
- core::rect<s32> rect(0, 0, 140, btn_height);\r
- rect = rect + v2s32(size.X/2-140/2, btn_y);\r
- Environment->addButton(rect, this, 260,\r
- wgettext("Exit to Menu"));\r
- }\r
- btn_y += btn_height + btn_gap;\r
- {\r
- core::rect<s32> rect(0, 0, 140, btn_height);\r
- rect = rect + v2s32(size.X/2-140/2, btn_y);\r
- Environment->addButton(rect, this, 257,\r
- wgettext("Exit to OS"));\r
- }\r
-\r
- {\r
- core::rect<s32> rect(0, 0, 180, 240);\r
- rect = rect + v2s32(size.X/2 + 90, size.Y/2-rect.getHeight()/2);\r
- Environment->addStaticText(chartowchar_t(gettext(\r
- "Default Controls:\n"\r
- "- WASD: Walk\n"\r
- "- Mouse left: dig/hit\n"\r
- "- Mouse right: place/use\n"\r
- "- Mouse wheel: select item\n"\r
- "- 0...9: select item\n"\r
- "- Shift: sneak\n"\r
- "- R: Toggle viewing all loaded chunks\n"\r
- "- I: Inventory menu\n"\r
- "- ESC: This menu\n"\r
- "- T: Chat\n"\r
- )), rect, false, true, this, 258);\r
- }\r
- {\r
- core::rect<s32> rect(0, 0, 180, 220);\r
- rect = rect + v2s32(size.X/2 - 90 - rect.getWidth(), size.Y/2-rect.getHeight()/2);\r
- \r
- v2u32 max_texture_size;\r
- {\r
- video::IVideoDriver* driver = Environment->getVideoDriver();\r
- max_texture_size = driver->getMaxTextureSize();\r
- }\r
-\r
- /*wchar_t text[200];\r
- swprintf(text, 200,\r
- L"Minetest-c55\n"\r
- L"by Perttu Ahola\n"\r
- L"celeron55@gmail.com\n\n"\r
- SWPRINTF_CHARSTRING L"\n"\r
- L"userdata path = "\r
- SWPRINTF_CHARSTRING\r
- ,\r
- BUILD_INFO,\r
- porting::path_user.c_str()\r
- );*/\r
-\r
- std::ostringstream os;\r
- os<<"Minetest\n";\r
- os<<"by Perttu Ahola and contributors\n";\r
- os<<"celeron55@gmail.com\n";\r
- os<<BUILD_INFO<<"\n";\r
- os<<"path_user = "<<wrap_rows(porting::path_user, 20)<<"\n";\r
- \r
- Environment->addStaticText(narrow_to_wide(os.str()).c_str(), rect, false, true, this, 259);\r
- }\r
- changeCtype("C");\r
-}\r
-\r
-void GUIPauseMenu::drawMenu()\r
-{\r
- gui::IGUISkin* skin = Environment->getSkin();\r
- if (!skin)\r
- return;\r
- video::IVideoDriver* driver = Environment->getVideoDriver();\r
- \r
- video::SColor bgcolor(140,0,0,0);\r
- driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);\r
-\r
- gui::IGUIElement::draw();\r
-}\r
-\r
-bool GUIPauseMenu::OnEvent(const SEvent& event)\r
-{\r
-\r
- if(event.EventType==EET_KEY_INPUT_EVENT)\r
- {\r
- if(event.KeyInput.PressedDown)\r
- {\r
- if(event.KeyInput.Key==KEY_ESCAPE)\r
- {\r
- quitMenu();\r
- return true;\r
- }\r
- else if(event.KeyInput.Key==KEY_RETURN)\r
- {\r
- quitMenu();\r
- return true;\r
- }\r
- }\r
- }\r
- if(event.EventType==EET_GUI_EVENT)\r
- {\r
- if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST\r
- && isVisible())\r
- {\r
- if(!canTakeFocus(event.GUIEvent.Element))\r
- {\r
- dstream<<"GUIPauseMenu: Not allowing focus change."\r
- <<std::endl;\r
- // Returning true disables focus change\r
- return true;\r
- }\r
- }\r
- if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)\r
- {\r
- switch(event.GUIEvent.Caller->getID())\r
- {\r
- case 256: // continue\r
- quitMenu();\r
- // ALWAYS return immediately after quitMenu()\r
- return true;\r
- case 261:\r
- quitMenu();\r
- m_gamecallback->changePassword();\r
- return true;\r
- case 260: // disconnect\r
- m_gamecallback->disconnect();\r
- quitMenu();\r
- return true;\r
- case 257: // exit\r
- m_gamecallback->exitToOS();\r
- quitMenu();\r
- return true;\r
- }\r
- }\r
- }\r
- \r
- return Parent ? Parent->OnEvent(event) : false;\r
-}\r
-\r
+/*
+Minetest
+Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "guiPauseMenu.h"
+#include "debug.h"
+#include "serialization.h"
+#include "porting.h"
+#include "config.h"
+#include "main.h"
+#include <IGUICheckBox.h>
+#include <IGUIEditBox.h>
+#include <IGUIButton.h>
+#include <IGUIStaticText.h>
+#include <IGUIFont.h>
+#include "gettext.h"
+#include "util/string.h"
+
+GUIPauseMenu::GUIPauseMenu(gui::IGUIEnvironment* env,
+ gui::IGUIElement* parent, s32 id,
+ IGameCallback *gamecallback,
+ IMenuManager *menumgr,
+ bool simple_singleplayer_mode):
+ GUIModalMenu(env, parent, id, menumgr),
+ m_gamecallback(gamecallback),
+ m_simple_singleplayer_mode(simple_singleplayer_mode)
+{
+}
+
+GUIPauseMenu::~GUIPauseMenu()
+{
+ removeChildren();
+}
+
+void GUIPauseMenu::removeChildren()
+{
+ {
+ gui::IGUIElement *e = getElementFromId(256);
+ if(e != NULL)
+ e->remove();
+ }
+ {
+ gui::IGUIElement *e = getElementFromId(257);
+ if(e != NULL)
+ e->remove();
+ }
+ {
+ gui::IGUIElement *e = getElementFromId(258);
+ if(e != NULL)
+ e->remove();
+ }
+ {
+ gui::IGUIElement *e = getElementFromId(259);
+ if(e != NULL)
+ e->remove();
+ }
+ {
+ gui::IGUIElement *e = getElementFromId(260);
+ if(e != NULL)
+ e->remove();
+ }
+ {
+ gui::IGUIElement *e = getElementFromId(261);
+ if(e != NULL)
+ e->remove();
+ }
+ {
+ gui::IGUIElement *e = getElementFromId(262);
+ if(e != NULL)
+ e->remove();
+ }
+}
+
+void GUIPauseMenu::regenerateGui(v2u32 screensize)
+{
+ /*
+ Remove stuff
+ */
+ removeChildren();
+
+ /*
+ Calculate new sizes and positions
+ */
+ core::rect<s32> rect(
+ screensize.X/2 - 580/2,
+ screensize.Y/2 - 300/2,
+ screensize.X/2 + 580/2,
+ screensize.Y/2 + 300/2
+ );
+
+ DesiredRect = rect;
+ recalculateAbsolutePosition(false);
+
+ v2s32 size = rect.getSize();
+
+ /*
+ Add stuff
+ */
+ const s32 btn_height = 30;
+ const s32 btn_gap = 20;
+ const s32 btn_num = m_simple_singleplayer_mode ? 4 : 5;
+ s32 btn_y = size.Y/2-((btn_num*btn_height+(btn_num-1)*btn_gap))/2;
+ changeCtype("");
+ {
+ core::rect<s32> rect(0, 0, 140, btn_height);
+ rect = rect + v2s32(size.X/2-140/2, btn_y);
+ wchar_t* text = wgettext("Continue");
+ Environment->addButton(rect, this, 256,
+ text);
+ delete[] text;
+ }
+ btn_y += btn_height + btn_gap;
+ if(!m_simple_singleplayer_mode)
+ {
+ {
+ core::rect<s32> rect(0, 0, 140, btn_height);
+ rect = rect + v2s32(size.X/2-140/2, btn_y);
+ wchar_t* text = wgettext("Change Password");
+ Environment->addButton(rect, this, 261,
+ text);
+ delete[] text;
+ }
+ btn_y += btn_height + btn_gap;
+ }
+ {
+ core::rect<s32> rect(0, 0, 140, btn_height);
+ rect = rect + v2s32(size.X/2-140/2, btn_y);
+ wchar_t* text = wgettext("Sound Volume");
+ Environment->addButton(rect, this, 262,
+ text);
+ delete[] text;
+ }
+ btn_y += btn_height + btn_gap;
+ {
+ core::rect<s32> rect(0, 0, 140, btn_height);
+ rect = rect + v2s32(size.X/2-140/2, btn_y);
+ wchar_t* text = wgettext("Exit to Menu");
+ Environment->addButton(rect, this, 260,
+ text);
+ delete[] text;
+ }
+ btn_y += btn_height + btn_gap;
+ {
+ core::rect<s32> rect(0, 0, 140, btn_height);
+ rect = rect + v2s32(size.X/2-140/2, btn_y);
+ wchar_t* text = wgettext("Exit to OS");
+ Environment->addButton(rect, this, 257,
+ text);
+ delete[] text;
+ }
+
+ {
+ core::rect<s32> rect(0, 0, 180, 240);
+ rect = rect + v2s32(size.X/2 + 90, size.Y/2-rect.getHeight()/2);
+ wchar_t* text = wgettext("Default Controls:\n"
+ "- WASD: move\n"
+ "- Space: jump/climb\n"
+ "- Shift: sneak/go down\n"
+ "- Q: drop item\n"
+ "- I: inventory\n"
+ "- Mouse: turn/look\n"
+ "- Mouse left: dig/punch\n"
+ "- Mouse right: place/use\n"
+ "- Mouse wheel: select item\n"
+ "- T: chat\n"
+ );
+ Environment->addStaticText(text, rect, false, true, this, 258);
+ delete[] text;
+
+ }
+ {
+ core::rect<s32> rect(0, 0, 180, 220);
+ rect = rect + v2s32(size.X/2 - 90 - rect.getWidth(), size.Y/2-rect.getHeight()/2);
+
+ v2u32 max_texture_size;
+ {
+ video::IVideoDriver* driver = Environment->getVideoDriver();
+ max_texture_size = driver->getMaxTextureSize();
+ }
+
+ std::ostringstream os;
+ os<<"Minetest\n";
+ os<<BUILD_INFO<<"\n";
+ os<<"path_user = "<<wrap_rows(porting::path_user, 20)<<"\n";
+
+ Environment->addStaticText(narrow_to_wide(os.str()).c_str(), rect, false, true, this, 259);
+ }
+ changeCtype("C");
+}
+
+void GUIPauseMenu::drawMenu()
+{
+ gui::IGUISkin* skin = Environment->getSkin();
+ if (!skin)
+ return;
+ video::IVideoDriver* driver = Environment->getVideoDriver();
+
+ video::SColor bgcolor(140,0,0,0);
+ driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
+
+ gui::IGUIElement::draw();
+}
+
+bool GUIPauseMenu::OnEvent(const SEvent& event)
+{
+
+ if(event.EventType==EET_KEY_INPUT_EVENT)
+ {
+ if(event.KeyInput.PressedDown)
+ {
+ if(event.KeyInput.Key==KEY_ESCAPE)
+ {
+ quitMenu();
+ return true;
+ }
+ else if(event.KeyInput.Key==KEY_RETURN)
+ {
+ quitMenu();
+ return true;
+ }
+ }
+ }
+ if(event.EventType==EET_GUI_EVENT)
+ {
+ if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
+ && isVisible())
+ {
+ if(!canTakeFocus(event.GUIEvent.Element))
+ {
+ dstream<<"GUIPauseMenu: Not allowing focus change."
+ <<std::endl;
+ // Returning true disables focus change
+ return true;
+ }
+ }
+ if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
+ {
+ switch(event.GUIEvent.Caller->getID())
+ {
+ case 256: // continue
+ quitMenu();
+ // ALWAYS return immediately after quitMenu()
+ return true;
+ case 261:
+ quitMenu();
+ m_gamecallback->changePassword();
+ return true;
+ case 262:
+ quitMenu();
+ m_gamecallback->changeVolume();
+ return true;
+ case 260: // disconnect
+ m_gamecallback->disconnect();
+ quitMenu();
+ return true;
+ case 257: // exit
+ m_gamecallback->exitToOS();
+ quitMenu();
+ return true;
+ }
+ }
+ }
+
+ return Parent ? Parent->OnEvent(event) : false;
+}
+