Cockatrice 2026-10-19-Development-3.1.2-beta.2
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
player_logic.h
Go to the documentation of this file.
1
6
7#ifndef PLAYER_H
8#define PLAYER_H
9
18
19#include <QColor>
20#include <QInputDialog>
21#include <QList>
22#include <QLoggingCategory>
23#include <QMap>
24#include <QObject>
25#include <QString>
27#include <qtmetamacros.h>
28
29// IWYU pragma: keep
30// ServerInfo_Card appears inside QList<...> in signal and slot
31// signatures, which the moc-generated code needs to be complete.
32#include <libcockatrice/protocol/pb/serverinfo_card.pb.h>
33
34class CardItem;
35class CounterState;
36class QWidget;
38struct ArrowData;
39struct LoadedDeck;
40template <class T> class QSharedPointer;
41
42inline Q_LOGGING_CATEGORY(PlayerLog, "player");
44class AbstractGame;
45class PlayerInfo;
47class PlayerActions;
48class ServerInfo_Card;
51class ServerInfo_User;
52
53const int MAX_TOKENS_PER_DIALOG = 99;
54
55class PlayerLogic : public QObject
56{
57 Q_OBJECT
58
59signals:
61 void requestZoneViewToggle(PlayerLogic *player, const QString &zoneName, int numberCards, bool isReversed);
63 CardZoneLogic *zone,
64 const QList<const ServerInfo_Card *> &cardList,
65 bool withWritePermission);
72 void counterRemoved(int counterId);
76 void concededChanged(int playerId, bool conceded);
81 void arrowDeleteRequested(int creatorId, int arrowId);
82 void arrowDeleted(int creatorId, int arrowId);
83 void arrowsClearedLocally(); // fires on clear() and processPlayerInfo
84
85public slots:
86 void setActive(bool _active);
87 void onRequestZoneViewToggle(const QString &zoneName, int numberCards, bool isReversed);
88
89public:
90 PlayerLogic(const ServerInfo_User &info, int _id, bool _local, bool _judge, AbstractGame *_parent);
91 ~PlayerLogic() override;
92
93 void initializeZones();
94 void updateZones();
95 void clear();
96
97 void processPlayerInfo(const ServerInfo_Player &info);
99
100 void addCard(CardItem *c);
101 void deleteCard(CardItem *c);
102
103 bool clearCardsToDelete();
104
105 bool getActive() const
106 {
107 return active;
108 }
109
111 {
112 return game;
113 }
114
115 [[nodiscard]] PlayerActions *getPlayerActions() const
116 {
117 return playerActions;
118 }
119
121 {
122 return playerEventHandler;
123 }
124
125 [[nodiscard]] PlayerInfo *getPlayerInfo() const
126 {
127 return playerInfo;
128 }
129
130 void setDeck(const DeckList &_deck);
131
132 [[nodiscard]] const DeckList &getDeck() const
133 {
134 return deck;
135 }
136
137 template <typename T> T *addZone(T *zone)
138 {
139 zones.insert(zone->getName(), zone);
140 return zone;
141 }
142
143 CardZoneLogic *getZone(const QString zoneName)
144 {
145 return zones.value(zoneName);
146 }
147
149 {
150 return zones;
151 }
152
154 {
155 return qobject_cast<PileZoneLogic *>(zones.value(ZoneNames::DECK));
156 }
157
159 {
160 return qobject_cast<PileZoneLogic *>(zones.value(ZoneNames::GRAVE));
161 }
162
164 {
165 return qobject_cast<PileZoneLogic *>(zones.value(ZoneNames::EXILE));
166 }
167
169 {
170 return qobject_cast<PileZoneLogic *>(zones.value(ZoneNames::SIDEBOARD));
171 }
172
174 {
175 return qobject_cast<TableZoneLogic *>(zones.value(ZoneNames::TABLE));
176 }
177
179 {
180 return qobject_cast<StackZoneLogic *>(zones.value(ZoneNames::STACK));
181 }
182
184 {
185 return qobject_cast<HandZoneLogic *>(zones.value(ZoneNames::HAND));
186 }
187
189 CounterState *addCounter(int id, const QString &name, const QColor &color, int radius, int value);
190 void delCounter(int counterId);
191 void clearCounters();
192
194 {
195 return counters;
196 }
197
202
203 void setConceded(bool _conceded);
204 bool getConceded() const
205 {
206 return conceded;
207 }
208
209 void setGameStarted();
210
211 void setDialogSemaphore(const bool _active)
212 {
213 dialogSemaphore = _active;
214 }
215
216 int getZoneId() const
217 {
218 return zoneId;
219 }
220
221 void setZoneId(int _zoneId);
222
225 {
226 return remotePlaymatCard;
227 }
229 {
230 return remotePlaymatParams;
231 }
233 {
234 return hasRemotePlaymat;
235 }
236
237private:
242
243 bool active;
245
247
251
254
255 // Playmat from player properties (for opponent display)
258 bool hasRemotePlaymat = false;
259};
260
261class AnnotationDialog : public QInputDialog
262{
263 Q_OBJECT
264 void keyPressEvent(QKeyEvent *e) override;
265
266public:
267 explicit AnnotationDialog(QWidget *parent = nullptr) : QInputDialog(parent)
268 {
269 }
270};
271
272#endif
Definition abstract_card_item.h:29
Definition abstract_game.h:23
AnnotationDialog(QWidget *parent=nullptr)
Definition player_logic.h:267
void keyPressEvent(QKeyEvent *e) override
Definition player_actions.cpp:1498
Definition card_item.h:33
Definition card_zone_logic.h:27
Definition counter_state.h:12
Represents a complete deck, including metadata, zones, cards, and sideboard plans.
Definition deck_list.h:67
Definition hand_zone_logic.h:18
Definition pile_zone_logic.h:18
Definition player_actions.h:44
Applies player-specific game events and emits corresponding log signals.
Definition player_event_handler.h:70
Definition player_info.h:16
StackZoneLogic * getStackZone()
Definition player_logic.h:178
PileZoneLogic * getRfgZone()
Definition player_logic.h:163
AbstractGame * getGame() const
Definition player_logic.h:110
PlayerEventHandler * getPlayerEventHandler() const
Definition player_logic.h:120
int getZoneId() const
Definition player_logic.h:216
void clearCustomZonesMenu()
void onRequestZoneViewToggle(const QString &zoneName, int numberCards, bool isReversed)
Definition player_logic.cpp:348
const QMap< QString, CardZoneLogic * > & getZones() const
Definition player_logic.h:148
PlayerInfo * getPlayerInfo() const
Definition player_logic.h:125
void activeChanged(bool active)
PileZoneLogic * getSideboardZone()
Definition player_logic.h:168
PlayerInfo * playerInfo
Definition player_logic.h:239
void addViewCustomZoneActionToCustomZoneMenu(QString zoneName)
void setPlaymatFromProperties(const ServerInfo_PlayerProperties &props)
Definition player_logic.cpp:265
void resetTopCardMenuActions()
PileZoneLogic * getDeckZone()
Definition player_logic.h:153
void setDialogSemaphore(const bool _active)
Definition player_logic.h:211
bool hasRemotePlaymat
Definition player_logic.h:258
void initializeZones()
Definition player_logic.cpp:44
QMap< QString, CardZoneLogic * > zones
Definition player_logic.h:249
void rearrangeCounters()
PlayerLogic(const ServerInfo_User &info, int _id, bool _local, bool _judge, AbstractGame *_parent)
Definition player_logic.cpp:36
void requestRevealedZoneView(PlayerLogic *player, CardZoneLogic *zone, const QList< const ServerInfo_Card * > &cardList, bool withWritePermission)
void playmatChanged()
Emitted when the remote playmat (card/params) is updated from player properties.
CounterState * addCounter(const ServerInfo_Counter &counter)
Definition player_logic.cpp:281
HandZoneLogic * getHandZone()
Definition player_logic.h:183
PlaymatParams remotePlaymatParams
Definition player_logic.h:257
int zoneId
Definition player_logic.h:248
const DeckList & getDeck() const
Definition player_logic.h:132
void processCardAttachment(const ServerInfo_Player &info)
Definition player_logic.cpp:208
T * addZone(T *zone)
Definition player_logic.h:137
void counterRemoved(int counterId)
bool getActive() const
Definition player_logic.h:105
void setDeck(const DeckList &_deck)
Definition player_logic.cpp:258
void clearCounters()
Definition player_logic.cpp:308
PlayerEventHandler * playerEventHandler
Definition player_logic.h:240
void counterAdded(CounterState *state)
void setZoneId(int _zoneId)
Definition player_logic.cpp:94
QList< CardItem * > cardsToDelete
Definition player_logic.h:253
void clear()
Definition player_logic.cpp:70
bool getConceded() const
Definition player_logic.h:204
void deleteCard(CardItem *c)
Definition player_logic.cpp:247
void setActive(bool _active)
Definition player_logic.cpp:343
void addCard(CardItem *c)
Definition player_logic.cpp:242
PileZoneLogic * getGraveZone()
Definition player_logic.h:158
void setGameStarted()
Definition player_logic.cpp:358
CounterState * getLifeCounter() const
Definition player_logic.cpp:317
void requestCardMenuUpdate(const CardItem *card)
CardRef remotePlaymatCard
Definition player_logic.h:256
PlayerActions * playerActions
Definition player_logic.h:241
AbstractGame * game
Definition player_logic.h:238
TableZoneLogic * getTableZone()
Definition player_logic.h:173
void delCounter(int counterId)
Definition player_logic.cpp:298
bool getHasRemotePlaymat() const
Definition player_logic.h:232
bool dialogSemaphore
Definition player_logic.h:252
QMap< int, CounterState * > getCounters() const
Definition player_logic.h:193
CardZoneLogic * getZone(const QString zoneName)
Definition player_logic.h:143
QMap< int, CounterState * > counters
Definition player_logic.h:250
const CardRef & getRemotePlaymatCard() const
Definition player_logic.h:224
bool active
Definition player_logic.h:243
void deckChanged()
void arrowDeleted(int creatorId, int arrowId)
DeckList deck
Definition player_logic.h:246
void requestZoneViewToggle(PlayerLogic *player, const QString &zoneName, int numberCards, bool isReversed)
bool clearCardsToDelete()
Definition player_logic.cpp:327
void concededChanged(int playerId, bool conceded)
void arrowsClearedLocally()
void newCardAdded(AbstractCardItem *card)
bool conceded
Definition player_logic.h:244
PlayerActions * getPlayerActions() const
Definition player_logic.h:115
void updateZones()
Definition player_logic.cpp:353
void arrowDeleteRequested(int creatorId, int arrowId)
void arrowCreateRequested(QSharedPointer< ArrowData > data)
void openDeckEditor(const LoadedDeck &deck)
void processPlayerInfo(const ServerInfo_Player &info)
Definition player_logic.cpp:102
void zoneIdChanged(int zoneId)
const PlaymatParams & getRemotePlaymatParams() const
Definition player_logic.h:228
void setConceded(bool _conceded)
Definition player_logic.cpp:82
Definition remote_connection_controller.h:20
Definition game.h:18
Definition arrow_registry.h:10
Definition stack_zone_logic.h:18
Definition table_zone_logic.h:18
Q_LOGGING_CATEGORY(CrashReportLog, "crash_report")
Defines the DeckList class, which manages a full deck structure including cards, zones,...
constexpr const char * TABLE
Definition zone_names.h:9
constexpr const char * EXILE
Definition zone_names.h:11
constexpr const char * SIDEBOARD
Definition zone_names.h:14
constexpr const char * HAND
Definition zone_names.h:12
constexpr const char * STACK
Definition zone_names.h:15
constexpr const char * DECK
Definition zone_names.h:13
constexpr const char * GRAVE
Definition zone_names.h:10
const int MAX_TOKENS_PER_DIALOG
Definition player_logic.h:53
Definition arrow_data.h:10
Definition card_ref.h:14
Represents a deck that was loaded from somewhere. Contains the DeckList itself, as well as info about...
Definition loaded_deck.h:14
Positioning parameters for a playmat card image.
Definition playmat_params.h:18
Definition serverinfo_card.proto:5
Definition serverinfo_counter.proto:3
Definition serverinfo_playerproperties.proto:3
Definition serverinfo_player.proto:6
Definition serverinfo_user.proto:2
Definition color.proto:4