Cockatrice 2026-06-01-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
4#include "board/arrow_data.h"
5#include "board/arrow_item.h"
7
8#include <QGraphicsScene>
9#include <QList>
10#include <QLoggingCategory>
11#include <QPointer>
12#include <QSet>
13
14inline Q_LOGGING_CATEGORY(GameSceneLog, "game_scene");
15inline Q_LOGGING_CATEGORY(GameScenePlayerAdditionRemovalLog, "game_scene.player_addition_removal");
16
17class PlayerLogic;
19class ZoneViewWidget;
20class CardZone;
22class CardItem;
23class ServerInfo_Card;
24class PhasesToolbar;
25class QBasicTimer;
26
39class GameScene : public QGraphicsScene
40{
41 Q_OBJECT
42private:
43 static const int playerAreaSpacing = 5;
44
46 QMap<int, PlayerGraphicsItem *> playerViews;
47 QList<QList<PlayerGraphicsItem *>> playersByColumn;
48 QMap<int, ArrowItem *> arrowRegistry;
49 QList<ZoneViewWidget *> zoneViews;
50 QSize viewSize;
51 QPointer<CardItem> hoveredCard;
52 QBasicTimer *animationTimer;
53 QSet<CardItem *> cardsToAnimate;
55
60 void updateHover(const QPointF &scenePos);
61
66 void beginCardHover(CardItem *card);
68 void endCardHover(CardItem *card);
69
70public:
76 explicit GameScene(PhasesToolbar *_phasesToolbar, QObject *parent = nullptr);
77
79 ~GameScene() override;
80
82 void retranslateUi();
83
85 QList<CardItem *> selectedCards() const;
86
91 void addPlayer(PlayerLogic *player);
92
97 void removePlayer(PlayerLogic *player);
98
103 void adjustPlayerRotation(int rotationAdjustment);
104
106 void rearrange();
107
112 void processViewSizeChange(const QSize &newSize);
113
119 QList<PlayerLogic *> collectActivePlayers(int &firstPlayerIndex) const;
120
127 QList<PlayerLogic *> rotatePlayers(const QList<PlayerLogic *> &players, int firstPlayerIndex) const;
128
134 static int determineColumnCount(int playerCount);
135
142 QSizeF computeSceneSizeAndPlayerLayout(const QList<PlayerLogic *> &playersPlaying, int columns);
143
148 QList<qreal> calculateMinWidthByColumn() const;
149
156 qreal calculateNewSceneWidth(const QSize &newSize, qreal minWidth) const;
157
163 void resizeColumnsAndPlayers(const QList<qreal> &minWidthByColumn, qreal newWidth);
164
166 static CardZone *findTopmostZone(const QList<QGraphicsItem *> &items);
167
169 static CardItem *findTopmostCardInZone(const QList<QGraphicsItem *> &items, CardZone *zone);
170
172 void updateHoveredCard(CardItem *newCard);
173
176
179 void startRubberBand(const QPointF &selectionOrigin);
180 void resizeRubberBand(const QPointF &cursorPoint, int selectedCount);
181 void stopRubberBand();
182
183public slots:
185 void toggleZoneView(PlayerLogic *player, const QString &zoneName, int numberCards, bool isReversed = false);
186
188 void addRevealedZoneView(PlayerLogic *player,
189 CardZoneLogic *zone,
190 const QList<const ServerInfo_Card *> &cardList,
191 bool withWritePermission);
192
194 void removeZoneView(ZoneViewWidget *item);
195
197 void clearViews();
198
201 QTransform getViewTransform() const;
202 QTransform getViewportTransform() const;
203
205 void addArrow(const ArrowData &data);
206 void deleteArrow(int arrowId);
207 void clearArrowsForPlayer(int playerId);
208
210 void requestArrowDeletion(int arrowId);
211 void requestClearArrowsForPlayer(int playerId);
212
213 void onCardZoneChanged(CardItem *card, bool sameZone);
214
215protected:
217 bool event(QEvent *event) override;
218
220 void timerEvent(QTimerEvent *event) override;
221
222signals:
223 void sigStartRubberBand(const QPointF &selectionOrigin);
224 void sigResizeRubberBand(const QPointF &cursorPoint, int selectedCount);
226 void arrowDeletionRequested(int arrowId);
227};
228
229#endif
Definition abstract_card_item.h:20
Definition card_item.h:28
Definition card_zone_logic.h:26
Definition card_zone.h:26
qreal calculateNewSceneWidth(const QSize &newSize, qreal minWidth) const
Calculates new scene width considering window aspect ratio.
Definition game_scene.cpp:334
static int determineColumnCount(int playerCount)
Determines the number of columns to display players in.
Definition game_scene.cpp:242
void toggleZoneView(PlayerLogic *player, const QString &zoneName, int numberCards, bool isReversed=false)
Toggles a zone view for a player.
Definition game_scene.cpp:550
void removeZoneView(ZoneViewWidget *item)
Removes a zone view widget from the scene.
Definition game_scene.cpp:599
void sigStopRubberBand()
void removePlayer(PlayerLogic *player)
Removes a player from the scene.
Definition game_scene.cpp:113
QList< CardItem * > selectedCards() const
Gets all selected CardItems.
Definition game_scene.cpp:63
QList< PlayerLogic * > collectActivePlayers(int &firstPlayerIndex) const
Collects all active (non-conceded) players.
Definition game_scene.cpp:200
QSizeF computeSceneSizeAndPlayerLayout(const QList< PlayerLogic * > &playersPlaying, int columns)
Computes layout positions and scene size based on players and columns.
Definition game_scene.cpp:260
void resizeRubberBand(const QPointF &cursorPoint, int selectedCount)
Definition game_scene.cpp:687
QList< PlayerLogic * > rotatePlayers(const QList< PlayerLogic * > &players, int firstPlayerIndex) const
Rotates the list of players for layout.
Definition game_scene.cpp:227
void startRubberBand(const QPointF &selectionOrigin)
Definition game_scene.cpp:682
static CardZone * findTopmostZone(const QList< QGraphicsItem * > &items)
Finds the topmost card zone under the cursor.
Definition game_scene.cpp:501
void timerEvent(QTimerEvent *event) override
Handles animation timer updates.
Definition game_scene.cpp:650
PhasesToolbar * phasesToolbar
Toolbar showing game phases.
Definition game_scene.h:45
QList< qreal > calculateMinWidthByColumn() const
Computes the minimum width for each column based on player minimum widths.
Definition game_scene.cpp:315
void updateHoveredCard(CardItem *newCard)
Updates hovered card highlighting.
Definition game_scene.cpp:474
void clearViews()
Closes all zone views.
Definition game_scene.cpp:608
void onCardZoneChanged(CardItem *card, bool sameZone)
Definition game_scene.cpp:446
QTransform getViewTransform() const
Definition game_scene.cpp:627
void addArrow(const ArrowData &data)
Directly modifies the scene.
Definition game_scene.cpp:370
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:511
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:485
void clearArrowsForPlayer(int playerId)
Definition game_scene.cpp:415
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:583
static const int playerAreaSpacing
Space between player areas.
Definition game_scene.h:43
QSize viewSize
Current view size.
Definition game_scene.h:50
void stopRubberBand()
Definition game_scene.cpp:692
void requestArrowDeletion(int arrowId)
Queues up arrow deletion but doesn't directly modify the scene.
Definition game_scene.cpp:430
void closeMostRecentZoneView()
Closes the most recently added zone view.
Definition game_scene.cpp:618
bool event(QEvent *event) override
Handles hover updates.
Definition game_scene.cpp:639
void endCardHover(CardItem *card)
Deactivates hover state and restores the card to its clip container.
Definition game_scene.cpp:493
~GameScene() override
Destructor, cleans up timer and zone views.
Definition game_scene.cpp:41
int playerRotation
Rotation offset for player layout.
Definition game_scene.h:54
QPointer< CardItem > hoveredCard
Currently hovered card.
Definition game_scene.h:51
void retranslateUi()
Updates UI text for all zone views.
Definition game_scene.cpp:56
void registerAnimationItem(AbstractCardItem *card)
Registers a card for animation updates.
Definition game_scene.cpp:664
void processViewSizeChange(const QSize &newSize)
Handles view resize and redistributes player positions.
Definition game_scene.cpp:178
QList< QList< PlayerGraphicsItem * > > playersByColumn
Players organized by column.
Definition game_scene.h:47
void deleteArrow(int arrowId)
Definition game_scene.cpp:408
void adjustPlayerRotation(int rotationAdjustment)
Adjusts the global rotation offset for player layout.
Definition game_scene.cpp:135
void unregisterAnimationItem(AbstractCardItem *card)
Unregisters a card from animation updates.
Definition game_scene.cpp:672
QBasicTimer * animationTimer
Timer for card animations.
Definition game_scene.h:52
QTransform getViewportTransform() const
Definition game_scene.cpp:632
void addPlayer(PlayerLogic *player)
Adds a player to the scene and stores their graphics item.
Definition game_scene.cpp:81
QMap< int, PlayerGraphicsItem * > playerViews
ID lookup for player graphics items.
Definition game_scene.h:46
void resizeColumnsAndPlayers(const QList< qreal > &minWidthByColumn, qreal newWidth)
Resizes columns and distributes extra width to players.
Definition game_scene.cpp:354
QList< ZoneViewWidget * > zoneViews
Active zone view widgets.
Definition game_scene.h:49
void requestClearArrowsForPlayer(int playerId)
Definition game_scene.cpp:437
void sigResizeRubberBand(const QPointF &cursorPoint, int selectedCount)
QMap< int, ArrowItem * > arrowRegistry
ID registry for arrow graphics items.
Definition game_scene.h:48
void rearrange()
Recomputes the layout of players and the scene size.
Definition game_scene.cpp:152
QSet< CardItem * > cardsToAnimate
Cards currently animating.
Definition game_scene.h:53
void sigStartRubberBand(const QPointF &selectionOrigin)
GameScene(PhasesToolbar *_phasesToolbar, QObject *parent=nullptr)
Constructs the GameScene.
Definition game_scene.cpp:30
void arrowDeletionRequested(int arrowId)
void updateHover(const QPointF &scenePos)
Updates which card is currently hovered based on scene coordinates.
Definition game_scene.cpp:465
Definition phases_toolbar.h:66
Definition player_graphics_item.h:23
Definition player_logic.h:65
Definition view_zone_widget.h:51
Q_LOGGING_CATEGORY(GameSceneLog, "game_scene")
Definition arrow_data.h:10