From 844f765ec69836d10caf5820bd3bb9735035bf6f Mon Sep 17 00:00:00 2001 From: drdev Date: Tue, 14 Oct 2014 03:18:10 +0000 Subject: [PATCH] Fix so auras properly attach to permanents --- .../java/forge/screens/match/CMatchUI.java | 8 +-- .../main/java/forge/view/arcane/PlayArea.java | 64 ++++++++++++++----- 2 files changed, 49 insertions(+), 23 deletions(-) diff --git a/forge-gui-desktop/src/main/java/forge/screens/match/CMatchUI.java b/forge-gui-desktop/src/main/java/forge/screens/match/CMatchUI.java index 836c1c75425..be0f084a3ac 100644 --- a/forge-gui-desktop/src/main/java/forge/screens/match/CMatchUI.java +++ b/forge-gui-desktop/src/main/java/forge/screens/match/CMatchUI.java @@ -345,13 +345,7 @@ public enum CMatchUI implements ICDoc, IMenuProvider, IMatchController { public void refreshCardDetails(final Iterable cards) { for (final CardView c : cards) { - if (ZoneType.Battlefield.equals(c.getZone())) { - PlayArea pa = getFieldViewFor(c.getController()).getTabletop(); - CardPanel pnl = pa.getCardPanel(c.getId()); - if (pnl != null) { - pnl.updatePTOverlay(); - } - } + updateSingleCard(c); } } diff --git a/forge-gui-desktop/src/main/java/forge/view/arcane/PlayArea.java b/forge-gui-desktop/src/main/java/forge/view/arcane/PlayArea.java index 99d8f8b60df..3c12b3dd5d5 100644 --- a/forge-gui-desktop/src/main/java/forge/view/arcane/PlayArea.java +++ b/forge-gui-desktop/src/main/java/forge/view/arcane/PlayArea.java @@ -645,30 +645,37 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen newPanels.add(placeholder); } - if (!newPanels.isEmpty()) { + boolean needLayoutRefresh = !newPanels.isEmpty(); + for (final CardView card : modelCopy) { + if (updateCard(card, true)) { + needLayoutRefresh = true; + } + } + if (needLayoutRefresh) { doLayout(); + } + if (!newPanels.isEmpty()) { for (final CardPanel toPanel : newPanels) { scrollRectToVisible(new Rectangle(toPanel.getCardX(), toPanel.getCardY(), toPanel.getCardWidth(), toPanel.getCardHeight())); Animation.moveCard(toPanel); } } - - for (final CardView card : modelCopy) { - updateCard(card, true); - } + invalidate(); repaint(); } - public void updateCard(final CardView card, boolean fromRefresh) { + public boolean updateCard(final CardView card, boolean fromRefresh) { final CardPanel toPanel = getCardPanel(card.getId()); - if (null == toPanel) { return; } + if (toPanel == null) { return false; } + boolean needLayoutRefresh = false; if (card.isTapped()) { toPanel.setTapped(true); toPanel.setTappedAngle(forge.view.arcane.CardPanel.TAPPED_ANGLE); - } else { + } + else { toPanel.setTapped(false); toPanel.setTappedAngle(0); } @@ -679,6 +686,10 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen for (final CardView e : enchants) { final CardPanel cardE = getCardPanel(e.getId()); if (cardE != null) { + if (cardE.getAttachedToPanel() != toPanel) { + cardE.setAttachedToPanel(toPanel); + needLayoutRefresh = true; //ensure layout refreshed if any attachments change + } toPanel.getAttachedPanels().add(cardE); } } @@ -689,6 +700,10 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen for (final CardView e : equips) { final CardPanel cardE = getCardPanel(e.getId()); if (cardE != null) { + if (cardE.getAttachedToPanel() != toPanel) { + cardE.setAttachedToPanel(toPanel); + needLayoutRefresh = true; //ensure layout refreshed if any attachments change + } toPanel.getAttachedPanels().add(cardE); } } @@ -699,25 +714,42 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen for (final CardView f : fortifications) { final CardPanel cardE = getCardPanel(f.getId()); if (cardE != null) { + if (cardE.getAttachedToPanel() != toPanel) { + cardE.setAttachedToPanel(toPanel); + needLayoutRefresh = true; //ensure layout refreshed if any attachments change + } toPanel.getAttachedPanels().add(cardE); } } } + CardPanel attachedToPanel; if (card.getEnchantingCard() != null) { - toPanel.setAttachedToPanel(getCardPanel(card.getEnchantingCard().getId())); - } else if (card.getEquipping() != null) { - toPanel.setAttachedToPanel(getCardPanel(card.getEquipping().getId())); - } else if (card.getFortifying() != null) { - toPanel.setAttachedToPanel(getCardPanel(card.getFortifying().getId())); - } else { - toPanel.setAttachedToPanel(null); + attachedToPanel = getCardPanel(card.getEnchantingCard().getId()); } - + else if (card.getEquipping() != null) { + attachedToPanel = getCardPanel(card.getEquipping().getId()); + } + else if (card.getFortifying() != null) { + attachedToPanel = getCardPanel(card.getFortifying().getId()); + } + else { + attachedToPanel = null; + } + if (toPanel.getAttachedToPanel() != attachedToPanel) { + toPanel.setAttachedToPanel(attachedToPanel); + needLayoutRefresh = true; //ensure layout refreshed if any attachments change + } + toPanel.setCard(card); if (fromRefresh) { toPanel.updatePTOverlay(); //ensure PT Overlay updated on refresh } + + if (needLayoutRefresh && !fromRefresh) { + doLayout(); //ensure layout refreshed here if not being called from a full refresh + } + return needLayoutRefresh; } private static enum RowType {