From 631903d605096567bd48637877fc36fd11584601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Br=C3=BCbach?= Date: Thu, 11 Sep 2025 21:59:04 +0200 Subject: [PATCH] Take hand visibility into account when calculating bounding boxes. Took 34 minutes Took 7 minutes Took 8 seconds --- cockatrice/src/game/player/player.cpp | 8 +++++--- cockatrice/src/game/zones/hand_zone.cpp | 17 +++++++++++++---- cockatrice/src/game/zones/table_zone.cpp | 17 ++++++++++++++++- cockatrice/src/game/zones/table_zone.h | 1 + 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/cockatrice/src/game/player/player.cpp b/cockatrice/src/game/player/player.cpp index cd8cc70d5..9a4e9ddf1 100644 --- a/cockatrice/src/game/player/player.cpp +++ b/cockatrice/src/game/player/player.cpp @@ -30,10 +30,12 @@ #include Player::Player(const ServerInfo_User &info, int _id, bool _local, bool _judge, AbstractGame *_parent) - : QObject(_parent), game(_parent), playerInfo(new PlayerInfo(info, _id, _local, _judge)), - playerEventHandler(new PlayerEventHandler(this)), playerActions(new PlayerActions(this)), active(false), - conceded(false), handVisible(false), deck(nullptr), zoneId(0), dialogSemaphore(false) + : QObject(_parent), game(_parent), playerEventHandler(new PlayerEventHandler(this)), + playerActions(new PlayerActions(this)), active(false), conceded(false), handVisible(_local), deck(nullptr), + zoneId(0), dialogSemaphore(false) { + playerInfo = new PlayerInfo(info, _id, _local, _judge); + initializeZones(); playerMenu = new PlayerMenu(this); diff --git a/cockatrice/src/game/zones/hand_zone.cpp b/cockatrice/src/game/zones/hand_zone.cpp index 298926ff5..8f5dc109d 100644 --- a/cockatrice/src/game/zones/hand_zone.cpp +++ b/cockatrice/src/game/zones/hand_zone.cpp @@ -54,10 +54,19 @@ void HandZone::handleDropEvent(const QList &dragItems, QRectF HandZone::boundingRect() const { - if (SettingsCache::instance().getHorizontalHand()) - return QRectF(0, 0, width, CARD_HEIGHT + 10); - else - return QRectF(0, 0, 100, zoneHeight); + if (SettingsCache::instance().getHorizontalHand()) { + if (getLogic()->getPlayer()->getHandVisible()) { + return QRectF(0, 0, width, CARD_HEIGHT + 10); + } else { + return QRectF(0, 0, width, 0); + } + } else { + if (getLogic()->getPlayer()->getHandVisible()) { + return QRectF(0, 0, 100, zoneHeight); + } else { + return QRectF(0, 0, 0, zoneHeight); + } + } } void HandZone::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/) diff --git a/cockatrice/src/game/zones/table_zone.cpp b/cockatrice/src/game/zones/table_zone.cpp index 8505825f8..813dfb42b 100644 --- a/cockatrice/src/game/zones/table_zone.cpp +++ b/cockatrice/src/game/zones/table_zone.cpp @@ -30,7 +30,13 @@ TableZone::TableZone(TableZoneLogic *_logic, QGraphicsItem *parent) : SelectZone updateBg(); - height = MARGIN_TOP + MARGIN_BOTTOM + TABLEROWS * CARD_HEIGHT + (TABLEROWS - 1) * PADDING_Y; + connect(getLogic()->getPlayer(), &Player::handVisibleChanged, this, &TableZone::updateHeight); + + if (getLogic()->getPlayer()->getHandVisible()) { + height = MARGIN_TOP + MARGIN_BOTTOM + TABLEROWS * CARD_HEIGHT + (TABLEROWS - 1) * PADDING_Y; + } else { + height = MARGIN_TOP + MARGIN_BOTTOM + TABLEROWS * CARD_HEIGHT * PADDING_Y; + } width = MIN_WIDTH; currentMinimumWidth = width; @@ -43,6 +49,15 @@ void TableZone::updateBg() update(); } +void TableZone::updateHeight() +{ + if (getLogic()->getPlayer()->getHandVisible()) { + height = MARGIN_TOP + MARGIN_BOTTOM + TABLEROWS * CARD_HEIGHT + (TABLEROWS - 1) * PADDING_Y; + } else { + height = MARGIN_TOP + MARGIN_BOTTOM + TABLEROWS * CARD_HEIGHT * PADDING_Y; + } +} + QRectF TableZone::boundingRect() const { return QRectF(0, 0, width, height); diff --git a/cockatrice/src/game/zones/table_zone.h b/cockatrice/src/game/zones/table_zone.h index 155ac7ab3..5f6e8e09d 100644 --- a/cockatrice/src/game/zones/table_zone.h +++ b/cockatrice/src/game/zones/table_zone.h @@ -85,6 +85,7 @@ private slots: Loads in any found custom background and updates */ void updateBg(); + void updateHeight(); public slots: /**