mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 08:34:52 -07:00
game: Automatic update of arrow position (#5729)
Currently, zones must keep track of which cards they move in order to manually call `updatePath` on arrows. This patch sets the `ItemSendsScenePositionChanges` flag on `ArrowTarget`s to automatically update arrow positions without requiring zones to keep track of that information.
This commit is contained in:
parent
c99afe7956
commit
4ada011632
6 changed files with 19 additions and 32 deletions
|
|
@ -6,6 +6,7 @@
|
||||||
ArrowTarget::ArrowTarget(Player *_owner, QGraphicsItem *parent)
|
ArrowTarget::ArrowTarget(Player *_owner, QGraphicsItem *parent)
|
||||||
: AbstractGraphicsItem(parent), owner(_owner), beingPointedAt(false)
|
: AbstractGraphicsItem(parent), owner(_owner), beingPointedAt(false)
|
||||||
{
|
{
|
||||||
|
setFlag(ItemSendsScenePositionChanges);
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrowTarget::~ArrowTarget()
|
ArrowTarget::~ArrowTarget()
|
||||||
|
|
@ -25,3 +26,16 @@ void ArrowTarget::setBeingPointedAt(bool _beingPointedAt)
|
||||||
beingPointedAt = _beingPointedAt;
|
beingPointedAt = _beingPointedAt;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVariant ArrowTarget::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
|
||||||
|
{
|
||||||
|
if (change == ItemScenePositionHasChanged && scene()) {
|
||||||
|
for (auto *arrow : arrowsFrom)
|
||||||
|
arrow->updatePath();
|
||||||
|
|
||||||
|
for (auto *arrow : arrowsTo)
|
||||||
|
arrow->updatePath();
|
||||||
|
}
|
||||||
|
|
||||||
|
return QGraphicsItem::itemChange(change, value);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,5 +57,8 @@ public:
|
||||||
{
|
{
|
||||||
arrowsTo.removeOne(arrow);
|
arrowsTo.removeOne(arrow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) override;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -331,5 +331,5 @@ QVariant AbstractCardItem::itemChange(QGraphicsItem::GraphicsItemChange change,
|
||||||
update();
|
update();
|
||||||
return value;
|
return value;
|
||||||
} else
|
} else
|
||||||
return QGraphicsItem::itemChange(change, value);
|
return ArrowTarget::itemChange(change, value);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -487,5 +487,5 @@ QVariant CardItem::itemChange(GraphicsItemChange change, const QVariant &value)
|
||||||
owner->getGame()->setActiveCard(nullptr);
|
owner->getGame()->setActiveCard(nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return QGraphicsItem::itemChange(change, value);
|
return AbstractCardItem::itemChange(change, value);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -109,8 +109,6 @@ void StackZone::handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone
|
||||||
void StackZone::reorganizeCards()
|
void StackZone::reorganizeCards()
|
||||||
{
|
{
|
||||||
if (!cards.isEmpty()) {
|
if (!cards.isEmpty()) {
|
||||||
QSet<ArrowItem *> arrowsToUpdate;
|
|
||||||
|
|
||||||
const auto cardCount = static_cast<int>(cards.size());
|
const auto cardCount = static_cast<int>(cards.size());
|
||||||
qreal totalWidth = boundingRect().width();
|
qreal totalWidth = boundingRect().width();
|
||||||
qreal cardWidth = cards.at(0)->boundingRect().width();
|
qreal cardWidth = cards.at(0)->boundingRect().width();
|
||||||
|
|
@ -125,16 +123,6 @@ void StackZone::reorganizeCards()
|
||||||
divideCardSpaceInZone(i, cardCount, boundingRect().height(), cards.at(0)->boundingRect().height());
|
divideCardSpaceInZone(i, cardCount, boundingRect().height(), cards.at(0)->boundingRect().height());
|
||||||
card->setPos(x, y);
|
card->setPos(x, y);
|
||||||
card->setRealZValue(i);
|
card->setRealZValue(i);
|
||||||
|
|
||||||
for (ArrowItem *item : card->getArrowsFrom()) {
|
|
||||||
arrowsToUpdate.insert(item);
|
|
||||||
}
|
|
||||||
for (ArrowItem *item : card->getArrowsTo()) {
|
|
||||||
arrowsToUpdate.insert(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (ArrowItem *item : arrowsToUpdate) {
|
|
||||||
item->updatePath();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
update();
|
update();
|
||||||
|
|
|
||||||
|
|
@ -157,8 +157,6 @@ void TableZone::handleDropEventByGrid(const QList<CardDragItem *> &dragItems,
|
||||||
|
|
||||||
void TableZone::reorganizeCards()
|
void TableZone::reorganizeCards()
|
||||||
{
|
{
|
||||||
QSet<ArrowItem *> arrowsToUpdate;
|
|
||||||
|
|
||||||
// Calculate card stack widths so mapping functions work properly
|
// Calculate card stack widths so mapping functions work properly
|
||||||
computeCardStackWidths();
|
computeCardStackWidths();
|
||||||
|
|
||||||
|
|
@ -189,23 +187,7 @@ void TableZone::reorganizeCards()
|
||||||
qreal childY = y + 5;
|
qreal childY = y + 5;
|
||||||
attachedCard->setPos(childX, childY);
|
attachedCard->setPos(childX, childY);
|
||||||
attachedCard->setRealZValue((childY + CARD_HEIGHT) * 100000 + (childX + 1) * 100);
|
attachedCard->setRealZValue((childY + CARD_HEIGHT) * 100000 + (childX + 1) * 100);
|
||||||
for (ArrowItem *item : attachedCard->getArrowsFrom()) {
|
|
||||||
arrowsToUpdate.insert(item);
|
|
||||||
}
|
|
||||||
for (ArrowItem *item : attachedCard->getArrowsTo()) {
|
|
||||||
arrowsToUpdate.insert(item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ArrowItem *item : cards[i]->getArrowsFrom()) {
|
|
||||||
arrowsToUpdate.insert(item);
|
|
||||||
}
|
|
||||||
for (ArrowItem *item : cards[i]->getArrowsTo()) {
|
|
||||||
arrowsToUpdate.insert(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (ArrowItem *item : arrowsToUpdate) {
|
|
||||||
item->updatePath();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resizeToContents();
|
resizeToContents();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue