Cockatrice 2025-11-30-Development-2.11.0-beta.38
A cross-platform 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 (Player *player, const QString &zoneName, int numberCards, bool isReversed=false)
 Toggles a zone view for a player.
void addRevealedZoneView (Player *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

Signals

void sigStartRubberBand (const QPointF &selectionOrigin)
void sigResizeRubberBand (const QPointF &cursorPoint)
void sigStopRubberBand ()

Public Member Functions

 GameScene (PhasesToolbar *_phasesToolbar, QObject *parent=nullptr)
 Constructs the GameScene.
 ~GameScene () override
void retranslateUi ()
 Updates localized text in all zone views.
void addPlayer (Player *player)
 Adds a player to the scene and stores their graphics item.
void removePlayer (Player *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< Player * > collectActivePlayers (int &firstPlayerIndex) const
 Collects all active (non-conceded) players.
QList< Player * > rotatePlayers (const QList< Player * > &players, int firstPlayerIndex) const
 Rotates the list of players for layout.
QSizeF computeSceneSizeAndPlayerLayout (const QList< Player * > &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)
void registerAnimationItem (AbstractCardItem *card)
void unregisterAnimationItem (AbstractCardItem *card)
void startRubberBand (const QPointF &selectionOrigin)
void resizeRubberBand (const QPointF &cursorPoint)
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)
static CardItemfindTopmostCardInZone (const QList< QGraphicsItem * > &items, CardZone *zone)

Protected Member Functions

bool event (QEvent *event) override
void timerEvent (QTimerEvent *event) override

Private Member Functions

void updateHover (const QPointF &scenePos)
 Updates which card is currently hovered based on scene coordinates.

Private Attributes

PhasesToolbarphasesToolbar
 Toolbar showing game phases.
QList< PlayerGraphicsItem * > players
 All player graphics items.
QList< QList< PlayerGraphicsItem * > > playersByColumn
 Players organized by column.
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

◆ addPlayer()

void GameScene::addPlayer ( Player * 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 ( Player * player,
CardZoneLogic * zone,
const QList< const ServerInfo_Card * > & cardList,
bool withWritePermission )
slot

Adds a revealed zone view (for shown cards).

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:

◆ 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:

◆ clearViews

void GameScene::clearViews ( )
slot

Closes all zone views.

Closes all zone views.

◆ closeMostRecentZoneView

void GameScene::closeMostRecentZoneView ( )
slot

Closes the most recently added zone view.

Closes the most recently added zone view.

Here is the caller graph for this function:

◆ collectActivePlayers()

QList< Player * > 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< Player * > & 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:

◆ 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:

◆ 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:

◆ 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.

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 ( Player * 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.

Removes a zone view widget from the scene.

Parameters
itemZone view to remove.
Here is the caller 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)
Here is the call graph for this function:

◆ retranslateUi()

void GameScene::retranslateUi ( )

Updates localized text in all zone views.

Updates UI text for all zone views.

◆ rotatePlayers()

QList< Player * > GameScene::rotatePlayers ( const QList< Player * > & 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:

◆ sigResizeRubberBand

void GameScene::sigResizeRubberBand ( const QPointF & cursorPoint)
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 ( Player * player,
const QString & zoneName,
int numberCards,
bool isReversed = false )
slot

Toggles a zone view for a player.

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.

◆ 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.

◆ players

QList<PlayerGraphicsItem *> GameScene::players
private

All player graphics items.

◆ playersByColumn

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

Players organized by column.

◆ 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: