Cockatrice 2026-06-01-Development-3.1.0-beta.3
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
GameScene Class Reference

Manages the game board display including players, zones, cards, and animations. More...

#include <game_scene.h>

Inheritance diagram for GameScene:
[legend]
Collaboration diagram for GameScene:
[legend]

Public Slots

void toggleZoneView (PlayerLogic *player, const QString &zoneName, int numberCards, bool isReversed=false)
 Toggles a zone view for a player.
void addRevealedZoneView (PlayerLogic *player, CardZoneLogic *zone, const QList< const ServerInfo_Card * > &cardList, bool withWritePermission)
 Adds a revealed zone view (for shown cards).
void removeZoneView (ZoneViewWidget *item)
 Removes a zone view widget from the scene.
void clearViews ()
 Closes all zone views.
void closeMostRecentZoneView ()
 Closes the most recently added zone view.
QTransform getViewTransform () const
QTransform getViewportTransform () const
void addArrow (const ArrowData &data)
 Directly modifies the scene.
void deleteArrow (int arrowId)
void clearArrowsForPlayer (int playerId)
void requestArrowDeletion (int arrowId)
 Queues up arrow deletion but doesn't directly modify the scene.
void requestClearArrowsForPlayer (int playerId)
void onCardZoneChanged (CardItem *card, bool sameZone)

Signals

void sigStartRubberBand (const QPointF &selectionOrigin)
void sigResizeRubberBand (const QPointF &cursorPoint, int selectedCount)
void sigStopRubberBand ()
void arrowDeletionRequested (int arrowId)

Public Member Functions

 GameScene (PhasesToolbar *_phasesToolbar, QObject *parent=nullptr)
 Constructs the GameScene.
 ~GameScene () override
 Destructor, cleans up timer and zone views.
void retranslateUi ()
 Updates UI text for all zone views.
QList< CardItem * > selectedCards () const
 Gets all selected CardItems.
void addPlayer (PlayerLogic *player)
 Adds a player to the scene and stores their graphics item.
void removePlayer (PlayerLogic *player)
 Removes a player from the scene.
void adjustPlayerRotation (int rotationAdjustment)
 Adjusts the global rotation offset for player layout.
void rearrange ()
 Recomputes the layout of players and the scene size.
void processViewSizeChange (const QSize &newSize)
 Handles view resize and redistributes player positions.
QList< PlayerLogic * > collectActivePlayers (int &firstPlayerIndex) const
 Collects all active (non-conceded) players.
QList< PlayerLogic * > rotatePlayers (const QList< PlayerLogic * > &players, int firstPlayerIndex) const
 Rotates the list of players for layout.
QSizeF computeSceneSizeAndPlayerLayout (const QList< PlayerLogic * > &playersPlaying, int columns)
 Computes layout positions and scene size based on players and columns.
QList< qreal > calculateMinWidthByColumn () const
 Computes the minimum width for each column based on player minimum widths.
qreal calculateNewSceneWidth (const QSize &newSize, qreal minWidth) const
 Calculates new scene width considering window aspect ratio.
void resizeColumnsAndPlayers (const QList< qreal > &minWidthByColumn, qreal newWidth)
 Resizes columns and distributes extra width to players.
void updateHoveredCard (CardItem *newCard)
 Updates hovered card highlighting.
void registerAnimationItem (AbstractCardItem *card)
 Registers a card for animation updates.
void unregisterAnimationItem (AbstractCardItem *card)
 Unregisters a card from animation updates.
void startRubberBand (const QPointF &selectionOrigin)
void resizeRubberBand (const QPointF &cursorPoint, int selectedCount)
void stopRubberBand ()

Static Public Member Functions

static int determineColumnCount (int playerCount)
 Determines the number of columns to display players in.
static CardZonefindTopmostZone (const QList< QGraphicsItem * > &items)
 Finds the topmost card zone under the cursor.
static CardItemfindTopmostCardInZone (const QList< QGraphicsItem * > &items, CardZone *zone)
 Finds the topmost card in a given zone, considering attachments and Z-order.

Protected Member Functions

bool event (QEvent *event) override
 Handles hover updates.
void timerEvent (QTimerEvent *event) override
 Handles animation timer updates.

Private Member Functions

void updateHover (const QPointF &scenePos)
 Updates which card is currently hovered based on scene coordinates.
