Add land dialog is now also shown during free deck building. Added a set selection drop down box to select the set the lands are used from.

This commit is contained in:
LevelX2 2015-06-04 19:37:54 +02:00
parent 1456e0172c
commit 3b9cb1dc6e
4 changed files with 161 additions and 95 deletions

View file

@ -186,6 +186,7 @@ public class DeckEditorPanel extends javax.swing.JPanel {
break;
case FREE_BUILDING:
this.btnSubmit.setVisible(false);
this.btnAddLand.setVisible(true);
this.cardSelector.loadCards(this.bigCard);
//this.cardTableSelector.loadCards(this.bigCard);
this.btnExit.setVisible(true);
@ -796,7 +797,7 @@ public class DeckEditorPanel extends javax.swing.JPanel {
private void btnAddLandActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddLandActionPerformed
AddLandDialog addLand = new AddLandDialog();
addLand.showDialog(deck);
addLand.showDialog(deck, mode);
refreshDeck();
}//GEN-LAST:event_btnAddLandActionPerformed

View file

@ -29,9 +29,9 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Group type="103" groupAlignment="1" attributes="0">
<Group type="102" alignment="1" attributes="0">
@ -39,34 +39,43 @@
<Component id="lblIsland" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="lblMountain" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="lblForest" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="lblLandSet" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="spnMountain" pref="85" max="32767" attributes="0"/>
<Component id="spnIsland" max="32767" attributes="0"/>
<Component id="spnForest" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="spnMountain" pref="85" max="32767" attributes="0"/>
<Component id="spnIsland" max="32767" attributes="0"/>
<Component id="spnForest" max="32767" attributes="0"/>
</Group>
<Component id="cbLandSet" min="-2" pref="207" max="-2" attributes="0"/>
</Group>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="lblPains" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="21" max="-2" attributes="0"/>
<Component id="spnPlains" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="lblSwamp" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="14" max="-2" attributes="0"/>
<Component id="spnSwamp" max="32767" attributes="0"/>
<Group type="102" alignment="1" attributes="0">
<Group type="103" groupAlignment="1" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="lblSwamp" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="14" max="-2" attributes="0"/>
<Component id="spnSwamp" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="lblPains" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="21" max="-2" attributes="0"/>
<Component id="spnPlains" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace min="-2" pref="122" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace min="-2" pref="114" max="-2" attributes="0"/>
<EmptySpace min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="btnCancel" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="btnAutoAdd" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="btnAdd" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="40" max="32767" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
</Group>
@ -75,6 +84,11 @@
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="cbLandSet" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="lblLandSet" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblForest" alignment="3" min="-2" max="-2" attributes="0"/>
@ -100,7 +114,7 @@
<Component id="lblSwamp" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="spnSwamp" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="38" max="32767" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="btnAdd" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnCancel" alignment="3" min="-2" max="-2" attributes="0"/>
@ -112,6 +126,23 @@
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="lblLandSet">
<Properties>
<Property name="text" type="java.lang.String" value="Set"/>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="cbLandSet">
<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>
</Component>
<Component class="javax.swing.JLabel" name="lblForest">
<Properties>
<Property name="text" type="java.lang.String" value="Forest"/>
@ -124,6 +155,11 @@
</Property>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblIsland">
<Properties>
<Property name="text" type="java.lang.String" value="Island"/>
</Properties>
</Component>
<Component class="javax.swing.JSpinner" name="spnIsland">
<Properties>
<Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor">
@ -131,9 +167,16 @@
</Property>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblIsland">
<Component class="javax.swing.JLabel" name="lblMountain">
<Properties>
<Property name="text" type="java.lang.String" value="Island"/>
<Property name="text" type="java.lang.String" value="Mountain"/>
</Properties>
</Component>
<Component class="javax.swing.JSpinner" name="spnMountain">
<Properties>
<Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor">
<SpinnerModel initial="0" minimum="0" numberType="java.lang.Integer" stepSize="1" type="number"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblPains">
@ -148,16 +191,9 @@
</Property>
</Properties>
</Component>
<Component class="javax.swing.JSpinner" name="spnMountain">
<Component class="javax.swing.JLabel" name="lblSwamp">
<Properties>
<Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor">
<SpinnerModel initial="0" minimum="0" numberType="java.lang.Integer" stepSize="1" type="number"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblMountain">
<Properties>
<Property name="text" type="java.lang.String" value="Mountain"/>
<Property name="text" type="java.lang.String" value="Swamp"/>
</Properties>
</Component>
<Component class="javax.swing.JSpinner" name="spnSwamp">
@ -167,11 +203,6 @@
</Property>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblSwamp">
<Properties>
<Property name="text" type="java.lang.String" value="Swamp"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="btnAdd">
<Properties>
<Property name="text" type="java.lang.String" value="Add"/>

View file

@ -31,6 +31,9 @@ import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JLayeredPane;
import mage.Mana;
import mage.cards.Card;
@ -41,6 +44,7 @@ import mage.cards.repository.CardRepository;
import mage.cards.repository.ExpansionInfo;
import mage.cards.repository.ExpansionRepository;
import mage.client.MageFrame;
import mage.client.constants.Constants.DeckEditorMode;
import mage.constants.Rarity;
/**
@ -60,45 +64,49 @@ public class AddLandDialog extends MageDialog {
this.setModal(true);
}
public void showDialog(Deck deck) {
public void showDialog(Deck deck, DeckEditorMode mode) {
this.deck = deck;
// decide from which sets basic lands are taken from
for (String setCode :deck.getExpansionSetCodes()) {
ExpansionInfo expansionInfo = ExpansionRepository.instance.getSetByCode(setCode);
if (expansionInfo != null && expansionInfo.hasBasicLands()) {
this.setCodesland.add(expansionInfo.getCode());
}
}
// if sets have no basic land, take land from block
if (this.setCodesland.isEmpty()) {
SortedSet<String> landSets = new TreeSet<>();
if (!mode.equals(DeckEditorMode.FREE_BUILDING)) {
// decide from which sets basic lands are taken from
for (String setCode :deck.getExpansionSetCodes()) {
ExpansionInfo expansionInfo = ExpansionRepository.instance.getSetByCode(setCode);
if (expansionInfo != null) {
List<ExpansionInfo> blockSets = ExpansionRepository.instance.getSetsFromBlock(expansionInfo.getBlockName());
for (ExpansionInfo blockSet: blockSets) {
if (blockSet.hasBasicLands()) {
this.setCodesland.add(blockSet.getCode());
if (expansionInfo != null && expansionInfo.hasBasicLands()) {
this.setCodesland.add(expansionInfo.getCode());
landSets.add(expansionInfo.getName());
}
}
// if sets have no basic land, take land from block
if (this.setCodesland.isEmpty()) {
for (String setCode :deck.getExpansionSetCodes()) {
ExpansionInfo expansionInfo = ExpansionRepository.instance.getSetByCode(setCode);
if (expansionInfo != null) {
List<ExpansionInfo> blockSets = ExpansionRepository.instance.getSetsFromBlock(expansionInfo.getBlockName());
for (ExpansionInfo blockSet: blockSets) {
if (blockSet.hasBasicLands()) {
this.setCodesland.add(blockSet.getCode());
landSets.add(blockSet.getName());
}
}
}
}
}
}
// if still no set with lands found, take one by random
}
// if still no set with lands found, add list of all available
if (this.setCodesland.isEmpty()) {
// if sets have no basic lands and also it has no parent or parent has no lands get last set with lands
// select a set with basic lands by random
Random generator = new Random();
List<ExpansionInfo> basicLandSets = ExpansionRepository.instance.getSetsWithBasicLandsByReleaseDate();
if (basicLandSets.size() > 0) {
this.setCodesland.add(basicLandSets.get(generator.nextInt(basicLandSets.size())).getCode());
for (ExpansionInfo expansionInfo: basicLandSets) {
landSets.add(expansionInfo.getName());
}
}
if (this.setCodesland.isEmpty()) {
}
if (landSets.isEmpty()) {
throw new IllegalArgumentException("No set with basic land was found");
}
if(landSets.size() > 1) {
landSets.add("<Random lands>");
}
cbLandSet.setModel(new DefaultComboBoxModel(landSets.toArray()));
MageFrame.getDesktop().add(this, JLayeredPane.PALETTE_LAYER);
this.setVisible(true);
@ -106,14 +114,22 @@ public class AddLandDialog extends MageDialog {
private void addLands(String landName, int number) {
Random random = new Random();
String landSetName = (String) cbLandSet.getSelectedItem();
CardCriteria criteria = new CardCriteria();
if (!setCodesland.isEmpty()) {
if (landSetName.equals("<Random lands>")) {
criteria.setCodes(setCodesland.toArray(new String[setCodesland.size()]));
}
} else {
ExpansionInfo expansionInfo = ExpansionRepository.instance.getSetByName(landSetName);
if (expansionInfo == null) {
throw new IllegalArgumentException("Code of Set " + landSetName + " not found");
}
criteria.setCodes(expansionInfo.getCode());
}
criteria.rarities(Rarity.LAND).name(landName);
List<CardInfo> cards = CardRepository.instance.findCards(criteria);
if (cards.isEmpty()) {
return;
throw new IllegalArgumentException("No basic lands found in Set: " + landSetName);
}
for (int i = 0; i < number; i++) {
@ -132,16 +148,18 @@ public class AddLandDialog extends MageDialog {
private void initComponents() {
jButton2 = new javax.swing.JButton();
lblLandSet = new javax.swing.JLabel();
cbLandSet = new javax.swing.JComboBox();
lblForest = new javax.swing.JLabel();
spnForest = new javax.swing.JSpinner();
spnIsland = new javax.swing.JSpinner();
lblIsland = new javax.swing.JLabel();
spnIsland = new javax.swing.JSpinner();
lblMountain = new javax.swing.JLabel();
spnMountain = new javax.swing.JSpinner();
lblPains = new javax.swing.JLabel();
spnPlains = new javax.swing.JSpinner();
spnMountain = new javax.swing.JSpinner();
lblMountain = new javax.swing.JLabel();
spnSwamp = new javax.swing.JSpinner();
lblSwamp = new javax.swing.JLabel();
spnSwamp = new javax.swing.JSpinner();
btnAdd = new javax.swing.JButton();
btnCancel = new javax.swing.JButton();
btnAutoAdd = new javax.swing.JButton();
@ -150,26 +168,30 @@ public class AddLandDialog extends MageDialog {
setTitle("Add Land");
lblLandSet.setText("Set");
cbLandSet.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
lblForest.setText("Forest");
spnForest.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(1)));
lblIsland.setText("Island");
spnIsland.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(1)));
lblIsland.setText("Island");
lblMountain.setText("Mountain");
spnMountain.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(1)));
lblPains.setText("Plains");
spnPlains.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(1)));
spnMountain.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(1)));
lblMountain.setText("Mountain");
lblSwamp.setText("Swamp");
spnSwamp.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(1)));
lblSwamp.setText("Swamp");
btnAdd.setText("Add");
btnAdd.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
@ -197,40 +219,50 @@ public class AddLandDialog extends MageDialog {
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblIsland)
.addComponent(lblMountain)
.addComponent(lblForest))
.addComponent(lblForest)
.addComponent(lblLandSet))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(spnMountain, javax.swing.GroupLayout.DEFAULT_SIZE, 85, Short.MAX_VALUE)
.addComponent(spnIsland)
.addComponent(spnForest)))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(lblPains)
.addGap(21, 21, 21)
.addComponent(spnPlains))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(lblSwamp)
.addGap(14, 14, 14)
.addComponent(spnSwamp)))
.addGap(114, 114, 114))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(spnMountain, javax.swing.GroupLayout.DEFAULT_SIZE, 85, Short.MAX_VALUE)
.addComponent(spnIsland)
.addComponent(spnForest))
.addComponent(cbLandSet, javax.swing.GroupLayout.PREFERRED_SIZE, 207, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(lblSwamp)
.addGap(14, 14, 14)
.addComponent(spnSwamp))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(lblPains)
.addGap(21, 21, 21)
.addComponent(spnPlains)))
.addGap(122, 122, 122)))
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addComponent(btnCancel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btnAutoAdd)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btnAdd)
.addGap(0, 40, Short.MAX_VALUE))))
.addGap(0, 0, Short.MAX_VALUE))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cbLandSet, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblLandSet))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblForest)
.addComponent(spnForest, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
@ -250,7 +282,7 @@ public class AddLandDialog extends MageDialog {
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblSwamp)
.addComponent(spnSwamp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 38, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnAdd)
.addComponent(btnCancel)
@ -322,9 +354,11 @@ public class AddLandDialog extends MageDialog {
private javax.swing.JButton btnAdd;
private javax.swing.JButton btnAutoAdd;
private javax.swing.JButton btnCancel;
private javax.swing.JComboBox cbLandSet;
private javax.swing.JButton jButton2;
private javax.swing.JLabel lblForest;
private javax.swing.JLabel lblIsland;
private javax.swing.JLabel lblLandSet;
private javax.swing.JLabel lblMountain;
private javax.swing.JLabel lblPains;
private javax.swing.JLabel lblSwamp;

View file

@ -78,7 +78,7 @@ public class ColorsChooser extends JComboBox implements ListCellRenderer {
}
private void drawOn(JPanel panel, String value) {
List<Image> images = new ArrayList<Image>();
List<Image> images = new ArrayList<>();
value = value.toUpperCase();
for (int i = 0; i < value.length(); i++) {
char symbol = value.charAt(i);