mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
- Allow Draft to play a specific drafted opponent instead of just a random one.
This commit is contained in:
@@ -5,8 +5,7 @@ import java.awt.event.ActionListener;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.swing.JButton;
|
import javax.swing.*;
|
||||||
import javax.swing.SwingUtilities;
|
|
||||||
|
|
||||||
import forge.GuiBase;
|
import forge.GuiBase;
|
||||||
import forge.Singletons;
|
import forge.Singletons;
|
||||||
@@ -44,6 +43,14 @@ public enum CSubmenuDraft implements ICDoc {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
VSubmenuDraft.SINGLETON_INSTANCE.getBtnStart().setEnabled(true);
|
VSubmenuDraft.SINGLETON_INSTANCE.getBtnStart().setEnabled(true);
|
||||||
|
fillOpponentComboBox();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private final ActionListener radioAction = new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(final ActionEvent e) {
|
||||||
|
fillOpponentComboBox();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -73,6 +80,10 @@ public enum CSubmenuDraft implements ICDoc {
|
|||||||
startGame(GameType.Draft);
|
startGame(GameType.Draft);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
view.getRadSingle().addActionListener(radioAction);
|
||||||
|
|
||||||
|
view.getRadAll().addActionListener(radioAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
@@ -88,6 +99,7 @@ public enum CSubmenuDraft implements ICDoc {
|
|||||||
|
|
||||||
if (!view.getLstDecks().getPool().isEmpty()) {
|
if (!view.getLstDecks().getPool().isEmpty()) {
|
||||||
btnStart.setEnabled(true);
|
btnStart.setEnabled(true);
|
||||||
|
fillOpponentComboBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
@@ -104,7 +116,6 @@ public enum CSubmenuDraft implements ICDoc {
|
|||||||
private void startGame(final GameType gameType) {
|
private void startGame(final GameType gameType) {
|
||||||
final boolean gauntlet = !VSubmenuDraft.SINGLETON_INSTANCE.isSingleSelected();
|
final boolean gauntlet = !VSubmenuDraft.SINGLETON_INSTANCE.isSingleSelected();
|
||||||
final DeckProxy humanDeck = VSubmenuDraft.SINGLETON_INSTANCE.getLstDecks().getSelectedItem();
|
final DeckProxy humanDeck = VSubmenuDraft.SINGLETON_INSTANCE.getLstDecks().getSelectedItem();
|
||||||
final int aiIndex = (int) Math.floor(Math.random() * 7);
|
|
||||||
|
|
||||||
if (humanDeck == null) {
|
if (humanDeck == null) {
|
||||||
FOptionPane.showErrorDialog("No deck selected for human.\n(You may need to build a new deck)", "No Deck");
|
FOptionPane.showErrorDialog("No deck selected for human.\n(You may need to build a new deck)", "No Deck");
|
||||||
@@ -120,10 +131,15 @@ public enum CSubmenuDraft implements ICDoc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FModel.getGauntletMini().resetGauntletDraft();
|
FModel.getGauntletMini().resetGauntletDraft();
|
||||||
|
String duelType = (String)VSubmenuDraft.SINGLETON_INSTANCE.getCbOpponent().getSelectedItem();
|
||||||
|
final DeckGroup opponentDecks = FModel.getDecks().getDraft().get(humanDeck.getName());
|
||||||
if (gauntlet) {
|
if (gauntlet) {
|
||||||
final int rounds = FModel.getDecks().getDraft().get(humanDeck.getName()).getAiDecks().size();
|
if ("Gauntlet".equals(duelType)) {
|
||||||
FModel.getGauntletMini().launch(rounds, humanDeck.getDeck(), gameType);
|
final int rounds = opponentDecks.getAiDecks().size();
|
||||||
|
FModel.getGauntletMini().launch(rounds, humanDeck.getDeck(), gameType);
|
||||||
|
} else if ("Tournament".equals(duelType)) {
|
||||||
|
// TODO Allow for tournament style draft, instead of always a gauntlet
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +151,8 @@ public enum CSubmenuDraft implements ICDoc {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
final DeckGroup opponentDecks = FModel.getDecks().getDraft().get(humanDeck.getName());
|
// Restore Zero Indexing
|
||||||
|
final int aiIndex = Integer.parseInt(duelType)-1;
|
||||||
final Deck aiDeck = opponentDecks.getAiDecks().get(aiIndex);
|
final Deck aiDeck = opponentDecks.getAiDecks().get(aiIndex);
|
||||||
if (aiDeck == null) {
|
if (aiDeck == null) {
|
||||||
throw new IllegalStateException("Draft: Computer deck is null!");
|
throw new IllegalStateException("Draft: Computer deck is null!");
|
||||||
@@ -176,4 +193,27 @@ public enum CSubmenuDraft implements ICDoc {
|
|||||||
CDeckEditorUI.SINGLETON_INSTANCE.setEditorController(draftController);
|
CDeckEditorUI.SINGLETON_INSTANCE.setEditorController(draftController);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void fillOpponentComboBox() {
|
||||||
|
final VSubmenuDraft view = VSubmenuDraft.SINGLETON_INSTANCE;
|
||||||
|
JComboBox<String> combo = view.getCbOpponent();
|
||||||
|
combo.removeAllItems();
|
||||||
|
|
||||||
|
final DeckProxy humanDeck = view.getLstDecks().getSelectedItem();
|
||||||
|
|
||||||
|
if (VSubmenuDraft.SINGLETON_INSTANCE.isSingleSelected()) {
|
||||||
|
// Single opponent
|
||||||
|
final DeckGroup opponentDecks = FModel.getDecks().getDraft().get(humanDeck.getName());
|
||||||
|
int indx = 0;
|
||||||
|
for (Deck d : opponentDecks.getAiDecks()) {
|
||||||
|
indx++;
|
||||||
|
// 1-7 instead of 0-6
|
||||||
|
combo.addItem(String.valueOf(indx));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Gauntlet/Tournament
|
||||||
|
combo.addItem("Gauntlet");
|
||||||
|
//combo.addItem("Tournament");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,9 @@ package forge.screens.home.sanctioned;
|
|||||||
|
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
|
|
||||||
import javax.swing.JButton;
|
import javax.swing.*;
|
||||||
import javax.swing.JLabel;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JRadioButton;
|
|
||||||
import javax.swing.SwingConstants;
|
|
||||||
|
|
||||||
|
import forge.toolbox.*;
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
import forge.game.GameType;
|
import forge.game.GameType;
|
||||||
import forge.gui.framework.DragCell;
|
import forge.gui.framework.DragCell;
|
||||||
@@ -22,10 +19,6 @@ import forge.screens.home.LblHeader;
|
|||||||
import forge.screens.home.StartButton;
|
import forge.screens.home.StartButton;
|
||||||
import forge.screens.home.VHomeUI;
|
import forge.screens.home.VHomeUI;
|
||||||
import forge.screens.home.VHomeUI.PnlDisplay;
|
import forge.screens.home.VHomeUI.PnlDisplay;
|
||||||
import forge.toolbox.FLabel;
|
|
||||||
import forge.toolbox.FRadioButton;
|
|
||||||
import forge.toolbox.FSkin;
|
|
||||||
import forge.toolbox.JXButtonPanel;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assembles Swing components of draft submenu singleton.
|
* Assembles Swing components of draft submenu singleton.
|
||||||
@@ -48,9 +41,11 @@ public enum VSubmenuDraft implements IVSubmenu<CSubmenuDraft> {
|
|||||||
|
|
||||||
private final DeckManager lstDecks = new DeckManager(GameType.Draft, CDeckEditorUI.SINGLETON_INSTANCE.getCDetailPicture());
|
private final DeckManager lstDecks = new DeckManager(GameType.Draft, CDeckEditorUI.SINGLETON_INSTANCE.getCDetailPicture());
|
||||||
|
|
||||||
private final JRadioButton radSingle = new FRadioButton("Play one opponent");
|
private final JRadioButton radSingle = new FRadioButton("Play an opponent");
|
||||||
private final JRadioButton radAll = new FRadioButton("Play all 7 opponents");
|
private final JRadioButton radAll = new FRadioButton("Play all 7 opponents");
|
||||||
|
|
||||||
|
private final JComboBox<String> cbOpponent = new JComboBox<String>();
|
||||||
|
|
||||||
private final JLabel lblInfo = new FLabel.Builder()
|
private final JLabel lblInfo = new FLabel.Builder()
|
||||||
.fontAlign(SwingConstants.LEFT).fontSize(16).fontStyle(Font.BOLD)
|
.fontAlign(SwingConstants.LEFT).fontSize(16).fontStyle(Font.BOLD)
|
||||||
.text("Build or select a deck").build();
|
.text("Build or select a deck").build();
|
||||||
@@ -82,6 +77,7 @@ public enum VSubmenuDraft implements IVSubmenu<CSubmenuDraft> {
|
|||||||
grpPanel.add(radSingle, "w 200px!, h 30px!");
|
grpPanel.add(radSingle, "w 200px!, h 30px!");
|
||||||
grpPanel.add(radAll, "w 200px!, h 30px!");
|
grpPanel.add(radAll, "w 200px!, h 30px!");
|
||||||
radSingle.setSelected(true);
|
radSingle.setSelected(true);
|
||||||
|
grpPanel.add(cbOpponent, "w 200px!, h 30px!");
|
||||||
|
|
||||||
pnlStart.setLayout(new MigLayout("insets 0, gap 0, wrap 2"));
|
pnlStart.setLayout(new MigLayout("insets 0, gap 0, wrap 2"));
|
||||||
pnlStart.setOpaque(false);
|
pnlStart.setOpaque(false);
|
||||||
@@ -113,7 +109,6 @@ public enum VSubmenuDraft implements IVSubmenu<CSubmenuDraft> {
|
|||||||
return EDocID.HOME_DRAFT;
|
return EDocID.HOME_DRAFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return {@link forge.gui.toolbox.ExperimentalLabel} */
|
|
||||||
public FLabel getBtnBuildDeck() {
|
public FLabel getBtnBuildDeck() {
|
||||||
return this.btnBuildDeck;
|
return this.btnBuildDeck;
|
||||||
}
|
}
|
||||||
@@ -133,6 +128,10 @@ public enum VSubmenuDraft implements IVSubmenu<CSubmenuDraft> {
|
|||||||
return lstDecks;
|
return lstDecks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JComboBox<String> getCbOpponent() { return cbOpponent; }
|
||||||
|
public JRadioButton getRadSingle() { return radSingle; }
|
||||||
|
public JRadioButton getRadAll() { return radAll; }
|
||||||
|
|
||||||
//========== Overridden from IVDoc
|
//========== Overridden from IVDoc
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|||||||
Reference in New Issue
Block a user