Introduce hotkey for calling up a command window
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Sat, 13 Aug 2011 16:16:49 +0000 (18:16 +0200)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Mon, 22 Aug 2011 11:02:08 +0000 (13:02 +0200)
This is just a chat window with the / text pre-loaded.

src/defaultsettings.cpp
src/game.cpp
src/guiKeyChangeMenu.cpp
src/guiKeyChangeMenu.h

index 2659978579fe534553b5125bb53d928e6dafb37c..8438bf4f54db190adcbbcb64f33653c8009f6974 100644 (file)
@@ -39,6 +39,7 @@ void set_default_settings()
        g_settings.setDefault("keymap_sneak", "KEY_LSHIFT");
        g_settings.setDefault("keymap_inventory", "KEY_KEY_I");
        g_settings.setDefault("keymap_chat", "KEY_KEY_T");
+       g_settings.setDefault("keymap_cmd", "/");
        g_settings.setDefault("keymap_rangeselect", "KEY_KEY_R");
        g_settings.setDefault("keymap_freemove", "KEY_KEY_K");
        g_settings.setDefault("keymap_fastmove", "KEY_KEY_J");
index 22fab706c53246420bad6bf764c7734a1cfe6950..dd1e58b4b87a1a2e952b27ea1a80d9ff5dc77a7f 100644 (file)
@@ -1320,6 +1320,14 @@ void the_game(
                                        &g_menumgr, dest,
                                        L""))->drop();
                }
+               else if(input->wasKeyDown(getKeySetting("keymap_cmd")))
+               {
+                       TextDest *dest = new TextDestChat(&client);
+
+                       (new GUITextInputMenu(guienv, guiroot, -1,
+                                       &g_menumgr, dest,
+                                       L"/"))->drop();
+               }
                else if(input->wasKeyDown(getKeySetting("keymap_freemove")))
                {
                        if(g_settings.getBool("free_move"))
index 5968d5c12b156b4ea0efa69ef7ff6bc66ca4fc74..d6de114937887adc6856045dc185daadf7f5cdf0 100644 (file)
@@ -226,6 +226,21 @@ void GUIKeyChangeMenu::regenerateGui(v2u32 screensize)
                this->chat = Environment->addButton(rect, this, GUI_ID_KEY_CHAT_BUTTON,
                                wgettext(key_chat.name()));
        }
+       offset += v2s32(0, 25);
+       {
+               core::rect < s32 > rect(0, 0, 100, 20);
+               rect += topleft + v2s32(offset.X, offset.Y);
+               Environment->addStaticText(wgettext("Command"), rect, false, true, this, -1);
+               //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
+       }
+
+       {
+               core::rect < s32 > rect(0, 0, 100, 30);
+               rect += topleft + v2s32(offset.X + 105, offset.Y - 5);
+               this->cmd = Environment->addButton(rect, this, GUI_ID_KEY_CMD_BUTTON,
+                               wgettext(key_cmd.name()));
+       }
+
 
        //next col
        offset = v2s32(250, 40);
@@ -333,6 +348,7 @@ bool GUIKeyChangeMenu::acceptInput()
        g_settings.set("keymap_sneak", key_sneak.sym());
        g_settings.set("keymap_inventory", key_inventory.sym());
        g_settings.set("keymap_chat", key_chat.sym());
+       g_settings.set("keymap_cmd", key_cmd.sym());
        g_settings.set("keymap_rangeselect", key_range.sym());
        g_settings.set("keymap_freemove", key_fly.sym());
        g_settings.set("keymap_fastmove", key_fast.sym());
@@ -351,6 +367,7 @@ void GUIKeyChangeMenu::init_keys()
        key_sneak = getKeySetting("keymap_sneak");
        key_inventory = getKeySetting("keymap_inventory");
        key_chat = getKeySetting("keymap_chat");
+       key_cmd = getKeySetting("keymap_cmd");
        key_range = getKeySetting("keymap_rangeselect");
        key_fly = getKeySetting("keymap_freemove");
        key_fast = getKeySetting("keymap_fastmove");
@@ -391,6 +408,9 @@ bool GUIKeyChangeMenu::resetMenu()
                case GUI_ID_KEY_CHAT_BUTTON:
                        this->chat->setText(wgettext(key_chat.name()));
                        break;
+               case GUI_ID_KEY_CMD_BUTTON:
+                       this->cmd->setText(wgettext(key_cmd.name()));
+                       break;
                case GUI_ID_KEY_RANGE_BUTTON:
                        this->range->setText(wgettext(key_range.name()));
                        break;
@@ -460,6 +480,11 @@ bool GUIKeyChangeMenu::OnEvent(const SEvent& event)
                        this->chat->setText(wgettext(kp.name()));
                        this->key_chat = kp;
                }
+               else if (activeKey == GUI_ID_KEY_CMD_BUTTON)
+               {
+                       this->cmd->setText(wgettext(kp.name()));
+                       this->key_cmd = kp;
+               }
                else if (activeKey == GUI_ID_KEY_RANGE_BUTTON)
                {
                        this->range->setText(wgettext(kp.name()));
@@ -564,6 +589,11 @@ bool GUIKeyChangeMenu::OnEvent(const SEvent& event)
                                activeKey = event.GUIEvent.Caller->getID();
                                this->chat->setText(wgettext("press Key"));
                                break;
+                       case GUI_ID_KEY_CMD_BUTTON:
+                               resetMenu();
+                               activeKey = event.GUIEvent.Caller->getID();
+                               this->cmd->setText(wgettext("press Key"));
+                               break;
                        case GUI_ID_KEY_SNEAK_BUTTON:
                                resetMenu();
                                activeKey = event.GUIEvent.Caller->getID();
index a1dfa17c255a51bddced5ec53d53904f5c10e2ae..2e8773a779e4469663a4371e93c25a906a59a3d4 100644 (file)
@@ -43,6 +43,7 @@ enum
        GUI_ID_KEY_FAST_BUTTON,
        GUI_ID_KEY_JUMP_BUTTON,
        GUI_ID_KEY_CHAT_BUTTON,
+       GUI_ID_KEY_CMD_BUTTON,
        GUI_ID_KEY_SNEAK_BUTTON,
        GUI_ID_KEY_INVENTORY_BUTTON,
        GUI_ID_KEY_DUMP_BUTTON,
@@ -87,6 +88,7 @@ private:
        gui::IGUIButton *range;
        gui::IGUIButton *dump;
        gui::IGUIButton *chat;
+       gui::IGUIButton *cmd;
 
        s32 activeKey;
        KeyPress key_forward;
@@ -101,6 +103,7 @@ private:
        KeyPress key_fast;
        KeyPress key_range;
        KeyPress key_chat;
+       KeyPress key_cmd;
        KeyPress key_dump;
 };