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