mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-28 00:42:19 -07:00
extract getOverlayColor() to AbstractCounter for shared fill+hover styling and Use server-provided color and radius for tax counters
This commit is contained in:
parent
eeae205f51
commit
c8ed9835bd
5 changed files with 27 additions and 18 deletions
|
|
@ -90,6 +90,19 @@ void AbstractCounter::setValue(int _value)
|
||||||
update();
|
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)
|
void AbstractCounter::setActive(bool _active)
|
||||||
{
|
{
|
||||||
active = _active;
|
active = _active;
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,14 @@ protected:
|
||||||
bool hovered = false;
|
bool hovered = false;
|
||||||
bool useNameForShortcut;
|
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 mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
||||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
|
||||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,9 @@
|
||||||
|
|
||||||
static constexpr qreal CORNER_RADIUS = 4.0;
|
static constexpr qreal CORNER_RADIUS = 4.0;
|
||||||
static constexpr qreal FONT_SIZE_RATIO = 0.6;
|
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)
|
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);
|
setCacheMode(DeviceCoordinateCache);
|
||||||
setAcceptHoverEvents(true);
|
setAcceptHoverEvents(true);
|
||||||
|
|
@ -36,10 +33,8 @@ void CommanderTaxCounter::paint(QPainter *painter,
|
||||||
|
|
||||||
QRectF rect = boundingRect().adjusted(1, 1, -1, -1);
|
QRectF rect = boundingRect().adjusted(1, 1, -1, -1);
|
||||||
|
|
||||||
QColor bgColor = hovered ? OVERLAY_BG_HOVERED : OVERLAY_BG_NORMAL;
|
|
||||||
|
|
||||||
painter->setPen(Qt::NoPen);
|
painter->setPen(Qt::NoPen);
|
||||||
painter->setBrush(bgColor);
|
painter->setBrush(getOverlayColor());
|
||||||
painter->drawRoundedRect(rect, CORNER_RADIUS, CORNER_RADIUS);
|
painter->drawRoundedRect(rect, CORNER_RADIUS, CORNER_RADIUS);
|
||||||
|
|
||||||
QFont f = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
|
QFont f = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
|
||||||
|
|
|
||||||
|
|
@ -11,14 +11,11 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @namespace TaxCounterSizes
|
* @namespace TaxCounterSizes
|
||||||
* @brief Size constants for commander tax counter layout.
|
* @brief Layout constants for commander tax counters.
|
||||||
*/
|
*/
|
||||||
namespace TaxCounterSizes
|
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 */
|
/** @brief Margin around and between tax counter icons */
|
||||||
constexpr int TAX_COUNTER_MARGIN = 2;
|
constexpr int TAX_COUNTER_MARGIN = 2;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -165,11 +165,9 @@ void CommandZone::unregisterTaxCounter(AbstractCounter *counter)
|
||||||
|
|
||||||
void CommandZone::rearrangeTaxCounters()
|
void CommandZone::rearrangeTaxCounters()
|
||||||
{
|
{
|
||||||
int activeTaxCounterCount = 0;
|
qreal y = TaxCounterSizes::TAX_COUNTER_MARGIN;
|
||||||
|
|
||||||
for (AbstractCounter *ctr : taxCounters) {
|
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->setPos(TaxCounterSizes::TAX_COUNTER_MARGIN, y);
|
||||||
ctr->setZValue(ZValues::TAX_COUNTERS);
|
ctr->setZValue(ZValues::TAX_COUNTERS);
|
||||||
// Visibility is owned solely by AbstractCounter::setActive() (the counter's own flag),
|
// 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,
|
// (tax counters are graphics children of the zone). This function only handles layout,
|
||||||
// so it stacks and measures by isActive() alone.
|
// so it stacks and measures by isActive() alone.
|
||||||
if (ctr->isActive()) {
|
if (ctr->isActive()) {
|
||||||
++activeTaxCounterCount;
|
y += ctr->getRadius() + TaxCounterSizes::TAX_COUNTER_MARGIN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int minHeight = activeTaxCounterCount * (TaxCounterSizes::TAX_COUNTER_SIZE + TaxCounterSizes::TAX_COUNTER_MARGIN) +
|
setMinimumHeight(static_cast<int>(y));
|
||||||
TaxCounterSizes::TAX_COUNTER_MARGIN;
|
|
||||||
setMinimumHeight(minHeight);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandZone::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
|
void CommandZone::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue