summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/quitdialog.cpp2
-rw-r--r--src/gui/quitdialog.h6
-rw-r--r--src/gui/setup_keyboard.cpp3
-rw-r--r--src/gui/specialswindow.h3
-rw-r--r--src/gui/widgets/button.cpp74
-rw-r--r--src/gui/widgets/button.h18
-rw-r--r--src/gui/widgets/tabbedarea.cpp8
-rw-r--r--src/gui/widgets/tabbedarea.h2
-rw-r--r--src/gui/windowmenu.cpp108
-rw-r--r--src/gui/windowmenu.h12
10 files changed, 207 insertions, 29 deletions
diff --git a/src/gui/quitdialog.cpp b/src/gui/quitdialog.cpp
index 6ecc62a6..3da07206 100644
--- a/src/gui/quitdialog.cpp
+++ b/src/gui/quitdialog.cpp
@@ -44,7 +44,9 @@ QuitDialog::QuitDialog(QuitDialog** pointerToMe):
mSwitchAccountServer = new RadioButton(_("Switch server"), "quitdialog");
mSwitchCharacter = new RadioButton(_("Switch character"), "quitdialog");
mOkButton = new Button(_("OK"), "ok", this);
+ mOkButton->setButtonIcon("button-icon-confirm.png");
mCancelButton = new Button(_("Cancel"), "cancel", this);
+ mCancelButton->setButtonIcon("button-icon-cancel.png");
addKeyListener(this);
diff --git a/src/gui/quitdialog.h b/src/gui/quitdialog.h
index 65a325b8..21fe2f8a 100644
--- a/src/gui/quitdialog.h
+++ b/src/gui/quitdialog.h
@@ -29,6 +29,8 @@
#include <vector>
+class Button;
+
/**
* The quit dialog.
*
@@ -62,8 +64,8 @@ class QuitDialog : public Window, public gcn::ActionListener,
gcn::RadioButton *mForceQuit;
gcn::RadioButton *mSwitchAccountServer;
gcn::RadioButton *mSwitchCharacter;
- gcn::Button *mOkButton;
- gcn::Button *mCancelButton;
+ Button *mOkButton;
+ Button *mCancelButton;
QuitDialog **mMyPointer;
};
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/specialswindow.h b/src/gui/specialswindow.h
index dedeeffc..b440ce13 100644
--- a/src/gui/specialswindow.h
+++ b/src/gui/specialswindow.h
@@ -51,6 +51,9 @@ class SpecialsWindow : public Window, public gcn::ActionListener {
void draw(gcn::Graphics *graphics);
+ bool hasSpecials()
+ { return !mEntries.empty(); }
+
private:
// (re)constructs the list of specials
void rebuild(const std::map<int, Special> &specialData);
diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp
index f072ef61..61ec28a2 100644
--- a/src/gui/widgets/button.cpp
+++ b/src/gui/widgets/button.cpp
@@ -25,6 +25,7 @@
#include "graphics.h"
#include "gui/palette.h"
+#include "gui/textpopup.h"
#include "resources/image.h"
#include "resources/theme.h"
@@ -36,7 +37,8 @@
int Button::mInstances = 0;
float Button::mAlpha = 1.0;
-ImageRect *Button::mButton;
+ImageRect* Button::mButton;
+TextPopup* Button::mTextPopup = 0;
enum{
BUTTON_STANDARD, // 0
@@ -81,23 +83,26 @@ Button::Button(const std::string &caption, const std::string &actionEventId,
adjustSize();
}
-void Button::setButtonIcon(const std::string& iconFile, int frameHeight,
- int frameWidth)
+bool Button::setButtonIcon(const std::string& iconFile)
{
// We clean up possible older references.
if (mButtonIcon)
removeButtonIcon();
// If nothing relevant was set, we can quit now.
- if (iconFile.empty() || !frameWidth || !frameHeight)
- return;
+ if (iconFile.empty())
+ return false;
// Load the icon frames.
Image *btnIcons = Theme::getImageFromTheme(iconFile);
if (!btnIcons)
- return;
+ return false;
- if (btnIcons->getWidth() > 0 && btnIcons->getHeight() > 0)
+ // Compute the sub images size.
+ const int frameWidth = btnIcons->getWidth() / 4;
+ const int frameHeight = btnIcons->getHeight();
+
+ if (frameWidth > 0 && frameHeight > 0)
{
mButtonIcon = new Image*[BUTTON_COUNT];
for (int mode = 0; mode < BUTTON_COUNT; ++mode)
@@ -110,6 +115,7 @@ void Button::setButtonIcon(const std::string& iconFile, int frameHeight,
}
btnIcons->decRef();
+ return (mButtonIcon);
}
void Button::removeButtonIcon()
@@ -159,6 +165,10 @@ void Button::init()
btn[mode]->decRef();
}
updateAlpha();
+
+ // Load the popup
+ if (!mTextPopup)
+ mTextPopup = new TextPopup();
}
mInstances++;
}
@@ -175,6 +185,9 @@ Button::~Button()
dtor<Image*>());
}
delete[] mButton;
+
+ // Remove the popup
+ delete mTextPopup;
}
removeButtonIcon();
}
@@ -301,3 +314,50 @@ void Button::setCaption(const std::string& caption)
mCaption = caption;
adjustSize();
}
+
+void Button::logic()
+{
+ gcn::Button::logic();
+ mTextPopup->logic();
+}
+
+void Button::mouseMoved(gcn::MouseEvent &event)
+{
+ gcn::Button::mouseMoved(event);
+ mTextPopup->mouseMoved(event);
+
+ int x = event.getX();
+ int y = event.getY();
+
+ if (event.getSource() == this && !mPopupText.empty())
+ {
+ if (mParent)
+ {
+ x += mParent->getX();
+ y += mParent->getY();
+ }
+
+ mTextPopup->show(x + getX(), y + getY(), mPopupText);
+ }
+ else
+ {
+ mTextPopup->setVisible(false);
+ }
+}
+
+void Button::mouseExited(gcn::MouseEvent &event)
+{
+ gcn::Button::mouseExited(event);
+ mTextPopup->mouseExited(event);
+
+ mTextPopup->setVisible(false);
+}
+
+void Button::setButtonPopupText(const std::string& text)
+{
+ mPopupText = text;
+ if (!mPopupText.empty())
+ mTextPopup->show(getX(), getY(), mPopupText);
+ else
+ mTextPopup->setVisible(false);
+}
diff --git a/src/gui/widgets/button.h b/src/gui/widgets/button.h
index 6d8f773c..7463d2ad 100644
--- a/src/gui/widgets/button.h
+++ b/src/gui/widgets/button.h
@@ -26,6 +26,7 @@
class ImageRect;
class Image;
+class TextPopup;
/**
* Button widget. Same as the Guichan button but with custom look.
@@ -71,8 +72,18 @@ class Button : public gcn::Button
* Standard, Highlighted, Pressed, and Disabled.
* If the image is too short, the missing states won't be loaded.
*/
- void setButtonIcon(const std::string& iconFile = std::string(),
- int frameHeight = 0, int frameWidth = 0);
+ bool setButtonIcon(const std::string& iconFile = std::string());
+
+ /**
+ * Set the button popup text when hovering it for a few seconds.
+ *
+ * @note: An empty text will disable the popup.
+ */
+ void setButtonPopupText(const std::string& text = std::string());
+
+ void logic();
+ void mouseMoved(gcn::MouseEvent &event);
+ void mouseExited(gcn::MouseEvent &event);
private:
void init();
@@ -84,6 +95,9 @@ class Button : public gcn::Button
static float mAlpha;
Image** mButtonIcon; /**< Button Icons graphics */
+
+ static TextPopup* mTextPopup; /**< The buttons popup */
+ std::string mPopupText; /**< the current button text */
};
#endif
diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp
index 412d3ddc..9b51b311 100644
--- a/src/gui/widgets/tabbedarea.cpp
+++ b/src/gui/widgets/tabbedarea.cpp
@@ -33,8 +33,12 @@ TabbedArea::TabbedArea() : gcn::TabbedArea(),
mWidgetContainer->setOpaque(false);
addWidgetListener(this);
- mArrowButton[0] = new Button("<", "shift_left", this);
- mArrowButton[1] = new Button(">", "shift_right", this);
+ mArrowButton[0] = new Button("", "shift_left", this);
+ mArrowButton[1] = new Button("", "shift_right", this);
+ if (!mArrowButton[0]->setButtonIcon("tab_arrows_left.png"))
+ mArrowButton[0]->setCaption("<");
+ if (!mArrowButton[1]->setButtonIcon("tab_arrows_right.png"))
+ mArrowButton[1]->setCaption(">");
add(mArrowButton[0]);
add(mArrowButton[1]);
diff --git a/src/gui/widgets/tabbedarea.h b/src/gui/widgets/tabbedarea.h
index d364eac5..cb29a756 100644
--- a/src/gui/widgets/tabbedarea.h
+++ b/src/gui/widgets/tabbedarea.h
@@ -117,7 +117,7 @@ class TabbedArea : public gcn::TabbedArea, public gcn::WidgetListener
typedef std::vector< std::pair<gcn::Tab*, gcn::Widget*> > TabContainer;
/** The tab arrows */
- gcn::Button *mArrowButton[2];
+ Button *mArrowButton[2];
/** Check whether the arrow should be clickable */
void updateArrowEnableState();
diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp
index 542ab4a0..2cac55b5 100644
--- a/src/gui/windowmenu.cpp
+++ b/src/gui/windowmenu.cpp
@@ -50,20 +50,27 @@ WindowMenu::WindowMenu():
{
int x = 0, h = 0;
- addButton(":-)", x, h);
- addButton(N_("Status"), x, h);
- addButton(N_("Equipment"), x, h);
- addButton(N_("Inventory"), x, h);
+ addButton(":-)", x, h, "button-icon-smilies.png");
+ addButton(N_("Status"), x, h, "button-icon-status.png",
+ KeyboardConfig::KEY_WINDOW_STATUS);
+ addButton(N_("Inventory"), x, h, "button-icon-inventory.png",
+ KeyboardConfig::KEY_WINDOW_INVENTORY);
+ addButton(N_("Equipment"), x, h, "button-icon-equipment.png",
+ KeyboardConfig::KEY_WINDOW_EQUIPMENT);
if (skillDialog->hasSkills())
- addButton(N_("Skills"), x, h);
+ addButton(N_("Skills"), x, h, "button-icon-skills.png",
+ KeyboardConfig::KEY_WINDOW_SKILL);
- // if (specialsWindow->hasSpecials())
- addButton(N_("Specials"), x, h);
+ if (specialsWindow->hasSpecials())
+ addButton(N_("Specials"), x, h, "button-icon-specials.png");
- addButton(N_("Social"), x, h);
- addButton(N_("Shortcut"), x, h);
- addButton(N_("Setup"), x, h);
+ addButton(N_("Social"), x, h, "button-icon-social.png",
+ KeyboardConfig::KEY_WINDOW_SOCIAL);
+ addButton(N_("Shortcuts"), x, h, "button-icon-shortcut.png",
+ KeyboardConfig::KEY_WINDOW_SHORTCUT);
+ addButton(N_("Setup"), x, h, "button-icon-setup.png",
+ KeyboardConfig::KEY_WINDOW_SETUP);
setDimension(gcn::Rectangle(graphics->getWidth() - x - 3, 3,
x - 3, h));
@@ -124,7 +131,7 @@ void WindowMenu::action(const gcn::ActionEvent &event)
{
window = socialWindow;
}
- else if (event.getId() == "Shortcut")
+ else if (event.getId() == "Shortcuts")
{
window = itemShortcutWindow;
}
@@ -156,11 +163,84 @@ void WindowMenu::valueChanged(const gcn::SelectionEvent &event)
}
}
-void WindowMenu::addButton(const char* text, int &x, int &h)
+static std::string createShortcutCaption(const std::string& text,
+ KeyboardConfig::KeyAction key)
{
- gcn::Button *btn = new Button(gettext(text), text, this);
+ 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)
+{
+ Button *btn = new Button("", text, this);
+ if (!iconPath.empty() && btn->setButtonIcon(iconPath))
+ {
+ // When in image button mode, we have room to show
+ // the keyboard shortcut.
+ btn->setButtonPopupText(createShortcutCaption(text, key));
+ }
+ else
+ {
+ btn->setCaption(gettext(text.c_str()));
+ }
+
btn->setPosition(x, 0);
add(btn);
x += btn->getWidth() + 3;
- h = btn->getHeight();
+ 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 == "Shortcuts")
+ {
+ button->setButtonPopupText(createShortcutCaption("Shortcuts",
+ 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 2bb3e764..962abaf5 100644
--- a/src/gui/windowmenu.h
+++ b/src/gui/windowmenu.h
@@ -22,6 +22,8 @@
#ifndef WINDOWMENU_H
#define WINDOWMENU_H
+#include "keyboardconfig.h"
+
#include "gui/widgets/container.h"
#include <guichan/actionlistener.hpp>
@@ -47,8 +49,16 @@ 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 char* text, int &x, int &h);
+ inline void addButton(const std::string& text, int &x, int &h,
+ const std::string& iconPath = std::string(),
+ KeyboardConfig::KeyAction key =
+ KeyboardConfig::KEY_NO_VALUE);
EmotePopup *mEmotePopup;
};