Cockatrice 2025-11-30-Development-2.11.0-beta.38
A cross-platform 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
5
6#include <QGraphicsScene>
7#include <QList>
8#include <QLoggingCategory>
9#include <QPointer>
10#include <QSet>
11
12inline Q_LOGGING_CATEGORY(GameSceneLog, "game_scene");
13inline Q_LOGGING_CATEGORY(GameScenePlayerAdditionRemovalLog, "game_scene.player_addition_removal");
14
15class Player;
17class ZoneViewWidget;
18class CardZone;
20class CardItem;
21class ServerInfo_Card;
22class PhasesToolbar;
23class QBasicTimer;
24
37class GameScene : public QGraphicsScene
38{
39 Q_OBJECT
40private:
41 static const int playerAreaSpacing = 5;
42
44 QList<PlayerGraphicsItem *> players;
45 QList<QList<PlayerGraphicsItem *>> playersByColumn;
46 QList<ZoneViewWidget *> zoneViews;
47 QSize viewSize;
48 QPointer<CardItem> hoveredCard;
49 QBasicTimer *animationTimer;
50 QSet<CardItem *> cardsToAnimate;
52
57 void updateHover(const QPointF &scenePos);
58
59public:
65 explicit GameScene(PhasesToolbar *_phasesToolbar, QObject *parent = nullptr);
66
68 ~GameScene() override;
69
71 void retranslateUi();
72
77 void addPlayer(Player *player);
78
83 void removePlayer(Player *player);
84
89 void adjustPlayerRotation(int rotationAdjustment);
90
92 void rearrange();
93
98 void processViewSizeChange(const QSize &newSize);
99
105 QList<Player *> collectActivePlayers(int &firstPlayerIndex) const;
106
113 QList<Player *> rotatePlayers(const QList<Player *> &players, int firstPlayerIndex) const;
114
120 static int determineColumnCount(int playerCount);
121
128 QSizeF computeSceneSizeAndPlayerLayout(const QList<Player *> &playersPlaying, int columns);
129
134 QList<qreal> calculateMinWidthByColumn() const;
135
142 qreal calculateNewSceneWidth(const QSize &newSize, qreal minWidth) const;
143
149 void resizeColumnsAndPlayers(const QList<qreal> &minWidthByColumn, qreal newWidth);
150
152 static CardZone *findTopmostZone(const QList<QGraphicsItem *> &items);
153
155 static CardItem *findTopmostCardInZone(const QList<QGraphicsItem *> &items, CardZone *zone);
156
158 void updateHoveredCard(CardItem *newCard);
159
162
165 void startRubberBand(const QPointF &selectionOrigin);
166 void resizeRubberBand(const QPointF &cursorPoint);
167 void stopRubberBand();
168
169public slots:
171 void toggleZoneView(Player *player, const QString &zoneName, int numberCards, bool isReversed = false);
172
174 void addRevealedZoneView(Player *player,
175 CardZoneLogic *zone,
176 const QList<const ServerInfo_Card *> &cardList,
177 bool withWritePermission);
178
180 void removeZoneView(ZoneViewWidget *item);
181
183 void clearViews();
184
187 QTransform getViewTransform() const;
188 QTransform getViewportTransform() const;
189
190protected:
192 bool event(QEvent *event) override;
193
195 void timerEvent(QTimerEvent *event) override;
196
197signals:
198 void sigStartRubberBand(const QPointF &selectionOrigin);
199 void sigResizeRubberBand(const QPointF &cursorPoint);
201};
202
203#endif
TODO: Document this.
Definition abstract_card_item.h:22
Definition card_item.h:29
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:296
static int determineColumnCount(int playerCount)
Determines the number of columns to display players in.
Definition game_scene.cpp:206
void removeZoneView(ZoneViewWidget *item)
Removes a zone view widget from the scene.
Definition game_scene.cpp:444
void sigStopRubberBand()
QList< Player * > rotatePlayers(const QList< Player * > &players, int firstPlayerIndex) const
Rotates the list of players for layout.
Definition game_scene.cpp:193
void toggleZoneView(Player *player, const QString &zoneName, int numberCards, bool isReversed=false)
Toggles a zone view for a player.
Definition game_scene.cpp:396
void startRubberBand(const QPointF &selectionOrigin)
Definition game_scene.cpp:518
static CardZone * findTopmostZone(const QList< QGraphicsItem * > &items)
Definition game_scene.cpp:352
void timerEvent(QTimerEvent *event) override
Definition game_scene.cpp:490
PhasesToolbar * phasesToolbar
Toolbar showing game phases.
Definition game_scene.h:43
QList< qreal > calculateMinWidthByColumn() const
Computes the minimum width for each column based on player minimum widths.
Definition game_scene.cpp:278
void addPlayer(Player *player)
Adds a player to the scene and stores their graphics item.
Definition game_scene.cpp:66
void updateHoveredCard(CardItem *newCard)
Definition game_scene.cpp:343
void clearViews()
Closes all zone views.
Definition game_scene.cpp:453
QTransform getViewTransform() const
Definition game_scene.cpp:470
static CardItem * findTopmostCardInZone(const QList< QGraphicsItem * > &items, CardZone *zone)
Definition game_scene.cpp:360
static const int playerAreaSpacing
Space between player areas.
Definition game_scene.h:41
QSize viewSize
Current view size.
Definition game_scene.h:47
void stopRubberBand()
Definition game_scene.cpp:528
void closeMostRecentZoneView()
Closes the most recently added zone view.
Definition game_scene.cpp:462
bool event(QEvent *event) override
Definition game_scene.cpp:482
~GameScene() override
Definition game_scene.cpp:39
QList< Player * > collectActivePlayers(int &firstPlayerIndex) const
Collects all active (non-conceded) players.
Definition game_scene.cpp:166
void resizeRubberBand(const QPointF &cursorPoint)
Definition game_scene.cpp:523
int playerRotation
Rotation offset for player layout.
Definition game_scene.h:51
QPointer< CardItem > hoveredCard
Currently hovered card.
Definition game_scene.h:48
void retranslateUi()
Updates localized text in all zone views.
Definition game_scene.cpp:54
void registerAnimationItem(AbstractCardItem *card)
Definition game_scene.cpp:502
void processViewSizeChange(const QSize &newSize)
Handles view resize and redistributes player positions.
Definition game_scene.cpp:144
QList< QList< PlayerGraphicsItem * > > playersByColumn
Players organized by column.
Definition game_scene.h:45
void sigResizeRubberBand(const QPointF &cursorPoint)
void adjustPlayerRotation(int rotationAdjustment)
Adjusts the global rotation offset for player layout.
Definition game_scene.cpp:101
void unregisterAnimationItem(AbstractCardItem *card)
Definition game_scene.cpp:509
QBasicTimer * animationTimer
Timer for card animations.
Definition game_scene.h:49
void removePlayer(Player *player)
Removes a player from the scene.
Definition game_scene.cpp:81
QTransform getViewportTransform() const
Definition game_scene.cpp:475
QSizeF computeSceneSizeAndPlayerLayout(const QList< Player * > &playersPlaying, int columns)
Computes layout positions and scene size based on players and columns.
Definition game_scene.cpp:224
void resizeColumnsAndPlayers(const QList< qreal > &minWidthByColumn, qreal newWidth)
Resizes columns and distributes extra width to players.
Definition game_scene.cpp:316
void addRevealedZoneView(Player *player, CardZoneLogic *zone, const QList< const ServerInfo_Card * > &cardList, bool withWritePermission)
Adds a revealed zone view (for shown cards).
Definition game_scene.cpp:428
QList< ZoneViewWidget * > zoneViews
Active zone view widgets.
Definition game_scene.h:46
void rearrange()
Recomputes the layout of players and the scene size.
Definition game_scene.cpp:118
QSet< CardItem * > cardsToAnimate
Cards currently animating.
Definition game_scene.h:50
void sigStartRubberBand(const QPointF &selectionOrigin)
GameScene(PhasesToolbar *_phasesToolbar, QObject *parent=nullptr)
Constructs the GameScene.
Definition game_scene.cpp:28
QList< PlayerGraphicsItem * > players
All player graphics items.
Definition game_scene.h:44
void updateHover(const QPointF &scenePos)
Updates which card is currently hovered based on scene coordinates.
Definition game_scene.cpp:334
Definition phases_toolbar.h:66
Definition player_graphics_item.h:22
Definition player.h:65
Definition view_zone_widget.h:49
Q_LOGGING_CATEGORY(GameSceneLog, "game_scene")