Merge pull request #4191 from JayDi85/viewer-more-info

Add more card's info to viewer (mage book)
This commit is contained in:
spjspj 2017-11-24 21:02:47 +10:00 committed by GitHub
commit 8ab422f55c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -27,9 +27,7 @@
*/
package mage.client.deckeditor.collection.viewer;
import mage.cards.Card;
import mage.cards.CardDimensions;
import mage.cards.MageCard;
import mage.cards.*;
import mage.cards.repository.CardCriteria;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
@ -38,9 +36,7 @@ import mage.client.MageFrame;
import mage.client.cards.BigCard;
import mage.client.components.HoverButton;
import mage.client.plugins.impl.Plugins;
import mage.client.util.Config;
import mage.client.util.ImageHelper;
import mage.client.util.NaturalOrderCardNumberComparator;
import mage.client.util.*;
import mage.client.util.audio.AudioManager;
import mage.client.util.sets.ConstructedFormats;
import mage.components.ImagePanel;
@ -48,7 +44,6 @@ import mage.components.ImagePanelStyle;
import mage.constants.Rarity;
import mage.view.CardView;
import org.apache.log4j.Logger;
import org.mage.card.arcane.GlowText;
import org.mage.card.arcane.ManaSymbols;
import javax.imageio.ImageIO;
@ -59,17 +54,17 @@ import java.io.FileNotFoundException;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.*;
import java.util.List;
import java.util.UUID;
import java.util.logging.Level;
import mage.client.util.CardsViewUtil;
import mage.game.command.Emblem;
import mage.game.permanent.PermanentToken;
import mage.game.permanent.token.Token;
import mage.view.EmblemView;
import mage.view.PermanentView;
import org.mage.plugins.card.images.CardDownloadData;
import static java.lang.Math.min;
import static org.mage.plugins.card.images.DownloadPictures.getTokenCardUrls;
/**
@ -115,6 +110,7 @@ public class MageBook extends JComponent {
Image image = ImageHelper.loadImage(LEFT_PAGE_BUTTON_IMAGE_PATH);
pageLeft = new HoverButton(null, image, image, image, new Rectangle(64, 64));
//pageLeft.setBorder(BorderFactory.createLineBorder(new Color(180, 50, 0), 3, true)); //debug
pageLeft.setBounds(0, 0, 64, 64);
pageLeft.setVisible(false);
pageLeft.setObserver(() -> {
@ -146,12 +142,46 @@ public class MageBook extends JComponent {
add(jPanelCenter, BorderLayout.CENTER);
add(jPanelRight, BorderLayout.LINE_END);
cardDimensions = new CardDimensions(0.45d);
}
int captionHeight = Math.max(30, pageLeft.getHeight()); // caption size = next-prev images
private void addLeftRightPageButtons() {
jLayeredPane.add(pageLeft, JLayeredPane.DEFAULT_LAYER, 0);
jLayeredPane.add(pageRight, JLayeredPane.DEFAULT_LAYER, 1);
// Top Panel (left page + (caption / stats) + right page
jPanelTop = new JPanel();
jPanelTop.setLayout(new BorderLayout());
// jPanelTop.setBorder(BorderFactory.createLineBorder(new Color(180, 50, 150), 3, true)); // debug
jPanelTop.setPreferredSize(new Dimension(captionHeight, captionHeight));
jPanelCenter.add(jPanelTop, BorderLayout.NORTH);
// page left
pageRight.setPreferredSize(new Dimension(pageRight.getWidth(), pageRight.getHeight()));
jPanelTop.add(pageRight, BorderLayout.EAST);
// page right
pageLeft.setPreferredSize(new Dimension(pageLeft.getWidth(), pageLeft.getHeight()));
jPanelTop.add(pageLeft, BorderLayout.WEST);
// Caption Panel
jPanelCaption = new JPanel();
jPanelCaption.setLayout(new BorderLayout());
jPanelCaption.setOpaque(false);
jPanelTop.add(jPanelCaption, BorderLayout.CENTER);
// set's caption
setCaption = new JLabel();
setCaption.setHorizontalAlignment(SwingConstants.CENTER);
//setCaption.setBorder(BorderFactory.createLineBorder(new Color(180, 50, 150), 3, true)); // debug
setCaption.setFont(jLayeredPane.getFont().deriveFont(25f));
setCaption.setText("EMPTY CAPTION");
jPanelCaption.add(setCaption, BorderLayout.NORTH);
// set's info
setInfo = new JLabel();
setInfo.setHorizontalAlignment(SwingConstants.CENTER);
//setCaption.setBorder(BorderFactory.createLineBorder(new Color(180, 50, 150), 3, true)); // debug
setInfo.setFont(jLayeredPane.getFont().deriveFont(17f));
setInfo.setText("EMPTY STATS");
jPanelCaption.add(setInfo, BorderLayout.SOUTH);
cardDimensions = new CardDimensions(0.45d);
}
private void addSetTabs() {
@ -174,7 +204,7 @@ public class MageBook extends JComponent {
if (setImage != null) {
tab.setOverlayImage(setImage);
} else {
System.out.println("Couldn't find: " + "/plugins/images/sets/" + set + "-C.jpg");
System.out.println("Couldn't find symbol image: " + "/plugins/images/sets/" + set + "-C.jpg");
}
tab.setSet(set);
tab.setBounds(0, y, 39, 120);
@ -217,8 +247,10 @@ public class MageBook extends JComponent {
private void showCardsOrTokens() {
stateChanged = false;
if (showCardsOrTokens) {
updateCardStats(currentSet, true);
showCards();
} else {
updateCardStats(currentSet, false);
int numTokens = showTokens();
showEmblems(numTokens);
}
@ -226,14 +258,16 @@ public class MageBook extends JComponent {
public void showCards() {
jLayeredPane.removeAll();
addLeftRightPageButtons();
// stats info
updateCardStats(currentSet, true);
List<CardInfo> cards = getCards(currentPage, currentSet);
int size = cards.size();
Rectangle rectangle = new Rectangle();
rectangle.translate(OFFSET_X, OFFSET_Y);
for (int i = 0; i < Math.min(conf.CARDS_PER_PAGE / 2, size); i++) {
for (int i = 0; i < min(conf.CARDS_PER_PAGE / 2, size); i++) {
Card card = cards.get(i).getMockCard();
addCard(new CardView(card), bigCard, null, rectangle);
@ -245,7 +279,7 @@ public class MageBook extends JComponent {
- (cardDimensions.frameWidth + CardPosition.GAP_X) * conf.CARD_COLUMNS + CardPosition.GAP_X - OFFSET_X;
rectangle.setLocation(second_page_x, OFFSET_Y);
for (int i = conf.CARDS_PER_PAGE / 2; i < Math.min(conf.CARDS_PER_PAGE, size); i++) {
for (int i = conf.CARDS_PER_PAGE / 2; i < min(conf.CARDS_PER_PAGE, size); i++) {
Card card = cards.get(i).getMockCard();
addCard(new CardView(card), bigCard, null, rectangle);
rectangle = CardPosition.translatePosition(i - conf.CARDS_PER_PAGE / 2, rectangle, conf);
@ -256,7 +290,6 @@ public class MageBook extends JComponent {
public int showTokens() {
jLayeredPane.removeAll();
addLeftRightPageButtons();
List<Token> tokens = getTokens(currentPage, currentSet);
int size = tokens.size();
@ -264,7 +297,7 @@ public class MageBook extends JComponent {
if (tokens != null && tokens.size() > 0) {
Rectangle rectangle = new Rectangle();
rectangle.translate(OFFSET_X, OFFSET_Y);
for (int i = 0; i < Math.min(conf.CARDS_PER_PAGE / 2, size); i++) {
for (int i = 0; i < min(conf.CARDS_PER_PAGE / 2, size); i++) {
Token token = tokens.get(i);
addToken(token, bigCard, null, rectangle);
rectangle = CardPosition.translatePosition(i, rectangle, conf);
@ -275,7 +308,7 @@ public class MageBook extends JComponent {
- (cardDimensions.frameWidth + CardPosition.GAP_X) * conf.CARD_COLUMNS + CardPosition.GAP_X - OFFSET_X;
rectangle.setLocation(second_page_x, OFFSET_Y);
for (int i = conf.CARDS_PER_PAGE / 2; i < Math.min(conf.CARDS_PER_PAGE, size); i++) {
for (int i = conf.CARDS_PER_PAGE / 2; i < min(conf.CARDS_PER_PAGE, size); i++) {
Token token = tokens.get(i);
addToken(token, bigCard, null, rectangle);
rectangle = CardPosition.translatePosition(i - conf.CARDS_PER_PAGE / 2, rectangle, conf);
@ -346,12 +379,26 @@ public class MageBook extends JComponent {
boolean implemented = card.getRarity() != Rarity.NA;
// implemented label
// old code, nowadays app load only implemented cards (JayDi85, 23.11.2017)
/*
GlowText label = new GlowText();
label.setGlow(implemented ? Color.green : NOT_IMPLEMENTED, 12, 0.0f);
label.setText(implemented ? "Implemented" : "Not implemented");
int dx = implemented ? 15 : 5;
label.setBounds(rectangle.x + dx, rectangle.y + cardDimensions.frameHeight + 7, 110, 30);
jLayeredPane.add(label);
*/
// card number label
JLabel cardNumber = new JLabel();
int dy = -5; // image panel have empty space in bottom (bug?), need to move label up
cardNumber.setBounds(rectangle.x, rectangle.y + cardImg.getHeight() + dy, cardDimensions.frameWidth, 20);
cardNumber.setHorizontalAlignment(SwingConstants.CENTER);
//cardNumber.setBorder(BorderFactory.createLineBorder(new Color(180, 50, 150), 3, true));
cardNumber.setFont(jLayeredPane.getFont().deriveFont(jLayeredPane.getFont().getStyle() | Font.BOLD));
cardNumber.setText(card.getCardNumber());
jLayeredPane.add(cardNumber);
}
private void addToken(Token token, BigCard bigCard, UUID gameId, Rectangle rectangle) {
@ -389,6 +436,60 @@ public class MageBook extends JComponent {
return cards.subList(start, end);
}
private void updateCardStats(String setCode, boolean isCardsShow){
// sets do not have total cards number, it's a workaround
ExpansionSet set = Sets.findSet(setCode);
if (set != null){
setCaption.setText(set.getCode() + " - " + set.getName());
}else{
setCaption.setText("ERROR");
setInfo.setText("ERROR");
return;
}
if (!isCardsShow){
// tokens or emblems, stats not need
setInfo.setText("");
return;
}
// cards stats
int startNumber = 9999;
int endNumber = 0;
List<ExpansionSet.SetCardInfo> cards = set.getSetCardInfo();
// first run for numbers list
LinkedList<Integer> haveNumbers = new LinkedList<>();
for (ExpansionSet.SetCardInfo card: cards){
int cardNumber = Integer.parseInt(card.getCardNumber());
startNumber = min(startNumber, cardNumber);
endNumber = Math.max(endNumber, cardNumber);
haveNumbers.add(cardNumber);
}
// second run for empty numbers
int countHave = haveNumbers.size();
int countNotHave = 0;
if (cards.size() > 0){
for(int i = startNumber; i <= endNumber; i++){
if(!haveNumbers.contains(i)){
countNotHave++;
}
}
}
// result
setInfo.setText(String.format("Have %d cards of %d", countHave, countHave + countNotHave));
if (countNotHave > 0) {
setInfo.setForeground(new Color(150, 0, 0));
}else{
setInfo.setForeground(jLayeredPane.getForeground());
}
}
private List<Token> getTokens(int page, String set) {
ArrayList<CardDownloadData> allTokens = getTokenCardUrls();
ArrayList<Token> tokens = new ArrayList<>();
@ -576,7 +677,6 @@ public class MageBook extends JComponent {
setSize(conf.WIDTH, conf.HEIGHT);
setPreferredSize(new Dimension(conf.WIDTH, conf.HEIGHT));
setMinimumSize(new Dimension(conf.WIDTH, conf.HEIGHT));
pageRight.setBounds(conf.WIDTH - 2 * LEFT_RIGHT_PAGES_WIDTH - 64, 0, 64, 64);
addSetTabs();
showCards();
}
@ -616,7 +716,7 @@ public class MageBook extends JComponent {
_3x3Configuration() {
this.WIDTH = 950;
this.HEIGHT = 650;
this.HEIGHT = 650 + 50; // + for caption
CARD_ROWS = 3;
CARD_COLUMNS = 3;
this.CARDS_PER_PAGE = 18;
@ -629,7 +729,7 @@ public class MageBook extends JComponent {
_4x4Configuration() {
this.WIDTH = 1250;
this.HEIGHT = 850;
this.HEIGHT = 850 + 50; // + for caption
CARD_ROWS = 4;
CARD_COLUMNS = 4;
this.CARDS_PER_PAGE = 32;
@ -638,6 +738,10 @@ public class MageBook extends JComponent {
}
}
private JPanel jPanelTop;
private JPanel jPanelCaption;
private JLabel setCaption;
private JLabel setInfo;
private JPanel jPanelLeft;
private ImagePanel jPanelCenter;
private JPanel jPanelRight;
@ -648,6 +752,8 @@ public class MageBook extends JComponent {
private int currentPage = 0;
private String currentSet = "RTR";
private int currentCardsInSet = 0;
private int currentCardsNotInSet = 0;
private static CardDimensions cardDimensions = new CardDimensions(1.2d);
private static final Logger log = Logger.getLogger(MageBook.class);