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