mirror of
https://github.com/correl/mage.git
synced 2025-01-13 11:01:58 +00:00
Added display of counters on card panel (needs probably some more fine adjusting and testing).
This commit is contained in:
parent
7c515ba60f
commit
d9a1cc1334
6 changed files with 219 additions and 53 deletions
|
@ -1,12 +1,40 @@
|
|||
package org.mage.card.arcane;
|
||||
|
||||
import de.schlichtherle.truezip.file.TFile;
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.awt.event.MouseWheelListener;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import mage.cards.MagePermanent;
|
||||
import mage.cards.TextPopup;
|
||||
import mage.cards.action.ActionCallback;
|
||||
import mage.cards.action.TransferData;
|
||||
import mage.client.plugins.adapters.MageActionCallback;
|
||||
import mage.client.plugins.impl.Plugins;
|
||||
import mage.client.util.ImageHelper;
|
||||
import mage.client.util.audio.AudioManager;
|
||||
import mage.components.ImagePanel;
|
||||
import mage.constants.AbilityType;
|
||||
|
@ -15,6 +43,7 @@ import mage.constants.EnlargeMode;
|
|||
import mage.utils.CardUtil;
|
||||
import mage.view.AbilityView;
|
||||
import mage.view.CardView;
|
||||
import mage.view.CounterView;
|
||||
import mage.view.PermanentView;
|
||||
import mage.view.StackAbilityView;
|
||||
import org.apache.log4j.Logger;
|
||||
|
@ -24,16 +53,6 @@ import org.mage.plugins.card.dl.sources.DirectLinksForDownload;
|
|||
import org.mage.plugins.card.images.ImageCache;
|
||||
import org.mage.plugins.card.utils.impl.ImageManagerImpl;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.view.CounterView;
|
||||
|
||||
/**
|
||||
* Main class for drawing Mage card object.
|
||||
*
|
||||
|
@ -45,6 +64,7 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
|
|||
|
||||
private static final Logger log = Logger.getLogger(CardPanel.class);
|
||||
|
||||
private static final int WIDTH_LIMIT = 90; // card width limit to create smaller counter
|
||||
public static final double TAPPED_ANGLE = Math.PI / 2;
|
||||
public static final double FLIPPED_ANGLE = Math.PI;
|
||||
public static final float ASPECT_RATIO = 3.5f / 2.5f;
|
||||
|
@ -71,11 +91,27 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
|
|||
public double flippedAngle = 0;
|
||||
public final ScaledImagePanel imagePanel;
|
||||
public ImagePanel overlayPanel;
|
||||
|
||||
public JPanel buttonPanel;
|
||||
public JPanel iconPanel;
|
||||
private JButton dayNightButton;
|
||||
|
||||
public JPanel copyIconPanel;
|
||||
public JLabel counterLabel;
|
||||
private JButton showCopySourceButton;
|
||||
|
||||
public JPanel iconPanel;
|
||||
private JButton typeButton;
|
||||
|
||||
public JPanel counterPanel;
|
||||
private JLabel loyaltyCounterLabel;
|
||||
private JLabel plusCounterLabel;
|
||||
private JLabel otherCounterLabel;
|
||||
private JLabel minusCounterLabel;
|
||||
private int loyaltyCounter;
|
||||
private int plusCounter;
|
||||
private int otherCounter;
|
||||
private int minusCounter;
|
||||
private int lastCardWidth;
|
||||
|
||||
private GlowText titleText;
|
||||
private GlowText ptText;
|
||||
private boolean displayEnabled = true;
|
||||
|
@ -106,10 +142,6 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
|
|||
private boolean transformed;
|
||||
private boolean animationInProgress = false;
|
||||
|
||||
private JButton dayNightButton;
|
||||
private JButton typeButton;
|
||||
private JButton showCopySourceButton;
|
||||
|
||||
private boolean displayTitleAnyway;
|
||||
|
||||
private JPanel cardArea;
|
||||
|
@ -159,6 +191,29 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
|
|||
});
|
||||
}
|
||||
|
||||
// panel to show counters on the card
|
||||
counterPanel = new JPanel();
|
||||
counterPanel.setLayout(null);
|
||||
counterPanel.setOpaque(false);
|
||||
add(counterPanel);
|
||||
|
||||
plusCounterLabel = new JLabel("");
|
||||
plusCounterLabel.setToolTipText("+1/+1");
|
||||
counterPanel.add(plusCounterLabel);
|
||||
|
||||
minusCounterLabel = new JLabel("");
|
||||
minusCounterLabel.setToolTipText("-1/-1");
|
||||
counterPanel.add(minusCounterLabel);
|
||||
|
||||
loyaltyCounterLabel = new JLabel("");
|
||||
loyaltyCounterLabel.setToolTipText("Loyalty");
|
||||
counterPanel.add(loyaltyCounterLabel);
|
||||
|
||||
otherCounterLabel = new JLabel("");
|
||||
counterPanel.add(otherCounterLabel);
|
||||
|
||||
counterPanel.setVisible(false);
|
||||
|
||||
if (newGameCard.isAbility()) {
|
||||
if (AbilityType.TRIGGERED.equals(newGameCard.getAbilityType())) {
|
||||
setTypeIcon(ImageManagerImpl.getInstance().getTriggeredAbilityImage(),"Triggered Ability");
|
||||
|
@ -308,7 +363,7 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
|
|||
// this holds reference to ActionCallback forever so set it to null to prevent
|
||||
this.callback = null;
|
||||
this.data = null;
|
||||
this.counterLabel = null;
|
||||
this.counterPanel = null;
|
||||
}
|
||||
|
||||
private void setText(CardView card) {
|
||||
|
@ -495,6 +550,26 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
|
|||
if (copyIconPanel != null) {
|
||||
copyIconPanel.setLocation(cardXOffset + borderSize, cardYOffset + borderSize);
|
||||
copyIconPanel.setSize(cardWidth - borderSize * 2, cardHeight - borderSize * 2);
|
||||
}
|
||||
if (counterPanel != null) {
|
||||
counterPanel.setLocation(cardXOffset + borderSize, cardYOffset + borderSize);
|
||||
counterPanel.setSize(cardWidth - borderSize * 2, cardHeight - borderSize * 2);
|
||||
int size = cardWidth > WIDTH_LIMIT ? 40: 20;
|
||||
|
||||
|
||||
minusCounterLabel.setLocation(counterPanel.getWidth() - size, counterPanel.getHeight() - size * 2);
|
||||
minusCounterLabel.setSize(size, size);
|
||||
|
||||
plusCounterLabel.setLocation(5, counterPanel.getHeight() - size * 2);
|
||||
plusCounterLabel.setSize(size, size);
|
||||
|
||||
loyaltyCounterLabel.setLocation(counterPanel.getWidth() - size, counterPanel.getHeight() - size);
|
||||
loyaltyCounterLabel.setSize(size, size);
|
||||
|
||||
otherCounterLabel.setLocation(5, counterPanel.getHeight() - size);
|
||||
otherCounterLabel.setSize(size, size);
|
||||
|
||||
|
||||
}
|
||||
int fontHeight = Math.round(cardHeight * (27f / 680));
|
||||
boolean showText = (!isAnimationPanel && fontHeight < 12);
|
||||
|
@ -741,32 +816,79 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
|
|||
}
|
||||
|
||||
|
||||
// if (card.getCounters() != null && !card.getCounters().isEmpty()) {
|
||||
// ImageIcon image = new ImageIcon(ImageManagerImpl.getInstance().getCounterImage());
|
||||
// String amount = "";
|
||||
// String name = "";
|
||||
// for (CounterView counterView:card.getCounters()) {
|
||||
// amount = Integer.toString(counterView.getCount());
|
||||
// name = counterView.getName();
|
||||
// break;
|
||||
// }
|
||||
// if (counterLabel == null) {
|
||||
// counterLabel = new JLabel(amount, image, JLabel.CENTER);
|
||||
// }
|
||||
// counterLabel.setToolTipText(name);
|
||||
// counterLabel.setLocation(50,50);
|
||||
//
|
||||
// this.add(counterLabel);
|
||||
// counterLabel.setVisible(true);
|
||||
// } else {
|
||||
// if (counterLabel != null) {
|
||||
// this.remove(counterLabel);
|
||||
// counterLabel = null;
|
||||
// }
|
||||
// }
|
||||
if (card.getCounters() != null && !card.getCounters().isEmpty()) {
|
||||
String name = "";
|
||||
if (lastCardWidth != cardWidth) {
|
||||
lastCardWidth = cardWidth;
|
||||
plusCounter = 0;
|
||||
minusCounter = 0;
|
||||
otherCounter = 0;
|
||||
loyaltyCounter = 0;
|
||||
}
|
||||
plusCounterLabel.setVisible(false);
|
||||
minusCounterLabel.setVisible(false);
|
||||
loyaltyCounterLabel.setVisible(false);
|
||||
otherCounterLabel.setVisible(false);
|
||||
for (CounterView counterView:card.getCounters()) {
|
||||
switch(counterView.getName()) {
|
||||
case "+1/+1":
|
||||
if (counterView.getCount() != plusCounter) {
|
||||
plusCounter = counterView.getCount();
|
||||
plusCounterLabel.setIcon(getCounterImageWithAmount(plusCounter, ImageManagerImpl.getInstance().getCounterImageGreen(), cardWidth));
|
||||
}
|
||||
plusCounterLabel.setVisible(true);
|
||||
break;
|
||||
case "-1/-1":
|
||||
if (counterView.getCount() != minusCounter) {
|
||||
minusCounter = counterView.getCount();
|
||||
minusCounterLabel.setIcon(getCounterImageWithAmount(minusCounter, ImageManagerImpl.getInstance().getCounterImageRed(), cardWidth));
|
||||
}
|
||||
minusCounterLabel.setVisible(true);
|
||||
break;
|
||||
case "Loyalty":
|
||||
if (counterView.getCount() != loyaltyCounter) {
|
||||
loyaltyCounter = counterView.getCount();
|
||||
loyaltyCounterLabel.setIcon(getCounterImageWithAmount(loyaltyCounter, ImageManagerImpl.getInstance().getCounterImageViolet(), cardWidth));
|
||||
}
|
||||
loyaltyCounterLabel.setVisible(true);
|
||||
break;
|
||||
default:
|
||||
if (name.isEmpty()) { // only first other counter is shown
|
||||
name = counterView.getName();
|
||||
otherCounter = counterView.getCount();
|
||||
otherCounterLabel.setToolTipText(name);
|
||||
otherCounterLabel.setIcon(getCounterImageWithAmount(otherCounter, ImageManagerImpl.getInstance().getCounterImageGrey(), cardWidth));
|
||||
otherCounterLabel.setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
counterPanel.setVisible(true);
|
||||
} else {
|
||||
plusCounterLabel.setVisible(false);
|
||||
minusCounterLabel.setVisible(false);
|
||||
loyaltyCounterLabel.setVisible(false);
|
||||
otherCounterLabel.setVisible(false);
|
||||
counterPanel.setVisible(false);
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
|
||||
private static ImageIcon getCounterImageWithAmount(int amount, BufferedImage image, int cardWidth) {
|
||||
int factor = cardWidth > WIDTH_LIMIT ? 2 :1;
|
||||
BufferedImage newImage;
|
||||
if (cardWidth > WIDTH_LIMIT) {
|
||||
newImage = ImageManagerImpl.deepCopy(image);
|
||||
} else {
|
||||
newImage = ImageHelper.getResizedImage(image, 20, 20);
|
||||
}
|
||||
Graphics graphics = newImage.getGraphics();
|
||||
graphics.setColor(Color.BLACK);
|
||||
graphics.setFont(new Font("Arial Black", Font.BOLD, factor * 9 ));
|
||||
graphics.drawString(Integer.toString(amount), 4 * factor, 11 * factor);
|
||||
return new ImageIcon(newImage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(int x, int y) {
|
||||
if (containsThis(x, y, true)) {
|
||||
|
|
|
@ -16,7 +16,10 @@ public interface ImageManager {
|
|||
Image getTriggeredAbilityImage();
|
||||
Image getActivatedAbilityImage();
|
||||
Image getCopyInformIconImage();
|
||||
Image getCounterImage();
|
||||
Image getCounterImageViolet();
|
||||
Image getCounterImageRed();
|
||||
Image getCounterImageGreen();
|
||||
Image getCounterImageGrey();
|
||||
|
||||
Image getDlgAcceptButtonImage();
|
||||
Image getDlgActiveAcceptButtonImage();
|
||||
|
|
|
@ -1,17 +1,21 @@
|
|||
package org.mage.plugins.card.utils.impl;
|
||||
|
||||
import mage.client.util.gui.BufferedImageBuilder;
|
||||
import org.mage.plugins.card.utils.ImageManager;
|
||||
import org.mage.plugins.card.utils.Transparency;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.Color;
|
||||
import java.awt.Image;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.CropImageFilter;
|
||||
import java.awt.image.FilteredImageSource;
|
||||
import java.awt.image.WritableRaster;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.imageio.ImageIO;
|
||||
import mage.client.util.gui.BufferedImageBuilder;
|
||||
import org.mage.plugins.card.utils.ImageManager;
|
||||
import org.mage.plugins.card.utils.Transparency;
|
||||
|
||||
public class ImageManagerImpl implements ImageManager {
|
||||
|
||||
|
@ -134,12 +138,39 @@ public class ImageManagerImpl implements ImageManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage getCounterImage() {
|
||||
if (imageCounter == null) {
|
||||
Image image = getImageFromResourceTransparent("/card/counter_green.png", Color.WHITE, new Rectangle(32, 32));
|
||||
imageCounter = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
public BufferedImage getCounterImageViolet() {
|
||||
if (imageCounterViolet == null) {
|
||||
Image image = getImageFromResourceTransparent("/card/counter_violet.png", Color.WHITE, new Rectangle(32, 32));
|
||||
imageCounterViolet = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return imageCounter;
|
||||
return imageCounterViolet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage getCounterImageGreen() {
|
||||
if (imageCounterGreen == null) {
|
||||
Image image = getImageFromResourceTransparent("/card/counter_green.png", Color.WHITE, new Rectangle(32, 32));
|
||||
imageCounterGreen = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return imageCounterGreen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage getCounterImageRed() {
|
||||
if (imageCounterRed == null) {
|
||||
Image image = getImageFromResourceTransparent("/card/counter_red.png", Color.WHITE, new Rectangle(32, 32));
|
||||
imageCounterRed = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return imageCounterRed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage getCounterImageGrey() {
|
||||
if (imageCounterGrey == null) {
|
||||
Image image = getImageFromResourceTransparent("/card/counter_grey.png", Color.WHITE, new Rectangle(32, 32));
|
||||
imageCounterGrey = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return imageCounterGrey;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -253,6 +284,13 @@ public class ImageManagerImpl implements ImageManager {
|
|||
return image;
|
||||
}
|
||||
|
||||
public static BufferedImage deepCopy(BufferedImage bi) {
|
||||
ColorModel cm = bi.getColorModel();
|
||||
boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
|
||||
WritableRaster raster = bi.copyData(null);
|
||||
return new BufferedImage(cm, raster, isAlphaPremultiplied, null);
|
||||
}
|
||||
|
||||
private static BufferedImage appImage;
|
||||
private static BufferedImage appSmallImage;
|
||||
private static BufferedImage appImageFlashed;
|
||||
|
@ -265,7 +303,10 @@ public class ImageManagerImpl implements ImageManager {
|
|||
private static BufferedImage triggeredAbilityIcon;
|
||||
private static BufferedImage activatedAbilityIcon;
|
||||
private static BufferedImage imageCopyIcon;
|
||||
private static BufferedImage imageCounter;
|
||||
private static BufferedImage imageCounterGreen;
|
||||
private static BufferedImage imageCounterGrey;
|
||||
private static BufferedImage imageCounterRed;
|
||||
private static BufferedImage imageCounterViolet;
|
||||
|
||||
private static BufferedImage imageDlgAcceptButton;
|
||||
private static BufferedImage imageDlgActiveAcceptButton;
|
||||
|
|
BIN
Mage.Client/src/main/resources/card/counter_grey.png
Normal file
BIN
Mage.Client/src/main/resources/card/counter_grey.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
BIN
Mage.Client/src/main/resources/card/counter_red.png
Normal file
BIN
Mage.Client/src/main/resources/card/counter_red.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
BIN
Mage.Client/src/main/resources/card/counter_violet.png
Normal file
BIN
Mage.Client/src/main/resources/card/counter_violet.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
Loading…
Reference in a new issue