GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/progs/manaplus/actions/windows.cpp Lines: 1 147 0.7 %
Date: 2017-11-29 Branches: 0 144 0.0 %

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