GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/tabs/socialpartytab.h Lines: 0 58 0.0 %
Date: 2017-11-29 Branches: 0 54 0.0 %

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