added sorting and counts to deck editor

This commit is contained in:
BetaSteward 2011-02-11 22:57:22 -05:00
parent f36254445a
commit d217d332b6
15 changed files with 372 additions and 507 deletions

View file

@ -50,6 +50,7 @@ import java.util.UUID;
import java.util.Map.Entry;
import mage.cards.MageCard;
import mage.client.constants.Constants.SortBy;
import mage.client.plugins.impl.Plugins;
import mage.client.util.Config;
import mage.client.util.Event;
@ -74,7 +75,7 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener
setOpaque(false);
}
public void loadCards(CardsView showCards, BigCard bigCard, UUID gameId) {
public void loadCards(CardsView showCards, SortBy sortBy, BigCard bigCard, UUID gameId) {
this.bigCard = bigCard;
this.gameId = gameId;
for (CardView card: showCards.values()) {
@ -89,7 +90,7 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener
i.remove();
}
}
drawCards();
drawCards(sortBy);
this.setVisible(true);
}
@ -105,7 +106,7 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener
cards.put(card.getId(), cardImg);
}
public void drawCards() {
public void drawCards(SortBy sortBy) {
int maxWidth = this.getParent().getWidth();
int numColumns = maxWidth / Config.dimensions.frameWidth;
int curColumn = 0;
@ -113,7 +114,20 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener
if (cards.size() > 0) {
Rectangle rectangle = new Rectangle(Config.dimensions.frameWidth, Config.dimensions.frameHeight);
List<MageCard> sortedCards = new ArrayList<MageCard>(cards.values());
Collections.sort(sortedCards, new CardComparator());
switch (sortBy) {
case NAME:
Collections.sort(sortedCards, new CardNameComparator());
break;
case RARITY:
Collections.sort(sortedCards, new CardRarityComparator());
break;
case COLOR:
Collections.sort(sortedCards, new CardColorComparator());
break;
case CASTING_COST:
Collections.sort(sortedCards, new CardCostComparator());
break;
}
for (MageCard cardImg: sortedCards) {
rectangle.setLocation(curColumn * Config.dimensions.frameWidth, curRow * 20);
cardImg.setBounds(rectangle);
@ -229,11 +243,38 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener
}
}
class CardComparator implements Comparator<MageCard> {
class CardNameComparator implements Comparator<MageCard> {
@Override
public int compare(MageCard o1, MageCard o2) {
return o1.getOriginal().getName().compareTo(o2.getOriginal().getName());
}
}
class CardRarityComparator implements Comparator<MageCard> {
@Override
public int compare(MageCard o1, MageCard o2) {
return o1.getOriginal().getRarity().compareTo(o2.getOriginal().getRarity());
}
}
class CardCostComparator implements Comparator<MageCard> {
@Override
public int compare(MageCard o1, MageCard o2) {
return Integer.valueOf(o1.getOriginal().getConvertedManaCost()).compareTo(Integer.valueOf(o2.getOriginal().getConvertedManaCost()));
}
}
class CardColorComparator implements Comparator<MageCard> {
@Override
public int compare(MageCard o1, MageCard o2) {
return o1.getOriginal().getColor().compareTo(o2.getOriginal().getColor());
}
}

View file

@ -21,17 +21,27 @@
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jPanel1" alignment="0" max="32767" attributes="0"/>
<Component id="jScrollPane1" alignment="0" pref="553" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Component id="jPanel1" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="0" max="-2" attributes="0"/>
<Component id="jScrollPane1" pref="321" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
<BorderConstraints direction="Center"/>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
@ -41,5 +51,65 @@
</Container>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="jPanel1">
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Component id="lblCount" max="32767" attributes="0"/>
<EmptySpace type="unrelated" min="-2" max="-2" attributes="0"/>
<Component id="lblCreatureCount" max="32767" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="lblLandCount" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="cbSortBy" min="-2" pref="338" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="103" groupAlignment="3" attributes="0">
<Component id="cbSortBy" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="lblCount" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="lblCreatureCount" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="lblLandCount" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JComboBox" name="cbSortBy">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="4">
<StringItem index="0" value="Item 1"/>
<StringItem index="1" value="Item 2"/>
<StringItem index="2" value="Item 3"/>
<StringItem index="3" value="Item 4"/>
</StringArray>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cbSortByActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="lblCount">
<Properties>
<Property name="text" type="java.lang.String" value="Card Count"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblCreatureCount">
<Properties>
<Property name="text" type="java.lang.String" value="Creature Count"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblLandCount">
<Properties>
<Property name="text" type="java.lang.String" value="Land Count"/>
</Properties>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Form>

View file

@ -44,8 +44,11 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.UUID;
import javax.swing.DefaultComboBoxModel;
import mage.Constants.CardType;
import mage.cards.MageCard;
import mage.client.constants.Constants.SortBy;
import mage.client.plugins.impl.Plugins;
import mage.client.util.Config;
import mage.client.util.Event;
@ -61,6 +64,9 @@ public class CardsList extends javax.swing.JPanel implements MouseListener {
protected CardEventSource cardEventSource = new CardEventSource();
private Dimension cardDimension;
private CardsView cards;
protected BigCard bigCard;
protected UUID gameId;
/** Creates new form Cards */
public CardsList() {
@ -68,32 +74,64 @@ public class CardsList extends javax.swing.JPanel implements MouseListener {
jScrollPane1.setOpaque(false);
cardArea.setOpaque(false);
jScrollPane1.getViewport().setOpaque(false);
cbSortBy.setModel(new DefaultComboBoxModel(SortBy.values()));
}
public void loadCards(CardsView showCards, BigCard bigCard, UUID gameId) {
loadCards(showCards, bigCard, gameId, false);
loadCards(showCards, bigCard, gameId, SortBy.UNSORTED);
}
public void loadCards(CardsView showCards, BigCard bigCard, UUID gameId, boolean sorted) {
public void loadCards(CardsView showCards, BigCard bigCard, UUID gameId, SortBy sortBy) {
//FIXME: why we remove all cards? for performance it's better to merge changes
cards = showCards;
this.bigCard = bigCard;
this.gameId = gameId;
drawCards(sortBy);
}
private void drawCards(SortBy sortBy) {
int maxWidth = this.getParent().getWidth();
int numColumns = maxWidth / Config.dimensions.frameWidth;
int curColumn = 0;
int curRow = 0;
int landCount = 0;
int creatureCount = 0;
cardArea.removeAll();
if (showCards != null && showCards.size() > 0) {
if (cards != null && cards.size() > 0) {
Rectangle rectangle = new Rectangle(Config.dimensions.frameWidth, Config.dimensions.frameHeight);
int count = 0;
List<CardView> sortedCards = new ArrayList<CardView>(showCards.values());
if (sorted)
Collections.sort(sortedCards, new CardViewComparator());
List<CardView> sortedCards = new ArrayList<CardView>(cards.values());
switch (sortBy) {
case NAME:
Collections.sort(sortedCards, new CardViewNameComparator());
break;
case RARITY:
Collections.sort(sortedCards, new CardViewRarityComparator());
break;
case COLOR:
Collections.sort(sortedCards, new CardViewColorComparator());
break;
case CASTING_COST:
Collections.sort(sortedCards, new CardViewCostComparator());
break;
}
for (CardView card: sortedCards) {
rectangle.setLocation(curColumn * Config.dimensions.frameWidth, curRow * 20);
addCard(card, bigCard, gameId, rectangle);
if (count >= 10) {
rectangle.translate(Config.dimensions.frameWidth, -200);
count = 0;
} else {
rectangle.translate(0, 20);
count++;
if (card.getCardTypes().contains(CardType.LAND))
landCount++;
if (card.getCardTypes().contains(CardType.CREATURE))
creatureCount++;
curColumn++;
if (curColumn == numColumns) {
curColumn = 0;
curRow++;
}
}
}
this.lblCount.setText("Count: " + Integer.toString(cards.size()));
this.lblCreatureCount.setText("Creatures: " + Integer.toString(creatureCount));
this.lblLandCount.setText("Lands: " + Integer.toString(landCount));
cardArea.setPreferredSize(new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight + 200));
cardArea.revalidate();
this.revalidate();
@ -133,20 +171,81 @@ public class CardsList extends javax.swing.JPanel implements MouseListener {
jScrollPane1 = new javax.swing.JScrollPane();
cardArea = new javax.swing.JLayeredPane();
jPanel1 = new javax.swing.JPanel();
cbSortBy = new javax.swing.JComboBox();
lblCount = new javax.swing.JLabel();
lblCreatureCount = new javax.swing.JLabel();
lblLandCount = new javax.swing.JLabel();
setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
setPreferredSize((!Beans.isDesignTime())?(new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight)):(new Dimension(100, 100)));
setLayout(new java.awt.BorderLayout());
jScrollPane1.setViewportView(cardArea);
add(jScrollPane1, java.awt.BorderLayout.CENTER);
cbSortBy.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
cbSortBy.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cbSortByActionPerformed(evt);
}
});
lblCount.setText("Card Count");
lblCreatureCount.setText("Creature Count");
lblLandCount.setText("Land Count");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addComponent(lblCount, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(lblCreatureCount, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(lblLandCount)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(cbSortBy, javax.swing.GroupLayout.PREFERRED_SIZE, 338, javax.swing.GroupLayout.PREFERRED_SIZE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cbSortBy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblCount)
.addComponent(lblCreatureCount)
.addComponent(lblLandCount))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 553, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, 0)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 321, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
private void cbSortByActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbSortByActionPerformed
drawCards((SortBy) cbSortBy.getSelectedItem());
}//GEN-LAST:event_cbSortByActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLayeredPane cardArea;
private javax.swing.JComboBox cbSortBy;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel lblCount;
private javax.swing.JLabel lblCreatureCount;
private javax.swing.JLabel lblLandCount;
// End of variables declaration//GEN-END:variables
@Override
@ -180,11 +279,38 @@ public class CardsList extends javax.swing.JPanel implements MouseListener {
}
class CardViewComparator implements Comparator<CardView> {
class CardViewNameComparator implements Comparator<CardView> {
@Override
public int compare(CardView o1, CardView o2) {
return o1.getName().compareTo(o2.getName());
}
}
class CardViewRarityComparator implements Comparator<CardView> {
@Override
public int compare(CardView o1, CardView o2) {
return o1.getRarity().compareTo(o2.getRarity());
}
}
class CardViewCostComparator implements Comparator<CardView> {
@Override
public int compare(CardView o1, CardView o2) {
return Integer.valueOf(o1.getConvertedManaCost()).compareTo(Integer.valueOf(o2.getConvertedManaCost()));
}
}
class CardViewColorComparator implements Comparator<CardView> {
@Override
public int compare(CardView o1, CardView o2) {
return o1.getColor().compareTo(o2.getColor());
}
}

View file

@ -92,4 +92,23 @@ public final class Constants {
Sideboard
}
public enum SortBy {
CASTING_COST ("Casting Cost"),
RARITY ("Rarity"),
COLOR ("Color"),
NAME ("Name"),
UNSORTED ("Unsorted");
private String text;
SortBy(String text) {
this.text = text;
}
@Override
public String toString() {
return text;
}
}
}

View file

@ -151,17 +151,6 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnClearActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="btnAddLand">
<Properties>
<Property name="text" type="java.lang.String" value="Add Land"/>
<Property name="focusable" type="boolean" value="false"/>
<Property name="horizontalTextPosition" type="int" value="0"/>
<Property name="verticalTextPosition" type="int" value="3"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnAddLandActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
@ -266,6 +255,21 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="rdoPlaneswalkersActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JComboBox" name="cbSortBy">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="4">
<StringItem index="0" value="Item 1"/>
<StringItem index="1" value="Item 2"/>
<StringItem index="2" value="Item 3"/>
<StringItem index="3" value="Item 4"/>
</StringArray>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cbSortByActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Container>
</SubComponents>

View file

@ -45,6 +45,7 @@ import mage.cards.ExpansionSet;
import mage.client.cards.BigCard;
import mage.client.cards.CardGrid;
import mage.client.cards.CardsStorage;
import mage.client.constants.Constants.SortBy;
import mage.filter.Filter.ComparisonScope;
import mage.filter.FilterCard;
import mage.sets.Sets;
@ -68,13 +69,13 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
cardGrid.setOpaque(false);
jScrollPane1.setOpaque(false);
jScrollPane1.getViewport().setOpaque(false);
cbSortBy.setModel(new DefaultComboBoxModel(SortBy.values()));
}
public void loadCards(List<Card> sideboard, BigCard bigCard, boolean construct) {
this.bigCard = bigCard;
this.btnBooster.setVisible(false);
this.btnClear.setVisible(false);
this.btnAddLand.setVisible(construct);
this.cbExpansionSet.setVisible(false);
this.cards.clear();
for (Card card: sideboard) {
@ -88,7 +89,6 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
this.bigCard = bigCard;
this.btnBooster.setVisible(true);
this.btnClear.setVisible(true);
this.btnAddLand.setVisible(false);
this.cbExpansionSet.setVisible(true);
Object[] l = Sets.getInstance().values().toArray();
Arrays.sort(l, new Comparator<Object>() {
@ -142,7 +142,7 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
filteredCards.add(card);
}
}
this.cardGrid.loadCards(new CardsView(filteredCards), bigCard, null);
this.cardGrid.loadCards(new CardsView(filteredCards), (SortBy) cbSortBy.getSelectedItem(), bigCard, null);
}
finally {
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
@ -188,7 +188,6 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
cbExpansionSet = new javax.swing.JComboBox();
btnBooster = new javax.swing.JButton();
btnClear = new javax.swing.JButton();
btnAddLand = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
cardGrid = new mage.client.cards.CardGrid();
tbTypes = new javax.swing.JToolBar();
@ -199,6 +198,7 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
rdoInstants = new javax.swing.JRadioButton();
rdoSorceries = new javax.swing.JRadioButton();
rdoPlaneswalkers = new javax.swing.JRadioButton();
cbSortBy = new javax.swing.JComboBox();
tbColor.setFloatable(false);
tbColor.setRollover(true);
@ -305,17 +305,6 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
});
tbColor.add(btnClear);
btnAddLand.setText("Add Land");
btnAddLand.setFocusable(false);
btnAddLand.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
btnAddLand.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
btnAddLand.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnAddLandActionPerformed(evt);
}
});
tbColor.add(btnAddLand);
jScrollPane1.setViewportView(cardGrid);
tbTypes.setFloatable(false);
@ -405,6 +394,14 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
});
tbTypes.add(rdoPlaneswalkers);
cbSortBy.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
cbSortBy.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cbSortByActionPerformed(evt);
}
});
tbTypes.add(cbSortBy);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
@ -531,17 +528,18 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
filterCards();
}//GEN-LAST:event_btnBoosterActionPerformed
private void btnAddLandActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddLandActionPerformed
}//GEN-LAST:event_btnAddLandActionPerformed
private void cbSortByActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbSortByActionPerformed
if (cbSortBy.getSelectedItem() instanceof SortBy)
this.cardGrid.drawCards((SortBy) cbSortBy.getSelectedItem());
}//GEN-LAST:event_cbSortByActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnAddLand;
private javax.swing.JButton btnBooster;
private javax.swing.JButton btnClear;
private mage.client.cards.CardGrid cardGrid;
private javax.swing.JComboBox cbExpansionSet;
private javax.swing.JComboBox cbSortBy;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JRadioButton rdoArtifacts;
private javax.swing.JRadioButton rdoBlack;
@ -562,22 +560,26 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
@Override
public void componentResized(ComponentEvent e) {
this.cardGrid.drawCards();
if (cbSortBy.getSelectedItem() instanceof SortBy)
this.cardGrid.drawCards((SortBy) cbSortBy.getSelectedItem());
}
@Override
public void componentMoved(ComponentEvent e) {
this.cardGrid.drawCards();
if (cbSortBy.getSelectedItem() instanceof SortBy)
this.cardGrid.drawCards((SortBy) cbSortBy.getSelectedItem());
}
@Override
public void componentShown(ComponentEvent e) {
this.cardGrid.drawCards();
if (cbSortBy.getSelectedItem() instanceof SortBy)
this.cardGrid.drawCards((SortBy) cbSortBy.getSelectedItem());
}
@Override
public void componentHidden(ComponentEvent e) {
this.cardGrid.drawCards();
if (cbSortBy.getSelectedItem() instanceof SortBy)
this.cardGrid.drawCards((SortBy) cbSortBy.getSelectedItem());
}
}

