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"
33 #include "gui/windows/clanwindow.h"
39 #include "gui/windows/chatwindow.h"
43 #include "gui/windows/helpwindow.h"
45 #include "gui/windows/killstats.h"
46 #include "gui/windows/mailwindow.h"
47 #include "gui/windows/minimap.h"
51 #include "gui/windows/shopwindow.h"
54 
56 
58 
59 #include "utils/gettext.h"
60 
61 #include "net/net.h"
62 
63 #include "debug.h"
64 
65 namespace Actions
66 {
67 
69 {
70  if (setupWindow != nullptr)
71  {
73  {
75  }
76  else
77  {
80  }
81  return true;
82  }
83  return false;
84 }
85 
87 {
88  if (setupWindow != nullptr)
90  return true;
91 }
92 
93 static bool showHelpPage(const std::string &page, const bool showHide)
94 {
95  if (helpWindow != nullptr)
96  {
97  if (showHide && helpWindow->isWindowVisible())
98  {
100  }
101  else
102  {
103  helpWindow->loadHelp(page);
105  }
106  return true;
107  }
108  return false;
109 }
110 
112 {
113  if ((chatWindow == nullptr) || !chatWindow->isInputFocused())
114  return showHelpPage("index", true);
115  if (event.tab == nullptr)
116  return showHelpPage("chatcommands", true);
117  switch (event.tab->getType())
118  {
119  case ChatTabType::PARTY:
120  return showHelpPage("chatparty", true);
121  case ChatTabType::GUILD:
122  return showHelpPage("chatguild", true);
124  return showHelpPage("chatwhisper", true);
125  case ChatTabType::DEBUG:
126  return showHelpPage("chatdebug", true);
127  case ChatTabType::TRADE:
128  return showHelpPage("chattrade", true);
129  case ChatTabType::BATTLE:
130  return showHelpPage("chatbattle", true);
131  case ChatTabType::LANG:
132  return showHelpPage("chatlang", true);
133  case ChatTabType::GM:
134  return showHelpPage("chatgm", true);
136  return showHelpPage("chatchannel", true);
137  case ChatTabType::CLAN:
138  return showHelpPage("chatclan", true);
139  default:
141  case ChatTabType::INPUT:
142  return showHelpPage("chatcommands", true);
143  }
144 }
145 
147 {
148  return showHelpPage("about", false);
149 }
150 
151 static void showHideWindow(Window *const window)
152 {
153  if (window != nullptr)
154  {
155  window->setVisible(fromBool(
156  !window->isWindowVisible(), Visible));
157  if (window->isWindowVisible())
158  window->requestMoveToTop();
159  }
160 }
161 
163 {
165  return true;
166 }
167 
169 {
171  return true;
172 }
173 
175 {
177  return true;
178 }
179 
181 {
183  return true;
184 }
185 
187 {
188  if (minimap != nullptr)
189  {
190  minimap->toggle();
191  return true;
192  }
193  return false;
194 }
195 
197 {
199  return true;
200 }
201 
203 {
205  return true;
206 }
207 
209 {
211  return true;
212 }
213 
215 {
217  return true;
218 }
219 
221 {
223  return true;
224 }
225 
227 {
229  return true;
230 }
231 
233 {
235  return true;
236 }
237 
239 {
241  return true;
242 }
243 
245 {
247  return true;
248 }
249 
251 {
253  return true;
254 }
255 
257 {
259  return true;
260 }
261 
263 {
265  return true;
266 }
267 
269 {
271  return true;
272 }
273 
275 {
276 #ifdef TMWA_SUPPORT
278  return false;
279 #endif // TMWA_SUPPORT
280 
282  return true;
283 }
284 
286 {
288  (localPlayer == nullptr) ||
290  {
291  return false;
292  }
293 
295  if (inventoryWindow != nullptr)
297  return true;
298 }
299 
301 {
302  if (updaterWindow != nullptr)
304  else
306  return true;
307 }
308 
310 {
311  if (setupWindow != nullptr)
312  {
316  // TRANSLATORS: settings tab name
317  setupWindow->activateTab(_("Quick"));
319  return true;
320  }
321  return false;
322 }
323 
325 {
327  return true;
328 }
329 
331 {
332  if (serverInfoWindow != nullptr &&
334  {
336  serverInfoWindow = nullptr;
337  }
338  else
339  {
343  }
344  return true;
345 }
346 
348 {
350  return true;
351 }
352 
354 {
355  const std::string args = event.args;
356  if (args.empty())
357  return false;
358 
359  Being *being = nullptr;
360  if (args[0] == ':')
361  {
362  being = actorManager->findBeing(fromInt(atoi(
363  args.substr(1).c_str()), BeingId));
364  if ((being != nullptr) && being->getType() == ActorType::Monster)
365  being = nullptr;
366  }
367  else
368  {
370  }
371  if (being == nullptr)
372  return true;
373  if (being == localPlayer)
374  {
375  if (equipmentWindow != nullptr &&
377  {
379  }
380  }
381  else
382  {
383  if (beingEquipmentWindow != nullptr)
384  {
387  }
388  }
389  return true;
390 }
391 
392 } // 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:89
#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:59
static bool showHelpPage(const std::string &page, const bool showHide)
Definition: windows.cpp:93
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
ClanWindow * clanWindow
Definition: clanwindow.cpp:37
bool isInputFocused() const
Definition: chatwindow.cpp:574
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:117
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:97
DidYouKnowWindow * didYouKnowWindow
void loadHelp(const std::string &helpFile)
Definition: helpwindow.cpp:125
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 clanWindowShow(InputEvent &event)
Definition: windows.cpp:58
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:151
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:100
ServerTypeT getNetworkType()
Definition: net.cpp:182
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