mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
fix bug with multi-attach sometimes only attaching one card (#5272)
This commit is contained in:
parent
90281262be
commit
17e6bfaca6
2 changed files with 15 additions and 4 deletions
|
|
@ -19,8 +19,8 @@
|
|||
#include <QtMath>
|
||||
|
||||
ArrowItem::ArrowItem(Player *_player, int _id, ArrowTarget *_startItem, ArrowTarget *_targetItem, const QColor &_color)
|
||||
: QGraphicsItem(), player(_player), id(_id), startItem(_startItem), targetItem(_targetItem), color(_color),
|
||||
fullColor(true)
|
||||
: QGraphicsItem(), player(_player), id(_id), startItem(_startItem), targetItem(_targetItem), targetLocked(false),
|
||||
color(_color), fullColor(true)
|
||||
{
|
||||
qDebug() << "ArrowItem constructor: startItem=" << static_cast<QGraphicsItem *>(startItem);
|
||||
setZValue(2000000005);
|
||||
|
|
@ -167,7 +167,7 @@ void ArrowDragItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||
{
|
||||
// This ensures that if a mouse move event happens after a call to delArrow(),
|
||||
// the event will be discarded as it would create some stray pointers.
|
||||
if (!startItem)
|
||||
if (targetLocked || !startItem)
|
||||
return;
|
||||
|
||||
QPointF endPos = event->scenePos();
|
||||
|
|
@ -268,7 +268,7 @@ void ArrowAttachItem::addChildArrow(ArrowAttachItem *childArrow)
|
|||
|
||||
void ArrowAttachItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (!startItem)
|
||||
if (targetLocked || !startItem)
|
||||
return;
|
||||
|
||||
QPointF endPos = event->scenePos();
|
||||
|
|
@ -337,6 +337,12 @@ void ArrowAttachItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|||
if (!startItem)
|
||||
return;
|
||||
|
||||
// Attaching could move startItem under the current cursor position, causing all children to retarget to it right
|
||||
// before they are processed. Prevent that.
|
||||
for (ArrowAttachItem *child : childArrows) {
|
||||
child->setTargetLocked(true);
|
||||
}
|
||||
|
||||
if (targetItem && (targetItem != startItem)) {
|
||||
auto startCard = qgraphicsitem_cast<CardItem *>(startItem);
|
||||
auto targetCard = qgraphicsitem_cast<CardItem *>(targetItem);
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ protected:
|
|||
Player *player;
|
||||
int id;
|
||||
ArrowTarget *startItem, *targetItem;
|
||||
bool targetLocked;
|
||||
QColor color;
|
||||
bool fullColor;
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
|
|
@ -64,6 +65,10 @@ public:
|
|||
{
|
||||
return targetItem;
|
||||
}
|
||||
void setTargetLocked(bool _targetLocked)
|
||||
{
|
||||
targetLocked = _targetLocked;
|
||||
}
|
||||
void delArrow();
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue