Code cleanup

- Add missing isCommandZoneCounterBlocked check to cmdSetCounterActive
  - Revert accidental deck view layout change from b4057a86
  - Fix duplicate @param in playSelectedCardsImpl doc
  - Add null check for PlayerLogic in CommandZoneMenu constructor
  - Add index bounds check in CommandZone handleDropEvent
  - Add index bounds check in StackZone handleDropEvent
  - Add ownership comment for tax counter widget creation
  - Add command zone to zoneGraphicsItems map
  - Conditionally show command zone menu item based on server support
  - Remove layer-violating includes from player_logic.cpp
  - Fix tax counter increment (1 per cast, not 2)
  - Add getTaxCounterIfActive() helper to PlayerGraphicsItem
This commit is contained in:
DawnFire42 2026-06-09 15:29:22 -04:00
parent 07229c85bf
commit be9b4137d7
No known key found for this signature in database
GPG key ID: 24BB855EE2911B33
13 changed files with 45 additions and 29 deletions

View file

@ -165,13 +165,11 @@ CardMenu::CardMenu(PlayerGraphicsItem *_player, const CardItem *_card, bool _sho
if (writeableCard) {
addAction(aPlay);
AbstractCounter *cmdTax = player->getCounterWidget(CounterIds::CommanderTax);
if (cmdTax && cmdTax->isActive()) {
if (player->getTaxCounterIfActive(CounterIds::CommanderTax)) {
addAction(aPlayAndIncreaseTax);
}
AbstractCounter *partnerTax = player->getCounterWidget(CounterIds::PartnerTax);
if (partnerTax && partnerTax->isActive()) {
if (player->getTaxCounterIfActive(CounterIds::PartnerTax)) {
addAction(aPlayAndIncreasePartnerTax);
}

View file

@ -26,7 +26,8 @@ CommandZoneMenu::CommandZoneMenu(PlayerGraphicsItem *_player, QMenu *playerMenu)
}
});
if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) {
PlayerLogic *logic = player->getLogic();
if (logic && logic->getPlayerInfo()->getLocalOrJudge()) {
addAction(aViewZone);
addSeparator();
@ -117,32 +118,29 @@ void CommandZoneMenu::actToggleMinimized()
void CommandZoneMenu::updateTaxCounterActionStates()
{
AbstractCounter *cmdTax = player->getCounterWidget(CounterIds::CommanderTax);
bool cmdActive = cmdTax != nullptr && cmdTax->isActive();
AbstractCounter *partnerTax = player->getCounterWidget(CounterIds::PartnerTax);
bool partnerActive = partnerTax != nullptr && partnerTax->isActive();
AbstractCounter *cmdTax = player->getTaxCounterIfActive(CounterIds::CommanderTax);
AbstractCounter *partnerTax = player->getTaxCounterIfActive(CounterIds::PartnerTax);
if (aIncreaseCommanderTax) {
aIncreaseCommanderTax->setVisible(cmdActive);
aIncreaseCommanderTax->setVisible(cmdTax != nullptr);
}
if (aDecreaseCommanderTax) {
aDecreaseCommanderTax->setVisible(cmdActive);
aDecreaseCommanderTax->setVisible(cmdTax != nullptr);
}
if (aToggleCommanderTaxCounter) {
aToggleCommanderTaxCounter->setText(cmdActive ? tr("&Remove Commander Tax") : tr("&Add Commander Tax"));
aToggleCommanderTaxCounter->setVisible(!cmdActive || (cmdTax && cmdTax->getValue() == 0));
aToggleCommanderTaxCounter->setText(cmdTax ? tr("&Remove Commander Tax") : tr("&Add Commander Tax"));
aToggleCommanderTaxCounter->setVisible(!cmdTax || cmdTax->getValue() == 0);
}
if (aIncreasePartnerTax) {
aIncreasePartnerTax->setVisible(partnerActive);
aIncreasePartnerTax->setVisible(partnerTax != nullptr);
}
if (aDecreasePartnerTax) {
aDecreasePartnerTax->setVisible(partnerActive);
aDecreasePartnerTax->setVisible(partnerTax != nullptr);
}
if (aTogglePartnerTaxCounter) {
aTogglePartnerTaxCounter->setText(partnerActive ? tr("R&emove Partner Tax") : tr("&Add Partner Tax"));
aTogglePartnerTaxCounter->setVisible(!partnerActive || (partnerTax && partnerTax->getValue() == 0));
aTogglePartnerTaxCounter->setText(partnerTax ? tr("R&emove Partner Tax") : tr("&Add Partner Tax"));
aTogglePartnerTaxCounter->setVisible(!partnerTax || partnerTax->getValue() == 0);
}
}

View file

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

View file

@ -143,6 +143,7 @@ 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)
@ -203,6 +204,8 @@ void PlayerGraphicsItem::onCounterAdded(CounterState *state)
qWarning() << "Cannot create tax counter" << state->getName() << "- command zone not available";
return;
}
// Qt parent (commandZoneGraphicsItem) owns widget; counterWidgets map holds reference
// for lookup; CommandZone::registerTaxCounter connects QObject::destroyed for cleanup
widget = new CommanderTaxCounter(state, player, commandZoneGraphicsItem);
widget->setActive(state->isActive());
commandZoneGraphicsItem->registerTaxCounter(widget);
@ -267,6 +270,12 @@ QList<AbstractCounter *> PlayerGraphicsItem::getTaxCounterWidgets() const
return result;
}
AbstractCounter *PlayerGraphicsItem::getTaxCounterIfActive(int counterId) const
{
AbstractCounter *counter = getCounterWidget(counterId);
return (counter && counter->isActive()) ? counter : nullptr;
}
void PlayerGraphicsItem::rearrangeZones()
{
auto base = QPointF(CardDimensions::HEIGHT_F + counterAreaWidth + 15, 0);

View file

@ -125,6 +125,8 @@ public:
}
/** @brief Returns all tax counter widgets (commander tax and partner tax). */
[[nodiscard]] QList<AbstractCounter *> getTaxCounterWidgets() const;
/** @brief Returns the tax counter if it exists and is active, or nullptr otherwise. */
[[nodiscard]] AbstractCounter *getTaxCounterIfActive(int counterId) const;
public slots:
void onPlayerActiveChanged(bool _active);

View file

@ -96,7 +96,8 @@ void CommandZone::handleDropEvent(const QList<CardDragItem *> &dragItems,
// Same-zone no-op: don't move a card onto itself
const auto &cards = getLogic()->getCards();
if (!cards.isEmpty() && startZone == getLogic() && cards.at(index)->getId() == dragItems.at(0)->getId()) {
if (!cards.isEmpty() && index < cards.size() && startZone == getLogic() &&
cards.at(index)->getId() == dragItems.at(0)->getId()) {
return;
}

View file

@ -51,7 +51,8 @@ void StackZone::handleDropEvent(const QList<CardDragItem *> &dragItems,
// Same-zone no-op: don't move a card onto itself
const auto &cards = getLogic()->getCards();
if (!cards.isEmpty() && startZone == getLogic() && cards.at(index)->getId() == dragItems.at(0)->getId()) {
if (!cards.isEmpty() && index < cards.size() && startZone == getLogic() &&
cards.at(index)->getId() == dragItems.at(0)->getId()) {
return;
}