void beginCardHover (CardItem *card)
 Activates hover state and escapes the card from its clip container so hover scaling is visible beyond zone bounds.
void endCardHover (CardItem *card)
 Deactivates hover state and restores the card to its clip container.

Private Attributes

PhasesToolbarphasesToolbar
 Toolbar showing game phases.
QMap< int, PlayerGraphicsItem * > playerViews
 ID lookup for player graphics items.
QList< QList< PlayerGraphicsItem * > > playersByColumn
 Players organized by column.
QMap< int, ArrowItem * > arrowRegistry
 ID registry for arrow graphics items.
QList< ZoneViewWidget * > zoneViews
 Active zone view widgets.
QSize viewSize
 Current view size.
QPointer< CardItemhoveredCard
 Currently hovered card.
QBasicTimer * animationTimer
 Timer for card animations.
QSet< CardItem * > cardsToAnimate
 Cards currently animating.
int playerRotation
 Rotation offset for player layout.

Static Private Attributes

static const int playerAreaSpacing = 5
 Space between player areas.

Detailed Description

Manages the game board display including players, zones, cards, and animations.

GameScene handles:

  • Dynamic arrangement of players in columns/rows.
  • Player rotation adjustments.
  • Zone views for cards (e.g., graveyard, library, revealed zones).
  • Hover and animation handling for cards.
  • Scene resizing and responsive layout.

Constructor & Destructor Documentation

◆ GameScene()

GameScene::GameScene ( PhasesToolbar * _phasesToolbar,
QObject * parent = nullptr )
explicit

Constructs the GameScene.

Parameters
_phasesToolbarToolbar widget for phases.
parentOptional parent QObject.
_phasesToolbarToolbar widget for phases.
parentOptional parent QObject.

Initializes the animation timer, adds the phases toolbar to the scene, and connects to settings changes for multi-column layout. Finally, calls rearrange() to layout players initially.

Here is the call graph for this function:

◆ ~GameScene()

GameScene::~GameScene ( )
override

Destructor, cleans up timer and zone views.

Member Function Documentation

◆ addArrow

void GameScene::addArrow ( const ArrowData & data)
slot

Directly modifies the scene.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addPlayer()

void GameScene::addPlayer ( PlayerLogic * player)

Adds a player to the scene and stores their graphics item.

Parameters
playerPlayer to add.
playerPlayer to add.

Connects to the player's sizeChanged signal to recompute layout on resize.

Here is the call graph for this function:

◆ addRevealedZoneView

void GameScene::addRevealedZoneView ( PlayerLogic * player,
CardZoneLogic * zone,
const QList< const ServerInfo_Card * > & cardList,
bool withWritePermission )
slot

Adds a revealed zone view (for shown cards).

Parameters
playerOwning player.
zoneZone logic.
cardListList of cards to show.
withWritePermissionWhether edits are allowed.
Here is the call graph for this function:

◆ adjustPlayerRotation()

void GameScene::adjustPlayerRotation ( int rotationAdjustment)

Adjusts the global rotation offset for player layout.

Parameters
rotationAdjustmentNumber of positions to rotate.
rotationAdjustmentNumber of positions to rotate.

Recomputes player layout after applying rotation.

Here is the call graph for this function:

◆ arrowDeletionRequested

void GameScene::arrowDeletionRequested ( int arrowId)
signal
Here is the caller graph for this function:

◆ beginCardHover()

void GameScene::beginCardHover ( CardItem * card)
private

Activates hover state and escapes the card from its clip container so hover scaling is visible beyond zone bounds.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculateMinWidthByColumn()

QList< qreal > GameScene::calculateMinWidthByColumn ( ) const

Computes the minimum width for each column based on player minimum widths.

Returns
List of minimum widths per column.
Here is the caller graph for this function:

◆ calculateNewSceneWidth()

qreal GameScene::calculateNewSceneWidth ( const QSize & newSize,
qreal minWidth ) const

Calculates new scene width considering window aspect ratio.

Parameters
newSizeView size.
minWidthMinimum width needed to fit all players.
Returns
Scene width respecting window and content.
Here is the caller graph for this function:

◆ clearArrowsForPlayer

void GameScene::clearArrowsForPlayer ( int playerId)
slot
Here is the caller graph for this function:

◆ clearViews

void GameScene::clearViews ( )
slot

Closes all zone views.

◆ closeMostRecentZoneView

void GameScene::closeMostRecentZoneView ( )
slot

Closes the most recently added zone view.

Here is the caller graph for this function:

◆ collectActivePlayers()

QList< PlayerLogic * > GameScene::collectActivePlayers ( int & firstPlayerIndex) const

Collects all active (non-conceded) players.

Parameters
firstPlayerIndexOutput index of first local player.
Returns
List of active players.
Parameters
firstPlayerIndexOutput index of first local player.
Returns
List of active players.

Used to determine rotation and layout order.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ computeSceneSizeAndPlayerLayout()

QSizeF GameScene::computeSceneSizeAndPlayerLayout ( const QList< PlayerLogic * > & playersPlaying,
int columns )

Computes layout positions and scene size based on players and columns.

Parameters
playersPlayingList of active players.
columnsNumber of columns to split into.
Returns
Calculated scene size.
Parameters
playersPlayingList of active players.
columnsNumber of columns to split into.
Returns
Calculated scene size.

Logic:

  • Determine rows per column (rounding up).
  • Calculate column widths based on widest player item.
  • Accumulate scene width and height.
  • Position players in columns with spacing.
  • Mirror graphics for visual balance.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ deleteArrow

void GameScene::deleteArrow ( int arrowId)
slot
Here is the caller graph for this function:

◆ determineColumnCount()

int GameScene::determineColumnCount ( int playerCount)
static

Determines the number of columns to display players in.

Parameters
playerCountTotal number of active players.
Returns
Number of columns (1 or 2).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ endCardHover()

void GameScene::endCardHover ( CardItem * card)
private

Deactivates hover state and restores the card to its clip container.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ event()

bool GameScene::event ( QEvent * event)
overrideprotected

Handles hover updates.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ findTopmostCardInZone()

CardItem * GameScene::findTopmostCardInZone ( const QList< QGraphicsItem * > & items,
CardZone * zone )
static

Finds the topmost card in a given zone, considering attachments and Z-order.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ findTopmostZone()

CardZone * GameScene::findTopmostZone ( const QList< QGraphicsItem * > & items)
static

Finds the topmost card zone under the cursor.

Here is the caller graph for this function:

◆ getViewportTransform

QTransform GameScene::getViewportTransform ( ) const
slot

◆ getViewTransform

QTransform GameScene::getViewTransform ( ) const
slot
Here is the caller graph for this function:

◆ onCardZoneChanged

void GameScene::onCardZoneChanged ( CardItem * card,
bool sameZone )
slot
Here is the call graph for this function:
Here is the caller graph for this function:

◆ processViewSizeChange()

void GameScene::processViewSizeChange ( const QSize & newSize)

Handles view resize and redistributes player positions.

Parameters
newSizeNew view size.
newSizeNew view size.

Steps:

  1. Compute minimum width per column from player items.
  2. Determine new scene width respecting aspect ratio.
  3. Resize columns and reposition players proportionally.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rearrange()

void GameScene::rearrange ( )

Recomputes the layout of players and the scene size.

Steps:

  1. Collect active players who haven't conceded.
  2. Rotate player list based on first local player and rotation offset.
  3. Determine number of columns.
  4. Compute scene size and layout.
  5. Update toolbar height and scene rectangle.
  6. Adjust columns and player positions to match view size.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ registerAnimationItem()

void GameScene::registerAnimationItem ( AbstractCardItem * card)

Registers a card for animation updates.

◆ removePlayer()

void GameScene::removePlayer ( PlayerLogic * player)

Removes a player from the scene.

Parameters
playerPlayer to remove.
playerPlayer to remove.

Closes any zone views associated with the player and recomputes layout.

Here is the call graph for this function:

◆ removeZoneView

void GameScene::removeZoneView ( ZoneViewWidget * item)
slot

Removes a zone view widget from the scene.

Parameters
itemZone view to remove.
Here is the caller graph for this function:

◆ requestArrowDeletion

void GameScene::requestArrowDeletion ( int arrowId)
slot

Queues up arrow deletion but doesn't directly modify the scene.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ requestClearArrowsForPlayer

void GameScene::requestClearArrowsForPlayer ( int playerId)
slot
Here is the call graph for this function:

◆ resizeColumnsAndPlayers()

void GameScene::resizeColumnsAndPlayers ( const QList< qreal > & minWidthByColumn,
qreal newWidth )

