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 a10b2700586..538d1e057fe 100644 --- a/Mage.Client/src/main/java/mage/client/cards/Card.java +++ b/Mage.Client/src/main/java/mage/client/cards/Card.java @@ -382,7 +382,7 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis List targets = card.getTargets(); if (targets != null) { for (UUID uuid : targets) { - System.out.println("Getting play area panel for uuid: " + uuid); + //System.out.println("Getting play area panel for uuid: " + uuid); PlayAreaPanel p = session.getGame().getPlayers().get(uuid); if (p != null) { 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 b69511a0345..7e01156c77f 100644 --- a/Mage.Client/src/main/java/mage/client/cards/Cards.java +++ b/Mage.Client/src/main/java/mage/client/cards/Cards.java @@ -58,7 +58,6 @@ import mage.view.CardsView; public class Cards extends javax.swing.JPanel { private Map cards = new HashMap(); - private boolean mouseHandlingEnabled = false; /** Creates new form Cards */ public Cards() { @@ -90,16 +89,6 @@ public class Cards extends javax.swing.JPanel { } } - if (!mouseHandlingEnabled) { - synchronized (this) { - if (!mouseHandlingEnabled) { - mouseHandlingEnabled = true; - jScrollPane1.addMouseListener(new MageMouseAdapter(cardArea, gameId)); - jScrollPane1.addMouseMotionListener(new MageMouseMotionAdapter(cardArea, bigCard)); - } - } - } - cardArea.setPreferredSize(new Dimension(cards.size() * Config.dimensions.frameWidth, Config.dimensions.frameHeight)); cardArea.revalidate(); cardArea.repaint(); 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 36d094e4792..fa9c5d6b982 100644 --- a/Mage.Client/src/main/java/mage/client/game/BattlefieldPanel.java +++ b/Mage.Client/src/main/java/mage/client/game/BattlefieldPanel.java @@ -89,8 +89,6 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane implements Compon public void init(UUID gameId, BigCard bigCard) { this.gameId = gameId; this.bigCard = bigCard; - addMouseListener(new MageMouseAdapter(this, gameId)); - addMouseMotionListener(new MageMouseMotionAdapter(this, bigCard)); } public void update(Map battlefield) { diff --git a/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java b/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java new file mode 100644 index 00000000000..530030fea3e --- /dev/null +++ b/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java @@ -0,0 +1,98 @@ +package mage.client.plugins.adapters; + +import java.awt.Component; +import java.awt.Image; +import java.awt.event.MouseEvent; +import java.awt.image.BufferedImage; + +import javax.swing.Popup; +import javax.swing.PopupFactory; + +import org.jdesktop.swingx.JXPanel; + +import mage.cards.MageCard; +import mage.cards.action.ActionCallback; +import mage.cards.action.TransferData; +import mage.client.MageFrame; +import mage.client.cards.BigCard; +import mage.client.plugins.impl.Plugins; +import mage.client.remote.Session; +import mage.client.util.DefaultActionCallback; +import mage.client.util.ImageHelper; +import mage.client.util.gui.GuiDisplayUtil; + +public class MageActionCallback implements ActionCallback { + + private Popup popup; + private Component parent; + private BigCard bigCard; + protected static DefaultActionCallback defaultCallback = DefaultActionCallback.getInstance(); + protected static Session session = MageFrame.getSession(); + + public MageActionCallback() { + } + + public void setCardPreviewComponent(BigCard bigCard) { + this.bigCard = bigCard; + } + + public void refreshSession() { + if (session == null) { + session = MageFrame.getSession(); + } + } + + @Override + public void mouseClicked(MouseEvent e, TransferData data) { + data.component.requestFocusInWindow(); + System.out.println("data="+data); + System.out.println("session="+session+",gameId="+data.gameId+",card="+data.card); + defaultCallback.mouseClicked(e, data.gameId, session, data.card); + } + + @Override + public void mouseEntered(MouseEvent e, TransferData data) { + if (popup != null) + popup.hide(); + PopupFactory factory = PopupFactory.getSharedInstance(); + popup = factory.getPopup(data.component, data.popupText, (int) data.locationOnScreen.getX() + data.popupOffsetX, (int) data.locationOnScreen.getY() + data.popupOffsetY + 40); + popup.show(); + //hack to get popup to resize to fit text + popup.hide(); + popup = factory.getPopup(data.component, data.popupText, (int) data.locationOnScreen.getX() + data.popupOffsetX, (int) data.locationOnScreen.getY() + data.popupOffsetY + 40); + popup.show(); + } + + @Override + public void mouseMoved(MouseEvent e, TransferData data) { + if (!Plugins.getInstance().isCardPluginLoaded()) {return;} + if (bigCard == null) {return;} + + MageCard card = (MageCard) data.component; + if (card.getOriginal().getId() != bigCard.getCardId()) { + synchronized (MageMouseAdapter.class) { + if (card.getOriginal().getId() != bigCard.getCardId()) { + Image image = card.getImage(); + if (image != null && image instanceof BufferedImage) { + image = ImageHelper.getResizedImage((BufferedImage) image, bigCard.getWidth(), bigCard.getHeight()); + bigCard.setCard(card.getOriginal().getId(), image, card.getOriginal().getRules()); + bigCard.hideTextComponent(); + } else { + JXPanel panel = GuiDisplayUtil.getDescription(card.getOriginal(), bigCard.getWidth(), bigCard.getHeight()); + panel.setVisible(true); + bigCard.hideTextComponent(); + bigCard.addJXPanel(card.getOriginal().getId(), panel); + } + } + } + } + } + + @Override + public void mouseExited(MouseEvent e) { + if (popup != null) { + popup.hide(); + } + } + +} diff --git a/Mage.Client/src/main/java/mage/client/plugins/adapters/MageMouseMotionAdapter.java b/Mage.Client/src/main/java/mage/client/plugins/adapters/MageMouseMotionAdapter.java index e67a7e88b38..12e21da5890 100644 --- a/Mage.Client/src/main/java/mage/client/plugins/adapters/MageMouseMotionAdapter.java +++ b/Mage.Client/src/main/java/mage/client/plugins/adapters/MageMouseMotionAdapter.java @@ -7,7 +7,6 @@ import java.awt.event.MouseMotionAdapter; import java.awt.image.BufferedImage; import mage.cards.MageCard; -import mage.cards.MagePermanent; import mage.client.cards.BigCard; import mage.client.plugins.impl.Plugins; import mage.client.util.ImageHelper; 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 b50c9024d76..0b328227cfa 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 @@ -18,6 +18,7 @@ import mage.client.cards.BigCard; import mage.client.cards.Card; import mage.client.cards.Permanent; import mage.client.plugins.MagePlugins; +import mage.client.plugins.adapters.MageActionCallback; import mage.client.util.Config; import mage.client.util.DefaultActionCallback; import mage.constants.Constants; @@ -34,14 +35,16 @@ import net.xeoh.plugins.base.impl.PluginManagerFactory; public class Plugins implements MagePlugins { - private static final MagePlugins fINSTANCE = new Plugins(); - private static PluginManager pm; + private final static MagePlugins fINSTANCE = new Plugins(); private final static Logger logger = Logging.getLogger(Plugins.class.getName()); + private static PluginManager pm; + private ThemePlugin themePlugin = null; private CardPlugin cardPlugin = null; private CounterPlugin counterPlugin = null; protected static DefaultActionCallback defaultCallback = DefaultActionCallback.getInstance(); private static final EmptyCallback emptyCallback = new EmptyCallback(); + private static final MageActionCallback mageActionCallback = new MageActionCallback(); public static MagePlugins getInstance() { return fINSTANCE; @@ -76,7 +79,9 @@ public class Plugins implements MagePlugins { @Override public MagePermanent getMagePermanent(PermanentView card, BigCard bigCard, CardDimensions dimension, UUID gameId) { if (cardPlugin != null) { - return cardPlugin.getMagePermanent(card, dimension, gameId, emptyCallback); + mageActionCallback.refreshSession(); + mageActionCallback.setCardPreviewComponent(bigCard); + return cardPlugin.getMagePermanent(card, dimension, gameId, mageActionCallback); } else { return new Permanent(card, bigCard, Config.dimensions, gameId); } @@ -85,7 +90,9 @@ public class Plugins implements MagePlugins { @Override public MageCard getMageCard(CardView card, BigCard bigCard, CardDimensions dimension, UUID gameId) { if (cardPlugin != null) { - return cardPlugin.getMageCard(card, dimension, gameId, emptyCallback); + mageActionCallback.refreshSession(); + mageActionCallback.setCardPreviewComponent(bigCard); + return cardPlugin.getMageCard(card, dimension, gameId, mageActionCallback); } else { return new Card(card, bigCard, Config.dimensions, gameId); } diff --git a/Mage.Client/src/main/java/mage/client/util/DefaultActionCallback.java b/Mage.Client/src/main/java/mage/client/util/DefaultActionCallback.java index 068e595e082..dfef73f2db0 100644 --- a/Mage.Client/src/main/java/mage/client/util/DefaultActionCallback.java +++ b/Mage.Client/src/main/java/mage/client/util/DefaultActionCallback.java @@ -18,7 +18,6 @@ public class DefaultActionCallback { } public void mouseClicked(MouseEvent e, UUID gameId, Session session, CardView card) { - System.out.println("gameId:" + gameId); if (gameId != null) session.sendPlayerUUID(gameId, card.getId()); } diff --git a/Mage.Common/src/mage/cards/action/ActionCallback.java b/Mage.Common/src/mage/cards/action/ActionCallback.java index 6e9667146c1..51e4632ea7a 100644 --- a/Mage.Common/src/mage/cards/action/ActionCallback.java +++ b/Mage.Common/src/mage/cards/action/ActionCallback.java @@ -3,6 +3,8 @@ package mage.cards.action; import java.awt.event.MouseEvent; public interface ActionCallback { - void mouseClicked(MouseEvent e); - void mouseMoved(MouseEvent e); + void mouseClicked(MouseEvent e, TransferData data); + void mouseMoved(MouseEvent e, TransferData data); + void mouseEntered(MouseEvent e, TransferData data); + void mouseExited(MouseEvent e); } diff --git a/Mage.Common/src/mage/cards/action/TransferData.java b/Mage.Common/src/mage/cards/action/TransferData.java new file mode 100644 index 00000000000..4b186a22046 --- /dev/null +++ b/Mage.Common/src/mage/cards/action/TransferData.java @@ -0,0 +1,18 @@ +package mage.cards.action; + +import java.awt.Component; +import java.awt.Point; +import java.util.UUID; + +import mage.cards.TextPopup; +import mage.view.CardView; + +public class TransferData { + public Component component; + public TextPopup popupText; + public Point locationOnScreen; + public int popupOffsetX; + public int popupOffsetY; + public UUID gameId; + public CardView card; +} diff --git a/Mage.Common/src/mage/cards/action/impl/EmptyCallback.java b/Mage.Common/src/mage/cards/action/impl/EmptyCallback.java index 11b66acca5d..a87d4746276 100644 --- a/Mage.Common/src/mage/cards/action/impl/EmptyCallback.java +++ b/Mage.Common/src/mage/cards/action/impl/EmptyCallback.java @@ -3,6 +3,7 @@ package mage.cards.action.impl; import java.awt.event.MouseEvent; import mage.cards.action.ActionCallback; +import mage.cards.action.TransferData; /** * Callback that does nothing on any action @@ -12,11 +13,19 @@ import mage.cards.action.ActionCallback; public class EmptyCallback implements ActionCallback { @Override - public void mouseClicked(MouseEvent e) { + public void mouseMoved(MouseEvent e, TransferData data) { } @Override - public void mouseMoved(MouseEvent e) { + public void mouseEntered(MouseEvent e, TransferData data) { + } + + @Override + public void mouseExited(MouseEvent e) { + } + + @Override + public void mouseClicked(MouseEvent e, TransferData data) { } } diff --git a/Mage.Common/src/mage/view/CardView.java b/Mage.Common/src/mage/view/CardView.java index 4ca40d1994c..f7124983e41 100644 --- a/Mage.Common/src/mage/view/CardView.java +++ b/Mage.Common/src/mage/view/CardView.java @@ -96,8 +96,6 @@ public class CardView implements Serializable { this.rarity = card.getRarity(); this.expansionSetCode = card.getExpansionSetCode(); } - //TODO:remove me - //System.out.println("**** CARD NUMBER **** : " + card.getCardNumber() + " : " + card.getName() + " : " + card.getExpansionSetCode()); this.cardNumber = card.getCardNumber(); if (card instanceof Spell) { @@ -109,7 +107,6 @@ public class CardView implements Serializable { for (UUID targetUUID : target.getTargets()) { if (this.targets == null) this.targets = new ArrayList(); this.targets.add(targetUUID); - System.out.println("Added target: " + targetUUID); } } } diff --git a/Mage.Plugins/Mage.Card.Plugin/src/main/java/org/mage/card/arcane/CardPanel.java b/Mage.Plugins/Mage.Card.Plugin/src/main/java/org/mage/card/arcane/CardPanel.java index a28f125ff81..c975d2a7490 100644 --- a/Mage.Plugins/Mage.Card.Plugin/src/main/java/org/mage/card/arcane/CardPanel.java +++ b/Mage.Plugins/Mage.Card.Plugin/src/main/java/org/mage/card/arcane/CardPanel.java @@ -12,20 +12,21 @@ import java.awt.Rectangle; import java.awt.RenderingHints; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; import java.awt.image.BufferedImage; import java.util.ArrayList; import java.util.List; +import java.util.UUID; import javax.swing.BorderFactory; import javax.swing.JRootPane; -import javax.swing.Popup; -import javax.swing.PopupFactory; import javax.swing.SwingUtilities; import mage.Constants.CardType; import mage.cards.MagePermanent; import mage.cards.TextPopup; import mage.cards.action.ActionCallback; +import mage.cards.action.TransferData; import mage.utils.CardUtil; import mage.view.AbilityView; import mage.view.CardView; @@ -39,7 +40,7 @@ import org.mage.plugins.card.images.ImageCache; @SuppressWarnings({"unchecked","rawtypes"}) -public class CardPanel extends MagePermanent implements MouseListener { +public class CardPanel extends MagePermanent implements MouseListener, MouseMotionListener { private static final long serialVersionUID = -3272134219262184410L; private static final Logger log = Logger.getLogger(CardPanel.class); @@ -82,15 +83,17 @@ public class CardPanel extends MagePermanent implements MouseListener { private ActionCallback callback; - protected Popup popup; protected boolean popupShowing; protected TextPopup popupText = new TextPopup(); + protected UUID gameId; + private TransferData data = new TransferData(); private boolean isPermanent; - - public CardPanel(CardView newGameCard, boolean loadImage, ActionCallback callback) { + + public CardPanel(CardView newGameCard, UUID gameId, boolean loadImage, ActionCallback callback) { this.gameCard = newGameCard; this.callback = callback; + this.gameId = gameId; this.isPermanent = this.gameCard instanceof PermanentView; if (isPermanent) { @@ -103,8 +106,9 @@ public class CardPanel extends MagePermanent implements MouseListener { setBackground(Color.black); setOpaque(false); - //addMouseListener(this); - + addMouseListener(this); + addMouseMotionListener(this); + titleText = new GlowText(); setText(gameCard); titleText.setFont(getFont().deriveFont(Font.BOLD, 13f)); @@ -554,30 +558,44 @@ public class CardPanel extends MagePermanent implements MouseListener { } @Override - public void mouseClicked(MouseEvent e) {} - - @Override - public void mouseEntered(MouseEvent arg0) { - if (!popupShowing) { - if (popup != null) - popup.hide(); - PopupFactory factory = PopupFactory.getSharedInstance(); - popup = factory.getPopup(this, popupText, (int) this.getLocationOnScreen().getX() + cardWidth + cardXOffset, (int) this.getLocationOnScreen().getY() + 40); - popup.show(); - //hack to get popup to resize to fit text - popup.hide(); - popup = factory.getPopup(this, popupText, (int) this.getLocationOnScreen().getX() + cardWidth + cardXOffset, (int) this.getLocationOnScreen().getY() + 40); - popup.show(); - popupShowing = true; - } + public void mouseClicked(MouseEvent e) { + data.component = this; + data.card = this.gameCard; + data.gameId = this.gameId; + callback.mouseClicked(e, data); } @Override - public void mouseExited(MouseEvent arg0) { + public void mouseEntered(MouseEvent e) { + if (!popupShowing) { + synchronized (this) { + if (!popupShowing) { + popupShowing = true; + callback.mouseEntered(e, getTransferDataForMouseEntered()); + } + } + } + } + + @Override + public void mouseDragged(MouseEvent e) {} + + @Override + public void mouseMoved(MouseEvent e) { + data.component = this; + callback.mouseMoved(e, data); + } + + @Override + public void mouseExited(MouseEvent e) { if(getMousePosition(true) != null) return; - if (popup != null) { - popup.hide(); - popupShowing = false; + if (popupShowing) { + synchronized (this) { + if (popupShowing) { + popupShowing = false; + callback.mouseExited(e); + } + } } } @@ -587,6 +605,20 @@ public class CardPanel extends MagePermanent implements MouseListener { @Override public void mouseReleased(MouseEvent e) {} + /** + * Prepares data to be sent to action callback on client side. + * + * @return + */ + private TransferData getTransferDataForMouseEntered() { + data.component = this; + data.popupText = popupText; + data.popupOffsetX = cardWidth + cardXOffset; + data.popupOffsetY = 40; + data.locationOnScreen = this.getLocationOnScreen(); + return data; + } + protected String getType(CardView card) { StringBuilder sbType = new StringBuilder(); 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 96112ea03a5..f0d9188022c 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 @@ -77,7 +77,7 @@ public class CardPluginImpl implements CardPlugin { @Override public MagePermanent getMagePermanent(PermanentView permanent, CardDimensions dimension, UUID gameId, ActionCallback callback) { - CardPanel cardPanel = new CardPanel(permanent, true, callback); + CardPanel cardPanel = new CardPanel(permanent, gameId, true, callback); cardPanel.setShowCastingCost(true); cardPanel.setCardBounds(0, 0, dimension.frameWidth, dimension.frameHeight); return cardPanel; @@ -85,7 +85,7 @@ public class CardPluginImpl implements CardPlugin { @Override public MagePermanent getMageCard(CardView permanent, CardDimensions dimension, UUID gameId, ActionCallback callback) { - CardPanel cardPanel = new CardPanel(permanent, true, callback); + CardPanel cardPanel = new CardPanel(permanent, gameId, true, callback); cardPanel.setShowCastingCost(true); cardPanel.setCardBounds(0, 0, dimension.frameWidth, dimension.frameHeight); return cardPanel;