mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
[card.plugin] unified mouse adapter. now tooltips should work.
This commit is contained in:
parent
fa99548105
commit
b501b10f9a
13 changed files with 205 additions and 57 deletions
|
|
@ -382,7 +382,7 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis
|
|||
List<UUID> 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) {
|
||||
|
|
|
|||
|
|
@ -58,7 +58,6 @@ import mage.view.CardsView;
|
|||
public class Cards extends javax.swing.JPanel {
|
||||
|
||||
private Map<UUID, MageCard> cards = new HashMap<UUID, MageCard>();
|
||||
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();
|
||||
|
|
|
|||
|
|
@ -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<UUID, PermanentView> battlefield) {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
18
Mage.Common/src/mage/cards/action/TransferData.java
Normal file
18
Mage.Common/src/mage/cards/action/TransferData.java
Normal file
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<UUID>();
|
||||
this.targets.add(targetUUID);
|
||||
System.out.println("Added target: " + targetUUID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue