mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 02:38:02 +00:00
Flesh out draft screen some more
This commit is contained in:
@@ -25,7 +25,6 @@ public abstract class LaunchScreen extends FScreen {
|
||||
private static final float PADDING = IMAGE_HEIGHT * 0.025f;
|
||||
|
||||
protected final StartButton btnStart;
|
||||
private boolean creatingMatch;
|
||||
|
||||
public LaunchScreen(String headerCaption) {
|
||||
super(headerCaption);
|
||||
@@ -48,8 +47,15 @@ public abstract class LaunchScreen extends FScreen {
|
||||
}
|
||||
|
||||
private void startMatch() {
|
||||
if (creatingMatch) { return; }
|
||||
creatingMatch = true; //ensure user doesn't create multiple matches by tapping multiple times
|
||||
final LaunchParams launchParams = new LaunchParams();
|
||||
if (!buildLaunchParams(launchParams)) { return; }
|
||||
|
||||
if (launchParams.gameType == null) {
|
||||
throw new RuntimeException("Must set launchParams.gameType");
|
||||
}
|
||||
if (launchParams.players.isEmpty()) {
|
||||
throw new RuntimeException("Must add at least one player to launchParams.players");
|
||||
}
|
||||
|
||||
final MatchLoader loader = new MatchLoader();
|
||||
loader.show(); //show loading overlay then delay starting game so UI can respond
|
||||
@@ -59,19 +65,8 @@ public abstract class LaunchScreen extends FScreen {
|
||||
FThreads.invokeInEdtLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
LaunchParams launchParams = new LaunchParams();
|
||||
if (buildLaunchParams(launchParams)) {
|
||||
if (launchParams.gameType == null) {
|
||||
throw new RuntimeException("Must set launchParams.gameType");
|
||||
}
|
||||
if (launchParams.players.isEmpty()) {
|
||||
throw new RuntimeException("Must add at least one player to launchParams.players");
|
||||
}
|
||||
|
||||
FControl.startMatch(launchParams.gameType, launchParams.appliedVariants, launchParams.players);
|
||||
}
|
||||
loader.hide();
|
||||
creatingMatch = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
package forge.screens.draft;
|
||||
|
||||
import forge.GuiBase;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
import forge.screens.LaunchScreen;
|
||||
import forge.toolbox.FLabel;
|
||||
import forge.toolbox.FOptionPane;
|
||||
import forge.toolbox.FRadioButton;
|
||||
import forge.toolbox.FRadioButton.RadioButtonGroup;
|
||||
import forge.util.Utils;
|
||||
import forge.assets.FSkinFont;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckGroup;
|
||||
import forge.deck.DeckProxy;
|
||||
import forge.game.GameType;
|
||||
import forge.game.player.RegisteredPlayer;
|
||||
import forge.itemmanager.DeckManager;
|
||||
import forge.itemmanager.ItemManagerConfig;
|
||||
import forge.model.FModel;
|
||||
@@ -16,13 +23,19 @@ public class DraftScreen extends LaunchScreen {
|
||||
|
||||
private final FLabel btnNewDraft = add(new FLabel.ButtonBuilder().text("New Booster Draft Game").font(FSkinFont.get(16)).build());
|
||||
private final DeckManager lstDecks = add(new DeckManager(GameType.Draft));
|
||||
private final FRadioButton radSingle = add(new FRadioButton("Play one opponent"));
|
||||
private final FRadioButton radAll = add(new FRadioButton("Play all 7 opponents"));
|
||||
|
||||
public DraftScreen() {
|
||||
super("Booster Draft");
|
||||
|
||||
lstDecks.setPool(DeckProxy.getDraftDecks(FModel.getDecks().getDraft()));
|
||||
lstDecks.setup(ItemManagerConfig.DRAFT_DECKS);
|
||||
btnStart.setEnabled(!lstDecks.getPool().isEmpty());
|
||||
|
||||
RadioButtonGroup group = new RadioButtonGroup();
|
||||
radSingle.setGroup(group);
|
||||
radAll.setGroup(group);
|
||||
radSingle.setSelected(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -32,12 +45,49 @@ public class DraftScreen extends LaunchScreen {
|
||||
float w = width - 2 * PADDING;
|
||||
btnNewDraft.setBounds(x, y, w, btnNewDraft.getAutoSizeBounds().height * 1.2f);
|
||||
y += btnNewDraft.getHeight() + PADDING;
|
||||
lstDecks.setBounds(x, y, w, height - y - PADDING);
|
||||
float radioButtonWidth = (w - PADDING) / 2;
|
||||
float radioButtonHeight = radSingle.getAutoSizeBounds().height;
|
||||
lstDecks.setBounds(x, y, w, height - y - PADDING - radioButtonHeight);
|
||||
y += lstDecks.getHeight() + PADDING;
|
||||
radSingle.setBounds(x, y, radioButtonWidth, radioButtonHeight);
|
||||
radAll.setBounds(x + radioButtonWidth, y, radioButtonWidth, radioButtonHeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean buildLaunchParams(LaunchParams launchParams) {
|
||||
final DeckProxy humanDeck = lstDecks.getSelectedItem();
|
||||
if (humanDeck == null) {
|
||||
FOptionPane.showErrorDialog("You must select an existing deck or build a deck from a new booster draft game.", "No Deck");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (FModel.getPreferences().getPrefBoolean(FPref.ENFORCE_DECK_LEGALITY)) {
|
||||
String errorMessage = GameType.Draft.getDecksFormat().getDeckConformanceProblem(humanDeck.getDeck());
|
||||
if (errorMessage != null) {
|
||||
FOptionPane.showErrorDialog("Your deck " + errorMessage + " Please edit or choose a different deck.", "Invalid Deck");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
FModel.getGauntletMini().resetGauntletDraft();
|
||||
|
||||
if (radAll.isSelected()) {
|
||||
int rounds = FModel.getDecks().getDraft().get(humanDeck.getName()).getAiDecks().size();
|
||||
FModel.getGauntletMini().launch(rounds, humanDeck.getDeck(), GameType.Draft);
|
||||
return false;
|
||||
}
|
||||
|
||||
final int aiIndex = (int) Math.floor(Math.random() * 7);
|
||||
DeckGroup opponentDecks = FModel.getDecks().getDraft().get(humanDeck.getName());
|
||||
Deck aiDeck = opponentDecks.getAiDecks().get(aiIndex);
|
||||
if (aiDeck == null) {
|
||||
throw new IllegalStateException("Draft: Computer deck is null!");
|
||||
}
|
||||
|
||||
launchParams.gameType = GameType.Draft;
|
||||
return false; //TODO: Support launching match
|
||||
launchParams.players.add(new RegisteredPlayer(humanDeck.getDeck()).setPlayer(GuiBase.getInterface().getGuiPlayer()));
|
||||
launchParams.players.add(new RegisteredPlayer(aiDeck).setPlayer(GuiBase.getInterface().createAiPlayer()));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user