View file

@ -38,6 +38,7 @@ package mage.client.deckeditor;
import mage.cards.decks.Deck;
import mage.client.cards.BigCard;
import mage.client.cards.CardsList;
import mage.client.constants.Constants.SortBy;
import mage.client.util.Event;
import mage.client.util.Listener;
import mage.view.CardsView;
@ -61,9 +62,9 @@ public class DeckArea extends javax.swing.JPanel {
}
public void loadDeck(Deck deck, BigCard bigCard) {
deckList.loadCards(new CardsView(deck.getCards()), bigCard, null, true);
deckList.loadCards(new CardsView(deck.getCards()), bigCard, null, SortBy.NAME);
if (sideboardList.isVisible())
sideboardList.loadCards(new CardsView(deck.getSideboard()), bigCard, null, true);
sideboardList.loadCards(new CardsView(deck.getSideboard()), bigCard, null, SortBy.NAME);
}
public void addDeckEventListener(Listener<Event> listener) {

View file

@ -40,6 +40,7 @@ import java.awt.event.ActionListener;
import java.util.UUID;
import javax.swing.Timer;
import mage.client.MageFrame;
import mage.client.constants.Constants.SortBy;
import mage.client.remote.Session;
import mage.client.util.Event;
import mage.client.util.Listener;
@ -97,7 +98,7 @@ public class DraftPanel extends javax.swing.JPanel {
public void loadBooster(DraftPickView draftPickView) {
draftBooster.loadBooster(draftPickView.getBooster(), bigCard);
draftPicks.loadCards(draftPickView.getPicks(), bigCard, null);
draftPicks.loadCards(draftPickView.getPicks(), SortBy.NAME, bigCard, null);
this.draftBooster.clearCardEventListeners();
this.draftBooster.addCardEventListener(
new Listener<Event> () {
@ -107,7 +108,7 @@ public class DraftPanel extends javax.swing.JPanel {
DraftPickView view = session.sendCardPick(draftId, (UUID)event.getSource());
if (view != null) {
draftBooster.loadBooster(view.getBooster(), bigCard);
draftPicks.loadCards(view.getPicks(), bigCard, null);
draftPicks.loadCards(view.getPicks(), SortBy.NAME, bigCard, null);
setMessage("Waiting for other players");
}
}

View file

@ -64,6 +64,7 @@ public class CardView implements Serializable {
protected List<String> superTypes;
protected ObjectColor color;
protected List<String> manaCost;
protected int convertedManaCost;
protected String art;
protected Rarity rarity;
protected String expansionSetCode;
@ -91,6 +92,7 @@ public class CardView implements Serializable {
this.superTypes = card.getSupertype();
this.color = card.getColor();
this.manaCost = card.getManaCost().getSymbols();
this.convertedManaCost = card.getManaCost().convertedManaCost();
if (card instanceof PermanentToken) {
this.art = "";
this.rarity = Rarity.NA;
@ -209,6 +211,10 @@ public class CardView implements Serializable {
return manaCost;
}
public int getConvertedManaCost() {
return convertedManaCost;
}
public String getArt() {
return art;
}

View file

@ -1,49 +0,0 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.mage</groupId>
<artifactId>mage-root</artifactId>
<version>0.6</version>
</parent>
<artifactId>Mage-Draft-8PlayerBooster</artifactId>
<packaging>jar</packaging>
<name>Mage Draft 8 Player Booster</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>Mage</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
<finalName>mage-draft-8playerbooster</finalName>
</build>
<properties/>
</project>

View file

@ -31,7 +31,7 @@ package mage;
import java.io.Serializable;
import mage.util.Copyable;
public class ObjectColor implements Serializable, Copyable<ObjectColor> {
public class ObjectColor implements Serializable, Copyable<ObjectColor>, Comparable<ObjectColor> {
public static final ObjectColor WHITE = new ObjectColor("W");
public static final ObjectColor BLUE = new ObjectColor("U");
@ -244,5 +244,41 @@ public class ObjectColor implements Serializable, Copyable<ObjectColor> {
System.out.println(new ObjectColor("W").shares(new ObjectColor("1")));
}
@Override
public int compareTo(ObjectColor o) {
int o1 = 0;
int o2 = 0;
if (this.isMulticolored())
o1 = 6;
else if(this.isColorless())
o1 = 0;
else if(this.isBlack())
o1 = 1;
else if(this.isBlue())
o1 = 2;
else if(this.isGreen())
o1 = 3;
else if(this.isRed())
o1 = 4;
else if(this.isWhite())
o1 = 5;
if (o.isMulticolored())
o2 = 6;
else if(o.isColorless())
o2 = 0;
else if(o.isBlack())
o2 = 1;
else if(o.isBlue())
o2 = 2;
else if(o.isGreen())
o2 = 3;
else if(o.isRed())
o2 = 4;
else if(o.isWhite())
o2 = 5;
return o1 - o2;
}
}

View file

@ -1,219 +0,0 @@
/*
* 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
* 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.game.tournament;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.cards.decks.Deck;
import mage.game.events.Listener;
import mage.game.events.TableEvent;
import mage.game.events.TableEvent.EventType;
import mage.game.events.TableEventSource;
import mage.game.match.Match;
import mage.players.Player;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public abstract class TournamentImpl implements Tournament {
protected UUID id = UUID.randomUUID();
protected List<Round> rounds = new CopyOnWriteArrayList<Round>();
protected Map<UUID, TournamentPlayer> players = new HashMap<UUID, TournamentPlayer>();
protected static Random rnd = new Random();
protected String matchName;
protected TournamentOptions options;
protected transient TableEventSource tableEventSource = new TableEventSource();
public TournamentImpl(TournamentOptions options) {
this.options = options;
}
@Override
public UUID getId() {
return id;
}
@Override
public void addPlayer(Player player, String playerType) {
players.put(player.getId(), new TournamentPlayer(player, playerType));
}
@Override
public TournamentPlayer getPlayer(UUID playerId) {
return players.get(playerId);
}
@Override
public Collection<TournamentPlayer> getPlayers() {
return players.values();
}
@Override
public Collection<Round> getRounds() {
return rounds;
}
@Override
public void leave(UUID playerId) {
//TODO: implement this
}
@Override
public void submitDeck(UUID playerId, Deck deck) {
if (players.containsKey(playerId)) {
players.get(playerId).submitDeck(deck);
}
synchronized (this) {
this.notifyAll();
}
}
protected Round createRoundRandom() {
Round round = new Round(rounds.size() + 1);
rounds.add(round);
List<TournamentPlayer> roundPlayers = getActivePlayers();
while (roundPlayers.size() > 1) {
int i = rnd.nextInt(roundPlayers.size());
TournamentPlayer player1 = roundPlayers.get(i);
roundPlayers.remove(i);
i = rnd.nextInt(roundPlayers.size());
TournamentPlayer player2 = roundPlayers.get(i);
roundPlayers.remove(i);
round.addPairing(new TournamentPairing(player1, player2));
}
return round;
}
protected void playRound(Round round) {
for (TournamentPairing pair: round.getPairs()) {
playMatch(pair);
}
while (!round.isRoundOver()) {
try {
//TODO: improve this
Thread.sleep(1000);
} catch (InterruptedException ex) {
Logger.getLogger(TournamentImpl.class.getName()).log(Level.SEVERE, null, ex);
break;
}
}
updateResults();
}
protected List<TournamentPlayer> getActivePlayers() {
List<TournamentPlayer> activePlayers = new ArrayList<TournamentPlayer>();
for (TournamentPlayer player: players.values()) {
if (!player.getEliminated()) {
activePlayers.add(player);
}
}
return activePlayers;
}
protected void updateResults() {
for (TournamentPlayer player: players.values()) {
player.setResults("");
}
for (Round round: rounds) {
for (TournamentPairing pair: round.getPairs()) {
UUID player1Id = pair.getPlayer1().getPlayer().getId();
UUID player2Id = pair.getPlayer2().getPlayer().getId();
Match match = pair.getMatch();
StringBuilder sb1 = new StringBuilder(players.get(player1Id).getResults());
StringBuilder sb2 = new StringBuilder(players.get(player2Id).getResults());
sb1.append(pair.getPlayer2().getPlayer().getName());
sb1.append(" (").append(match.getPlayer(player1Id).getWins());
sb1.append("-").append(match.getPlayer(player2Id).getWins()).append(")");
sb2.append(pair.getPlayer1().getPlayer().getName());
sb2.append(" (").append(match.getPlayer(player2Id).getWins());
sb2.append("-").append(match.getPlayer(player1Id).getWins()).append(") ");
players.get(player1Id).setResults(sb1.toString());
players.get(player2Id).setResults(sb2.toString());
}
}
}
@Override
public boolean isDoneConstructing() {
for (TournamentPlayer player: this.players.values()) {
if (!player.isDoneConstructing())
return false;
}
return true;
}
@Override
public boolean allJoined() {
for (TournamentPlayer player: this.players.values()) {
if (!player.isJoined())
return false;
}
return true;
}
@Override
public void addTableEventListener(Listener<TableEvent> listener) {
tableEventSource.addListener(listener);
}
public void construct() {
tableEventSource.fireTableEvent(EventType.CONSTRUCT);
synchronized(this) {
while (!isDoneConstructing()) {
try {
this.wait();
} catch (InterruptedException ex) { }
}
}
nextStep();
}
public void playMatch(TournamentPairing pair) {
options.getMatchOptions().getPlayerTypes().clear();
options.getMatchOptions().getPlayerTypes().add(pair.getPlayer1().getPlayerType());
options.getMatchOptions().getPlayerTypes().add(pair.getPlayer2().getPlayerType());
tableEventSource.fireTableEvent(EventType.START_MATCH, pair, options.getMatchOptions());
}
protected abstract void runTournament();
}

View file

@ -1,115 +0,0 @@
/*
* 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
* 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.game.tournament;
import mage.cards.decks.Deck;
import mage.players.Player;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class TournamentPlayer {
protected int points;
protected String name;
protected String playerType;
protected Player player;
protected Deck deck;
protected String results = "";
protected boolean eliminated = false;
protected boolean doneConstructing;
protected boolean joined = false;
public TournamentPlayer(Player player, String playerType) {
this.player = player;
this.playerType = playerType;
}
public Player getPlayer() {
return player;
}
public String getPlayerType() {
return playerType;
}
public Deck getDeck() {
return deck;
}
public int getPoints() {
return points;
}
public void setPoints(int points) {
this.points = points;
}
public boolean getEliminated() {
return eliminated;
}
public void setEliminated() {
this.eliminated = true;
}
public boolean isJoined() {
return joined;
}
public void setJoined() {
this.joined = true;
}
public void setConstructing() {
this.doneConstructing = false;
}
public void submitDeck(Deck deck) {
this.deck = deck;
this.doneConstructing = true;
}
public boolean isDoneConstructing() {
return this.doneConstructing;
}
public void setDeck(Deck deck) {
this.deck = deck;
}
public String getResults() {
return this.results;
}
public void setResults(String results) {
this.results = results;
}
}

View file

@ -1,58 +0,0 @@
/*
* 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
* 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.game.tournament;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public abstract class TournamentSingleElimination extends TournamentImpl {
public TournamentSingleElimination(TournamentOptions options) {
super(options);
}
@Override
protected void runTournament() {
while (this.getActivePlayers().size() > 1) {
Round round = createRoundRandom();
playRound(round);
eliminatePlayers(round);
}
nextStep();
}
private void eliminatePlayers(Round round) {
for (TournamentPairing pair: round.getPairs()) {
pair.eliminatePlayers();
}
}
}