summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-07-15 20:41:05 +0200
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-08-11 02:39:49 +0200
commit30d2e0c9a16a981c895c070e9f972d577fadc531 (patch)
tree55a3ac596adbc5d93deba2aee0177580c2730c83
parent3bdb7ebbcc6f7d08ed90f2232f0901b1c0e92d51 (diff)
downloadmana-30d2e0c9a16a981c895c070e9f972d577fadc531.tar.gz
mana-30d2e0c9a16a981c895c070e9f972d577fadc531.tar.bz2
mana-30d2e0c9a16a981c895c070e9f972d577fadc531.tar.xz
mana-30d2e0c9a16a981c895c070e9f972d577fadc531.zip
The shortcuts are now refreshed when reassigning keys.
-rw-r--r--src/game.cpp1
-rw-r--r--src/game.h9
-rw-r--r--src/gui/setup_keyboard.cpp3
-rw-r--r--src/gui/windowmenu.cpp69
-rw-r--r--src/gui/windowmenu.h5
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"
diff --git a/src/game.h b/src/game.h
index 22e242c9..9e38f928 100644
--- a/src/game.h
+++ b/src/game.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(),