Get bottom view to update properly when card is inserted into known portion (#5415)

* more cleanup

* turns out reorganizeCards is not needed if the view doesn't change

* works now
This commit is contained in:
RickyRister 2025-01-05 14:43:44 -08:00 committed by GitHub
parent 5aa1cfea21
commit ffef1b54e0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -111,16 +111,20 @@ void ZoneViewZone::zoneDumpReceived(const Response &r)
void ZoneViewZone::updateCardIds(CardAction action) void ZoneViewZone::updateCardIds(CardAction action)
{ {
int cardCount = cards.size(); if (origZone->contentsKnown()) {
if (!origZone->contentsKnown()) { return;
}
if (cards.isEmpty()) { if (cards.isEmpty()) {
return; return;
} }
int cardCount = cards.size();
auto startId = 0; auto startId = 0;
if (isReversed) { if (isReversed) {
// these get called after this zone's card list updates but before parent zone's card list updates // the card has not been added to origZone's cardList at this point
startId = origZone->getCards().size() - cardCount; startId = origZone->getCards().size() - cardCount;
switch (action) { switch (action) {
case INITIALIZE: case INITIALIZE:
@ -137,7 +141,6 @@ void ZoneViewZone::updateCardIds(CardAction action)
for (int i = 0; i < cardCount; ++i) { for (int i = 0; i < cardCount; ++i) {
cards[i]->setId(i + startId); cards[i]->setId(i + startId);
} }
}
} }
// Because of boundingRect(), this function must not be called before the zone was added to a scene. // Because of boundingRect(), this function must not be called before the zone was added to a scene.
@ -275,21 +278,24 @@ void ZoneViewZone::setPileView(int _pileView)
void ZoneViewZone::addCardImpl(CardItem *card, int x, int /*y*/) void ZoneViewZone::addCardImpl(CardItem *card, int x, int /*y*/)
{ {
if (!isReversed) {
// if x is negative set it to add at end // if x is negative set it to add at end
if (x < 0 || x >= cards.size()) { if (x < 0) {
x = cards.size(); x = cards.size();
} }
cards.insert(x, card);
if (isReversed) {
if (x != 0) {
cards.append(card);
} else { } else {
// map x (which is in origZone indexes) to this viewZone's cardList index
int firstId = cards.isEmpty() ? origZone->getCards().size() : cards.front()->getId();
int insertionIndex = x - firstId;
if (insertionIndex >= 0) {
// card was put into a portion of the deck that's in the view
cards.insert(insertionIndex, card);
} else {
// card was put into a portion of the deck that's not in the view
updateCardIds(ADD_CARD); updateCardIds(ADD_CARD);
reorganizeCards();
return; return;
} }
} else {
cards.insert(x, card);
} }
card->setParentItem(this); card->setParentItem(this);
@ -324,7 +330,6 @@ void ZoneViewZone::removeCard(int position)
position -= cards.first()->getId(); position -= cards.first()->getId();
if (position < 0 || position >= cards.size()) { if (position < 0 || position >= cards.size()) {
updateCardIds(REMOVE_CARD); updateCardIds(REMOVE_CARD);
reorganizeCards();
return; return;
} }
} }