Deck editor - renamed sort type "Color Detailed" to "Color Identity" and compare for the sort also with mana symbols in casting cost and rules.

This commit is contained in:
LevelX2 2015-09-21 00:31:42 +02:00
parent e94163a4c3
commit 322eae2ec6
6 changed files with 233 additions and 187 deletions

View file

@ -31,7 +31,6 @@
*
* Created on 30-Mar-2010, 9:25:40 PM
*/
package mage.client.cards;
import java.awt.Component;
@ -54,6 +53,7 @@ import mage.client.plugins.impl.Plugins;
import mage.client.util.Config;
import mage.client.util.Event;
import mage.client.util.Listener;
import mage.utils.CardUtil;
import mage.view.CardView;
import mage.view.CardsView;
import org.mage.card.arcane.CardPanel;
@ -144,7 +144,7 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
int curRow = 0;
if (cards.size() > 0) {
Rectangle rectangle = new Rectangle(Config.dimensions.frameWidth, Config.dimensions.frameHeight);
List<MageCard> sortedCards = new ArrayList<MageCard>(cards.values());
List<MageCard> sortedCards = new ArrayList<>(cards.values());
switch (sortSetting.getSortBy()) {
case NAME:
Collections.sort(sortedCards, new CardNameComparator());
@ -155,12 +155,13 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
case COLOR:
Collections.sort(sortedCards, new CardColorComparator());
break;
case COLOR_DETAILED:
Collections.sort(sortedCards, new CardColorDetailedComparator());
case COLOR_IDENTITY:
Collections.sort(sortedCards, new CardColorDetailedIdentity());
break;
case CASTING_COST:
Collections.sort(sortedCards, new CardCostComparator());
break;
}
MageCard lastCard = null;
for (MageCard cardImg : sortedCards) {
@ -187,8 +188,9 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
curRow = 0;
}
break;
case COLOR_DETAILED:
if (cardImg.getOriginal().getColor().hashCode() != lastCard.getOriginal().getColor().hashCode()) {
case COLOR_IDENTITY:
if (CardUtil.getColorIdentitySortValue(cardImg.getOriginal().getManaCost(), cardImg.getOriginal().getColor(), cardImg.getOriginal().getRules())
!= CardUtil.getColorIdentitySortValue(lastCard.getOriginal().getManaCost(), lastCard.getOriginal().getColor(), lastCard.getOriginal().getRules())) {
curColumn++;
curRow = 0;
}
@ -206,8 +208,7 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
moveToFront(cardImg);
curRow++;
lastCard = cardImg;
}
else {
} else {
rectangle.setLocation(curColumn * Config.dimensions.frameWidth, curRow * 20);
cardImg.setBounds(rectangle);
cardImg.setCardBounds(rectangle.x, rectangle.y, Config.dimensions.frameWidth, Config.dimensions.frameHeight);
@ -275,10 +276,10 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
cardEventSource.clearListeners();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
@ -296,10 +297,8 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2 && !e.isConsumed()) {
@ -322,16 +321,20 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
}
@Override
public void mousePressed(MouseEvent e) {}
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {}
public void mouseExited(MouseEvent e) {
}
private void resizeArea() {
Dimension area = new Dimension(0, 0);
@ -379,8 +382,7 @@ class CardRarityComparator implements Comparator<MageCard> {
int val = o1.getOriginal().getRarity().compareTo(o2.getOriginal().getRarity());
if (val == 0) {
return o1.getOriginal().getName().compareTo(o2.getOriginal().getName());
}
else {
} else {
return val;
}
}
@ -394,8 +396,7 @@ class CardCostComparator implements Comparator<MageCard> {
int val = Integer.valueOf(o1.getOriginal().getConvertedManaCost()).compareTo(Integer.valueOf(o2.getOriginal().getConvertedManaCost()));
if (val == 0) {
return o1.getOriginal().getName().compareTo(o2.getOriginal().getName());
}
else {
} else {
return val;
}
}
@ -409,23 +410,22 @@ class CardColorComparator implements Comparator<MageCard> {
int val = o1.getOriginal().getColor().compareTo(o2.getOriginal().getColor());
if (val == 0) {
return o1.getOriginal().getName().compareTo(o2.getOriginal().getName());
}
else {
} else {
return val;
}
}
}
class CardColorDetailedComparator implements Comparator<MageCard> {
class CardColorDetailedIdentity implements Comparator<MageCard> {
@Override
public int compare(MageCard o1, MageCard o2) {
int val = o1.getOriginal().getColor().hashCode() - o2.getOriginal().getColor().hashCode();
int val = CardUtil.getColorIdentitySortValue(o1.getOriginal().getManaCost(), o1.getOriginal().getColor(), o1.getOriginal().getRules())
- CardUtil.getColorIdentitySortValue(o2.getOriginal().getManaCost(), o2.getOriginal().getColor(), o2.getOriginal().getRules());
if (val == 0) {
return o1.getOriginal().getName().compareTo(o2.getOriginal().getName());
}
else {
} else {
return val;
}
}

View file

@ -31,7 +31,6 @@
*
* Created on Dec 18, 2009, 10:40:12 AM
*/
package mage.client.cards;
import java.awt.Color;
@ -59,7 +58,7 @@ import mage.client.constants.Constants.DeckEditorMode;
import mage.client.constants.Constants.SortBy;
import static mage.client.constants.Constants.SortBy.CASTING_COST;
import static mage.client.constants.Constants.SortBy.COLOR;
import static mage.client.constants.Constants.SortBy.COLOR_DETAILED;
import static mage.client.constants.Constants.SortBy.COLOR_IDENTITY;
import static mage.client.constants.Constants.SortBy.RARITY;
import mage.client.deckeditor.SortSetting;
import mage.client.deckeditor.table.TableModel;
@ -67,7 +66,7 @@ import mage.client.deckeditor.table.UpdateCountsCallback;
import mage.client.dialog.PreferencesDialog;
import mage.client.plugins.impl.Plugins;
import mage.client.util.CardViewColorComparator;
import mage.client.util.CardViewColorDetailedComparator;
import mage.client.util.CardViewColorIdentityComparator;
import mage.client.util.CardViewCostComparator;
import mage.client.util.CardViewNameComparator;
import mage.client.util.CardViewRarityComparator;
@ -99,7 +98,9 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
private JTable mainTable;
private ICardGrid currentView;
/** Creates new form Cards */
/**
* Creates new form Cards
*/
public CardsList() {
initComponents();
makeTransparent();
@ -256,7 +257,6 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
return list;
}
public void loadCards(CardsView showCards, BigCard bigCard, UUID gameId) {
int selectedRow = -1;
if (currentView.equals(mainModel)) {
@ -301,8 +301,7 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
if (oldMageCards.containsKey(uuid)) {
mageCards.put(uuid, oldMageCards.get(uuid));
oldMageCards.remove(uuid);
}
else{
} else {
mageCards.put(uuid, addCard(cards.get(uuid), bigCard, gameId));
}
}
@ -324,8 +323,8 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
case COLOR:
comparator = new CardViewColorComparator();
break;
case COLOR_DETAILED:
comparator = new CardViewColorDetailedComparator();
case COLOR_IDENTITY:
comparator = new CardViewColorIdentityComparator();
break;
case CASTING_COST:
comparator = new CardViewCostComparator();
@ -419,7 +418,6 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
return cardImg;
}
private void setCardBounds(MageCard card, Rectangle rectangle) {
card.setBounds(rectangle);
card.setCardBounds(rectangle.x, rectangle.y, Config.dimensions.frameWidth, Config.dimensions.frameHeight);
@ -456,10 +454,10 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
mainModel.clearCardEventListeners();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
@ -732,15 +730,13 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
if (obj instanceof Card) {
if (e.isAltDown()) {
cardEventSource.altDoubleClick(((Card) obj).getOriginal(), "alt-double-click");
}
else {
} else {
cardEventSource.doubleClick(((Card) obj).getOriginal(), "double-click");
}
} else if (obj instanceof MageCard) {
if (e.isAltDown()) {
cardEventSource.altDoubleClick(((MageCard) obj).getOriginal(), "alt-double-click");
}
else {
} else {
cardEventSource.doubleClick(((MageCard) obj).getOriginal(), "double-click");
}
}

View file

@ -25,7 +25,6 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.client.constants;
import java.io.File;
@ -37,6 +36,7 @@ import javax.swing.border.Border;
* @author BetaSteward_at_googlemail.com
*/
public final class Constants {
private Constants() {
throw new AssertionError();
}
@ -83,21 +83,24 @@ public final class Constants {
public static final String BASE_MUSICS_PATH = "music" + File.separator;
public interface IO {
String imageBaseDir = "plugins" + File.separator + "images" + File.separator;
String IMAGE_PROPERTIES_FILE = "image.url.properties";
}
public enum DeckEditorMode {
FREE_BUILDING,
LIMITED_BUILDING,
SIDEBOARDING
}
public enum SortBy {
CASTING_COST("Casting Cost"),
RARITY("Rarity"),
COLOR("Color"),
COLOR_DETAILED ("Color Detailed"),
COLOR_IDENTITY("Color Identity"),
NAME("Name"),
UNSORTED("Unsorted");
@ -120,8 +123,8 @@ public final class Constants {
return RARITY;
case "Color":
return COLOR;
case "Color Detailed":
return COLOR_DETAILED;
case "Color Identity":
return COLOR_IDENTITY;
case "Name":
return NAME;
default:

View file

@ -25,21 +25,31 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.client.util;
import java.util.Comparator;
import java.util.List;
import mage.ObjectColor;
import mage.view.CardView;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class CardViewColorDetailedComparator implements Comparator<CardView> {
public class CardViewColorIdentityComparator implements Comparator<CardView> {
@Override
public int compare(CardView o1, CardView o2) {
return o1.getColor().hashCode() - o2.getColor().hashCode();
return sortValue(o1.getManaCost(), o1.getColor()) - sortValue(o2.getManaCost(), o2.getColor());
}
static public int sortValue(List<String> manaCost, ObjectColor color) {
int hash = 3;
hash = 23 * hash + (color.isWhite() || manaCost.contains("{W}") ? 1 : 0);
hash = 23 * hash + (color.isBlue() || manaCost.contains("{U}") ? 1 : 0);
hash = 23 * hash + (color.isBlack() || manaCost.contains("{B}") ? 1 : 0);
hash = 23 * hash + (color.isRed() || manaCost.contains("{R}") ? 1 : 0);
hash = 23 * hash + (color.isGreen() || manaCost.contains("{G}") ? 1 : 0);
return hash;
}
}

View file

@ -25,7 +25,6 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.client.util;
import java.util.Comparator;
@ -39,7 +38,7 @@ public class CardViewCostComparator implements Comparator<CardView> {
@Override
public int compare(CardView o1, CardView o2) {
return Integer.valueOf(o1.getConvertedManaCost()).compareTo(Integer.valueOf(o2.getConvertedManaCost()));
return Integer.valueOf(o1.getConvertedManaCost()).compareTo(o2.getConvertedManaCost());
}
}

View file

@ -1,5 +1,7 @@
package mage.utils;
import java.util.List;
import mage.ObjectColor;
import mage.cards.Card;
import mage.cards.MagePermanent;
import mage.constants.CardType;
@ -13,6 +15,12 @@ import mage.view.CardView;
*/
public class CardUtil {
private static final String regexBlack = ".*\\x7b.{0,2}B.{0,2}\\x7d.*";
private static final String regexBlue = ".*\\x7b.{0,2}U.{0,2}\\x7d.*";
private static final String regexRed = ".*\\x7b.{0,2}R.{0,2}\\x7d.*";
private static final String regexGreen = ".*\\x7b.{0,2}G.{0,2}\\x7d.*";
private static final String regexWhite = ".*\\x7b.{0,2}W.{0,2}\\x7d.*";
public static boolean isCreature(CardView card) {
return is(card, CardType.CREATURE);
}
@ -48,4 +56,34 @@ public class CardUtil {
public static boolean isLand(Card card) {
return card.getCardType().contains(CardType.LAND);
}
public static int getColorIdentitySortValue(List<String> manaCost, ObjectColor originalColor, List<String> rules) {
ObjectColor color = new ObjectColor(originalColor);
for (String rule : rules) {
rule = rule.replaceAll("(?i)<i.*?</i>", ""); // Ignoring reminder text in italic
if (rule.matches(regexBlack)) {
color.setBlack(true);
}
if (rule.matches(regexBlue)) {
color.setBlue(true);
}
if (rule.matches(regexGreen)) {
color.setGreen(true);
}
if (rule.matches(regexRed)) {
color.setRed(true);
}
if (rule.matches(regexWhite)) {
color.setWhite(true);
}
}
int hash = 3;
hash = 23 * hash + (color.isWhite() || manaCost.contains("{W}") ? 1 : 0);
hash = 23 * hash + (color.isBlue() || manaCost.contains("{U}") ? 1 : 0);
hash = 23 * hash + (color.isBlack() || manaCost.contains("{B}") ? 1 : 0);
hash = 23 * hash + (color.isRed() || manaCost.contains("{R}") ? 1 : 0);
hash = 23 * hash + (color.isGreen() || manaCost.contains("{G}") ? 1 : 0);
return hash;
}
}