From 70b37804dbf7845f42278a37663f9cbe5f618914 Mon Sep 17 00:00:00 2001 From: RickyRister Date: Fri, 3 Jan 2025 19:37:18 -0800 Subject: [PATCH] saving before changing something --- cockatrice/src/game/zones/view_zone.cpp | 34 +++++++++++++++++++------ cockatrice/src/game/zones/view_zone.h | 9 ++++++- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/cockatrice/src/game/zones/view_zone.cpp b/cockatrice/src/game/zones/view_zone.cpp index 333073a70..047949398 100644 --- a/cockatrice/src/game/zones/view_zone.cpp +++ b/cockatrice/src/game/zones/view_zone.cpp @@ -108,12 +108,12 @@ void ZoneViewZone::zoneDumpReceived(const Response &r) } } previousOrigSize = origZone->getCards().size(); - updateCardIds(false); + updateCardIds(INITIALIZE, -1); reorganizeCards(); emit cardCountChanged(); } -void ZoneViewZone::updateCardIds(bool /*isRemoval*/) +void ZoneViewZone::updateCardIds(CardAction action, int index) { int cardCount = cards.size(); if (!origZone->contentsKnown()) { @@ -127,11 +127,28 @@ void ZoneViewZone::updateCardIds(bool /*isRemoval*/) if (cards.first()->getId() != firstCardId) { startId -= 1; } + + qDebug() << "TRACK" << "action" << action << "index" << index << "startId" << startId; + switch (action) { + case INITIALIZE: + break; + case ADD_CARD: + if (index > startId) { + startId += 1; + } + break; + case REMOVE_CARD: + startId -= 1; + break; + } + /*if (cards.first()->getId() != firstCardId) { + startId -= 1; + } if (origZone->getCards().size() != previousOrigSize) { qDebug() << "TRACK origZoneSize changed" << "orig" << origZone->getCards().size() << "prev" << previousOrigSize; previousOrigSize = origZone->getCards().size(); - } + }*/ } for (int i = 0; i < cardCount; ++i) { @@ -291,7 +308,7 @@ void ZoneViewZone::addCardImpl(CardItem *card, int x, int /*y*/) } card->setParentItem(this); card->update(); - updateCardIds(false); + updateCardIds(ADD_CARD, x); reorganizeCards(); } @@ -314,11 +331,12 @@ void ZoneViewZone::handleDropEvent(const QList &dragItems, player->sendGameCommand(cmd); } -void ZoneViewZone::removeCard(int position) +void ZoneViewZone::removeCard(const int position) { if (isReversed) { - position -= cards.first()->getId(); - if (position < 0 || position >= cards.size()) { + int bottomPos = position - cards.first()->getId(); + if (bottomPos < 0 || bottomPos >= cards.size()) { + updateCardIds(REMOVE_CARD, bottomPos); reorganizeCards(); return; } @@ -330,7 +348,7 @@ void ZoneViewZone::removeCard(int position) CardItem *card = cards.takeAt(position); card->deleteLater(); - updateCardIds(false); + updateCardIds(REMOVE_CARD, position); reorganizeCards(); } diff --git a/cockatrice/src/game/zones/view_zone.h b/cockatrice/src/game/zones/view_zone.h index df104f2ae..6332fbc52 100644 --- a/cockatrice/src/game/zones/view_zone.h +++ b/cockatrice/src/game/zones/view_zone.h @@ -38,7 +38,14 @@ private: int firstCardId; int previousOrigSize; - void updateCardIds(bool isRemoval); + enum CardAction + { + INITIALIZE, + ADD_CARD, + REMOVE_CARD + }; + + void updateCardIds(CardAction action, int index); struct GridSize {