ManaPlus
windows.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2012-2019 The ManaPlus Developers
4  * Copyright (C) 2019-2021 Andrei Karas
5  *
6  * This file is part of The ManaPlus 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 "actions/windows.h"
23 
24 #include "actormanager.h"
25 #include "client.h"
26 
27 #include "actions/actiondef.h"
28 
29 #include "being/localplayer.h"
30 
31 #include "gui/dialogsmanager.h"
32 
33 #include "gui/windows/bankwindow.h"
34 #include "gui/windows/clanwindow.h"
40 #include "gui/windows/chatwindow.h"
44 #include "gui/windows/helpwindow.h"
46 #include "gui/windows/killstats.h"
47 #include "gui/windows/mailwindow.h"
48 #include "gui/windows/minimap.h"
52 #include "gui/windows/shopwindow.h"
55 
57 
59 
60 #include "utils/gettext.h"
61 
62 #include "net/net.h"
63 
64 #include "debug.h"
65 
66 namespace Actions
67 {
68 
70 {
71  if (setupWindow != nullptr)
72  {
74  {
76  }
77  else
78  {
81  }
82  return true;
83  }
84  return false;
85 }
86 
88 {
89  if (setupWindow != nullptr)
91  return true;
92 }
93 
94 static bool showHelpPage(const std::string &page, const bool showHide)
95 {
96  if (helpWindow != nullptr)
97  {
98  if (showHide && helpWindow->isWindowVisible())
99  {
101  }
102  else
103  {
104  helpWindow->loadHelp(page);
106  }
107  return true;
108  }
109  return false;
110 }
111 
113 {
114  if ((chatWindow == nullptr) || !chatWindow->isInputFocused())
115  return showHelpPage("index", true);
116  if (event.tab == nullptr)
117  return showHelpPage("chatcommands", true);
118  switch (event.tab->getType())
119  {
120  case ChatTabType::PARTY:
121  return showHelpPage("chatparty", true);
122  case ChatTabType::GUILD:
123  return showHelpPage("chatguild", true);
125  return showHelpPage("chatwhisper", true);
126  case ChatTabType::DEBUG:
127  return showHelpPage("chatdebug", true);
128  case ChatTabType::TRADE:
129  return showHelpPage("chattrade", true);
130  case ChatTabType::BATTLE:
131  return showHelpPage("chatbattle", true);
132  case ChatTabType::LANG:
133  return showHelpPage("chatlang", true);
134  case ChatTabType::GM:
135  return showHelpPage("chatgm", true);
137  return showHelpPage("chatchannel", true);
138  case ChatTabType::CLAN:
139  return showHelpPage("chatclan", true);
140  default:
142  case ChatTabType::INPUT:
143  return showHelpPage("chatcommands", true);
144  }
145 }
146 
148 {
149  return showHelpPage("about", false);
150 }
151 
152 static void showHideWindow(Window *const window)
153 {
154  if (window != nullptr)
155  {
156  window->setVisible(fromBool(
157  !window->isWindowVisible(), Visible));
158  if (window->isWindowVisible())
159  window->requestMoveToTop();
160  }
161 }
162 
164 {
166  return true;
167 }
168 
170 {
172  return true;
173 }
174 
176 {
178  return true;
179 }
180 
182 {
184  return true;
185 }
186 
188 {
189  if (minimap != nullptr)
190  {
191  minimap->toggle();
192  return true;
193  }
194  return false;
195 }
196 
198 {
200  return true;
201 }
202 
204 {
206  return true;
207 }
208 
210 {
212  return true;
213 }
214 
216 {
218  return true;
219 }
220 
222 {
224  return true;
225 }
226 
228 {
230  return true;
231 }
232 
234 {
236  return true;
237 }
238 
240 {
242  return true;
243 }
244 
246 {
248  return true;
249 }
250 
252 {
254  return true;
255 }
256 
258 {
260  return true;
261 }
262 
264 {
266  return true;
267 }
268 
270 {
272  return true;
273 }
274 
276 {
277 #ifdef TMWA_SUPPORT
279  return false;
280 #endif // TMWA_SUPPORT
281 
283  return true;
284 }
285 
287 {
289  (localPlayer == nullptr) ||
291  {
292  return false;
293  }
294 
296  if (inventoryWindow != nullptr)
298  return true;
299 }
300 
302 {
303  if (updaterWindow != nullptr)
305  else
307  return true;
308 }
309 
311 {
312  if (setupWindow != nullptr)
313  {
317  // TRANSLATORS: settings tab name
318  setupWindow->activateTab(_("Quick"));
320  return true;
321  }
322  return false;
323 }
324 
326 {
328  return true;
329 }
330 
332 {
333  if (serverInfoWindow != nullptr &&
335  {
337  serverInfoWindow = nullptr;
338  }
339  else
340  {
344  }
345  return true;
346 }
347 
349 {
351  return true;
352 }
353 
355 {
356  const std::string args = event.args;
357  if (args.empty())
358  return false;
359 
360  Being *being = nullptr;
361  if (args[0] == ':')
362  {
363  being = actorManager->findBeing(fromInt(atoi(
364  args.substr(1).c_str()), BeingId));
365  if ((being != nullptr) && being->getType() == ActorType::Monster)
366  being = nullptr;
367  }
368  else
369  {
371  }
372  if (being == nullptr)
373  return true;
374  if (being == localPlayer)
375  {
376  if (equipmentWindow != nullptr &&
378  {
380  }
381  }
382  else
383  {
384  if (beingEquipmentWindow != nullptr)
385  {
388  }
389  }
390  return true;
391 }
392 
393 } // namespace Actions
#define impHandler0(name)
Definition: actiondef.h:34
#define impHandler(name)
Definition: actiondef.h:33
ActorManager * actorManager
BankWindow * bankWindow
Definition: bankwindow.cpp:40
int BeingId
Definition: beingid.h:30
#define fromBool(val, name)
Definition: booldefines.h:49
ChatWindow * chatWindow
Definition: chatwindow.cpp:94
ClanWindow * clanWindow
Definition: clanwindow.cpp:38
Being * findBeing(const BeingId id) const
Being * findBeingByName(const std::string &name, const ActorTypeT type) const
bool getHaveCart() const
Definition: actorsprite.h:175
Definition: being.h:96
ActorTypeT getType() const
Definition: being.h:116
bool isInputFocused() const
Definition: chatwindow.cpp:579
ServerInfo & getCurrentServer()
Definition: client.h:98
static void createUpdaterWindow()
void setBeing(Being *const being)
void loadHelp(const std::string &helpFile)
Definition: helpwindow.cpp:126
void toggle()
Definition: minimap.cpp:248
void doCancel()
void hideWindows()
void setVisible(Visible visible)
void activateTab(const std::string &name)
virtual void requestMoveToTop()
Definition: widget.cpp:213
Definition: window.h:102
virtual void setVisible(Visible visible)
Definition: window.cpp:778
bool isWindowVisible() const
Definition: window.h:484
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:36
DebugWindow * debugWindow
Definition: debugwindow.cpp:43
DidYouKnowWindow * didYouKnowWindow
Client * client
Definition: client.cpp:118
EquipmentWindow * equipmentWindow
EquipmentWindow * beingEquipmentWindow
#define _(s)
Definition: gettext.h:35
HelpWindow * helpWindow
Definition: helpwindow.cpp:54
#define fromInt(val, name)
Definition: intdefines.h:46
InventoryWindow * inventoryWindow
InventoryWindow * cartWindow
KillStats * killStats
Definition: killstats.cpp:45
LocalPlayer * localPlayer
MailWindow * mailWindow
Definition: mailwindow.cpp:54
Minimap * minimap
Definition: minimap.cpp:62
bool updaterWindowShow(InputEvent &event)
Definition: windows.cpp:55
bool setupWindowShow(InputEvent &event)
Definition: windows.cpp:31
bool serverInfoWindowShow(InputEvent &event)
Definition: windows.cpp:58
bool shortcutWindowShow(InputEvent &event)
Definition: windows.cpp:41
bool debugWindowShow(InputEvent &event)
Definition: windows.cpp:42
bool didYouKnowWindowShow(InputEvent &event)
Definition: windows.cpp:51
bool hideWindows(InputEvent &event)
Definition: windows.cpp:32
bool quickWindowShow(InputEvent &event)
Definition: windows.cpp:56
bool whoIsOnlineWindowShow(InputEvent &event)
Definition: windows.cpp:50
bool cartWindowShow(InputEvent &event)
Definition: windows.cpp:54
bool socialWindowShow(InputEvent &event)
Definition: windows.cpp:43
bool clanWindowShow(InputEvent &event)
Definition: windows.cpp:59
bool inventoryWindowShow(InputEvent &event)
Definition: windows.cpp:36
static bool showHelpPage(const std::string &page, const bool showHide)
Definition: windows.cpp:94
bool equipmentWindowShow(InputEvent &event)
Definition: windows.cpp:37
bool statusWindowShow(InputEvent &event)
Definition: windows.cpp:35
bool aboutWindowShow(InputEvent &event)
Definition: windows.cpp:34
bool showItems(InputEvent &event)
Definition: windows.cpp:60
bool shopWindowShow(InputEvent &event)
Definition: windows.cpp:46
bool dropShortcutWindowShow(InputEvent &event)
Definition: windows.cpp:47
bool mailWindowShow(InputEvent &event)
Definition: windows.cpp:57
bool helpWindowShow(InputEvent &event)
Definition: windows.cpp:33
bool outfitWindowShow(InputEvent &event)
Definition: windows.cpp:45
bool killStatsWindowShow(InputEvent &event)
Definition: windows.cpp:48
bool skillDialogShow(InputEvent &event)
Definition: windows.cpp:38
static void showHideWindow(Window *const window)
Definition: windows.cpp:152
bool questsWindowShow(InputEvent &event)
Definition: windows.cpp:52
bool spellShortcutWindowShow(InputEvent &event)
Definition: windows.cpp:49
bool emoteShortcutWindowShow(InputEvent &event)
Definition: windows.cpp:44
bool chatWindowShow(InputEvent &event)
Definition: windows.cpp:40
bool bankWindowShow(InputEvent &event)
Definition: windows.cpp:53
bool minimapWindowShow(InputEvent &event)
Definition: windows.cpp:39
ServerTypeT getNetworkType()
Definition: net.cpp:189
OutfitWindow * outfitWindow
QuestsWindow * questsWindow
ServerInfoWindow * serverInfoWindow
SetupWindow * setupWindow
Definition: setupwindow.cpp:64
ShopWindow * shopWindow
Definition: shopwindow.cpp:101
ShortcutWindow * dropShortcutWindow
ShortcutWindow * spellShortcutWindow
ShortcutWindow * emoteShortcutWindow
ShortcutWindow * itemShortcutWindow
SkillDialog * skillDialog
Definition: skilldialog.cpp:66
SocialWindow * socialWindow
StatusWindow * statusWindow
UpdaterWindow * updaterWindow
bool Visible
Definition: visible.h:30
const bool Visible_false
Definition: visible.h:30
const bool Visible_true
Definition: visible.h:30
WhoIsOnline * whoIsOnline
Definition: whoisonline.cpp:82