Merge origin/master

This commit is contained in:
LevelX2 2017-11-24 12:30:52 +01:00
commit 95fd562fa0
2 changed files with 170 additions and 31 deletions

View file

@ -27,9 +27,7 @@
*/ */
package mage.client.deckeditor.collection.viewer; package mage.client.deckeditor.collection.viewer;
import mage.cards.Card; import mage.cards.*;
import mage.cards.CardDimensions;
import mage.cards.MageCard;
import mage.cards.repository.CardCriteria; import mage.cards.repository.CardCriteria;
import mage.cards.repository.CardInfo; import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository; import mage.cards.repository.CardRepository;
@ -38,9 +36,7 @@ import mage.client.MageFrame;
import mage.client.cards.BigCard; import mage.client.cards.BigCard;
import mage.client.components.HoverButton; import mage.client.components.HoverButton;
import mage.client.plugins.impl.Plugins; import mage.client.plugins.impl.Plugins;
import mage.client.util.Config; import mage.client.util.*;
import mage.client.util.ImageHelper;
import mage.client.util.NaturalOrderCardNumberComparator;
import mage.client.util.audio.AudioManager; import mage.client.util.audio.AudioManager;
import mage.client.util.sets.ConstructedFormats; import mage.client.util.sets.ConstructedFormats;
import mage.components.ImagePanel; import mage.components.ImagePanel;
@ -48,7 +44,6 @@ import mage.components.ImagePanelStyle;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.view.CardView; import mage.view.CardView;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.mage.card.arcane.GlowText;
import org.mage.card.arcane.ManaSymbols; import org.mage.card.arcane.ManaSymbols;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
@ -59,17 +54,17 @@ import java.io.FileNotFoundException;
import java.io.InputStream; import java.io.InputStream;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.*;
import java.util.List; 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.command.Emblem;
import mage.game.permanent.PermanentToken; import mage.game.permanent.PermanentToken;
import mage.game.permanent.token.Token; import mage.game.permanent.token.Token;
import mage.view.EmblemView; import mage.view.EmblemView;
import mage.view.PermanentView; import mage.view.PermanentView;
import org.mage.plugins.card.images.CardDownloadData; import org.mage.plugins.card.images.CardDownloadData;
import static java.lang.Math.min;
import static org.mage.plugins.card.images.DownloadPictures.getTokenCardUrls; 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); Image image = ImageHelper.loadImage(LEFT_PAGE_BUTTON_IMAGE_PATH);
pageLeft = new HoverButton(null, image, image, image, new Rectangle(64, 64)); 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.setBounds(0, 0, 64, 64);
pageLeft.setVisible(false); pageLeft.setVisible(false);
pageLeft.setObserver(() -> { pageLeft.setObserver(() -> {
@ -146,12 +142,46 @@ public class MageBook extends JComponent {
add(jPanelCenter, BorderLayout.CENTER); add(jPanelCenter, BorderLayout.CENTER);
add(jPanelRight, BorderLayout.LINE_END); 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); // Top Panel (left page + (caption / stats) + right page
jLayeredPane.add(pageRight, JLayeredPane.DEFAULT_LAYER, 1); 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() { private void addSetTabs() {
@ -174,7 +204,7 @@ public class MageBook extends JComponent {
if (setImage != null) { if (setImage != null) {
tab.setOverlayImage(setImage); tab.setOverlayImage(setImage);
} else { } 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.setSet(set);
tab.setBounds(0, y, 39, 120); tab.setBounds(0, y, 39, 120);
@ -217,8 +247,10 @@ public class MageBook extends JComponent {
private void showCardsOrTokens() { private void showCardsOrTokens() {
stateChanged = false; stateChanged = false;
if (showCardsOrTokens) { if (showCardsOrTokens) {
updateCardStats(currentSet, true);
showCards(); showCards();
} else { } else {
updateCardStats(currentSet, false);
int numTokens = showTokens(); int numTokens = showTokens();
showEmblems(numTokens); showEmblems(numTokens);
} }
@ -226,14 +258,16 @@ public class MageBook extends JComponent {
public void showCards() { public void showCards() {
jLayeredPane.removeAll(); jLayeredPane.removeAll();
addLeftRightPageButtons();
// stats info
updateCardStats(currentSet, true);
List<CardInfo> cards = getCards(currentPage, currentSet); List<CardInfo> cards = getCards(currentPage, currentSet);
int size = cards.size(); int size = cards.size();
Rectangle rectangle = new Rectangle(); Rectangle rectangle = new Rectangle();
rectangle.translate(OFFSET_X, OFFSET_Y); 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(); Card card = cards.get(i).getMockCard();
addCard(new CardView(card), bigCard, null, rectangle); 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; - (cardDimensions.frameWidth + CardPosition.GAP_X) * conf.CARD_COLUMNS + CardPosition.GAP_X - OFFSET_X;
rectangle.setLocation(second_page_x, OFFSET_Y); 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(); Card card = cards.get(i).getMockCard();
addCard(new CardView(card), bigCard, null, rectangle); addCard(new CardView(card), bigCard, null, rectangle);
rectangle = CardPosition.translatePosition(i - conf.CARDS_PER_PAGE / 2, rectangle, conf); rectangle = CardPosition.translatePosition(i - conf.CARDS_PER_PAGE / 2, rectangle, conf);
@ -256,7 +290,6 @@ public class MageBook extends JComponent {
public int showTokens() { public int showTokens() {
jLayeredPane.removeAll(); jLayeredPane.removeAll();
addLeftRightPageButtons();
List<Token> tokens = getTokens(currentPage, currentSet); List<Token> tokens = getTokens(currentPage, currentSet);
int size = tokens.size(); int size = tokens.size();
@ -264,7 +297,7 @@ public class MageBook extends JComponent {
if (tokens != null && tokens.size() > 0) { if (tokens != null && tokens.size() > 0) {
Rectangle rectangle = new Rectangle(); Rectangle rectangle = new Rectangle();
rectangle.translate(OFFSET_X, OFFSET_Y); 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); Token token = tokens.get(i);
addToken(token, bigCard, null, rectangle); addToken(token, bigCard, null, rectangle);
rectangle = CardPosition.translatePosition(i, rectangle, conf); 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; - (cardDimensions.frameWidth + CardPosition.GAP_X) * conf.CARD_COLUMNS + CardPosition.GAP_X - OFFSET_X;
rectangle.setLocation(second_page_x, OFFSET_Y); 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); Token token = tokens.get(i);
addToken(token, bigCard, null, rectangle); addToken(token, bigCard, null, rectangle);
rectangle = CardPosition.translatePosition(i - conf.CARDS_PER_PAGE / 2, rectangle, conf); 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; boolean implemented = card.getRarity() != Rarity.NA;
// implemented label
// old code, nowadays app load only implemented cards (JayDi85, 23.11.2017)
/*
GlowText label = new GlowText(); GlowText label = new GlowText();
label.setGlow(implemented ? Color.green : NOT_IMPLEMENTED, 12, 0.0f); label.setGlow(implemented ? Color.green : NOT_IMPLEMENTED, 12, 0.0f);
label.setText(implemented ? "Implemented" : "Not implemented"); label.setText(implemented ? "Implemented" : "Not implemented");
int dx = implemented ? 15 : 5; int dx = implemented ? 15 : 5;
label.setBounds(rectangle.x + dx, rectangle.y + cardDimensions.frameHeight + 7, 110, 30); label.setBounds(rectangle.x + dx, rectangle.y + cardDimensions.frameHeight + 7, 110, 30);
jLayeredPane.add(label); 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) { 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); 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) { private List<Token> getTokens(int page, String set) {
ArrayList<CardDownloadData> allTokens = getTokenCardUrls(); ArrayList<CardDownloadData> allTokens = getTokenCardUrls();
ArrayList<Token> tokens = new ArrayList<>(); ArrayList<Token> tokens = new ArrayList<>();
@ -576,7 +677,6 @@ public class MageBook extends JComponent {
setSize(conf.WIDTH, conf.HEIGHT); setSize(conf.WIDTH, conf.HEIGHT);
setPreferredSize(new Dimension(conf.WIDTH, conf.HEIGHT)); setPreferredSize(new Dimension(conf.WIDTH, conf.HEIGHT));
setMinimumSize(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(); addSetTabs();
showCards(); showCards();
} }
@ -616,7 +716,7 @@ public class MageBook extends JComponent {
_3x3Configuration() { _3x3Configuration() {
this.WIDTH = 950; this.WIDTH = 950;
this.HEIGHT = 650; this.HEIGHT = 650 + 50; // + for caption
CARD_ROWS = 3; CARD_ROWS = 3;
CARD_COLUMNS = 3; CARD_COLUMNS = 3;
this.CARDS_PER_PAGE = 18; this.CARDS_PER_PAGE = 18;
@ -629,7 +729,7 @@ public class MageBook extends JComponent {
_4x4Configuration() { _4x4Configuration() {
this.WIDTH = 1250; this.WIDTH = 1250;
this.HEIGHT = 850; this.HEIGHT = 850 + 50; // + for caption
CARD_ROWS = 4; CARD_ROWS = 4;
CARD_COLUMNS = 4; CARD_COLUMNS = 4;
this.CARDS_PER_PAGE = 32; 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 JPanel jPanelLeft;
private ImagePanel jPanelCenter; private ImagePanel jPanelCenter;
private JPanel jPanelRight; private JPanel jPanelRight;
@ -648,6 +752,8 @@ public class MageBook extends JComponent {
private int currentPage = 0; private int currentPage = 0;
private String currentSet = "RTR"; private String currentSet = "RTR";
private int currentCardsInSet = 0;
private int currentCardsNotInSet = 0;
private static CardDimensions cardDimensions = new CardDimensions(1.2d); private static CardDimensions cardDimensions = new CardDimensions(1.2d);
private static final Logger log = Logger.getLogger(MageBook.class); private static final Logger log = Logger.getLogger(MageBook.class);

View file

@ -16,8 +16,8 @@ import java.util.regex.Pattern;
/** /**
* @author stravant@gmail.com * @author stravant@gmail.com
* <p> * <p>
* Various static utilities for use in the card renderer * Various static utilities for use in the card renderer
*/ */
public final class CardRendererUtils { public final class CardRendererUtils {
@ -52,6 +52,38 @@ public final class CardRendererUtils {
return bimage; return bimage;
} }
private static Color abitbrighter(Color c) {
int r = c.getRed();
int g = c.getGreen();
int b = c.getBlue();
int alpha = c.getAlpha();
int plus_r = (int) ((255 - r) / 2);
int plus_g = (int) ((255 - g) / 2);
int plus_b = (int) ((255 - b) / 2);
return new Color(r + plus_r,
g + plus_g,
b + plus_b,
alpha);
}
private static Color abitdarker(Color c) {
int r = c.getRed();
int g = c.getGreen();
int b = c.getBlue();
int alpha = c.getAlpha();
int plus_r = (int) ((255 - r) / 2);
int plus_g = (int) ((255 - g) / 2);
int plus_b = (int) ((255 - b) / 2);
return new Color(r - plus_r,
g - plus_g,
b - plus_b,
alpha);
}
// Draw a rounded box with a 2-pixel border // Draw a rounded box with a 2-pixel border
// Used on various card parts. // Used on various card parts.
public static void drawRoundedBox(Graphics2D g, int x, int y, int w, int h, int bevel, Paint border, Paint fill) { public static void drawRoundedBox(Graphics2D g, int x, int y, int w, int h, int bevel, Paint border, Paint fill) {
@ -68,10 +100,11 @@ public final class CardRendererUtils {
g.fillOval(x + 2, y + 2, bevel * 2 - 4, h - 4); g.fillOval(x + 2, y + 2, bevel * 2 - 4, h - 4);
g.fillOval(x + 2 + w - bevel * 2, y + 2, bevel * 2 - 4, h - 4); g.fillOval(x + 2 + w - bevel * 2, y + 2, bevel * 2 - 4, h - 4);
g.fillRect(x + bevel, y + 2, w - 2 * bevel, h - 4); g.fillRect(x + bevel, y + 2, w - 2 * bevel, h - 4);
g.setPaint(border); g.setPaint(fill);
g.setColor(g.getColor().brighter().brighter()); g.setColor(abitbrighter(g.getColor()));
g.drawLine(x + 1 + bevel, y + 1, x + 1 + bevel + w - 2 * bevel - 2, y + 1); g.drawLine(x + 1 + bevel, y + 1, x + 1 + bevel + w - 2 * bevel - 2, y + 1);
g.setColor(g.getColor().darker().darker()); g.setPaint(fill);
g.setColor(abitdarker(g.getColor()));
g.drawLine(x + 1 + bevel, y + h - 2, x + 1 + bevel + w - 2 * bevel - 2, y + h - 2); g.drawLine(x + 1 + bevel, y + h - 2, x + 1 + bevel + w - 2 * bevel - 2, y + h - 2);
} }