From 0697cbe24c343b1cc73ea09df06baab23a18f9f7 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Fri, 1 Feb 2019 18:57:24 +0400 Subject: [PATCH] UI: added draft rating column to deck editor --- .../deckeditor/table/MageCardComparator.java | 18 ++++++++++++------ .../client/deckeditor/table/TableModel.java | 9 ++++++--- .../main/java/mage/game/draft/RateCard.java | 4 ++++ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/table/MageCardComparator.java b/Mage.Client/src/main/java/mage/client/deckeditor/table/MageCardComparator.java index 11a8a9d24b..3c52cabeb4 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/table/MageCardComparator.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/table/MageCardComparator.java @@ -26,10 +26,12 @@ */ package mage.client.deckeditor.table; -import java.util.Comparator; - import mage.cards.MageCard; +import mage.game.draft.RateCard; import mage.view.CardView; +import org.apache.log4j.Logger; + +import java.util.Comparator; /** * {@link MageCard} comparator. Used to sort cards in Deck Editor Table View @@ -39,6 +41,8 @@ import mage.view.CardView; */ public class MageCardComparator implements Comparator { + private static final Logger logger = Logger.getLogger(MageCardComparator.class); + private final int column; private final boolean ascending; @@ -49,14 +53,12 @@ public class MageCardComparator implements Comparator { @Override public int compare(CardView a, CardView b) { - Comparable aCom = null; - Comparable bCom = null; + Comparable aCom = 1; + Comparable bCom = 1; switch (column) { // #skip case 0: - aCom = 1; - bCom = 1; break; // Name case 1: @@ -107,6 +109,10 @@ public class MageCardComparator implements Comparator { aCom = Integer.parseInt(a.getCardNumber().replaceAll("[\\D]", "")); bCom = Integer.parseInt(b.getCardNumber().replaceAll("[\\D]", "")); break; + case 9: + aCom = RateCard.rateCard(a.getOriginalCard(), null); + bCom = RateCard.rateCard(b.getOriginalCard(), null); + break; default: break; } diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/table/TableModel.java b/Mage.Client/src/main/java/mage/client/deckeditor/table/TableModel.java index 20e6513c1d..7ab42ac18a 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/table/TableModel.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/table/TableModel.java @@ -1,4 +1,3 @@ - package mage.client.deckeditor.table; import mage.client.MageFrame; @@ -13,6 +12,7 @@ import mage.client.util.Event; import mage.client.util.Listener; import mage.client.util.gui.GuiDisplayUtil; import mage.constants.EnlargeMode; +import mage.game.draft.RateCard; import mage.view.CardView; import mage.view.CardsView; import org.apache.log4j.Logger; @@ -25,8 +25,8 @@ import javax.swing.table.TableColumnModel; import java.awt.*; import java.awt.event.*; import java.awt.image.BufferedImage; -import java.util.*; import java.util.List; +import java.util.*; import java.util.Map.Entry; /** @@ -51,8 +51,9 @@ public class TableModel extends AbstractTableModel implements ICardGrid { private boolean displayNoCopies = false; private UpdateCountsCallback updateCountsCallback; - private final String column[] = {"Qty", "Name", "Cost", "Color", "Type", "Stats", "Rarity", "Set", "#"}; + private final String[] column = {"Qty", "Name", "Cost", "Color", "Type", "Stats", "Rarity", "Set", "Card number", "Draft Rating"}; public final int COLUMN_INDEX_COST = 2; + public final int COLUMN_INDEX_RATING = 9; private SortSetting sortSetting; private int recentSortedColumn; @@ -239,6 +240,8 @@ public class TableModel extends AbstractTableModel implements ICardGrid { return c.getExpansionSetCode(); case 8: return c.getCardNumber(); + case 9: + return RateCard.rateCard(c.getOriginalCard(), null); default: return "error"; } diff --git a/Mage/src/main/java/mage/game/draft/RateCard.java b/Mage/src/main/java/mage/game/draft/RateCard.java index 0de7de1886..59c2a46bb9 100644 --- a/Mage/src/main/java/mage/game/draft/RateCard.java +++ b/Mage/src/main/java/mage/game/draft/RateCard.java @@ -78,6 +78,10 @@ public final class RateCard { } public static int rateCard(Card card, List allowedColors, boolean useCache) { + if (card == null) { + return 0; + } + if (useCache && allowedColors == null && rated.containsKey(card.getName())) { int rate = rated.get(card.getName()); return rate;