[card.plugin] now replaces cards in deckeditor if used. removed debug logging.

This commit is contained in:
magenoxx 2010-11-22 13:02:36 +00:00
parent b501b10f9a
commit 08d020d998
4 changed files with 58 additions and 30 deletions

View file

@ -466,13 +466,13 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis
public void setAlpha(float transparency) {} public void setAlpha(float transparency) {}
@Override @Override
public PermanentView getOriginal() { public CardView getOriginal() {
throw new RuntimeException("Not implemented"); return card;
} }
@Override @Override
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"); // do nothing
} }
@Override @Override

View file

@ -40,15 +40,17 @@ import java.awt.Rectangle;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID; import java.util.UUID;
import java.util.Map.Entry;
import mage.cards.MageCard;
import mage.client.plugins.impl.Plugins;
import mage.client.util.Config; import mage.client.util.Config;
import mage.client.util.Event; import mage.client.util.Event;
import mage.client.util.Listener; import mage.client.util.Listener;
@ -64,7 +66,7 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener
protected CardEventSource cardEventSource = new CardEventSource(); protected CardEventSource cardEventSource = new CardEventSource();
protected BigCard bigCard; protected BigCard bigCard;
protected UUID gameId; protected UUID gameId;
private Map<UUID, Card> cards = new HashMap<UUID, Card>(); private Map<UUID, MageCard> cards = new HashMap<UUID, MageCard>();
public CardGrid() { public CardGrid() {
initComponents(); initComponents();
@ -75,15 +77,11 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener
this.gameId = gameId; this.gameId = gameId;
for (CardView card: showCards.values()) { for (CardView card: showCards.values()) {
if (!cards.containsKey(card.getId())) { if (!cards.containsKey(card.getId())) {
Card cardImg = new Card(card, bigCard, Config.dimensions, gameId); addCard(card, bigCard, gameId);
cardImg.addMouseListener(this);
add(cardImg);
cardImg.update(card);
cards.put(card.getId(), cardImg);
} }
} }
for (Iterator<Entry<UUID, Card>> i = cards.entrySet().iterator(); i.hasNext();) { for (Iterator<Entry<UUID, MageCard>> i = cards.entrySet().iterator(); i.hasNext();) {
Entry<UUID, Card> entry = i.next(); Entry<UUID, MageCard> entry = i.next();
if (!showCards.containsKey(entry.getKey())) { if (!showCards.containsKey(entry.getKey())) {
removeCard(entry.getKey()); removeCard(entry.getKey());
i.remove(); i.remove();
@ -92,6 +90,15 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener
drawCards(); drawCards();
this.setVisible(true); this.setVisible(true);
} }
private void addCard(CardView card, BigCard bigCard, UUID gameId) {
MageCard cardImg = Plugins.getInstance().getMageCard(card, bigCard, Config.dimensions, gameId);
cards.put(card.getId(), cardImg);
cardImg.addMouseListener(this);
add(cardImg);
cardImg.update(card);
cards.put(card.getId(), cardImg);
}
public void drawCards() { public void drawCards() {
int maxWidth = this.getParent().getWidth(); int maxWidth = this.getParent().getWidth();
@ -100,11 +107,12 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener
int curRow = 0; int curRow = 0;
if (cards.size() > 0) { if (cards.size() > 0) {
Rectangle rectangle = new Rectangle(Config.dimensions.frameWidth, Config.dimensions.frameHeight); Rectangle rectangle = new Rectangle(Config.dimensions.frameWidth, Config.dimensions.frameHeight);
List<Card> sortedCards = new ArrayList<Card>(cards.values()); List<MageCard> sortedCards = new ArrayList<MageCard>(cards.values());
Collections.sort(sortedCards, new CardComparator()); Collections.sort(sortedCards, new CardComparator());
for (Card cardImg: sortedCards) { for (MageCard cardImg: sortedCards) {
rectangle.setLocation(curColumn * Config.dimensions.frameWidth, curRow * 20); rectangle.setLocation(curColumn * Config.dimensions.frameWidth, curRow * 20);
cardImg.setBounds(rectangle); cardImg.setBounds(rectangle);
cardImg.setCardBounds(rectangle.x, rectangle.y, Config.dimensions.frameWidth, Config.dimensions.frameHeight);
moveToFront(cardImg); moveToFront(cardImg);
curColumn++; curColumn++;
if (curColumn == numColumns) { if (curColumn == numColumns) {
@ -121,7 +129,11 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener
if (comp instanceof Card) { if (comp instanceof Card) {
if (((Card)comp).getCardId().equals(cardId)) { if (((Card)comp).getCardId().equals(cardId)) {
remove(comp); remove(comp);
} } else if (comp instanceof MageCard) {
if (((MageCard)comp).getOriginal().getId().equals(cardId)) {
remove(comp);
}
}
} }
} }
} }
@ -164,7 +176,12 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2 && !e.isConsumed()) { if (e.getClickCount() == 2 && !e.isConsumed()) {
e.consume(); e.consume();
cardEventSource.doubleClick(((Card)e.getSource()).getCardId(), "double-click"); Object obj = e.getSource();
if (obj instanceof Card) {
cardEventSource.doubleClick(((Card)obj).getCardId(), "double-click");
} else if (obj instanceof MageCard) {
cardEventSource.doubleClick(((MageCard)obj).getOriginal().getId(), "double-click");
}
} }
} }
@ -202,11 +219,11 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener
} }
} }
class CardComparator implements Comparator<Card> { class CardComparator implements Comparator<MageCard> {
@Override @Override
public int compare(Card o1, Card o2) { public int compare(MageCard o1, MageCard o2) {
return o1.card.getName().compareTo(o2.card.getName()); return o1.getOriginal().getName().compareTo(o2.getOriginal().getName());
} }
} }

View file

@ -40,6 +40,9 @@ import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;
import java.beans.Beans; import java.beans.Beans;
import java.util.UUID; import java.util.UUID;
import mage.cards.MageCard;
import mage.client.plugins.impl.Plugins;
import mage.client.util.Config; import mage.client.util.Config;
import mage.client.util.Event; import mage.client.util.Event;
import mage.client.util.Listener; import mage.client.util.Listener;
@ -60,17 +63,13 @@ public class CardsList extends javax.swing.JPanel implements MouseListener {
} }
public void loadCards(CardsView showCards, BigCard bigCard, UUID gameId) { public void loadCards(CardsView showCards, BigCard bigCard, UUID gameId) {
//FIXME: why we remove all cards? for performance it's better to merge changes
cardArea.removeAll(); cardArea.removeAll();
if (showCards != null && showCards.size() > 0) { if (showCards != null && showCards.size() > 0) {
Rectangle rectangle = new Rectangle(Config.dimensions.frameWidth, Config.dimensions.frameHeight); Rectangle rectangle = new Rectangle(Config.dimensions.frameWidth, Config.dimensions.frameHeight);
int count = 0; int count = 0;
for (CardView card: showCards.values()) { for (CardView card: showCards.values()) {
Card cardImg = new Card(card, bigCard, Config.dimensions, gameId); addCard(card, bigCard, gameId, rectangle);
cardImg.setBounds(rectangle);
cardArea.add(cardImg);
cardArea.moveToFront(cardImg);
cardImg.update(card);
cardImg.addMouseListener(this);
if (count >= 10) { if (count >= 10) {
rectangle.translate(Config.dimensions.frameWidth, -200); rectangle.translate(Config.dimensions.frameWidth, -200);
count = 0; count = 0;
@ -87,7 +86,16 @@ public class CardsList extends javax.swing.JPanel implements MouseListener {
this.setVisible(true); this.setVisible(true);
} }
private void addCard(CardView card, BigCard bigCard, UUID gameId, Rectangle rectangle) {
MageCard cardImg = Plugins.getInstance().getMageCard(card, bigCard, Config.dimensions, gameId);
cardImg.setBounds(rectangle);
cardArea.add(cardImg);
cardArea.moveToFront(cardImg);
cardImg.update(card);
cardImg.addMouseListener(this);
cardImg.setCardBounds(rectangle.x, rectangle.y, Config.dimensions.frameWidth, Config.dimensions.frameHeight);
}
public void addCardEventListener(Listener<Event> listener) { public void addCardEventListener(Listener<Event> listener) {
cardEventSource.addListener(listener); cardEventSource.addListener(listener);
} }
@ -127,7 +135,12 @@ public class CardsList extends javax.swing.JPanel implements MouseListener {
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2 && !e.isConsumed()) { if (e.getClickCount() == 2 && !e.isConsumed()) {
e.consume(); e.consume();
cardEventSource.doubleClick(((Card)e.getSource()).getCardId(), "double-click"); Object obj = e.getSource();
if (obj instanceof Card) {
cardEventSource.doubleClick(((Card)obj).getCardId(), "double-click");
} else if (obj instanceof MageCard) {
cardEventSource.doubleClick(((MageCard)obj).getOriginal().getId(), "double-click");
}
} }
} }

View file

@ -45,8 +45,6 @@ public class MageActionCallback implements ActionCallback {
@Override @Override
public void mouseClicked(MouseEvent e, TransferData data) { public void mouseClicked(MouseEvent e, TransferData data) {
data.component.requestFocusInWindow(); 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); defaultCallback.mouseClicked(e, data.gameId, session, data.card);
} }