* Deck editor - Fixed a bug that prevented users to add cards to deck or sideboard (was caused by creatures with negative toughness and it was sorted by p/t - fixes #1414).

This commit is contained in:
LevelX2 2015-12-13 10:34:35 +01:00
parent d9b20298b7
commit ea0ba76736

View file

@ -24,36 +24,37 @@
* 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.deckeditor.table; package mage.client.deckeditor.table;
import java.util.Comparator; import java.util.Comparator;
import mage.cards.MageCard; import mage.cards.MageCard;
import mage.view.CardView; import mage.view.CardView;
/** /**
* {@link MageCard} comparator. Used to sort cards in Deck Editor Table View pane. * {@link MageCard} comparator. Used to sort cards in Deck Editor Table View
* pane.
* *
* @author nantuko * @author nantuko
*/ */
public class MageCardComparator implements Comparator<CardView> { public class MageCardComparator implements Comparator<CardView> {
private final int column; private final int column;
private boolean ascending; private final boolean ascending;
public MageCardComparator(int column, boolean ascending) { public MageCardComparator(int column, boolean ascending) {
this.column = column; this.column = column;
this.ascending = ascending; this.ascending = ascending;
} }
@Override
public int compare(CardView a, CardView b) { public int compare(CardView a, CardView b) {
Comparable aCom = null; Comparable aCom = null;
Comparable bCom = null; Comparable bCom = null;
if (column == 0)// #skip if (column == 0)// #skip
{ {
aCom = Integer.valueOf(1); aCom = 1;
bCom = Integer.valueOf(1); bCom = 1;
} else if (column == 1)// Name } else if (column == 1)// Name
{ {
aCom = a.getName(); aCom = a.getName();
@ -76,13 +77,15 @@ public class MageCardComparator implements Comparator<CardView> {
bCom = CardHelper.getType(b); bCom = CardHelper.getType(b);
} else if (column == 5)// Stats, attack and defense } else if (column == 5)// Stats, attack and defense
{ {
aCom = new Float(-1); aCom = (float) -1;
bCom = new Float(-1); bCom = (float) -1;
if (CardHelper.isCreature(a)) if (CardHelper.isCreature(a)) {
aCom = new Float(a.getPower() + "." + a.getToughness()); aCom = new Float(a.getPower() + "." + (a.getToughness().startsWith("-") ? "0" : a.getToughness()));
if (CardHelper.isCreature(b)) }
bCom = new Float(b.getPower() + "." + b.getToughness()); if (CardHelper.isCreature(b)) {
bCom = new Float(b.getPower() + "." + (b.getToughness().startsWith("-") ? "0" : b.getToughness()));
}
} else if (column == 6)// Rarity } else if (column == 6)// Rarity
{ {
aCom = a.getRarity().toString(); aCom = a.getRarity().toString();
@ -93,9 +96,10 @@ public class MageCardComparator implements Comparator<CardView> {
bCom = b.getExpansionSetCode(); bCom = b.getExpansionSetCode();
} }
if (ascending) if (ascending) {
return aCom.compareTo(bCom); return aCom.compareTo(bCom);
else } else {
return bCom.compareTo(aCom); return bCom.compareTo(aCom);
}
}// compare() }// compare()
} }