Create command zone conditionally based on game setting

This commit is contained in:
DawnFire42 2026-08-10 18:53:40 -04:00
parent cf9a4e9a02
commit 4d972f4df5
No known key found for this signature in database
GPG key ID: 24BB855EE2911B33
6 changed files with 22 additions and 53 deletions

View file

@ -33,7 +33,7 @@
PlayerLogic::PlayerLogic(const ServerInfo_User &info, int _id, bool _local, bool _judge, AbstractGame *_parent) 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)), : QObject(_parent), game(_parent), playerInfo(new PlayerInfo(info, _id, _local, _judge)),
playerEventHandler(new PlayerEventHandler(this)), playerActions(new PlayerActions(this)), active(false), 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(); initializeZones();
} }
@ -49,7 +49,9 @@ void PlayerLogic::initializeZones()
bool visibleHand = playerInfo->getLocalOrJudge() || bool visibleHand = playerInfo->getLocalOrJudge() ||
(game->getPlayerManager()->isSpectator() && game->getGameMetaInfo()->spectatorsOmniscient()); (game->getPlayerManager()->isSpectator() && game->getGameMetaInfo()->spectatorsOmniscient());
addZone(new HandZoneLogic(this, ZoneNames::HAND, false, false, visibleHand, this)); addZone(new HandZoneLogic(this, ZoneNames::HAND, false, false, visibleHand, this));
if (game->getGameMetaInfo()->proto().enable_command_zone()) {
addZone(new CommandZoneLogic(this, ZoneNames::COMMAND, true, false, true, this)); addZone(new CommandZoneLogic(this, ZoneNames::COMMAND, true, false, true, this));
}
} }
PlayerLogic::~PlayerLogic() PlayerLogic::~PlayerLogic()
@ -123,19 +125,7 @@ void PlayerLogic::processPlayerInfo(const ServerInfo_Player &info)
emit clearCustomZonesMenu(); emit clearCustomZonesMenu();
// Check if server has command zone by scanning the zone list
const int zoneListSize = info.zone_list_size(); 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) { for (int i = 0; i < zoneListSize; ++i) {
const ServerInfo_Zone &zoneInfo = info.zone_list(i); const ServerInfo_Zone &zoneInfo = info.zone_list(i);

View file

@ -89,8 +89,6 @@ signals:
void arrowDeleteRequested(int creatorId, int arrowId); void arrowDeleteRequested(int creatorId, int arrowId);
void arrowDeleted(int creatorId, int arrowId); void arrowDeleted(int creatorId, int arrowId);
void arrowsClearedLocally(); // fires on clear() and processPlayerInfo 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: public slots:
void setActive(bool _active); void setActive(bool _active);
@ -200,15 +198,15 @@ public:
} }
/** @brief Returns the command zone logic, or nullptr if not present. */ /** @brief Returns the command zone logic, or nullptr if not present. */
CommandZoneLogic *getCommandZone() CommandZoneLogic *getCommandZone() const
{ {
return qobject_cast<CommandZoneLogic *>(zones.value(ZoneNames::COMMAND)); return qobject_cast<CommandZoneLogic *>(zones.value(ZoneNames::COMMAND));
} }
/** @brief Whether the server confirmed command zone support for this game. */ /** @brief Whether this game has command zone support (determined at game creation). */
bool hasServerCommandZone() const bool hasCommandZone() const
{ {
return serverHasCommandZone; return getCommandZone() != nullptr;
} }
CounterState *addCounter(const ServerInfo_Counter &counter); CounterState *addCounter(const ServerInfo_Counter &counter);
@ -263,7 +261,6 @@ private:
QMap<int, CounterState *> counters; QMap<int, CounterState *> counters;
bool dialogSemaphore; bool dialogSemaphore;
bool serverHasCommandZone;
QList<CardItem *> cardsToDelete; QList<CardItem *> cardsToDelete;
}; };

View file