Resizes columns and distributes extra width to players.

Parameters
minWidthByColumnMinimum widths per column.
newWidthTotal scene width.
minWidthByColumnMinimum widths per column.
newWidthTotal scene width.

Extra width is distributed evenly across columns. Each player item is notified to adjust internal layout for the new column width.

Here is the caller graph for this function:

◆ resizeRubberBand()

void GameScene::resizeRubberBand ( const QPointF & cursorPoint,
int selectedCount )
Here is the call graph for this function:

◆ retranslateUi()

void GameScene::retranslateUi ( )

Updates UI text for all zone views.

Updates localized text in all zone views.

◆ rotatePlayers()

QList< PlayerLogic * > GameScene::rotatePlayers ( const QList< PlayerLogic * > & activePlayers,
int firstPlayerIndex ) const

Rotates the list of players for layout.

Parameters
playersOriginal list of players.
firstPlayerIndexIndex of first local player.
Returns
Rotated list.
Parameters
playersOriginal list of players.
firstPlayerIndexIndex of first local player.
Returns
Rotated list.

Applies rotation offset and ensures the list wraps correctly.

Here is the caller graph for this function:

◆ selectedCards()

QList< CardItem * > GameScene::selectedCards ( ) const

Gets all selected CardItems.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sigResizeRubberBand

void GameScene::sigResizeRubberBand ( const QPointF & cursorPoint,
int selectedCount )
signal
Here is the caller graph for this function:

◆ sigStartRubberBand

void GameScene::sigStartRubberBand ( const QPointF & selectionOrigin)
signal
Here is the caller graph for this function:

◆ sigStopRubberBand

void GameScene::sigStopRubberBand ( )
signal
Here is the caller graph for this function:

◆ startRubberBand()

void GameScene::startRubberBand ( const QPointF & selectionOrigin)
Here is the call graph for this function:

◆ stopRubberBand()

void GameScene::stopRubberBand ( )
Here is the call graph for this function:

◆ timerEvent()

void GameScene::timerEvent ( QTimerEvent * event)
overrideprotected

Handles animation timer updates.

◆ toggleZoneView

void GameScene::toggleZoneView ( PlayerLogic * player,
const QString & zoneName,
int numberCards,
bool isReversed = false )
slot

Toggles a zone view for a player.

Parameters
playerPlayer owning the zone.
zoneNameName of the zone.
numberCardsNumber of cards visible in the view.
isReversedWhether the zone view is reversed.

If an identical view exists, it is closed. Otherwise, a new ZoneViewWidget is created and positioned based on zone type.

Here is the call graph for this function:

◆ unregisterAnimationItem()

void GameScene::unregisterAnimationItem ( AbstractCardItem * card)

Unregisters a card from animation updates.

◆ updateHover()

void GameScene::updateHover ( const QPointF & scenePos)
private

Updates which card is currently hovered based on scene coordinates.

Parameters
scenePosScene position of the cursor.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateHoveredCard()

void GameScene::updateHoveredCard ( CardItem * newCard)

Updates hovered card highlighting.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ animationTimer

QBasicTimer* GameScene::animationTimer
private

Timer for card animations.

◆ arrowRegistry

QMap<int, ArrowItem *> GameScene::arrowRegistry
private

ID registry for arrow graphics items.

◆ cardsToAnimate

QSet<CardItem *> GameScene::cardsToAnimate
private

Cards currently animating.

◆ hoveredCard

QPointer<CardItem> GameScene::hoveredCard
private

Currently hovered card.

◆ phasesToolbar

PhasesToolbar* GameScene::phasesToolbar
private

Toolbar showing game phases.

◆ playerAreaSpacing

const int GameScene::playerAreaSpacing = 5
staticprivate

Space between player areas.

◆ playerRotation

int GameScene::playerRotation
private

Rotation offset for player layout.

◆ playersByColumn

QList<QList<PlayerGraphicsItem *> > GameScene::playersByColumn
private

Players organized by column.

◆ playerViews

QMap<int, PlayerGraphicsItem *> GameScene::playerViews
private

ID lookup for player graphics items.

◆ viewSize

QSize GameScene::viewSize
private

Current view size.

◆ zoneViews

QList<ZoneViewWidget *> GameScene::zoneViews
private

Active zone view widgets.


The documentation for this class was generated from the following files: