Add cancel button to password change menu. (#5720)
[oweals/minetest.git] / src / guiKeyChangeMenu.cpp
index 9b5a31d267368dd2ca7e16ac41664ca7cdd11eb0..ae53c56f9153ade63c150683a4efad2d99e2d77a 100644 (file)
@@ -22,7 +22,6 @@
 #include "guiKeyChangeMenu.h"
 #include "debug.h"
 #include "serialization.h"
-#include "main.h"
 #include <string>
 #include <IGUICheckBox.h>
 #include <IGUIEditBox.h>
@@ -54,12 +53,19 @@ enum
        GUI_ID_KEY_CINEMATIC_BUTTON,
        GUI_ID_KEY_CHAT_BUTTON,
        GUI_ID_KEY_CMD_BUTTON,
+       GUI_ID_KEY_CMD_LOCAL_BUTTON,
        GUI_ID_KEY_CONSOLE_BUTTON,
        GUI_ID_KEY_SNEAK_BUTTON,
        GUI_ID_KEY_DROP_BUTTON,
        GUI_ID_KEY_INVENTORY_BUTTON,
+       GUI_ID_KEY_HOTBAR_PREV_BUTTON,
+       GUI_ID_KEY_HOTBAR_NEXT_BUTTON,
+       GUI_ID_KEY_MUTE_BUTTON,
+       GUI_ID_KEY_DEC_VOLUME_BUTTON,
+       GUI_ID_KEY_INC_VOLUME_BUTTON,
        GUI_ID_KEY_DUMP_BUTTON,
        GUI_ID_KEY_RANGE_BUTTON,
+       GUI_ID_KEY_ZOOM_BUTTON,
        // other
        GUI_ID_CB_AUX1_DESCENDS,
        GUI_ID_CB_DOUBLETAP_JUMP,
@@ -82,7 +88,7 @@ GUIKeyChangeMenu::~GUIKeyChangeMenu()
        removeChildren();
 
        for (std::vector<key_setting*>::iterator iter = key_settings.begin();
-                       iter != key_settings.end(); iter ++) {
+                       iter != key_settings.end(); ++iter) {
                delete[] (*iter)->button_name;
                delete (*iter);
        }
@@ -108,7 +114,7 @@ void GUIKeyChangeMenu::removeChildren()
 void GUIKeyChangeMenu::regenerateGui(v2u32 screensize)
 {
        removeChildren();
-       v2s32 size(620, 430);
+       v2s32 size(745, 430);
        
        core::rect < s32 > rect(screensize.X / 2 - size.X / 2,
                                                        screensize.Y / 2 - size.Y / 2, screensize.X / 2 + size.X / 2,
@@ -138,22 +144,24 @@ void GUIKeyChangeMenu::regenerateGui(v2u32 screensize)
        {
                key_setting *k = key_settings.at(i);
                {
-                       core::rect < s32 > rect(0, 0, 110, 20);
+                       core::rect < s32 > rect(0, 0, 150, 20);
                        rect += topleft + v2s32(offset.X, offset.Y);
                        Environment->addStaticText(k->button_name, rect, false, true, this, -1);
                }
 
                {
                        core::rect < s32 > rect(0, 0, 100, 30);
-                       rect += topleft + v2s32(offset.X + 115, offset.Y - 5);
+                       rect += topleft + v2s32(offset.X + 120, offset.Y - 5);
                        const wchar_t *text = wgettext(k->key.name());
                        k->button = Environment->addButton(rect, this, k->id, text);
                        delete[] text;
                }
-               if(i + 1 == KMaxButtonPerColumns)
-                       offset = v2s32(260, 60);
-               else
+               if ((i + 1) % KMaxButtonPerColumns == 0) {
+                       offset.X += 230;
+                       offset.Y = 60;
+               } else {
                        offset += v2s32(0, 25);
+               }
        }
        
        {
@@ -188,7 +196,7 @@ void GUIKeyChangeMenu::regenerateGui(v2u32 screensize)
 
        {
                core::rect < s32 > rect(0, 0, 100, 30);
-               rect += topleft + v2s32(size.X - 100 - 20, size.Y - 40);
+               rect += topleft + v2s32(size.X / 2 - 105, size.Y - 40);
                const wchar_t *text =  wgettext("Save");
                Environment->addButton(rect, this, GUI_ID_BACK_BUTTON,
                                 text);
@@ -196,7 +204,7 @@ void GUIKeyChangeMenu::regenerateGui(v2u32 screensize)
        }
        {
                core::rect < s32 > rect(0, 0, 100, 30);
-               rect += topleft + v2s32(size.X - 100 - 20 - 100 - 20, size.Y - 40);
+               rect += topleft + v2s32(size.X / 2 + 5, size.Y - 40);
                const wchar_t *text = wgettext("Cancel");
                Environment->addButton(rect, this, GUI_ID_ABORT_BUTTON,
                                text);
@@ -214,7 +222,7 @@ void GUIKeyChangeMenu::drawMenu()
        video::SColor bgcolor(140, 0, 0, 0);
 
        {
-               core::rect < s32 > rect(0, 0, 620, 620);
+               core::rect < s32 > rect(0, 0, 745, 620);
                rect += AbsoluteRect.UpperLeftCorner;
                driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
        }
@@ -270,8 +278,7 @@ bool GUIKeyChangeMenu::resetMenu()
 bool GUIKeyChangeMenu::OnEvent(const SEvent& event)
 {
        if (event.EventType == EET_KEY_INPUT_EVENT && activeKey >= 0
-               && event.KeyInput.PressedDown)
-       {
+                       && event.KeyInput.PressedDown) {
                
                bool prefer_character = shift_down;
                KeyPress kp(event.KeyInput, prefer_character);
@@ -303,7 +310,7 @@ bool GUIKeyChangeMenu::OnEvent(const SEvent& event)
 
                // But go on
                {
-                       key_setting *k=NULL;
+                       key_setting *k = NULL;
                        for(size_t i = 0; i < key_settings.size(); i++)
                        {
                                if(key_settings.at(i)->id == activeKey)
@@ -312,7 +319,7 @@ bool GUIKeyChangeMenu::OnEvent(const SEvent& event)
                                        break;
                                }
                        }
-                       assert(k);
+                       FATAL_ERROR_IF(k == NULL, "Key setting not found");
                        k->key = kp;
                        const wchar_t *text = wgettext(k->key.name());
                        k->button->setText(text);
@@ -329,9 +336,12 @@ bool GUIKeyChangeMenu::OnEvent(const SEvent& event)
                                return true;
                        }
                }
-       }
-       if (event.EventType == EET_GUI_EVENT)
-       {
+       } else if (event.EventType == EET_KEY_INPUT_EVENT && activeKey < 0
+                       && event.KeyInput.PressedDown
+                       && event.KeyInput.Key == irr::KEY_ESCAPE) {
+               quitMenu();
+               return true;
+       } else if (event.EventType == EET_GUI_EVENT) {
                if (event.GUIEvent.EventType == gui::EGET_ELEMENT_FOCUS_LOST
                        && isVisible())
                {
@@ -364,7 +374,7 @@ bool GUIKeyChangeMenu::OnEvent(const SEvent& event)
                                                        break;
                                                }
                                        }
-                                       assert(k);
+                                       FATAL_ERROR_IF(k == NULL, "Key setting not found");
 
                                        resetMenu();
                                        shift_down = false;
@@ -404,8 +414,14 @@ void GUIKeyChangeMenu::init_keys()
        this->add_key(GUI_ID_KEY_SNEAK_BUTTON,     wgettext("Sneak"),            "keymap_sneak");
        this->add_key(GUI_ID_KEY_DROP_BUTTON,      wgettext("Drop"),             "keymap_drop");
        this->add_key(GUI_ID_KEY_INVENTORY_BUTTON, wgettext("Inventory"),        "keymap_inventory");
+       this->add_key(GUI_ID_KEY_HOTBAR_PREV_BUTTON,wgettext("Prev. item"),      "keymap_hotbar_previous");
+       this->add_key(GUI_ID_KEY_HOTBAR_NEXT_BUTTON,wgettext("Next item"),       "keymap_hotbar_next");
+       this->add_key(GUI_ID_KEY_MUTE_BUTTON,      wgettext("Mute"),             "keymap_mute");
+       this->add_key(GUI_ID_KEY_DEC_VOLUME_BUTTON,wgettext("Dec. volume"),      "keymap_decrease_volume");
+       this->add_key(GUI_ID_KEY_INC_VOLUME_BUTTON,wgettext("Inc. volume"),      "keymap_increase_volume");
        this->add_key(GUI_ID_KEY_CHAT_BUTTON,      wgettext("Chat"),             "keymap_chat");
        this->add_key(GUI_ID_KEY_CMD_BUTTON,       wgettext("Command"),          "keymap_cmd");
+       this->add_key(GUI_ID_KEY_CMD_LOCAL_BUTTON, wgettext("Local command"),    "keymap_cmd_local");
        this->add_key(GUI_ID_KEY_CONSOLE_BUTTON,   wgettext("Console"),          "keymap_console");
        this->add_key(GUI_ID_KEY_FLY_BUTTON,       wgettext("Toggle fly"),       "keymap_freemove");
        this->add_key(GUI_ID_KEY_FAST_BUTTON,      wgettext("Toggle fast"),      "keymap_fastmove");
@@ -413,5 +429,6 @@ void GUIKeyChangeMenu::init_keys()
        this->add_key(GUI_ID_KEY_NOCLIP_BUTTON,    wgettext("Toggle noclip"),    "keymap_noclip");
        this->add_key(GUI_ID_KEY_RANGE_BUTTON,     wgettext("Range select"),     "keymap_rangeselect");
        this->add_key(GUI_ID_KEY_DUMP_BUTTON,      wgettext("Print stacks"),     "keymap_print_debug_stacks");
+       this->add_key(GUI_ID_KEY_ZOOM_BUTTON,      wgettext("Zoom"),             "keymap_zoom");
 }