Cockatrice 2026-06-27-Development-3.1.0-beta.3
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
game_scene.h
Go to the documentation of this file.
1#ifndef GAMESCENE_H
2#define GAMESCENE_H
3
7#include "board/arrow_item.h"
8
9#include <QGraphicsScene>
10#include <QList>
11#include <QLoggingCategory>
12#include <QPointer>
13#include <QSet>
14
15inline Q_LOGGING_CATEGORY(GameSceneLog, "game_scene");
16inline Q_LOGGING_CATEGORY(GameScenePlayerAdditionRemovalLog, "game_scene.player_addition_removal");
17
18class PlayerLogic;
20class ZoneViewWidget;
21class CardZone;
23class CardItem;
24class ServerInfo_Card;
25class PhasesToolbar;
26class QBasicTimer;
27
40class GameScene : public QGraphicsScene
41{
42 Q_OBJECT
43private:
44 static const int playerAreaSpacing = 5;
45
47 QMap<int, PlayerGraphicsItem *> playerViews;
48 QList<QList<PlayerGraphicsItem *>> playersByColumn;
50 QList<ZoneViewWidget *> zoneViews;
51 QSize viewSize;
52 QPointer<CardItem> hoveredCard;
53 QBasicTimer *animationTimer;
54 QSet<CardItem *> cardsToAnimate;
56
61 void updateHover(const QPointF &scenePos);
62
67 void beginCardHover(CardItem *card);
69 void endCardHover(CardItem *card);
70
71public:
77 explicit GameScene(PhasesToolbar *_phasesToolbar, QObject *parent = nullptr);
78
80 ~GameScene() override;
81
83 void retranslateUi();
84
86 QList<CardItem *> selectedCards() const;
87
92 void addPlayer(PlayerLogic *player);
93
98 void removePlayer(PlayerLogic *player);
99
100 QMap<int, PlayerGraphicsItem *> getPlayers() const
101 {
102 return playerViews;
103 }
104
106 {
107 return playerViews.value(playerId);
108 }
109
114 void adjustPlayerRotation(int rotationAdjustment);
115
117 void rearrange();
118
123 void processViewSizeChange(const QSize &newSize);
124
130 QList<PlayerLogic *> collectActivePlayers(int &firstPlayerIndex) const;
131
138 QList<PlayerLogic *> rotatePlayers(const QList<PlayerLogic *> &players, int firstPlayerIndex) const;
139
145 static int determineColumnCount(int playerCount);
146
153 QSizeF computeSceneSizeAndPlayerLayout(const QList<PlayerLogic *> &playersPlaying, int columns);
154
159 QList<qreal> calculateMinWidthByColumn() const;
160
167 qreal calculateNewSceneWidth(const QSize &newSize, qreal minWidth) const;
168
174 void resizeColumnsAndPlayers(const QList<qreal> &minWidthByColumn, qreal newWidth);
175
177 static CardZone *findTopmostZone(const QList<QGraphicsItem *> &items);
178
180 static CardItem *findTopmostCardInZone(const QList<QGraphicsItem *> &items, CardZone *zone);
181
183 void updateHoveredCard(CardItem *newCard);
184
187
190 void startRubberBand(const QPointF &selectionOrigin);
191 void resizeRubberBand(const QPointF &cursorPoint, int selectedCount);
192 void stopRubberBand();
193
194public slots:
195 void onCardSelectionChanged(AbstractCardItem *card, bool selected);
196 void onCardRightClicked(AbstractCardItem *card, QPoint screenPos);
197 void playSelected(AbstractCardItem *card);
199 void hideSelected(AbstractCardItem *card);
201 void toggleZoneView(PlayerLogic *player, const QString &zoneName, int numberCards, bool isReversed = false);
202
204 void addRevealedZoneView(PlayerLogic *player,
205 CardZoneLogic *zone,
206 const QList<const ServerInfo_Card *> &cardList,
207 bool withWritePermission);
208
210 void removeZoneView(ZoneViewWidget *item);
211
213 void clearViews();
214
217 QTransform getViewTransform() const;
218 QTransform getViewportTransform() const;
219
221 void addArrow(QSharedPointer<ArrowData> data);
222 void deleteArrow(int playerId, int arrowId);
223 void clearArrowsForPlayer(int playerId);
224 void clearArrowsForPlayerLocally(int playerId);
225
227 void requestArrowDeletion(int playerId, int arrowId);
228
229 void onCardZoneChanged(CardItem *card, bool sameZone);
230
231protected:
233 bool event(QEvent *event) override;
234
236 void timerEvent(QTimerEvent *event) override;
237
238signals:
239 void sigStartRubberBand(const QPointF &selectionOrigin);
240 void sigResizeRubberBand(const QPointF &cursorPoint, int selectedCount);
242 void arrowDeletionRequested(int creatorId, int arrowId);
243};
244
245#endif
Definition abstract_card_item.h:20
Definition arrow_registry.h:27
Definition card_item.h:28
Definition card_zone_logic.h:26
Definition card_zone.h:26
void onCardRightClicked(AbstractCardItem *card, QPoint screenPos)
Definition game_scene.cpp:99
qreal calculateNewSceneWidth(const QSize &newSize, qreal minWidth) const
Calculates new scene width considering window aspect ratio.
Definition game_scene.cpp:417
static int determineColumnCount(int playerCount)
Determines the number of columns to display players in.
Definition game_scene.cpp:325
void toggleZoneView(PlayerLogic *player, const QString &zoneName, int numberCards, bool isReversed=false)
Toggles a zone view for a player.
Definition game_scene.cpp:623
void removeZoneView(ZoneViewWidget *item)
Removes a zone view widget from the scene.
Definition game_scene.cpp:672
void sigStopRubberBand()
void removePlayer(PlayerLogic *player)
Removes a player from the scene.
Definition game_scene.cpp:195
QList< CardItem * > selectedCards() const
Gets all selected CardItems.
Definition game_scene.cpp:67
void requestArrowDeletion(int playerId, int arrowId)
Queues up arrow deletion but doesn't directly modify the scene.
Definition game_scene.cpp:498
QList< PlayerLogic * > collectActivePlayers(int &firstPlayerIndex) const
Collects all active (non-conceded) players.
Definition game_scene.cpp:283
QSizeF computeSceneSizeAndPlayerLayout(const QList< PlayerLogic * > &playersPlaying, int columns)
Computes layout positions and scene size based on players and columns.
Definition game_scene.cpp:343
void resizeRubberBand(const QPointF &cursorPoint, int selectedCount)
Definition game_scene.cpp:760
QList< PlayerLogic * > rotatePlayers(const QList< PlayerLogic * > &players, int firstPlayerIndex) const
Rotates the list of players for layout.
Definition game_scene.cpp:310
void startRubberBand(const QPointF &selectionOrigin)
Definition game_scene.cpp:755
static CardZone * findTopmostZone(const QList< QGraphicsItem * > &items)
Finds the topmost card zone under the cursor.
Definition game_scene.cpp:574
void timerEvent(QTimerEvent *event) override
Handles animation timer updates.
Definition game_scene.cpp:723
PhasesToolbar * phasesToolbar
Toolbar showing game phases.
Definition game_scene.h:46
QList< qreal > calculateMinWidthByColumn() const
Computes the minimum width for each column based on player minimum widths.
Definition game_scene.cpp:398
void updateHoveredCard(CardItem *newCard)
Updates hovered card highlighting.
Definition game_scene.cpp:547
void clearViews()
Closes all zone views.
Definition game_scene.cpp:681
void deleteArrow(int playerId, int arrowId)
Definition game_scene.cpp:491
void onCardZoneChanged(CardItem *card, bool sameZone)
Definition game_scene.cpp:505
QTransform getViewTransform() const
Definition game_scene.cpp:700
static CardItem * findTopmostCardInZone(const QList< QGraphicsItem * > &items, CardZone *zone)
Finds the topmost card in a given zone, considering attachments and Z-order.
Definition game_scene.cpp:584
void beginCardHover(CardItem *card)
Activates hover state and escapes the card from its clip container so hover scaling is visible beyond...
Definition game_scene.cpp:558
void clearArrowsForPlayer(int playerId)
Definition game_scene.cpp:522
void arrowDeletionRequested(int creatorId, int arrowId)
void addRevealedZoneView(PlayerLogic *player, CardZoneLogic *zone, const QList< const ServerInfo_Card * > &cardList, bool withWritePermission)
Adds a revealed zone view (for shown cards).
Definition game_scene.cpp:656
void playSelectedFaceDown(AbstractCardItem *card)
Definition game_scene.cpp:131
static const int playerAreaSpacing
Space between player areas.
Definition game_scene.h:44
QSize viewSize
Current view size.
Definition game_scene.h:51
void stopRubberBand()
Definition game_scene.cpp:765
void clearArrowsForPlayerLocally(int playerId)
Definition game_scene.cpp:529
void closeMostRecentZoneView()
Closes the most recently added zone view.
Definition game_scene.cpp:691
bool event(QEvent *event) override
Handles hover updates.
Definition game_scene.cpp:712
void endCardHover(CardItem *card)
Deactivates hover state and restores the card to its clip container.
Definition game_scene.cpp:566
~GameScene() override
Destructor, cleans up timer and zone views.
Definition game_scene.cpp:45
int playerRotation
Rotation offset for player layout.
Definition game_scene.h:55
QPointer< CardItem > hoveredCard
Currently hovered card.
Definition game_scene.h:52
void retranslateUi()
Updates UI text for all zone views.
Definition game_scene.cpp:60
void registerAnimationItem(AbstractCardItem *card)
Registers a card for animation updates.
Definition game_scene.cpp:737
void processViewSizeChange(const QSize &newSize)
Handles view resize and redistributes player positions.
Definition game_scene.cpp:261
QList< QList< PlayerGraphicsItem * > > playersByColumn
Players organized by column.
Definition game_scene.h:48
void addArrow(QSharedPointer< ArrowData > data)
Directly modifies the scene.
Definition game_scene.cpp:453
QMap< int, PlayerGraphicsItem * > getPlayers() const
Definition game_scene.h:100
void adjustPlayerRotation(int rotationAdjustment)
Adjusts the global rotation offset for player layout.
Definition game_scene.cpp:218
void unregisterAnimationItem(AbstractCardItem *card)
Unregisters a card from animation updates.
Definition game_scene.cpp:745
QBasicTimer * animationTimer
Timer for card animations.
Definition game_scene.h:53
QTransform getViewportTransform() const
Definition game_scene.cpp:705
void addPlayer(PlayerLogic *player)
Adds a player to the scene and stores their graphics item.
Definition game_scene.cpp:159
PlayerGraphicsItem * viewForPlayer(int playerId)
Definition game_scene.h:105
QMap< int, PlayerGraphicsItem * > playerViews
ID lookup for player graphics items.
Definition game_scene.h:47
void resizeColumnsAndPlayers(const QList< qreal > &minWidthByColumn, qreal newWidth)
Resizes columns and distributes extra width to players.
Definition game_scene.cpp:437
void hideSelected(AbstractCardItem *card)
Definition game_scene.cpp:142
void playSelected(AbstractCardItem *card)
Definition game_scene.cpp:120
ArrowRegistry arrowRegistry
ID registry for arrow graphics items.
Definition game_scene.h:49
QList< ZoneViewWidget * > zoneViews
Active zone view widgets.
Definition game_scene.h:50
void sigResizeRubberBand(const QPointF &cursorPoint, int selectedCount)
void rearrange()
Recomputes the layout of players and the scene size.
Definition game_scene.cpp:235
QSet< CardItem * > cardsToAnimate
Cards currently animating.
Definition game_scene.h:54
void sigStartRubberBand(const QPointF &selectionOrigin)
GameScene(PhasesToolbar *_phasesToolbar, QObject *parent=nullptr)
Constructs the GameScene.
Definition game_scene.cpp:34
void updateHover(const QPointF &scenePos)
Updates which card is currently hovered based on scene coordinates.
Definition game_scene.cpp:538
void onCardSelectionChanged(AbstractCardItem *card, bool selected)
Definition game_scene.cpp:79
Definition phases_toolbar.h:66
Definition player_graphics_item.h:25
Definition player_logic.h:64
Definition view_zone_widget.h:51
Q_LOGGING_CATEGORY(GameSceneLog, "game_scene")