mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 18:58: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.Precon;
|
||||
import static forge.quest.QuestStartPool.Rotating;
|
||||
import static forge.quest.QuestStartPool.UserDeck;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
@@ -12,9 +13,12 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import forge.Command;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.io.DeckSerializer;
|
||||
import forge.Singletons;
|
||||
import forge.gui.framework.ICDoc;
|
||||
import forge.properties.ForgeProps;
|
||||
@@ -47,17 +51,27 @@ public enum CSubmenuQuestData implements ICDoc {
|
||||
private final Command cmdQuestSelect = new Command() { @Override
|
||||
public void execute() { changeQuest(); } };
|
||||
|
||||
private File userDeck = null;
|
||||
private final Command cmdQuestDelete = new Command() { @Override
|
||||
public void execute() { update(); } };
|
||||
|
||||
private final ActionListener preconListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
view.getCbxFormat().setEnabled(view.getRadRotatingStart().isSelected() && !view.getBoxCustom().isSelected());
|
||||
view.getCbxPrecon().setEnabled(view.getRadPreconStart().isSelected());
|
||||
view.getBoxPersist().setEnabled(view.getRadRotatingStart().isSelected());
|
||||
view.getBoxCustom().setEnabled(view.getRadRotatingStart().isSelected());
|
||||
view.getBtnCustom().setEnabled(view.getRadRotatingStart().isSelected() && view.getBoxCustom().isSelected());
|
||||
view.getCbxFormat().setEnabled(view.getRadRotatingStart().isSelected()
|
||||
|| (view.getRadPreconStart().isSelected() && view.getBoxDeckFormat().isSelected())
|
||||
&& !view.getBoxCustom().isSelected());
|
||||
view.getCbxPrecon().setEnabled(view.getRadPreconStart().isSelected() && !view.getBoxDeckUser().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() {
|
||||
@@ -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)
|
||||
* @see forge.control.home.IControlSubmenu#update()
|
||||
*/
|
||||
@@ -85,6 +121,9 @@ public enum CSubmenuQuestData implements ICDoc {
|
||||
view.getRadPreconStart().addActionListener(preconListener);
|
||||
view.getBoxCustom().addActionListener(preconListener);
|
||||
view.getBtnFormatCustom().addActionListener(customFormatListener);
|
||||
view.getBoxDeckUser().addActionListener(preconListener);
|
||||
view.getBoxDeckFormat().addActionListener(preconListener);
|
||||
view.getBtnDeckImport().addActionListener(btnDeckImportListener);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -154,6 +193,11 @@ public enum CSubmenuQuestData implements ICDoc {
|
||||
final VSubmenuQuestData view = VSubmenuQuestData.SINGLETON_INSTANCE;
|
||||
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;
|
||||
|
||||
if (view.getRadEasy().isSelected()) {
|
||||
@@ -177,7 +221,11 @@ public enum CSubmenuQuestData implements ICDoc {
|
||||
} else if (view.getRadRotatingStart().isSelected()) {
|
||||
startPool = Rotating;
|
||||
} 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);
|
||||
@@ -192,13 +240,18 @@ public enum CSubmenuQuestData implements ICDoc {
|
||||
}
|
||||
|
||||
// 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) {
|
||||
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,
|
||||
useCustomFormat ? userFormat : null,
|
||||
view.getBoxPersist().isSelected());
|
||||
useCustomFormat ? userFormat : null, doPersist, userDeck);
|
||||
Singletons.getModel().getQuest().save();
|
||||
|
||||
// Save in preferences.
|
||||
|
||||
@@ -150,6 +150,8 @@ public class DialogCustomFormat extends JDialog {
|
||||
return;
|
||||
}
|
||||
|
||||
// Fix a problem with not updating changes
|
||||
customFormat.emptyAllowedSets();
|
||||
|
||||
for (int i = 0; i < choices.length; i++) {
|
||||
if (choices[i] != null) {
|
||||
|
||||
@@ -81,6 +81,10 @@ public enum VSubmenuQuestData implements IVSubmenu<CSubmenuQuestData> {
|
||||
|
||||
private final JRadioButton radPreconStart = new FRadioButton("Preconstructed Deck: ");
|
||||
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)
|
||||
.fontSize(16).hoverable(true).text("Embark!").build();
|
||||
@@ -152,6 +156,9 @@ public enum VSubmenuQuestData implements IVSubmenu<CSubmenuQuestData> {
|
||||
radUnrestricted.setSelected(true);
|
||||
cbxPrecon.setEnabled(false);
|
||||
radMedium.setEnabled(true);
|
||||
boxDeckUser.setEnabled(false);
|
||||
btnDeckImport.setEnabled(false);
|
||||
boxDeckFormat.setEnabled(false);
|
||||
|
||||
// Fantasy box enabled by Default
|
||||
boxFantasy.setSelected(true);
|
||||
@@ -176,7 +183,10 @@ public enum VSubmenuQuestData implements IVSubmenu<CSubmenuQuestData> {
|
||||
pnlOptions.add(boxFormatPersist, constraints);
|
||||
|
||||
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(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 {@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} */
|
||||
public JComboBox getCbxFormat() {
|
||||
return this.cbxFormat;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
package forge.quest;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -213,11 +214,15 @@ public class QuestController {
|
||||
* @param userFormat user-defined format, if any
|
||||
* @param persist
|
||||
* 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,
|
||||
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));
|
||||
} else {
|
||||
this.load(new QuestData(name, diff, mode, null, null));
|
||||
@@ -225,6 +230,12 @@ public class QuestController {
|
||||
|
||||
final Predicate<CardPrinted> filter;
|
||||
switch (startPool) {
|
||||
case UserDeck:
|
||||
if (userDeck == null) {
|
||||
throw new RuntimeException("User deck is null!");
|
||||
}
|
||||
this.myCards.addDeck(Deck.fromFile(userDeck));
|
||||
return;
|
||||
case Precon:
|
||||
this.myCards.addPreconDeck(QuestController.getPrecons().get(preconName));
|
||||
return;
|
||||
|
||||
@@ -3,5 +3,6 @@ package forge.quest;
|
||||
public enum QuestStartPool {
|
||||
Complete,
|
||||
Rotating,
|
||||
Precon
|
||||
Precon,
|
||||
UserDeck
|
||||
}
|
||||
|
||||
@@ -246,6 +246,15 @@ public final class QuestUtilCards {
|
||||
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.
|
||||
*
|
||||
|
||||
@@ -129,6 +129,17 @@ public final class GameFormatQuest {
|
||||
this.filterPrinted = this.buildFilterPrinted();
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty the whole list.
|
||||
*/
|
||||
public void emptyAllowedSets() {
|
||||
if (allowedSetCodes != null) {
|
||||
while (!allowedSetCodes.isEmpty()) {
|
||||
allowedSetCodes.remove(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param setCode
|
||||
* the set code to add
|
||||
|
||||
Reference in New Issue
Block a user