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