Quest start UI done

This commit is contained in:
Maxmtg
2012-11-13 20:41:14 +00:00
parent b36d711d75
commit bee6a0a3b8
5 changed files with 123 additions and 32 deletions

View File

@@ -6,6 +6,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.swing.JOptionPane;
import forge.Command;
@@ -13,6 +14,7 @@ import forge.deck.Deck;
import forge.Singletons;
import forge.game.GameFormat;
import forge.gui.framework.ICDoc;
import forge.item.CardPrinted;
import forge.properties.ForgeProps;
import forge.properties.NewConstants;
import forge.quest.QuestController;
@@ -39,6 +41,7 @@ public enum CSubmenuQuestData implements ICDoc {
private final VSubmenuQuestData view = VSubmenuQuestData.SINGLETON_INSTANCE;
private final List<String> customFormatCodes = new ArrayList<String>();
private final List<String> customPrizeFormatCodes = new ArrayList<String>();
private final Command cmdQuestSelect = new Command() { @Override
public void execute() { changeQuest(); } };
@@ -57,6 +60,10 @@ public enum CSubmenuQuestData implements ICDoc {
view.getBtnCustomFormat().setCommand( new Command() { @Override public void execute() {
new DialogCustomFormat(customFormatCodes);
}});
view.getBtnPrizeCustomFormat().setCommand( new Command() { @Override public void execute() {
new DialogCustomFormat(customPrizeFormatCodes);
}});
}
/* (non-Javadoc)
@@ -173,7 +180,42 @@ public enum CSubmenuQuestData implements ICDoc {
break;
}
GameFormat fmtPrizes = fmtStartPool;
GameFormat fmtPrizes = null;
switch(view.getPrizedPoolType()) {
case Complete:
fmtPrizes = null;
break;
case CustomFormat:
if ( customPrizeFormatCodes.isEmpty() )
{
int answer = JOptionPane.showConfirmDialog(null, "You have defined custom format as containing no sets.\nThis will choose all editions without restriction as prized.\n\nContinue?");
if ( JOptionPane.YES_OPTION != answer )
return;
}
fmtPrizes = customPrizeFormatCodes.isEmpty() ? null : new GameFormat("Custom Prizes", customPrizeFormatCodes, null); // chosen sets and no banend cards
break;
case Rotating:
fmtPrizes = view.getPrizedRotatingFormat();
break;
default: // same as starting
fmtPrizes = fmtStartPool;
if ( null == fmtPrizes && dckStartPool != null) { // build it form deck
List<String> sets = new ArrayList<String>();
for(Entry<CardPrinted, Integer> c : dckStartPool.getMain()) {
String edition = c.getKey().getEdition();
if ( !sets.contains(edition) )
sets.add(edition);
}
for(Entry<CardPrinted, Integer> c : dckStartPool.getSideboard()) {
String edition = c.getKey().getEdition();
if ( !sets.contains(edition) )
sets.add(edition);
}
fmtPrizes = new GameFormat("From deck", sets, null);
}
break;
}
final Object o = JOptionPane.showInputDialog(null, "Poets will remember your quest as:", "Quest Name", JOptionPane.OK_CANCEL_OPTION);

View File

@@ -7,7 +7,6 @@ import java.util.HashMap;
import java.util.Map;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
@@ -96,11 +95,18 @@ public enum VSubmenuQuestData implements IVSubmenu<CSubmenuQuestData> {
private final JComboBox cbxCustomDeck = new JComboBox();
private final FLabel btnDefineCustomFormat = new FLabel.Builder().opaque(true).hoverable(true).text("Define custom format").build();
private final FLabel btnPrizeDefineCustomFormat = new FLabel.Builder().opaque(true).hoverable(true).text("Define custom format").build();
private final JLabel lblPrizedCards = new FLabel.Builder().text("Prized cards:").build();
private final JComboBox cbxPrizedCards = new JComboBox();
private final JCheckBox cboAllowUnlocks = new FCheckBox("Allow sets unlock");
private final JLabel lblPrizeFormat = new FLabel.Builder().text("Sanctioned format:").build();
private final JComboBox cbxPrizeFormat = new JComboBox();
private final JLabel lblPrizeUnrestricted = new FLabel.Builder().text("All cards will be avaliable to win.").build();
private final JLabel lblPrizeSameAsStarting = new FLabel.Builder().text("Only sets found in starting pool will be avaliable.").build();
private final JCheckBox cboAllowUnlocks = new FCheckBox("Allow unlock of not included editions");
private final FLabel btnEmbark = new FLabel.Builder().opaque(true)
.fontSize(16).hoverable(true).text("Embark!").build();
@@ -136,6 +142,21 @@ public enum VSubmenuQuestData implements IVSubmenu<CSubmenuQuestData> {
}
};
/* Listeners */
private final ActionListener alPrizesPool = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
StartingPoolType newVal = getPrizedPoolType();
lblPrizeUnrestricted.setVisible(newVal == StartingPoolType.Complete);
cboAllowUnlocks.setVisible(newVal != StartingPoolType.Complete);
lblPrizeFormat.setVisible(newVal == StartingPoolType.Rotating);
cbxPrizeFormat.setVisible(newVal == StartingPoolType.Rotating);
btnPrizeDefineCustomFormat.setVisible(newVal == StartingPoolType.CustomFormat);
lblPrizeSameAsStarting.setVisible(newVal == null);
}
};
/**
* Constructor.
*/
@@ -163,14 +184,21 @@ public enum VSubmenuQuestData implements IVSubmenu<CSubmenuQuestData> {
// initial adjustment
alStartingPool.actionPerformed(null);
alPrizesPool.actionPerformed(null);
cbxPrizedCards.addItem("Same format as staring pool");
cbxPrizedCards.addItem("More options to come (WIP)");
cbxPrizedCards.addItem("Same as starting pool");
cbxPrizedCards.addItem(StartingPoolType.Complete);
cbxPrizedCards.addItem(StartingPoolType.Rotating);
cbxPrizedCards.addItem(StartingPoolType.CustomFormat);
cbxPrizedCards.addActionListener(alPrizesPool);
for (GameFormat gf : Singletons.getModel().getFormats()) {
cbxFormat.addItem(gf);
cbxPrizeFormat.addItem(gf);
}
cboAllowUnlocks.setSelected(true);
final Map<String, String> preconDescriptions = new HashMap<String, String>();
IStorageView<PreconDeck> preconDecks = QuestController.getPrecons();
@@ -228,7 +256,7 @@ public enum VSubmenuQuestData implements IVSubmenu<CSubmenuQuestData> {
final String cboWidth = "pushx, ";
final String cboWidthStart = cboWidth + hidemode;
pnlRestrictions.setLayout(new MigLayout("insets 0, gap 0, wrap 2", "[120, al right][240, fill]", "[|]12[|]"));
pnlRestrictions.setLayout(new MigLayout("insets 0, gap 0, wrap 2", "[120, al right][240, fill]", "[|]12[|]6[]"));
pnlRestrictions.add(lblStartingPool, constraints + lblWidthStart);
pnlRestrictions.add(cbxStartingPool, constraints + cboWidthStart);
@@ -250,8 +278,15 @@ public enum VSubmenuQuestData implements IVSubmenu<CSubmenuQuestData> {
pnlRestrictions.add(lblPrizedCards, constraints + lblWidth);
pnlRestrictions.add(cbxPrizedCards, constraints + cboWidth);
pnlRestrictions.add(cboAllowUnlocks, constraints + "spanx 2, ax center");
cboAllowUnlocks.setOpaque(false);
pnlRestrictions.add(lblPrizeFormat, constraints + lblWidthStart);
pnlRestrictions.add(cbxPrizeFormat, constraints + cboWidthStart); // , skip 1
pnlRestrictions.add(btnPrizeDefineCustomFormat, constraints + hidemode + "spanx 2, w 240px");
pnlRestrictions.add(lblPrizeSameAsStarting, constraints + hidemode + "spanx 2" );
pnlRestrictions.add(lblPrizeUnrestricted, constraints + hidemode + "spanx 2" );
pnlRestrictions.add(cboAllowUnlocks, constraints + "spanx 2, ax right");
// cboAllowUnlocks.setOpaque(false);
pnlRestrictions.setOpaque(false);
pnlOptions.add(pnlRestrictions, "pushx, ay top");
@@ -389,6 +424,12 @@ public enum VSubmenuQuestData implements IVSubmenu<CSubmenuQuestData> {
return (StartingPoolType) cbxStartingPool.getSelectedItem();
}
public StartingPoolType getPrizedPoolType() {
Object v = cbxPrizedCards.getSelectedItem();
return v instanceof StartingPoolType ? (StartingPoolType) v : null;
}
public boolean isFantasy() {
return boxFantasy.isSelected();
}
@@ -397,12 +438,15 @@ public enum VSubmenuQuestData implements IVSubmenu<CSubmenuQuestData> {
return (GameFormat) cbxFormat.getSelectedItem();
}
/**
* TODO: Write javadoc for this method.
* @return
*/
public GameFormat getPrizedRotatingFormat() {
return (GameFormat) cbxPrizeFormat.getSelectedItem();
}
public FLabel getBtnCustomFormat() {
// TODO Auto-generated method stub
return btnDefineCustomFormat;
}
public FLabel getBtnPrizeCustomFormat() {
return btnPrizeDefineCustomFormat;
}
}

View File

@@ -221,7 +221,7 @@ public class QuestController {
final GameFormat formatPrizes, final boolean allowSetUnlocks,
final Deck startingCards, final GameFormat formatStartingPool) {
this.load(new QuestData(name, difficulty, mode, formatPrizes)); // pass awards and unlocks here
this.load(new QuestData(name, difficulty, mode, formatPrizes, allowSetUnlocks)); // pass awards and unlocks here
if ( null != startingCards )
this.myCards.addDeck(startingCards);
@@ -349,8 +349,8 @@ public class QuestController {
}
int toUnlock = this.questFormat.getExcludedSetCodes().size();
if (toUnlock > (wins + 50) / 50) {
toUnlock = (wins + 50) / 50;
if (toUnlock > 1 + wins / 50) {
toUnlock = 1 + wins / 50;
}
if (toUnlock > 8) {
toUnlock = 8;

View File

@@ -36,6 +36,8 @@ import forge.game.GameFormat;
*/
public final class GameFormatQuest extends GameFormat {
private boolean allowUnlocks = true;
/**
* Instantiates a new game format based on two lists.
*
@@ -50,14 +52,20 @@ public final class GameFormatQuest extends GameFormat {
super(newName, setsToAllow, cardsToBan);
}
public GameFormatQuest(final String newName, final List<String> setsToAllow, final List<String> cardsToBan, boolean allowSetUnlocks) {
super(newName, setsToAllow, cardsToBan);
allowUnlocks = allowSetUnlocks;
}
/**
* Instantiates a new game format based on an existing format.
*
* @param toCopy
* an existing format
* @param allowSetUnlocks
*/
public GameFormatQuest(final GameFormat toCopy) {
public GameFormatQuest(final GameFormat toCopy, boolean allowSetUnlocks) {
this(toCopy.getName(), toCopy.getAllowedSetCodes(), toCopy.getBannedCardNames());
allowUnlocks = allowSetUnlocks;
}
@@ -82,17 +90,6 @@ public final class GameFormatQuest extends GameFormat {
allowedSetCodes.clear();
}
/**
* @param setCode
* the set code to add
*/
public void addAllowedSet(final String setCode) {
if (!allowedSetCodes.contains(setCode)) {
allowedSetCodes.add(setCode);
}
}
/**
* Get the list of excluded sets.
*
@@ -137,6 +134,10 @@ public final class GameFormatQuest extends GameFormat {
return (this.isSetLegal("ICE") || this.isSetLegal("CSP"));
}
public boolean canUnlockSets() {
return allowUnlocks;
}
/**
* The Class Predicates.
*/

View File

@@ -57,6 +57,8 @@ public final class QuestData {
private final QuestAssets assets;
private final QuestAchievements achievements;
/**
* Instantiates a new quest data.
* @param mode2
@@ -69,15 +71,17 @@ public final class QuestData {
* String, persistent format for the quest (null if none).
* @param userFormat
* user-defined format, if any (null if none).
* @param allowSetUnlocks
*/
public QuestData(String name2, int diff, QuestMode mode2, GameFormat userFormat) {
public QuestData(String name2, int diff, QuestMode mode2, GameFormat userFormat, boolean allowSetUnlocks) {
this.name = name2;
if ( userFormat != null)
this.format = new GameFormatQuest(userFormat);
this.format = new GameFormatQuest(userFormat, allowSetUnlocks);
this.mode = mode2;
this.achievements = new QuestAchievements(diff);
this.assets = new QuestAssets(format);
}
/**