GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/tabs/socialguildtab.h Lines: 0 66 0.0 %
Date: 2021-03-17 Branches: 0 52 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_SOCIALGUILDTAB_H
24
#define GUI_WIDGETS_TABS_SOCIALGUILDTAB_H
25
26
#include "gui/widgets/tabs/socialtab.h"
27
28
#include "being/localplayer.h"
29
30
#include "const/sound.h"
31
32
#include "utils/delete2.h"
33
#include "utils/foreach.h"
34
#include "utils/gettext.h"
35
#include "utils/stringutils.h"
36
37
#include "net/guildhandler.h"
38
39
#include "localconsts.h"
40
41
class SocialGuildTab final : public SocialTab,
42
                             public ActionListener
43
{
44
    public:
45
        SocialGuildTab(const Widget2 *const widget,
46
                       Guild *const guild,
47
                       const Opaque showBackground) :
48
            SocialTab(widget),
49
            ActionListener(),
50
            mGuild(guild)
51
        {
52
            // TRANSLATORS: tab in social window
53
            setCaption(_("Guild"));
54
55
            setTabColor(&getThemeColor(ThemeColorId::GUILD_SOCIAL_TAB, 255U),
56
                &getThemeColor(ThemeColorId::GUILD_SOCIAL_TAB_OUTLINE, 255U));
57
            setHighlightedTabColor(&getThemeColor(
58
                ThemeColorId::GUILD_SOCIAL_TAB_HIGHLIGHTED, 255U),
59
                &getThemeColor(
60
                ThemeColorId::GUILD_SOCIAL_TAB_HIGHLIGHTED_OUTLINE, 255U));
61
            setSelectedTabColor(&getThemeColor(
62
                ThemeColorId::GUILD_SOCIAL_TAB_SELECTED, 255U),
63
                &getThemeColor(
64
                ThemeColorId::GUILD_SOCIAL_TAB_SELECTED_OUTLINE, 255U));
65
66
            createControls(guild, showBackground);
67
            mMenuAction = "guild";
68
        }
69
70
        A_DELETE_COPY(SocialGuildTab)
71
72
        ~SocialGuildTab() override final
73
        {
74
            delete2(mList)
75
            delete2(mScroll)
76
        }
77
78
        void action(const ActionEvent &event) override final
79
        {
80
            const std::string &eventId = event.getId();
81
            if (eventId == "do invite")
82
            {
83
                const std::string name = mInviteDialog->getText();
84
                guildHandler->invite(name);
85
86
                if (localChatTab != nullptr)
87
                {
88
                    localChatTab->chatLog(strprintf(
89
                        // TRANSLATORS: chat message
90
                        _("Invited user %s to guild %s."),
91
                        name.c_str(),
92
                        mGuild->getName().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
                guildHandler->leave(mGuild->getId());
106
                if (localChatTab != nullptr)
107
                {
108
                    localChatTab->chatLog(strprintf(
109
                        // TRANSLATORS: chat message
110
                        _("Guild %s quit requested."),
111
                        mGuild->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: guild invite message
128
                _("Member Invite to Guild"),
129
                // TRANSLATORS: guild invite message
130
                strprintf(_("Who would you like to invite to guild %s?"),
131
                mGuild->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: guild leave message
142
                _("Leave Guild?"),
143
                // TRANSLATORS: guild leave message
144
                strprintf(_("Are you sure you want to leave guild %s?"),
145
                mGuild->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, const int total0) override final
154
        {
155
            if ((online0 != 0) || (total0 != 0))
156
            {
157
                // TRANSLATORS: social window label
158
                mCounterString = strprintf(_("Members: %u/%u"),
159
                    CAST_U32(online0),
160
                    CAST_U32(total0));
161
            }
162
            else
163
            {
164
                if (localPlayer == nullptr)
165
                    return;
166
167
                const Guild *const guild = localPlayer->getGuild();
168
                if (guild == nullptr)
169
                    return;
170
171
                const Guild::MemberList *const members = guild->getMembers();
172
                int online = 0;
173
                int total = 0;
174
                FOR_EACHP (Guild::MemberList::const_iterator, it, members)
175
                {
176
                    if ((*it)->getOnline())
177
                        online ++;
178
                    total ++;
179
                }
180
181
                // TRANSLATORS: social window label
182
                mCounterString = strprintf(_("Players: %u/%u"),
183
                    CAST_U32(online),
184
                    CAST_U32(total));
185
            }
186
            updateCounter();
187
        }
188
189
    private:
190
        Guild *mGuild;
191
};
192
193
#endif  // GUI_WIDGETS_TABS_SOCIALGUILDTAB_H