Mana
Loading...
Searching...
No Matches
windowmenu.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include "gui/windowmenu.h"
23
24#include "graphics.h"
25
26#include "gui/abilitieswindow.h"
27#include "gui/emotepopup.h"
28#include "gui/questswindow.h"
29#include "gui/skilldialog.h"
30
31#include "gui/widgets/button.h"
32#include "gui/widgets/window.h"
34
35#include "net/net.h"
36#include "net/playerhandler.h"
37
38#include "resources/questdb.h"
39
40#include "utils/gettext.h"
41
42#include <string>
43
47extern Window *setupWindow;
48extern Window *statusWindow;
49extern Window *socialWindow;
50
52{
53 int x = 0, h = 0;
54
55 addButton(":-)", x, h, "button-icon-smilies.png");
56 addButton(N_("Status"), x, h, "button-icon-status.png",
58 addButton(N_("Inventory"), x, h, "button-icon-inventory.png",
60 addButton(N_("Equipment"), x, h, "button-icon-equipment.png",
62
64 addButton(N_("Skills"), x, h, "button-icon-skills.png",
66
68 addButton(N_("Abilities"), x, h, "button-icon-abilities.png");
69
71 addButton(N_("Quests"), x, h, "button-icon-quests.png");
72
73 addButton(N_("Social"), x, h, "button-icon-social.png",
75 addButton(N_("Shortcuts"), x, h, "button-icon-shortcut.png",
77 addButton(N_("Setup"), x, h, "button-icon-setup.png",
79
80 setDimension(gcn::Rectangle(graphics->getWidth() - x, 3,
81 x - 3, h));
82 setVisible(true);
83}
84
89
90void WindowMenu::action(const gcn::ActionEvent &event)
91{
92 Window *window = nullptr;
93
94 if (event.getId() == ":-)")
95 {
96 if (!mEmotePopup)
97 {
98 const gcn::Widget *s = event.getSource();
99 const gcn::Rectangle &r = s->getDimension();
100 const int parentX = s->getParent()->getX();
101
103 const int offset = (r.width - mEmotePopup->getWidth()) / 2;
104 mEmotePopup->setPosition(parentX + r.x + offset,
105 r.y + r.height + 5);
106
108 }
109 else
110 {
112 mEmotePopup = nullptr;
113 }
114 }
115 else if (event.getId() == "Status")
116 {
117 window = statusWindow;
118 }
119 else if (event.getId() == "Equipment")
120 {
121 window = equipmentWindow;
122 }
123 else if (event.getId() == "Inventory")
124 {
125 window = inventoryWindow;
126 }
127 else if (event.getId() == "Skills")
128 {
129 window = skillDialog;
130 }
131 else if (event.getId() == "Quests")
132 {
133 window = questsWindow;
134 }
135 else if (event.getId() == "Abilities")
136 {
137 window = abilitiesWindow;
138 }
139 else if (event.getId() == "Social")
140 {
141 window = socialWindow;
142 }
143 else if (event.getId() == "Shortcuts")
144 {
145 window = itemShortcutWindow;
146 }
147 else if (event.getId() == "Setup")
148 {
149 window = setupWindow;
150 }
151
152 if (window)
153 {
154 window->setVisible(!window->isVisible());
155 if (window->isVisible())
156 {
157 window->requestMoveToTop();
158 }
159 }
160}
161
162void WindowMenu::valueChanged(const gcn::SelectionEvent &event)
163{
164 if (event.getSource() == mEmotePopup)
165 {
166 int emoteId = mEmotePopup->getSelectedEmoteId();
167 if (emoteId != -1)
168 Net::getPlayerHandler()->emote(emoteId);
169
171 mEmotePopup = nullptr;
172 }
173}
174
175static std::string createShortcutCaption(const std::string &text,
177{
178 std::string caption = gettext(text.c_str());
179
181 {
182 auto keyValue = keyboard.getKeyValue(key);
183 if (keyValue > 0)
184 {
185 caption += " (";
186 caption += SDL_GetKeyName(keyValue);
187 caption += ")";
188 }
189 }
190
191 return caption;
192}
193
194void WindowMenu::addButton(const std::string &text, int &x, int &h,
195 const std::string &iconPath,
197{
198 auto *btn = new Button(std::string(), text, this);
199 if (!iconPath.empty() && btn->setButtonIcon(iconPath))
200 {
201 btn->setButtonPopupText(createShortcutCaption(text, key));
202 }
203 else
204 {
205 btn->setCaption(gettext(text.c_str()));
206 btn->setButtonPopupText(createShortcutCaption(std::string(), key));
207 }
208
209 btn->setPosition(x, 0);
210 add(btn);
211 x += btn->getWidth() + 3;
212 h = std::max(h, btn->getHeight());
213}
214
216{
217 for (auto &widget : mWidgets)
218 {
219 auto *button = dynamic_cast<Button*>(widget);
220 if (!button)
221 continue;
222
223 const std::string &eventId = button->getActionEventId();
224 if (eventId == "Status")
225 {
226 button->setButtonPopupText(createShortcutCaption(eventId,
228 }
229 else if (eventId == "Equipment")
230 {
231 button->setButtonPopupText(createShortcutCaption(eventId,
233 }
234 else if (eventId == "Inventory")
235 {
236 button->setButtonPopupText(createShortcutCaption(eventId,
238 }
239 else if (eventId == "Skills")
240 {
241 button->setButtonPopupText(createShortcutCaption(eventId,
243 }
244 else if (eventId == "Quests")
245 {
246 button->setButtonPopupText(
247 createShortcutCaption(eventId, KeyboardConfig::KEY_WINDOW_QUESTS));
248 }
249 else if (eventId == "Social")
250 {
251 button->setButtonPopupText(createShortcutCaption(eventId,
253 }
254 else if (eventId == "Shortcuts")
255 {
256 button->setButtonPopupText(createShortcutCaption(eventId,
258 }
259 else if (eventId == "Setup")
260 {
261 button->setButtonPopupText(createShortcutCaption(eventId,
263 }
264 }
265}
bool hasAbilities() const
Button widget.
Definition button.h:38
void setButtonPopupText(const std::string &text)
Set the button popup text when hovering it for a few seconds.
Definition button.h:78
An emote popup.
Definition emotepopup.h:43
void addSelectionListener(gcn::SelectionListener *listener)
Adds a listener to the list that's notified each time a change to the selection occurs.
Definition emotepopup.h:70
int getSelectedEmoteId() const
Returns the selected emote.
int getWidth() const
Returns the logical width of the screen.
Definition graphics.h:221
int getKeyValue(int index) const
Obtain the value stored in memory.
KeyAction
All the key functions.
virtual void emote(int emoteId)=0
bool hasSkills()
Definition skilldialog.h:76
void scheduleDelete(gcn::Widget *widget)
Schedule a widget for deletion.
~WindowMenu() override
void valueChanged(const gcn::SelectionEvent &event) override
void addButton(const std::string &text, int &x, int &h, const std::string &iconPath=std::string(), KeyboardConfig::KeyAction key=KeyboardConfig::KEY_NO_VALUE)
void action(const gcn::ActionEvent &event) override
void updatePopUpCaptions()
Update the pop-up captions with new key shortcuts.
EmotePopup * mEmotePopup
Definition windowmenu.h:62
A window.
Definition window.h:59
virtual void setVisible(bool visible)
Overloads window setVisible by Guichan to allow sticky window handling.
Definition window.cpp:282
Graphics * graphics
Definition client.cpp:104
KeyboardConfig keyboard
Definition client.cpp:101
AbilitiesWindow * abilitiesWindow
Definition game.cpp:107
InventoryWindow * inventoryWindow
Definition game.cpp:96
SocialWindow * socialWindow
Definition game.cpp:108
QuestsWindow * questsWindow
Definition game.cpp:98
ShortcutWindow * itemShortcutWindow
Definition game.cpp:104
EquipmentWindow * equipmentWindow
Definition game.cpp:100
StatusWindow * statusWindow
Definition game.cpp:94
SkillDialog * skillDialog
Definition game.cpp:97
#define gettext(s)
Definition gettext.h:37
#define N_(s)
Definition gettext.h:39
PlayerHandler * getPlayerHandler()
Definition net.cpp:110
bool hasQuests()
Definition questdb.cpp:124
Setup * setupWindow
Definition setup.cpp:120
WindowContainer * windowContainer
Window * equipmentWindow
Definition game.cpp:100
Window * statusWindow
Definition game.cpp:94
Window * setupWindow
Definition setup.cpp:120
Window * inventoryWindow
Definition game.cpp:96
Window * itemShortcutWindow
Definition game.cpp:104
Window * socialWindow
Definition game.cpp:108