mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 20:41:58 -08:00
...
This commit is contained in:
parent
c346276b0d
commit
ad50277430
24 changed files with 220 additions and 85 deletions
|
|
@ -53,10 +53,14 @@ public class BigCard extends javax.swing.JPanel {
|
|||
protected Image bigImage;
|
||||
protected UUID cardId;
|
||||
|
||||
public BigCard() {
|
||||
public BigCard() {
|
||||
initComponents();
|
||||
}
|
||||
|
||||
public void removeTextComponent() {
|
||||
remove(this.scrollPane);
|
||||
}
|
||||
|
||||
public void setCard(UUID cardId, Image image, List<String> strings) {
|
||||
if (this.cardId == null || !this.cardId.equals(cardId)) {
|
||||
this.cardId = cardId;
|
||||
|
|
@ -66,6 +70,10 @@ public class BigCard extends javax.swing.JPanel {
|
|||
}
|
||||
}
|
||||
|
||||
public UUID getCardId() {
|
||||
return cardId;
|
||||
}
|
||||
|
||||
private void drawText(java.util.List<String> strings) {
|
||||
text.setText("");
|
||||
StyledDocument doc = text.getStyledDocument();
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ import java.awt.Dimension;
|
|||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.RenderingHints;
|
||||
|
|
@ -97,7 +98,7 @@ import mage.view.StackAbilityView;
|
|||
public class Card extends MagePermanent implements MouseMotionListener, MouseListener, FocusListener, ComponentListener {
|
||||
|
||||
protected static Session session = MageFrame.getSession();
|
||||
protected static DefaultActionCallback callback = new DefaultActionCallback();
|
||||
protected static DefaultActionCallback callback = DefaultActionCallback.getInstance();
|
||||
|
||||
protected Point p;
|
||||
protected CardDimensions dimension;
|
||||
|
|
@ -469,4 +470,9 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis
|
|||
public void setCardBounds(int x, int y, int width, int height) {
|
||||
throw new RuntimeException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getImage() {
|
||||
return image;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,9 +36,14 @@ package mage.client.game;
|
|||
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Image;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.ComponentListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseMotionAdapter;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
|
@ -49,11 +54,16 @@ import javax.swing.JComponent;
|
|||
import javax.swing.JScrollPane;
|
||||
|
||||
import mage.cards.MagePermanent;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.cards.BigCard;
|
||||
import mage.client.cards.Card;
|
||||
import mage.client.cards.Permanent;
|
||||
import mage.client.plugins.adapters.MageMouseAdapter;
|
||||
import mage.client.plugins.adapters.MageMouseMotionAdapter;
|
||||
import mage.client.plugins.impl.Plugins;
|
||||
import mage.client.util.Config;
|
||||
import mage.client.util.DefaultActionCallback;
|
||||
import mage.client.util.ImageHelper;
|
||||
import mage.view.PermanentView;
|
||||
|
||||
/**
|
||||
|
|
@ -66,61 +76,32 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane implements Compon
|
|||
private UUID gameId;
|
||||
private BigCard bigCard;
|
||||
private Map<String, JComponent> ui = new HashMap<String, JComponent>();
|
||||
|
||||
//TODO: made it singleton
|
||||
protected static DefaultActionCallback defaultCallback = new DefaultActionCallback();
|
||||
|
||||
protected static DefaultActionCallback defaultCallback = DefaultActionCallback.getInstance();
|
||||
|
||||
/** Creates new form BattlefieldPanel */
|
||||
public BattlefieldPanel(JScrollPane jScrollPane) {
|
||||
ui.put("jScrollPane", jScrollPane);
|
||||
ui.put("battlefieldPanel", this);
|
||||
initComponents();
|
||||
|
||||
/*addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.getButton() == MouseEvent.BUTTON1) {
|
||||
int count = e.getClickCount();
|
||||
//System.out.println("pressed");
|
||||
if (count > 0) {
|
||||
Object o = getComponentAt(e.getPoint());
|
||||
//System.out.println("obj="+o);
|
||||
//System.out.println("e: "+e.getX());
|
||||
if (o instanceof MagePermanent) {
|
||||
System.out.println("ok");
|
||||
MagePermanent selectedCard = (MagePermanent) o;
|
||||
//TODO: uncomment when attached cards works in plugin
|
||||
/*
|
||||
int x = e.getX() - selectedCard.getX();
|
||||
int y = e.getY() - selectedCard.getY();
|
||||
CardView card = selectedCard.getCardByPosition(x, y);
|
||||
*/
|
||||
/*defaultCallback.mouseClicked(e, gameId, MageFrame.getSession(), selectedCard.getOriginal());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
System.out.println("e: "+e.getX());
|
||||
Object o = getComponentAt(e.getPoint());
|
||||
if (o instanceof MagePermanent) {
|
||||
MagePermanent card = (MagePermanent) o;
|
||||
System.out.println("card: "+card.getOriginal().getId());
|
||||
bigCard.setCard(card.getOriginal().getId(), null, card.getOriginal().getRules());
|
||||
}
|
||||
}
|
||||
});*/
|
||||
|
||||
addMouseListener(new MageMouseAdapter(this, gameId));
|
||||
addMouseMotionListener(new MageMouseMotionAdapter(this, bigCard));
|
||||
}
|
||||
|
||||
public void init(UUID gameId, BigCard bigCard) {
|
||||
this.gameId = gameId;
|
||||
this.bigCard = bigCard;
|
||||
if (Plugins.getInstance().isCardPluginLoaded()) {
|
||||
bigCard.removeTextComponent();
|
||||
}
|
||||
}
|
||||
|
||||
public void update(Map<UUID, PermanentView> battlefield) {
|
||||
for (PermanentView permanent: battlefield.values()) {
|
||||
if (!permanents.containsKey(permanent.getId())) {
|
||||
//TODO: remove me
|
||||
//System.out.println("Add permanent: " + permanent.getCardNumber());
|
||||
addPermanent(permanent);
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
package mage.client.plugins.adapters;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.UUID;
|
||||
|
||||
import mage.cards.MagePermanent;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.plugins.impl.Plugins;
|
||||
import mage.client.util.DefaultActionCallback;
|
||||
|
||||
public class MageMouseAdapter extends MouseAdapter {
|
||||
|
||||
private Component parent;
|
||||
private UUID gameId;
|
||||
protected static DefaultActionCallback defaultCallback = DefaultActionCallback.getInstance();
|
||||
|
||||
public MageMouseAdapter(Component parent, UUID gameId) {
|
||||
this.parent = parent;
|
||||
this.gameId = gameId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (!Plugins.getInstance().isCardPluginLoaded())
|
||||
return;
|
||||
if (e.getButton() == MouseEvent.BUTTON1) {
|
||||
int count = e.getClickCount();
|
||||
if (count > 0) {
|
||||
Object o = parent.getComponentAt(e.getPoint());
|
||||
if (o instanceof MagePermanent) {
|
||||
MagePermanent selectedCard = (MagePermanent) o;
|
||||
// TODO: uncomment when attached cards works in plugin
|
||||
/*
|
||||
* int x = e.getX() - selectedCard.getX(); int y = e.getY()
|
||||
* - selectedCard.getY(); CardView card =
|
||||
* selectedCard.getCardByPosition(x, y);
|
||||
*/
|
||||
defaultCallback.mouseClicked(e, gameId, MageFrame.getSession(), selectedCard.getOriginal());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
package mage.client.plugins.adapters;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Image;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseMotionAdapter;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import mage.cards.MagePermanent;
|
||||
import mage.client.cards.BigCard;
|
||||
import mage.client.plugins.impl.Plugins;
|
||||
import mage.client.util.ImageHelper;
|
||||
|
||||
public class MageMouseMotionAdapter extends MouseMotionAdapter {
|
||||
|
||||
private Component parent;
|
||||
private BigCard bigCard;
|
||||
|
||||
public MageMouseMotionAdapter(Component parent, BigCard bigCard) {
|
||||
this.parent = parent;
|
||||
this.bigCard = bigCard;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
if (!Plugins.getInstance().isCardPluginLoaded()) return;
|
||||
Object o = parent.getComponentAt(e.getPoint());
|
||||
if (o instanceof MagePermanent) {
|
||||
MagePermanent card = (MagePermanent) o;
|
||||
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());
|
||||
} else {
|
||||
//TODO: add description panel
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
package mage.client.plugins.impl;
|
||||
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
|
@ -12,12 +11,10 @@ import javax.swing.JComponent;
|
|||
|
||||
import mage.cards.CardDimensions;
|
||||
import mage.cards.MagePermanent;
|
||||
import mage.cards.interfaces.ActionCallback;
|
||||
import mage.client.MageFrame;
|
||||
import mage.cards.action.impl.EmptyCallback;
|
||||
import mage.client.cards.BigCard;
|
||||
import mage.client.cards.Permanent;
|
||||
import mage.client.plugins.MagePlugins;
|
||||
import mage.client.remote.Session;
|
||||
import mage.client.util.Config;
|
||||
import mage.client.util.DefaultActionCallback;
|
||||
import mage.constants.Constants;
|
||||
|
|
@ -36,7 +33,8 @@ public class Plugins implements MagePlugins {
|
|||
private static PluginManager pm;
|
||||
private final static Logger logger = Logging.getLogger(Plugins.class.getName());
|
||||
private CardPlugin cardPlugin = null;
|
||||
protected static DefaultActionCallback defaultCallback = new DefaultActionCallback();
|
||||
protected static DefaultActionCallback defaultCallback = DefaultActionCallback.getInstance();
|
||||
private static final EmptyCallback emptyCallback = new EmptyCallback();
|
||||
|
||||
public static MagePlugins getInstance() {
|
||||
return fINSTANCE;
|
||||
|
|
@ -68,16 +66,7 @@ public class Plugins implements MagePlugins {
|
|||
@Override
|
||||
public MagePermanent getMagePermanent(final PermanentView card, BigCard bigCard, CardDimensions dimension, final UUID gameId) {
|
||||
if (cardPlugin != null) {
|
||||
return cardPlugin.getMagePermanent(card, dimension, gameId, new ActionCallback() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//defaultCallback.mouseClicked(e, gameId, MageFrame.getSession(), card);
|
||||
}
|
||||
@Override
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
//defaultCallback.mouseClicked(e, gameId, MageFrame.getSession(), card);
|
||||
}
|
||||
});
|
||||
return cardPlugin.getMagePermanent(card, dimension, gameId, emptyCallback);
|
||||
} else {
|
||||
return new Permanent(card, bigCard, Config.dimensions, gameId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,15 @@ import mage.view.CardView;
|
|||
|
||||
|
||||
public class DefaultActionCallback {
|
||||
|
||||
private static final DefaultActionCallback INSTANCE = new DefaultActionCallback();
|
||||
|
||||
private DefaultActionCallback() {}
|
||||
|
||||
public static DefaultActionCallback getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public void mouseClicked(MouseEvent e, UUID gameId, Session session, CardView card) {
|
||||
System.out.println("gameId:" + gameId);
|
||||
if (gameId != null)
|
||||
|
|
|
|||
|
|
@ -52,6 +52,8 @@ import mage.view.AbilityView;
|
|||
import mage.view.CardView;
|
||||
import mage.view.StackAbilityView;
|
||||
|
||||
import com.mortennobel.imagescaling.ResampleOp;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
|
@ -299,4 +301,14 @@ public class ImageHelper {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an image scaled to the size appropriate for the card picture
|
||||
* panel
|
||||
*/
|
||||
public static BufferedImage getResizedImage(BufferedImage original, int width, int height) {
|
||||
ResampleOp resampleOp = new ResampleOp(width, height);
|
||||
BufferedImage image = resampleOp.filter(original, null);
|
||||
return image;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue