* Removed land set restriction on limited add land dialog (fixes #4373).

This commit is contained in:
LevelX2 2018-02-03 18:35:47 +01:00
parent 75b8a4b165
commit 82defb2ab8

View file

@ -73,26 +73,27 @@ public class AddLandDialog extends MageDialog {
public void showDialog(Deck deck, DeckEditorMode mode) { public void showDialog(Deck deck, DeckEditorMode mode) {
this.deck = deck; this.deck = deck;
SortedSet<String> landSetNames = new TreeSet<>(); SortedSet<String> landSetNames = new TreeSet<>();
if (mode!=DeckEditorMode.FREE_BUILDING) { String defaultSetName = null;
if (mode != DeckEditorMode.FREE_BUILDING) {
// decide from which sets basic lands are taken from // decide from which sets basic lands are taken from
for (String setCode : deck.getExpansionSetCodes()) { for (String setCode : deck.getExpansionSetCodes()) {
ExpansionInfo expansionInfo = ExpansionRepository.instance.getSetByCode(setCode); ExpansionInfo expansionInfo = ExpansionRepository.instance.getSetByCode(setCode);
if (expansionInfo != null && expansionInfo.hasBasicLands()) { if (expansionInfo != null && expansionInfo.hasBasicLands()) {
this.landSetCodes.add(expansionInfo.getCode()); defaultSetName = expansionInfo.getName();
landSetNames.add(expansionInfo.getName()); break;
} }
} }
// if sets have no basic land, take land from block // if sets have no basic land, take land from block
if (this.landSetCodes.isEmpty()) { if (defaultSetName == null) {
for (String setCode : deck.getExpansionSetCodes()) { for (String setCode : deck.getExpansionSetCodes()) {
ExpansionInfo expansionInfo = ExpansionRepository.instance.getSetByCode(setCode); ExpansionInfo expansionInfo = ExpansionRepository.instance.getSetByCode(setCode);
if (expansionInfo != null) { if (expansionInfo != null) {
List<ExpansionInfo> blockSets = ExpansionRepository.instance.getSetsFromBlock(expansionInfo.getBlockName()); List<ExpansionInfo> blockSets = ExpansionRepository.instance.getSetsFromBlock(expansionInfo.getBlockName());
for (ExpansionInfo blockSet : blockSets) { for (ExpansionInfo blockSet : blockSets) {
if (blockSet.hasBasicLands()) { if (blockSet.hasBasicLands()) {
this.landSetCodes.add(blockSet.getCode()); defaultSetName = expansionInfo.getName();
landSetNames.add(blockSet.getName()); break;
} }
} }
} }
@ -100,12 +101,10 @@ public class AddLandDialog extends MageDialog {
} }
} }
// if still no set with lands found, add list of all available // if still no set with lands found, add list of all available
if (this.landSetCodes.isEmpty()) {
List<ExpansionInfo> basicLandSets = ExpansionRepository.instance.getSetsWithBasicLandsByReleaseDate(); List<ExpansionInfo> basicLandSets = ExpansionRepository.instance.getSetsWithBasicLandsByReleaseDate();
for (ExpansionInfo expansionInfo : basicLandSets) { for (ExpansionInfo expansionInfo : basicLandSets) {
landSetNames.add(expansionInfo.getName()); landSetNames.add(expansionInfo.getName());
} }
}
if (landSetNames.isEmpty()) { if (landSetNames.isEmpty()) {
throw new IllegalArgumentException("No set with basic land was found"); throw new IllegalArgumentException("No set with basic land was found");
} }
@ -113,12 +112,22 @@ public class AddLandDialog extends MageDialog {
landSetNames.add("<Random lands>"); landSetNames.add("<Random lands>");
} }
cbLandSet.setModel(new DefaultComboBoxModel(landSetNames.toArray())); cbLandSet.setModel(new DefaultComboBoxModel(landSetNames.toArray()));
if (defaultSetName != null) {
String item;
for (int i = 0; i < cbLandSet.getItemCount(); i++) {
item = (String) cbLandSet.getItemAt(i);
if (item.equalsIgnoreCase(defaultSetName)) {
cbLandSet.setSelectedIndex(i);
break;
}
}
}
// windows settings // windows settings
if (this.isModal()){ if (this.isModal()) {
MageFrame.getDesktop().add(this, JLayeredPane.MODAL_LAYER); MageFrame.getDesktop().add(this, JLayeredPane.MODAL_LAYER);
}else{ } else {
MageFrame.getDesktop().add(this, JLayeredPane.PALETTE_LAYER); MageFrame.getDesktop().add(this, JLayeredPane.PALETTE_LAYER);
} }