From fed97c040a58402960de613ddd09a5b34298f6f5 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Sun, 27 Dec 2020 01:39:00 +0400 Subject: [PATCH] * GUI: fixed that cast/played card can be visible in hand zone until end of the game or re-connect (#7297); --- .../main/java/mage/client/cards/Cards.java | 43 +++++++++---------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/cards/Cards.java b/Mage.Client/src/main/java/mage/client/cards/Cards.java index 7b27867cfa..a7a561c0f7 100644 --- a/Mage.Client/src/main/java/mage/client/cards/Cards.java +++ b/Mage.Client/src/main/java/mage/client/cards/Cards.java @@ -1,10 +1,3 @@ - - - /* - * Cards.java - * - * Created on Dec 18, 2009, 10:40:12 AM - */ package mage.client.cards; import mage.cards.MageCard; @@ -122,15 +115,8 @@ public boolean loadCards(CardsView cardsView, BigCard bigCard, UUID gameId, boolean revertOrder) { boolean changed = false; - // remove objects no longer on the stack from display - for (Iterator> i = cards.entrySet().iterator(); i.hasNext(); ) { - Entry entry = i.next(); - if (!cardsView.containsKey(entry.getKey())) { - removeCard(entry.getKey()); - i.remove(); - changed = true; - } - } + // remove objects no longer to display + changed = removeOutdatedCards(cardsView); // Workaround for bug leaving display of objects on the stack (issue #213 https://github.com/magefree/mage/issues/213) if (cardsView.isEmpty() && countCards() > 0) { @@ -254,18 +240,29 @@ card.setLocation(dx, (int) card.getLocation().getY()); } - private void removeCard(UUID cardId) { + private boolean removeOutdatedCards(CardsView cardsView) { + boolean changed = false; + + // components for (Component comp : cardArea.getComponents()) { + UUID cardId = null; if (comp instanceof Card) { - if (((Card) comp).getCardId().equals(cardId)) { - cardArea.remove(comp); - } + cardId = ((Card) comp).getCardId(); } else if (comp instanceof MageCard) { - if (((MageCard) comp).getOriginal().getId().equals(cardId)) { - cardArea.remove(comp); - } + cardId = ((MageCard) comp).getOriginal().getId(); + } else { + LOGGER.error("Unknown card conponent in cards panel to remove: " + comp); + } + if (cardId == null || !cardsView.containsKey(cardId)) { + cardArea.remove(comp); + changed = true; } } + + // links + cards.keySet().removeIf(id -> !cardsView.containsKey(id)); + + return changed; } private int countCards() {