ManaPlus
windows.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2012-2018 The ManaPlus Developers
4  *
5  * This file is part of The ManaPlus Client.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include "actions/windows.h"
22 
23 #include "actormanager.h"
24 #include "client.h"
25 
26 #include "actions/actiondef.h"
27 
28 #include "being/localplayer.h"
29 
30 #include "gui/dialogsmanager.h"
31 
32 #include "gui/windows/bankwindow.h"
38 #include "gui/windows/chatwindow.h"
42 #include "gui/windows/helpwindow.h"
44 #include "gui/windows/killstats.h"
45 #include "gui/windows/mailwindow.h"
46 #include "gui/windows/minimap.h"
50 #include "gui/windows/shopwindow.h"
53 
55 
57 
58 #include "utils/gettext.h"
59 
60 #include "net/net.h"
61 
62 #include "debug.h"
63 
64 namespace Actions
65 {
66 
68 {
69  if (setupWindow != nullptr)
70  {
72  {
74  }
75  else
76  {
79  }
80  return true;
81  }
82  return false;
83 }
84 
86 {
87  if (setupWindow != nullptr)
89  return true;
90 }
91 
92 static bool showHelpPage(const std::string &page, const bool showHide)
93 {
94  if (helpWindow != nullptr)
95  {
96  if (showHide && helpWindow->isWindowVisible())
97  {
99  }
100  else
101  {
102  helpWindow->loadHelp(page);
104  }
105  return true;
106  }
107  return false;
108 }
109 
111 {
112  if ((chatWindow == nullptr) || !chatWindow->isInputFocused())
113  return showHelpPage("index", true);
114  if (event.tab == nullptr)
115  return showHelpPage("chatcommands", true);
116  switch (event.tab->getType())
117  {
118  case ChatTabType::PARTY:
119  return showHelpPage("chatparty", true);
120  case ChatTabType::GUILD:
121  return showHelpPage("chatguild", true);
123  return showHelpPage("chatwhisper", true);
124  case ChatTabType::DEBUG:
125  return showHelpPage("chatdebug", true);
126  case ChatTabType::TRADE:
127  return showHelpPage("chattrade", true);
128  case ChatTabType::BATTLE:
129  return showHelpPage("chatbattle", true);
130  case ChatTabType::LANG:
131  return showHelpPage("chatlang", true);
132  case ChatTabType::GM:
133  return showHelpPage("chatgm", true);
135  return showHelpPage("chatchannel", true);
136  default:
138  case ChatTabType::INPUT:
139  return showHelpPage("chatcommands", true);
140  }
141 }
142 
144 {
145  return showHelpPage("about", false);
146 }
147 
148 static void showHideWindow(Window *const window)
149 {
150  if (window != nullptr)
151  {
152  window->setVisible(fromBool(
153  !window->isWindowVisible(), Visible));
154  if (window->isWindowVisible())
155  window->requestMoveToTop();
156  }
157 }
158 
160 {
162  return true;
163 }
164 
166 {
168  return true;
169 }
170 
172 {
174  return true;
175 }
176 
178 {
180  return true;
181 }
182 
184 {
185  if (minimap != nullptr)
186  {
187  minimap->toggle();
188  return true;
189  }
190  return false;
191 }
192 
194 {
196  return true;
197 }
198 
200 {
202  return true;
203 }
204 
206 {
208  return true;
209 }
210 
212 {
214  return true;
215 }
216 
218 {
220  return true;
221 }
222 
224 {
226  return true;
227 }
228 
230 {
232  return true;
233 }
234 
236 {
238  return true;
239 }
240 
242 {
244  return true;
245 }
246 
248 {
250  return true;
251 }
252 
254 {
256  return true;
257 }
258 
260 {
262  return true;
263 }
264 
266 {
268  return true;
269 }
270 
272 {
273 #ifdef TMWA_SUPPORT
275  return false;
276 #endif // TMWA_SUPPORT
277 
279  return true;
280 }
281 
283 {
285  (localPlayer == nullptr) ||
287  {
288  return false;
289  }
290 
292  if (inventoryWindow != nullptr)
294  return true;
295 }
296 
298 {
299  if (updaterWindow != nullptr)
301  else
303  return true;
304 }
305 
307 {
308  if (setupWindow != nullptr)
309  {
313  // TRANSLATORS: settings tab name
314  setupWindow->activateTab(_("Quick"));
316  return true;
317  }
318  return false;
319 }
320 
322 {
324  return true;
325 }
326 
328 {
329  if (serverInfoWindow != nullptr &&
331  {
333  serverInfoWindow = nullptr;
334  }
335  else
336  {
340  }
341  return true;
342 }
343 
345 {
346  const std::string args = event.args;
347  if (args.empty())
348  return false;
349 
350  Being *being = nullptr;
351  if (args[0] == ':')
352  {
353  being = actorManager->findBeing(fromInt(atoi(
354  args.substr(1).c_str()), BeingId));
355  if ((being != nullptr) && being->getType() == ActorType::Monster)
356  being = nullptr;
357  }
358  else
359  {
361  }
362  if (being == nullptr)
363  return true;
364  if (being == localPlayer)
365  {
366  if (equipmentWindow != nullptr &&
368  {
370  }
371  }
372  else
373  {
374  if (beingEquipmentWindow != nullptr)
375  {
378  }
379  }
380  return true;
381 }
382 
383 } // namespace Actions
bool bankWindowShow(InputEvent &event)
Definition: windows.cpp:52
bool emoteShortcutWindowShow(InputEvent &event)
Definition: windows.cpp:43
void hideWindows()
DebugWindow * debugWindow
Definition: debugwindow.cpp:39
ChatWindow * chatWindow
Definition: chatwindow.cpp:88
#define _(s)
Definition: gettext.h:34
bool helpWindowShow(InputEvent &event)
Definition: windows.cpp:32
void activateTab(const std::string &name)
void setBeing(Being *const being)
bool skillDialogShow(InputEvent &event)
Definition: windows.cpp:37
const bool Visible_true
Definition: visible.h:29
bool whoIsOnlineWindowShow(InputEvent &event)
Definition: windows.cpp:49
bool didYouKnowWindowShow(InputEvent &event)
Definition: windows.cpp:50
OutfitWindow * outfitWindow
QuestsWindow * questsWindow
bool cartWindowShow(InputEvent &event)
Definition: windows.cpp:53
#define fromInt(val, name)
Definition: intdefines.h:45
bool debugWindowShow(InputEvent &event)
Definition: windows.cpp:41
bool showItems(InputEvent &event)
Definition: windows.cpp:58
static bool showHelpPage(const std::string &page, const bool showHide)
Definition: windows.cpp:92
void toggle()
Definition: minimap.cpp:247
virtual void requestMoveToTop()
Definition: widget.cpp:212
bool serverInfoWindowShow(InputEvent &event)
Definition: windows.cpp:57
BankWindow * bankWindow
Definition: bankwindow.cpp:39
Definition: window.h:98
bool setupWindowShow(InputEvent &event)
Definition: windows.cpp:30
int BeingId
Definition: beingid.h:29
bool isInputFocused() const
Definition: chatwindow.cpp:573
StatusWindow * statusWindow
WhoIsOnline * whoIsOnline
Definition: whoisonline.cpp:78
#define impHandler0(name)
Definition: actiondef.h:33
bool updaterWindowShow(InputEvent &event)
Definition: windows.cpp:54
Client * client
Definition: client.cpp:113
bool outfitWindowShow(InputEvent &event)
Definition: windows.cpp:44
bool shortcutWindowShow(InputEvent &event)
Definition: windows.cpp:40
bool quickWindowShow(InputEvent &event)
Definition: windows.cpp:55
InventoryWindow * inventoryWindow
ServerInfo & getCurrentServer()
Definition: client.h:93
DidYouKnowWindow * didYouKnowWindow
void loadHelp(const std::string &helpFile)
Definition: helpwindow.cpp:124
static void createUpdaterWindow()
bool questsWindowShow(InputEvent &event)
Definition: windows.cpp:51
ShortcutWindow * dropShortcutWindow
KillStats * killStats
Definition: killstats.cpp:45
const bool Visible_false
Definition: visible.h:29
#define fromBool(val, name)
Definition: booldefines.h:48
bool statusWindowShow(InputEvent &event)
Definition: windows.cpp:34
LocalPlayer * localPlayer
EquipmentWindow * beingEquipmentWindow
bool dropShortcutWindowShow(InputEvent &event)
Definition: windows.cpp:46
ServerInfoWindow * serverInfoWindow
Being * findBeing(const BeingId id) const
void doCancel()
bool isWindowVisible() const
Definition: window.h:483
void setVisible(Visible visible)
ActorTypeT getType() const
Definition: being.h:115
ShortcutWindow * itemShortcutWindow
UpdaterWindow * updaterWindow
bool mailWindowShow(InputEvent &event)
Definition: windows.cpp:56
ShortcutWindow * spellShortcutWindow
static void showHideWindow(Window *const window)
Definition: windows.cpp:148
SocialWindow * socialWindow
bool equipmentWindowShow(InputEvent &event)
Definition: windows.cpp:36
bool minimapWindowShow(InputEvent &event)
Definition: windows.cpp:38
ShortcutWindow * emoteShortcutWindow
bool killStatsWindowShow(InputEvent &event)
Definition: windows.cpp:47
ShopWindow * shopWindow
Definition: shopwindow.cpp:99
ServerTypeT getNetworkType()
Definition: net.cpp:178
bool socialWindowShow(InputEvent &event)
Definition: windows.cpp:42
SkillDialog * skillDialog
Definition: skilldialog.cpp:65
virtual void setVisible(Visible visible)
Definition: window.cpp:773
bool Visible
Definition: visible.h:29
bool hideWindows(InputEvent &event)
Definition: windows.cpp:31
InventoryWindow * cartWindow
bool aboutWindowShow(InputEvent &event)
Definition: windows.cpp:33
EquipmentWindow * equipmentWindow
bool chatWindowShow(InputEvent &event)
Definition: windows.cpp:39
Being * findBeingByName(const std::string &name, const ActorTypeT type) const
SetupWindow * setupWindow
Definition: setupwindow.cpp:63
MailWindow * mailWindow
Definition: mailwindow.cpp:53
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:35
HelpWindow * helpWindow
Definition: helpwindow.cpp:53
Definition: being.h:93
bool spellShortcutWindowShow(InputEvent &event)
Definition: windows.cpp:48
bool shopWindowShow(InputEvent &event)
Definition: windows.cpp:45
bool getHaveCart() const
Definition: actorsprite.h:174
#define impHandler(name)
Definition: actiondef.h:32
bool inventoryWindowShow(InputEvent &event)
Definition: windows.cpp:35
ActorManager * actorManager
Minimap * minimap
Definition: minimap.cpp:61