mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
1) You can use a Draft/Sealed deck as your quest starting card pool, 2) You can enforce formats when playing with specific starting pools, 3) Fixed a bug in the custom format dialog.
This commit is contained in:
@@ -3,6 +3,7 @@ package forge.gui.home.quest;
|
|||||||
import static forge.quest.QuestStartPool.Complete;
|
import static forge.quest.QuestStartPool.Complete;
|
||||||
import static forge.quest.QuestStartPool.Precon;
|
import static forge.quest.QuestStartPool.Precon;
|
||||||
import static forge.quest.QuestStartPool.Rotating;
|
import static forge.quest.QuestStartPool.Rotating;
|
||||||
|
import static forge.quest.QuestStartPool.UserDeck;
|
||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
@@ -12,9 +13,12 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.swing.JFileChooser;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
import forge.Command;
|
import forge.Command;
|
||||||
|
import forge.deck.Deck;
|
||||||
|
import forge.deck.io.DeckSerializer;
|
||||||
import forge.Singletons;
|
import forge.Singletons;
|
||||||
import forge.gui.framework.ICDoc;
|
import forge.gui.framework.ICDoc;
|
||||||
import forge.properties.ForgeProps;
|
import forge.properties.ForgeProps;
|
||||||
@@ -47,17 +51,27 @@ public enum CSubmenuQuestData implements ICDoc {
|
|||||||
private final Command cmdQuestSelect = new Command() { @Override
|
private final Command cmdQuestSelect = new Command() { @Override
|
||||||
public void execute() { changeQuest(); } };
|
public void execute() { changeQuest(); } };
|
||||||
|
|
||||||
|
private File userDeck = null;
|
||||||
private final Command cmdQuestDelete = new Command() { @Override
|
private final Command cmdQuestDelete = new Command() { @Override
|
||||||
public void execute() { update(); } };
|
public void execute() { update(); } };
|
||||||
|
|
||||||
private final ActionListener preconListener = new ActionListener() {
|
private final ActionListener preconListener = new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent actionEvent) {
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
view.getCbxFormat().setEnabled(view.getRadRotatingStart().isSelected() && !view.getBoxCustom().isSelected());
|
view.getCbxFormat().setEnabled(view.getRadRotatingStart().isSelected()
|
||||||
view.getCbxPrecon().setEnabled(view.getRadPreconStart().isSelected());
|
|| (view.getRadPreconStart().isSelected() && view.getBoxDeckFormat().isSelected())
|
||||||
view.getBoxPersist().setEnabled(view.getRadRotatingStart().isSelected());
|
&& !view.getBoxCustom().isSelected());
|
||||||
view.getBoxCustom().setEnabled(view.getRadRotatingStart().isSelected());
|
view.getCbxPrecon().setEnabled(view.getRadPreconStart().isSelected() && !view.getBoxDeckUser().isSelected());
|
||||||
view.getBtnCustom().setEnabled(view.getRadRotatingStart().isSelected() && view.getBoxCustom().isSelected());
|
view.getBoxPersist().setEnabled(view.getRadRotatingStart().isSelected()
|
||||||
|
|| (view.getRadPreconStart().isSelected() && view.getBoxDeckFormat().isSelected()));
|
||||||
|
view.getBoxCustom().setEnabled(view.getRadRotatingStart().isSelected()
|
||||||
|
|| (view.getRadPreconStart().isSelected() && view.getBoxDeckFormat().isSelected() && view.getBoxPersist().isSelected()));
|
||||||
|
view.getBtnCustom().setEnabled((view.getRadRotatingStart().isSelected()
|
||||||
|
|| (view.getRadPreconStart().isSelected() && view.getBoxDeckFormat().isSelected()) && view.getBoxPersist().isSelected())
|
||||||
|
&& view.getBoxCustom().isSelected());
|
||||||
|
view.getBoxDeckUser().setEnabled(view.getRadPreconStart().isSelected());
|
||||||
|
view.getBtnDeckImport().setEnabled(view.getRadPreconStart().isSelected() && view.getBoxDeckUser().isSelected());
|
||||||
|
view.getBoxDeckFormat().setEnabled(view.getRadPreconStart().isSelected());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private final ActionListener customFormatListener = new ActionListener() {
|
private final ActionListener customFormatListener = new ActionListener() {
|
||||||
@@ -72,6 +86,28 @@ public enum CSubmenuQuestData implements ICDoc {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private final ActionListener btnDeckImportListener = new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
final JFileChooser open = new JFileChooser(ForgeProps.getFile(NewConstants.NEW_DECKS));
|
||||||
|
open.setDialogTitle("Import a Draft/Sealed Deck");
|
||||||
|
open.addChoosableFileFilter(DeckSerializer.DCK_FILTER);
|
||||||
|
open.setCurrentDirectory(ForgeProps.getFile(NewConstants.NEW_DECKS));
|
||||||
|
final int returnVal = open.showOpenDialog(null);
|
||||||
|
|
||||||
|
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||||
|
userDeck = open.getSelectedFile();
|
||||||
|
if (userDeck.getPath().toLowerCase().contains("draft") || userDeck.getPath().toLowerCase().contains("sealed")) {
|
||||||
|
} else {
|
||||||
|
JOptionPane.showMessageDialog(null, "Only Sealed Deck and Draft decks are allowed as a starting deck",
|
||||||
|
"Illegal starting deck", JOptionPane.ERROR_MESSAGE);
|
||||||
|
userDeck = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see forge.control.home.IControlSubmenu#update()
|
* @see forge.control.home.IControlSubmenu#update()
|
||||||
*/
|
*/
|
||||||
@@ -85,6 +121,9 @@ public enum CSubmenuQuestData implements ICDoc {
|
|||||||
view.getRadPreconStart().addActionListener(preconListener);
|
view.getRadPreconStart().addActionListener(preconListener);
|
||||||
view.getBoxCustom().addActionListener(preconListener);
|
view.getBoxCustom().addActionListener(preconListener);
|
||||||
view.getBtnFormatCustom().addActionListener(customFormatListener);
|
view.getBtnFormatCustom().addActionListener(customFormatListener);
|
||||||
|
view.getBoxDeckUser().addActionListener(preconListener);
|
||||||
|
view.getBoxDeckFormat().addActionListener(preconListener);
|
||||||
|
view.getBtnDeckImport().addActionListener(btnDeckImportListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
@@ -154,6 +193,11 @@ public enum CSubmenuQuestData implements ICDoc {
|
|||||||
final VSubmenuQuestData view = VSubmenuQuestData.SINGLETON_INSTANCE;
|
final VSubmenuQuestData view = VSubmenuQuestData.SINGLETON_INSTANCE;
|
||||||
int difficulty = 0;
|
int difficulty = 0;
|
||||||
|
|
||||||
|
if (view.getRadPreconStart().isSelected() && view.getBoxDeckUser().isSelected() && userDeck == null) {
|
||||||
|
JOptionPane.showMessageDialog(null, "Please select a deck first!",
|
||||||
|
"No deck selected", JOptionPane.ERROR_MESSAGE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
final QuestMode mode = view.getBoxFantasy().isSelected() ? QuestMode.Fantasy : QuestMode.Classic;
|
final QuestMode mode = view.getBoxFantasy().isSelected() ? QuestMode.Fantasy : QuestMode.Classic;
|
||||||
|
|
||||||
if (view.getRadEasy().isSelected()) {
|
if (view.getRadEasy().isSelected()) {
|
||||||
@@ -177,7 +221,11 @@ public enum CSubmenuQuestData implements ICDoc {
|
|||||||
} else if (view.getRadRotatingStart().isSelected()) {
|
} else if (view.getRadRotatingStart().isSelected()) {
|
||||||
startPool = Rotating;
|
startPool = Rotating;
|
||||||
} else {
|
} else {
|
||||||
startPool = Precon;
|
if (view.getBoxDeckUser().isSelected() && userDeck != null) {
|
||||||
|
startPool = UserDeck;
|
||||||
|
} else {
|
||||||
|
startPool = Precon;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final Object o = JOptionPane.showInputDialog(null, "Poets will remember your quest as:", "Quest Name", JOptionPane.OK_CANCEL_OPTION);
|
final Object o = JOptionPane.showInputDialog(null, "Poets will remember your quest as:", "Quest Name", JOptionPane.OK_CANCEL_OPTION);
|
||||||
@@ -192,13 +240,18 @@ public enum CSubmenuQuestData implements ICDoc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Give the user a few cards to build a deck
|
// Give the user a few cards to build a deck
|
||||||
final boolean useCustomFormat = (view.getRadRotatingStart().isSelected() && view.getBoxCustom().isSelected());
|
final boolean useCustomFormat = ((view.getRadRotatingStart().isSelected()
|
||||||
|
|| (view.getRadPreconStart().isSelected() && view.getBoxDeckFormat().isSelected()))
|
||||||
|
&& view.getBoxCustom().isSelected());
|
||||||
if (useCustomFormat && userFormat != null) {
|
if (useCustomFormat && userFormat != null) {
|
||||||
userFormat.updateFilters();
|
userFormat.updateFilters();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final boolean doPersist = view.getBoxPersist().isSelected()
|
||||||
|
&& (view.getRadRotatingStart().isSelected() || (view.getRadPreconStart().isSelected() && view.getBoxDeckFormat().isSelected()));
|
||||||
|
|
||||||
Singletons.getModel().getQuest().newGame(questName, difficulty, mode, startPool, rotatingFormat, startPrecon,
|
Singletons.getModel().getQuest().newGame(questName, difficulty, mode, startPool, rotatingFormat, startPrecon,
|
||||||
useCustomFormat ? userFormat : null,
|
useCustomFormat ? userFormat : null, doPersist, userDeck);
|
||||||
view.getBoxPersist().isSelected());
|
|
||||||
Singletons.getModel().getQuest().save();
|
Singletons.getModel().getQuest().save();
|
||||||
|
|
||||||
// Save in preferences.
|
// Save in preferences.
|
||||||
|
|||||||
@@ -150,6 +150,8 @@ public class DialogCustomFormat extends JDialog {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fix a problem with not updating changes
|
||||||
|
customFormat.emptyAllowedSets();
|
||||||
|
|
||||||
for (int i = 0; i < choices.length; i++) {
|
for (int i = 0; i < choices.length; i++) {
|
||||||
if (choices[i] != null) {
|
if (choices[i] != null) {
|
||||||
|
|||||||
@@ -81,6 +81,10 @@ public enum VSubmenuQuestData implements IVSubmenu<CSubmenuQuestData> {
|
|||||||
|
|
||||||
private final JRadioButton radPreconStart = new FRadioButton("Preconstructed Deck: ");
|
private final JRadioButton radPreconStart = new FRadioButton("Preconstructed Deck: ");
|
||||||
private final JComboBox cbxPrecon = new JComboBox();
|
private final JComboBox cbxPrecon = new JComboBox();
|
||||||
|
private final FCheckBox boxDeckUser = new FCheckBox("User Deck");
|
||||||
|
private final JButton btnDeckImport = new JButton("Import");
|
||||||
|
private final FCheckBox boxDeckFormat = new FCheckBox("Use Format");
|
||||||
|
|
||||||
|
|
||||||
private final FLabel btnEmbark = new FLabel.Builder().opaque(true)
|
private final FLabel btnEmbark = new FLabel.Builder().opaque(true)
|
||||||
.fontSize(16).hoverable(true).text("Embark!").build();
|
.fontSize(16).hoverable(true).text("Embark!").build();
|
||||||
@@ -152,6 +156,9 @@ public enum VSubmenuQuestData implements IVSubmenu<CSubmenuQuestData> {
|
|||||||
radUnrestricted.setSelected(true);
|
radUnrestricted.setSelected(true);
|
||||||
cbxPrecon.setEnabled(false);
|
cbxPrecon.setEnabled(false);
|
||||||
radMedium.setEnabled(true);
|
radMedium.setEnabled(true);
|
||||||
|
boxDeckUser.setEnabled(false);
|
||||||
|
btnDeckImport.setEnabled(false);
|
||||||
|
boxDeckFormat.setEnabled(false);
|
||||||
|
|
||||||
// Fantasy box enabled by Default
|
// Fantasy box enabled by Default
|
||||||
boxFantasy.setSelected(true);
|
boxFantasy.setSelected(true);
|
||||||
@@ -176,7 +183,10 @@ public enum VSubmenuQuestData implements IVSubmenu<CSubmenuQuestData> {
|
|||||||
pnlOptions.add(boxFormatPersist, constraints);
|
pnlOptions.add(boxFormatPersist, constraints);
|
||||||
|
|
||||||
pnlOptions.add(boxFantasy, constraints + ", gap 1% 4% 0 5px");
|
pnlOptions.add(boxFantasy, constraints + ", gap 1% 4% 0 5px");
|
||||||
pnlOptions.add(radPreconStart, constraints);
|
pnlOptions.add(radPreconStart, constraints + ", w 14%!, h 27px!, split 4");
|
||||||
|
pnlOptions.add(boxDeckUser, constraints + ", w 12%!, h 27px!");
|
||||||
|
pnlOptions.add(btnDeckImport, constraints + ", w 12%!, h 27px!");
|
||||||
|
pnlOptions.add(boxDeckFormat, constraints + ", w 12%!, h 27px!");
|
||||||
|
|
||||||
pnlOptions.add(cbxPrecon, constraints + ", skip 1");
|
pnlOptions.add(cbxPrecon, constraints + ", skip 1");
|
||||||
pnlOptions.add(btnEmbark, "w 300px!, h 30px!, ax center, span 2, gap 0 0 15px 30px");
|
pnlOptions.add(btnEmbark, "w 300px!, h 30px!, ax center, span 2, gap 0 0 15px 30px");
|
||||||
@@ -304,6 +314,27 @@ public enum VSubmenuQuestData implements IVSubmenu<CSubmenuQuestData> {
|
|||||||
return radPreconStart;
|
return radPreconStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {@link javax.swing.JCheckBox}
|
||||||
|
*/
|
||||||
|
public JCheckBox getBoxDeckUser() {
|
||||||
|
return boxDeckUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {@link javax.swing.JButton}
|
||||||
|
*/
|
||||||
|
public JButton getBtnDeckImport() {
|
||||||
|
return btnDeckImport;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {@link javax.swing.JCheckBox}
|
||||||
|
*/
|
||||||
|
public JCheckBox getBoxDeckFormat() {
|
||||||
|
return boxDeckFormat;
|
||||||
|
}
|
||||||
|
|
||||||
/** @return {@link javax.swing.JComboBox} */
|
/** @return {@link javax.swing.JComboBox} */
|
||||||
public JComboBox getCbxFormat() {
|
public JComboBox getCbxFormat() {
|
||||||
return this.cbxFormat;
|
return this.cbxFormat;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package forge.quest;
|
package forge.quest;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -213,11 +214,15 @@ public class QuestController {
|
|||||||
* @param userFormat user-defined format, if any
|
* @param userFormat user-defined format, if any
|
||||||
* @param persist
|
* @param persist
|
||||||
* enforce the format for the whole quest
|
* enforce the format for the whole quest
|
||||||
|
* @param userDeck
|
||||||
|
* user-specified starting deck
|
||||||
*/
|
*/
|
||||||
public void newGame(final String name, final int diff, final QuestMode mode, final QuestStartPool startPool,
|
public void newGame(final String name, final int diff, final QuestMode mode, final QuestStartPool startPool,
|
||||||
final String startFormat, final String preconName, final GameFormatQuest userFormat, final boolean persist) {
|
final String startFormat, final String preconName, final GameFormatQuest userFormat, final boolean persist,
|
||||||
|
final File userDeck) {
|
||||||
|
|
||||||
if (persist && startPool == QuestStartPool.Rotating) {
|
if (persist
|
||||||
|
&& (startPool == QuestStartPool.Rotating || startPool == QuestStartPool.Precon || startPool == QuestStartPool.UserDeck)) {
|
||||||
this.load(new QuestData(name, diff, mode, startFormat, userFormat));
|
this.load(new QuestData(name, diff, mode, startFormat, userFormat));
|
||||||
} else {
|
} else {
|
||||||
this.load(new QuestData(name, diff, mode, null, null));
|
this.load(new QuestData(name, diff, mode, null, null));
|
||||||
@@ -225,6 +230,12 @@ public class QuestController {
|
|||||||
|
|
||||||
final Predicate<CardPrinted> filter;
|
final Predicate<CardPrinted> filter;
|
||||||
switch (startPool) {
|
switch (startPool) {
|
||||||
|
case UserDeck:
|
||||||
|
if (userDeck == null) {
|
||||||
|
throw new RuntimeException("User deck is null!");
|
||||||
|
}
|
||||||
|
this.myCards.addDeck(Deck.fromFile(userDeck));
|
||||||
|
return;
|
||||||
case Precon:
|
case Precon:
|
||||||
this.myCards.addPreconDeck(QuestController.getPrecons().get(preconName));
|
this.myCards.addPreconDeck(QuestController.getPrecons().get(preconName));
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -3,5 +3,6 @@ package forge.quest;
|
|||||||
public enum QuestStartPool {
|
public enum QuestStartPool {
|
||||||
Complete,
|
Complete,
|
||||||
Rotating,
|
Rotating,
|
||||||
Precon
|
Precon,
|
||||||
|
UserDeck
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -246,6 +246,15 @@ public final class QuestUtilCards {
|
|||||||
this.addAllCards(precon.getDeck().getSideboard().toFlatList());
|
this.addAllCards(precon.getDeck().getSideboard().toFlatList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void addDeck(final Deck fromDeck) {
|
||||||
|
if (fromDeck == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.qc.getMyDecks().add(fromDeck);
|
||||||
|
this.addAllCards(fromDeck.getMain().toFlatList());
|
||||||
|
this.addAllCards(fromDeck.getSideboard().toFlatList());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sell card.
|
* Sell card.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -129,6 +129,17 @@ public final class GameFormatQuest {
|
|||||||
this.filterPrinted = this.buildFilterPrinted();
|
this.filterPrinted = this.buildFilterPrinted();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Empty the whole list.
|
||||||
|
*/
|
||||||
|
public void emptyAllowedSets() {
|
||||||
|
if (allowedSetCodes != null) {
|
||||||
|
while (!allowedSetCodes.isEmpty()) {
|
||||||
|
allowedSetCodes.remove(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param setCode
|
* @param setCode
|
||||||
* the set code to add
|
* the set code to add
|
||||||
|
|||||||
Reference in New Issue
Block a user