[card.plugin] now cards displayed on hand and stack (some stuff still needs to be updated). PLEASE DO REBUILD PLUGIN IF U USE mage-card-plugins.jar.

This commit is contained in:
magenoxx 2010-11-21 13:02:55 +00:00
parent 06b7e63843
commit 63d8231928
13 changed files with 168 additions and 62 deletions

View file

@ -479,4 +479,9 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis
public Image getImage() {
return image;
}
@Override
public PermanentView getOriginalPermanent() {
return null;
}
}

View file

@ -34,14 +34,23 @@
package mage.client.cards;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.MouseListener;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import javax.swing.BorderFactory;
import mage.cards.CardDimensions;
import mage.cards.MageCard;
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.view.CardView;
import mage.view.CardsView;
@ -52,8 +61,9 @@ import mage.view.CardsView;
*/
public class Cards extends javax.swing.JPanel {
private Map<UUID, Card> cards = new HashMap<UUID, Card>();
private Map<UUID, MageCard> cards = new HashMap<UUID, MageCard>();
private boolean mouseHandlingEnabled = false;
/** Creates new form Cards */
public Cards() {
initComponents();
@ -61,45 +71,86 @@ public class Cards extends javax.swing.JPanel {
jScrollPane1.setOpaque(false);
jScrollPane1.getViewport().setOpaque(false);
cardArea.setOpaque(false);
if (Plugins.getInstance().isCardPluginLoaded()) {
cardArea.setLayout(null);
}
}
public boolean loadCards(CardsView cardsView, BigCard bigCard, UUID gameId) {
boolean changed = false;
for (CardView card: cardsView.values()) {
if (!cards.containsKey(card.getId())) {
Card cardImg = new Card(card, bigCard, Config.dimensions, gameId);
cards.put(card.getId(), cardImg);
cardArea.add(cardImg);
addCard(card, bigCard, gameId);
changed = true;
}
cards.get(card.getId()).update(card);
}
for (Iterator<Entry<UUID, Card>> i = cards.entrySet().iterator(); i.hasNext();) {
Entry<UUID, Card> entry = i.next();
for (Iterator<Entry<UUID, MageCard>> i = cards.entrySet().iterator(); i.hasNext();) {
Entry<UUID, MageCard> entry = i.next();
if (!cardsView.containsKey(entry.getKey())) {
removeCard(entry.getKey());
i.remove();
changed = true;
}
}
if (!mouseHandlingEnabled) {
synchronized (this) {
if (!mouseHandlingEnabled) {
mouseHandlingEnabled = true;
//cardArea.addMouseListener(new MageMouseAdapter(this, gameId));
//cardArea.addMouseMotionListener(new MageMouseMotionAdapter(this, bigCard));
jScrollPane1.addMouseListener(new MageMouseAdapter(cardArea, gameId));
jScrollPane1.addMouseMotionListener(new MageMouseMotionAdapter(cardArea, bigCard));
//addMouseListener(new MageMouseAdapter(this, gameId));
}
}
}
cardArea.setPreferredSize(new Dimension(cards.size() * Config.dimensions.frameWidth, Config.dimensions.frameHeight));
cardArea.revalidate();
cardArea.repaint();
this.revalidate();
this.repaint();
if (changed) {
layoutCards(Config.dimensions);
}
return changed;
}
private void addCard(CardView card, BigCard bigCard, UUID gameId) {
MageCard cardImg = Plugins.getInstance().getMageCard(card, bigCard, Config.dimensions, gameId);
cards.put(card.getId(), cardImg);
cardArea.add(cardImg);
/*if (Plugins.getInstance().isCardPluginLoaded()) {
cardImg.setBorder(BorderFactory.createLineBorder(Color.red));
}*/
}
private void removeCard(UUID cardId) {
for (Component comp: cardArea.getComponents()) {
if (comp instanceof Card) {
if (((Card)comp).getCardId().equals(cardId)) {
cardArea.remove(comp);
}
} else if (comp instanceof MageCard) {
if (((MageCard)comp).getOriginal().equals(cardId)) {
cardArea.remove(comp);
}
}
}
}
private void layoutCards(CardDimensions dimension) {
if (Plugins.getInstance().isCardPluginLoaded()) {
int dx = 0;
for (MageCard card: cards.values()) {
card.setLocation(dx, 0);
card.setCardBounds(dx, 0, dimension.frameWidth, dimension.frameHeight);
dx += dimension.frameWidth + 5;
}
}
}
/** This method is called from within the constructor to

View file

@ -120,7 +120,7 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane implements Compon
}
private void addPermanent(PermanentView permanent) {
MagePermanent perm = Plugins.getInstance().getMagePermanent(permanent, bigCard, Config.dimensions, gameId);;
MagePermanent perm = Plugins.getInstance().getMagePermanent(permanent, bigCard, Config.dimensions, gameId);
perm.addComponentListener(this);
if (!Plugins.getInstance().isCardPluginLoaded()) {
perm.setBounds(findEmptySpace(new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight)));

View file

@ -9,8 +9,10 @@ import javax.swing.JComponent;
import mage.cards.Card;
import mage.cards.CardDimensions;
import mage.cards.MageCard;
import mage.cards.MagePermanent;
import mage.client.cards.BigCard;
import mage.view.CardView;
import mage.view.PermanentView;
public interface MagePlugins {
@ -19,6 +21,7 @@ public interface MagePlugins {
void updateGamePanel(Map<String, JComponent> ui);
JComponent updateTablePanel(Map<String, JComponent> ui);
MagePermanent getMagePermanent(PermanentView card, BigCard bigCard, CardDimensions dimension, UUID gameId);
MageCard getMageCard(CardView card, BigCard bigCard, CardDimensions dimension, UUID gameId);
boolean isThemePluginLoaded();
boolean isCardPluginLoaded();
boolean isCounterPluginLoaded();

View file

@ -1,23 +1,14 @@
package mage.client.plugins.adapters;
import java.awt.Color;
import java.awt.Component;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;
import java.util.UUID;
import javax.swing.Popup;
import javax.swing.PopupFactory;
import mage.cards.MagePermanent;
import mage.cards.MageCard;
import mage.client.MageFrame;
import mage.client.game.PlayAreaPanel;
import mage.client.plugins.impl.Plugins;
import mage.client.util.Config;
import mage.client.util.DefaultActionCallback;
import mage.client.util.gui.ArrowBuilder;
public class MageMouseAdapter extends MouseAdapter {
@ -38,8 +29,8 @@ public class MageMouseAdapter extends MouseAdapter {
int count = e.getClickCount();
if (count > 0) {
Object o = parent.getComponentAt(e.getPoint());
if (o instanceof MagePermanent) {
MagePermanent selectedCard = (MagePermanent) o;
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()

View file

@ -6,6 +6,7 @@ import java.awt.event.MouseEvent;
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;
@ -29,8 +30,8 @@ public class MageMouseMotionAdapter extends MouseMotionAdapter {
if (!Plugins.getInstance().isCardPluginLoaded()) {return;}
if (bigCard == null) {return;}
Object o = parent.getComponentAt(e.getPoint());
if (o instanceof MagePermanent) {
MagePermanent card = (MagePermanent) o;
if (o instanceof MageCard) {
MageCard card = (MageCard) o;
if (card.getOriginal().getId() != bigCard.getCardId()) {
synchronized (MageMouseAdapter.class) {
if (card.getOriginal().getId() != bigCard.getCardId()) {

View file

@ -10,11 +10,12 @@ import java.util.logging.Logger;
import javax.swing.JComponent;
import mage.cards.Card;
import mage.cards.CardDimensions;
import mage.cards.MageCard;
import mage.cards.MagePermanent;
import mage.cards.action.impl.EmptyCallback;
import mage.client.cards.BigCard;
import mage.client.cards.Card;
import mage.client.cards.Permanent;
import mage.client.plugins.MagePlugins;
import mage.client.util.Config;
@ -25,10 +26,10 @@ import mage.interfaces.plugin.CardPlugin;
import mage.interfaces.plugin.CounterPlugin;
import mage.interfaces.plugin.ThemePlugin;
import mage.util.Logging;
import mage.view.CardView;
import mage.view.PermanentView;
import net.xeoh.plugins.base.PluginManager;
import net.xeoh.plugins.base.impl.PluginManagerFactory;
import net.xeoh.plugins.base.util.PluginManagerUtil;
public class Plugins implements MagePlugins {
@ -73,7 +74,7 @@ public class Plugins implements MagePlugins {
}
@Override
public MagePermanent getMagePermanent(final PermanentView card, BigCard bigCard, CardDimensions dimension, final UUID gameId) {
public MagePermanent getMagePermanent(PermanentView card, BigCard bigCard, CardDimensions dimension, UUID gameId) {
if (cardPlugin != null) {
return cardPlugin.getMagePermanent(card, dimension, gameId, emptyCallback);
} else {
@ -81,6 +82,15 @@ 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);
} else {
return new Card(card, bigCard, Config.dimensions, gameId);
}
}
@Override
public boolean isCardPluginLoaded() {
return this.cardPlugin != null;
@ -92,7 +102,7 @@ public class Plugins implements MagePlugins {
}
@Override
public void downloadImage(Set<Card> allCards) {
public void downloadImage(Set<mage.cards.Card> allCards) {
if (this.cardPlugin != null) this.cardPlugin.downloadImages(allCards);
}