mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-06 05:23:56 -07:00
Sync command zone visibility on construction and reflow stack on height change
- Sync command zone visibility in the PlayerGraphicsItem constructor in case processPlayerInfo runs before the signal is connected.
- Emit CommandZone::effectiveHeightChanged() when a minimized zone's height changes so the stack zone repositions.
This commit is contained in:
parent
4c60fd2ebd
commit
f74f83c5ec
3 changed files with 15 additions and 5 deletions
|
|
@ -66,6 +66,8 @@ PlayerGraphicsItem::PlayerGraphicsItem(PlayerLogic *_player) : player(_player)
|
||||||
connect(player, &PlayerLogic::addViewCustomZoneActionToCustomZoneMenu, this,
|
connect(player, &PlayerLogic::addViewCustomZoneActionToCustomZoneMenu, this,
|
||||||
&PlayerGraphicsItem::onCustomZoneAdded);
|
&PlayerGraphicsItem::onCustomZoneAdded);
|
||||||
connect(player, &PlayerLogic::commandZoneSupportChanged, this, &PlayerGraphicsItem::setCommandZoneVisible);
|
connect(player, &PlayerLogic::commandZoneSupportChanged, this, &PlayerGraphicsItem::setCommandZoneVisible);
|
||||||
|
// Sync initial state in case processPlayerInfo already ran before this connection.
|
||||||
|
setCommandZoneVisible(player->hasServerCommandZone());
|
||||||
|
|
||||||
playerMenu->setMenusForGraphicItems();
|
playerMenu->setMenusForGraphicItems();
|
||||||
|
|
||||||
|
|
@ -131,6 +133,7 @@ void PlayerGraphicsItem::initializeZones()
|
||||||
commandZoneGraphicsItem->setZValue(ZValues::COMMAND_ZONE);
|
commandZoneGraphicsItem->setZValue(ZValues::COMMAND_ZONE);
|
||||||
commandZoneGraphicsItem->setVisible(false);
|
commandZoneGraphicsItem->setVisible(false);
|
||||||
connect(commandZoneGraphicsItem, &CommandZone::minimizedChanged, this, &PlayerGraphicsItem::rearrangeZones);
|
connect(commandZoneGraphicsItem, &CommandZone::minimizedChanged, this, &PlayerGraphicsItem::rearrangeZones);
|
||||||
|
connect(commandZoneGraphicsItem, &CommandZone::effectiveHeightChanged, this, &PlayerGraphicsItem::rearrangeZones);
|
||||||
|
|
||||||
connect(handZoneGraphicsItem->getLogic(), &HandZoneLogic::cardCountChanged, handCounter,
|
connect(handZoneGraphicsItem->getLogic(), &HandZoneLogic::cardCountChanged, handCounter,
|
||||||
&HandCounter::updateNumber);
|
&HandCounter::updateNumber);
|
||||||
|
|
|
||||||
|
|
@ -44,15 +44,20 @@ void CommandZone::setMinimumHeight(int height)
|
||||||
if (minimumHeight == height) {
|
if (minimumHeight == height) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Only meaningful while minimized, where currentHeight() depends on minimumHeight.
|
||||||
|
const qreal oldEffectiveHeight = currentHeight();
|
||||||
minimumHeight = height;
|
minimumHeight = height;
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
updateClipRect();
|
updateClipRect();
|
||||||
reorganizeCards();
|
reorganizeCards();
|
||||||
update();
|
update();
|
||||||
// NOTE: Do NOT emit minimizedChanged here. The minimized STATE has not changed,
|
// Do NOT emit minimizedChanged: the minimized STATE is unchanged, and that signal
|
||||||
// only the minimum height constraint. Emitting here causes an infinite loop:
|
// feeds rearrangeZones -> rearrangeCounters -> setMinimumHeight (infinite loop).
|
||||||
// rearrangeZones -> rearrangeCounters -> rearrangeTaxCounters -> setMinimumHeight
|
// effectiveHeightChanged repositions neighbouring zones and converges instead: the
|
||||||
// -> minimizedChanged -> rearrangeZones (loop!)
|
// rearrange re-enters setMinimumHeight with the same height and early-returns above.
|
||||||
|
if (!qFuzzyCompare(currentHeight(), oldEffectiveHeight)) {
|
||||||
|
emit effectiveHeightChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CommandZone::isMinimized() const
|
bool CommandZone::isMinimized() const
|
||||||
|
|
|
||||||
|
|
@ -95,8 +95,10 @@ public:
|
||||||
void rearrangeTaxCounters();
|
void rearrangeTaxCounters();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/** @brief Emitted when the zone toggles between minimized and expanded states. */
|
|
||||||
void minimizedChanged(bool isMinimized);
|
void minimizedChanged(bool isMinimized);
|
||||||
|
// Displayed height changed without a minimized-state change (e.g. tax counter toggled
|
||||||
|
// while minimized); lets neighbouring zones reposition.
|
||||||
|
void effectiveHeightChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
|
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue