-/*\r
-Minetest-c55\r
-Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>\r
-Original author Kabak Dmitry <userdima@gmail.com>, contributed under\r
-the minetest contributor agreement.\r
-\r
-This program is free software; you can redistribute it and/or modify\r
-it under the terms of the GNU General Public License as published by\r
-the Free Software Foundation; either version 2 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 General Public License for more details.\r
-\r
-You should have received a copy of the GNU 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
-\r
-#include "guiPauseMenu.h"\r
-#include "debug.h"\r
-\r
-GUIPauseMenu::GUIPauseMenu(gui::IGUIEnvironment* env,\r
- gui::IGUIElement* parent, s32 id,\r
- IrrlichtDevice *dev):\r
- IGUIElement(gui::EGUIET_ELEMENT, env, parent, id,\r
- core::rect<s32>(0,0,100,100))\r
-{\r
- m_dev = dev;\r
- m_screensize_old = v2u32(0,0);\r
- \r
- resizeGui();\r
-\r
- setVisible(false);\r
-}\r
-\r
-GUIPauseMenu::~GUIPauseMenu()\r
-{\r
-}\r
-\r
-void GUIPauseMenu::resizeGui()\r
-{\r
- video::IVideoDriver* driver = Environment->getVideoDriver();\r
- v2u32 screensize = driver->getScreenSize();\r
- if(screensize == m_screensize_old)\r
- return;\r
- m_screensize_old = screensize;\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
- core::rect<s32> rect(\r
- screensize.X/2 - 560/2,\r
- screensize.Y/2 - 300/2,\r
- screensize.X/2 + 560/2,\r
- screensize.Y/2 + 300/2\r
- );\r
- \r
- DesiredRect = rect;\r
- recalculateAbsolutePosition(false);\r
-\r
- v2s32 size = rect.getSize();\r
-\r
- {\r
- core::rect<s32> rect(0, 0, 140, 30);\r
- rect = rect + v2s32(size.X/2-140/2, size.Y/2-30/2-25);\r
- Environment->addButton(rect, this, 256, L"Continue");\r
- }\r
- {\r
- core::rect<s32> rect(0, 0, 140, 30);\r
- rect = rect + v2s32(size.X/2-140/2, size.Y/2-30/2+25);\r
- Environment->addButton(rect, this, 257, L"Exit");\r
- }\r
-}\r
-\r
-void GUIPauseMenu::draw()\r
-{\r
- if(!IsVisible)\r
- return;\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
- if(event.EventType==EET_KEY_INPUT_EVENT)\r
- {\r
- if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)\r
- {\r
- setVisible(false);\r
- return true;\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
- setVisible(false);\r
- break;\r
- case 257: // exit\r
- m_dev->closeDevice();\r
- break;\r
- }\r
- }\r
- }\r
-\r
- return Parent ? Parent->OnEvent(event) : false;\r
-}\r
-\r
-#if 0\r
-GUIPauseMenu::GUIPauseMenu(IrrlichtDevice *device, IEventReceiver *recv):\r
- dev(device),\r
- oldRecv(recv)\r
-{\r
- if(!dev)\r
- return;\r
- guienv=dev->getGUIEnvironment();\r
-\r
- if (!loadMenu())\r
- return;\r
-\r
- device->setEventReceiver(this); // now WE are the input receiver! ahhaha! \r
-}\r
-\r
-GUIPauseMenu::~GUIPauseMenu(void)\r
-{\r
-}\r
-\r
-void GUIPauseMenu::scaleGui() // this function scales gui from the size stored in file to screen size\r
-{\r
- core::dimension2du screen=dev->getVideoDriver()->getScreenSize();\r
- core::vector2di real=root->getAbsolutePosition().LowerRightCorner; // determine gui size stored in file (which is size of my menu root node)\r
- float factorX=(float)screen.Width/(float)real.X;\r
- float factorY=(float)screen.Height/(float)real.Y;\r
- scaleGui(guienv->getRootGUIElement(),factorX,factorY);\r
-}\r
-void GUIPauseMenu::scaleGui(gui::IGUIElement *node,float factorX,float factorY) // recursive set scale\r
-{\r
- if((node->getParent() && node->getParent()->getID()==255) || node->getID()==255) // modify only menu's elements\r
- {\r
- int lx,rx,ly,ry;\r
- lx=(float)node->getRelativePosition().UpperLeftCorner.X*factorX;\r
- ly=(float)node->getRelativePosition().UpperLeftCorner.Y*factorY;\r
- rx=(float)node->getRelativePosition().LowerRightCorner.X*factorX;\r
- ry=(float)node->getRelativePosition().LowerRightCorner.Y*factorY;\r
- node->setRelativePosition(core::recti(lx,ly,rx,ry));\r
- }\r
-\r
- core::list<gui::IGUIElement*>::ConstIterator it = node->getChildren().begin();\r
- for(; it != node->getChildren().end(); ++it)\r
- scaleGui((*it),factorX,factorY);\r
-}\r
-\r
-bool GUIPauseMenu::loadMenu()\r
-{\r
- guienv->loadGUI("../data/pauseMenu.gui");\r
-\r
- root=(gui::IGUIStaticText*)guienv->getRootGUIElement()->getElementFromId(255,true);\r
- if(!root) // if there is no my root node then menu file not found or corrupted\r
- return false;\r
-\r
- scaleGui(); // scale gui to our screen size\r
-\r
- root->setVisible(false); // hide our menu\r
- // make it transparent\r
- //root->setBackgroundColor(video::SColor(100,128,100,128));\r
- root->setBackgroundColor(video::SColor(140,0,0,0));\r
-\r
- return true;\r
-}\r
-\r
-bool GUIPauseMenu::OnEvent(const SEvent& event)\r
-{\r
- if(!dev->isWindowFocused())\r
- setVisible(true);\r
-\r
- bool ret=false;\r
- if(oldRecv && !isVisible()) // call master if we have it and if we are inactive\r
- ret=oldRecv->OnEvent(event);\r
-\r
- if(ret==true)\r
- return true; // if the master receiver does the work\r
-\r
- if(event.EventType==EET_KEY_INPUT_EVENT)\r
- {\r
- if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)\r
- {\r
- setVisible(!isVisible());\r
- }\r
- }\r
- if(event.EventType==EET_GUI_EVENT)\r
- {\r
- if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)\r
- {\r
- switch(event.GUIEvent.Caller->getID())\r
- {\r
- case 256: // continue\r
- setVisible(false);\r
- break;\r
- case 257: // exit\r
- dev->closeDevice();\r
- break;\r
- }\r
- }\r
- }\r
-\r
- return false;\r
-}\r
-#endif\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 "version.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;
+ {
+ 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<<minetest_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);
+ }
+}
+
+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;
+}
+