diff --git a/Mage.Client/plugins/mage-card-plugin.jar b/Mage.Client/plugins/mage-card-plugin.jar index 84066e9439a..45bf0f62ec8 100644 Binary files a/Mage.Client/plugins/mage-card-plugin.jar and b/Mage.Client/plugins/mage-card-plugin.jar differ diff --git a/Mage.Client/src/main/java/mage/client/cards/Card.java b/Mage.Client/src/main/java/mage/client/cards/Card.java index 4b87aeb9d5d..fd2772068a7 100644 --- a/Mage.Client/src/main/java/mage/client/cards/Card.java +++ b/Mage.Client/src/main/java/mage/client/cards/Card.java @@ -484,4 +484,7 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis public PermanentView getOriginalPermanent() { return null; } + + @Override + public float getAlpha() {return 0;} } 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 07cd8822a16..70551b3b346 100644 --- a/Mage.Client/src/main/java/mage/client/game/BattlefieldPanel.java +++ b/Mage.Client/src/main/java/mage/client/game/BattlefieldPanel.java @@ -39,16 +39,19 @@ import java.awt.Dimension; import java.awt.Rectangle; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; -import java.awt.event.ComponentListener; +import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Map; -import java.util.UUID; import java.util.Map.Entry; +import java.util.UUID; import javax.swing.JComponent; import javax.swing.JScrollPane; +import com.sun.swing.internal.plaf.synth.resources.synth; + import mage.cards.MagePermanent; import mage.client.cards.BigCard; import mage.client.cards.Permanent; @@ -61,7 +64,7 @@ import mage.view.PermanentView; * * @author BetaSteward_at_googlemail.com */ -public class BattlefieldPanel extends javax.swing.JLayeredPane implements ComponentListener { +public class BattlefieldPanel extends javax.swing.JLayeredPane { private Map permanents = new HashMap(); private UUID gameId; @@ -71,6 +74,7 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane implements Compon protected static DefaultActionCallback defaultCallback = DefaultActionCallback.getInstance(); protected static Map battlefield; protected static Map attachmentCache = new HashMap(); + protected static List threads = new ArrayList(); /** Creates new form BattlefieldPanel */ public BattlefieldPanel(JScrollPane jScrollPane) { @@ -123,6 +127,12 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane implements Compon if (changed) { BattlefieldPanel.battlefield = battlefield; sortLayout(); + synchronized (this) { + for (Thread t : threads) { + t.start(); + } + threads.clear(); + } } } @@ -137,19 +147,32 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane implements Compon } invalidate(); + repaint(); } private void addPermanent(PermanentView permanent) { - MagePermanent perm = Plugins.getInstance().getMagePermanent(permanent, bigCard, Config.dimensions, gameId); - perm.addComponentListener(this); + final MagePermanent perm = Plugins.getInstance().getMagePermanent(permanent, bigCard, Config.dimensions, gameId); if (!Plugins.getInstance().isCardPluginLoaded()) { perm.setBounds(findEmptySpace(new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight))); + } else { + perm.setAlpha(0); } permanents.put(permanent.getId(), perm); - this.add(perm, 10); + + BattlefieldPanel.this.add(perm, 10); if (!Plugins.getInstance().isCardPluginLoaded()) { moveToFront(perm); perm.update(permanent); + } else { + Thread t = new Thread(new Runnable() { + @Override + public void run() { + Plugins.getInstance().onAddCard(perm); + } + }); + synchronized (this) { + threads.add(t); + } } } @@ -162,34 +185,46 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane implements Compon if (!Plugins.getInstance().isCardPluginLoaded()) { for (UUID attachmentId: permanent.getAttachments()) { MagePermanent link = permanents.get(attachmentId); - perm.getLinks().add(link); - r.translate(20, 20); - link.setBounds(r); - setPosition(link, ++position); + if (link != null) { + perm.getLinks().add(link); + r.translate(20, 20); + link.setBounds(r); + setPosition(link, ++position); + } } } else { for (UUID attachmentId: permanent.getAttachments()) { MagePermanent link = permanents.get(attachmentId); - link.setBounds(r); - perm.getLinks().add(link); - r.translate(8, 10); - perm.setBounds(r); - moveToFront(link); - moveToFront(perm); + if (link != null) { + link.setBounds(r); + perm.getLinks().add(link); + r.translate(8, 10); + perm.setBounds(r); + moveToFront(link); + moveToFront(perm); + } } } } private void removePermanent(UUID permanentId) { - for (Component comp: this.getComponents()) { + for (Component c: this.getComponents()) { + final Component comp = c; if (comp instanceof Permanent) { if (((Permanent)comp).getPermanentId().equals(permanentId)) { this.remove(comp); } } else if (comp instanceof MagePermanent) { if (((MagePermanent)comp).getOriginal().getId().equals(permanentId)) { - this.remove(comp); + Thread t = new Thread(new Runnable() { + @Override + public void run() { + Plugins.getInstance().onRemoveCard((MagePermanent)comp); + BattlefieldPanel.this.remove(comp); + } + }); + t.start(); } } } @@ -241,48 +276,6 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane implements Compon setOpaque(true); }// //GEN-END:initComponents - @Override - public void componentResized(ComponentEvent e) { - resizeBattlefield(); - } - - @Override - public void componentMoved(ComponentEvent e) { - resizeBattlefield(); - } - - @Override - public void componentShown(ComponentEvent e) { - resizeBattlefield(); - } - - @Override - public void componentHidden(ComponentEvent e) { - resizeBattlefield(); - } - - private void resizeBattlefield() { - /*Dimension area = new Dimension(0, 0); - Dimension size = getPreferredSize(); - - for (Component comp: getComponents()) { - Rectangle r = comp.getBounds(); - if (r.x + r.width > area.width) { - area.width = r.x + r.width; - } - if (r.y + r.height > area.height) { - area.height = r.y + r.height; - } - } - if (size.height != area.height || size.width != area.width) { - setPreferredSize(area); - revalidate(); - repaint(); - }*/ - - } - - // Variables declaration - do not modify//GEN-BEGIN:variables // End of variables declaration//GEN-END:variables diff --git a/Mage.Client/src/main/java/mage/client/plugins/MagePlugins.java b/Mage.Client/src/main/java/mage/client/plugins/MagePlugins.java index bd9b765eb63..000b2727fef 100644 --- a/Mage.Client/src/main/java/mage/client/plugins/MagePlugins.java +++ b/Mage.Client/src/main/java/mage/client/plugins/MagePlugins.java @@ -32,4 +32,6 @@ public interface MagePlugins { int getGamesPlayed(); void addGamesPlayed(); Image getManaSymbolImage(String symbol); + void onAddCard(MagePermanent card); + void onRemoveCard(MagePermanent card); } diff --git a/Mage.Client/src/main/java/mage/client/plugins/impl/Plugins.java b/Mage.Client/src/main/java/mage/client/plugins/impl/Plugins.java index 2f6f0db61dc..88c645203bd 100644 --- a/Mage.Client/src/main/java/mage/client/plugins/impl/Plugins.java +++ b/Mage.Client/src/main/java/mage/client/plugins/impl/Plugins.java @@ -167,4 +167,18 @@ public class Plugins implements MagePlugins { } return null; } + + @Override + public void onAddCard(MagePermanent card) { + if (this.cardPlugin != null) { + this.cardPlugin.onAddCard(card); + } + } + + @Override + public void onRemoveCard(MagePermanent card) { + if (this.cardPlugin != null) { + this.cardPlugin.onRemoveCard(card); + } + } } diff --git a/Mage.Common/src/mage/cards/MageCard.java b/Mage.Common/src/mage/cards/MageCard.java index e538a1bbec9..5b941213605 100644 --- a/Mage.Common/src/mage/cards/MageCard.java +++ b/Mage.Common/src/mage/cards/MageCard.java @@ -14,6 +14,7 @@ public abstract class MageCard extends JPanel { abstract public void onEndAnimation(); abstract public boolean isTapped(); abstract public void setAlpha(float transparency); + abstract public float getAlpha(); abstract public CardView getOriginal(); abstract public void setCardBounds(int x, int y, int width, int height); abstract public void update(CardView card); diff --git a/Mage.Common/src/mage/interfaces/plugin/CardPlugin.java b/Mage.Common/src/mage/interfaces/plugin/CardPlugin.java index 8ffd12c04f5..72cdd0346d4 100644 --- a/Mage.Common/src/mage/interfaces/plugin/CardPlugin.java +++ b/Mage.Common/src/mage/interfaces/plugin/CardPlugin.java @@ -31,4 +31,6 @@ public interface CardPlugin extends Plugin { void downloadImages(Set allCards); void downloadSymbols(); Image getManaSymbolImage(String symbol); + void onAddCard(MagePermanent card); + void onRemoveCard(MagePermanent card); } diff --git a/Mage.Plugins/Mage.Card.Plugin/src/main/java/org/mage/card/arcane/Animation.java b/Mage.Plugins/Mage.Card.Plugin/src/main/java/org/mage/card/arcane/Animation.java index f39de00dcc0..8f5ea355ab2 100644 --- a/Mage.Plugins/Mage.Card.Plugin/src/main/java/org/mage/card/arcane/Animation.java +++ b/Mage.Plugins/Mage.Card.Plugin/src/main/java/org/mage/card/arcane/Animation.java @@ -287,30 +287,30 @@ abstract public class Animation { } } - static public void showCard(final CardPanel panel) { + static public void showCard(final MagePermanent card) { new Animation(600) { protected void start () { } protected void update (float percentage) { float alpha = percentage; - panel.setAlpha(alpha); - panel.repaint(); + card.setAlpha(alpha); + card.repaint(); } protected void end () { + card.setAlpha(1.f); } }; } - static public void hideCard(final CardPanel panel, final MagePermanent card) { + static public void hideCard(final MagePermanent card) { new Animation(600) { protected void start () { } protected void update (float percentage) { float alpha = 1 - percentage; - panel.setAlpha(alpha); card.setAlpha(alpha); card.repaint(); } diff --git a/Mage.Plugins/Mage.Card.Plugin/src/main/java/org/mage/plugins/card/CardPluginImpl.java b/Mage.Plugins/Mage.Card.Plugin/src/main/java/org/mage/plugins/card/CardPluginImpl.java index 4b962d27d0c..dd70c1aba95 100644 --- a/Mage.Plugins/Mage.Card.Plugin/src/main/java/org/mage/plugins/card/CardPluginImpl.java +++ b/Mage.Plugins/Mage.Card.Plugin/src/main/java/org/mage/plugins/card/CardPluginImpl.java @@ -32,6 +32,7 @@ import net.xeoh.plugins.base.annotations.events.PluginLoaded; import net.xeoh.plugins.base.annotations.meta.Author; import org.apache.log4j.Logger; +import org.mage.card.arcane.Animation; import org.mage.card.arcane.CardPanel; import org.mage.card.arcane.ManaSymbols; import org.mage.plugins.card.constants.Constants; @@ -433,4 +434,32 @@ public class CardPluginImpl implements CardPlugin { public Image getManaSymbolImage(String symbol) { return ManaSymbols.getManaSymbolImage(symbol); } + + @Override + public void onAddCard(MagePermanent card) { + if (card != null) { + Animation.showCard((CardPanel) card); + try { + while ((card).getAlpha() + 0.05f < 1) { + Thread.sleep(30); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + @Override + public void onRemoveCard(MagePermanent card) { + if (card != null) { + Animation.hideCard((CardPanel) card); + try { + while ((card).getAlpha() - 0.05f > 0) { + Thread.sleep(30); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } }