mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-28 00:42:19 -07:00
Create command zone conditionally based on game setting
This commit is contained in:
parent
cf9a4e9a02
commit
4d972f4df5
6 changed files with 22 additions and 53 deletions
|
|
@ -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));
|
||||||
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()
|
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);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
||||||
commandZoneMenu = addManagedMenu<CommandZoneMenu>(player, playerMenu);
|
if (player->getLogic()->hasCommandZone()) {
|
||||||
auto updateCommandZoneMenuVisibility = [this](bool has) {
|
commandZoneMenu = addManagedMenu<CommandZoneMenu>(player, playerMenu);
|
||||||
if (commandZoneMenu) {
|
} else {
|
||||||
commandZoneMenu->menuAction()->setVisible(has);
|
commandZoneMenu = nullptr;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
connect(player->getLogic(), &PlayerLogic::commandZoneSupportChanged, this, updateCommandZoneMenuVisibility);
|
|
||||||
updateCommandZoneMenuVisibility(player->getLogic()->hasServerCommandZone());
|
|
||||||
|
|
||||||
customZonesMenu = addManagedMenu<CustomZoneMenu>(player);
|
customZonesMenu = addManagedMenu<CustomZoneMenu>(player);
|
||||||
playerMenu->addSeparator();
|
playerMenu->addSeparator();
|
||||||
|
|
|
||||||
|
|
@ -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();
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue