checkstyle

This commit is contained in:
jendave
2011-10-26 18:13:13 +00:00
parent 6d2615eff6
commit d5872e3b47
7 changed files with 693 additions and 493 deletions

View File

@@ -1,30 +1,38 @@
package forge.quest.gui; package forge.quest.gui;
import javax.swing.*; import javax.swing.JPanel;
/** /**
* <p>Abstract QuestAbstractPanel class.</p> * <p>
* * Abstract QuestAbstractPanel class.
* </p>
*
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
*/ */
public abstract class QuestAbstractPanel extends JPanel { public abstract class QuestAbstractPanel extends JPanel {
/** Constant <code>serialVersionUID=-6378675010346615367L</code> */ /** Constant <code>serialVersionUID=-6378675010346615367L</code>. */
private static final long serialVersionUID = -6378675010346615367L; private static final long serialVersionUID = -6378675010346615367L;
/** The main frame. */
public QuestFrame mainFrame; public QuestFrame mainFrame;
/** /**
* <p>Constructor for QuestAbstractPanel.</p> * <p>
* * Constructor for QuestAbstractPanel.
* @param mainFrame a {@link forge.quest.gui.QuestFrame} object. * </p>
*
* @param mainFrame
* a {@link forge.quest.gui.QuestFrame} object.
*/ */
protected QuestAbstractPanel(QuestFrame mainFrame) { protected QuestAbstractPanel(final QuestFrame mainFrame) {
this.mainFrame = mainFrame; this.mainFrame = mainFrame;
} }
/** /**
* <p>refreshState.</p> * <p>
* refreshState.
* </p>
*/ */
public abstract void refreshState(); public abstract void refreshState();
} }

View File

@@ -1,45 +1,60 @@
package forge.quest.gui; package forge.quest.gui;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Dimension;
import java.awt.HeadlessException;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import forge.AllZone; import forge.AllZone;
import forge.gui.GuiUtils; import forge.gui.GuiUtils;
import forge.quest.gui.bazaar.QuestBazaarPanel; import forge.quest.gui.bazaar.QuestBazaarPanel;
import forge.view.swing.Gui_HomeScreen; import forge.view.swing.Gui_HomeScreen;
import forge.view.swing.OldGuiNewGame; import forge.view.swing.OldGuiNewGame;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.util.HashMap;
import java.util.Map;
/** /**
* <p>QuestFrame class.</p> * <p>
* * QuestFrame class.
* </p>
*
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
*/ */
public class QuestFrame extends JFrame { public class QuestFrame extends JFrame {
/** Constant <code>serialVersionUID=-2832625381531838412L</code> */ /** Constant <code>serialVersionUID=-2832625381531838412L</code>. */
private static final long serialVersionUID = -2832625381531838412L; private static final long serialVersionUID = -2832625381531838412L;
/** The visible panel. */
JPanel visiblePanel; JPanel visiblePanel;
/** The quest layout. */
CardLayout questLayout; CardLayout questLayout;
/** Constant <code>MAIN_PANEL="Main"</code> */ /** Constant <code>MAIN_PANEL="Main"</code>. */
public static final String MAIN_PANEL = "Main"; public static final String MAIN_PANEL = "Main";
/** Constant <code>BAZAAR_PANEL="Bazaar"</code> */
/** Constant <code>BAZAAR_PANEL="Bazaar"</code>. */
public static final String BAZAAR_PANEL = "Bazaar"; public static final String BAZAAR_PANEL = "Bazaar";
/** The sub panel map. */
Map<String, QuestAbstractPanel> subPanelMap = new HashMap<String, QuestAbstractPanel>(); Map<String, QuestAbstractPanel> subPanelMap = new HashMap<String, QuestAbstractPanel>();
/** /**
* <p>Constructor for QuestFrame.</p> * <p>
* * Constructor for QuestFrame.
* @throws java.awt.HeadlessException if any. * </p>
*
* @throws HeadlessException
* the headless exception
*/ */
public QuestFrame() throws HeadlessException { public QuestFrame() throws HeadlessException {
this.setTitle("Quest Mode"); this.setTitle("Quest Mode");
visiblePanel = new JPanel(new BorderLayout()); visiblePanel = new JPanel(new BorderLayout());
visiblePanel.setBorder(new EmptyBorder(2, 2, 2, 2)); visiblePanel.setBorder(new EmptyBorder(2, 2, 2, 2));
questLayout = new CardLayout(); questLayout = new CardLayout();
@@ -68,41 +83,48 @@ public class QuestFrame extends JFrame {
} }
/** /**
* <p>showPane.</p> * <p>
* * showPane.
* @param paneName a {@link java.lang.String} object. * </p>
*
* @param paneName
* a {@link java.lang.String} object.
*/ */
private void showPane(String paneName) { private void showPane(final String paneName) {
subPanelMap.get(paneName).refreshState(); subPanelMap.get(paneName).refreshState();
questLayout.show(visiblePanel, paneName); questLayout.show(visiblePanel, paneName);
} }
/** /**
* <p>showMainPane.</p> * <p>
* showMainPane.
* </p>
*/ */
public void showMainPane() { public final void showMainPane() {
showPane(MAIN_PANEL); showPane(MAIN_PANEL);
} }
/** /**
* <p>showBazaarPane.</p> * <p>
* showBazaarPane.
* </p>
*/ */
public void showBazaarPane() { public final void showBazaarPane() {
showPane(BAZAAR_PANEL); showPane(BAZAAR_PANEL);
} }
/** /**
* <p>returnToMainMenu.</p> * <p>
* returnToMainMenu.
* </p>
*/ */
public void returnToMainMenu() { public final void returnToMainMenu() {
AllZone.getQuestData().saveData(); AllZone.getQuestData().saveData();
if (System.getenv("NG2") != null) { if (System.getenv("NG2") != null) {
if (System.getenv("NG2").equalsIgnoreCase("true")) { if (System.getenv("NG2").equalsIgnoreCase("true")) {
String argz[] = {}; String[] argz = {};
Gui_HomeScreen.main(argz); Gui_HomeScreen.main(argz);
} else { } else {
new OldGuiNewGame(); new OldGuiNewGame();

View File

@@ -1,109 +1,151 @@
package forge.quest.gui; package forge.quest.gui;
import java.awt.BorderLayout;
import forge.*; import java.awt.CardLayout;
import forge.deck.Deck; import java.awt.Component;
import forge.gui.GuiUtils; import java.awt.Dimension;
import forge.gui.deckeditor.DeckEditorShop; import java.awt.Font;
import forge.gui.deckeditor.DeckEditorQuest;
import forge.quest.data.QuestData;
import forge.quest.data.QuestUtil;
import forge.quest.data.item.QuestItemZeppelin;
import forge.quest.gui.main.QuestDuel;
import forge.quest.gui.main.QuestDuelPanel;
import forge.quest.gui.main.QuestChallenge;
import forge.quest.gui.main.QuestChallengePanel;
import forge.quest.gui.main.QuestEventManager;
import forge.quest.gui.main.QuestSelectablePanel;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.util.*; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Set;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import forge.AllZone;
import forge.Command;
import forge.Constant;
import forge.GuiDisplay4;
import forge.ImageCache;
import forge.deck.Deck;
import forge.gui.GuiUtils;
import forge.gui.deckeditor.DeckEditorQuest;
import forge.gui.deckeditor.DeckEditorShop;
import forge.quest.data.QuestData;
import forge.quest.data.QuestUtil;
import forge.quest.data.item.QuestItemZeppelin;
import forge.quest.gui.main.QuestChallenge;
import forge.quest.gui.main.QuestChallengePanel;
import forge.quest.gui.main.QuestDuel;
import forge.quest.gui.main.QuestDuelPanel;
import forge.quest.gui.main.QuestEventManager;
import forge.quest.gui.main.QuestSelectablePanel;
/** /**
* <p>QuestMainPanel class.</p> * <p>
* QuestMainPanel class.
* </p>
* VIEW - lays out swing components for duel and challenge events. * VIEW - lays out swing components for duel and challenge events.
* *
* @author Forge * @author Forge
* @version $Id: QuestMainPanel.java 10358 2011-09-11 05:20:13Z Doublestrike $ * @version $Id: QuestMainPanel.java 10358 2011-09-11 05:20:13Z Doublestrike $
*/ */
public class QuestMainPanel extends QuestAbstractPanel { public class QuestMainPanel extends QuestAbstractPanel {
/** Constant <code>serialVersionUID=6142934729724012402L</code> */ /** Constant <code>serialVersionUID=6142934729724012402L</code>. */
private static final long serialVersionUID = 6142934729724012402L; private static final long serialVersionUID = 6142934729724012402L;
private forge.quest.data.QuestData questData; private forge.quest.data.QuestData questData;
private forge.quest.gui.main.QuestEventManager qem; private forge.quest.gui.main.QuestEventManager qem;
/** The credits label. */
JLabel creditsLabel = new JLabel(); JLabel creditsLabel = new JLabel();
/** The life label. */
JLabel lifeLabel = new JLabel(); JLabel lifeLabel = new JLabel();
/** The stats label. */
JLabel statsLabel = new JLabel(); JLabel statsLabel = new JLabel();
/** The title label. */
JLabel titleLabel = new JLabel(); JLabel titleLabel = new JLabel();
/** The next quest label. */
JLabel nextQuestLabel = new JLabel(); JLabel nextQuestLabel = new JLabel();
/** The pet combo box. */
JComboBox petComboBox = new JComboBox(); JComboBox petComboBox = new JComboBox();
/** The deck combo box. */
JComboBox deckComboBox = new JComboBox(); JComboBox deckComboBox = new JComboBox();
/** The event button. */
JButton eventButton = new JButton("Challenges"); JButton eventButton = new JButton("Challenges");
/** The play button. */
JButton playButton = new JButton("Play"); JButton playButton = new JButton("Play");
private QuestSelectablePanel selectedOpponent; private QuestSelectablePanel selectedOpponent;
/** The next match panel. */
JPanel nextMatchPanel = new JPanel(); JPanel nextMatchPanel = new JPanel();
/** The next match layout. */
CardLayout nextMatchLayout; CardLayout nextMatchLayout;
/** The is showing challenges. */
boolean isShowingChallenges = false; boolean isShowingChallenges = false;
private JCheckBox devModeCheckBox = new JCheckBox("Developer Mode"); private JCheckBox devModeCheckBox = new JCheckBox("Developer Mode");
//private JCheckBox newGUICheckbox = new JCheckBox("Use new UI", true); // private JCheckBox newGUICheckbox = new JCheckBox("Use new UI", true);
private JCheckBox smoothLandCheckBox = new JCheckBox("Adjust AI Land"); private JCheckBox smoothLandCheckBox = new JCheckBox("Adjust AI Land");
private JCheckBox petCheckBox = new JCheckBox("Summon Pet"); private JCheckBox petCheckBox = new JCheckBox("Summon Pet");
private JCheckBox plantBox = new JCheckBox("Summon Plant"); private JCheckBox plantBox = new JCheckBox("Summon Plant");
/** Constant <code>NO_DECKS_AVAILABLE="No decks available"</code> */ /** Constant <code>NO_DECKS_AVAILABLE="No decks available"</code>. */
private static final String NO_DECKS_AVAILABLE = "No decks available"; private static final String NO_DECKS_AVAILABLE = "No decks available";
/** Constant <code>DUELS="Duels"</code> */ /** Constant <code>DUELS="Duels"</code>. */
private static final String DUELS = "Duels"; private static final String DUELS = "Duels";
/** Constant <code>CHALLENGES="Challenges"</code> */ /** Constant <code>CHALLENGES="Challenges"</code>. */
private static final String CHALLENGES = "Challenges"; private static final String CHALLENGES = "Challenges";
//TODO: Make this ordering permanent // TODO: Make this ordering permanent
/** Constant <code>lastUsedDeck="//TODO: Make this ordering permanent"</code> */ /** Constant <code>lastUsedDeck="//TODO: Make this ordering permanent"</code>. */
private static String lastUsedDeck; private static String lastUsedDeck;
private JButton zeppelinButton = new JButton("<html>Launch<br>Zeppelin</html>", private JButton zeppelinButton = new JButton("<html>Launch<br>Zeppelin</html>", GuiUtils.getResizedIcon(
GuiUtils.getResizedIcon(GuiUtils.getIconFromFile("ZeppelinIcon.png"), 40, 40)); GuiUtils.getIconFromFile("ZeppelinIcon.png"), 40, 40));
private JPanel zeppelinPanel = new JPanel(); private JPanel zeppelinPanel = new JPanel();
/** /**
* <p>Constructor for QuestMainPanel.</p> * <p>
* * Constructor for QuestMainPanel.
* @param mainFrame a {@link forge.quest.gui.QuestFrame} object. * </p>
*
* @param mainFrame
* a {@link forge.quest.gui.QuestFrame} object.
*/ */
public QuestMainPanel(QuestFrame mainFrame) { public QuestMainPanel(final QuestFrame mainFrame) {
super(mainFrame); super(mainFrame);
questData = AllZone.getQuestData(); questData = AllZone.getQuestData();
qem = AllZone.getQuestEventManager(); qem = AllZone.getQuestEventManager();
// QuestEventManager is the MODEL for this VIEW. // QuestEventManager is the MODEL for this VIEW.
// All quest events are generated here, the first time the VIEW is made. // All quest events are generated here, the first time the VIEW is made.
if(qem==null) { if (qem == null) {
qem = new QuestEventManager(); qem = new QuestEventManager();
qem.assembleAllEvents(); qem.assembleAllEvents();
AllZone.setQuestEventManager(qem); AllZone.setQuestEventManager(qem);
} }
initUI(); initUI();
} }
/** /**
* <p>initUI.</p> * <p>
* initUI.
* </p>
*/ */
private void initUI() { private void initUI() {
refresh(); refresh();
@@ -126,14 +168,16 @@ public class QuestMainPanel extends QuestAbstractPanel {
} }
/** /**
* <p>createStatusPanel.</p> * <p>
* * createStatusPanel.
* </p>
*
* @return a {@link javax.swing.JPanel} object. * @return a {@link javax.swing.JPanel} object.
*/ */
private JPanel createStatusPanel() { private JPanel createStatusPanel() {
JPanel northPanel = new JPanel(); JPanel northPanel = new JPanel();
JLabel modeLabel; JLabel modeLabel;
JLabel difficultyLabel;//Create labels at the top JLabel difficultyLabel; // Create labels at the top
titleLabel.setFont(new Font(Font.DIALOG, Font.PLAIN, 28)); titleLabel.setFont(new Font(Font.DIALOG, Font.PLAIN, 28));
titleLabel.setAlignmentX(LEFT_ALIGNMENT); titleLabel.setAlignmentX(LEFT_ALIGNMENT);
northPanel.setLayout(new BoxLayout(northPanel, BoxLayout.Y_AXIS)); northPanel.setLayout(new BoxLayout(northPanel, BoxLayout.Y_AXIS));
@@ -160,21 +204,23 @@ public class QuestMainPanel extends QuestAbstractPanel {
} }
/** /**
* <p>createSidePanel.</p> * <p>
* * createSidePanel.
* </p>
*
* @return a {@link javax.swing.JPanel} object. * @return a {@link javax.swing.JPanel} object.
*/ */
private JPanel createSidePanel() { private JPanel createSidePanel() {
JPanel panel = new JPanel(); JPanel panel = new JPanel();
JPanel optionsPanel; //Create options checkbox list JPanel optionsPanel; // Create options checkbox list
optionsPanel = createOptionsPanel(); optionsPanel = createOptionsPanel();
List<Component> eastComponents = new ArrayList<Component>(); List<Component> eastComponents = new ArrayList<Component>();
//Create buttons // Create buttons
JButton mainMenuButton = new JButton("Return to Main Menu"); JButton mainMenuButton = new JButton("Return to Main Menu");
mainMenuButton.addActionListener(new ActionListener() { mainMenuButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(final ActionEvent actionEvent) {
mainFrame.returnToMainMenu(); mainFrame.returnToMainMenu();
} }
}); });
@@ -182,7 +228,7 @@ public class QuestMainPanel extends QuestAbstractPanel {
JButton cardShopButton = new JButton("Card Shop"); JButton cardShopButton = new JButton("Card Shop");
cardShopButton.addActionListener(new ActionListener() { cardShopButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(final ActionEvent actionEvent) {
QuestMainPanel.this.showCardShop(); QuestMainPanel.this.showCardShop();
} }
}); });
@@ -194,7 +240,7 @@ public class QuestMainPanel extends QuestAbstractPanel {
bazaarButton = new JButton("Bazaar"); bazaarButton = new JButton("Bazaar");
bazaarButton.addActionListener(new ActionListener() { bazaarButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(final ActionEvent actionEvent) {
QuestMainPanel.this.showBazaar(); QuestMainPanel.this.showBazaar();
} }
}); });
@@ -202,9 +248,8 @@ public class QuestMainPanel extends QuestAbstractPanel {
bazaarButton.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 20)); bazaarButton.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 20));
} }
eventButton.addActionListener(new ActionListener() { eventButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(final ActionEvent actionEvent) {
QuestMainPanel.this.showChallenges(); QuestMainPanel.this.showChallenges();
} }
}); });
@@ -212,9 +257,8 @@ public class QuestMainPanel extends QuestAbstractPanel {
eventButton.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 18)); eventButton.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 18));
eventButton.setPreferredSize(new Dimension(0, 60)); eventButton.setPreferredSize(new Dimension(0, 60));
playButton.addActionListener(new ActionListener() { playButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(final ActionEvent actionEvent) {
QuestMainPanel.this.launchGame(); QuestMainPanel.this.launchGame();
} }
}); });
@@ -222,7 +266,6 @@ public class QuestMainPanel extends QuestAbstractPanel {
playButton.setFont(new Font(Font.DIALOG, Font.BOLD, 28)); playButton.setFont(new Font(Font.DIALOG, Font.BOLD, 28));
playButton.setPreferredSize(new Dimension(0, 100)); playButton.setPreferredSize(new Dimension(0, 100));
eastComponents.add(playButton); eastComponents.add(playButton);
eastComponents.add(optionsPanel); eastComponents.add(optionsPanel);
@@ -266,8 +309,10 @@ public class QuestMainPanel extends QuestAbstractPanel {
} }
/** /**
* <p>createOptionsPanel.</p> * <p>
* * createOptionsPanel.
* </p>
*
* @return a {@link javax.swing.JPanel} object. * @return a {@link javax.swing.JPanel} object.
*/ */
private JPanel createOptionsPanel() { private JPanel createOptionsPanel() {
@@ -275,7 +320,7 @@ public class QuestMainPanel extends QuestAbstractPanel {
optionsPanel = new JPanel(); optionsPanel = new JPanel();
optionsPanel.setLayout(new BoxLayout(optionsPanel, BoxLayout.Y_AXIS)); optionsPanel.setLayout(new BoxLayout(optionsPanel, BoxLayout.Y_AXIS));
//optionsPanel.add(this.newGUICheckbox); // optionsPanel.add(this.newGUICheckbox);
optionsPanel.add(Box.createVerticalStrut(5)); optionsPanel.add(Box.createVerticalStrut(5));
optionsPanel.add(this.smoothLandCheckBox); optionsPanel.add(this.smoothLandCheckBox);
optionsPanel.add(Box.createVerticalStrut(5)); optionsPanel.add(Box.createVerticalStrut(5));
@@ -285,8 +330,10 @@ public class QuestMainPanel extends QuestAbstractPanel {
} }
/** /**
* <p>createMatchSettingsPanel.</p> * <p>
* * createMatchSettingsPanel.
* </p>
*
* @return a {@link javax.swing.JPanel} object. * @return a {@link javax.swing.JPanel} object.
*/ */
private JPanel createMatchSettingsPanel() { private JPanel createMatchSettingsPanel() {
@@ -302,7 +349,7 @@ public class QuestMainPanel extends QuestAbstractPanel {
GuiUtils.addGap(deckPanel); GuiUtils.addGap(deckPanel);
this.deckComboBox.addActionListener(new ActionListener() { this.deckComboBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(final ActionEvent actionEvent) {
playButton.setEnabled(canGameBeLaunched()); playButton.setEnabled(canGameBeLaunched());
lastUsedDeck = (String) deckComboBox.getSelectedItem(); lastUsedDeck = (String) deckComboBox.getSelectedItem();
} }
@@ -313,7 +360,7 @@ public class QuestMainPanel extends QuestAbstractPanel {
JButton editDeckButton = new JButton("Deck Editor"); JButton editDeckButton = new JButton("Deck Editor");
editDeckButton.addActionListener(new ActionListener() { editDeckButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(final ActionEvent actionEvent) {
showDeckEditor(); showDeckEditor();
} }
}); });
@@ -322,7 +369,6 @@ public class QuestMainPanel extends QuestAbstractPanel {
deckPanel.setAlignmentX(LEFT_ALIGNMENT); deckPanel.setAlignmentX(LEFT_ALIGNMENT);
matchPanel.add(deckPanel); matchPanel.add(deckPanel);
GuiUtils.addGap(matchPanel); GuiUtils.addGap(matchPanel);
if (questData.getMode().equals(forge.quest.data.QuestData.FANTASY)) { if (questData.getMode().equals(forge.quest.data.QuestData.FANTASY)) {
@@ -333,7 +379,7 @@ public class QuestMainPanel extends QuestAbstractPanel {
petPanel.setLayout(new BoxLayout(petPanel, BoxLayout.X_AXIS)); petPanel.setLayout(new BoxLayout(petPanel, BoxLayout.X_AXIS));
this.petCheckBox.addActionListener(new ActionListener() { this.petCheckBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(final ActionEvent actionEvent) {
if (petCheckBox.isSelected()) { if (petCheckBox.isSelected()) {
questData.getPetManager().setSelectedPet((String) petComboBox.getSelectedItem()); questData.getPetManager().setSelectedPet((String) petComboBox.getSelectedItem());
} else { } else {
@@ -347,7 +393,7 @@ public class QuestMainPanel extends QuestAbstractPanel {
petPanel.add(this.petCheckBox); petPanel.add(this.petCheckBox);
GuiUtils.addGap(petPanel); GuiUtils.addGap(petPanel);
this.petComboBox.addActionListener(new ActionListener() { this.petComboBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(final ActionEvent actionEvent) {
if (petCheckBox.isSelected()) { if (petCheckBox.isSelected()) {
questData.getPetManager().setSelectedPet((String) petComboBox.getSelectedItem()); questData.getPetManager().setSelectedPet((String) petComboBox.getSelectedItem());
} else { } else {
@@ -355,13 +401,12 @@ public class QuestMainPanel extends QuestAbstractPanel {
} }
} }
}); });
this.petComboBox.setMaximumSize( this.petComboBox.setMaximumSize(new Dimension(Integer.MAX_VALUE, (int) this.petCheckBox.getPreferredSize()
new Dimension(Integer.MAX_VALUE, .getHeight()));
(int) this.petCheckBox.getPreferredSize().getHeight()));
petPanel.add(this.petComboBox); petPanel.add(this.petComboBox);
this.plantBox.addActionListener(new ActionListener() { this.plantBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(final ActionEvent actionEvent) {
questData.getPetManager().usePlant = plantBox.isSelected(); questData.getPetManager().usePlant = plantBox.isSelected();
} }
}); });
@@ -374,7 +419,7 @@ public class QuestMainPanel extends QuestAbstractPanel {
fantasyPanel.add(petPanel, BorderLayout.WEST); fantasyPanel.add(petPanel, BorderLayout.WEST);
zeppelinButton.addActionListener(new ActionListener() { zeppelinButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(final ActionEvent actionEvent) {
questData.randomizeOpponents(); questData.randomizeOpponents();
refreshNextMatchPanel(); refreshNextMatchPanel();
QuestItemZeppelin zeppelin = (QuestItemZeppelin) questData.getInventory().getItem("Zeppelin"); QuestItemZeppelin zeppelin = (QuestItemZeppelin) questData.getInventory().getItem("Zeppelin");
@@ -394,9 +439,12 @@ public class QuestMainPanel extends QuestAbstractPanel {
} }
/** /**
* <p>createDuelPanel.</p> * <p>
* Makes a parent panel, then selectable panel instances for all available duels. * createDuelPanel.
* * </p>
* Makes a parent panel, then selectable panel instances for all available
* duels.
*
* @return a {@link javax.swing.JPanel} object. * @return a {@link javax.swing.JPanel} object.
*/ */
private JPanel createDuelPanel() { private JPanel createDuelPanel() {
@@ -421,20 +469,23 @@ public class QuestMainPanel extends QuestAbstractPanel {
} }
/** /**
* <p>createChallengePanel.</p> * <p>
* Makes a parent panel, then selectable panel instances for all available challenges. * createChallengePanel.
* * </p>
* Makes a parent panel, then selectable panel instances for all available
* challenges.
*
* @return a {@link javax.swing.JPanel} object. * @return a {@link javax.swing.JPanel} object.
*/ */
private JPanel createChallengePanel() { private JPanel createChallengePanel() {
JPanel ChallengePanel = new JPanel(); JPanel ChallengePanel = new JPanel();
QuestSelectablePanel selpan; QuestSelectablePanel selpan;
ChallengePanel.setLayout(new BoxLayout(ChallengePanel, BoxLayout.Y_AXIS)); ChallengePanel.setLayout(new BoxLayout(ChallengePanel, BoxLayout.Y_AXIS));
ChallengePanel.setBorder(new TitledBorder(new EtchedBorder(), "Available Challenges")); ChallengePanel.setBorder(new TitledBorder(new EtchedBorder(), "Available Challenges"));
List<QuestChallenge> challenges = qem.generateChallenges(); List<QuestChallenge> challenges = qem.generateChallenges();
for (QuestChallenge qc : challenges) { for (QuestChallenge qc : challenges) {
selpan = new QuestChallengePanel(qc); selpan = new QuestChallengePanel(qc);
ChallengePanel.add(selpan); ChallengePanel.add(selpan);
@@ -443,14 +494,15 @@ public class QuestMainPanel extends QuestAbstractPanel {
GuiUtils.addGap(ChallengePanel, 3); GuiUtils.addGap(ChallengePanel, 3);
} }
return ChallengePanel; return ChallengePanel;
} }
/** /**
* <p>refresh.</p> * <p>
* refresh.
* </p>
*/ */
void refresh() { final void refresh() {
AllZone.getQuestData().saveData(); AllZone.getQuestData().saveData();
devModeCheckBox.setSelected(Constant.Runtime.DevMode[0]); devModeCheckBox.setSelected(Constant.Runtime.DevMode[0]);
@@ -460,7 +512,7 @@ public class QuestMainPanel extends QuestAbstractPanel {
statsLabel.setText(questData.getWin() + " wins / " + questData.getLost() + " losses"); statsLabel.setText(questData.getWin() + " wins / " + questData.getLost() + " losses");
titleLabel.setText(questData.getRank()); titleLabel.setText(questData.getRank());
//copy lastUsedDeck as removal triggers selection change. // copy lastUsedDeck as removal triggers selection change.
String lastUsedDeck = QuestMainPanel.lastUsedDeck; String lastUsedDeck = QuestMainPanel.lastUsedDeck;
deckComboBox.removeAllItems(); deckComboBox.removeAllItems();
@@ -470,7 +522,7 @@ public class QuestMainPanel extends QuestAbstractPanel {
List<String> deckNames = new ArrayList<String>(questData.getDeckNames()); List<String> deckNames = new ArrayList<String>(questData.getDeckNames());
Collections.sort(deckNames, new Comparator<String>() { Collections.sort(deckNames, new Comparator<String>() {
public int compare(String s, String s1) { public int compare(final String s, final String s1) {
return s.compareToIgnoreCase(s1); return s.compareToIgnoreCase(s1);
} }
}); });
@@ -520,7 +572,6 @@ public class QuestMainPanel extends QuestAbstractPanel {
petComboBox.setSelectedItem(questData.getPetManager().getSelectedPet().getName()); petComboBox.setSelectedItem(questData.getPetManager().getSelectedPet().getName());
} }
this.plantBox.setEnabled(questData.getPetManager().getPlant().getLevel() > 0); this.plantBox.setEnabled(questData.getPetManager().getPlant().getLevel() > 0);
this.plantBox.setSelected(questData.getPetManager().shouldPlantBeUsed()); this.plantBox.setSelected(questData.getPetManager().shouldPlantBeUsed());
@@ -537,7 +588,6 @@ public class QuestMainPanel extends QuestAbstractPanel {
zeppelinButton.setEnabled(false); zeppelinButton.setEnabled(false);
} }
} }
if (nextChallengeInWins() > 0) { if (nextChallengeInWins() > 0) {
@@ -552,7 +602,9 @@ public class QuestMainPanel extends QuestAbstractPanel {
} }
/** /**
* <p>refreshNextMatchPanel.</p> * <p>
* refreshNextMatchPanel.
* </p>
*/ */
private void refreshNextMatchPanel() { private void refreshNextMatchPanel() {
nextMatchPanel.removeAll(); nextMatchPanel.removeAll();
@@ -568,18 +620,22 @@ public class QuestMainPanel extends QuestAbstractPanel {
} }
/** /**
* <p>nextChallengeInWins.</p> * <p>
* * nextChallengeInWins.
* </p>
*
* @return a int. * @return a int.
*/ */
private int nextChallengeInWins() { private int nextChallengeInWins() {
// Number of wins was 25, lowereing the number to 20 to help short term questers. // Number of wins was 25, lowereing the number to 20 to help short term
// questers.
if (questData.getWin() < 20) { if (questData.getWin() < 20) {
return 20 - questData.getWin(); return 20 - questData.getWin();
} }
// The int mul has been lowered by one, should face special opps more frequently. // The int mul has been lowered by one, should face special opps more
// frequently.
int challengesPlayed = questData.getChallengesPlayed(); int challengesPlayed = questData.getChallengesPlayed();
int mul = 5; int mul = 5;
@@ -594,16 +650,17 @@ public class QuestMainPanel extends QuestAbstractPanel {
return (delta > 0) ? delta : 0; return (delta > 0) ? delta : 0;
} }
/** /**
* <p>showDeckEditor.</p> * <p>
* showDeckEditor.
* </p>
*/ */
void showDeckEditor() { final void showDeckEditor() {
Command exit = new Command() { Command exit = new Command() {
private static final long serialVersionUID = -5110231879431074581L; private static final long serialVersionUID = -5110231879431074581L;
public void execute() { public void execute() {
//saves all deck data // saves all deck data
AllZone.getQuestData().saveData(); AllZone.getQuestData().saveData();
new QuestFrame(); new QuestFrame();
@@ -615,24 +672,28 @@ public class QuestMainPanel extends QuestAbstractPanel {
g.show(exit); g.show(exit);
g.setVisible(true); g.setVisible(true);
mainFrame.dispose(); mainFrame.dispose();
}//deck editor button } // deck editor button
/** /**
* <p>showBazaar.</p> * <p>
* showBazaar.
* </p>
*/ */
void showBazaar() { final void showBazaar() {
mainFrame.showBazaarPane(); mainFrame.showBazaarPane();
} }
/** /**
* <p>showCardShop.</p> * <p>
* showCardShop.
* </p>
*/ */
void showCardShop() { final void showCardShop() {
Command exit = new Command() { Command exit = new Command() {
private static final long serialVersionUID = 8567193482568076362L; private static final long serialVersionUID = 8567193482568076362L;
public void execute() { public void execute() {
//saves all deck data // saves all deck data
AllZone.getQuestData().saveData(); AllZone.getQuestData().saveData();
new QuestFrame(); new QuestFrame();
@@ -646,13 +707,16 @@ public class QuestMainPanel extends QuestAbstractPanel {
this.mainFrame.dispose(); this.mainFrame.dispose();
}//card shop button } // card shop button
/** /**
* <p>launchGame.</p> * <p>
* launchGame.
* </p>
*/ */
private void launchGame() { private void launchGame() {
//TODO: This is a temporary hack to see if the image cache affects the heap usage significantly. // TODO This is a temporary hack to see if the image cache affects the
// heap usage significantly.
ImageCache.clear(); ImageCache.clear();
QuestItemZeppelin zeppelin = (QuestItemZeppelin) questData.getInventory().getItem("Zeppelin"); QuestItemZeppelin zeppelin = (QuestItemZeppelin) questData.getInventory().getItem("Zeppelin");
@@ -660,9 +724,9 @@ public class QuestMainPanel extends QuestAbstractPanel {
questData.randomizeOpponents(); questData.randomizeOpponents();
String humanDeckName = (String) deckComboBox.getSelectedItem(); String humanDeckName = (String) deckComboBox.getSelectedItem();
Deck humanDeck = questData.getDeck(humanDeckName); Deck humanDeck = questData.getDeck(humanDeckName);
Constant.Runtime.HumanDeck[0] = humanDeck; Constant.Runtime.HumanDeck[0] = humanDeck;
moveDeckToTop(humanDeckName); moveDeckToTop(humanDeckName);
@@ -671,16 +735,16 @@ public class QuestMainPanel extends QuestAbstractPanel {
// Dev Mode occurs before Display // Dev Mode occurs before Display
Constant.Runtime.DevMode[0] = devModeCheckBox.isSelected(); Constant.Runtime.DevMode[0] = devModeCheckBox.isSelected();
//DO NOT CHANGE THIS ORDER, GuiDisplay needs to be created before cards are added // DO NOT CHANGE THIS ORDER, GuiDisplay needs to be created before cards
//if (newGUICheckbox.isSelected()) { // are added
AllZone.setDisplay(new GuiDisplay4()); // if (newGUICheckbox.isSelected()) {
//} else { AllZone.setDisplay(new GuiDisplay4());
// AllZone.setDisplay(new GuiDisplay3()); // } else {
//} // AllZone.setDisplay(new GuiDisplay3());
// }
Constant.Runtime.Smooth[0] = smoothLandCheckBox.isSelected(); Constant.Runtime.Smooth[0] = smoothLandCheckBox.isSelected();
AllZone.getMatchState().reset(); AllZone.getMatchState().reset();
if (isShowingChallenges) { if (isShowingChallenges) {
setupChallenge(humanDeck); setupChallenge(humanDeck);
@@ -694,32 +758,35 @@ public class QuestMainPanel extends QuestAbstractPanel {
mainFrame.dispose(); mainFrame.dispose();
} }
/** /**
* <p>setupDuel.</p> * <p>
* * setupDuel.
* @param humanDeck a {@link forge.deck.Deck} object. * </p>
*
* @param humanDeck
* a {@link forge.deck.Deck} object.
*/ */
void setupDuel(Deck humanDeck) { final void setupDuel(final Deck humanDeck) {
Deck computer = selectedOpponent.getEvent().getEventDeck(); Deck computer = selectedOpponent.getEvent().getEventDeck();
Constant.Runtime.ComputerDeck[0] = computer; Constant.Runtime.ComputerDeck[0] = computer;
QuestDuel selectedDuel = (QuestDuel)selectedOpponent.getEvent(); QuestDuel selectedDuel = (QuestDuel) selectedOpponent.getEvent();
AllZone.setQuestEvent(selectedDuel); AllZone.setQuestEvent(selectedDuel);
AllZone.getGameAction().newGame(humanDeck, computer, AllZone.getGameAction().newGame(humanDeck, computer, QuestUtil.getHumanStartingCards(questData),
QuestUtil.getHumanStartingCards(questData), QuestUtil.getComputerStartingCards(questData), questData.getLife(), 20, null);
QuestUtil.getComputerStartingCards(questData),
questData.getLife(), 20, null);
} }
/** /**
* <p>setupChallenge.</p> * <p>
* * setupChallenge.
* @param humanDeck a {@link forge.deck.Deck} object. * </p>
*
* @param humanDeck
* a {@link forge.deck.Deck} object.
*/ */
private void setupChallenge(Deck humanDeck) { private void setupChallenge(final Deck humanDeck) {
QuestChallenge selectedChallenge = (QuestChallenge)selectedOpponent.getEvent(); QuestChallenge selectedChallenge = (QuestChallenge) selectedOpponent.getEvent();
Deck computer = selectedOpponent.getEvent().getEventDeck(); Deck computer = selectedOpponent.getEvent().getEventDeck();
Constant.Runtime.ComputerDeck[0] = computer; Constant.Runtime.ComputerDeck[0] = computer;
@@ -733,15 +800,17 @@ public class QuestMainPanel extends QuestAbstractPanel {
} }
AllZone.getGameAction().newGame(humanDeck, computer, AllZone.getGameAction().newGame(humanDeck, computer,
QuestUtil.getHumanStartingCards(questData, selectedChallenge), QuestUtil.getHumanStartingCards(questData, selectedChallenge),
QuestUtil.getComputerStartingCards(questData, selectedChallenge), QuestUtil.getComputerStartingCards(questData, selectedChallenge), questData.getLife() + extraLife,
questData.getLife() + extraLife, selectedChallenge.getAILife(), selectedChallenge); selectedChallenge.getAILife(), selectedChallenge);
} }
/** /**
* <p>getEventIconFilename.</p> * <p>
* * getEventIconFilename.
* </p>
*
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
private String getEventIconFilename() { private String getEventIconFilename() {
@@ -749,9 +818,11 @@ public class QuestMainPanel extends QuestAbstractPanel {
} }
/** /**
* <p>showChallenges.</p> * <p>
* showChallenges.
* </p>
*/ */
void showChallenges() { final void showChallenges() {
if (isShowingChallenges) { if (isShowingChallenges) {
isShowingChallenges = false; isShowingChallenges = false;
eventButton.setText("Challenges"); eventButton.setText("Challenges");
@@ -769,16 +840,33 @@ public class QuestMainPanel extends QuestAbstractPanel {
refresh(); refresh();
} }
/**
* The Class SelectionAdapter.
*/
class SelectionAdapter extends MouseAdapter { class SelectionAdapter extends MouseAdapter {
/** The selectable panel. */
QuestSelectablePanel selectablePanel; QuestSelectablePanel selectablePanel;
SelectionAdapter(QuestSelectablePanel selectablePanel) { /**
* Instantiates a new selection adapter.
*
* @param selectablePanel
* the selectable panel
*/
SelectionAdapter(final QuestSelectablePanel selectablePanel) {
super(); super();
this.selectablePanel = selectablePanel; this.selectablePanel = selectablePanel;
} }
/*
* (non-Javadoc)
*
* @see
* java.awt.event.MouseAdapter#mouseClicked(java.awt.event.MouseEvent)
*/
@Override @Override
public void mouseClicked(MouseEvent mouseEvent) { public void mouseClicked(final MouseEvent mouseEvent) {
if (selectedOpponent != null) { if (selectedOpponent != null) {
selectedOpponent.setSelected(false); selectedOpponent.setSelected(false);
@@ -793,27 +881,31 @@ public class QuestMainPanel extends QuestAbstractPanel {
} }
/** /**
* <p>moveDeckToTop.</p> * <p>
* * moveDeckToTop.
* @param humanDeckName a {@link java.lang.String} object. * </p>
*
* @param humanDeckName
* a {@link java.lang.String} object.
*/ */
private void moveDeckToTop(String humanDeckName) { private void moveDeckToTop(final String humanDeckName) {
QuestMainPanel.lastUsedDeck = humanDeckName; QuestMainPanel.lastUsedDeck = humanDeckName;
} }
/** /**
* <p>canGameBeLaunched.</p> * <p>
* * canGameBeLaunched.
* </p>
*
* @return a boolean. * @return a boolean.
*/ */
boolean canGameBeLaunched() { final boolean canGameBeLaunched() {
return !(NO_DECKS_AVAILABLE.equals(deckComboBox.getSelectedItem()) || selectedOpponent == null); return !(NO_DECKS_AVAILABLE.equals(deckComboBox.getSelectedItem()) || selectedOpponent == null);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void refreshState() { public final void refreshState() {
this.refresh(); this.refresh();
} }

View File

@@ -1,5 +1,26 @@
package forge.quest.gui; package forge.quest.gui;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import forge.AllZone; import forge.AllZone;
import forge.error.ErrorViewer; import forge.error.ErrorViewer;
import forge.gui.GuiUtils; import forge.gui.GuiUtils;
@@ -9,22 +30,16 @@ import forge.quest.data.QuestPreferences;
import forge.view.swing.Gui_HomeScreen; import forge.view.swing.Gui_HomeScreen;
import forge.view.swing.OldGuiNewGame; import forge.view.swing.OldGuiNewGame;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
/** /**
* <p>Gui_QuestOptions class.</p> * <p>
* * Gui_QuestOptions class.
* </p>
*
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
*/ */
public class QuestOptions extends JFrame { public class QuestOptions extends JFrame {
/** Constant <code>serialVersionUID=2018518804206822235L</code> */ /** Constant <code>serialVersionUID=2018518804206822235L</code>. */
private static final long serialVersionUID = 2018518804206822235L; private static final long serialVersionUID = 2018518804206822235L;
private QuestData questData = new QuestData(); private QuestData questData = new QuestData();
@@ -52,7 +67,9 @@ public class QuestOptions extends JFrame {
private JPanel jPanel3 = new JPanel(); private JPanel jPanel3 = new JPanel();
/** /**
* <p>Constructor for Gui_QuestOptions.</p> * <p>
* Constructor for Gui_QuestOptions.
* </p>
*/ */
public QuestOptions() { public QuestOptions() {
try { try {
@@ -70,19 +87,20 @@ public class QuestOptions extends JFrame {
} }
/** /**
* <p>setup.</p> * <p>
* setup.
* </p>
*/ */
private void setup() { private void setup() {
//make the text look correct on the screen // make the text look correct on the screen
jTextArea1.setBackground(getBackground()); jTextArea1.setBackground(getBackground());
// if user closes this window, go back to "New Game" screen
//if user closes this window, go back to "New Game" screen
this.addWindowListener(new WindowAdapter() { this.addWindowListener(new WindowAdapter() {
@Override @Override
public void windowClosing(WindowEvent ev) { public void windowClosing(final WindowEvent ev) {
QuestOptions.this.dispose(); QuestOptions.this.dispose();
if (System.getenv("NG2") != null) { if (System.getenv("NG2") != null) {
if (System.getenv("NG2").equalsIgnoreCase("true")) { if (System.getenv("NG2").equalsIgnoreCase("true")) {
String argz[] = {}; String argz[] = {};
@@ -97,37 +115,43 @@ public class QuestOptions extends JFrame {
} }
}); });
//is there any saved data? // is there any saved data?
if (!questData.hasSaveFile()) continueQuestButton.setEnabled(false); if (!questData.hasSaveFile()) {
} //setup() continueQuestButton.setEnabled(false);
}
} // setup()
//show total number of games for each difficulty // show total number of games for each difficulty
/** /**
* <p>setupRadioButtonText.</p> * <p>
* setupRadioButtonText.
* </p>
*/ */
private void setupRadioButtonText() { private void setupRadioButtonText() {
String[] diff = QuestPreferences.getDifficulty(); String[] diff = QuestPreferences.getDifficulty();
JRadioButton[] b = {easyRadio, mediumRadio, hardRadio, veryHardRadio}; JRadioButton[] b = {easyRadio, mediumRadio, hardRadio, veryHardRadio};
for (int i = 0; i < diff.length; i++) { for (int i = 0; i < diff.length; i++) {
//-2 because you start a level 1, and the last level is secret // -2 because you start a level 1, and the last level is secret
int numberLevels = QuestData.RANK_TITLES.length - 2; int numberLevels = QuestData.RANK_TITLES.length - 2;
int numGames = numberLevels * QuestPreferences.getWinsForRankIncrease(i); int numGames = numberLevels * QuestPreferences.getWinsForRankIncrease(i);
b[i].setText(String.format("%s - %d", diff[i], numGames)); b[i].setText(String.format("%s - %d", diff[i], numGames));
} }
}//setupRadioButtonText() } // setupRadioButtonText()
/** /**
* <p>jbInit.</p> * <p>
* * jbInit.
* @throws java.lang.Exception if any. * </p>
*
* @throws java.lang.Exception
* if any.
*/ */
private void jbInit() throws Exception { private void jbInit() throws Exception {
TitledBorder titledBorder1 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white, TitledBorder titledBorder1 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white, new Color(148, 145,
new Color(148, 145, 140)), 140)), "Quest Length");
"Quest Length");
Border border2 = BorderFactory.createEtchedBorder(Color.white, new Color(148, 145, 140)); Border border2 = BorderFactory.createEtchedBorder(Color.white, new Color(148, 145, 140));
TitledBorder titledBorder2 = new TitledBorder(border2, "Continue"); TitledBorder titledBorder2 = new TitledBorder(border2, "Continue");
jLabel1.setFont(new java.awt.Font("Dialog", 0, 25)); jLabel1.setFont(new java.awt.Font("Dialog", 0, 25));
@@ -140,7 +164,7 @@ public class QuestOptions extends JFrame {
continueQuestButton.setFont(new java.awt.Font("Dialog", 0, 18)); continueQuestButton.setFont(new java.awt.Font("Dialog", 0, 18));
continueQuestButton.setText("Continue Quest"); continueQuestButton.setText("Continue Quest");
continueQuestButton.addActionListener(new java.awt.event.ActionListener() { continueQuestButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(final ActionEvent e) {
continueQuestButton_actionPerformed(e); continueQuestButton_actionPerformed(e);
} }
}); });
@@ -170,7 +194,7 @@ public class QuestOptions extends JFrame {
newQuestButton.setFont(new java.awt.Font("Dialog", 0, 16)); newQuestButton.setFont(new java.awt.Font("Dialog", 0, 16));
newQuestButton.setText("New Quest"); newQuestButton.setText("New Quest");
newQuestButton.addActionListener(new java.awt.event.ActionListener() { newQuestButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(final ActionEvent e) {
newQuestButton_actionPerformed(e); newQuestButton_actionPerformed(e);
} }
}); });
@@ -188,7 +212,7 @@ public class QuestOptions extends JFrame {
jTextArea1.setFont(new java.awt.Font("Dialog", 0, 12)); jTextArea1.setFont(new java.awt.Font("Dialog", 0, 12));
jTextArea1.setDisabledTextColor(Color.black); jTextArea1.setDisabledTextColor(Color.black);
jTextArea1.setEditable(false); jTextArea1.setEditable(false);
// jTextArea1.setText("Note: Starting a new quest will delete your current quest data"); // jTextArea1.setText("Note: Starting a new quest will delete your current quest data");
jTextArea1.setText(sb.toString()); jTextArea1.setText(sb.toString());
jTextArea1.setLineWrap(true); jTextArea1.setLineWrap(true);
jTextArea1.setWrapStyleWord(true); jTextArea1.setWrapStyleWord(true);
@@ -203,7 +227,7 @@ public class QuestOptions extends JFrame {
jPanel2.add(mediumRadio, null); jPanel2.add(mediumRadio, null);
jPanel2.add(fantasyRadio, null); jPanel2.add(fantasyRadio, null);
jPanel2.add(hardRadio, null); jPanel2.add(hardRadio, null);
jPanel2.add(new JLabel("")); // for empty cell jPanel2.add(new JLabel("")); // for empty cell
jPanel2.add(veryHardRadio, null); jPanel2.add(veryHardRadio, null);
jPanel2.add(cbStandardStart, null); jPanel2.add(cbStandardStart, null);
@@ -225,12 +249,15 @@ public class QuestOptions extends JFrame {
} }
/** /**
* <p>continueQuestButton_actionPerformed.</p> * <p>
* * continueQuestButton_actionPerformed.
* @param e a {@link java.awt.event.ActionEvent} object. * </p>
*
* @param e
* a {@link java.awt.event.ActionEvent} object.
*/ */
void continueQuestButton_actionPerformed(ActionEvent e) { final void continueQuestButton_actionPerformed(final ActionEvent e) {
//set global variable // set global variable
AllZone.setQuestData(QuestDataIO.loadData()); AllZone.setQuestData(QuestDataIO.loadData());
AllZone.getQuestData().guessDifficultyIndex(); AllZone.getQuestData().guessDifficultyIndex();
dispose(); dispose();
@@ -240,49 +267,54 @@ public class QuestOptions extends JFrame {
} }
/** /**
* <p>newQuestButton_actionPerformed.</p> * <p>
* * newQuestButton_actionPerformed.
* @param e a {@link java.awt.event.ActionEvent} object. * </p>
*
* @param e
* a {@link java.awt.event.ActionEvent} object.
*/ */
void newQuestButton_actionPerformed(ActionEvent e) { final void newQuestButton_actionPerformed(final ActionEvent e) {
int difficulty = 0; int difficulty = 0;
String mode = fantasyRadio.isSelected() ? forge.quest.data.QuestData.FANTASY : forge.quest.data.QuestData.REALISTIC; String mode = fantasyRadio.isSelected() ? forge.quest.data.QuestData.FANTASY
: forge.quest.data.QuestData.REALISTIC;
if (easyRadio.isSelected()) difficulty = 0; if (easyRadio.isSelected()) {
difficulty = 0;
else if (mediumRadio.isSelected()) difficulty = 1; } else if (mediumRadio.isSelected()) {
difficulty = 1;
else if (hardRadio.isSelected()) difficulty = 2; } else if (hardRadio.isSelected()) {
difficulty = 2;
else if (veryHardRadio.isSelected()) difficulty = 3; } else if (veryHardRadio.isSelected()) {
difficulty = 3;
else //user didn't select a difficulty{ } else {
// user didn't select a difficulty{
return; return;
}
if (questData.hasSaveFile()) { if (questData.hasSaveFile()) {
// this will overwrite your save file! // this will overwrite your save file!
Object[] possibleValues = {"Yes", "No"}; Object[] possibleValues = {"Yes", "No"};
Object choice = JOptionPane.showOptionDialog(null, "Starting a new quest will overwrite your current quest. Continue?", Object choice = JOptionPane.showOptionDialog(null,
"Start New Quest?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, "Starting a new quest will overwrite your current quest. Continue?", "Start New Quest?",
null, possibleValues, possibleValues[1]); JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, possibleValues, possibleValues[1]);
if (!choice.equals(0)) if (!choice.equals(0)) {
return; return;
}
} }
//give the user a few cards to build a deck // give the user a few cards to build a deck
questData.newGame(difficulty, mode, cbStandardStart.isSelected()); questData.newGame(difficulty, mode, cbStandardStart.isSelected());
questData.saveData(); questData.saveData();
// set global variable
//set global variable
AllZone.setQuestData(questData); AllZone.setQuestData(questData);
dispose(); dispose();
new QuestFrame(); new QuestFrame();
} }
} }

View File

@@ -1,7 +1,13 @@
package forge.quest.gui; package forge.quest.gui;
import static java.util.Collections.unmodifiableList;
import javax.swing.*; import java.util.List;
import javax.swing.AbstractListModel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener; import javax.swing.event.ListSelectionListener;
@@ -12,28 +18,30 @@ import forge.gui.game.CardDetailPanel;
import forge.gui.game.CardPicturePanel; import forge.gui.game.CardPicturePanel;
import forge.item.CardPrinted; import forge.item.CardPrinted;
import java.util.List;
import static java.util.Collections.unmodifiableList;
/** /**
* A simple JPanel that shows three columns: card list, pic, and description.. * A simple JPanel that shows three columns: card list, pic, and description..
* *
* @author Forge * @author Forge
* @version $Id: ListChooser.java 9708 2011-08-09 19:34:12Z jendave $ * @version $Id: ListChooser.java 9708 2011-08-09 19:34:12Z jendave $
*/ */
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class QuestWinLoseCardViewer extends JPanel { public class QuestWinLoseCardViewer extends JPanel {
//Data and number of choices for the list // Data and number of choices for the list
private List<CardPrinted> list; private List<CardPrinted> list;
//initialized before; listeners may be added to it // initialized before; listeners may be added to it
private JList jList; private JList jList;
private CardDetailPanel detail; private CardDetailPanel detail;
private CardPicturePanel picture; private CardPicturePanel picture;
public QuestWinLoseCardViewer(List<CardPrinted> list) { /**
* Instantiates a new quest win lose card viewer.
*
* @param list
* the list
*/
public QuestWinLoseCardViewer(final List<CardPrinted> list) {
this.list = unmodifiableList(list); this.list = unmodifiableList(list);
jList = new JList(new ChooserListModel()); jList = new JList(new ChooserListModel());
detail = new CardDetailPanel(null); detail = new CardDetailPanel(null);
@@ -42,7 +50,7 @@ public class QuestWinLoseCardViewer extends JPanel {
this.add(new JScrollPane(jList)); this.add(new JScrollPane(jList));
this.add(picture); this.add(picture);
this.add(detail); this.add(detail);
this.setLayout( new java.awt.GridLayout(1, 3, 6, 0) ); this.setLayout(new java.awt.GridLayout(1, 3, 6, 0));
// selection is here // selection is here
jList.getSelectionModel().addListSelectionListener(new SelListener()); jList.getSelectionModel().addListSelectionListener(new SelListener());
@@ -53,14 +61,18 @@ public class QuestWinLoseCardViewer extends JPanel {
private static final long serialVersionUID = 3871965346333840556L; private static final long serialVersionUID = 3871965346333840556L;
public int getSize() { return list.size(); } public int getSize() {
public Object getElementAt(int index) { return list.get(index); } return list.size();
} }
public Object getElementAt(final int index) {
return list.get(index);
}
}
private class SelListener implements ListSelectionListener { private class SelListener implements ListSelectionListener {
private Card[] cache = null; private Card[] cache = null;
public void valueChanged(final ListSelectionEvent e) { public void valueChanged(final ListSelectionEvent e) {
int row = jList.getSelectedIndex(); int row = jList.getSelectedIndex();
// (String) jList.getSelectedValue(); // (String) jList.getSelectedValue();
@@ -71,15 +83,17 @@ public class QuestWinLoseCardViewer extends JPanel {
picture.setCard(cp); picture.setCard(cp);
} }
} }
private void ensureCacheHas(int row, CardPrinted cp) { private void ensureCacheHas(final int row, final CardPrinted cp) {
if (cache == null) { cache = new Card[list.size()]; } if (cache == null) {
cache = new Card[list.size()];
}
if (null == cache[row]) { if (null == cache[row]) {
Card card = AllZone.getCardFactory().getCard(cp.getName(), null); Card card = AllZone.getCardFactory().getCard(cp.getName(), null);
card.setCurSetCode(cp.getSet()); card.setCurSetCode(cp.getSet());
card.setImageFilename(CardUtil.buildFilename(card)); card.setImageFilename(CardUtil.buildFilename(card));
cache[row] = card; cache[row] = card;
} }
} }
} }

View File

@@ -12,7 +12,6 @@ import javax.swing.JLabel;
import javax.swing.SwingConstants; import javax.swing.SwingConstants;
import net.slightlymagic.maxmtg.Predicate; import net.slightlymagic.maxmtg.Predicate;
import forge.AllZone; import forge.AllZone;
import forge.CardList; import forge.CardList;
import forge.Constant; import forge.Constant;
@@ -31,52 +30,61 @@ import forge.quest.data.QuestData;
import forge.quest.data.QuestMatchState; import forge.quest.data.QuestMatchState;
import forge.quest.data.QuestPreferences; import forge.quest.data.QuestPreferences;
import forge.quest.data.QuestUtil; import forge.quest.data.QuestUtil;
import forge.quest.gui.QuestWinLoseCardViewer;
import forge.quest.gui.main.QuestEvent;
import forge.quest.gui.main.QuestChallenge; import forge.quest.gui.main.QuestChallenge;
import forge.quest.gui.main.QuestEvent;
import forge.view.swing.WinLoseModeHandler; import forge.view.swing.WinLoseModeHandler;
/** <p>QuestWinLoseHandler.</p> // TODO: Auto-generated Javadoc
* Processes win/lose presentation for Quest events. This presentation /**
* is displayed by WinLoseFrame. Components to be added to pnlCustom in * <p>
* QuestWinLoseHandler.
* </p>
* Processes win/lose presentation for Quest events. This presentation is
* displayed by WinLoseFrame. Components to be added to pnlCustom in
* WinLoseFrame should use MigLayout. * WinLoseFrame should use MigLayout.
* *
*/ */
public class QuestWinLoseHandler extends WinLoseModeHandler { public class QuestWinLoseHandler extends WinLoseModeHandler {
private boolean wonMatch; private boolean wonMatch;
private ImageIcon icoTemp; private ImageIcon icoTemp;
private JLabel lblTemp1; private JLabel lblTemp1;
private JLabel lblTemp2; private JLabel lblTemp2;
/** The spacer. */
int spacer = 50; int spacer = 50;
private class CommonObjects { private class CommonObjects {
public QuestMatchState qMatchState; public QuestMatchState qMatchState;
public QuestData qData; public QuestData qData;
public QuestEvent qEvent; public QuestEvent qEvent;
} }
private CommonObjects model; private CommonObjects model;
/**
* Instantiates a new quest win lose handler.
*/
public QuestWinLoseHandler() { public QuestWinLoseHandler() {
super(); super();
model = new CommonObjects(); model = new CommonObjects();
model.qMatchState = AllZone.getMatchState(); model.qMatchState = AllZone.getMatchState();
model.qData = AllZone.getQuestData(); model.qData = AllZone.getQuestData();
model.qEvent = AllZone.getQuestEvent(); model.qEvent = AllZone.getQuestEvent();
wonMatch = model.qMatchState.isMatchWonBy(AllZone.getHumanPlayer().getName()); wonMatch = model.qMatchState.isMatchWonBy(AllZone.getHumanPlayer().getName());
} }
/** /**
* <p>startNextRound.</p> * <p>
* startNextRound.
* </p>
* Either continues or restarts a current game. * Either continues or restarts a current game.
* *
* @param e a {@link java.awt.event.ActionEvent} object.
*/ */
@Override @Override
public void startNextRound() { public final void startNextRound() {
if (Constant.Quest.fantasyQuest[0]) { if (Constant.Quest.fantasyQuest[0]) {
int extraLife = 0; int extraLife = 0;
if (model.qEvent.getEventType().equals("challenge")) { if (model.qEvent.getEventType().equals("challenge")) {
if (model.qData.getInventory().hasItem("Zeppelin")) { if (model.qData.getInventory().hasItem("Zeppelin")) {
extraLife = 3; extraLife = 3;
@@ -85,97 +93,102 @@ public class QuestWinLoseHandler extends WinLoseModeHandler {
CardList humanList = QuestUtil.getHumanStartingCards(model.qData, model.qEvent); CardList humanList = QuestUtil.getHumanStartingCards(model.qData, model.qEvent);
CardList computerList = QuestUtil.getComputerStartingCards(model.qData, model.qEvent); CardList computerList = QuestUtil.getComputerStartingCards(model.qData, model.qEvent);
int humanLife = model.qData.getLife() + extraLife; int humanLife = model.qData.getLife() + extraLife;
int computerLife = 20; int computerLife = 20;
if (model.qEvent.getEventType().equals("challenge")) { if (model.qEvent.getEventType().equals("challenge")) {
computerLife = ((QuestChallenge)model.qEvent).getAILife(); computerLife = ((QuestChallenge) model.qEvent).getAILife();
} }
AllZone.getGameAction().newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0], AllZone.getGameAction().newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0], humanList,
humanList, computerList, humanLife, computerLife, model.qEvent); computerList, humanLife, computerLife, model.qEvent);
} else { } else {
super.startNextRound(); super.startNextRound();
} }
} }
/** /**
* <p>populateCustomPanel.</p> * <p>
* Checks conditions of win and fires various reward display methods accordingly. * populateCustomPanel.
* * </p>
* @param boolean indicating if custom panel has contents. * Checks conditions of win and fires various reward display methods
* accordingly.
*
* @return true, if successful
*/ */
@Override @Override
public boolean populateCustomPanel() { public final boolean populateCustomPanel() {
view.btnRestart.setVisible(false); view.btnRestart.setVisible(false);
model.qData.getCards().resetNewList(); model.qData.getCards().resetNewList();
if(!model.qMatchState.isMatchOver()) { if (!model.qMatchState.isMatchOver()) {
view.btnQuit.setText("Quit (15 Credits)"); view.btnQuit.setText("Quit (15 Credits)");
return false; return false;
} } else {
else {
view.btnContinue.setVisible(false); view.btnContinue.setVisible(false);
if(wonMatch) { if (wonMatch) {
view.btnQuit.setText("Great!"); view.btnQuit.setText("Great!");
} } else {
else {
view.btnQuit.setText("OK"); view.btnQuit.setText("OK");
} }
} }
// Win case // Win case
if(wonMatch) { if (wonMatch) {
// Standard event reward credits // Standard event reward credits
awardEventCredits(); awardEventCredits();
// Challenge reward credits // Challenge reward credits
if(model.qEvent.getEventType().equals("challenge")) { if (model.qEvent.getEventType().equals("challenge")) {
awardChallengeWin(); awardChallengeWin();
} }
// Random rare given at 50% chance (65% with luck upgrade) // Random rare given at 50% chance (65% with luck upgrade)
if (getLuckyCoinResult()) { if (getLuckyCoinResult()) {
awardRandomRare("You've won a random rare."); awardRandomRare("You've won a random rare.");
} }
// Random rare for winning against a very hard deck // Random rare for winning against a very hard deck
if(model.qData.getDifficultyIndex() == 4) { if (model.qData.getDifficultyIndex() == 4) {
awardRandomRare("You've won a random rare for winning against a very hard deck."); awardRandomRare("You've won a random rare for winning against a very hard deck.");
} }
// Award jackpot every 80 games won (currently 10 rares) // Award jackpot every 80 games won (currently 10 rares)
int wins = model.qData.getWin(); int wins = model.qData.getWin();
if (wins > 0 && wins % 80 == 0) { if (wins > 0 && wins % 80 == 0) {
awardJackpot(); awardJackpot();
} }
} }
// Lose case // Lose case
else { else {
penalizeLoss(); penalizeLoss();
} }
// Win or lose, still a chance to win a booster, frequency set in preferences // Win or lose, still a chance to win a booster, frequency set in
// preferences
int outcome = wonMatch ? model.qData.getWin() : model.qData.getLost(); int outcome = wonMatch ? model.qData.getWin() : model.qData.getLost();
if (outcome % QuestPreferences.getWinsForBooster(model.qData.getDifficultyIndex()) == 0) { if (outcome % QuestPreferences.getWinsForBooster(model.qData.getDifficultyIndex()) == 0) {
awardBooster(); awardBooster();
} }
return true; return true;
} }
/** /**
* <p>actionOnQuit.</p> * <p>
* When "quit" button is pressed, this method adjusts quest data as appropriate and saves. * actionOnQuit.
* * </p>
* When "quit" button is pressed, this method adjusts quest data as
* appropriate and saves.
*
*/ */
@Override @Override
public void actionOnQuit() { public final void actionOnQuit() {
// Record win/loss in quest data // Record win/loss in quest data
if (wonMatch) { if (wonMatch) {
model.qData.addWin(); model.qData.addWin();
} else { } else {
model.qData.addLost(); model.qData.addLost();
model.qData.subtractCredits(15); model.qData.subtractCredits(15);
} }
@@ -192,16 +205,18 @@ public class QuestWinLoseHandler extends WinLoseModeHandler {
new QuestFrame(); new QuestFrame();
} }
/** /**
* <p>awardEventCredits.</p> * <p>
* awardEventCredits.
* </p>
* Generates and displays standard rewards for gameplay and skill level. * Generates and displays standard rewards for gameplay and skill level.
* *
*/ */
private void awardEventCredits() { private void awardEventCredits() {
// TODO use q.qdPrefs to write bonus credits in prefs file // TODO use q.qdPrefs to write bonus credits in prefs file
StringBuilder sb = new StringBuilder("<html>"); StringBuilder sb = new StringBuilder("<html>");
int credTotal = 0; int credTotal = 0;
int credBase = 0; int credBase = 0;
int credGameplay = 0; int credGameplay = 0;
@@ -211,84 +226,83 @@ public class QuestWinLoseHandler extends WinLoseModeHandler {
// Basic win bonus // Basic win bonus
int base = QuestPreferences.getMatchRewardBase(); int base = QuestPreferences.getMatchRewardBase();
double multiplier = 1; double multiplier = 1;
String diff = AllZone.getQuestEvent().getDifficulty(); String diff = AllZone.getQuestEvent().getDifficulty();
diff = diff.substring(0, 1).toUpperCase() + diff.substring(1); diff = diff.substring(0, 1).toUpperCase() + diff.substring(1);
if(diff.equalsIgnoreCase("medium")) { if (diff.equalsIgnoreCase("medium")) {
multiplier = 1.5; multiplier = 1.5;
} } else if (diff.equalsIgnoreCase("hard")) {
else if(diff.equalsIgnoreCase("hard")) {
multiplier = 2; multiplier = 2;
} } else if (diff.equalsIgnoreCase("very hard")) {
else if(diff.equalsIgnoreCase("very hard")) {
multiplier = 2.5; multiplier = 2.5;
} } else if (diff.equalsIgnoreCase("expert")) {
else if(diff.equalsIgnoreCase("expert")) {
multiplier = 3; multiplier = 3;
} }
credBase += (int) (base * multiplier + (QuestPreferences.getMatchRewardTotalWins() * model.qData.getWin()));
credBase += (int) (base*multiplier +
(QuestPreferences.getMatchRewardTotalWins() * model.qData.getWin()));
sb.append(diff + " opponent: " + credBase + " credits.<br>"); sb.append(diff + " opponent: " + credBase + " credits.<br>");
// Gameplay bonuses (for each game win) // Gameplay bonuses (for each game win)
boolean hasNeverLost = true; boolean hasNeverLost = true;
Player computer = AllZone.getComputerPlayer(); Player computer = AllZone.getComputerPlayer();
for (GameSummary game : model.qMatchState.getGamesPlayed()) { for (GameSummary game : model.qMatchState.getGamesPlayed()) {
if (game.isWinner(computer.getName())) { if (game.isWinner(computer.getName())) {
hasNeverLost = false; hasNeverLost = false;
continue; // no rewards for losing a game continue; // no rewards for losing a game
} }
// Alternate win // Alternate win
GamePlayerRating aiRating = game.getPlayerRating(computer.getName()); GamePlayerRating aiRating = game.getPlayerRating(computer.getName());
GamePlayerRating humanRating = game.getPlayerRating(AllZone.getHumanPlayer().getName()); GamePlayerRating humanRating = game.getPlayerRating(AllZone.getHumanPlayer().getName());
GameLossReason whyAiLost = aiRating.getLossReason(); GameLossReason whyAiLost = aiRating.getLossReason();
int altReward = getCreditsRewardForAltWin(whyAiLost); int altReward = getCreditsRewardForAltWin(whyAiLost);
if (altReward > 0) { if (altReward > 0) {
String winConditionName = "Unknown (bug)"; String winConditionName = "Unknown (bug)";
if (game.getWinCondition() == GameEndReason.WinsGameSpellEffect) { if (game.getWinCondition() == GameEndReason.WinsGameSpellEffect) {
winConditionName = game.getWinSpellEffect(); winConditionName = game.getWinSpellEffect();
} else { } else {
switch(whyAiLost) { switch (whyAiLost) {
case Poisoned: winConditionName = "Poison"; break; case Poisoned:
case Milled: winConditionName = "Milled"; break; winConditionName = "Poison";
case SpellEffect: winConditionName = aiRating.getLossSpellName(); break; break;
default: break; case Milled:
winConditionName = "Milled";
break;
case SpellEffect:
winConditionName = aiRating.getLossSpellName();
break;
default:
break;
} }
} }
credGameplay += 50; credGameplay += 50;
sb.append(String.format("Alternate win condition: <u>%s</u>! " + sb.append(String.format("Alternate win condition: <u>%s</u>! " + "Bonus: %d credits.<br>",
"Bonus: %d credits.<br>",
winConditionName, 50)); winConditionName, 50));
} }
// Mulligan to zero // Mulligan to zero
int cntCardsHumanStartedWith = humanRating.getOpeningHandSize(); int cntCardsHumanStartedWith = humanRating.getOpeningHandSize();
int mulliganReward = QuestPreferences.getMatchMullToZero(); int mulliganReward = QuestPreferences.getMatchMullToZero();
if (0 == cntCardsHumanStartedWith) { if (0 == cntCardsHumanStartedWith) {
credGameplay += mulliganReward; credGameplay += mulliganReward;
sb.append(String.format("Mulliganed to zero and still won! " + sb.append(String
"Bonus: %d credits.<br>", mulliganReward)); .format("Mulliganed to zero and still won! " + "Bonus: %d credits.<br>", mulliganReward));
} }
// Early turn bonus // Early turn bonus
int winTurn = game.getTurnGameEnded(); int winTurn = game.getTurnGameEnded();
int turnCredits = getCreditsRewardForWinByTurn(winTurn); int turnCredits = getCreditsRewardForWinByTurn(winTurn);
if (winTurn == 0) { System.err.println("QuestWinLoseHandler > " + if (winTurn == 0) {
"turn calculation error: Zero turn win"); System.err.println("QuestWinLoseHandler > " + "turn calculation error: Zero turn win");
} else if (winTurn == 1) { sb.append("Won in one turn!"); } else if (winTurn == 1) {
} else if (winTurn <= 5) { sb.append("Won by turn 5!"); sb.append("Won in one turn!");
} else if (winTurn <= 10) { sb.append("Won by turn 10!"); } else if (winTurn <= 5) {
} else if (winTurn <= 15) { sb.append("Won by turn 15!"); sb.append("Won by turn 5!");
} else if (winTurn <= 10) {
sb.append("Won by turn 10!");
} else if (winTurn <= 15) {
sb.append("Won by turn 15!");
} }
if (turnCredits > 0) { if (turnCredits > 0) {
@@ -296,46 +310,46 @@ public class QuestWinLoseHandler extends WinLoseModeHandler {
sb.append(String.format(" Bonus: %d credits.<br>", turnCredits)); sb.append(String.format(" Bonus: %d credits.<br>", turnCredits));
} }
} // End for(game) } // End for(game)
// Undefeated bonus // Undefeated bonus
if (hasNeverLost) { if (hasNeverLost) {
credUndefeated += QuestPreferences.getMatchRewardNoLosses(); credUndefeated += QuestPreferences.getMatchRewardNoLosses();
int reward = QuestPreferences.getMatchRewardNoLosses(); int reward = QuestPreferences.getMatchRewardNoLosses();
sb.append(String.format("You have not lost once! " + sb.append(String.format("You have not lost once! " + "Bonus: %d credits.<br>", reward));
"Bonus: %d credits.<br>", reward));
} }
// Estates bonus // Estates bonus
credTotal = credBase + credGameplay + credUndefeated; credTotal = credBase + credGameplay + credUndefeated;
switch(model.qData.getInventory().getItemLevel("Estates")) { switch (model.qData.getInventory().getItemLevel("Estates")) {
case 1: case 1:
credEstates = (int)0.1*credTotal; credEstates = (int) 0.1 * credTotal;
sb.append("Estates bonus: 10%.<br>"); sb.append("Estates bonus: 10%.<br>");
break; break;
case 2: case 2:
credEstates = (int)0.15*credTotal; credEstates = (int) 0.15 * credTotal;
sb.append("Estates bonus: 15%.<br>"); sb.append("Estates bonus: 15%.<br>");
break; break;
case 3: case 3:
credEstates = (int)0.2*credTotal; credEstates = (int) 0.2 * credTotal;
sb.append("Estates bonus: 20%.<br>"); sb.append("Estates bonus: 20%.<br>");
break; break;
default: break; default:
break;
} }
credTotal += credEstates; credTotal += credEstates;
// Final output // Final output
String congrats = "<br><h3>"; String congrats = "<br><h3>";
if(credTotal < 100) { if (credTotal < 100) {
congrats += "You've earned"; congrats += "You've earned";
} else if(credTotal < 250) { } else if (credTotal < 250) {
congrats += "Could be worse: "; congrats += "Could be worse: ";
} else if(credTotal < 500) { } else if (credTotal < 500) {
congrats += "A respectable"; congrats += "A respectable";
} else if(credTotal < 750) { } else if (credTotal < 750) {
congrats += "An impressive"; congrats += "An impressive";
} else { } else {
congrats += "Spectacular match!"; congrats += "Spectacular match!";
@@ -344,148 +358,154 @@ public class QuestWinLoseHandler extends WinLoseModeHandler {
sb.append(String.format("%s <b>%d credits</b> in total.</h3>", congrats, credTotal)); sb.append(String.format("%s <b>%d credits</b> in total.</h3>", congrats, credTotal));
sb.append("</body></html>"); sb.append("</body></html>");
model.qData.addCredits(credTotal); model.qData.addCredits(credTotal);
// Generate Swing components and attach. // Generate Swing components and attach.
icoTemp = GuiUtils.getResizedIcon("GoldIcon.png",0.5); icoTemp = GuiUtils.getResizedIcon("GoldIcon.png", 0.5);
lblTemp1 = new TitleLabel("Gameplay Results"); lblTemp1 = new TitleLabel("Gameplay Results");
lblTemp2 = new JLabel(sb.toString()); lblTemp2 = new JLabel(sb.toString());
lblTemp2.setHorizontalAlignment(SwingConstants.CENTER); lblTemp2.setHorizontalAlignment(SwingConstants.CENTER);
lblTemp2.setFont(AllZone.getSkin().font2.deriveFont(Font.PLAIN,14)); lblTemp2.setFont(AllZone.getSkin().font2.deriveFont(Font.PLAIN, 14));
lblTemp2.setForeground(Color.white); lblTemp2.setForeground(Color.white);
lblTemp2.setIcon(icoTemp); lblTemp2.setIcon(icoTemp);
lblTemp2.setIconTextGap(50); lblTemp2.setIconTextGap(50);
view.pnlCustom.add(lblTemp1, "align center, width 95%!");
view.pnlCustom.add(lblTemp1,"align center, width 95%!"); view.pnlCustom.add(lblTemp2, "align center, width 95%!, gaptop 10");
view.pnlCustom.add(lblTemp2,"align center, width 95%!, gaptop 10");
} }
/** /**
* <p>awardRandomRare.</p> * <p>
* awardRandomRare.
* </p>
* Generates and displays a random rare win case. * Generates and displays a random rare win case.
* *
*/ */
private void awardRandomRare(String message) { private void awardRandomRare(final String message) {
CardPrinted c = model.qData.getCards().addRandomRare(); CardPrinted c = model.qData.getCards().addRandomRare();
List<CardPrinted> cardsWon = new ArrayList<CardPrinted>(); List<CardPrinted> cardsWon = new ArrayList<CardPrinted>();
cardsWon.add(c); cardsWon.add(c);
// Generate Swing components and attach. // Generate Swing components and attach.
lblTemp1 = new TitleLabel(message); lblTemp1 = new TitleLabel(message);
QuestWinLoseCardViewer cv = new QuestWinLoseCardViewer(cardsWon); QuestWinLoseCardViewer cv = new QuestWinLoseCardViewer(cardsWon);
view.pnlCustom.add(lblTemp1,"align center, width 95%!, " + view.pnlCustom.add(lblTemp1, "align center, width 95%!, " + "gaptop " + spacer + ", gapbottom 10");
"gaptop " + spacer + ", gapbottom 10"); view.pnlCustom.add(cv, "align center, width 95%!");
view.pnlCustom.add(cv,"align center, width 95%!");
} }
/** /**
* <p>awardJackpot.</p> * <p>
* awardJackpot.
* </p>
* Generates and displays jackpot win case. * Generates and displays jackpot win case.
* *
*/ */
private void awardJackpot() { private void awardJackpot() {
List<CardPrinted> cardsWon = model.qData.getCards().addRandomRare(10); List<CardPrinted> cardsWon = model.qData.getCards().addRandomRare(10);
// Generate Swing components and attach. // Generate Swing components and attach.
lblTemp1 = new TitleLabel("You just won 10 random rares!"); lblTemp1 = new TitleLabel("You just won 10 random rares!");
QuestWinLoseCardViewer cv = new QuestWinLoseCardViewer(cardsWon); QuestWinLoseCardViewer cv = new QuestWinLoseCardViewer(cardsWon);
view.pnlCustom.add(lblTemp1,"align center, width 95%!, " + view.pnlCustom.add(lblTemp1, "align center, width 95%!, " + "gaptop " + spacer + ", gapbottom 10");
"gaptop " + spacer + ", gapbottom 10"); view.pnlCustom.add(cv, "align center, width 95%!");
view.pnlCustom.add(cv,"align center, width 95%!");
} }
/** /**
* <p>awardBooster.</p> * <p>
* awardBooster.
* </p>
* Generates and displays booster pack win case. * Generates and displays booster pack win case.
* *
*/ */
private void awardBooster() { private void awardBooster() {
ListChooser<GameFormat> ch = new ListChooser<GameFormat>("Choose bonus booster format", 1, SetUtils.getFormats()); ListChooser<GameFormat> ch = new ListChooser<GameFormat>("Choose bonus booster format", 1,
SetUtils.getFormats());
ch.show(); ch.show();
GameFormat selected = ch.getSelectedValue(); GameFormat selected = ch.getSelectedValue();
List<CardPrinted> cardsWon = model.qData.getCards().addCards(Predicate.and(selected.getFilterPrinted(),CardPrinted.Predicates.Presets.nonAlternate)); List<CardPrinted> cardsWon = model.qData.getCards().addCards(
Predicate.and(selected.getFilterPrinted(), CardPrinted.Predicates.Presets.nonAlternate));
// Generate Swing components and attach.
lblTemp1 = new TitleLabel("Bonus booster pack from the \""+selected.getName()+"\" format!"); // Generate Swing components and attach.
lblTemp1 = new TitleLabel("Bonus booster pack from the \"" + selected.getName() + "\" format!");
QuestWinLoseCardViewer cv = new QuestWinLoseCardViewer(cardsWon); QuestWinLoseCardViewer cv = new QuestWinLoseCardViewer(cardsWon);
view.pnlCustom.add(lblTemp1,"align center, width 95%!, " + view.pnlCustom.add(lblTemp1, "align center, width 95%!, " + "gaptop " + spacer + ", gapbottom 10");
"gaptop " + spacer + ", gapbottom 10"); view.pnlCustom.add(cv, "align center, width 95%!");
view.pnlCustom.add(cv,"align center, width 95%!");
} }
/** /**
* <p>awardChallengeWin.</p> * <p>
* awardChallengeWin.
* </p>
* Generates and displays win case for challenge event. * Generates and displays win case for challenge event.
* *
*/ */
private void awardChallengeWin() { private void awardChallengeWin() {
if(!((QuestChallenge)model.qEvent).getRepeatable()) { if (!((QuestChallenge) model.qEvent).getRepeatable()) {
model.qData.addCompletedChallenge(((QuestChallenge)model.qEvent).getId()); model.qData.addCompletedChallenge(((QuestChallenge) model.qEvent).getId());
} }
// Note: challenge only registers as "played" if it's won. // Note: challenge only registers as "played" if it's won.
// This doesn't seem right, but it's easy to fix. Doublestrike 01-10-11 // This doesn't seem right, but it's easy to fix. Doublestrike 01-10-11
model.qData.addChallengesPlayed(); model.qData.addChallengesPlayed();
List<CardPrinted> cardsWon = ((QuestChallenge)model.qEvent).getCardRewardList(); List<CardPrinted> cardsWon = ((QuestChallenge) model.qEvent).getCardRewardList();
long questRewardCredits = ((QuestChallenge)model.qEvent).getCreditsReward(); long questRewardCredits = ((QuestChallenge) model.qEvent).getCreditsReward();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("<html>Challenge completed.<br><br>"); sb.append("<html>Challenge completed.<br><br>");
sb.append("Challenge bounty: <b>" + questRewardCredits + " credits.</b></html>"); sb.append("Challenge bounty: <b>" + questRewardCredits + " credits.</b></html>");
model.qData.addCredits(questRewardCredits); model.qData.addCredits(questRewardCredits);
// Generate Swing components and attach. // Generate Swing components and attach.
icoTemp = GuiUtils.getResizedIcon("BoxIcon.png",0.5); icoTemp = GuiUtils.getResizedIcon("BoxIcon.png", 0.5);
lblTemp1 = new TitleLabel("Challenge Rewards for \"" + lblTemp1 = new TitleLabel("Challenge Rewards for \"" + ((QuestChallenge) model.qEvent).getTitle() + "\"");
((QuestChallenge)model.qEvent).getTitle() + "\"");
lblTemp2 = new JLabel(sb.toString()); lblTemp2 = new JLabel(sb.toString());
lblTemp2.setFont(AllZone.getSkin().font2.deriveFont(Font.PLAIN,14)); lblTemp2.setFont(AllZone.getSkin().font2.deriveFont(Font.PLAIN, 14));
lblTemp2.setForeground(Color.white); lblTemp2.setForeground(Color.white);
lblTemp2.setHorizontalAlignment(SwingConstants.CENTER); lblTemp2.setHorizontalAlignment(SwingConstants.CENTER);
lblTemp2.setIconTextGap(50); lblTemp2.setIconTextGap(50);
lblTemp2.setIcon(icoTemp); lblTemp2.setIcon(icoTemp);
view.pnlCustom.add(lblTemp1,"align center, width 95%!, " + view.pnlCustom.add(lblTemp1, "align center, width 95%!, " + "gaptop " + spacer);
"gaptop " + spacer); view.pnlCustom.add(lblTemp2, "align center, width 95%!, height 80!, gapbottom 10");
view.pnlCustom.add(lblTemp2,"align center, width 95%!, height 80!, gapbottom 10");
if (cardsWon != null) { if (cardsWon != null) {
QuestWinLoseCardViewer cv = new QuestWinLoseCardViewer(cardsWon); QuestWinLoseCardViewer cv = new QuestWinLoseCardViewer(cardsWon);
view.pnlCustom.add(cv,"align center, width 95%!"); view.pnlCustom.add(cv, "align center, width 95%!");
model.qData.getCards().addAllCards(cardsWon); model.qData.getCards().addAllCards(cardsWon);
} }
} }
private void penalizeLoss() { private void penalizeLoss() {
icoTemp = GuiUtils.getResizedIcon("HeartIcon.png",0.5); icoTemp = GuiUtils.getResizedIcon("HeartIcon.png", 0.5);
lblTemp1 = new TitleLabel("Gameplay Results"); lblTemp1 = new TitleLabel("Gameplay Results");
lblTemp2 = new JLabel("You lose! You have lost 15 credits."); lblTemp2 = new JLabel("You lose! You have lost 15 credits.");
lblTemp2.setFont(AllZone.getSkin().font2.deriveFont(Font.PLAIN,14)); lblTemp2.setFont(AllZone.getSkin().font2.deriveFont(Font.PLAIN, 14));
lblTemp2.setForeground(Color.white); lblTemp2.setForeground(Color.white);
lblTemp2.setHorizontalAlignment(SwingConstants.CENTER); lblTemp2.setHorizontalAlignment(SwingConstants.CENTER);
lblTemp2.setIconTextGap(50); lblTemp2.setIconTextGap(50);
lblTemp2.setIcon(icoTemp); lblTemp2.setIcon(icoTemp);
view.pnlCustom.add(lblTemp1,"align center, width 95%!"); view.pnlCustom.add(lblTemp1, "align center, width 95%!");
view.pnlCustom.add(lblTemp2,"align center, width 95%!, height 80!"); view.pnlCustom.add(lblTemp2, "align center, width 95%!, height 80!");
} }
/** /**
* <p>getLuckyCoinResult.</p> * <p>
* getLuckyCoinResult.
* </p>
* A chance check, for rewards like random rares. * A chance check, for rewards like random rares.
* *
* @return boolean * @return boolean
*/ */
private boolean getLuckyCoinResult() { private boolean getLuckyCoinResult() {
@@ -493,65 +513,77 @@ public class QuestWinLoseHandler extends WinLoseModeHandler {
return MyRandom.random.nextFloat() <= (hasCoin ? 0.65f : 0.5f); return MyRandom.random.nextFloat() <= (hasCoin ? 0.65f : 0.5f);
} }
/** /**
* <p>getCreditsRewardForAltWin.</p> * <p>
* getCreditsRewardForAltWin.
* </p>
* Retrieves credits for win under special conditions. * Retrieves credits for win under special conditions.
* *
* @param GameLossReason why AI lost * @param GameLossReason
* why AI lost
* @return int * @return int
*/ */
private int getCreditsRewardForAltWin(final GameLossReason whyAiLost) { private int getCreditsRewardForAltWin(final GameLossReason whyAiLost) {
switch (whyAiLost) { switch (whyAiLost) {
case LifeReachedZero: return 0; // nothing special here, ordinary kill case LifeReachedZero:
case Milled: return QuestPreferences.getMatchRewardMilledWinBonus(); return 0; // nothing special here, ordinary kill
case Poisoned: return QuestPreferences.getMatchRewardPoisonWinBonus(); case Milled:
case DidNotLoseYet: return QuestPreferences.getMatchRewardAltWinBonus(); // Felidar, Helix Pinnacle, etc. return QuestPreferences.getMatchRewardMilledWinBonus();
case SpellEffect: return QuestPreferences.getMatchRewardAltWinBonus(); // Door to Nothingness, etc. case Poisoned:
default: return 0; return QuestPreferences.getMatchRewardPoisonWinBonus();
case DidNotLoseYet:
return QuestPreferences.getMatchRewardAltWinBonus(); // Felidar,
// Helix
// Pinnacle,
// etc.
case SpellEffect:
return QuestPreferences.getMatchRewardAltWinBonus(); // Door to
// Nothingness,
// etc.
default:
return 0;
} }
} }
/** /**
* <p>getCreditsRewardForWinByTurn.</p> * <p>
* getCreditsRewardForWinByTurn.
* </p>
* Retrieves credits for win on or under turn count. * Retrieves credits for win on or under turn count.
* *
* @param int turn count * @param int turn count
* @return int credits won * @return int credits won
*/ */
private int getCreditsRewardForWinByTurn(final int iTurn) { private int getCreditsRewardForWinByTurn(final int iTurn) {
int credits = 0; int credits = 0;
if (iTurn == 1) { if (iTurn == 1) {
credits = QuestPreferences.getMatchRewardWinFirst(); credits = QuestPreferences.getMatchRewardWinFirst();
} } else if (iTurn <= 5) {
else if (iTurn <= 5) {
credits = QuestPreferences.getMatchRewardWinByFifth(); credits = QuestPreferences.getMatchRewardWinByFifth();
} } else if (iTurn <= 10) {
else if (iTurn <= 10) {
credits = QuestPreferences.getMatchRewardWinByTen(); credits = QuestPreferences.getMatchRewardWinByTen();
} } else if (iTurn <= 15) {
else if (iTurn <= 15) {
credits = QuestPreferences.getMatchRewardWinByFifteen(); credits = QuestPreferences.getMatchRewardWinByFifteen();
} }
return credits; return credits;
} }
/** /**
* JLabel header between reward sections. * JLabel header between reward sections.
* *
*/ */
@SuppressWarnings("serial") @SuppressWarnings("serial")
private class TitleLabel extends JLabel { private class TitleLabel extends JLabel {
TitleLabel(String msg) { TitleLabel(final String msg) {
super(msg); super(msg);
this.setFont(AllZone.getSkin().font2.deriveFont(Font.ITALIC,16)); this.setFont(AllZone.getSkin().font2.deriveFont(Font.ITALIC, 16));
this.setPreferredSize(new Dimension(200,40)); this.setPreferredSize(new Dimension(200, 40));
this.setHorizontalAlignment(SwingConstants.CENTER); this.setHorizontalAlignment(SwingConstants.CENTER);
this.setForeground(Color.white); this.setForeground(Color.white);
this.setBorder(BorderFactory.createMatteBorder(1, 0, 1, 0, Color.white)); this.setBorder(BorderFactory.createMatteBorder(1, 0, 1, 0, Color.white));
} }
} }
}
}

View File

@@ -1,2 +1,2 @@
/** Forge Card Game */ /** Forge Card Game. */
package forge.quest.gui; package forge.quest.gui;