From e8b1e3ef0c085f958fa6840b2901e50327373ad2 Mon Sep 17 00:00:00 2001 From: RickyRister <42636155+RickyRister@users.noreply.github.com> Date: Fri, 24 Jan 2025 18:08:28 -0800 Subject: [PATCH] don't autoclose card view if single card gets dragged into same zone (#5517) * rename canResize param to toNewZone * pass toNewZone down * don't autoclose card view if card gets dragged into same zone --- cockatrice/src/game/zones/card_zone.cpp | 4 ++-- cockatrice/src/game/zones/table_zone.cpp | 4 ++-- cockatrice/src/game/zones/table_zone.h | 4 ++-- cockatrice/src/game/zones/view_zone.cpp | 13 +++++++++++-- cockatrice/src/game/zones/view_zone.h | 2 +- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/cockatrice/src/game/zones/card_zone.cpp b/cockatrice/src/game/zones/card_zone.cpp index 1db741754..f3ebbd214 100644 --- a/cockatrice/src/game/zones/card_zone.cpp +++ b/cockatrice/src/game/zones/card_zone.cpp @@ -173,7 +173,7 @@ CardItem *CardZone::getCard(int cardId, const QString &cardName) return c; } -CardItem *CardZone::takeCard(int position, int cardId, bool /*canResize*/) +CardItem *CardZone::takeCard(int position, int cardId, bool toNewZone) { if (position == -1) { // position == -1 means either that the zone is indexed by card id @@ -190,7 +190,7 @@ CardItem *CardZone::takeCard(int position, int cardId, bool /*canResize*/) return nullptr; for (auto *view : views) { - view->removeCard(position); + view->removeCard(position, toNewZone); } CardItem *c = cards.takeAt(position); diff --git a/cockatrice/src/game/zones/table_zone.cpp b/cockatrice/src/game/zones/table_zone.cpp index ee1d0219d..686cb3588 100644 --- a/cockatrice/src/game/zones/table_zone.cpp +++ b/cockatrice/src/game/zones/table_zone.cpp @@ -244,10 +244,10 @@ void TableZone::toggleTapped() player->sendGameCommand(player->prepareGameCommand(cmdList)); } -CardItem *TableZone::takeCard(int position, int cardId, bool canResize) +CardItem *TableZone::takeCard(int position, int cardId, bool toNewZone) { CardItem *result = CardZone::takeCard(position, cardId); - if (canResize) + if (toNewZone) resizeToContents(); return result; } diff --git a/cockatrice/src/game/zones/table_zone.h b/cockatrice/src/game/zones/table_zone.h index 4653b564a..271276967 100644 --- a/cockatrice/src/game/zones/table_zone.h +++ b/cockatrice/src/game/zones/table_zone.h @@ -147,10 +147,10 @@ public: @param position card position @param cardId id of card to take - @param canResize defaults to true + @param toNewZone Whether the destination of the card is not the same as the starting zone. Defaults to true @return CardItem that has been removed */ - CardItem *takeCard(int position, int cardId, bool canResize = true) override; + CardItem *takeCard(int position, int cardId, bool toNewZone = true) override; /** Resizes the TableZone in case CardItems are within or diff --git a/cockatrice/src/game/zones/view_zone.cpp b/cockatrice/src/game/zones/view_zone.cpp index 3cd2be8a3..d86e71f90 100644 --- a/cockatrice/src/game/zones/view_zone.cpp +++ b/cockatrice/src/game/zones/view_zone.cpp @@ -315,6 +315,11 @@ bool ZoneViewZone::prepareAddCard(int x) } } + // autoclose check is done both here and in removeCard + if (cards.isEmpty() && !doInsert && SettingsCache::instance().getCloseEmptyCardView()) { + close(); + } + return doInsert; } @@ -365,7 +370,7 @@ void ZoneViewZone::handleDropEvent(const QList &dragItems, player->sendGameCommand(cmd); } -void ZoneViewZone::removeCard(int position) +void ZoneViewZone::removeCard(int position, bool toNewZone) { if (isReversed) { position -= cards.first()->getId(); @@ -382,7 +387,11 @@ void ZoneViewZone::removeCard(int position) CardItem *card = cards.takeAt(position); card->deleteLater(); - if (cards.isEmpty() && SettingsCache::instance().getCloseEmptyCardView()) { + // The toNewZone check is to prevent the view from auto-closing if the view contains only a single card and that + // card gets dragged within the view. + // Another autoclose check is done in prepareAddCard so that the view autocloses if the last card was moved to an + // unrevealed portion of the same zone. + if (cards.isEmpty() && SettingsCache::instance().getCloseEmptyCardView() && toNewZone) { close(); return; } diff --git a/cockatrice/src/game/zones/view_zone.h b/cockatrice/src/game/zones/view_zone.h index 41ed99609..3c69317aa 100644 --- a/cockatrice/src/game/zones/view_zone.h +++ b/cockatrice/src/game/zones/view_zone.h @@ -71,7 +71,7 @@ public: void reorganizeCards() override; void initializeCards(const QList &cardList = QList()); bool prepareAddCard(int x); - void removeCard(int position); + void removeCard(int position, bool toNewZone); int getNumberCards() const { return numberCards;