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_WINDOWS_SOCIALWINDOW_H
24 #define GUI_WINDOWS_SOCIALWINDOW_H
25 
26 #include "gui/widgets/window.h"
27 
28 #include "listeners/actionlistener.h"
29 #include "listeners/playerrelationslistener.h"
30 
31 class Button;
32 class ConfirmDialog;
33 class Guild;
34 class Label;
35 class Map;
36 class Party;
37 class SocialTab;
38 class TabbedArea;
39 class TextDialog;
40 
41 /**
42  * Party window.
43  *
44  * \ingroup Interface
45  */
46 class SocialWindow final : public Window,
47                            private ActionListener,
48                            public PlayerRelationsListener
49 {
50     public:
51         SocialWindow();
52 
53         A_DELETE_COPY(SocialWindow)
54 
55         ~SocialWindow() override final;
56 
57         void postInit() override final;
58 
59         bool addTab(Guild *const guild);
60 
61         bool removeTab(Guild *const guild);
62 
63         bool addTab(Party *const party);
64 
65         bool removeTab(Party *const party);
66 
67         void action(const ActionEvent &event) override final;
68 
69         void showGuildInvite(const std::string &restrict guildName,
70                              const int guildId,
71                              const std::string &restrict inviterName);
72 
73         void showPartyInvite(const std::string &restrict partyName,
74                              const std::string &restrict inviter,
75                              const int partyId);
76 
77         void updateActiveList();
78 
79         void updateAvatar(const std::string &name);
80 
81         void resetDamage(const std::string &name);
82 
83         void slowLogic();
84 
85         void updatePortals();
86 
87         void updatePortalNames();
88 
89         void updateParty();
90 
91         int getPortalIndex(const int x, const int y) A_WARN_UNUSED;
92 
93         void addPortal(const int x, const int y);
94 
95         void removePortal(const int x, const int y);
96 
97         void nextTab();
98 
99         void prevTab();
100 
getMap()101         const Map* getMap() const noexcept2 A_WARN_UNUSED
102         { return mMap; }
103 
setMap(Map * const map)104         void setMap(Map *const map)
105         { mMap = map; mProcessedPortals = false; }
106 
getProcessedPortals()107         bool getProcessedPortals() const noexcept2 A_WARN_UNUSED
108         { return mProcessedPortals; }
109 
setProcessedPortals(const bool n)110         void setProcessedPortals(const bool n) noexcept2
111         { mProcessedPortals = n; }
112 
113         void selectPortal(const unsigned num);
114 
115         void updateAttackFilter();
116 
117         void updatePickupFilter();
118 
119         void widgetResized(const Event &event) override final;
120 
121         void updateCounter(const SocialTab *const tab,
122                            const std::string &count);
123 
124         void updateMenu(const SocialTab *const tab,
125                         const std::string &menu);
126 
127         void updateGuildCounter(const int online,
128                                 const int total);
129 
130         void updatedPlayer(const std::string &name) override final;
131 
132         void updateAll() override final;
133 
134 #ifdef USE_PROFILER
135         void logicChildren();
136 #endif  // USE_PROFILER
137 
138     protected:
139         friend class SocialTab;
140         typedef std::map<Guild*, SocialTab*> GuildMap;
141         typedef std::map<Party*, SocialTab*> PartyMap;
142 
143         void updateButtons();
144 
145         int mGuildInvited;
146         ConfirmDialog *mGuildAcceptDialog;
147         TextDialog *mGuildCreateDialog;
148         std::string mPartyInviter;
149         GuildMap mGuilds;
150         PartyMap mParties;
151 
152         ConfirmDialog *mPartyAcceptDialog;
153 
154         SocialTab *mAttackFilter;
155         SocialTab *mPickupFilter;
156         SocialTab *mPlayers A_NONNULLPOINTER;
157         SocialTab *mNavigation A_NONNULLPOINTER;
158         SocialTab *mFriends A_NONNULLPOINTER;
159 
160         Button *mMenuButton A_NONNULLPOINTER;
161         Label *mCountLabel A_NONNULLPOINTER;
162         TabbedArea *mTabs A_NONNULLPOINTER;
163         Map *mMap;
164 
165         time_t mLastUpdateTime;
166         int mPartyId;
167         bool mNeedUpdate;
168         bool mProcessedPortals;
169 };
170 
171 extern SocialWindow *socialWindow;
172 
173 #endif  // GUI_WINDOWS_SOCIALWINDOW_H
174