mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-01 02:53:56 -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>
|
#include <QtMath>
|
||||||
|
|
||||||
ArrowItem::ArrowItem(Player *_player, int _id, ArrowTarget *_startItem, ArrowTarget *_targetItem, const QColor &_color)
|
ArrowItem::ArrowItem(Player *_player, int _id, ArrowTarget *_startItem, ArrowTarget *_targetItem, const QColor &_color)
|
||||||
: QGraphicsItem(), player(_player), id(_id), startItem(_startItem), targetItem(_targetItem), color(_color),
|
: QGraphicsItem(), player(_player), id(_id), startItem(_startItem), targetItem(_targetItem), targetLocked(false),
|
||||||
fullColor(true)
|
color(_color), fullColor(true)
|
||||||
{
|
{
|
||||||
qDebug() << "ArrowItem constructor: startItem=" << static_cast<QGraphicsItem *>(startItem);
|
qDebug() << "ArrowItem constructor: startItem=" << static_cast<QGraphicsItem *>(startItem);
|
||||||
setZValue(2000000005);
|
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(),
|
// 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.
|
// the event will be discarded as it would create some stray pointers.
|
||||||
if (!startItem)
|
if (targetLocked || !startItem)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QPointF endPos = event->scenePos();
|
QPointF endPos = event->scenePos();
|
||||||
|
|
@ -268,7 +268,7 @@ void ArrowAttachItem::addChildArrow(ArrowAttachItem *childArrow)
|
||||||
|
|
||||||
void ArrowAttachItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
void ArrowAttachItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (!startItem)
|
if (targetLocked || !startItem)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QPointF endPos = event->scenePos();
|
QPointF endPos = event->scenePos();
|
||||||
|
|
@ -337,6 +337,12 @@ void ArrowAttachItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
if (!startItem)
|
if (!startItem)
|
||||||
return;
|
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)) {
|
if (targetItem && (targetItem != startItem)) {
|
||||||
auto startCard = qgraphicsitem_cast<CardItem *>(startItem);
|
auto startCard = qgraphicsitem_cast<CardItem *>(startItem);
|
||||||
auto targetCard = qgraphicsitem_cast<CardItem *>(targetItem);
|
auto targetCard = qgraphicsitem_cast<CardItem *>(targetItem);
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ protected:
|
||||||
Player *player;
|
Player *player;
|
||||||
int id;
|
int id;
|
||||||
ArrowTarget *startItem, *targetItem;
|
ArrowTarget *startItem, *targetItem;
|
||||||
|
bool targetLocked;
|
||||||
QColor color;
|
QColor color;
|
||||||
bool fullColor;
|
bool fullColor;
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
|
@ -64,6 +65,10 @@ public:
|
||||||
{
|
{
|
||||||
return targetItem;
|
return targetItem;
|
||||||
}
|
}
|
||||||
|
void setTargetLocked(bool _targetLocked)
|
||||||
|
{
|
||||||
|
targetLocked = _targetLocked;
|
||||||
|
}
|
||||||
void delArrow();
|
void delArrow();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue