extract getOverlayColor() to AbstractCounter for shared fill+hover styling and Use server-provided color and radius for tax counters

This commit is contained in:
DawnFire42 2026-08-10 15:08:27 -04:00
parent eeae205f51
commit c8ed9835bd
No known key found for this signature in database
GPG key ID: 24BB855EE2911B33
5 changed files with 27 additions and 18 deletions

View file

@ -90,6 +90,19 @@ void AbstractCounter::setValue(int _value)
update();
}
static constexpr int OVERLAY_ALPHA = 191;
static constexpr int HOVER_LIGHTEN_PERCENT = 130;
QColor AbstractCounter::getOverlayColor() const
{
QColor result = color;
result.setAlpha(OVERLAY_ALPHA);
if (hovered) {
result = result.lighter(HOVER_LIGHTEN_PERCENT);
}
return result;
}
void AbstractCounter::setActive(bool _active)
{
active = _active;

View file

@ -36,6 +36,14 @@ protected:
bool hovered = false;
bool useNameForShortcut;
/**
* @brief Returns the counter's color adjusted for overlay rendering.
*
* Applies semi-transparency and lightens the color when hovered.
* Use this for fill-based counters; SVG-based counters (GeneralCounter) bypass this.
*/
[[nodiscard]] QColor getOverlayColor() const;
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;

View file

@ -9,12 +9,9 @@
static constexpr qreal CORNER_RADIUS = 4.0;
static constexpr qreal FONT_SIZE_RATIO = 0.6;
static constexpr int OVERLAY_ALPHA = 191;
static const QColor OVERLAY_BG_NORMAL{40, 40, 40, OVERLAY_ALPHA};
static const QColor OVERLAY_BG_HOVERED{70, 70, 70, OVERLAY_ALPHA};
CommanderTaxCounter::CommanderTaxCounter(CounterState *state, PlayerLogic *player, QGraphicsItem *parent)
: AbstractCounter(state, player, false, false, parent), size(TaxCounterSizes::TAX_COUNTER_SIZE)
: AbstractCounter(state, player, false, false, parent), size(state->getRadius())
{
setCacheMode(DeviceCoordinateCache);
setAcceptHoverEvents(true);
@ -36,10 +33,8 @@ void CommanderTaxCounter::paint(QPainter *painter,
QRectF rect = boundingRect().adjusted(1, 1, -1, -1);
QColor bgColor = hovered ? OVERLAY_BG_HOVERED : OVERLAY_BG_NORMAL;
painter->setPen(Qt::NoPen);
painter->setBrush(bgColor);
painter->setBrush(getOverlayColor());
painter->drawRoundedRect(rect, CORNER_RADIUS, CORNER_RADIUS);
QFont f = QFontDatabase::systemFont(QFontDatabase::GeneralFont);

View file

@ -11,14 +11,11 @@
/**
* @namespace TaxCounterSizes
* @brief Size constants for commander tax counter layout.
* @brief Layout constants for commander tax counters.
*/
namespace TaxCounterSizes
{
/** @brief Size of commander tax counter icons (width and height) */
constexpr int TAX_COUNTER_SIZE = 24;
/** @brief Margin around and between tax counter icons */
constexpr int TAX_COUNTER_MARGIN = 2;

View file

@ -165,11 +165,9 @@ void CommandZone::unregisterTaxCounter(AbstractCounter *counter)
void CommandZone::rearrangeTaxCounters()
{
int activeTaxCounterCount = 0;
qreal y = TaxCounterSizes::TAX_COUNTER_MARGIN;
for (AbstractCounter *ctr : taxCounters) {
qreal y = TaxCounterSizes::TAX_COUNTER_MARGIN +
activeTaxCounterCount * (TaxCounterSizes::TAX_COUNTER_SIZE + TaxCounterSizes::TAX_COUNTER_MARGIN);
ctr->setPos(TaxCounterSizes::TAX_COUNTER_MARGIN, y);
ctr->setZValue(ZValues::TAX_COUNTERS);
// Visibility is owned solely by AbstractCounter::setActive() (the counter's own flag),
@ -177,13 +175,11 @@ void CommandZone::rearrangeTaxCounters()
// (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;
y += ctr->getRadius() + TaxCounterSizes::TAX_COUNTER_MARGIN;
}
}
int minHeight = activeTaxCounterCount * (TaxCounterSizes::TAX_COUNTER_SIZE + TaxCounterSizes::TAX_COUNTER_MARGIN) +
TaxCounterSizes::TAX_COUNTER_MARGIN;
setMinimumHeight(minHeight);
setMinimumHeight(static_cast<int>(y));
}
void CommandZone::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)