forked from External/mage
Now StackAbilityView has sourceCard. Added displaying source card for abilities. Fixed arrows offsets. Added "source" blue arrows (target arrows are red). Fixed NullPointerException happen for AbilityPicker. Fixed random order of spells in stack. Code clean up.
This commit is contained in:
parent
a910b59399
commit
03cb41f2aa
10 changed files with 110 additions and 139 deletions
|
|
@ -11,6 +11,7 @@ import java.util.UUID;
|
|||
|
||||
import javax.swing.Popup;
|
||||
import javax.swing.PopupFactory;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import mage.cards.MageCard;
|
||||
import mage.cards.MagePermanent;
|
||||
|
|
@ -70,26 +71,45 @@ public class MageActionCallback implements ActionCallback {
|
|||
// Draw Arrows for targets
|
||||
List<UUID> targets = data.card.getTargets();
|
||||
if (targets != null) {
|
||||
Point parent = SwingUtilities.getRoot(data.component).getLocationOnScreen();
|
||||
Point me = new Point(data.locationOnScreen);
|
||||
me.translate(-parent.x, -parent.y);
|
||||
for (UUID uuid : targets) {
|
||||
//System.out.println("Getting play area panel for uuid: " + uuid);
|
||||
|
||||
PlayAreaPanel p = session.getGame().getPlayers().get(uuid);
|
||||
if (p != null) {
|
||||
Point target = p.getLocationOnScreen();
|
||||
Point me = data.locationOnScreen;
|
||||
target.translate(-parent.x, -parent.y);
|
||||
ArrowBuilder.addArrow((int)me.getX() + 35, (int)me.getY(), (int)target.getX() + 40, (int)target.getY() - 40, Color.red);
|
||||
} else {
|
||||
for (PlayAreaPanel pa : session.getGame().getPlayers().values()) {
|
||||
MagePermanent permanent = pa.getBattlefieldPanel().getPermanents().get(uuid);
|
||||
if (permanent != null) {
|
||||
Point target = permanent.getLocationOnScreen();
|
||||
Point me = data.locationOnScreen;
|
||||
target.translate(-parent.x, -parent.y);
|
||||
ArrowBuilder.addArrow((int)me.getX() + 35, (int)me.getY(), (int)target.getX() + 40, (int)target.getY() + 10, Color.red);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draw Arrows for source
|
||||
if (data.card.isAbility()) {
|
||||
Point parent = SwingUtilities.getRoot(data.component).getLocationOnScreen();
|
||||
Point me = new Point(data.locationOnScreen);
|
||||
me.translate(-parent.x, -parent.y);
|
||||
UUID uuid = data.card.getId();
|
||||
for (PlayAreaPanel pa : session.getGame().getPlayers().values()) {
|
||||
MagePermanent permanent = pa.getBattlefieldPanel().getPermanents().get(uuid);
|
||||
if (permanent != null) {
|
||||
Point source = permanent.getLocationOnScreen();
|
||||
source.translate(-parent.x, -parent.y);
|
||||
ArrowBuilder.addArrow((int)source.getX() + 40, (int)source.getY() + 10, (int)me.getX() + 35, (int)me.getY() + 20, Color.blue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -99,13 +119,18 @@ public class MageActionCallback implements ActionCallback {
|
|||
|
||||
MageCard card = (MageCard) data.component;
|
||||
if (card.getOriginal().getId() != bigCard.getCardId()) {
|
||||
synchronized (MageMouseAdapter.class) {
|
||||
synchronized (MageActionCallback.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();
|
||||
bigCard.showTextComponent();
|
||||
if (card.getOriginal().isAbility()) {
|
||||
bigCard.showTextComponent();
|
||||
} else {
|
||||
bigCard.hideTextComponent();
|
||||
};
|
||||
} else {
|
||||
JXPanel panel = GuiDisplayUtil.getDescription(card.getOriginal(), bigCard.getWidth(), bigCard.getHeight());
|
||||
panel.setVisible(true);
|
||||
|
|
|
|||
|
|
@ -1,47 +0,0 @@
|
|||
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.MageCard;
|
||||
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 MageCard) {
|
||||
MageCard selectedCard = (MageCard) 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
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.MageCard;
|
||||
import mage.client.cards.BigCard;
|
||||
import mage.client.plugins.impl.Plugins;
|
||||
import mage.client.util.ImageHelper;
|
||||
import mage.client.util.gui.GuiDisplayUtil;
|
||||
|
||||
import org.jdesktop.swingx.JXPanel;
|
||||
|
||||
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;}
|
||||
if (bigCard == null) {return;}
|
||||
Object o = parent.getComponentAt(e.getPoint());
|
||||
if (o instanceof MageCard) {
|
||||
MageCard card = (MageCard) o;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue