allowing sorting by piles in deck editor

This commit is contained in:
BetaSteward 2011-02-21 00:21:20 -05:00
parent 85e1f68554
commit 8f2e4f09b6
6 changed files with 174 additions and 37 deletions

View file

@ -75,7 +75,7 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener
setOpaque(false);
}
public void loadCards(CardsView showCards, SortBy sortBy, BigCard bigCard, UUID gameId) {
public void loadCards(CardsView showCards, SortBy sortBy, boolean piles, BigCard bigCard, UUID gameId) {
this.bigCard = bigCard;
this.gameId = gameId;
for (CardView card: showCards.values()) {
@ -90,7 +90,7 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener
i.remove();
}
}
drawCards(sortBy);
drawCards(sortBy, piles);
this.setVisible(true);
}
@ -106,7 +106,7 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener
cards.put(card.getId(), cardImg);
}
public void drawCards(SortBy sortBy) {
public void drawCards(SortBy sortBy, boolean piles) {
int maxWidth = this.getParent().getWidth();
int numColumns = maxWidth / Config.dimensions.frameWidth;
int curColumn = 0;
@ -128,15 +128,54 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener
Collections.sort(sortedCards, new CardCostComparator());
break;
}
MageCard lastCard = null;
for (MageCard cardImg: sortedCards) {
rectangle.setLocation(curColumn * Config.dimensions.frameWidth, curRow * 20);
cardImg.setBounds(rectangle);
cardImg.setCardBounds(rectangle.x, rectangle.y, Config.dimensions.frameWidth, Config.dimensions.frameHeight);
moveToFront(cardImg);
curColumn++;
if (curColumn == numColumns) {
curColumn = 0;
if (piles) {
if (lastCard == null)
lastCard = cardImg;
switch (sortBy) {
case NAME:
if (!cardImg.getOriginal().getName().equals(lastCard.getOriginal().getName())) {
curColumn++;
curRow = 0;
}
break;
case RARITY:
if (!cardImg.getOriginal().getRarity().equals(lastCard.getOriginal().getRarity())) {
curColumn++;
curRow = 0;
}
break;
case COLOR:
if (cardImg.getOriginal().getColor().compareTo(lastCard.getOriginal().getColor()) != 0) {
curColumn++;
curRow = 0;
}
break;
case CASTING_COST:
if (cardImg.getOriginal().getConvertedManaCost() != lastCard.getOriginal().getConvertedManaCost()) {
curColumn++;
curRow = 0;
}
break;
}
rectangle.setLocation(curColumn * Config.dimensions.frameWidth, curRow * 20);
cardImg.setBounds(rectangle);
cardImg.setCardBounds(rectangle.x, rectangle.y, Config.dimensions.frameWidth, Config.dimensions.frameHeight);
moveToFront(cardImg);
curRow++;
lastCard = cardImg;
}
else {
rectangle.setLocation(curColumn * Config.dimensions.frameWidth, curRow * 20);
cardImg.setBounds(rectangle);
cardImg.setCardBounds(rectangle.x, rectangle.y, Config.dimensions.frameWidth, Config.dimensions.frameHeight);
moveToFront(cardImg);
curColumn++;
if (curColumn == numColumns) {
curColumn = 0;
curRow++;
}
}
}
}

View file

@ -27,7 +27,7 @@
<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="639" max="32767" attributes="0"/>
<Component id="jScrollPane1" alignment="0" pref="625" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
@ -35,7 +35,7 @@
<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="397" max="32767" attributes="0"/>
<Component id="jScrollPane1" pref="258" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -58,12 +58,14 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Component id="lblCount" min="-2" pref="81" max="-2" attributes="0"/>
<EmptySpace type="unrelated" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" min="-2" max="-2" attributes="1"/>
<Component id="lblCreatureCount" min="-2" pref="100" max="-2" attributes="0"/>
<EmptySpace type="unrelated" min="-2" max="-2" attributes="0"/>
<Component id="lblLandCount" min="-2" pref="75" max="-2" attributes="0"/>
<EmptySpace type="unrelated" min="-2" max="-2" attributes="0"/>
<Component id="cbSortBy" pref="353" max="32767" attributes="0"/>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Component id="chkPiles" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Component id="cbSortBy" pref="300" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -74,6 +76,7 @@
<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"/>
<Component id="chkPiles" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -109,6 +112,14 @@
<Property name="text" type="java.lang.String" value="Land Count"/>
</Properties>
</Component>
<Component class="javax.swing.JCheckBox" name="chkPiles">
<Properties>
<Property name="text" type="java.lang.String" value="Piles"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="chkPilesActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Container>
</SubComponents>

View file

@ -46,6 +46,7 @@ import java.util.List;
import java.util.UUID;
import javax.swing.DefaultComboBoxModel;
import mage.Constants.CardType;
import mage.ObjectColor;
import mage.cards.MageCard;
import mage.client.constants.Constants.SortBy;
@ -115,17 +116,58 @@ public class CardsList extends javax.swing.JPanel implements MouseListener {
Collections.sort(sortedCards, new CardViewCostComparator());
break;
}
CardView lastCard = null;
for (CardView card: sortedCards) {
rectangle.setLocation(curColumn * Config.dimensions.frameWidth, curRow * 20);
addCard(card, bigCard, gameId, rectangle);
if (card.getCardTypes().contains(CardType.LAND))
landCount++;
if (card.getCardTypes().contains(CardType.CREATURE))
creatureCount++;
curColumn++;
if (curColumn == numColumns) {
curColumn = 0;
if (chkPiles.isSelected()) {
if (lastCard == null)
lastCard = card;
switch (sortBy) {
case NAME:
if (!card.getName().equals(lastCard.getName())) {
curColumn++;
curRow = 0;
}
break;
case RARITY:
if (!card.getRarity().equals(lastCard.getRarity())) {
curColumn++;
curRow = 0;
}
break;
case COLOR:
if (card.getColor().compareTo(lastCard.getColor()) != 0) {
curColumn++;
curRow = 0;
}
break;
case CASTING_COST:
if (card.getConvertedManaCost() != lastCard.getConvertedManaCost()) {
curColumn++;
curRow = 0;
}
break;
}
rectangle.setLocation(curColumn * Config.dimensions.frameWidth, curRow * 20);
addCard(card, bigCard, gameId, rectangle);
if (card.getCardTypes().contains(CardType.LAND))
landCount++;
if (card.getCardTypes().contains(CardType.CREATURE))
creatureCount++;
curRow++;
lastCard = card;
}
else {
rectangle.setLocation(curColumn * Config.dimensions.frameWidth, curRow * 20);
addCard(card, bigCard, gameId, rectangle);
if (card.getCardTypes().contains(CardType.LAND))
landCount++;
if (card.getCardTypes().contains(CardType.CREATURE))
creatureCount++;
curColumn++;
if (curColumn == numColumns) {
curColumn = 0;
curRow++;
}
}
}
}
@ -176,6 +218,7 @@ public class CardsList extends javax.swing.JPanel implements MouseListener {
lblCount = new javax.swing.JLabel();
lblCreatureCount = new javax.swing.JLabel();
lblLandCount = new javax.swing.JLabel();
chkPiles = new javax.swing.JCheckBox();
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)));
@ -195,6 +238,13 @@ public class CardsList extends javax.swing.JPanel implements MouseListener {
lblLandCount.setText("Land Count");
chkPiles.setText("Piles");
chkPiles.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
chkPilesActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
@ -205,8 +255,10 @@ public class CardsList extends javax.swing.JPanel implements MouseListener {
.addComponent(lblCreatureCount, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(lblLandCount, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(cbSortBy, 0, 353, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(chkPiles)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cbSortBy, 0, 300, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@ -214,7 +266,8 @@ public class CardsList extends javax.swing.JPanel implements MouseListener {
.addComponent(cbSortBy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblCount)
.addComponent(lblCreatureCount)
.addComponent(lblLandCount))
.addComponent(lblLandCount)
.addComponent(chkPiles))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
@ -222,14 +275,14 @@ public class CardsList extends javax.swing.JPanel implements MouseListener {
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, 639, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 625, 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, 397, Short.MAX_VALUE))
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 258, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
@ -237,10 +290,15 @@ public class CardsList extends javax.swing.JPanel implements MouseListener {
drawCards((SortBy) cbSortBy.getSelectedItem());
}//GEN-LAST:event_cbSortByActionPerformed
private void chkPilesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkPilesActionPerformed
drawCards((SortBy) cbSortBy.getSelectedItem());
}//GEN-LAST:event_chkPilesActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLayeredPane cardArea;
private javax.swing.JComboBox cbSortBy;
private javax.swing.JCheckBox chkPiles;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel lblCount;

View file

@ -255,6 +255,17 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="rdoPlaneswalkersActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JCheckBox" name="chkPiles">
<Properties>
<Property name="text" type="java.lang.String" value="Piles"/>
<Property name="focusable" type="boolean" value="false"/>
<Property name="horizontalTextPosition" type="int" value="4"/>
<Property name="verticalTextPosition" type="int" value="3"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="chkPilesActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JComboBox" name="cbSortBy">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">

View file

@ -142,7 +142,7 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
filteredCards.add(card);
}
}
this.cardGrid.loadCards(new CardsView(filteredCards), (SortBy) cbSortBy.getSelectedItem(), bigCard, null);
this.cardGrid.loadCards(new CardsView(filteredCards), (SortBy) cbSortBy.getSelectedItem(), chkPiles.isSelected(), bigCard, null);
}
finally {
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
@ -198,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();
chkPiles = new javax.swing.JCheckBox();
cbSortBy = new javax.swing.JComboBox();
tbColor.setFloatable(false);
@ -394,6 +395,17 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
});
tbTypes.add(rdoPlaneswalkers);
chkPiles.setText("Piles");
chkPiles.setFocusable(false);
chkPiles.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
chkPiles.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
chkPiles.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
chkPilesActionPerformed(evt);
}
});
tbTypes.add(chkPiles);
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) {
@ -530,9 +542,14 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
private void cbSortByActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbSortByActionPerformed
if (cbSortBy.getSelectedItem() instanceof SortBy)
this.cardGrid.drawCards((SortBy) cbSortBy.getSelectedItem());
this.cardGrid.drawCards((SortBy) cbSortBy.getSelectedItem(), chkPiles.isSelected());
}//GEN-LAST:event_cbSortByActionPerformed
private void chkPilesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkPilesActionPerformed
if (cbSortBy.getSelectedItem() instanceof SortBy)
this.cardGrid.drawCards((SortBy) cbSortBy.getSelectedItem(), chkPiles.isSelected());
}//GEN-LAST:event_chkPilesActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnBooster;
@ -540,6 +557,7 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
private mage.client.cards.CardGrid cardGrid;
private javax.swing.JComboBox cbExpansionSet;
private javax.swing.JComboBox cbSortBy;
private javax.swing.JCheckBox chkPiles;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JRadioButton rdoArtifacts;
private javax.swing.JRadioButton rdoBlack;
@ -561,25 +579,25 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
@Override
public void componentResized(ComponentEvent e) {
if (cbSortBy.getSelectedItem() instanceof SortBy)
this.cardGrid.drawCards((SortBy) cbSortBy.getSelectedItem());
this.cardGrid.drawCards((SortBy) cbSortBy.getSelectedItem(), chkPiles.isSelected());
}
@Override
public void componentMoved(ComponentEvent e) {
if (cbSortBy.getSelectedItem() instanceof SortBy)
this.cardGrid.drawCards((SortBy) cbSortBy.getSelectedItem());
this.cardGrid.drawCards((SortBy) cbSortBy.getSelectedItem(), chkPiles.isSelected());
}
@Override
public void componentShown(ComponentEvent e) {
if (cbSortBy.getSelectedItem() instanceof SortBy)
this.cardGrid.drawCards((SortBy) cbSortBy.getSelectedItem());
this.cardGrid.drawCards((SortBy) cbSortBy.getSelectedItem(), chkPiles.isSelected());
}
@Override
public void componentHidden(ComponentEvent e) {
if (cbSortBy.getSelectedItem() instanceof SortBy)
this.cardGrid.drawCards((SortBy) cbSortBy.getSelectedItem());
this.cardGrid.drawCards((SortBy) cbSortBy.getSelectedItem(), chkPiles.isSelected());
}
}

View file

@ -98,7 +98,7 @@ public class DraftPanel extends javax.swing.JPanel {
public void loadBooster(DraftPickView draftPickView) {
draftBooster.loadBooster(draftPickView.getBooster(), bigCard);
draftPicks.loadCards(draftPickView.getPicks(), SortBy.NAME, bigCard, null);
draftPicks.loadCards(draftPickView.getPicks(), SortBy.NAME, false, bigCard, null);
this.draftBooster.clearCardEventListeners();
this.draftBooster.addCardEventListener(
new Listener<Event> () {
@ -108,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(), SortBy.NAME, bigCard, null);
draftPicks.loadCards(view.getPicks(), SortBy.NAME, false, bigCard, null);
setMessage("Waiting for other players");
}
}