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 * Created on 30-Mar-2010, 9:25:40 PM
*/ */
package mage.client.cards; package mage.client.cards;
import java.awt.Component; import java.awt.Component;
@ -54,6 +53,7 @@ import mage.client.plugins.impl.Plugins;
import mage.client.util.Config; import mage.client.util.Config;
import mage.client.util.Event; import mage.client.util.Event;
import mage.client.util.Listener; import mage.client.util.Listener;
import mage.utils.CardUtil;
import mage.view.CardView; import mage.view.CardView;
import mage.view.CardsView; import mage.view.CardsView;
import org.mage.card.arcane.CardPanel; import org.mage.card.arcane.CardPanel;
@ -82,7 +82,7 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
} }
public void clear() { public void clear() {
for(MouseListener ml: this.getMouseListeners()) { for (MouseListener ml : this.getMouseListeners()) {
this.removeMouseListener(ml); this.removeMouseListener(ml);
} }
this.clearCardEventListeners(); this.clearCardEventListeners();
@ -101,7 +101,7 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
this.bigCard = bigCard; this.bigCard = bigCard;
this.gameId = gameId; this.gameId = gameId;
if (merge) { if (merge) {
for (CardView card: showCards.values()) { for (CardView card : showCards.values()) {
if (!cards.containsKey(card.getId())) { if (!cards.containsKey(card.getId())) {
addCard(card, bigCard, gameId, drawImage); addCard(card, bigCard, gameId, drawImage);
} }
@ -115,7 +115,7 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
} }
} else { } else {
this.clearCards(); this.clearCards();
for (CardView card: showCards.values()) { for (CardView card : showCards.values()) {
addCard(card, bigCard, gameId, drawImage); addCard(card, bigCard, gameId, drawImage);
} }
} }
@ -144,7 +144,7 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
int curRow = 0; int curRow = 0;
if (cards.size() > 0) { if (cards.size() > 0) {
Rectangle rectangle = new Rectangle(Config.dimensions.frameWidth, Config.dimensions.frameHeight); 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()) { switch (sortSetting.getSortBy()) {
case NAME: case NAME:
Collections.sort(sortedCards, new CardNameComparator()); Collections.sort(sortedCards, new CardNameComparator());
@ -155,15 +155,16 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
case COLOR: case COLOR:
Collections.sort(sortedCards, new CardColorComparator()); Collections.sort(sortedCards, new CardColorComparator());
break; break;
case COLOR_DETAILED: case COLOR_IDENTITY:
Collections.sort(sortedCards, new CardColorDetailedComparator()); Collections.sort(sortedCards, new CardColorDetailedIdentity());
break; break;
case CASTING_COST: case CASTING_COST:
Collections.sort(sortedCards, new CardCostComparator()); Collections.sort(sortedCards, new CardCostComparator());
break; break;
} }
MageCard lastCard = null; MageCard lastCard = null;
for (MageCard cardImg: sortedCards) { for (MageCard cardImg : sortedCards) {
if (sortSetting.isPilesToggle()) { if (sortSetting.isPilesToggle()) {
if (lastCard == null) { if (lastCard == null) {
lastCard = cardImg; lastCard = cardImg;
@ -187,8 +188,9 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
curRow = 0; curRow = 0;
} }
break; break;
case COLOR_DETAILED: case COLOR_IDENTITY:
if (cardImg.getOriginal().getColor().hashCode() != lastCard.getOriginal().getColor().hashCode()) { if (CardUtil.getColorIdentitySortValue(cardImg.getOriginal().getManaCost(), cardImg.getOriginal().getColor(), cardImg.getOriginal().getRules())
!= CardUtil.getColorIdentitySortValue(lastCard.getOriginal().getManaCost(), lastCard.getOriginal().getColor(), lastCard.getOriginal().getRules())) {
curColumn++; curColumn++;
curRow = 0; curRow = 0;
} }
@ -206,8 +208,7 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
moveToFront(cardImg); moveToFront(cardImg);
curRow++; curRow++;
lastCard = cardImg; lastCard = cardImg;
} } else {
else {
rectangle.setLocation(curColumn * Config.dimensions.frameWidth, curRow * 20); rectangle.setLocation(curColumn * Config.dimensions.frameWidth, curRow * 20);
cardImg.setBounds(rectangle); cardImg.setBounds(rectangle);
cardImg.setCardBounds(rectangle.x, rectangle.y, Config.dimensions.frameWidth, Config.dimensions.frameHeight); cardImg.setCardBounds(rectangle.x, rectangle.y, Config.dimensions.frameWidth, Config.dimensions.frameHeight);
@ -227,9 +228,9 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
private void clearCards() { private void clearCards() {
// remove possible mouse listeners, preventing gc // remove possible mouse listeners, preventing gc
for (MageCard mageCard: cards.values()) { for (MageCard mageCard : cards.values()) {
if (mageCard instanceof CardPanel) { if (mageCard instanceof CardPanel) {
((CardPanel)mageCard).cleanUp(); ((CardPanel) mageCard).cleanUp();
} }
} }
this.cards.clear(); this.cards.clear();
@ -237,7 +238,7 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
} }
private void removeAllCardImg() { private void removeAllCardImg() {
for (Component comp: getComponents()) { for (Component comp : getComponents()) {
if (comp instanceof Card || comp instanceof MageCard) { if (comp instanceof Card || comp instanceof MageCard) {
remove(comp); remove(comp);
} }
@ -245,14 +246,14 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
} }
private void removeCardImg(UUID cardId) { private void removeCardImg(UUID cardId) {
for (Component comp: getComponents()) { for (Component comp : getComponents()) {
if (comp instanceof Card) { if (comp instanceof Card) {
if (((Card)comp).getCardId().equals(cardId)) { if (((Card) comp).getCardId().equals(cardId)) {
remove(comp); remove(comp);
comp = null; comp = null;
} }
} else if (comp instanceof MageCard) { } else if (comp instanceof MageCard) {
if (((MageCard)comp).getOriginal().getId().equals(cardId)) { if (((MageCard) comp).getOriginal().getId().equals(cardId)) {
remove(comp); remove(comp);
comp = null; comp = null;
} }
@ -275,10 +276,10 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
cardEventSource.clearListeners(); cardEventSource.clearListeners();
} }
/** This method is called from within the constructor to /**
* initialize the form. * This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is * WARNING: Do NOT modify this code. The content of this method is always
* always regenerated by the Form Editor. * regenerated by the Form Editor.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents // <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 }// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2 && !e.isConsumed()) { if (e.getClickCount() == 2 && !e.isConsumed()) {
@ -322,22 +321,26 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
} }
@Override @Override
public void mousePressed(MouseEvent e) {} public void mousePressed(MouseEvent e) {
}
@Override @Override
public void mouseReleased(MouseEvent e) {} public void mouseReleased(MouseEvent e) {
}
@Override @Override
public void mouseEntered(MouseEvent e) {} public void mouseEntered(MouseEvent e) {
}
@Override @Override
public void mouseExited(MouseEvent e) {} public void mouseExited(MouseEvent e) {
}
private void resizeArea() { private void resizeArea() {
Dimension area = new Dimension(0, 0); Dimension area = new Dimension(0, 0);
Dimension size = getPreferredSize(); Dimension size = getPreferredSize();
for (Component comp: getComponents()) { for (Component comp : getComponents()) {
Rectangle r = comp.getBounds(); Rectangle r = comp.getBounds();
if (r.x + r.width > area.width) { if (r.x + r.width > area.width) {
area.width = r.x + r.width; area.width = r.x + r.width;
@ -379,8 +382,7 @@ class CardRarityComparator implements Comparator<MageCard> {
int val = o1.getOriginal().getRarity().compareTo(o2.getOriginal().getRarity()); int val = o1.getOriginal().getRarity().compareTo(o2.getOriginal().getRarity());
if (val == 0) { if (val == 0) {
return o1.getOriginal().getName().compareTo(o2.getOriginal().getName()); return o1.getOriginal().getName().compareTo(o2.getOriginal().getName());
} } else {
else {
return val; return val;
} }
} }
@ -394,8 +396,7 @@ class CardCostComparator implements Comparator<MageCard> {
int val = Integer.valueOf(o1.getOriginal().getConvertedManaCost()).compareTo(Integer.valueOf(o2.getOriginal().getConvertedManaCost())); int val = Integer.valueOf(o1.getOriginal().getConvertedManaCost()).compareTo(Integer.valueOf(o2.getOriginal().getConvertedManaCost()));
if (val == 0) { if (val == 0) {
return o1.getOriginal().getName().compareTo(o2.getOriginal().getName()); return o1.getOriginal().getName().compareTo(o2.getOriginal().getName());
} } else {
else {
return val; return val;
} }
} }
@ -409,23 +410,22 @@ class CardColorComparator implements Comparator<MageCard> {
int val = o1.getOriginal().getColor().compareTo(o2.getOriginal().getColor()); int val = o1.getOriginal().getColor().compareTo(o2.getOriginal().getColor());
if (val == 0) { if (val == 0) {
return o1.getOriginal().getName().compareTo(o2.getOriginal().getName()); return o1.getOriginal().getName().compareTo(o2.getOriginal().getName());
} } else {
else {
return val; return val;
} }
} }
} }
class CardColorDetailedComparator implements Comparator<MageCard> { class CardColorDetailedIdentity implements Comparator<MageCard> {
@Override @Override
public int compare(MageCard o1, MageCard o2) { 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) { if (val == 0) {
return o1.getOriginal().getName().compareTo(o2.getOriginal().getName()); return o1.getOriginal().getName().compareTo(o2.getOriginal().getName());
} } else {
else {
return val; return val;
} }
} }

View file

@ -1,37 +1,36 @@
/* /*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, are * Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met: * permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this list of * 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer. * conditions and the following disclaimer.
* *
* 2. Redistributions in binary form must reproduce the above copyright notice, this list * 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials * of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution. * provided with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* The views and conclusions contained in the software and documentation are those of the * The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
/* /*
* CardsList.java * CardsList.java
* *
* Created on Dec 18, 2009, 10:40:12 AM * Created on Dec 18, 2009, 10:40:12 AM
*/ */
package mage.client.cards; package mage.client.cards;
import java.awt.Color; import java.awt.Color;
@ -59,7 +58,7 @@ import mage.client.constants.Constants.DeckEditorMode;
import mage.client.constants.Constants.SortBy; import mage.client.constants.Constants.SortBy;
import static mage.client.constants.Constants.SortBy.CASTING_COST; 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;
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 static mage.client.constants.Constants.SortBy.RARITY;
import mage.client.deckeditor.SortSetting; import mage.client.deckeditor.SortSetting;
import mage.client.deckeditor.table.TableModel; import mage.client.deckeditor.table.TableModel;
@ -67,7 +66,7 @@ import mage.client.deckeditor.table.UpdateCountsCallback;
import mage.client.dialog.PreferencesDialog; import mage.client.dialog.PreferencesDialog;
import mage.client.plugins.impl.Plugins; import mage.client.plugins.impl.Plugins;
import mage.client.util.CardViewColorComparator; import mage.client.util.CardViewColorComparator;
import mage.client.util.CardViewColorDetailedComparator; import mage.client.util.CardViewColorIdentityComparator;
import mage.client.util.CardViewCostComparator; import mage.client.util.CardViewCostComparator;
import mage.client.util.CardViewNameComparator; import mage.client.util.CardViewNameComparator;
import mage.client.util.CardViewRarityComparator; import mage.client.util.CardViewRarityComparator;
@ -99,7 +98,9 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
private JTable mainTable; private JTable mainTable;
private ICardGrid currentView; private ICardGrid currentView;
/** Creates new form Cards */ /**
* Creates new form Cards
*/
public CardsList() { public CardsList() {
initComponents(); initComponents();
makeTransparent(); makeTransparent();
@ -115,22 +116,22 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
mainModel.removeTableModelListener(mainTable); mainModel.removeTableModelListener(mainTable);
mainModel.clear(); mainModel.clear();
} }
if(cardArea != null) { if (cardArea != null) {
for(MouseListener ml: cardArea.getMouseListeners()) { for (MouseListener ml : cardArea.getMouseListeners()) {
cardArea.removeMouseListener(ml); cardArea.removeMouseListener(ml);
} }
} }
if(mainTable != null) { if (mainTable != null) {
for(MouseListener ml: mainTable.getMouseListeners()) { for (MouseListener ml : mainTable.getMouseListeners()) {
mainTable.removeMouseListener(ml); mainTable.removeMouseListener(ml);
} }
} }
if (currentView != null) { if (currentView != null) {
currentView.clearCardEventListeners(); currentView.clearCardEventListeners();
} }
for (Component comp :cardArea.getComponents()) { for (Component comp : cardArea.getComponents()) {
if (comp instanceof CardPanel) { if (comp instanceof CardPanel) {
((CardPanel)comp).cleanUp(); ((CardPanel) comp).cleanUp();
} }
} }
mageCards.clear(); mageCards.clear();
@ -256,7 +257,6 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
return list; return list;
} }
public void loadCards(CardsView showCards, BigCard bigCard, UUID gameId) { public void loadCards(CardsView showCards, BigCard bigCard, UUID gameId) {
int selectedRow = -1; int selectedRow = -1;
if (currentView.equals(mainModel)) { if (currentView.equals(mainModel)) {
@ -270,7 +270,7 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
chkPiles.setSelected(sortSetting.isPilesToggle()); chkPiles.setSelected(sortSetting.isPilesToggle());
currentView.loadCards(showCards, sortSetting, bigCard, gameId); currentView.loadCards(showCards, sortSetting, bigCard, gameId);
if (selectedRow >= 0) { if (selectedRow >= 0) {
selectedRow = Math.min(selectedRow, mainTable.getRowCount()-1); selectedRow = Math.min(selectedRow, mainTable.getRowCount() - 1);
if (selectedRow >= 0) { if (selectedRow >= 0) {
mainTable.setRowSelectionInterval(selectedRow, selectedRow); mainTable.setRowSelectionInterval(selectedRow, selectedRow);
} }
@ -297,17 +297,16 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
mageCards = new LinkedHashMap<>(); mageCards = new LinkedHashMap<>();
//Find card view //Find card view
for(UUID uuid : cards.keySet()){ for (UUID uuid : cards.keySet()) {
if(oldMageCards.containsKey(uuid)){ if (oldMageCards.containsKey(uuid)) {
mageCards.put(uuid, oldMageCards.get(uuid)); mageCards.put(uuid, oldMageCards.get(uuid));
oldMageCards.remove(uuid); oldMageCards.remove(uuid);
} } else {
else{
mageCards.put(uuid, addCard(cards.get(uuid), bigCard, gameId)); mageCards.put(uuid, addCard(cards.get(uuid), bigCard, gameId));
} }
} }
//Remove unused cards //Remove unused cards
for(MageCard card : oldMageCards.values()){ for (MageCard card : oldMageCards.values()) {
cardArea.remove(card); cardArea.remove(card);
} }
@ -324,25 +323,25 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
case COLOR: case COLOR:
comparator = new CardViewColorComparator(); comparator = new CardViewColorComparator();
break; break;
case COLOR_DETAILED: case COLOR_IDENTITY:
comparator = new CardViewColorDetailedComparator(); comparator = new CardViewColorIdentityComparator();
break; break;
case CASTING_COST: case CASTING_COST:
comparator = new CardViewCostComparator(); comparator = new CardViewCostComparator();
break; break;
} }
if(comparator != null){ if (comparator != null) {
Collections.sort(sortedCards, new CardViewNameComparator()); Collections.sort(sortedCards, new CardViewNameComparator());
Collections.sort(sortedCards, comparator); Collections.sort(sortedCards, comparator);
} }
CardView lastCard = null; CardView lastCard = null;
for (CardView card: sortedCards) { for (CardView card : sortedCards) {
if (sortSetting.isPilesToggle()) { if (sortSetting.isPilesToggle()) {
if (lastCard == null) { if (lastCard == null) {
lastCard = card; lastCard = card;
} }
if(comparator != null){ if (comparator != null) {
if(comparator.compare(card, lastCard) > 0){ if (comparator.compare(card, lastCard) > 0) {
curColumn++; curColumn++;
maxRow = Math.max(maxRow, curRow); maxRow = Math.max(maxRow, curRow);
curRow = 0; curRow = 0;
@ -368,20 +367,20 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
maxRow = Math.max(maxRow, curRow); maxRow = Math.max(maxRow, curRow);
maxColumn = Math.max(maxColumn, curColumn); maxColumn = Math.max(maxColumn, curColumn);
updateCounts(); updateCounts();
cardArea.setPreferredSize(new Dimension((maxColumn+1) * Config.dimensions.frameWidth, Config.dimensions.frameHeight + maxRow*20)); cardArea.setPreferredSize(new Dimension((maxColumn + 1) * Config.dimensions.frameWidth, Config.dimensions.frameHeight + maxRow * 20));
cardArea.revalidate(); cardArea.revalidate();
this.revalidate(); this.revalidate();
this.repaint(); this.repaint();
this.setVisible(true); this.setVisible(true);
} }
private void updateCounts(){ private void updateCounts() {
int landCount = 0; int landCount = 0;
int creatureCount = 0; int creatureCount = 0;
int sorceryCount = 0; int sorceryCount = 0;
int instantCount = 0; int instantCount = 0;
int enchantmentCount = 0; int enchantmentCount = 0;
for (CardView card: cards.values()) { for (CardView card : cards.values()) {
if (card.getCardTypes().contains(CardType.LAND)) { if (card.getCardTypes().contains(CardType.LAND)) {
landCount++; landCount++;
} }
@ -419,7 +418,6 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
return cardImg; return cardImg;
} }
private void setCardBounds(MageCard card, Rectangle rectangle) { private void setCardBounds(MageCard card, Rectangle rectangle) {
card.setBounds(rectangle); card.setBounds(rectangle);
card.setCardBounds(rectangle.x, rectangle.y, Config.dimensions.frameWidth, Config.dimensions.frameHeight); 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(); mainModel.clearCardEventListeners();
} }
/** This method is called from within the constructor to /**
* initialize the form. * This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is * WARNING: Do NOT modify this code. The content of this method is always
* always regenerated by the Form Editor. * regenerated by the Form Editor.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
@ -731,22 +729,20 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
e.consume(); e.consume();
if (obj instanceof Card) { if (obj instanceof Card) {
if (e.isAltDown()) { if (e.isAltDown()) {
cardEventSource.altDoubleClick(((Card)obj).getOriginal(), "alt-double-click"); cardEventSource.altDoubleClick(((Card) obj).getOriginal(), "alt-double-click");
} } else {
else { cardEventSource.doubleClick(((Card) obj).getOriginal(), "double-click");
cardEventSource.doubleClick(((Card)obj).getOriginal(), "double-click");
} }
} else if (obj instanceof MageCard) { } else if (obj instanceof MageCard) {
if (e.isAltDown()) { if (e.isAltDown()) {
cardEventSource.altDoubleClick(((MageCard)obj).getOriginal(), "alt-double-click"); cardEventSource.altDoubleClick(((MageCard) obj).getOriginal(), "alt-double-click");
} } else {
else { cardEventSource.doubleClick(((MageCard) obj).getOriginal(), "double-click");
cardEventSource.doubleClick(((MageCard)obj).getOriginal(), "double-click");
} }
} }
} }
if (obj instanceof MageCard) { if (obj instanceof MageCard) {
checkMenu(e, ((MageCard)obj).getOriginal()); checkMenu(e, ((MageCard) obj).getOriginal());
} else { } else {
checkMenu(e, null); checkMenu(e, null);
} }
@ -758,14 +754,14 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
if (!e.isConsumed()) { if (!e.isConsumed()) {
Object obj = e.getSource(); Object obj = e.getSource();
if (obj instanceof MageCard) { if (obj instanceof MageCard) {
checkMenu(e, ((MageCard)obj).getOriginal()); checkMenu(e, ((MageCard) obj).getOriginal());
} else { } else {
checkMenu(e, null); checkMenu(e, null);
} }
} }
} }
private void checkMenu(MouseEvent Me, SimpleCardView card){ private void checkMenu(MouseEvent Me, SimpleCardView card) {
if (Me.isPopupTrigger()) { if (Me.isPopupTrigger()) {
Me.consume(); Me.consume();
cardEventSource.showPopupMenuEvent(card, Me.getComponent(), Me.getX(), Me.getY(), "show-popup-menu"); cardEventSource.showPopupMenuEvent(card, Me.getComponent(), Me.getX(), Me.getY(), "show-popup-menu");

View file

@ -1,31 +1,30 @@
/* /*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, are * Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met: * permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this list of * 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer. * conditions and the following disclaimer.
* *
* 2. Redistributions in binary form must reproduce the above copyright notice, this list * 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials * of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution. * provided with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* The views and conclusions contained in the software and documentation are those of the * The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.client.constants; package mage.client.constants;
import java.io.File; import java.io.File;
@ -37,6 +36,7 @@ import javax.swing.border.Border;
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
public final class Constants { public final class Constants {
private Constants() { private Constants() {
throw new AssertionError(); throw new AssertionError();
} }
@ -69,7 +69,7 @@ public final class Constants {
public static final int POWBOX_TEXT_MAX_LEFT = 212; public static final int POWBOX_TEXT_MAX_LEFT = 212;
public static final int DAMAGE_MAX_LEFT = 180; public static final int DAMAGE_MAX_LEFT = 180;
public static final Border EMPTY_BORDER = BorderFactory.createEmptyBorder(2,2,2,2); public static final Border EMPTY_BORDER = BorderFactory.createEmptyBorder(2, 2, 2, 2);
public static final double SCALE_FACTOR = 0.5; public static final double SCALE_FACTOR = 0.5;
@ -80,26 +80,29 @@ public final class Constants {
public static final String RESOURCE_PATH_SET = IO.imageBaseDir + "sets" + File.separator; public static final String RESOURCE_PATH_SET = IO.imageBaseDir + "sets" + File.separator;
public static final String RESOURCE_PATH_SET_SMALL = RESOURCE_PATH_SET + File.separator + "small" + File.separator; public static final String RESOURCE_PATH_SET_SMALL = RESOURCE_PATH_SET + File.separator + "small" + File.separator;
public static final String BASE_SOUND_PATH = "sounds" + File.separator; public static final String BASE_SOUND_PATH = "sounds" + File.separator;
public static final String BASE_MUSICS_PATH = "music" + File.separator ; public static final String BASE_MUSICS_PATH = "music" + File.separator;
public interface IO { public interface IO {
String imageBaseDir = "plugins" + File.separator + "images" + File.separator; String imageBaseDir = "plugins" + File.separator + "images" + File.separator;
String IMAGE_PROPERTIES_FILE = "image.url.properties"; String IMAGE_PROPERTIES_FILE = "image.url.properties";
} }
public enum DeckEditorMode { public enum DeckEditorMode {
FREE_BUILDING, FREE_BUILDING,
LIMITED_BUILDING, LIMITED_BUILDING,
SIDEBOARDING SIDEBOARDING
} }
public enum SortBy { public enum SortBy {
CASTING_COST ("Casting Cost"),
RARITY ("Rarity"), CASTING_COST("Casting Cost"),
COLOR ("Color"), RARITY("Rarity"),
COLOR_DETAILED ("Color Detailed"), COLOR("Color"),
NAME ("Name"), COLOR_IDENTITY("Color Identity"),
UNSORTED ("Unsorted"); NAME("Name"),
UNSORTED("Unsorted");
private final String text; private final String text;
@ -120,8 +123,8 @@ public final class Constants {
return RARITY; return RARITY;
case "Color": case "Color":
return COLOR; return COLOR;
case "Color Detailed": case "Color Identity":
return COLOR_DETAILED; return COLOR_IDENTITY;
case "Name": case "Name":
return NAME; return NAME;
default: default:

View file

@ -25,21 +25,31 @@
* authors and should not be interpreted as representing official policies, either expressed * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.client.util; package mage.client.util;
import java.util.Comparator; import java.util.Comparator;
import java.util.List;
import mage.ObjectColor;
import mage.view.CardView; import mage.view.CardView;
/** /**
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
public class CardViewColorDetailedComparator implements Comparator<CardView> { public class CardViewColorIdentityComparator implements Comparator<CardView> {
@Override @Override
public int compare(CardView o1, CardView o2) { 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 * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.client.util; package mage.client.util;
import java.util.Comparator; import java.util.Comparator;
@ -39,7 +38,7 @@ public class CardViewCostComparator implements Comparator<CardView> {
@Override @Override
public int compare(CardView o1, CardView o2) { 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; package mage.utils;
import java.util.List;
import mage.ObjectColor;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.MagePermanent; import mage.cards.MagePermanent;
import mage.constants.CardType; import mage.constants.CardType;
@ -13,6 +15,12 @@ import mage.view.CardView;
*/ */
public class CardUtil { 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) { public static boolean isCreature(CardView card) {
return is(card, CardType.CREATURE); return is(card, CardType.CREATURE);
} }
@ -48,4 +56,34 @@ public class CardUtil {
public static boolean isLand(Card card) { public static boolean isLand(Card card) {
return card.getCardType().contains(CardType.LAND); 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;
}
} }