mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
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.
41 lines
1 KiB
C++
41 lines
1 KiB
C++
#include "arrow_target.h"
|
|
|
|
#include "../player/player.h"
|
|
#include "arrow_item.h"
|
|
|
|
ArrowTarget::ArrowTarget(Player *_owner, QGraphicsItem *parent)
|
|
: AbstractGraphicsItem(parent), owner(_owner), beingPointedAt(false)
|
|
{
|
|
setFlag(ItemSendsScenePositionChanges);
|
|
}
|
|
|
|
ArrowTarget::~ArrowTarget()
|
|
{
|
|
for (int i = 0; i < arrowsFrom.size(); ++i) {
|
|
arrowsFrom[i]->setStartItem(0);
|
|
arrowsFrom[i]->delArrow();
|
|
}
|
|
for (int i = 0; i < arrowsTo.size(); ++i) {
|
|
arrowsTo[i]->setTargetItem(0);
|
|
arrowsTo[i]->delArrow();
|
|
}
|
|
}
|
|
|
|
void ArrowTarget::setBeingPointedAt(bool _beingPointedAt)
|
|
{
|
|
beingPointedAt = _beingPointedAt;
|
|
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);
|
|
}
|