GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/progs/manaplus/actions/windows.cpp Lines: 1 151 0.7 %
Date: 2018-05-24 20:11:55 Branches: 0 149 0.0 %

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