mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 18:58:00 +00:00
Support selecting deck for gauntlet without one specified
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package forge.deckchooser;
|
||||
|
||||
import forge.FThreads;
|
||||
import forge.UiCommand;
|
||||
import forge.deck.ColorDeckGenerator;
|
||||
import forge.deck.Deck;
|
||||
@@ -20,12 +21,14 @@ import forge.quest.QuestEvent;
|
||||
import forge.quest.QuestEventChallenge;
|
||||
import forge.quest.QuestUtil;
|
||||
import forge.toolbox.FLabel;
|
||||
import forge.toolbox.FOptionPane;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -45,6 +48,31 @@ public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
|
||||
private final ForgePreferences prefs = FModel.getPreferences();
|
||||
private FPref stateSetting = null;
|
||||
|
||||
//Show dialog to select a deck
|
||||
public static Deck promptForDeck(String title, DeckType defaultDeckType, boolean forAi) {
|
||||
FThreads.assertExecutedByEdt(true);
|
||||
final FDeckChooser chooser = new FDeckChooser(forAi);
|
||||
chooser.initialize(defaultDeckType);
|
||||
chooser.populate();
|
||||
Dimension parentSize = JOptionPane.getRootFrame().getSize();
|
||||
chooser.setMinimumSize(new Dimension((int)(parentSize.getWidth() / 2), (int)parentSize.getHeight() - 200));
|
||||
final FOptionPane optionPane = new FOptionPane(null, title, null, chooser, new String[] { "OK", "Cancel" }, 0);
|
||||
optionPane.setDefaultFocus(chooser);
|
||||
chooser.lstDecks.setItemActivateCommand(new UiCommand() {
|
||||
@Override
|
||||
public void run() {
|
||||
optionPane.setResult(0); //accept selected deck on double click or Enter
|
||||
}
|
||||
});
|
||||
optionPane.setVisible(true);
|
||||
int dialogResult = optionPane.getResult();
|
||||
optionPane.dispose();
|
||||
if (dialogResult == 0) {
|
||||
return chooser.getDeck();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public FDeckChooser(boolean forAi) {
|
||||
setOpaque(false);
|
||||
isAi = forAi;
|
||||
|
||||
@@ -3,6 +3,8 @@ package forge.screens.home.gauntlet;
|
||||
import forge.GuiBase;
|
||||
import forge.UiCommand;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckType;
|
||||
import forge.deckchooser.FDeckChooser;
|
||||
import forge.game.GameType;
|
||||
import forge.game.player.RegisteredPlayer;
|
||||
import forge.gauntlet.GauntletData;
|
||||
@@ -11,6 +13,7 @@ import forge.gui.SOverlayUtils;
|
||||
import forge.gui.framework.ICDoc;
|
||||
import forge.interfaces.IGuiBase;
|
||||
import forge.model.FModel;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
@@ -91,6 +94,18 @@ public enum CSubmenuGauntletLoad implements ICDoc {
|
||||
FModel.setGauntletData(
|
||||
GauntletIO.loadGauntlet(view.getGauntletLister().getSelectedGauntletFile()));
|
||||
|
||||
final GauntletData gd = FModel.getGauntletData();
|
||||
final Deck aiDeck = gd.getDecks().get(gd.getCompleted());
|
||||
Deck userDeck = gd.getUserDeck();
|
||||
if (userDeck == null) {
|
||||
//give user a chance to select a deck if none saved with gauntlet
|
||||
userDeck = FDeckChooser.promptForDeck("Select a deck to play for this gauntlet", DeckType.CUSTOM_DECK, false);
|
||||
if (userDeck == null) { return; } //prevent crash if user doesn't select a deck
|
||||
gd.setUserDeck(userDeck);
|
||||
GauntletIO.saveGauntlet(gd);
|
||||
updateData(); //show deck in row
|
||||
}
|
||||
|
||||
// Start game
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
@@ -100,14 +115,11 @@ public enum CSubmenuGauntletLoad implements ICDoc {
|
||||
}
|
||||
});
|
||||
|
||||
final GauntletData gd = FModel.getGauntletData();
|
||||
final Deck aiDeck = gd.getDecks().get(gd.getCompleted());
|
||||
|
||||
List<RegisteredPlayer> starter = new ArrayList<RegisteredPlayer>();
|
||||
IGuiBase fc = GuiBase.getInterface();
|
||||
starter.add(new RegisteredPlayer(gd.getUserDeck()).setPlayer(fc.getGuiPlayer()));
|
||||
starter.add(new RegisteredPlayer(userDeck).setPlayer(fc.getGuiPlayer()));
|
||||
starter.add(new RegisteredPlayer(aiDeck).setPlayer(fc.createAiPlayer()));
|
||||
|
||||
|
||||
fc.startMatch(GameType.Gauntlet, starter);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,10 @@ Release Notes
|
||||
- New Commander 2014 and KTK cards -
|
||||
We have added a branch to our SVN for the new cards that are currently being scripted. These cards are not yet available in this build of forge. Please be patient and they will soon become available.
|
||||
|
||||
- Improved Gauntlet Support -
|
||||
Add column to Load Gauntlet screen to display your deck for the gauntlet
|
||||
Fix so your deck is saved with a gauntlet when starting a quick gauntlet
|
||||
Instead of crashing, prompt user to select a deck if attempting to load a gauntlet that doesn't have one saved
|
||||
|
||||
---------
|
||||
New Cards
|
||||
|
||||
Reference in New Issue
Block a user