@ -55,11 +55,7 @@ MoveMenu::MoveMenu(PlayerGraphicsItem *player, QWidget *parent) : QMenu(tr("Move
addAction(aMoveToExile); addAction(aMoveToExile);
addSeparator(); addSeparator();
addAction(aMoveToCommandZone); addAction(aMoveToCommandZone);
aMoveToCommandZone->setVisible(player->getLogic()->hasCommandZone());
auto *playerLogic = player->getLogic();
auto updateCommandZoneVisibility = [this](bool has) { aMoveToCommandZone->setVisible(has); };
connect(playerLogic, &PlayerLogic::commandZoneSupportChanged, this, updateCommandZoneVisibility);
updateCommandZoneVisibility(playerLogic->hasServerCommandZone());
setShortcutsActive(); setShortcutsActive();

View file

@ -34,14 +34,11 @@ PlayerMenu::PlayerMenu(PlayerGraphicsItem *_player) : QObject(_player), player(_
if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) { if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) {
sideboardMenu = addManagedMenu<SideboardMenu>(player, playerMenu); sideboardMenu = addManagedMenu<SideboardMenu>(player, playerMenu);
if (player->getLogic()->hasCommandZone()) {
commandZoneMenu = addManagedMenu<CommandZoneMenu>(player, playerMenu); commandZoneMenu = addManagedMenu<CommandZoneMenu>(player, playerMenu);
auto updateCommandZoneMenuVisibility = [this](bool has) { } else {
if (commandZoneMenu) { commandZoneMenu = nullptr;
commandZoneMenu->menuAction()->setVisible(has);
} }
};
connect(player->getLogic(), &PlayerLogic::commandZoneSupportChanged, this, updateCommandZoneMenuVisibility);
updateCommandZoneMenuVisibility(player->getLogic()->hasServerCommandZone());
customZonesMenu = addManagedMenu<CustomZoneMenu>(player); customZonesMenu = addManagedMenu<CustomZoneMenu>(player);
playerMenu->addSeparator(); playerMenu->addSeparator();

View file

@ -66,9 +66,6 @@ PlayerGraphicsItem::PlayerGraphicsItem(PlayerLogic *_player) : player(_player)
connect(player, &PlayerLogic::addViewCustomZoneActionToCustomZoneMenu, this, connect(player, &PlayerLogic::addViewCustomZoneActionToCustomZoneMenu, this,
&PlayerGraphicsItem::onCustomZoneAdded); &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(); playerMenu->setMenusForGraphicItems();
@ -129,11 +126,14 @@ void PlayerGraphicsItem::initializeZones()
new HandZone(player->getHandZone(), static_cast<int>(tableZoneGraphicsItem->boundingRect().height()), this); new HandZone(player->getHandZone(), static_cast<int>(tableZoneGraphicsItem->boundingRect().height()), this);
connect(player->getPlayerActions(), &PlayerActions::requestSortHand, handZoneGraphicsItem, &HandZone::sortHand); connect(player->getPlayerActions(), &PlayerActions::requestSortHand, handZoneGraphicsItem, &HandZone::sortHand);
// Command zone // Command zone (only created for commander games)
commandZoneGraphicsItem = new CommandZone(player->getCommandZone(), ZoneSizes::COMMAND_ZONE_HEIGHT, this); if (auto *commandZoneLogic = player->getCommandZone()) {
commandZoneGraphicsItem->setVisible(false); commandZoneGraphicsItem = new CommandZone(commandZoneLogic, ZoneSizes::COMMAND_ZONE_HEIGHT, this);
connect(commandZoneGraphicsItem, &CommandZone::minimizedChanged, this, &PlayerGraphicsItem::rearrangeZones); connect(commandZoneGraphicsItem, &CommandZone::minimizedChanged, this, &PlayerGraphicsItem::rearrangeZones);
connect(commandZoneGraphicsItem, &CommandZone::effectiveHeightChanged, this, &PlayerGraphicsItem::rearrangeZones); connect(commandZoneGraphicsItem, &CommandZone::effectiveHeightChanged, this,
&PlayerGraphicsItem::rearrangeZones);
zoneGraphicsItems.insert(commandZoneLogic->getName(), commandZoneGraphicsItem);
}
connect(handZoneGraphicsItem->getLogic(), &HandZoneLogic::cardCountChanged, handCounter, connect(handZoneGraphicsItem->getLogic(), &HandZoneLogic::cardCountChanged, handCounter,
&HandCounter::updateNumber); &HandCounter::updateNumber);
@ -146,7 +146,6 @@ void PlayerGraphicsItem::initializeZones()
zoneGraphicsItems.insert(player->getTableZone()->getName(), tableZoneGraphicsItem); zoneGraphicsItems.insert(player->getTableZone()->getName(), tableZoneGraphicsItem);
zoneGraphicsItems.insert(player->getStackZone()->getName(), stackZoneGraphicsItem); zoneGraphicsItems.insert(player->getStackZone()->getName(), stackZoneGraphicsItem);
zoneGraphicsItems.insert(player->getHandZone()->getName(), handZoneGraphicsItem); zoneGraphicsItems.insert(player->getHandZone()->getName(), handZoneGraphicsItem);
zoneGraphicsItems.insert(player->getCommandZone()->getName(), commandZoneGraphicsItem);
} }
void PlayerGraphicsItem::onCustomZoneAdded(QString customZoneName) void PlayerGraphicsItem::onCustomZoneAdded(QString customZoneName)
@ -397,11 +396,3 @@ void PlayerGraphicsItem::positionCommandAndStackZones(const QPointF &base)
} }
stackZoneGraphicsItem->setPos(base.x(), base.y() + (commandZoneVisible ? totalCommandZoneHeight() : 0)); stackZoneGraphicsItem->setPos(base.x(), base.y() + (commandZoneVisible ? totalCommandZoneHeight() : 0));
} }
void PlayerGraphicsItem::setCommandZoneVisible(bool visible)
{
if (commandZoneGraphicsItem) {
commandZoneGraphicsItem->setVisible(visible);
}
rearrangeZones();
}

View file

@ -133,8 +133,6 @@ public slots:
void onCounterRemoved(int counterId); void onCounterRemoved(int counterId);
void rearrangeCounters(); void rearrangeCounters();
void retranslateUi(); void retranslateUi();
/** @brief Shows or hides the command zone and rearranges dependent zones. */
void setCommandZoneVisible(bool visible);
signals: signals:
void sizeChanged(); void sizeChanged();