GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/tabs/socialpartytab.h Lines: 0 62 0.0 %
Date: 2018-07-14 Branches: 0 50 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2010  The Mana Developers
4
 *  Copyright (C) 2011-2018  The ManaPlus Developers
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
#ifndef GUI_WIDGETS_TABS_SOCIALPARTYTAB_H
23
#define GUI_WIDGETS_TABS_SOCIALPARTYTAB_H
24
25
#include "gui/widgets/tabs/socialtab.h"
26
27
#include "const/sound.h"
28
29
#include "party.h"
30
31
#include "being/localplayer.h"
32
33
#include "net/partyhandler.h"
34
35
#include "utils/delete2.h"
36
#include "utils/foreach.h"
37
#include "utils/gettext.h"
38
#include "utils/stringutils.h"
39
40
#include "localconsts.h"
41
42
class SocialPartyTab final : public SocialTab,
43
                             public ActionListener
44
{
45
    public:
46
        SocialPartyTab(const Widget2 *const widget,
47
                       Party *const party,
48
                       const Opaque showBackground) :
49
            SocialTab(widget),
50
            ActionListener(),
51
            mParty(party)
52
        {
53
            // TRANSLATORS: tab in social window
54
            setCaption(_("Party"));
55
56
            setTabColor(&getThemeColor(ThemeColorId::PARTY_SOCIAL_TAB, 255U),
57
                &getThemeColor(ThemeColorId::PARTY_SOCIAL_TAB_OUTLINE, 255U));
58
            setHighlightedTabColor(&getThemeColor(
59
                ThemeColorId::PARTY_SOCIAL_TAB_HIGHLIGHTED, 255U),
60
                &getThemeColor(
61
                ThemeColorId::PARTY_SOCIAL_TAB_HIGHLIGHTED_OUTLINE, 255U));
62
            setSelectedTabColor(&getThemeColor(
63
                ThemeColorId::PARTY_SOCIAL_TAB_SELECTED, 255U),
64
                &getThemeColor(
65
                ThemeColorId::PARTY_SOCIAL_TAB_SELECTED_OUTLINE, 255U));
66
67
            createControls(party, showBackground);
68
            mMenuAction = "party";
69
        }
70
71
        A_DELETE_COPY(SocialPartyTab)
72
73
        ~SocialPartyTab() override final
74
        {
75
            delete2(mList)
76
            delete2(mScroll)
77
        }
78
79
        void action(const ActionEvent &event) override final
80
        {
81
            const std::string &eventId = event.getId();
82
            if (eventId == "do invite")
83
            {
84
                const std::string name = mInviteDialog->getText();
85
                partyHandler->invite(name);
86
87
                if (localChatTab != nullptr)
88
                {
89
                    localChatTab->chatLog(strprintf(
90
                        // TRANSLATORS: chat message
91
                        _("Invited user %s to party."),
92
                        name.c_str()),
93
                        ChatMsgType::BY_SERVER,
94
                        IgnoreRecord_false,
95
                        TryRemoveColors_true);
96
                }
97
                mInviteDialog = nullptr;
98
            }
99
            else if (eventId == "~do invite")
100
            {
101
                mInviteDialog = nullptr;
102
            }
103
            else if (eventId == "yes")
104
            {
105
                partyHandler->leave();
106
                if (localChatTab != nullptr)
107
                {
108
                    localChatTab->chatLog(strprintf(
109
                        // TRANSLATORS: tab in social window
110
                        _("Party %s quit requested."),
111
                        mParty->getName().c_str()),
112
                        ChatMsgType::BY_SERVER,
113
                        IgnoreRecord_false,
114
                        TryRemoveColors_true);
115
                }
116
                mConfirmDialog = nullptr;
117
            }
118
            else if (eventId == "~yes")
119
            {
120
                mConfirmDialog = nullptr;
121
            }
122
        }
123
124
        void invite() override final
125
        {
126
            CREATEWIDGETV(mInviteDialog, TextDialog,
127
                // TRANSLATORS: party invite message
128
                _("Member Invite to Party"),
129
                // TRANSLATORS: party invite message
130
                strprintf(_("Who would you like to invite to party %s?"),
131
                mParty->getName().c_str()),
132
                socialWindow,
133
                false);
134
            mInviteDialog->setActionEventId("do invite");
135
            mInviteDialog->addActionListener(this);
136
        }
137
138
        void leave() override final
139
        {
140
            CREATEWIDGETV(mConfirmDialog, ConfirmDialog,
141
                // TRANSLATORS: party leave message
142
                _("Leave Party?"),
143
                // TRANSLATORS: party leave message
144
                strprintf(_("Are you sure you want to leave party %s?"),
145
                mParty->getName().c_str()),
146
                SOUND_REQUEST,
147
                false,
148
                Modal_false,
149
                socialWindow);
150
            mConfirmDialog->addActionListener(this);
151
        }
152
153
        void buildCounter(const int online0 A_UNUSED,
154
                          const int total0 A_UNUSED) override final
155
        {
156
            if (localPlayer == nullptr)
157
                return;
158
159
            const Party *const party = localPlayer->getParty();
160
            if (party == nullptr)
161
                return;
162
163
            const Party::MemberList *const members = party->getMembers();
164
            int online = 0;
165
            int total = 0;
166
            FOR_EACHP (Party::MemberList::const_iterator, it, members)
167
            {
168
                if ((*it)->getOnline())
169
                    online ++;
170
                total ++;
171
            }
172
173
            // TRANSLATORS: social window label
174
            mCounterString = strprintf(_("Players: %u/%u"),
175
                CAST_U32(online),
176
                CAST_U32(total));
177
            updateCounter();
178
        }
179
180
    private:
181
        Party *mParty;
182
};
183
184
#endif  // GUI_WIDGETS_TABS_SOCIALPARTYTAB_H