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" |
35 |
|
|
#include "gui/windows/skilldialog.h" |
36 |
|
|
#include "gui/windows/socialwindow.h" |
37 |
|
|
#include "gui/windows/statuswindow.h" |
38 |
|
|
#include "gui/windows/questswindow.h" |
39 |
|
|
#include "gui/windows/whoisonline.h" |
40 |
|
|
#include "gui/windows/chatwindow.h" |
41 |
|
|
#include "gui/windows/debugwindow.h" |
42 |
|
|
#include "gui/windows/didyouknowwindow.h" |
43 |
|
|
#include "gui/windows/equipmentwindow.h" |
44 |
|
|
#include "gui/windows/helpwindow.h" |
45 |
|
|
#include "gui/windows/inventorywindow.h" |
46 |
|
|
#include "gui/windows/killstats.h" |
47 |
|
|
#include "gui/windows/mailwindow.h" |
48 |
|
|
#include "gui/windows/minimap.h" |
49 |
|
|
#include "gui/windows/outfitwindow.h" |
50 |
|
|
#include "gui/windows/setupwindow.h" |
51 |
|
|
#include "gui/windows/serverinfowindow.h" |
52 |
|
|
#include "gui/windows/shopwindow.h" |
53 |
|
|
#include "gui/windows/shortcutwindow.h" |
54 |
|
|
#include "gui/windows/updaterwindow.h" |
55 |
|
|
|
56 |
|
|
#include "gui/widgets/createwidget.h" |
57 |
|
|
|
58 |
|
|
#include "gui/widgets/tabs/chat/chattab.h" |
59 |
|
|
|
60 |
|
|
#include "utils/gettext.h" |
61 |
|
|
|
62 |
|
|
#include "net/net.h" |
63 |
|
|
|
64 |
|
|
#include "debug.h" |
65 |
|
|
|
66 |
|
|
namespace Actions |
67 |
|
|
{ |
68 |
|
|
|
69 |
|
|
impHandler0(setupWindowShow) |
70 |
|
|
{ |
71 |
|
|
if (setupWindow != nullptr) |
72 |
|
|
{ |
73 |
|
|
if (setupWindow->isWindowVisible()) |
74 |
|
|
{ |
75 |
|
|
setupWindow->doCancel(); |
76 |
|
|
} |
77 |
|
|
else |
78 |
|
|
{ |
79 |
|
|
setupWindow->setVisible(Visible_true); |
80 |
|
|
setupWindow->requestMoveToTop(); |
81 |
|
|
} |
82 |
|
|
return true; |
83 |
|
|
} |
84 |
|
|
return false; |
85 |
|
|
} |
86 |
|
|
|
87 |
|
|
impHandler0(hideWindows) |
88 |
|
|
{ |
89 |
|
|
if (setupWindow != nullptr) |
90 |
|
|
setupWindow->hideWindows(); |
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 |
|
|
{ |
100 |
|
|
helpWindow->setVisible(Visible_false); |
101 |
|
|
} |
102 |
|
|
else |
103 |
|
|
{ |
104 |
|
|
helpWindow->loadHelp(page); |
105 |
|
|
helpWindow->requestMoveToTop(); |
106 |
|
|
} |
107 |
|
|
return true; |
108 |
|
|
} |
109 |
|
|
return false; |
110 |
|
|
} |
111 |
|
|
|
112 |
|
|
impHandler(helpWindowShow) |
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); |
124 |
|
|
case ChatTabType::WHISPER: |
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); |
136 |
|
|
case ChatTabType::CHANNEL: |
137 |
|
|
return showHelpPage("chatchannel", true); |
138 |
|
|
case ChatTabType::CLAN: |
139 |
|
|
return showHelpPage("chatclan", true); |
140 |
|
|
default: |
141 |
|
|
case ChatTabType::UNKNOWN: |
142 |
|
|
case ChatTabType::INPUT: |
143 |
|
|
return showHelpPage("chatcommands", true); |
144 |
|
|
} |
145 |
|
|
} |
146 |
|
|
|
147 |
|
|
impHandler0(aboutWindowShow) |
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 |
|
|
|
163 |
|
|
impHandler0(statusWindowShow) |
164 |
|
|
{ |
165 |
|
|
showHideWindow(statusWindow); |
166 |
|
|
return true; |
167 |
|
|
} |
168 |
|
|
|
169 |
|
|
impHandler0(inventoryWindowShow) |
170 |
|
|
{ |
171 |
|
|
showHideWindow(inventoryWindow); |
172 |
|
|
return true; |
173 |
|
|
} |
174 |
|
|
|
175 |
|
|
impHandler0(equipmentWindowShow) |
176 |
|
|
{ |
177 |
|
|
showHideWindow(equipmentWindow); |
178 |
|
|
return true; |
179 |
|
|
} |
180 |
|
|
|
181 |
|
|
impHandler0(skillDialogShow) |
182 |
|
|
{ |
183 |
|
|
showHideWindow(skillDialog); |
184 |
|
|
return true; |
185 |
|
|
} |
186 |
|
|
|
187 |
|
|
impHandler0(minimapWindowShow) |
188 |
|
|
{ |
189 |
|
|
if (minimap != nullptr) |
190 |
|
|
{ |
191 |
|
|
minimap->toggle(); |
192 |
|
|
return true; |
193 |
|
|
} |
194 |
|
|
return false; |
195 |
|
|
} |
196 |
|
|
|
197 |
|
|
impHandler0(chatWindowShow) |
198 |
|
|
{ |
199 |
|
|
showHideWindow(chatWindow); |
200 |
|
|
return true; |
201 |
|
|
} |
202 |
|
|
|
203 |
|
|
impHandler0(shortcutWindowShow) |
204 |
|
|
{ |
205 |
|
|
showHideWindow(itemShortcutWindow); |
206 |
|
|
return true; |
207 |
|
|
} |
208 |
|
|
|
209 |
|
|
impHandler0(debugWindowShow) |
210 |
|
|
{ |
211 |
|
|
showHideWindow(debugWindow); |
212 |
|
|
return true; |
213 |
|
|
} |
214 |
|
|
|
215 |
|
|
impHandler0(socialWindowShow) |
216 |
|
|
{ |
217 |
|
|
showHideWindow(socialWindow); |
218 |
|
|
return true; |
219 |
|
|
} |
220 |
|
|
|
221 |
|
|
impHandler0(emoteShortcutWindowShow) |
222 |
|
|
{ |
223 |
|
|
showHideWindow(emoteShortcutWindow); |
224 |
|
|
return true; |
225 |
|
|
} |
226 |
|
|
|
227 |
|
|
impHandler0(outfitWindowShow) |
228 |
|
|
{ |
229 |
|
|
showHideWindow(outfitWindow); |
230 |
|
|
return true; |
231 |
|
|
} |
232 |
|
|
|
233 |
|
|
impHandler0(shopWindowShow) |
234 |
|
|
{ |
235 |
|
|
showHideWindow(shopWindow); |
236 |
|
|
return true; |
237 |
|
|
} |
238 |
|
|
|
239 |
|
|
impHandler0(dropShortcutWindowShow) |
240 |
|
|
{ |
241 |
|
|
showHideWindow(dropShortcutWindow); |
242 |
|
|
return true; |
243 |
|
|
} |
244 |
|
|
|
245 |
|
|
impHandler0(killStatsWindowShow) |
246 |
|
|
{ |
247 |
|
|
showHideWindow(killStats); |
248 |
|
|
return true; |
249 |
|
|
} |
250 |
|
|
|
251 |
|
|
impHandler0(spellShortcutWindowShow) |
252 |
|
|
{ |
253 |
|
|
showHideWindow(spellShortcutWindow); |
254 |
|
|
return true; |
255 |
|
|
} |
256 |
|
|
|
257 |
|
|
impHandler0(whoIsOnlineWindowShow) |
258 |
|
|
{ |
259 |
|
|
showHideWindow(whoIsOnline); |
260 |
|
|
return true; |
261 |
|
|
} |
262 |
|
|
|
263 |
|
|
impHandler0(didYouKnowWindowShow) |
264 |
|
|
{ |
265 |
|
|
showHideWindow(didYouKnowWindow); |
266 |
|
|
return true; |
267 |
|
|
} |
268 |
|
|
|
269 |
|
|
impHandler0(questsWindowShow) |
270 |
|
|
{ |
271 |
|
|
showHideWindow(questsWindow); |
272 |
|
|
return true; |
273 |
|
|
} |
274 |
|
|
|
275 |
|
|
impHandler0(bankWindowShow) |
276 |
|
|
{ |
277 |
|
|
#ifdef TMWA_SUPPORT |
278 |
|
|
if (Net::getNetworkType() == ServerType::TMWATHENA) |
279 |
|
|
return false; |
280 |
|
|
#endif // TMWA_SUPPORT |
281 |
|
|
|
282 |
|
|
showHideWindow(bankWindow); |
283 |
|
|
return true; |
284 |
|
|
} |
285 |
|
|
|
286 |
|
|
impHandler0(cartWindowShow) |
287 |
|
|
{ |
288 |
|
|
if (Net::getNetworkType() == ServerType::TMWATHENA || |
289 |
|
|
(localPlayer == nullptr) || |
290 |
|
|
!localPlayer->getHaveCart()) |
291 |
|
|
{ |
292 |
|
|
return false; |
293 |
|
|
} |
294 |
|
|
|
295 |
|
|
showHideWindow(cartWindow); |
296 |
|
|
if (inventoryWindow != nullptr) |
297 |
|
|
inventoryWindow->updateDropButton(); |
298 |
|
|
return true; |
299 |
|
|
} |
300 |
|
|
|
301 |
|
|
impHandler0(updaterWindowShow) |
302 |
|
|
{ |
303 |
|
|
if (updaterWindow != nullptr) |
304 |
|
|
updaterWindow->deleteSelf(); |
305 |
|
|
else |
306 |
|
|
DialogsManager::createUpdaterWindow(); |
307 |
|
|
return true; |
308 |
|
|
} |
309 |
|
|
|
310 |
|
|
impHandler0(quickWindowShow) |
311 |
|
|
{ |
312 |
|
|
if (setupWindow != nullptr) |
313 |
|
|
{ |
314 |
|
|
if (setupWindow->isWindowVisible()) |
315 |
|
|
setupWindow->doCancel(); |
316 |
|
|
setupWindow->setVisible(Visible_true); |
317 |
|
|
// TRANSLATORS: settings tab name |
318 |
|
|
setupWindow->activateTab(_("Quick")); |
319 |
|
|
setupWindow->requestMoveToTop(); |
320 |
|
|
return true; |
321 |
|
|
} |
322 |
|
|
return false; |
323 |
|
|
} |
324 |
|
|
|
325 |
|
|
impHandler0(mailWindowShow) |
326 |
|
|
{ |
327 |
|
|
showHideWindow(mailWindow); |
328 |
|
|
return true; |
329 |
|
|
} |
330 |
|
|
|
331 |
|
|
impHandler0(serverInfoWindowShow) |
332 |
|
|
{ |
333 |
|
|
if (serverInfoWindow != nullptr && |
334 |
|
|
serverInfoWindow->isWindowVisible()) |
335 |
|
|
{ |
336 |
|
|
serverInfoWindow->close(); |
337 |
|
|
serverInfoWindow = nullptr; |
338 |
|
|
} |
339 |
|
|
else |
340 |
|
|
{ |
341 |
|
|
serverInfoWindow = CREATEWIDGETR(ServerInfoWindow, |
342 |
|
|
client->getCurrentServer()); |
343 |
|
|
serverInfoWindow->requestMoveToTop(); |
344 |
|
|
} |
345 |
|
|
return true; |
346 |
|
|
} |
347 |
|
|
|
348 |
|
|
impHandler0(clanWindowShow) |
349 |
|
|
{ |
350 |
|
|
showHideWindow(clanWindow); |
351 |
|
|
return true; |
352 |
|
|
} |
353 |
|
|
|
354 |
|
|
impHandler(showItems) |
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 |
|
|
{ |
370 |
|
|
being = actorManager->findBeingByName(args, ActorType::Player); |
371 |
|
|
} |
372 |
|
|
if (being == nullptr) |
373 |
|
|
return true; |
374 |
|
|
if (being == localPlayer) |
375 |
|
|
{ |
376 |
|
|
if (equipmentWindow != nullptr && |
377 |
|
|
!equipmentWindow->isWindowVisible()) |
378 |
|
|
{ |
379 |
|
|
equipmentWindow->setVisible(Visible_true); |
380 |
|
|
} |
381 |
|
|
} |
382 |
|
|
else |
383 |
|
|
{ |
384 |
|
|
if (beingEquipmentWindow != nullptr) |
385 |
|
|
{ |
386 |
|
|
beingEquipmentWindow->setBeing(being); |
387 |
|
|
beingEquipmentWindow->setVisible(Visible_true); |
388 |
|
|
} |
389 |
|
|
} |
390 |
|
|
return true; |
391 |
|
|
} |
392 |
|
|
|
393 |
|
2 |
} // namespace Actions |