mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 10:40:06 -08:00
Fixed interfaces. Some changes to mouse handling (commented out for a while).
This commit is contained in:
parent
14c91ec9d9
commit
d9686a0a9b
6 changed files with 112 additions and 84 deletions
|
|
@ -145,6 +145,10 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis
|
||||||
return card.getId();
|
return card.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void update(PermanentView permanent) {
|
||||||
|
this.update(permanent.getOriginal());
|
||||||
|
}
|
||||||
|
|
||||||
public void update(CardView card) {
|
public void update(CardView card) {
|
||||||
this.card = card;
|
this.card = card;
|
||||||
Graphics2D gImage = image.createGraphics();
|
Graphics2D gImage = image.createGraphics();
|
||||||
|
|
@ -465,9 +469,4 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis
|
||||||
public void setCardBounds(int x, int y, int width, int height) {
|
public void setCardBounds(int x, int y, int width, int height) {
|
||||||
throw new RuntimeException("Not implemented");
|
throw new RuntimeException("Not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateCard(PermanentView card) {
|
|
||||||
update(card);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@ import mage.client.cards.BigCard;
|
||||||
import mage.client.cards.Permanent;
|
import mage.client.cards.Permanent;
|
||||||
import mage.client.plugins.impl.Plugins;
|
import mage.client.plugins.impl.Plugins;
|
||||||
import mage.client.util.Config;
|
import mage.client.util.Config;
|
||||||
|
import mage.client.util.DefaultActionCallback;
|
||||||
import mage.view.PermanentView;
|
import mage.view.PermanentView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -66,10 +67,50 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane implements Compon
|
||||||
private BigCard bigCard;
|
private BigCard bigCard;
|
||||||
private Map<String, JComponent> ui = new HashMap<String, JComponent>();
|
private Map<String, JComponent> ui = new HashMap<String, JComponent>();
|
||||||
|
|
||||||
|
//TODO: made it singleton
|
||||||
|
protected static DefaultActionCallback defaultCallback = new DefaultActionCallback();
|
||||||
|
|
||||||
/** Creates new form BattlefieldPanel */
|
/** Creates new form BattlefieldPanel */
|
||||||
public BattlefieldPanel(JScrollPane jScrollPane) {
|
public BattlefieldPanel(JScrollPane jScrollPane) {
|
||||||
ui.put("jScrollPane", jScrollPane);
|
ui.put("jScrollPane", jScrollPane);
|
||||||
initComponents();
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(UUID gameId, BigCard bigCard) {
|
public void init(UUID gameId, BigCard bigCard) {
|
||||||
|
|
@ -83,7 +124,7 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane implements Compon
|
||||||
addPermanent(permanent);
|
addPermanent(permanent);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
permanents.get(permanent.getId()).updateCard(permanent);
|
permanents.get(permanent.getId()).update(permanent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Iterator<Entry<UUID, MagePermanent>> i = permanents.entrySet().iterator(); i.hasNext();) {
|
for (Iterator<Entry<UUID, MagePermanent>> i = permanents.entrySet().iterator(); i.hasNext();) {
|
||||||
|
|
@ -100,6 +141,7 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane implements Compon
|
||||||
}
|
}
|
||||||
|
|
||||||
Plugins.getInstance().sortPermanents(ui, permanents.values());
|
Plugins.getInstance().sortPermanents(ui, permanents.values());
|
||||||
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addPermanent(PermanentView permanent) {
|
private void addPermanent(PermanentView permanent) {
|
||||||
|
|
@ -109,9 +151,9 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane implements Compon
|
||||||
perm.setBounds(findEmptySpace(new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight)));
|
perm.setBounds(findEmptySpace(new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight)));
|
||||||
}
|
}
|
||||||
permanents.put(permanent.getId(), perm);
|
permanents.put(permanent.getId(), perm);
|
||||||
this.add(perm);
|
this.add(perm, 10);
|
||||||
moveToFront(perm);
|
moveToFront(perm);
|
||||||
perm.updateCard(permanent);
|
perm.update(permanent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void groupAttachments(PermanentView permanent) {
|
private void groupAttachments(PermanentView permanent) {
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,11 @@ public class Plugins implements MagePlugins {
|
||||||
return cardPlugin.getMagePermanent(card, dimension, gameId, new ActionCallback() {
|
return cardPlugin.getMagePermanent(card, dimension, gameId, new ActionCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
defaultCallback.mouseClicked(e, gameId, MageFrame.getSession(), card);
|
//defaultCallback.mouseClicked(e, gameId, MageFrame.getSession(), card);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void mouseMoved(MouseEvent e) {
|
||||||
|
//defaultCallback.mouseClicked(e, gameId, MageFrame.getSession(), card);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -4,4 +4,5 @@ import java.awt.event.MouseEvent;
|
||||||
|
|
||||||
public interface ActionCallback {
|
public interface ActionCallback {
|
||||||
void mouseClicked(MouseEvent e);
|
void mouseClicked(MouseEvent e);
|
||||||
|
void mouseMoved(MouseEvent e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,7 @@
|
||||||
package mage.cards.interfaces;
|
package mage.cards.interfaces;
|
||||||
|
|
||||||
import java.awt.event.ComponentListener;
|
|
||||||
import java.awt.event.FocusListener;
|
|
||||||
import java.awt.event.MouseListener;
|
|
||||||
import java.awt.event.MouseMotionListener;
|
|
||||||
|
|
||||||
import mage.view.PermanentView;
|
import mage.view.PermanentView;
|
||||||
|
|
||||||
public interface PermanentInterface extends MouseMotionListener, MouseListener, FocusListener, ComponentListener {
|
public interface PermanentInterface {
|
||||||
void updateCard(PermanentView card);
|
void update(PermanentView card);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,11 @@ import java.awt.event.ComponentEvent;
|
||||||
import java.awt.event.FocusEvent;
|
import java.awt.event.FocusEvent;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.JRootPane;
|
import javax.swing.JRootPane;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
|
@ -26,12 +28,16 @@ import mage.cards.interfaces.ActionCallback;
|
||||||
import mage.utils.CardUtil;
|
import mage.utils.CardUtil;
|
||||||
import mage.view.PermanentView;
|
import mage.view.PermanentView;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
import org.mage.card.arcane.ScaledImagePanel.MultipassType;
|
import org.mage.card.arcane.ScaledImagePanel.MultipassType;
|
||||||
import org.mage.card.arcane.ScaledImagePanel.ScalingType;
|
import org.mage.card.arcane.ScaledImagePanel.ScalingType;
|
||||||
|
|
||||||
@SuppressWarnings({"unchecked","rawtypes"})
|
@SuppressWarnings({"unchecked","rawtypes"})
|
||||||
public class CardPanel extends MagePermanent {
|
public class CardPanel extends MagePermanent {
|
||||||
private static final long serialVersionUID = -3272134219262184410L;
|
private static final long serialVersionUID = -3272134219262184410L;
|
||||||
|
|
||||||
|
private static final Logger log = Logger.getLogger(CardPanel.class);
|
||||||
|
|
||||||
static public final double TAPPED_ANGLE = Math.PI / 2;
|
static public final double TAPPED_ANGLE = Math.PI / 2;
|
||||||
static public final float ASPECT_RATIO = 3.5f / 2.5f;
|
static public final float ASPECT_RATIO = 3.5f / 2.5f;
|
||||||
//static public final float ASPECT_RATIO = 1.0f;
|
//static public final float ASPECT_RATIO = 1.0f;
|
||||||
|
|
@ -73,11 +79,6 @@ public class CardPanel extends MagePermanent {
|
||||||
this.gameCard = newGameCard;
|
this.gameCard = newGameCard;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
|
|
||||||
addMouseListener(this);
|
|
||||||
addFocusListener(this);
|
|
||||||
addMouseMotionListener(this);
|
|
||||||
addComponentListener(this);
|
|
||||||
|
|
||||||
//for container debug (don't remove)
|
//for container debug (don't remove)
|
||||||
//setBorder(BorderFactory.createLineBorder(Color.green));
|
//setBorder(BorderFactory.createLineBorder(Color.green));
|
||||||
|
|
||||||
|
|
@ -127,14 +128,23 @@ public class CardPanel extends MagePermanent {
|
||||||
|
|
||||||
Util.threadPool.submit(new Runnable() {
|
Util.threadPool.submit(new Runnable() {
|
||||||
public void run () {
|
public void run () {
|
||||||
BufferedImage srcImage = null; //TODO: ImageCache.getImageOriginal(gameCard);
|
//BufferedImage srcImage = null; //TODO: ImageCache.getImageOriginal(gameCard);
|
||||||
tappedAngle = gameCard.isTapped() ? CardPanel.TAPPED_ANGLE : 0;
|
tappedAngle = gameCard.isTapped() ? CardPanel.TAPPED_ANGLE : 0;
|
||||||
|
|
||||||
|
try {
|
||||||
|
log.info("loading image...");
|
||||||
|
BufferedImage srcImage = ImageIO.read(CardPanel.class.getClassLoader().getResourceAsStream("Mountain.40.full.jpg"));
|
||||||
|
srcImage = null;
|
||||||
|
log.info("done, image="+srcImage);
|
||||||
if (srcImage != null) {
|
if (srcImage != null) {
|
||||||
//setImage(srcImage, ImageUtil.getBlurredImage(srcImage, 3, 1.0f));
|
//setImage(srcImage, ImageUtil.getBlurredImage(srcImage, 3, 1.0f));
|
||||||
hasImage = true;
|
hasImage = true;
|
||||||
setText(gameCard);
|
setText(gameCard);
|
||||||
setImage(srcImage, srcImage);
|
setImage(srcImage, srcImage);
|
||||||
}
|
}
|
||||||
|
} catch (IOException io) {
|
||||||
|
io.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -143,7 +153,7 @@ public class CardPanel extends MagePermanent {
|
||||||
if (hasImage) {
|
if (hasImage) {
|
||||||
titleText.setText("");
|
titleText.setText("");
|
||||||
} else {
|
} else {
|
||||||
titleText.setText(card.getName());
|
titleText.setText(card.getName() + card.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -226,14 +236,11 @@ public class CardPanel extends MagePermanent {
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO:uncomment
|
//TODO:uncomment
|
||||||
/*
|
if (!hasImage /*&& gameCard.getTableID() > 0*/) {
|
||||||
if (!hasImage && gameCard.getTableID() > 0) {
|
|
||||||
g2d.setColor(new Color(30,200,200,120));
|
g2d.setColor(new Color(30,200,200,120));
|
||||||
} else {
|
} else {
|
||||||
g2d.setColor(new Color(0,0,0,200));
|
g2d.setColor(new Color(0,0,0,200));
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
g2d.setColor(new Color(30,200,200,120));
|
|
||||||
|
|
||||||
//for debug repainting
|
//for debug repainting
|
||||||
//g2d.setColor(new Color(MyRandom.random.nextInt(255),MyRandom.random.nextInt(255),MyRandom.random.nextInt(255),150));
|
//g2d.setColor(new Color(MyRandom.random.nextInt(255),MyRandom.random.nextInt(255),MyRandom.random.nextInt(255),150));
|
||||||
|
|
@ -259,6 +266,19 @@ public class CardPanel extends MagePermanent {
|
||||||
g2d.drawRoundRect(cardXOffset - i, cardYOffset - i + offset, cardWidth + i * 2 - 1, cardHeight + i * 2 - 1,
|
g2d.drawRoundRect(cardXOffset - i, cardYOffset - i + offset, cardWidth + i * 2 - 1, cardHeight + i * 2 - 1,
|
||||||
cornerSize, cornerSize);
|
cornerSize, cornerSize);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
Point component = getLocation();
|
||||||
|
|
||||||
|
int cx = getCardX() + component.x;
|
||||||
|
int cy = getCardY() + component.y;
|
||||||
|
int cw = getCardWidth();
|
||||||
|
int ch = getCardHeight();
|
||||||
|
|
||||||
|
System.out.println("x="+component.x);
|
||||||
|
|
||||||
|
g2d.setColor(Color.white);
|
||||||
|
g2d.drawRect(getCardX() - component.x, getCardY() - component.y, cw, ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void paintChildren (Graphics g) {
|
protected void paintChildren (Graphics g) {
|
||||||
|
|
@ -419,7 +439,7 @@ public class CardPanel extends MagePermanent {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateCard(PermanentView card) {
|
public void update(PermanentView card) {
|
||||||
if (this.gameCard.isTapped() != card.isTapped()) {
|
if (this.gameCard.isTapped() != card.isTapped()) {
|
||||||
Animation.tapCardToggle(this, this);
|
Animation.tapCardToggle(this, this);
|
||||||
}
|
}
|
||||||
|
|
@ -446,8 +466,7 @@ public class CardPanel extends MagePermanent {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean contains(int x, int y) {
|
public boolean contains(int x, int y) {
|
||||||
if (containsThis(x, y, true))
|
if (containsThis(x, y, true)) return true;
|
||||||
return true;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* if (attachedCount > 0) { for (MWCardImpl card :
|
* if (attachedCount > 0) { for (MWCardImpl card :
|
||||||
|
|
@ -458,70 +477,38 @@ public class CardPanel extends MagePermanent {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean containsThis(int x, int y, boolean root) {
|
public boolean containsThis(int x, int y, boolean root) {
|
||||||
int dy = getLocation().y;
|
//log.info("x="+x+", y="+y);
|
||||||
if (root) dy = 0;
|
Point component = getLocation();
|
||||||
int cx = getCardX();
|
|
||||||
int cy = getCardY() + dy;
|
//int dy = component.y;
|
||||||
|
//if (root) dy = 0;
|
||||||
|
|
||||||
|
int cx = getCardX() - component.x;
|
||||||
|
int cy = getCardY() - component.y;
|
||||||
int cw = getCardWidth();
|
int cw = getCardWidth();
|
||||||
int ch = getCardHeight();
|
int ch = getCardHeight();
|
||||||
if (isTapped()) {
|
if (isTapped()) {
|
||||||
|
//log.info("tapped");
|
||||||
cy = ch - cw + cx /*+ attachedDy*attachedCount*/;
|
cy = ch - cw + cx /*+ attachedDy*attachedCount*/;
|
||||||
ch = cw;
|
ch = cw;
|
||||||
cw = getCardHeight();
|
cw = getCardHeight();
|
||||||
}
|
}
|
||||||
//int dx = drawIcons ? 19 : 0;
|
//int dx = drawIcons ? 19 : 0;
|
||||||
int dx = 0;
|
//int dx = 0;
|
||||||
if (x >= cx && x <= cx + cw + dx && y >= cy && y <= cy + ch) {
|
|
||||||
|
if (x >= cx && x <= cx + cw && y >= cy && y <= cy + ch) {
|
||||||
|
//log.info("!cx="+cx+", cy="+cy+", dx="+cw +", ch="+ch);
|
||||||
|
//log.info(getOriginal().getId());
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
//log.info("cx="+cx+", cy="+cy+", dx="+cw +", ch="+ch);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PermanentView getOriginal() {
|
public PermanentView getOriginal() {
|
||||||
return this.gameCard;
|
return this.gameCard;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseDragged(MouseEvent e) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseMoved(MouseEvent e) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseClicked(MouseEvent e) {
|
|
||||||
System.out.println("clicked: " + this.gameCard.getId());
|
|
||||||
callback.mouseClicked(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseEntered(MouseEvent e) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseExited(MouseEvent e) { }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mousePressed(MouseEvent e) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseReleased(MouseEvent e) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void focusGained(FocusEvent e) { }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void focusLost(FocusEvent e) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void componentHidden(ComponentEvent e) { }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void componentMoved(ComponentEvent e) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void componentResized(ComponentEvent e) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void componentShown(ComponentEvent e) {}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue