diff --git a/cockatrice/src/game/player/player_logic.cpp b/cockatrice/src/game/player/player_logic.cpp index 9e88f7ee3..715777c65 100644 --- a/cockatrice/src/game/player/player_logic.cpp +++ b/cockatrice/src/game/player/player_logic.cpp @@ -33,7 +33,7 @@ PlayerLogic::PlayerLogic(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), zoneId(0), dialogSemaphore(false), serverHasCommandZone(false) + conceded(false), zoneId(0), dialogSemaphore(false) { initializeZones(); } @@ -49,7 +49,9 @@ void PlayerLogic::initializeZones() bool visibleHand = playerInfo->getLocalOrJudge() || (game->getPlayerManager()->isSpectator() && game->getGameMetaInfo()->spectatorsOmniscient()); addZone(new HandZoneLogic(this, ZoneNames::HAND, false, false, visibleHand, this)); - addZone(new CommandZoneLogic(this, ZoneNames::COMMAND, true, false, true, this)); + if (game->getGameMetaInfo()->proto().enable_command_zone()) { + addZone(new CommandZoneLogic(this, ZoneNames::COMMAND, true, false, true, this)); + } } PlayerLogic::~PlayerLogic() @@ -123,19 +125,7 @@ void PlayerLogic::processPlayerInfo(const ServerInfo_Player &info) emit clearCustomZonesMenu(); - // Check if server has command zone by scanning the zone list const int zoneListSize = info.zone_list_size(); - bool foundCommandZone = false; - for (int i = 0; i < zoneListSize; ++i) { - if (QString::fromStdString(info.zone_list(i).name()) == ZoneNames::COMMAND) { - foundCommandZone = true; - break; - } - } - if (serverHasCommandZone != foundCommandZone) { - serverHasCommandZone = foundCommandZone; - emit commandZoneSupportChanged(foundCommandZone); - } for (int i = 0; i < zoneListSize; ++i) { const ServerInfo_Zone &zoneInfo = info.zone_list(i); diff --git a/cockatrice/src/game/player/player_logic.h b/cockatrice/src/game/player/player_logic.h index 16c86d16f..a98446c9e 100644 --- a/cockatrice/src/game/player/player_logic.h +++ b/cockatrice/src/game/player/player_logic.h @@ -89,8 +89,6 @@ signals: void arrowDeleteRequested(int creatorId, int arrowId); void arrowDeleted(int creatorId, int arrowId); void arrowsClearedLocally(); // fires on clear() and processPlayerInfo - /** @brief Emitted when server command zone support is detected or lost (e.g. on game join or reconnect). */ - void commandZoneSupportChanged(bool hasCommandZone); public slots: void setActive(bool _active); @@ -200,15 +198,15 @@ public: } /** @brief Returns the command zone logic, or nullptr if not present. */ - CommandZoneLogic *getCommandZone() + CommandZoneLogic *getCommandZone() const { return qobject_cast(zones.value(ZoneNames::COMMAND)); } - /** @brief Whether the server confirmed command zone support for this game. */ - bool hasServerCommandZone() const + /** @brief Whether this game has command zone support (determined at game creation). */ + bool hasCommandZone() const { - return serverHasCommandZone; + return getCommandZone() != nullptr; } CounterState *addCounter(const ServerInfo_Counter &counter); @@ -263,7 +261,6 @@ private: QMap counters; bool dialogSemaphore; - bool serverHasCommandZone; QList cardsToDelete; }; diff --git a/cockatrice/src/game_graphics/player/menu/move_menu.cpp b/cockatrice/src/game_graphics/player/menu/move_menu.cpp index a56b09da8..d0f0b1dfe 100644 --- a/cockatrice/src/game_graphics/player/menu/move_menu.cpp +++ b/cockatrice/src/game_graphics/player/menu/move_menu.cpp @@ -55,11 +55,7 @@ MoveMenu::MoveMenu(PlayerGraphicsItem *player, QWidget *parent) : QMenu(tr("Move addAction(aMoveToExile); addSeparator(); addAction(aMoveToCommandZone); - - auto *playerLogic = player->getLogic(); - auto updateCommandZoneVisibility = [this](bool has) { aMoveToCommandZone->setVisible(has); }; - connect(playerLogic, &PlayerLogic::commandZoneSupportChanged, this, updateCommandZoneVisibility); - updateCommandZoneVisibility(playerLogic->hasServerCommandZone()); + aMoveToCommandZone->setVisible(player->getLogic()->hasCommandZone()); setShortcutsActive(); diff --git a/cockatrice/src/game_graphics/player/menu/player_menu.cpp b/cockatrice/src/game_graphics/player/menu/player_menu.cpp index afd3e8aca..c9929abf8 100644 --- a/cockatrice/src/game_graphics/player/menu/player_menu.cpp +++ b/cockatrice/src/game_graphics/player/menu/player_menu.cpp @@ -34,14 +34,11 @@ PlayerMenu::PlayerMenu(PlayerGraphicsItem *_player) : QObject(_player), player(_ if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) { sideboardMenu = addManagedMenu(player, playerMenu); - commandZoneMenu = addManagedMenu(player, playerMenu); - auto updateCommandZoneMenuVisibility = [this](bool has) { - if (commandZoneMenu) { - commandZoneMenu->menuAction()->setVisible(has); - } - }; - connect(player->getLogic(), &PlayerLogic::commandZoneSupportChanged, this, updateCommandZoneMenuVisibility); - updateCommandZoneMenuVisibility(player->getLogic()->hasServerCommandZone()); + if (player->getLogic()->hasCommandZone()) { + commandZoneMenu = addManagedMenu(player, playerMenu); + } else { + commandZoneMenu = nullptr; + } customZonesMenu = addManagedMenu(player); playerMenu->addSeparator(); diff --git a/cockatrice/src/game_graphics/player/player_graphics_item.cpp b/cockatrice/src/game_graphics/player/player_graphics_item.cpp index 315ba4082..48174e6c7 100644 --- a/cockatrice/src/game_graphics/player/player_graphics_item.cpp +++ b/cockatrice/src/game_graphics/player/player_graphics_item.cpp @@ -66,9 +66,6 @@ PlayerGraphicsItem::PlayerGraphicsItem(PlayerLogic *_player) : player(_player) connect(player, &PlayerLogic::addViewCustomZoneActionToCustomZoneMenu, this, &PlayerGraphicsItem::onCustomZoneAdded); - connect(player, &PlayerLogic::commandZoneSupportChanged, this, &PlayerGraphicsItem::setCommandZoneVisible); - // Sync initial state in case processPlayerInfo already ran before this connection. - setCommandZoneVisible(player->hasServerCommandZone()); playerMenu->setMenusForGraphicItems(); @@ -129,11 +126,14 @@ void PlayerGraphicsItem::initializeZones() new HandZone(player->getHandZone(), static_cast(tableZoneGraphicsItem->boundingRect().height()), this); connect(player->getPlayerActions(), &PlayerActions::requestSortHand, handZoneGraphicsItem, &HandZone::sortHand); - // Command zone - commandZoneGraphicsItem = new CommandZone(player->getCommandZone(), ZoneSizes::COMMAND_ZONE_HEIGHT, this); - commandZoneGraphicsItem->setVisible(false); - connect(commandZoneGraphicsItem, &CommandZone::minimizedChanged, this, &PlayerGraphicsItem::rearrangeZones); - connect(commandZoneGraphicsItem, &CommandZone::effectiveHeightChanged, this, &PlayerGraphicsItem::rearrangeZones); + // Command zone (only created for commander games) + if (auto *commandZoneLogic = player->getCommandZone()) { + commandZoneGraphicsItem = new CommandZone(commandZoneLogic, ZoneSizes::COMMAND_ZONE_HEIGHT, this); + connect(commandZoneGraphicsItem, &CommandZone::minimizedChanged, this, &PlayerGraphicsItem::rearrangeZones); + connect(commandZoneGraphicsItem, &CommandZone::effectiveHeightChanged, this, + &PlayerGraphicsItem::rearrangeZones); + zoneGraphicsItems.insert(commandZoneLogic->getName(), commandZoneGraphicsItem); + } connect(handZoneGraphicsItem->getLogic(), &HandZoneLogic::cardCountChanged, handCounter, &HandCounter::updateNumber); @@ -146,7 +146,6 @@ void PlayerGraphicsItem::initializeZones() zoneGraphicsItems.insert(player->getTableZone()->getName(), tableZoneGraphicsItem); zoneGraphicsItems.insert(player->getStackZone()->getName(), stackZoneGraphicsItem); zoneGraphicsItems.insert(player->getHandZone()->getName(), handZoneGraphicsItem); - zoneGraphicsItems.insert(player->getCommandZone()->getName(), commandZoneGraphicsItem); } void PlayerGraphicsItem::onCustomZoneAdded(QString customZoneName) @@ -397,11 +396,3 @@ void PlayerGraphicsItem::positionCommandAndStackZones(const QPointF &base) } stackZoneGraphicsItem->setPos(base.x(), base.y() + (commandZoneVisible ? totalCommandZoneHeight() : 0)); } - -void PlayerGraphicsItem::setCommandZoneVisible(bool visible) -{ - if (commandZoneGraphicsItem) { - commandZoneGraphicsItem->setVisible(visible); - } - rearrangeZones(); -} diff --git a/cockatrice/src/game_graphics/player/player_graphics_item.h b/cockatrice/src/game_graphics/player/player_graphics_item.h index 3338f19b0..9561792e5 100644 --- a/cockatrice/src/game_graphics/player/player_graphics_item.h +++ b/cockatrice/src/game_graphics/player/player_graphics_item.h @@ -133,8 +133,6 @@ public slots: void onCounterRemoved(int counterId); void rearrangeCounters(); void retranslateUi(); - /** @brief Shows or hides the command zone and rearranges dependent zones. */ - void setCommandZoneVisible(bool visible); signals: void sizeChanged();