mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-28 00:42:19 -07:00
Unified fix to allow cards to be dropped correctly in vertical stacked zones without requiring cross-zone special case
This commit is contained in:
parent
bb2afaadd1
commit
f28ceca1de
4 changed files with 12 additions and 17 deletions
|
|
@ -105,12 +105,12 @@ void CommandZone::handleDropEvent(const QList<CardDragItem *> &dragItems,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto &cards = getLogic()->getCards();
|
||||||
int index = calcDropIndexFromY(dropPoint.y(), MIN_CARD_VISIBLE);
|
int index = calcDropIndexFromY(dropPoint.y(), MIN_CARD_VISIBLE);
|
||||||
|
|
||||||
// Same-zone no-op: don't move a card onto itself
|
// Same-zone no-op: don't move a card onto itself (index may equal size for append)
|
||||||
const auto &cards = getLogic()->getCards();
|
if (startZone == getLogic() && !cards.isEmpty() &&
|
||||||
if (!cards.isEmpty() && index < cards.size() && startZone == getLogic() &&
|
cards.at(qMin(index, static_cast<int>(cards.size()) - 1))->getId() == dragItems.at(0)->getId()) {
|
||||||
cards.at(index)->getId() == dragItems.at(0)->getId()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ int SelectZone::calcDropIndexFromY(qreal dropY, qreal minOffset) const
|
||||||
if (effectiveOffset <= 0.0) {
|
if (effectiveOffset <= 0.0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return qBound(0, qRound((dropY - start) / effectiveOffset), params.cardCount - 1);
|
return qBound(0, qRound((dropY - start) / effectiveOffset), params.cardCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectZone::restoreStaleEscapedCards()
|
void SelectZone::restoreStaleEscapedCards()
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ protected:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Computes the card index at a given y-coordinate within the zone's vertical layout.
|
* @brief Computes the card index at a given y-coordinate within the zone's vertical layout.
|
||||||
* Returns 0 if the zone has no cards or the offset is zero.
|
* Returns 0..cardCount (inclusive), where cardCount means append after the last card.
|
||||||
*/
|
*/
|
||||||
int calcDropIndexFromY(qreal dropY, qreal minOffset = 0.0) const;
|
int calcDropIndexFromY(qreal dropY, qreal minOffset = 0.0) const;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,17 +48,12 @@ void StackZone::handleDropEvent(const QList<CardDragItem *> &dragItems,
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto &cards = getLogic()->getCards();
|
const auto &cards = getLogic()->getCards();
|
||||||
int index;
|
int index = calcDropIndexFromY(dropPoint.y(), MIN_CARD_VISIBLE);
|
||||||
if (startZone == getLogic()) {
|
|
||||||
// Reordering within the zone: use drop position
|
// Same-zone no-op: don't move a card onto itself (index may equal size for append)
|
||||||
index = calcDropIndexFromY(dropPoint.y(), MIN_CARD_VISIBLE);
|
if (startZone == getLogic() && !cards.isEmpty() &&
|
||||||
// Same-zone no-op: don't move a card onto itself
|
cards.at(qMin(index, static_cast<int>(cards.size()) - 1))->getId() == dragItems.at(0)->getId()) {
|
||||||
if (!cards.isEmpty() && cards.at(index)->getId() == dragItems.at(0)->getId()) {
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Coming from another zone: append at end (top of stack, rendered on top)
|
|
||||||
index = static_cast<int>(cards.size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Command_MoveCard cmd;
|
Command_MoveCard cmd;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue