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

@ -1,16 +1,16 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
*
* 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
* provided with the distribution.
*
*
* 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
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
@ -20,7 +20,7 @@
* 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
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
* 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
* or implied, of BetaSteward_at_googlemail.com.
@ -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;
@ -82,7 +82,7 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
}
public void clear() {
for(MouseListener ml: this.getMouseListeners()) {
for (MouseListener ml : this.getMouseListeners()) {
this.removeMouseListener(ml);
}
this.clearCardEventListeners();
@ -101,7 +101,7 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
this.bigCard = bigCard;
this.gameId = gameId;
if (merge) {
for (CardView card: showCards.values()) {
for (CardView card : showCards.values()) {
if (!cards.containsKey(card.getId())) {
addCard(card, bigCard, gameId, drawImage);
}
@ -115,7 +115,7 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
}
} else {
this.clearCards();
for (CardView card: showCards.values()) {
for (CardView card : showCards.values()) {
addCard(card, bigCard, gameId, drawImage);
}
}
@ -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,15 +155,16 @@ 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) {
for (MageCard cardImg : sortedCards) {
if (sortSetting.isPilesToggle()) {
if (lastCard == null) {
lastCard = cardImg;
@ -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);
@ -221,15 +222,15 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
}
}
resizeArea();
revalidate();
repaint();
revalidate();
repaint();
}
private void clearCards() {
// remove possible mouse listeners, preventing gc
for (MageCard mageCard: cards.values()) {
for (MageCard mageCard : cards.values()) {
if (mageCard instanceof CardPanel) {
((CardPanel)mageCard).cleanUp();
((CardPanel) mageCard).cleanUp();
}
}
this.cards.clear();
@ -237,7 +238,7 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
}
private void removeAllCardImg() {
for (Component comp: getComponents()) {
for (Component comp : getComponents()) {
if (comp instanceof Card || comp instanceof MageCard) {
remove(comp);
}
@ -245,14 +246,14 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
}
private void removeCardImg(UUID cardId) {
for (Component comp: getComponents()) {
for (Component comp : getComponents()) {
if (comp instanceof Card) {
if (((Card)comp).getCardId().equals(cardId)) {
if (((Card) comp).getCardId().equals(cardId)) {
remove(comp);
comp = null;
}
} else if (comp instanceof MageCard) {
if (((MageCard)comp).getOriginal().getId().equals(cardId)) {
if (((MageCard) comp).getOriginal().getId().equals(cardId)) {
remove(comp);
comp = null;
}
@ -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,22 +321,26 @@ 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);
Dimension size = getPreferredSize();
for (Component comp: getComponents()) {
for (Component comp : getComponents()) {
Rectangle r = comp.getBounds();
if (r.x + r.width > area.width) {
area.width = r.x + r.width;
@ -348,13 +351,13 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
}
if (size.height != area.height || size.width != area.width) {
setPreferredSize(area);
}
}
}
@Override
public void refresh() {
revalidate();
repaint();
repaint();
}
@Override
@ -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

@ -1,37 +1,36 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 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
* provided with the distribution.
*
* 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
* 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
* 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
* 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
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 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
* or implied, of BetaSteward_at_googlemail.com.
*/
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 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
* provided with the distribution.
*
* 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
* 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
* 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
* 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
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 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
* or implied, of BetaSteward_at_googlemail.com.
*/
/*
* CardsList.java
*
* 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;
@ -86,7 +85,7 @@ import org.mage.card.arcane.CardPanel;
* @author BetaSteward_at_googlemail.com
*/
public class CardsList extends javax.swing.JPanel implements MouseListener, ICardGrid {
protected CardEventSource cardEventSource = new CardEventSource();
private Dimension cardDimension;
private CardsView cards;
@ -98,8 +97,10 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
private TableModel mainModel;
private JTable mainTable;
private ICardGrid currentView;
/** Creates new form Cards */
/**
* Creates new form Cards
*/
public CardsList() {
initComponents();
makeTransparent();
@ -115,22 +116,22 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
mainModel.removeTableModelListener(mainTable);
mainModel.clear();
}
if(cardArea != null) {
for(MouseListener ml: cardArea.getMouseListeners()) {
if (cardArea != null) {
for (MouseListener ml : cardArea.getMouseListeners()) {
cardArea.removeMouseListener(ml);
}
}
if(mainTable != null) {
for(MouseListener ml: mainTable.getMouseListeners()) {
if (mainTable != null) {
for (MouseListener ml : mainTable.getMouseListeners()) {
mainTable.removeMouseListener(ml);
}
}
if (currentView != null) {
currentView.clearCardEventListeners();
}
for (Component comp :cardArea.getComponents()) {
if (comp instanceof CardPanel) {
((CardPanel)comp).cleanUp();
for (Component comp : cardArea.getComponents()) {
if (comp instanceof CardPanel) {
((CardPanel) comp).cleanUp();
}
}
mageCards.clear();
@ -208,20 +209,20 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
// activate spinner for card number change
mainModel.setNumberEditable(true);
TableColumnModel tcm = mainTable.getColumnModel();
TableColumn tc = tcm.getColumn(0);
TableColumn tc = tcm.getColumn(0);
tc.setMaxWidth(55);
tc.setMinWidth(55);
tc.setPreferredWidth(55);
tc.setCellEditor(new TableSpinnerEditor(this));
tc.setCellEditor(new TableSpinnerEditor(this));
}
}
public void handleSetNumber(int number) {
if (mainTable.getSelectedRowCount() == 1) {
mainModel.setNumber(mainTable.getSelectedRow(), number);
}
}
}
public void handleDoubleClick() {
if (mainTable.getSelectedRowCount() > 0) {
int[] n = mainTable.getSelectedRows();
@ -232,7 +233,7 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
}
}
}
public void handleAltDoubleClick() {
if (mainTable.getSelectedRowCount() > 0) {
int[] n = mainTable.getSelectedRows();
@ -243,7 +244,7 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
}
}
}
public ICardGrid getMainModel() {
return mainModel;
}
@ -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)) {
@ -270,7 +270,7 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
chkPiles.setSelected(sortSetting.isPilesToggle());
currentView.loadCards(showCards, sortSetting, bigCard, gameId);
if (selectedRow >= 0) {
selectedRow = Math.min(selectedRow, mainTable.getRowCount()-1);
selectedRow = Math.min(selectedRow, mainTable.getRowCount() - 1);
if (selectedRow >= 0) {
mainTable.setRowSelectionInterval(selectedRow, selectedRow);
}
@ -281,7 +281,7 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
if (cards == null) {
cards = new CardsView();
}
currentView.loadCards(cards, sortSetting, bigCard, gameId);
currentView.loadCards(cards, sortSetting, bigCard, gameId);
}
@Override
@ -295,22 +295,21 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
Comparator<CardView> comparator = null;
Map<UUID, MageCard> oldMageCards = mageCards;
mageCards = new LinkedHashMap<>();
//Find card view
for(UUID uuid : cards.keySet()){
if(oldMageCards.containsKey(uuid)){
for (UUID uuid : cards.keySet()) {
if (oldMageCards.containsKey(uuid)) {
mageCards.put(uuid, oldMageCards.get(uuid));
oldMageCards.remove(uuid);
}
else{
} else {
mageCards.put(uuid, addCard(cards.get(uuid), bigCard, gameId));
}
}
//Remove unused cards
for(MageCard card : oldMageCards.values()){
for (MageCard card : oldMageCards.values()) {
cardArea.remove(card);
}
if (cards != null && cards.size() > 0) {
Rectangle rectangle = new Rectangle(Config.dimensions.frameWidth, Config.dimensions.frameHeight);
List<CardView> sortedCards = new ArrayList<>(cards.values());
@ -324,25 +323,25 @@ 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();
break;
}
if(comparator != null){
if (comparator != null) {
Collections.sort(sortedCards, new CardViewNameComparator());
Collections.sort(sortedCards, comparator);
}
CardView lastCard = null;
for (CardView card: sortedCards) {
for (CardView card : sortedCards) {
if (sortSetting.isPilesToggle()) {
if (lastCard == null) {
lastCard = card;
}
if(comparator != null){
if(comparator.compare(card, lastCard) > 0){
if (comparator != null) {
if (comparator.compare(card, lastCard) > 0) {
curColumn++;
maxRow = Math.max(maxRow, curRow);
curRow = 0;
@ -350,7 +349,7 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
}
rectangle.setLocation(curColumn * Config.dimensions.frameWidth, curRow * 20);
setCardBounds(mageCards.get(card.getId()), rectangle);
curRow++;
lastCard = card;
} else {
@ -368,21 +367,21 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
maxRow = Math.max(maxRow, curRow);
maxColumn = Math.max(maxColumn, curColumn);
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();
this.revalidate();
this.repaint();
this.setVisible(true);
}
private void updateCounts(){
private void updateCounts() {
int landCount = 0;
int creatureCount = 0;
int sorceryCount = 0;
int instantCount = 0;
int enchantmentCount = 0;
for (CardView card: cards.values()) {
if (card.getCardTypes().contains(CardType.LAND)) {
for (CardView card : cards.values()) {
if (card.getCardTypes().contains(CardType.LAND)) {
landCount++;
}
if (card.getCardTypes().contains(CardType.CREATURE)) {
@ -398,7 +397,7 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
enchantmentCount++;
}
}
int count = cards != null ? cards.size() : 0;
this.lblCount.setText(Integer.toString(count));
this.lblCreatureCount.setText(Integer.toString(creatureCount));
@ -418,7 +417,6 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
cardImg.addMouseListener(this);
return cardImg;
}
private void setCardBounds(MageCard card, Rectangle rectangle) {
card.setBounds(rectangle);
@ -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
@ -678,9 +676,9 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
currentView = mainModel;
panelCardArea.setViewportView(mainTable);
cbSortBy.setEnabled(false);
chkPiles.setEnabled(false);
chkPiles.setEnabled(false);
PreferencesDialog.saveValue(PreferencesDialog.KEY_DRAFT_VIEW, "listView");
redrawCards();
redrawCards();
}//GEN-LAST:event_jToggleListViewActionPerformed
private void cbSortByActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbSortByActionPerformed
@ -698,8 +696,8 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
panelCardArea.setViewportView(cardArea);
cbSortBy.setEnabled(true);
chkPiles.setEnabled(true);
PreferencesDialog.saveValue(PreferencesDialog.KEY_DRAFT_VIEW, "cardView");
redrawCards();
PreferencesDialog.saveValue(PreferencesDialog.KEY_DRAFT_VIEW, "cardView");
redrawCards();
}//GEN-LAST:event_jToggleCardViewActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
@ -725,28 +723,26 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
@Override
public void mousePressed(MouseEvent e) {
if (e.getClickCount() >= 1 && !e.isConsumed()) {
if (e.getClickCount() >= 1 && !e.isConsumed()) {
Object obj = e.getSource();
if (e.getClickCount() == 2) {
e.consume();
if (obj instanceof Card) {
if (e.isAltDown()) {
cardEventSource.altDoubleClick(((Card)obj).getOriginal(), "alt-double-click");
}
else {
cardEventSource.doubleClick(((Card)obj).getOriginal(), "double-click");
cardEventSource.altDoubleClick(((Card) obj).getOriginal(), "alt-double-click");
} 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 {
cardEventSource.doubleClick(((MageCard)obj).getOriginal(), "double-click");
cardEventSource.altDoubleClick(((MageCard) obj).getOriginal(), "alt-double-click");
} else {
cardEventSource.doubleClick(((MageCard) obj).getOriginal(), "double-click");
}
}
}
if (obj instanceof MageCard) {
checkMenu(e, ((MageCard)obj).getOriginal());
checkMenu(e, ((MageCard) obj).getOriginal());
} else {
checkMenu(e, null);
}
@ -758,14 +754,14 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
if (!e.isConsumed()) {
Object obj = e.getSource();
if (obj instanceof MageCard) {
checkMenu(e, ((MageCard)obj).getOriginal());
checkMenu(e, ((MageCard) obj).getOriginal());
} else {
checkMenu(e, null);
}
}
}
private void checkMenu(MouseEvent Me, SimpleCardView card){
private void checkMenu(MouseEvent Me, SimpleCardView card) {
if (Me.isPopupTrigger()) {
Me.consume();
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.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 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
* provided with the distribution.
*
* 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
* 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
* 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
* 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
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 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
* or implied, of BetaSteward_at_googlemail.com.
*/
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 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
* provided with the distribution.
*
* 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
* 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
* 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
* 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
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 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
* 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();
}
@ -69,7 +69,7 @@ public final class Constants {
public static final int POWBOX_TEXT_MAX_LEFT = 212;
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;
@ -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_SMALL = RESOURCE_PATH_SET + File.separator + "small" + 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 {
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"),
NAME ("Name"),
UNSORTED ("Unsorted");
CASTING_COST("Casting Cost"),
RARITY("Rarity"),
COLOR("Color"),
COLOR_IDENTITY("Color Identity"),
NAME("Name"),
UNSORTED("Unsorted");
private final String text;
@ -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

@ -1,16 +1,16 @@
/*
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
*
* 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
* provided with the distribution.
*
*
* 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
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
@ -20,12 +20,11 @@
* 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
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
* 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
* 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;
}
}