Manages the game board display including players, zones, cards, and animations.
More...
#include <game_scene.h>
|
| void | updateHover (const QPointF &scenePos) |
| | Updates which card is currently hovered based on scene coordinates.
|
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.
◆ GameScene()
| GameScene::GameScene |
( |
PhasesToolbar * | _phasesToolbar, |
|
|
QObject * | parent = nullptr ) |
|
explicit |
Constructs the GameScene.
- Parameters
-
| _phasesToolbar | Toolbar widget for phases. |
| parent | Optional parent QObject. |
| _phasesToolbar | Toolbar widget for phases. |
| parent | Optional 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.
◆ ~GameScene()
| GameScene::~GameScene |
( |
| ) |
|
|
override |
Destructor, cleans up timer and zone views.
◆ addPlayer()
| void GameScene::addPlayer |
( |
Player * | player | ) |
|
Adds a player to the scene and stores their graphics item.
- Parameters
-
Connects to the player's sizeChanged signal to recompute layout on resize.
◆ 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
-
| player | Owning player. |
| zone | Zone logic. |
| cardList | List of cards to show. |
| withWritePermission | Whether edits are allowed. |
◆ adjustPlayerRotation()
| void GameScene::adjustPlayerRotation |
( |
int | rotationAdjustment | ) |
|
Adjusts the global rotation offset for player layout.
- Parameters
-
| rotationAdjustment | Number of positions to rotate. |
| rotationAdjustment | Number of positions to rotate. |
Recomputes player layout after applying rotation.
◆ 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.
◆ calculateNewSceneWidth()
| qreal GameScene::calculateNewSceneWidth |
( |
const QSize & | newSize, |
|
|
qreal | minWidth ) const |
Calculates new scene width considering window aspect ratio.
- Parameters
-
| newSize | View size. |
| minWidth | Minimum width needed to fit all players. |
- Returns
- Scene width respecting window and content.
◆ 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.
◆ collectActivePlayers()
| QList< Player * > GameScene::collectActivePlayers |
( |
int & | firstPlayerIndex | ) |
const |
Collects all active (non-conceded) players.
- Parameters
-
| firstPlayerIndex | Output index of first local player. |
- Returns
- List of active players.
- Parameters
-
| firstPlayerIndex | Output index of first local player. |
- Returns
- List of active players.
Used to determine rotation and layout order.
◆ computeSceneSizeAndPlayerLayout()
| QSizeF GameScene::computeSceneSizeAndPlayerLayout |
( |
const QList< Player * > & | playersPlaying, |
|
|
int | columns ) |
Computes layout positions and scene size based on players and columns.
- Parameters
-
| playersPlaying | List of active players. |
| columns | Number of columns to split into. |
- Returns
- Calculated scene size.
- Parameters
-
| playersPlaying | List of active players. |
| columns | Number 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.
◆ determineColumnCount()
| int GameScene::determineColumnCount |
( |
int | playerCount | ) |
|
|
static |
Determines the number of columns to display players in.
- Parameters
-
| playerCount | Total number of active players. |
- Returns
- Number of columns (1 or 2).
◆ event()
| bool GameScene::event |
( |
QEvent * | event | ) |
|
|
overrideprotected |
◆ findTopmostCardInZone()
| CardItem * GameScene::findTopmostCardInZone |
( |
const QList< QGraphicsItem * > & | items, |
|
|
CardZone * | zone ) |
|
static |
Finds the topmost card in a given zone, considering attachments and Z-order.
◆ findTopmostZone()
| CardZone * GameScene::findTopmostZone |
( |
const QList< QGraphicsItem * > & | items | ) |
|
|
static |
Finds the topmost card zone under the cursor.
◆ getViewportTransform
| QTransform GameScene::getViewportTransform |
( |
| ) |
const |
|
slot |
◆ getViewTransform
| QTransform GameScene::getViewTransform |
( |
| ) |
const |
|
slot |
◆ processViewSizeChange()
| void GameScene::processViewSizeChange |
( |
const QSize & | newSize | ) |
|
Handles view resize and redistributes player positions.
- Parameters
-
| newSize | New view size. |
| newSize | New view size. |
Steps:
- Compute minimum width per column from player items.
- Determine new scene width respecting aspect ratio.
- Resize columns and reposition players proportionally.
◆ rearrange()
| void GameScene::rearrange |
( |
| ) |
|
Recomputes the layout of players and the scene size.
Recomputes the layout of players and the scene size.
Steps:
- Collect active players who haven't conceded.
- Rotate player list based on first local player and rotation offset.
- Determine number of columns.
- Compute scene size and layout.
- Update toolbar height and scene rectangle.
- Adjust columns and player positions to match view size.
◆ registerAnimationItem()
Registers a card for animation updates.
◆ removePlayer()
| void GameScene::removePlayer |
( |
Player * | player | ) |
|
Removes a player from the scene.
- Parameters
-
Closes any zone views associated with the player and recomputes layout.
◆ removeZoneView
Removes a zone view widget from the scene.
Removes a zone view widget from the scene.
- Parameters
-
◆ resizeColumnsAndPlayers()
| void GameScene::resizeColumnsAndPlayers |
( |
const QList< qreal > & | minWidthByColumn, |
|
|
qreal | newWidth ) |
Resizes columns and distributes extra width to players.
- Parameters
-
| minWidthByColumn | Minimum widths per column. |
| newWidth | Total scene width. |
| minWidthByColumn | Minimum widths per column. |
| newWidth | Total scene width. |
Extra width is distributed evenly across columns. Each player item is notified to adjust internal layout for the new column width.
◆ resizeRubberBand()
| void GameScene::resizeRubberBand |
( |
const QPointF & | cursorPoint | ) |
|
◆ 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
-
| players | Original list of players. |
| firstPlayerIndex | Index of first local player. |
- Returns
- Rotated list.
- Parameters
-
| players | Original list of players. |
| firstPlayerIndex | Index of first local player. |
- Returns
- Rotated list.
Applies rotation offset and ensures the list wraps correctly.
◆ sigResizeRubberBand
| void GameScene::sigResizeRubberBand |
( |
const QPointF & | cursorPoint | ) |
|
|
signal |
◆ sigStartRubberBand
| void GameScene::sigStartRubberBand |
( |
const QPointF & | selectionOrigin | ) |
|
|
signal |
◆ sigStopRubberBand
| void GameScene::sigStopRubberBand |
( |
| ) |
|
|
signal |
◆ startRubberBand()
| void GameScene::startRubberBand |
( |
const QPointF & | selectionOrigin | ) |
|
◆ stopRubberBand()
| void GameScene::stopRubberBand |
( |
| ) |
|
◆ 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
-
| player | Player owning the zone. |
| zoneName | Name of the zone. |
| numberCards | Number of cards visible in the view. |
| isReversed | Whether 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.
◆ unregisterAnimationItem()
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
-
| scenePos | Scene position of the cursor. |
◆ updateHoveredCard()
| void GameScene::updateHoveredCard |
( |
CardItem * | newCard | ) |
|
Updates hovered card highlighting.
◆ animationTimer
| QBasicTimer* GameScene::animationTimer |
|
private |
Timer for card animations.
◆ cardsToAnimate
| QSet<CardItem *> GameScene::cardsToAnimate |
|
private |
Cards currently animating.
◆ hoveredCard
| QPointer<CardItem> GameScene::hoveredCard |
|
private |
◆ phasesToolbar
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
All player graphics items.
◆ playersByColumn
Players organized by column.
◆ viewSize
| QSize GameScene::viewSize |
|
private |
◆ zoneViews
Active zone view widgets.
The documentation for this class was generated from the following files: