Mana
Loading...
Searching...
No Matches
party.h
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2010-2012 The Mana Developers
4 *
5 * This file is part of The Mana Client.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#pragma once
22
23#include "avatar.h"
24
26
27#include "utils/dtor.h"
28
29#include <map>
30#include <string>
31#include <vector>
32
33class Party;
34
35class PartyMember : public Avatar
36{
37public:
38 int getID() const { return mId; }
39
40 void setID(int id) { mId = id; }
41
42 Party *getParty() const { return mParty; }
43
44 bool getLeader() const { return mLeader; }
45
46 void setLeader(bool leader) { mLeader = leader; setDisplayBold(leader); }
47
48protected:
49 friend class Party;
50
51 PartyMember(Party *party, int id, const std::string &name);
52
53 int mId;
55 bool mLeader = false;
56};
57
58class Party : public AvatarListModel
59{
60public:
61
65 void setName(const std::string &name)
66 {
67 mName = name;
68 }
69
73 PartyMember *addMember(int id, const std::string &name);
74
80 PartyMember *getMember(int id) const;
81
87 PartyMember *getMember(const std::string &name) const;
88
93 const std::string &getName() const
94 {
95 return mName;
96 }
97
102 short getId() const
103 {
104 return mId;
105 }
106
110 void removeMember(PartyMember *member);
111
115 void removeMember(int id);
116
120 void removeMember(const std::string &name);
121
123
124 void removeFromMembers();
125
130 int getNumberOfElements() override {
131 return mMembers.size();
132 }
133
134 Avatar *getAvatarAt(int i) override;
135
140 bool getInviteRights() const
141 {
142 return mCanInviteUsers;
143 }
144
145 void setRights(short rights);
146
147 bool isMember(PartyMember *member) const;
148
149 bool isMember(int id) const;
150
151 bool isMember(const std::string &name) const;
152
153 void getNames(std::vector<std::string> &names) const;
154
155 static Party *getParty(int id);
156
157private:
158 using PartyMap = std::map<int, Party *>;
160
164 Party(short id);
165
166 ~Party() override;
167
168 std::vector<PartyMember *> mMembers;
169 std::string mName;
170 short mId;
171 bool mCanInviteUsers = false;
172};
void setDisplayBold(bool displayBold)
Definition avatar.h:61
int mId
Definition party.h:53
bool mLeader
Definition party.h:55
bool getLeader() const
Definition party.h:44
void setID(int id)
Definition party.h:40
Party * mParty
Definition party.h:54
Party * getParty() const
Definition party.h:42
int getID() const
Definition party.h:38
void setLeader(bool leader)
Definition party.h:46
Definition party.h:59
static PartyMap parties
Definition party.h:159
bool getInviteRights() const
Get whether user can invite users to this party.
Definition party.h:140
Avatar * getAvatarAt(int i) override
Definition party.cpp:128
std::string mName
Definition party.h:169
static Party * getParty(int id)
Definition party.cpp:185
bool isMember(PartyMember *member) const
Definition party.cpp:142
const std::string & getName() const
Get the name of the party.
Definition party.h:93
std::map< int, Party * > PartyMap
Definition party.h:158
void setRights(short rights)
Definition party.cpp:133
std::vector< PartyMember * > mMembers
Definition party.h:168
PartyMember * getMember(int id) const
Find a member by ID.
Definition party.cpp:60
PartyMember * addMember(int id, const std::string &name)
Adds member to the list.
Definition party.cpp:45
void setName(const std::string &name)
Set the party's name.
Definition party.h:65
void removeFromMembers()
Definition party.cpp:121
void removeMember(PartyMember *member)
Removes a member from the party.
Definition party.cpp:78
int getNumberOfElements() override
Get size of members list.
Definition party.h:130
void getNames(std::vector< std::string > &names) const
Definition party.cpp:178
short getId() const
Get the id of the party.
Definition party.h:102
~Party() override
Definition party.cpp:40
void clearMembers()
Definition party.h:122
bool mCanInviteUsers
Definition party.h:171
short mId
Definition party.h:170
void delete_all(Container &c)
Definition dtor.h:46