GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/listeners/playerpostdeathlistener.h Lines: 2 18 11.1 %
Date: 2018-06-18 21:15:20 Branches: 0 8 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2004-2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  The Mana Developers
5
 *  Copyright (C) 2011-2018  The ManaPlus Developers
6
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
#ifndef LISTENERS_PLAYERPOSTDEATHLISTENER_H
24
#define LISTENERS_PLAYERPOSTDEATHLISTENER_H
25
26
#include "being/localplayer.h"
27
28
#include "gui/dialogsmanager.h"
29
#include "gui/popupmanager.h"
30
31
#include "gui/windows/npcdialog.h"
32
33
#include "net/adminhandler.h"
34
#include "net/playerhandler.h"
35
36
#include "localconsts.h"
37
38
extern Window *deathNotice;
39
40
/**
41
  * Listener used for handling death message.
42
  */
43
2
struct PlayerPostDeathListener final : public ActionListener
44
{
45
    PlayerPostDeathListener() :
46
4
        ActionListener()
47
    { }
48
49
    A_DELETE_COPY(PlayerPostDeathListener)
50
51
    void action(const ActionEvent &event) override final
52
    {
53
        const bool respawn = !(event.getId() == "no");
54
        deathNotice = nullptr;
55
        if (respawn)
56
        {
57
            if (playerHandler != nullptr)
58
                playerHandler->respawn();
59
60
            DialogsManager::closeDialogs();
61
            PopupManager::closePopupMenu();
62
            NpcDialog::clearDialogs();
63
64
            if (localPlayer != nullptr)
65
                localPlayer->respawn();
66
        }
67
        else
68
        {
69
            DialogsManager::closeDialogs();
70
            PopupManager::closePopupMenu();
71
            NpcDialog::clearDialogs();
72
            if (localPlayer != nullptr)
73
                adminHandler->alive(localPlayer->getName());
74
        }
75
    }
76
};
77
78
#endif  // LISTENERS_PLAYERPOSTDEATHLISTENER_H