Reconcile tax counter visibility ownership and harden tax log formatting

- Make AbstractCounter::setActive() the sole owner of counter visibility; document the contract.
  - Drop the redundant setVisible() from CommandZone::rearrangeTaxCounters(); it now only lays out by isActive().
  - Format tax log lines with a single atomic 4-arg arg() instead of mixing string and int overloads.
This commit is contained in:
DawnFire42 2026-06-16 16:36:12 -04:00
parent a9793bc006
commit 3fea1246f1
No known key found for this signature in database
GPG key ID: 24BB855EE2911B33
3 changed files with 17 additions and 7 deletions

View file

@ -113,7 +113,13 @@ public:
/**
* @brief Sets the active state of this counter.
* When inactive, the counter is hidden via setVisible(false).
*
* This is the sole owner of the counter's own visibility flag: active maps directly to
* setVisible(_active). For counters nested in another item (e.g. tax counters parented to
* the command zone), Qt AND-s this flag with the parent's visibility, so an active counter
* inside a hidden zone still does not render. Container layout code must therefore not set
* visibility itself; it only positions counters and may read isActive().
*
* @param _active True to show and enable the counter, false to hide it
*/
virtual void setActive(bool _active);

View file

@ -680,12 +680,15 @@ void MessageLogWidget::logSetCounter(PlayerLogic *player, QString counterName, i
QString playerName = sanitizeHtml(player->getPlayerInfo()->getName());
QString valueStr = QString("<font class=\"blue\">%1</font>").arg(value);
int delta = value - oldValue;
QString deltaStr = QString::number(delta);
QString counterDisplayName = TranslateCounterName::getDisplayName(counterName);
QString taxLabel = QString("<font class=\"blue\">%1</font>").arg(sanitizeHtml(counterDisplayName));
if (value > oldValue) {
appendHtmlServerMessage(tr("%1 increases %2 to %3 (+%4).").arg(playerName, taxLabel, valueStr).arg(delta));
// delta > 0 here; the format string supplies the leading '+'
appendHtmlServerMessage(tr("%1 increases %2 to %3 (+%4).").arg(playerName, taxLabel, valueStr, deltaStr));
} else {
appendHtmlServerMessage(tr("%1 decreases %2 to %3 (%4).").arg(playerName, taxLabel, valueStr).arg(delta));
// delta < 0 here; deltaStr already carries the '-' sign
appendHtmlServerMessage(tr("%1 decreases %2 to %3 (%4).").arg(playerName, taxLabel, valueStr, deltaStr));
}
return;
}

View file

@ -150,7 +150,6 @@ void CommandZone::registerTaxCounter(AbstractCounter *counter)
void CommandZone::rearrangeTaxCounters()
{
bool commandZoneVisible = isVisible();
int activeTaxCounterCount = 0;
for (AbstractCounter *ctr : taxCounters) {
@ -158,9 +157,11 @@ void CommandZone::rearrangeTaxCounters()
activeTaxCounterCount * (TaxCounterSizes::TAX_COUNTER_SIZE + TaxCounterSizes::TAX_COUNTER_MARGIN);
ctr->setPos(TaxCounterSizes::TAX_COUNTER_MARGIN, y);
ctr->setZValue(ZValues::TAX_COUNTERS);
bool visible = commandZoneVisible && ctr->isActive();
ctr->setVisible(visible);
if (visible) {
// Visibility is owned solely by AbstractCounter::setActive() (the counter's own flag),
// which Qt AND-s with this CommandZone's visibility via child-visibility propagation
// (tax counters are graphics children of the zone). This function only handles layout,
// so it stacks and measures by isActive() alone.
if (ctr->isActive()) {
++activeTaxCounterCount;
}
}