[Refactor] Hold zone views and card view teardown outside game graphics (#7429)

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2026-10-31 18:44:13 +01:00 • committed by GitHub
parent 2335e064ac
commit edb5caec8a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 84 additions and 39 deletions

View file

@ -291,6 +291,8 @@ void GameScene::addPlayer(PlayerLogic *player)
[this, id = player->getPlayerInfo()->getId()]() { clearArrowsForPlayerLocally(id); });
connect(player->getPlayerEventHandler(), &PlayerEventHandler::cardZoneChanged, this, &GameScene::onCardZoneChanged);
connect(player->getPlayerEventHandler(), &PlayerEventHandler::cardViewRefreshRequested, this,
&GameScene::onCardViewRefreshRequested);
rearrange();
}
@ -650,6 +652,25 @@ void GameScene::onCardZoneChanged(CardItem *card, bool sameZone)
}
}
void GameScene::onCardViewRefreshRequested(CardState *card, bool zoneChanged, PlayerLogic *newOwner)
{
auto *item = qobject_cast<CardItem *>(card->parent());
if (!item) {
return;
}
if (zoneChanged) {
item->deleteCardInfoPopup();
}
item->deleteDragItem();
if (zoneChanged) {
item->setBeingPointedAt(false);
item->setHovered(false);
}
if (newOwner) {
item->setOwner(newOwner);
}
}
void GameScene::clearArrowsForPlayer(int playerId)
{
for (int arrowId : arrowRegistry.idsForPlayer(playerId)) {

View file

@ -43,6 +43,7 @@ class ZoneViewWidget;
class CardZone;
class AbstractCardItem;
class CardItem;
class CardState;
class ServerInfo_Card;
class PhasesToolbar;
class QBasicTimer;
@ -282,6 +283,14 @@ public slots:
void requestArrowDeletion(int playerId, int arrowId);
void onCardZoneChanged(CardItem *card, bool sameZone);
/**
* @brief Refreshes the view of a card that the server just moved.
*
* @param card The card that moved.
* @param zoneChanged Whether the card crossed a zone boundary.
* @param newOwner The player the card now belongs to, or nullptr to leave the owner alone.
*/
void onCardViewRefreshRequested(CardState *card, bool zoneChanged, PlayerLogic *newOwner);
protected:
/** @brief Handles hover updates. */

View file

@ -40,21 +40,23 @@ class QGraphicsItem;
ZoneViewZone::ZoneViewZone(ZoneViewZoneLogic *_logic, QGraphicsItem *parent)
: SelectZone(_logic, parent), bRect(QRectF()), minRows(0), groupBy(CardList::NoSort), sortBy(CardList::NoSort)
{
if (!(qobject_cast<ZoneViewZoneLogic *>(getLogic())->getRevealZone() &&
!qobject_cast<ZoneViewZoneLogic *>(getLogic())->getWriteableRevealZone())) {
qobject_cast<ZoneViewZoneLogic *>(getLogic())->getOriginalZone()->getViews().append(this);
auto *viewLogic = qobject_cast<ZoneViewZoneLogic *>(getLogic());
if (!(viewLogic->getRevealZone() && !viewLogic->getWriteableRevealZone())) {
viewLogic->getOriginalZone()->getViews().append(viewLogic);
}
connect(_logic, &ZoneViewZoneLogic::closeView, this, &ZoneViewZone::close);
}
void ZoneViewZone::addToViews()
{
qobject_cast<ZoneViewZoneLogic *>(getLogic())->getOriginalZone()->getViews().append(this);
auto *viewLogic = qobject_cast<ZoneViewZoneLogic *>(getLogic());
viewLogic->getOriginalZone()->getViews().append(viewLogic);
}
void ZoneViewZone::removeFromViews()
{
qobject_cast<ZoneViewZoneLogic *>(getLogic())->getOriginalZone()->getViews().removeOne(this);
auto *viewLogic = qobject_cast<ZoneViewZoneLogic *>(getLogic());
viewLogic->getOriginalZone()->getViews().removeOne(viewLogic);
}
/**
@ -64,9 +66,9 @@ void ZoneViewZone::removeFromViews()
void ZoneViewZone::close()
{
emit closed();
if (!(qobject_cast<ZoneViewZoneLogic *>(getLogic())->getRevealZone() &&
!qobject_cast<ZoneViewZoneLogic *>(getLogic())->getWriteableRevealZone())) {
qobject_cast<ZoneViewZoneLogic *>(getLogic())->getOriginalZone()->getViews().removeOne(this);
auto *viewLogic = qobject_cast<ZoneViewZoneLogic *>(getLogic());
if (!(viewLogic->getRevealZone() && !viewLogic->getWriteableRevealZone())) {
viewLogic->getOriginalZone()->getViews().removeOne(viewLogic);
}
deleteLater();
}