* Draft shows now cards to draft in optimized size. Added some elements to cardPanel only if needed. Removed some legacy code about foiled card display.

This commit is contained in:
LevelX2 2014-01-15 01:45:07 +01:00
parent 1c5f0c8b7f
commit e892d4388d
9 changed files with 123 additions and 108 deletions

View file

@ -470,15 +470,6 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis
return image;
}
@Override
public void setFoil(boolean foil) {
}
@Override
public boolean isFoil() {
return false;
}
@Override
public void setZone(String zone) {
//To change body of implemented methods use File | Settings | File Templates.

View file

@ -41,15 +41,16 @@ import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import mage.cards.CardDimensions;
import mage.cards.MageCard;
import mage.client.plugins.impl.Plugins;
import mage.client.util.CardViewRarityComparator;
import mage.client.util.Config;
import mage.client.util.Event;
import mage.client.util.Listener;
import mage.constants.Constants;
import mage.view.CardView;
import mage.view.CardsView;
import org.apache.log4j.Logger;
/**
*
@ -57,6 +58,8 @@ import mage.view.CardsView;
*/
public class DraftGrid extends javax.swing.JPanel implements MouseListener {
private static final Logger logger = Logger.getLogger(DraftGrid.class);
protected CardEventSource cardEventSource = new CardEventSource();
protected BigCard bigCard;
@ -68,30 +71,57 @@ public class DraftGrid extends javax.swing.JPanel implements MouseListener {
public void loadBooster(CardsView booster, BigCard bigCard) {
this.bigCard = bigCard;
this.removeAll();
int maxRows = 4;
int numColumns = 5;
int curColumn = 0;
int curRow = 0;
int offsetX = 5;
int offsetY = 3;
Rectangle rectangle = new Rectangle(Config.dimensions.frameWidth, Config.dimensions.frameHeight);
Dimension dimension = new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight);
List<CardView> sortedCards = new ArrayList<CardView>(booster.values());
Collections.sort(sortedCards, new CardViewRarityComparator());
for (CardView card: sortedCards) {
MageCard cardImg = Plugins.getInstance().getMageCard(card, bigCard, dimension, null, true);
cardImg.addMouseListener(this);
add(cardImg);
cardImg.update(card);
rectangle.setLocation(curColumn * (Config.dimensions.frameWidth + offsetX) + offsetX, curRow * (Config.dimensions.frameHeight + offsetY) + offsetY);
cardImg.setBounds(rectangle);
cardImg.setCardBounds(rectangle.x, rectangle.y, Config.dimensions.frameWidth, Config.dimensions.frameHeight);
curColumn++;
if (curColumn == numColumns) {
curColumn = 0;
curRow++;
CardDimensions cardDimension = null;
int maxCards;
double scale ;
for (int i = 1; i < maxRows; i++) {
scale = (double) (this.getHeight()/i) / Constants.FRAME_MAX_HEIGHT;
cardDimension = new CardDimensions(scale);
maxCards = this.getWidth() / (cardDimension.frameWidth + offsetX);
if ((maxCards * i) >= booster.size()) {
numColumns = booster.size() / i;
if (booster.size() % i > 0) {
numColumns++;
}
break;
}
}
repaint();
if (cardDimension != null) {
Rectangle rectangle = new Rectangle(cardDimension.frameWidth, cardDimension.frameHeight);
Dimension dimension = new Dimension(cardDimension.frameWidth, cardDimension.frameHeight);
List<CardView> sortedCards = new ArrayList<CardView>(booster.values());
Collections.sort(sortedCards, new CardViewRarityComparator());
for (CardView card: sortedCards) {
MageCard cardImg = Plugins.getInstance().getMageCard(card, bigCard, dimension, null, true);
cardImg.addMouseListener(this);
add(cardImg);
cardImg.update(card);
rectangle.setLocation(curColumn * (cardDimension.frameWidth + offsetX) + offsetX, curRow * (rectangle.height + offsetY) + offsetY);
cardImg.setBounds(rectangle);
cardImg.setCardBounds(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
curColumn++;
if (curColumn == numColumns) {
curColumn = 0;
curRow++;
}
}
repaint();
} else {
logger.warn("Draft Grid - no possible fit of cards");
}
}
public void addCardEventListener(Listener<Event> listener) {

View file

@ -16,7 +16,6 @@ import mage.client.util.ImageHelper;
import mage.client.util.gui.ArrowBuilder;
import mage.client.util.gui.GuiDisplayUtil;
import mage.components.CardInfoPane;
import mage.constants.Rarity;
import mage.remote.Session;
import mage.utils.ThreadUtils;
import mage.view.CardView;
@ -412,7 +411,7 @@ public class MageActionCallback implements ActionCallback {
if (image != null && image instanceof BufferedImage) {
// XXX: scaled to fit width
image = ImageHelper.getResizedImage((BufferedImage) image, bigCard.getWidth());
bigCard.setCard(card.getOriginal().getId(), image, card.getOriginal().getRules(), card.isFoil());
bigCard.setCard(card.getOriginal().getId(), image, card.getOriginal().getRules(), false);
if (card.getOriginal().isAbility()) {
bigCard.showTextComponent();
} else {

View file

@ -85,7 +85,7 @@ public class Config {
// cardScalingFactor = Double.valueOf(0.4);
// cardScalingFactorEnlarged = Double.valueOf(0.5);
// handScalingFactor = Double.valueOf(1.3);
// defaultGameType = p.getProperty("default-game-type", "Human");;
// defaultGameType = p.getProperty("default-game-type", "Human");
// defaultDeckPath = "";
// defaultOtherPlayerIndex = "1";
// defaultComputerName = "Computer";

View file

@ -25,6 +25,7 @@ import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.constants.Constants;
/**
* Main class for drawing Mage card object.
@ -71,7 +72,7 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
private GlowText ptText;
private boolean displayEnabled = true;
private boolean isAnimationPanel;
private int cardXOffset, cardYOffset, cardWidth, cardHeight;
public int cardXOffset, cardYOffset, cardWidth, cardHeight;
private boolean isSelected;
private boolean showCastingCost;
@ -99,10 +100,11 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
private boolean displayTitleAnyway;
public CardPanel(CardView newGameCard, UUID gameId, final boolean loadImage, ActionCallback callback, final boolean foil) {
public CardPanel(CardView newGameCard, UUID gameId, final boolean loadImage, ActionCallback callback, final boolean foil, Dimension dimension) {
this.gameCard = newGameCard;
this.callback = callback;
this.gameId = gameId;
this.setCardBounds(0, 0, dimension.width, dimension.height);
this.isPermanent = this.gameCard instanceof PermanentView;
if (isPermanent) {
@ -112,54 +114,58 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
//for container debug (don't remove)
//setBorder(BorderFactory.createLineBorder(Color.green));
buttonPanel = new JPanel();
buttonPanel.setLayout(null);
buttonPanel.setOpaque(false);
add(buttonPanel);
if (this.gameCard.canTransform()) {
buttonPanel = new JPanel();
buttonPanel.setLayout(null);
buttonPanel.setOpaque(false);
add(buttonPanel);
dayNightButton = new JButton("");
dayNightButton.setLocation(2, 2);
dayNightButton.setSize(25, 25);
dayNightButton = new JButton("");
dayNightButton.setLocation(2, 2);
dayNightButton.setSize(25, 25);
buttonPanel.setVisible(this.gameCard.canTransform());
buttonPanel.setVisible(this.gameCard.canTransform());
BufferedImage day = ImageManagerImpl.getInstance().getDayImage();
dayNightButton.setIcon(new ImageIcon(day));
BufferedImage day = ImageManagerImpl.getInstance().getDayImage();
dayNightButton.setIcon(new ImageIcon(day));
buttonPanel.add(dayNightButton);
buttonPanel.add(dayNightButton);
dayNightButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// if card is being rotated, ignore action performed
// if card is tapped, no visual transforming is possible (implementation limitation)
// if card is permanent, it will be rotated by Mage, so manual rotate should be possible
if (animationInProgress || isTapped() || isPermanent) {
if (isPermanent) {
JOptionPane.showMessageDialog(null, "You can't transform cards on battlefield.");
dayNightButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// if card is being rotated, ignore action performed
// if card is tapped, no visual transforming is possible (implementation limitation)
// if card is permanent, it will be rotated by Mage, so manual rotate should be possible
if (animationInProgress || isTapped() || isPermanent) {
if (isPermanent) {
JOptionPane.showMessageDialog(null, "You can't transform cards on battlefield.");
}
return;
}
return;
Animation.transformCard(CardPanel.this, CardPanel.this, true);
}
Animation.transformCard(CardPanel.this, CardPanel.this, true);
}
});
});
}
if (this.gameCard.isToken()) {
// token icon
iconPanel = new JPanel();
iconPanel.setLayout(null);
iconPanel.setOpaque(false);
add(iconPanel);
iconPanel = new JPanel();
iconPanel.setLayout(null);
iconPanel.setOpaque(false);
add(iconPanel);
tokenButton = new JButton("");
tokenButton.setLocation(2, 2);
tokenButton.setSize(25, 25);
tokenButton = new JButton("");
tokenButton.setLocation(2, 2);
tokenButton.setSize(25, 25);
iconPanel.setVisible(this.gameCard.isToken());
iconPanel.setVisible(this.gameCard.isToken());
BufferedImage tokenIconImage = ImageManagerImpl.getInstance().getTokenIconImage();
tokenButton.setIcon(new ImageIcon(tokenIconImage));
BufferedImage tokenIconImage = ImageManagerImpl.getInstance().getTokenIconImage();
tokenButton.setIcon(new ImageIcon(tokenIconImage));
iconPanel.add(tokenButton);
iconPanel.add(tokenButton);
}
setBackground(Color.black);
setOpaque(false);
@ -211,12 +217,11 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
if (!loadImage || gameCard.isFaceDown()) {
return;
}
BufferedImage srcImage = ImageCache.getThumbnail(gameCard);
BufferedImage srcImage = ImageCache.getImage(gameCard, getCardWidth(), getCardHeight());
if (srcImage != null) {
hasImage = true;
setText(gameCard);
setImage(srcImage);
setFoil(foil);
}
if (gameCard.isTransformed()) {
toggleTransformed();
@ -260,10 +265,6 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
}
}
@Override
public boolean isFoil() {
return this.isFoil;
}
@Override
public void setZone(String zone) {
@ -275,11 +276,6 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
return zone;
}
@Override
public void setFoil(boolean foil) {
this.isFoil = foil;
}
public void setScalingType(ScalingType scalingType) {
imagePanel.setScalingType(scalingType);
}
@ -303,12 +299,6 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
repaint();
}
public void setAttacking(boolean isAttacking) {
//TODO:uncomment
//this.gameCard.setAttacking(isAttacking);
repaint();
}
public boolean getSelected() {
return this.isSelected;
}
@ -427,12 +417,15 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
overlayPanel.setVisible(false);
}
buttonPanel.setLocation(cardXOffset + borderSize, cardYOffset + borderSize);
buttonPanel.setSize(cardWidth - borderSize * 2, cardHeight - borderSize * 2);
iconPanel.setLocation(cardXOffset + borderSize, cardYOffset + borderSize);
iconPanel.setSize(cardWidth - borderSize * 2, cardHeight - borderSize * 2);
if (buttonPanel != null) {
buttonPanel.setLocation(cardXOffset + borderSize, cardYOffset + borderSize);
buttonPanel.setSize(cardWidth - borderSize * 2, cardHeight - borderSize * 2);
dayNightButton.setLocation(0, cardHeight - 30);
}
if (iconPanel != null) {
iconPanel.setLocation(cardXOffset + borderSize, cardYOffset + borderSize);
iconPanel.setSize(cardWidth - borderSize * 2, cardHeight - borderSize * 2);
}
int fontHeight = Math.round(cardHeight * (27f / 680));
boolean showText = (!isAnimationPanel && fontHeight < 12);
titleText.setVisible(showText);
@ -450,8 +443,7 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
int offsetX = Math.round((CARD_SIZE_FULL.width - cardWidth) / 10.0f);
ptText.setLocation(cardXOffset + ptX - TEXT_GLOW_SIZE / 2 - offsetX, cardYOffset + ptY - TEXT_GLOW_SIZE / 2);
dayNightButton.setLocation(0, cardHeight - 30);
if (isAnimationPanel || cardWidth < 200) {
imagePanel.setScalingType(ScalingType.nearestNeighbor);
} else {
@ -465,7 +457,7 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
}
@Override
public void setCardBounds(int x, int y, int width, int height) {
public final void setCardBounds(int x, int y, int width, int height) {
cardWidth = width;
cardHeight = height;
int rotCenterX = Math.round(width / 2f);

View file

@ -79,9 +79,7 @@ public class CardPluginImpl implements CardPlugin {
@Override
public MagePermanent getMagePermanent(PermanentView permanent, Dimension dimension, UUID gameId, ActionCallback callback, boolean canBeFoil, boolean loadImage) {
boolean foil = canBeFoil && (new Random()).nextInt(5) == 0;
CardPanel cardPanel = new CardPanel(permanent, gameId, loadImage, callback, foil);
cardPanel.setCardBounds(0, 0, dimension.width, dimension.height);
CardPanel cardPanel = new CardPanel(permanent, gameId, loadImage, callback, false, dimension);
boolean implemented = !permanent.getRarity().equals(Rarity.NA);
cardPanel.setShowCastingCost(implemented);
return cardPanel;
@ -89,9 +87,7 @@ public class CardPluginImpl implements CardPlugin {
@Override
public MagePermanent getMageCard(CardView permanent, Dimension dimension, UUID gameId, ActionCallback callback, boolean canBeFoil, boolean loadImage) {
boolean foil = canBeFoil && (new Random()).nextInt(5) == 0;
CardPanel cardPanel = new CardPanel(permanent, gameId, loadImage, callback, foil);
cardPanel.setCardBounds(0, 0, dimension.width, dimension.height);
CardPanel cardPanel = new CardPanel(permanent, gameId, loadImage, callback, false, dimension);
boolean implemented = !permanent.getRarity().equals(Rarity.NA);
cardPanel.setShowCastingCost(implemented);
return cardPanel;

View file

@ -56,12 +56,13 @@ public class ImageCache {
@Override
public BufferedImage apply(String key) {
try {
boolean thumbnail = false;
boolean usesVariousArt = false;
if (key.endsWith("#usesVariousArt")) {
usesVariousArt = true;
key = key.replace("#usesVariousArt", "");
}
boolean thumbnail = false;
if (key.endsWith("#thumb")) {
thumbnail = true;
key = key.replace("#thumb", "");
@ -93,6 +94,7 @@ public class ImageCache {
}
TFile file = new TFile(path);
if (!file.exists()) {
log.warn("File does not exist: " + file.toString());
return null;
}
@ -100,7 +102,7 @@ public class ImageCache {
String thumbnailPath = buildThumbnailPath(path);
TFile thumbnailFile = new TFile(thumbnailPath);
if (thumbnailFile.exists()) {
//log.debug("loading thumbnail for " + key + ", path="+thumbnailPath);
log.debug("loading thumbnail for " + key + ", path="+thumbnailPath);
return loadImage(thumbnailFile);
} else {
BufferedImage image = loadImage(file);
@ -108,7 +110,7 @@ public class ImageCache {
if (image == null) {
return null;
}
//log.debug("creating thumbnail for " + key);
log.debug("creating thumbnail for " + key);
return makeThumbnail(image, thumbnailPath);
}
} else {
@ -156,7 +158,7 @@ public class ImageCache {
if (card.getUsesVariousArt()) {
key += "#usesVariousArt";
}
//log.debug("#key: " + key);
// log.debug("#key: " + key);
return getImage(key);
}
@ -165,7 +167,7 @@ public class ImageCache {
if (card.getUsesVariousArt()) {
key += "#usesVariousArt";
}
//log.debug("#key: " + key);
// log.debug("#key: " + key);
return getImage(key);
}
@ -213,6 +215,7 @@ public class ImageCache {
public static BufferedImage loadImage(TFile file) {
BufferedImage image = null;
if (!file.exists()) {
log.debug("File does not exist: " + file.toString());
return null;
}
try {
@ -297,9 +300,16 @@ public class ImageCache {
* Returns the image appropriate to display the card in the picture panel
*/
public static BufferedImage getImage(CardView card, int width, int height) {
if (Constants.THUMBNAIL_SIZE_FULL.width + 10 > width) {
return getThumbnail(card);
}
String key = getKey(card);
if (card.getUsesVariousArt()) {
key += "#usesVariousArt";
}
BufferedImage original = getImage(key);
if (original == null) {
log.warn(key + " not found");
return null;
}