diff --git a/Mage.Client/src/main/java/mage/client/cards/Permanent.java b/Mage.Client/src/main/java/mage/client/cards/Permanent.java index 1d89e8c59c..e7401b39de 100644 --- a/Mage.Client/src/main/java/mage/client/cards/Permanent.java +++ b/Mage.Client/src/main/java/mage/client/cards/Permanent.java @@ -34,9 +34,6 @@ package mage.client.cards; -import static mage.constants.Constants.DAMAGE_MAX_LEFT; -import static mage.constants.Constants.POWBOX_TEXT_MAX_TOP; - import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; @@ -48,15 +45,15 @@ import java.awt.image.BufferedImage; import java.util.ArrayList; import java.util.List; import java.util.UUID; - import javax.swing.PopupFactory; - -import mage.constants.CardType; import mage.cards.CardDimensions; import mage.cards.MagePermanent; +import mage.cards.Sets; +import static mage.client.constants.Constants.DAMAGE_MAX_LEFT; +import static mage.client.constants.Constants.POWBOX_TEXT_MAX_TOP; import mage.client.util.Config; import mage.client.util.ImageHelper; -import mage.cards.Sets; +import mage.constants.CardType; import mage.view.CounterView; import mage.view.PermanentView; @@ -68,12 +65,16 @@ public class Permanent extends Card { protected PermanentView permanent; - protected List<MagePermanent> links = new ArrayList<MagePermanent>(); + protected List<MagePermanent> links = new ArrayList<>(); protected boolean linked; protected BufferedImage tappedImage; protected BufferedImage flippedImage; - /** Creates new form Permanent */ + /** Creates new form Permanent + * @param permanent + * @param bigCard + * @param dimensions + * @param gameId */ public Permanent(PermanentView permanent, BigCard bigCard, CardDimensions dimensions, UUID gameId) { super(permanent, bigCard, dimensions, gameId); this.setSize(this.getPreferredSize()); @@ -85,6 +86,7 @@ public class Permanent extends Card { return permanent.getId(); } + @Override public List<MagePermanent> getLinks() { return links; } @@ -134,9 +136,10 @@ public class Permanent extends Card { @Override protected List<String> getRules() { if (permanent.getCounters() != null) { - List<String> rules = new ArrayList<String>(permanent.getRules()); - for (CounterView counter: permanent.getCounters()) + List<String> rules = new ArrayList<>(permanent.getRules()); + for (CounterView counter: permanent.getCounters()) { rules.add(counter.getCount() + " x " + counter.getName()); + } return rules; } else { @@ -158,8 +161,12 @@ public class Permanent extends Card { Rectangle r = this.getBounds(); r.x += dx; r.y += dy; - if (r.x < 0) r.x = 0; - if (r.y < 0) r.y = 0; + if (r.x < 0) { + r.x = 0; + } + if (r.y < 0) { + r.y = 0; + } this.setBounds(r); this.repaint(); for (MagePermanent perm: links) { @@ -213,6 +220,7 @@ public class Permanent extends Card { g.dispose(); } + @Override public void update(PermanentView permanent) { this.permanent = permanent; super.update(permanent); @@ -247,8 +255,9 @@ public class Permanent extends Card { @Override public void mouseEntered(MouseEvent arg0) { if (!popupShowing) { - if (popup != null) + if (popup != null) { popup.hide(); + } PopupFactory factory = PopupFactory.getSharedInstance(); int x = (int) this.getLocationOnScreen().getX() + (permanent.isTapped()?Config.dimensions.frameHeight:Config.dimensions.frameWidth); int y = (int) this.getLocationOnScreen().getY() + 40; @@ -262,6 +271,11 @@ public class Permanent extends Card { } } + @Override + public PermanentView getOriginalPermanent() { + return permanent; + } + /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is diff --git a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java index 5c591c06ae..05b1cda976 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java @@ -180,7 +180,7 @@ public class PreferencesDialog extends javax.swing.JDialog { public static final String KEY_AVATAR = "selectedId"; - private static final Map<String, String> cache = new HashMap<String, String>(); + private static final Map<String, String> cache = new HashMap<>(); private static final Boolean UPDATE_CACHE_POLICY = Boolean.TRUE; @@ -190,8 +190,8 @@ public class PreferencesDialog extends javax.swing.JDialog { public static final int DEFAULT_AVATAR_ID = 51; private static int selectedAvatarId = DEFAULT_AVATAR_ID; - private static final Set<Integer> available_avatars = new HashSet<Integer>(); - private static final Map<Integer, JPanel> panels = new HashMap<Integer, JPanel>(); + private static final Set<Integer> available_avatars = new HashSet<>(); + private static final Map<Integer, JPanel> panels = new HashMap<>(); private static final Border GREEN_BORDER = BorderFactory.createLineBorder(Color.GREEN, 3); private static final Border BLACK_BORDER = BorderFactory.createLineBorder(Color.BLACK, 3); diff --git a/Mage.Client/src/main/java/mage/client/game/BattlefieldPanel.java b/Mage.Client/src/main/java/mage/client/game/BattlefieldPanel.java index a30538a033..6d5a935d83 100644 --- a/Mage.Client/src/main/java/mage/client/game/BattlefieldPanel.java +++ b/Mage.Client/src/main/java/mage/client/game/BattlefieldPanel.java @@ -59,6 +59,7 @@ import mage.client.plugins.impl.Plugins; import mage.client.util.Config; import mage.client.util.audio.AudioManager; import mage.constants.CardType; +import mage.utils.CardUtil; import mage.view.PermanentView; /** @@ -117,7 +118,7 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane { } } permanents.clear(); - Plugins.getInstance().sortPermanents(uiComponentsList, permanents.values()); + // Plugins.getInstance().sortPermanents(uiComponentsList, permanents.values()); this.bigCard = null; } @@ -126,19 +127,23 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane { List<PermanentView> permanentsToAdd = new ArrayList<>(); for (PermanentView permanent: battlefield.values()) { - if (!permanents.containsKey(permanent.getId())) { + MagePermanent oldMagePermanent = permanents.get(permanent.getId()); + if (oldMagePermanent == null) { permanentsToAdd.add(permanent); changed = true; - } else { - MagePermanent p = permanents.get(permanent.getId()); + } else { if (!changed) { - int s1 = permanent.getAttachments() == null ? 0 : permanent.getAttachments().size(); - int s2 = p.getLinks().size(); - if (s1 != s2) { - changed = true; + changed = CardUtil.isCreature(oldMagePermanent.getOriginalPermanent()) != CardUtil.isCreature(permanent); + if (!changed) { + int s1 = permanent.getAttachments() == null ? 0 : permanent.getAttachments().size(); + int s2 = oldMagePermanent.getLinks().size(); + if (s1 != s2) { + changed = true; + } } + } - permanents.get(permanent.getId()).update(permanent); + oldMagePermanent.update(permanent); } } diff --git a/Mage.Client/src/main/java/org/mage/card/arcane/CardPanel.java b/Mage.Client/src/main/java/org/mage/card/arcane/CardPanel.java index 76297fbdc4..8a205410ca 100644 --- a/Mage.Client/src/main/java/org/mage/card/arcane/CardPanel.java +++ b/Mage.Client/src/main/java/org/mage/card/arcane/CardPanel.java @@ -77,7 +77,6 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti // for two faced cards public CardView temporary; - private List<MagePermanent> links = new ArrayList<>(); public double tappedAngle = 0; @@ -915,6 +914,9 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti @Override public PermanentView getOriginalPermanent() { + if (isPermanent) { + return (PermanentView) this.gameCard; + } throw new IllegalStateException("Is not permanent."); }