mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-28 08:52: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;
|
||||
}
|
||||
|
||||
const auto &cards = getLogic()->getCards();
|
||||
int index = calcDropIndexFromY(dropPoint.y(), MIN_CARD_VISIBLE);
|
||||
|
||||
// Same-zone no-op: don't move a card onto itself
|
||||
const auto &cards = getLogic()->getCards();
|
||||
if (!cards.isEmpty() && index < cards.size() && startZone == getLogic() &&
|
||||
cards.at(index)->getId() == dragItems.at(0)->getId()) {
|
||||
// Same-zone no-op: don't move a card onto itself (index may equal size for append)
|
||||
if (startZone == getLogic() && !cards.isEmpty() &&
|
||||
cards.at(qMin(index, static_cast<int>(cards.size()) - 1))->getId() == dragItems.at(0)->getId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ int SelectZone::calcDropIndexFromY(qreal dropY, qreal minOffset) const
|
|||
if (effectiveOffset <= 0.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()
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ protected:
|
|||
|
||||
/**
|
||||
* @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;
|
||||
|
||||
|
|
|
|||
|
|
@ -48,17 +48,12 @@ void StackZone::handleDropEvent(const QList<CardDragItem *> &dragItems,
|
|||
}
|
||||
|
||||
const auto &cards = getLogic()->getCards();
|
||||
int index;
|
||||
if (startZone == getLogic()) {
|
||||
// Reordering within the zone: use drop position
|
||||
index = calcDropIndexFromY(dropPoint.y(), MIN_CARD_VISIBLE);
|
||||
// Same-zone no-op: don't move a card onto itself
|
||||
if (!cards.isEmpty() && cards.at(index)->getId() == dragItems.at(0)->getId()) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// Coming from another zone: append at end (top of stack, rendered on top)
|
||||
index = static_cast<int>(cards.size());
|
||||
int index = calcDropIndexFromY(dropPoint.y(), MIN_CARD_VISIBLE);
|
||||
|
||||
// Same-zone no-op: don't move a card onto itself (index may equal size for append)
|
||||
if (startZone == getLogic() && !cards.isEmpty() &&
|
||||
cards.at(qMin(index, static_cast<int>(cards.size()) - 1))->getId() == dragItems.at(0)->getId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Command_MoveCard cmd;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue