refactor(z-values): replace magic Z-value numbers with ZValues constants

Magic numbers like 2000000007 are impossible to understand without
context. Named constants (ZValues::DRAG_ITEM) are self-documenting.

This intentionally renumbers overlay Z-values to use a cleaner offset
sequence. The relative stacking order is preserved, which is what
matters for correct rendering.

Each consumer now includes z_values.h and uses semantic constants
instead of magic numbers.
This commit is contained in:
DawnFire42 2026-03-02 01:28:18 -05:00
parent d22fa8b447
commit 652ca041b4
No known key found for this signature in database
GPG key ID: 24BB855EE2911B33
4 changed files with 12 additions and 8 deletions

View file

@ -1,6 +1,7 @@
#include "abstract_card_drag_item.h" #include "abstract_card_drag_item.h"
#include "../../client/settings/cache_settings.h" #include "../../client/settings/cache_settings.h"
#include "../z_values.h"
#include <QCursor> #include <QCursor>
#include <QDebug> #include <QDebug>
@ -18,13 +19,13 @@ AbstractCardDragItem::AbstractCardDragItem(AbstractCardItem *_item,
{ {
if (parentDrag) { if (parentDrag) {
parentDrag->addChildDrag(this); parentDrag->addChildDrag(this);
setZValue(2000000007 + hotSpot.x() * 1000000 + hotSpot.y() * 1000 + 1000); setZValue(ZValues::childDragZValue(hotSpot.x(), hotSpot.y()));
connect(parentDrag, &QObject::destroyed, this, &AbstractCardDragItem::deleteLater); connect(parentDrag, &QObject::destroyed, this, &AbstractCardDragItem::deleteLater);
} else { } else {
hotSpot = QPointF{qBound(0.0, hotSpot.x(), static_cast<qreal>(CARD_WIDTH - 1)), hotSpot = QPointF{qBound(0.0, hotSpot.x(), static_cast<qreal>(CARD_WIDTH - 1)),
qBound(0.0, hotSpot.y(), static_cast<qreal>(CARD_HEIGHT - 1))}; qBound(0.0, hotSpot.y(), static_cast<qreal>(CARD_HEIGHT - 1))};
setCursor(Qt::ClosedHandCursor); setCursor(Qt::ClosedHandCursor);
setZValue(2000000007); setZValue(ZValues::DRAG_ITEM);
} }
if (item->getTapped()) if (item->getTapped())
setTransform(QTransform() setTransform(QTransform()

View file

@ -3,6 +3,7 @@
#include "../../client/settings/cache_settings.h" #include "../../client/settings/cache_settings.h"
#include "../../interface/card_picture_loader/card_picture_loader.h" #include "../../interface/card_picture_loader/card_picture_loader.h"
#include "../game_scene.h" #include "../game_scene.h"
#include "../z_values.h"
#include <QCursor> #include <QCursor>
#include <QGraphicsScene> #include <QGraphicsScene>
@ -215,7 +216,7 @@ void AbstractCardItem::setHovered(bool _hovered)
if (_hovered) if (_hovered)
processHoverEvent(); processHoverEvent();
isHovered = _hovered; isHovered = _hovered;
setZValue(_hovered ? 2000000004 : realZValue); setZValue(_hovered ? ZValues::HOVERED_CARD : realZValue);
setScale(_hovered && SettingsCache::instance().getScaleCards() ? 1.1 : 1); setScale(_hovered && SettingsCache::instance().getScaleCards() ? 1.1 : 1);
setTransformOriginPoint(_hovered ? CARD_WIDTH / 2 : 0, _hovered ? CARD_HEIGHT / 2 : 0); setTransformOriginPoint(_hovered ? CARD_WIDTH / 2 : 0, _hovered ? CARD_HEIGHT / 2 : 0);
update(); update();

View file

@ -5,6 +5,7 @@
#include "../player/player.h" #include "../player/player.h"
#include "../player/player_actions.h" #include "../player/player_actions.h"
#include "../player/player_target.h" #include "../player/player_target.h"
#include "../z_values.h"
#include "../zones/card_zone.h" #include "../zones/card_zone.h"
#include "card_item.h" #include "card_item.h"
@ -23,7 +24,7 @@ ArrowItem::ArrowItem(Player *_player, int _id, ArrowTarget *_startItem, ArrowTar
: QGraphicsItem(), player(_player), id(_id), startItem(_startItem), targetItem(_targetItem), targetLocked(false), : QGraphicsItem(), player(_player), id(_id), startItem(_startItem), targetItem(_targetItem), targetLocked(false),
color(_color), fullColor(true) color(_color), fullColor(true)
{ {
setZValue(2000000005); setZValue(ZValues::ARROWS);
if (startItem) if (startItem)
startItem->addArrowFrom(this); startItem->addArrowFrom(this);

View file

@ -7,6 +7,7 @@
#include "../game_scene.h" #include "../game_scene.h"
#include "../player/player.h" #include "../player/player.h"
#include "../player/player_actions.h" #include "../player/player_actions.h"
#include "../z_values.h"
#include "view_zone.h" #include "view_zone.h"
#include <QCheckBox> #include <QCheckBox>
@ -47,7 +48,7 @@ ZoneViewWidget::ZoneViewWidget(Player *_player,
{ {
setAcceptHoverEvents(true); setAcceptHoverEvents(true);
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
setZValue(2000000006); setZValue(ZValues::ZONE_VIEW_WIDGET);
setFlag(ItemIgnoresTransformations); setFlag(ItemIgnoresTransformations);
QGraphicsLinearLayout *vbox = new QGraphicsLinearLayout(Qt::Vertical); QGraphicsLinearLayout *vbox = new QGraphicsLinearLayout(Qt::Vertical);
@ -71,7 +72,7 @@ ZoneViewWidget::ZoneViewWidget(Player *_player,
QGraphicsProxyWidget *searchEditProxy = new QGraphicsProxyWidget; QGraphicsProxyWidget *searchEditProxy = new QGraphicsProxyWidget;
searchEditProxy->setWidget(&searchEdit); searchEditProxy->setWidget(&searchEdit);
searchEditProxy->setZValue(2000000007); searchEditProxy->setZValue(ZValues::DRAG_ITEM);
vbox->addItem(searchEditProxy); vbox->addItem(searchEditProxy);
// top row // top row
@ -80,13 +81,13 @@ ZoneViewWidget::ZoneViewWidget(Player *_player,
// groupBy options // groupBy options
QGraphicsProxyWidget *groupBySelectorProxy = new QGraphicsProxyWidget; QGraphicsProxyWidget *groupBySelectorProxy = new QGraphicsProxyWidget;
groupBySelectorProxy->setWidget(&groupBySelector); groupBySelectorProxy->setWidget(&groupBySelector);
groupBySelectorProxy->setZValue(2000000008); groupBySelectorProxy->setZValue(ZValues::TOP_UI);
hTopRow->addItem(groupBySelectorProxy); hTopRow->addItem(groupBySelectorProxy);
// sortBy options // sortBy options
QGraphicsProxyWidget *sortBySelectorProxy = new QGraphicsProxyWidget; QGraphicsProxyWidget *sortBySelectorProxy = new QGraphicsProxyWidget;
sortBySelectorProxy->setWidget(&sortBySelector); sortBySelectorProxy->setWidget(&sortBySelector);
sortBySelectorProxy->setZValue(2000000007); sortBySelectorProxy->setZValue(ZValues::DRAG_ITEM);
hTopRow->addItem(sortBySelectorProxy); hTopRow->addItem(sortBySelectorProxy);
vbox->addItem(hTopRow); vbox->addItem(hTopRow);