mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-29 17:32:17 -07:00
[Arrows] More fixes and assurances for drag arrows
This commit is contained in:
parent
daa896866f
commit
ce7b3842e4
2 changed files with 25 additions and 1 deletions
|
|
@ -229,7 +229,11 @@ void GameEventHandler::handleArrowDeletion(int creatorId, int arrowId)
|
||||||
|
|
||||||
void GameEventHandler::handleArrowDeletionFinished(const Response &response, int creatorId, int arrowId)
|
void GameEventHandler::handleArrowDeletionFinished(const Response &response, int creatorId, int arrowId)
|
||||||
{
|
{
|
||||||
if (response.response_code() == Response::RespNameNotFound) {
|
// The server confirms the arrow no longer exists whether it deleted it itself
|
||||||
|
// (RespOk, followed by an Event_DeleteArrow broadcast) or never had it
|
||||||
|
// (RespNameNotFound). In both cases the local copy has to go. deleteArrow is
|
||||||
|
// a no-op if the arrow was already removed by the event broadcast.
|
||||||
|
if (response.response_code() == Response::RespOk || response.response_code() == Response::RespNameNotFound) {
|
||||||
emit arrowDeleted(creatorId, arrowId);
|
emit arrowDeleted(creatorId, arrowId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,14 @@ ArrowItem::~ArrowItem()
|
||||||
|
|
||||||
void ArrowItem::onTargetDestroyed()
|
void ArrowItem::onTargetDestroyed()
|
||||||
{
|
{
|
||||||
|
if (data->id == -1) {
|
||||||
|
// Drag and attach arrows are never inserted into the arrow registry and
|
||||||
|
// have no server-side counterpart, so no deletion event can clean them
|
||||||
|
// up. Delete them locally when either endpoint is destroyed.
|
||||||
|
delArrow();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
emit requestDeletion(data->creatorId, data->id);
|
emit requestDeletion(data->creatorId, data->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -384,6 +392,12 @@ void ArrowDragItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||||
void ArrowDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
void ArrowDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (!startItem) {
|
if (!startItem) {
|
||||||
|
// The source card was destroyed while the arrow was being drawn.
|
||||||
|
// Clean up the arrow and its children instead of leaking them.
|
||||||
|
delArrow();
|
||||||
|
for (auto *child : childArrows) {
|
||||||
|
child->mouseReleaseEvent(event);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -507,6 +521,12 @@ void ArrowAttachItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||||
void ArrowAttachItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
void ArrowAttachItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (!startItem) {
|
if (!startItem) {
|
||||||
|
// The source card was destroyed while the arrow was being drawn.
|
||||||
|
// Clean up the arrow and its children instead of leaking them.
|
||||||
|
delArrow();
|
||||||
|
for (auto *child : childArrows) {
|
||||||
|
child->mouseReleaseEvent(event);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue