diff options
-rw-r--r-- | src/game.cpp | 1 | ||||
-rw-r--r-- | src/game.h | 9 | ||||
-rw-r--r-- | src/gui/setup_keyboard.cpp | 3 | ||||
-rw-r--r-- | src/gui/windowmenu.cpp | 69 | ||||
-rw-r--r-- | src/gui/windowmenu.h | 5 |
5 files changed, 77 insertions, 10 deletions
diff --git a/src/game.cpp b/src/game.cpp index af9c2c39..1e4c4076 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -64,7 +64,6 @@ #include "gui/textdialog.h" #include "gui/trade.h" #include "gui/viewport.h" -#include "gui/windowmenu.h" #include "gui/widgets/chattab.h" #include "gui/widgets/emoteshortcutcontainer.h" @@ -24,8 +24,9 @@ #include <string> +#include "gui/windowmenu.h" + class Map; -class WindowMenu; /** * The main class responsible for running the game. The game starts after you @@ -73,6 +74,12 @@ class Game int getCurrentTileWidth() const; int getCurrentTileHeight() const; + /** + * Update the key shortcuts in the window menu. + */ + void updateWindowMenuCaptions() + { mWindowMenu->updatePopUpCaptions(); } + private: int mLastTarget; bool mDisconnected; diff --git a/src/gui/setup_keyboard.cpp b/src/gui/setup_keyboard.cpp index d3ee3937..b8ce3e89 100644 --- a/src/gui/setup_keyboard.cpp +++ b/src/gui/setup_keyboard.cpp @@ -22,6 +22,7 @@ #include "gui/setup_keyboard.h" +#include "game.h" #include "keyboardconfig.h" #include "gui/gui.h" @@ -190,6 +191,8 @@ void Setup_Keyboard::refreshAssignedKey(int index) } mKeyListModel->setElementAt(index, caption); + if (Game *game = Game::instance()) + game->updateWindowMenuCaptions(); } void Setup_Keyboard::newKeyCallback(int index) diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp index a618ae8e..20b6f00c 100644 --- a/src/gui/windowmenu.cpp +++ b/src/gui/windowmenu.cpp @@ -163,6 +163,19 @@ void WindowMenu::valueChanged(const gcn::SelectionEvent &event) } } +static std::string createShortcutCaption(const std::string& text, + KeyboardConfig::KeyAction key) +{ + std::string caption = gettext(text.c_str()); + if (key != KeyboardConfig::KEY_NO_VALUE) + { + caption += " ("; + caption += SDL_GetKeyName((SDLKey) keyboard.getKeyValue(key)); + caption += ")"; + } + return caption; +} + void WindowMenu::addButton(const std::string& text, int &x, int &h, const std::string& iconPath, KeyboardConfig::KeyAction key) @@ -172,14 +185,7 @@ void WindowMenu::addButton(const std::string& text, int &x, int &h, { // When in image button mode, we have room to show // the keyboard shortcut. - std::string caption = gettext(text.c_str()); - if (key != KeyboardConfig::KEY_NO_VALUE) - { - caption += " ("; - caption += SDL_GetKeyName((SDLKey) keyboard.getKeyValue(key)); - caption += ")"; - } - btn->setButtonPopupText(caption); + btn->setButtonPopupText(createShortcutCaption(text, key)); } else { @@ -191,3 +197,50 @@ void WindowMenu::addButton(const std::string& text, int &x, int &h, x += btn->getWidth() + 3; h = std::max(h, btn->getHeight()); } + +void WindowMenu::updatePopUpCaptions() +{ + for (WidgetList::iterator it = mWidgets.begin(); it != mWidgets.end(); ++it) + { + Button *button = dynamic_cast<Button*> (*it); + if (button) + { + std::string eventId = button->getActionEventId(); + if (eventId == "Status") + { + button->setButtonPopupText(createShortcutCaption("Status", + KeyboardConfig::KEY_WINDOW_STATUS)); + } + else if (eventId == "Equipment") + { + button->setButtonPopupText(createShortcutCaption("Equipment", + KeyboardConfig::KEY_WINDOW_EQUIPMENT)); + } + else if (eventId == "Inventory") + { + button->setButtonPopupText(createShortcutCaption("Inventory", + KeyboardConfig::KEY_WINDOW_INVENTORY)); + } + else if (eventId == "Skills") + { + button->setButtonPopupText(createShortcutCaption("Skills", + KeyboardConfig::KEY_WINDOW_SKILL)); + } + else if (eventId == "Social") + { + button->setButtonPopupText(createShortcutCaption("Social", + KeyboardConfig::KEY_WINDOW_SOCIAL)); + } + else if (eventId == "Shortcut") + { + button->setButtonPopupText(createShortcutCaption("Shortcut", + KeyboardConfig::KEY_WINDOW_SHORTCUT)); + } + else if (eventId == "Setup") + { + button->setButtonPopupText(createShortcutCaption("Setup", + KeyboardConfig::KEY_WINDOW_SETUP)); + } + } + } +} diff --git a/src/gui/windowmenu.h b/src/gui/windowmenu.h index 09374943..962abaf5 100644 --- a/src/gui/windowmenu.h +++ b/src/gui/windowmenu.h @@ -49,6 +49,11 @@ class WindowMenu : public Container, void valueChanged(const gcn::SelectionEvent &event); + /** + * Update the pop-up captions with new key shortcuts. + */ + void updatePopUpCaptions(); + private: inline void addButton(const std::string& text, int &x, int &h, const std::string& iconPath = std::string(), |