mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -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());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue