diff --git a/src/main/java/forge/quest/gui/QuestAbstractPanel.java b/src/main/java/forge/quest/gui/QuestAbstractPanel.java index 47eb1c79f9b..9423eec2aca 100644 --- a/src/main/java/forge/quest/gui/QuestAbstractPanel.java +++ b/src/main/java/forge/quest/gui/QuestAbstractPanel.java @@ -1,30 +1,38 @@ package forge.quest.gui; -import javax.swing.*; +import javax.swing.JPanel; /** - *
Abstract QuestAbstractPanel class.
- * + *+ * Abstract QuestAbstractPanel class. + *
+ * * @author Forge * @version $Id$ */ public abstract class QuestAbstractPanel extends JPanel { - /** ConstantserialVersionUID=-6378675010346615367L */
+ /** Constant serialVersionUID=-6378675010346615367L. */
private static final long serialVersionUID = -6378675010346615367L;
+ /** The main frame. */
public QuestFrame mainFrame;
/**
- * Constructor for QuestAbstractPanel.
- * - * @param mainFrame a {@link forge.quest.gui.QuestFrame} object. + *+ * Constructor for QuestAbstractPanel. + *
+ * + * @param mainFrame + * a {@link forge.quest.gui.QuestFrame} object. */ - protected QuestAbstractPanel(QuestFrame mainFrame) { + protected QuestAbstractPanel(final QuestFrame mainFrame) { this.mainFrame = mainFrame; } /** - *refreshState.
+ *+ * refreshState. + *
*/ public abstract void refreshState(); } diff --git a/src/main/java/forge/quest/gui/QuestFrame.java b/src/main/java/forge/quest/gui/QuestFrame.java index 708817e51f0..64355d00bae 100644 --- a/src/main/java/forge/quest/gui/QuestFrame.java +++ b/src/main/java/forge/quest/gui/QuestFrame.java @@ -1,45 +1,60 @@ 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.gui.GuiUtils; import forge.quest.gui.bazaar.QuestBazaarPanel; import forge.view.swing.Gui_HomeScreen; import forge.view.swing.OldGuiNewGame; -import javax.swing.*; -import javax.swing.border.EmptyBorder; -import java.awt.*; -import java.util.HashMap; -import java.util.Map; - /** - *QuestFrame class.
- * + *+ * QuestFrame class. + *
+ * * @author Forge * @version $Id$ */ public class QuestFrame extends JFrame { - /** ConstantserialVersionUID=-2832625381531838412L */
+ /** Constant serialVersionUID=-2832625381531838412L. */
private static final long serialVersionUID = -2832625381531838412L;
+ /** The visible panel. */
JPanel visiblePanel;
+
+ /** The quest layout. */
CardLayout questLayout;
- /** Constant MAIN_PANEL="Main" */
+ /** Constant MAIN_PANEL="Main". */
public static final String MAIN_PANEL = "Main";
- /** Constant BAZAAR_PANEL="Bazaar" */
+
+ /** Constant BAZAAR_PANEL="Bazaar". */
public static final String BAZAAR_PANEL = "Bazaar";
+ /** The sub panel map. */
MapConstructor for QuestFrame.
- * - * @throws java.awt.HeadlessException if any. + *+ * Constructor for QuestFrame. + *
+ * + * @throws HeadlessException + * the headless exception */ public QuestFrame() throws HeadlessException { - this.setTitle("Quest Mode"); - + this.setTitle("Quest Mode"); + visiblePanel = new JPanel(new BorderLayout()); visiblePanel.setBorder(new EmptyBorder(2, 2, 2, 2)); questLayout = new CardLayout(); @@ -68,41 +83,48 @@ public class QuestFrame extends JFrame { } - /** - *showPane.
- * - * @param paneName a {@link java.lang.String} object. + *+ * showPane. + *
+ * + * @param paneName + * a {@link java.lang.String} object. */ - private void showPane(String paneName) { + private void showPane(final String paneName) { subPanelMap.get(paneName).refreshState(); questLayout.show(visiblePanel, paneName); } /** - *showMainPane.
+ *+ * showMainPane. + *
*/ - public void showMainPane() { + public final void showMainPane() { showPane(MAIN_PANEL); } /** - *showBazaarPane.
+ *+ * showBazaarPane. + *
*/ - public void showBazaarPane() { + public final void showBazaarPane() { showPane(BAZAAR_PANEL); } - /** - *returnToMainMenu.
+ *+ * returnToMainMenu. + *
*/ - public void returnToMainMenu() { + public final void returnToMainMenu() { AllZone.getQuestData().saveData(); - + if (System.getenv("NG2") != null) { if (System.getenv("NG2").equalsIgnoreCase("true")) { - String argz[] = {}; + String[] argz = {}; Gui_HomeScreen.main(argz); } else { new OldGuiNewGame(); diff --git a/src/main/java/forge/quest/gui/QuestMainPanel.java b/src/main/java/forge/quest/gui/QuestMainPanel.java index 37e5ddfaf52..a2e60a95190 100644 --- a/src/main/java/forge/quest/gui/QuestMainPanel.java +++ b/src/main/java/forge/quest/gui/QuestMainPanel.java @@ -1,109 +1,151 @@ package forge.quest.gui; - -import forge.*; -import forge.deck.Deck; -import forge.gui.GuiUtils; -import forge.gui.deckeditor.DeckEditorShop; -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.BorderLayout; +import java.awt.CardLayout; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; 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.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; /** - *QuestMainPanel class.
+ *+ * QuestMainPanel class. + *
* VIEW - lays out swing components for duel and challenge events. - * + * * @author Forge * @version $Id: QuestMainPanel.java 10358 2011-09-11 05:20:13Z Doublestrike $ */ public class QuestMainPanel extends QuestAbstractPanel { - /** ConstantserialVersionUID=6142934729724012402L */
+ /** Constant serialVersionUID=6142934729724012402L. */
private static final long serialVersionUID = 6142934729724012402L;
private forge.quest.data.QuestData questData;
private forge.quest.gui.main.QuestEventManager qem;
+ /** The credits label. */
JLabel creditsLabel = new JLabel();
+
+ /** The life label. */
JLabel lifeLabel = new JLabel();
+
+ /** The stats label. */
JLabel statsLabel = new JLabel();
+
+ /** The title label. */
JLabel titleLabel = new JLabel();
+
+ /** The next quest label. */
JLabel nextQuestLabel = new JLabel();
+ /** The pet combo box. */
JComboBox petComboBox = new JComboBox();
+
+ /** The deck combo box. */
JComboBox deckComboBox = new JComboBox();
+ /** The event button. */
JButton eventButton = new JButton("Challenges");
+
+ /** The play button. */
JButton playButton = new JButton("Play");
private QuestSelectablePanel selectedOpponent;
+ /** The next match panel. */
JPanel nextMatchPanel = new JPanel();
+
+ /** The next match layout. */
CardLayout nextMatchLayout;
+ /** The is showing challenges. */
boolean isShowingChallenges = false;
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 petCheckBox = new JCheckBox("Summon Pet");
private JCheckBox plantBox = new JCheckBox("Summon Plant");
- /** Constant NO_DECKS_AVAILABLE="No decks available" */
+ /** Constant NO_DECKS_AVAILABLE="No decks available". */
private static final String NO_DECKS_AVAILABLE = "No decks available";
- /** Constant DUELS="Duels" */
+ /** Constant DUELS="Duels". */
private static final String DUELS = "Duels";
- /** Constant CHALLENGES="Challenges" */
+ /** Constant CHALLENGES="Challenges". */
private static final String CHALLENGES = "Challenges";
- //TODO: Make this ordering permanent
- /** Constant lastUsedDeck="//TODO: Make this ordering permanent" */
+ // TODO: Make this ordering permanent
+ /** Constant lastUsedDeck="//TODO: Make this ordering permanent". */
private static String lastUsedDeck;
- private JButton zeppelinButton = new JButton("LaunchConstructor for QuestMainPanel.
- * - * @param mainFrame a {@link forge.quest.gui.QuestFrame} object. + *+ * Constructor for QuestMainPanel. + *
+ * + * @param mainFrame + * a {@link forge.quest.gui.QuestFrame} object. */ - public QuestMainPanel(QuestFrame mainFrame) { + public QuestMainPanel(final QuestFrame mainFrame) { super(mainFrame); questData = AllZone.getQuestData(); qem = AllZone.getQuestEventManager(); - + // QuestEventManager is the MODEL for this VIEW. // All quest events are generated here, the first time the VIEW is made. - if(qem==null) { + if (qem == null) { qem = new QuestEventManager(); - qem.assembleAllEvents(); + qem.assembleAllEvents(); AllZone.setQuestEventManager(qem); - } + } initUI(); } /** - *initUI.
+ *+ * initUI. + *
*/ private void initUI() { refresh(); @@ -126,14 +168,16 @@ public class QuestMainPanel extends QuestAbstractPanel { } /** - *createStatusPanel.
- * + *+ * createStatusPanel. + *
+ * * @return a {@link javax.swing.JPanel} object. */ private JPanel createStatusPanel() { JPanel northPanel = new JPanel(); 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.setAlignmentX(LEFT_ALIGNMENT); northPanel.setLayout(new BoxLayout(northPanel, BoxLayout.Y_AXIS)); @@ -160,21 +204,23 @@ public class QuestMainPanel extends QuestAbstractPanel { } /** - *createSidePanel.
- * + *+ * createSidePanel. + *
+ * * @return a {@link javax.swing.JPanel} object. */ private JPanel createSidePanel() { JPanel panel = new JPanel(); - JPanel optionsPanel; //Create options checkbox list + JPanel optionsPanel; // Create options checkbox list optionsPanel = createOptionsPanel(); ListcreateOptionsPanel.
- * + *+ * createOptionsPanel. + *
+ * * @return a {@link javax.swing.JPanel} object. */ private JPanel createOptionsPanel() { @@ -275,7 +320,7 @@ public class QuestMainPanel extends QuestAbstractPanel { optionsPanel = new JPanel(); optionsPanel.setLayout(new BoxLayout(optionsPanel, BoxLayout.Y_AXIS)); - //optionsPanel.add(this.newGUICheckbox); + // optionsPanel.add(this.newGUICheckbox); optionsPanel.add(Box.createVerticalStrut(5)); optionsPanel.add(this.smoothLandCheckBox); optionsPanel.add(Box.createVerticalStrut(5)); @@ -285,8 +330,10 @@ public class QuestMainPanel extends QuestAbstractPanel { } /** - *createMatchSettingsPanel.
- * + *+ * createMatchSettingsPanel. + *
+ * * @return a {@link javax.swing.JPanel} object. */ private JPanel createMatchSettingsPanel() { @@ -302,7 +349,7 @@ public class QuestMainPanel extends QuestAbstractPanel { GuiUtils.addGap(deckPanel); this.deckComboBox.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { + public void actionPerformed(final ActionEvent actionEvent) { playButton.setEnabled(canGameBeLaunched()); lastUsedDeck = (String) deckComboBox.getSelectedItem(); } @@ -313,7 +360,7 @@ public class QuestMainPanel extends QuestAbstractPanel { JButton editDeckButton = new JButton("Deck Editor"); editDeckButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { + public void actionPerformed(final ActionEvent actionEvent) { showDeckEditor(); } }); @@ -322,7 +369,6 @@ public class QuestMainPanel extends QuestAbstractPanel { deckPanel.setAlignmentX(LEFT_ALIGNMENT); matchPanel.add(deckPanel); - GuiUtils.addGap(matchPanel); 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)); this.petCheckBox.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { + public void actionPerformed(final ActionEvent actionEvent) { if (petCheckBox.isSelected()) { questData.getPetManager().setSelectedPet((String) petComboBox.getSelectedItem()); } else { @@ -347,7 +393,7 @@ public class QuestMainPanel extends QuestAbstractPanel { petPanel.add(this.petCheckBox); GuiUtils.addGap(petPanel); this.petComboBox.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { + public void actionPerformed(final ActionEvent actionEvent) { if (petCheckBox.isSelected()) { questData.getPetManager().setSelectedPet((String) petComboBox.getSelectedItem()); } else { @@ -355,13 +401,12 @@ public class QuestMainPanel extends QuestAbstractPanel { } } }); - this.petComboBox.setMaximumSize( - new Dimension(Integer.MAX_VALUE, - (int) this.petCheckBox.getPreferredSize().getHeight())); + this.petComboBox.setMaximumSize(new Dimension(Integer.MAX_VALUE, (int) this.petCheckBox.getPreferredSize() + .getHeight())); petPanel.add(this.petComboBox); this.plantBox.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { + public void actionPerformed(final ActionEvent actionEvent) { questData.getPetManager().usePlant = plantBox.isSelected(); } }); @@ -374,7 +419,7 @@ public class QuestMainPanel extends QuestAbstractPanel { fantasyPanel.add(petPanel, BorderLayout.WEST); zeppelinButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { + public void actionPerformed(final ActionEvent actionEvent) { questData.randomizeOpponents(); refreshNextMatchPanel(); QuestItemZeppelin zeppelin = (QuestItemZeppelin) questData.getInventory().getItem("Zeppelin"); @@ -394,9 +439,12 @@ public class QuestMainPanel extends QuestAbstractPanel { } /** - *createDuelPanel.
- * Makes a parent panel, then selectable panel instances for all available duels. - * + *+ * createDuelPanel. + *
+ * Makes a parent panel, then selectable panel instances for all available + * duels. + * * @return a {@link javax.swing.JPanel} object. */ private JPanel createDuelPanel() { @@ -421,20 +469,23 @@ public class QuestMainPanel extends QuestAbstractPanel { } /** - *createChallengePanel.
- * Makes a parent panel, then selectable panel instances for all available challenges. - * + *+ * createChallengePanel. + *
+ * Makes a parent panel, then selectable panel instances for all available + * challenges. + * * @return a {@link javax.swing.JPanel} object. */ private JPanel createChallengePanel() { JPanel ChallengePanel = new JPanel(); - + QuestSelectablePanel selpan; ChallengePanel.setLayout(new BoxLayout(ChallengePanel, BoxLayout.Y_AXIS)); ChallengePanel.setBorder(new TitledBorder(new EtchedBorder(), "Available Challenges")); Listrefresh.
+ *+ * refresh. + *
*/ - void refresh() { + final void refresh() { AllZone.getQuestData().saveData(); devModeCheckBox.setSelected(Constant.Runtime.DevMode[0]); @@ -460,7 +512,7 @@ public class QuestMainPanel extends QuestAbstractPanel { statsLabel.setText(questData.getWin() + " wins / " + questData.getLost() + " losses"); titleLabel.setText(questData.getRank()); - //copy lastUsedDeck as removal triggers selection change. + // copy lastUsedDeck as removal triggers selection change. String lastUsedDeck = QuestMainPanel.lastUsedDeck; deckComboBox.removeAllItems(); @@ -470,7 +522,7 @@ public class QuestMainPanel extends QuestAbstractPanel { ListrefreshNextMatchPanel.
+ *+ * refreshNextMatchPanel. + *
*/ private void refreshNextMatchPanel() { nextMatchPanel.removeAll(); @@ -568,18 +620,22 @@ public class QuestMainPanel extends QuestAbstractPanel { } /** - *nextChallengeInWins.
- * + *+ * nextChallengeInWins. + *
+ * * @return a int. */ 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) { 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 mul = 5; @@ -594,16 +650,17 @@ public class QuestMainPanel extends QuestAbstractPanel { return (delta > 0) ? delta : 0; } - /** - *showDeckEditor.
+ *+ * showDeckEditor. + *
*/ - void showDeckEditor() { + final void showDeckEditor() { Command exit = new Command() { private static final long serialVersionUID = -5110231879431074581L; public void execute() { - //saves all deck data + // saves all deck data AllZone.getQuestData().saveData(); new QuestFrame(); @@ -615,24 +672,28 @@ public class QuestMainPanel extends QuestAbstractPanel { g.show(exit); g.setVisible(true); mainFrame.dispose(); - }//deck editor button + } // deck editor button /** - *showBazaar.
+ *+ * showBazaar. + *
*/ - void showBazaar() { + final void showBazaar() { mainFrame.showBazaarPane(); } /** - *showCardShop.
+ *+ * showCardShop. + *
*/ - void showCardShop() { + final void showCardShop() { Command exit = new Command() { private static final long serialVersionUID = 8567193482568076362L; public void execute() { - //saves all deck data + // saves all deck data AllZone.getQuestData().saveData(); new QuestFrame(); @@ -646,13 +707,16 @@ public class QuestMainPanel extends QuestAbstractPanel { this.mainFrame.dispose(); - }//card shop button + } // card shop button /** - *launchGame.
+ *+ * 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(); QuestItemZeppelin zeppelin = (QuestItemZeppelin) questData.getInventory().getItem("Zeppelin"); @@ -660,9 +724,9 @@ public class QuestMainPanel extends QuestAbstractPanel { questData.randomizeOpponents(); String humanDeckName = (String) deckComboBox.getSelectedItem(); - + Deck humanDeck = questData.getDeck(humanDeckName); - + Constant.Runtime.HumanDeck[0] = humanDeck; moveDeckToTop(humanDeckName); @@ -671,16 +735,16 @@ public class QuestMainPanel extends QuestAbstractPanel { // Dev Mode occurs before Display Constant.Runtime.DevMode[0] = devModeCheckBox.isSelected(); - //DO NOT CHANGE THIS ORDER, GuiDisplay needs to be created before cards are added - //if (newGUICheckbox.isSelected()) { - AllZone.setDisplay(new GuiDisplay4()); - //} else { - // AllZone.setDisplay(new GuiDisplay3()); - //} - + // DO NOT CHANGE THIS ORDER, GuiDisplay needs to be created before cards + // are added + // if (newGUICheckbox.isSelected()) { + AllZone.setDisplay(new GuiDisplay4()); + // } else { + // AllZone.setDisplay(new GuiDisplay3()); + // } Constant.Runtime.Smooth[0] = smoothLandCheckBox.isSelected(); - + AllZone.getMatchState().reset(); if (isShowingChallenges) { setupChallenge(humanDeck); @@ -694,32 +758,35 @@ public class QuestMainPanel extends QuestAbstractPanel { mainFrame.dispose(); } - /** - *setupDuel.
- * - * @param humanDeck a {@link forge.deck.Deck} object. + *+ * setupDuel. + *
+ * + * @param humanDeck + * a {@link forge.deck.Deck} object. */ - void setupDuel(Deck humanDeck) { + final void setupDuel(final Deck humanDeck) { Deck computer = selectedOpponent.getEvent().getEventDeck(); Constant.Runtime.ComputerDeck[0] = computer; - QuestDuel selectedDuel = (QuestDuel)selectedOpponent.getEvent(); + QuestDuel selectedDuel = (QuestDuel) selectedOpponent.getEvent(); AllZone.setQuestEvent(selectedDuel); - AllZone.getGameAction().newGame(humanDeck, computer, - QuestUtil.getHumanStartingCards(questData), - QuestUtil.getComputerStartingCards(questData), - questData.getLife(), 20, null); + AllZone.getGameAction().newGame(humanDeck, computer, QuestUtil.getHumanStartingCards(questData), + QuestUtil.getComputerStartingCards(questData), questData.getLife(), 20, null); } /** - *setupChallenge.
- * - * @param humanDeck a {@link forge.deck.Deck} object. + *+ * setupChallenge. + *
+ * + * @param humanDeck + * a {@link forge.deck.Deck} object. */ - private void setupChallenge(Deck humanDeck) { - QuestChallenge selectedChallenge = (QuestChallenge)selectedOpponent.getEvent(); + private void setupChallenge(final Deck humanDeck) { + QuestChallenge selectedChallenge = (QuestChallenge) selectedOpponent.getEvent(); Deck computer = selectedOpponent.getEvent().getEventDeck(); Constant.Runtime.ComputerDeck[0] = computer; @@ -733,15 +800,17 @@ public class QuestMainPanel extends QuestAbstractPanel { } AllZone.getGameAction().newGame(humanDeck, computer, - QuestUtil.getHumanStartingCards(questData, selectedChallenge), - QuestUtil.getComputerStartingCards(questData, selectedChallenge), - questData.getLife() + extraLife, selectedChallenge.getAILife(), selectedChallenge); + QuestUtil.getHumanStartingCards(questData, selectedChallenge), + QuestUtil.getComputerStartingCards(questData, selectedChallenge), questData.getLife() + extraLife, + selectedChallenge.getAILife(), selectedChallenge); } /** - *getEventIconFilename.
- * + *+ * getEventIconFilename. + *
+ * * @return a {@link java.lang.String} object. */ private String getEventIconFilename() { @@ -749,9 +818,11 @@ public class QuestMainPanel extends QuestAbstractPanel { } /** - *showChallenges.
+ *+ * showChallenges. + *
*/ - void showChallenges() { + final void showChallenges() { if (isShowingChallenges) { isShowingChallenges = false; eventButton.setText("Challenges"); @@ -769,16 +840,33 @@ public class QuestMainPanel extends QuestAbstractPanel { refresh(); } + /** + * The Class SelectionAdapter. + */ class SelectionAdapter extends MouseAdapter { + + /** The selectable panel. */ QuestSelectablePanel selectablePanel; - SelectionAdapter(QuestSelectablePanel selectablePanel) { + /** + * Instantiates a new selection adapter. + * + * @param selectablePanel + * the selectable panel + */ + SelectionAdapter(final QuestSelectablePanel selectablePanel) { super(); this.selectablePanel = selectablePanel; } + /* + * (non-Javadoc) + * + * @see + * java.awt.event.MouseAdapter#mouseClicked(java.awt.event.MouseEvent) + */ @Override - public void mouseClicked(MouseEvent mouseEvent) { + public void mouseClicked(final MouseEvent mouseEvent) { if (selectedOpponent != null) { selectedOpponent.setSelected(false); @@ -793,27 +881,31 @@ public class QuestMainPanel extends QuestAbstractPanel { } /** - *moveDeckToTop.
- * - * @param humanDeckName a {@link java.lang.String} object. + *+ * moveDeckToTop. + *
+ * + * @param humanDeckName + * a {@link java.lang.String} object. */ - private void moveDeckToTop(String humanDeckName) { + private void moveDeckToTop(final String humanDeckName) { QuestMainPanel.lastUsedDeck = humanDeckName; } - /** - *canGameBeLaunched.
- * + *+ * canGameBeLaunched. + *
+ * * @return a boolean. */ - boolean canGameBeLaunched() { + final boolean canGameBeLaunched() { return !(NO_DECKS_AVAILABLE.equals(deckComboBox.getSelectedItem()) || selectedOpponent == null); } /** {@inheritDoc} */ @Override - public void refreshState() { + public final void refreshState() { this.refresh(); } diff --git a/src/main/java/forge/quest/gui/QuestOptions.java b/src/main/java/forge/quest/gui/QuestOptions.java index 5da2c14af70..0f4d263068f 100644 --- a/src/main/java/forge/quest/gui/QuestOptions.java +++ b/src/main/java/forge/quest/gui/QuestOptions.java @@ -1,5 +1,26 @@ 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.error.ErrorViewer; import forge.gui.GuiUtils; @@ -9,22 +30,16 @@ import forge.quest.data.QuestPreferences; import forge.view.swing.Gui_HomeScreen; 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; - /** - *Gui_QuestOptions class.
- * + *+ * Gui_QuestOptions class. + *
+ * * @author Forge * @version $Id$ */ public class QuestOptions extends JFrame { - /** ConstantserialVersionUID=2018518804206822235L */
+ /** Constant serialVersionUID=2018518804206822235L. */
private static final long serialVersionUID = 2018518804206822235L;
private QuestData questData = new QuestData();
@@ -52,7 +67,9 @@ public class QuestOptions extends JFrame {
private JPanel jPanel3 = new JPanel();
/**
- * Constructor for Gui_QuestOptions.
+ *+ * Constructor for Gui_QuestOptions. + *
*/ public QuestOptions() { try { @@ -70,19 +87,20 @@ public class QuestOptions extends JFrame { } /** - *setup.
+ *+ * setup. + *
*/ private void setup() { - //make the text look correct on the screen + // make the text look correct on the screen 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() { @Override - public void windowClosing(WindowEvent ev) { + public void windowClosing(final WindowEvent ev) { QuestOptions.this.dispose(); - + if (System.getenv("NG2") != null) { if (System.getenv("NG2").equalsIgnoreCase("true")) { String argz[] = {}; @@ -97,37 +115,43 @@ public class QuestOptions extends JFrame { } }); - //is there any saved data? - if (!questData.hasSaveFile()) continueQuestButton.setEnabled(false); - } //setup() + // is there any saved data? + if (!questData.hasSaveFile()) { + continueQuestButton.setEnabled(false); + } + } // setup() - //show total number of games for each difficulty + // show total number of games for each difficulty /** - *setupRadioButtonText.
+ *+ * setupRadioButtonText. + *
*/ private void setupRadioButtonText() { String[] diff = QuestPreferences.getDifficulty(); JRadioButton[] b = {easyRadio, mediumRadio, hardRadio, veryHardRadio}; 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 numGames = numberLevels * QuestPreferences.getWinsForRankIncrease(i); b[i].setText(String.format("%s - %d", diff[i], numGames)); } - }//setupRadioButtonText() + } // setupRadioButtonText() /** - *jbInit.
- * - * @throws java.lang.Exception if any. + *+ * jbInit. + *
+ * + * @throws java.lang.Exception + * if any. */ private void jbInit() throws Exception { - TitledBorder titledBorder1 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white, - new Color(148, 145, 140)), - "Quest Length"); + TitledBorder titledBorder1 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white, new Color(148, 145, + 140)), "Quest Length"); Border border2 = BorderFactory.createEtchedBorder(Color.white, new Color(148, 145, 140)); TitledBorder titledBorder2 = new TitledBorder(border2, "Continue"); 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.setText("Continue Quest"); continueQuestButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(ActionEvent e) { + public void actionPerformed(final ActionEvent e) { continueQuestButton_actionPerformed(e); } }); @@ -170,7 +194,7 @@ public class QuestOptions extends JFrame { newQuestButton.setFont(new java.awt.Font("Dialog", 0, 16)); newQuestButton.setText("New Quest"); newQuestButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(ActionEvent e) { + public void actionPerformed(final ActionEvent e) { newQuestButton_actionPerformed(e); } }); @@ -188,7 +212,7 @@ public class QuestOptions extends JFrame { jTextArea1.setFont(new java.awt.Font("Dialog", 0, 12)); jTextArea1.setDisabledTextColor(Color.black); 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.setLineWrap(true); jTextArea1.setWrapStyleWord(true); @@ -203,7 +227,7 @@ public class QuestOptions extends JFrame { jPanel2.add(mediumRadio, null); jPanel2.add(fantasyRadio, 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(cbStandardStart, null); @@ -225,12 +249,15 @@ public class QuestOptions extends JFrame { } /** - *continueQuestButton_actionPerformed.
- * - * @param e a {@link java.awt.event.ActionEvent} object. + *+ * continueQuestButton_actionPerformed. + *
+ * + * @param e + * a {@link java.awt.event.ActionEvent} object. */ - void continueQuestButton_actionPerformed(ActionEvent e) { - //set global variable + final void continueQuestButton_actionPerformed(final ActionEvent e) { + // set global variable AllZone.setQuestData(QuestDataIO.loadData()); AllZone.getQuestData().guessDifficultyIndex(); dispose(); @@ -240,49 +267,54 @@ public class QuestOptions extends JFrame { } /** - *newQuestButton_actionPerformed.
- * - * @param e a {@link java.awt.event.ActionEvent} object. + *+ * newQuestButton_actionPerformed. + *
+ * + * @param e + * a {@link java.awt.event.ActionEvent} object. */ - void newQuestButton_actionPerformed(ActionEvent e) { + final void newQuestButton_actionPerformed(final ActionEvent e) { 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; - - else if (mediumRadio.isSelected()) difficulty = 1; - - else if (hardRadio.isSelected()) difficulty = 2; - - else if (veryHardRadio.isSelected()) difficulty = 3; - - else //user didn't select a difficulty{ + if (easyRadio.isSelected()) { + difficulty = 0; + } else if (mediumRadio.isSelected()) { + difficulty = 1; + } else if (hardRadio.isSelected()) { + difficulty = 2; + } else if (veryHardRadio.isSelected()) { + difficulty = 3; + } else { + // user didn't select a difficulty{ return; + } if (questData.hasSaveFile()) { // this will overwrite your save file! Object[] possibleValues = {"Yes", "No"}; - Object choice = JOptionPane.showOptionDialog(null, "Starting a new quest will overwrite your current quest. Continue?", - "Start New Quest?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, - null, possibleValues, possibleValues[1]); + Object choice = JOptionPane.showOptionDialog(null, + "Starting a new quest will overwrite your current quest. Continue?", "Start New Quest?", + JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, possibleValues, possibleValues[1]); - if (!choice.equals(0)) + if (!choice.equals(0)) { 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.saveData(); - - //set global variable + // set global variable AllZone.setQuestData(questData); dispose(); new QuestFrame(); } - } diff --git a/src/main/java/forge/quest/gui/QuestWinLoseCardViewer.java b/src/main/java/forge/quest/gui/QuestWinLoseCardViewer.java index 30c44a49301..51fea9f74d2 100644 --- a/src/main/java/forge/quest/gui/QuestWinLoseCardViewer.java +++ b/src/main/java/forge/quest/gui/QuestWinLoseCardViewer.java @@ -1,7 +1,13 @@ 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.ListSelectionListener; @@ -12,28 +18,30 @@ import forge.gui.game.CardDetailPanel; import forge.gui.game.CardPicturePanel; 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 * @version $Id: ListChooser.java 9708 2011-08-09 19:34:12Z jendave $ */ @SuppressWarnings("serial") public class QuestWinLoseCardViewer extends JPanel { - //Data and number of choices for the list + // Data and number of choices for the list private ListQuestWinLoseHandler.
- * Processes win/lose presentation for Quest events. This presentation - * is displayed by WinLoseFrame. Components to be added to pnlCustom in +// TODO: Auto-generated Javadoc +/** + *+ * QuestWinLoseHandler. + *
+ * Processes win/lose presentation for Quest events. This presentation is + * displayed by WinLoseFrame. Components to be added to pnlCustom in * WinLoseFrame should use MigLayout. - * + * */ public class QuestWinLoseHandler extends WinLoseModeHandler { private boolean wonMatch; private ImageIcon icoTemp; private JLabel lblTemp1; private JLabel lblTemp2; + + /** The spacer. */ int spacer = 50; - - private class CommonObjects { + + private class CommonObjects { public QuestMatchState qMatchState; public QuestData qData; public QuestEvent qEvent; } private CommonObjects model; - + + /** + * Instantiates a new quest win lose handler. + */ public QuestWinLoseHandler() { - super(); + super(); model = new CommonObjects(); model.qMatchState = AllZone.getMatchState(); model.qData = AllZone.getQuestData(); model.qEvent = AllZone.getQuestEvent(); wonMatch = model.qMatchState.isMatchWonBy(AllZone.getHumanPlayer().getName()); } - + /** - *startNextRound.
+ *+ * startNextRound. + *
* Either continues or restarts a current game. - * - * @param e a {@link java.awt.event.ActionEvent} object. + * */ @Override - public void startNextRound() { + public final void startNextRound() { if (Constant.Quest.fantasyQuest[0]) { int extraLife = 0; - + if (model.qEvent.getEventType().equals("challenge")) { if (model.qData.getInventory().hasItem("Zeppelin")) { extraLife = 3; @@ -85,97 +93,102 @@ public class QuestWinLoseHandler extends WinLoseModeHandler { CardList humanList = QuestUtil.getHumanStartingCards(model.qData, model.qEvent); CardList computerList = QuestUtil.getComputerStartingCards(model.qData, model.qEvent); - + int humanLife = model.qData.getLife() + extraLife; int computerLife = 20; 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], - humanList, computerList, humanLife, computerLife, model.qEvent); - } else { + AllZone.getGameAction().newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0], humanList, + computerList, humanLife, computerLife, model.qEvent); + } else { super.startNextRound(); } } - + /** - *populateCustomPanel.
- * Checks conditions of win and fires various reward display methods accordingly. - * - * @param boolean indicating if custom panel has contents. + *+ * populateCustomPanel. + *
+ * Checks conditions of win and fires various reward display methods + * accordingly. + * + * @return true, if successful */ @Override - public boolean populateCustomPanel() { + public final boolean populateCustomPanel() { view.btnRestart.setVisible(false); model.qData.getCards().resetNewList(); - - if(!model.qMatchState.isMatchOver()) { + + if (!model.qMatchState.isMatchOver()) { view.btnQuit.setText("Quit (15 Credits)"); return false; - } - else { + } else { view.btnContinue.setVisible(false); - if(wonMatch) { + if (wonMatch) { view.btnQuit.setText("Great!"); - } - else { + } else { view.btnQuit.setText("OK"); } } - + // Win case - if(wonMatch) { + if (wonMatch) { // Standard event reward credits awardEventCredits(); - + // Challenge reward credits - if(model.qEvent.getEventType().equals("challenge")) { + if (model.qEvent.getEventType().equals("challenge")) { awardChallengeWin(); } - + // Random rare given at 50% chance (65% with luck upgrade) - if (getLuckyCoinResult()) { + if (getLuckyCoinResult()) { awardRandomRare("You've won a random rare."); } - + // 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."); } - + // Award jackpot every 80 games won (currently 10 rares) int wins = model.qData.getWin(); - if (wins > 0 && wins % 80 == 0) { - awardJackpot(); + if (wins > 0 && wins % 80 == 0) { + awardJackpot(); } } // Lose case else { 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(); if (outcome % QuestPreferences.getWinsForBooster(model.qData.getDifficultyIndex()) == 0) { - awardBooster(); + awardBooster(); } return true; } - + /** - *actionOnQuit.
- * When "quit" button is pressed, this method adjusts quest data as appropriate and saves. - * + *+ * actionOnQuit. + *
+ * When "quit" button is pressed, this method adjusts quest data as + * appropriate and saves. + * */ @Override - public void actionOnQuit() { + public final void actionOnQuit() { // Record win/loss in quest data if (wonMatch) { model.qData.addWin(); } else { - model.qData.addLost(); + model.qData.addLost(); model.qData.subtractCredits(15); } @@ -192,16 +205,18 @@ public class QuestWinLoseHandler extends WinLoseModeHandler { new QuestFrame(); } - + /** - *awardEventCredits.
+ *+ * awardEventCredits. + *
* 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 StringBuilder sb = new StringBuilder(""); - + int credTotal = 0; int credBase = 0; int credGameplay = 0; @@ -211,84 +226,83 @@ public class QuestWinLoseHandler extends WinLoseModeHandler { // Basic win bonus int base = QuestPreferences.getMatchRewardBase(); double multiplier = 1; - + String diff = AllZone.getQuestEvent().getDifficulty(); diff = diff.substring(0, 1).toUpperCase() + diff.substring(1); - - if(diff.equalsIgnoreCase("medium")) { + + if (diff.equalsIgnoreCase("medium")) { multiplier = 1.5; - } - else if(diff.equalsIgnoreCase("hard")) { + } else if (diff.equalsIgnoreCase("hard")) { multiplier = 2; - } - else if(diff.equalsIgnoreCase("very hard")) { + } else if (diff.equalsIgnoreCase("very hard")) { multiplier = 2.5; - } - else if(diff.equalsIgnoreCase("expert")) { + } else if (diff.equalsIgnoreCase("expert")) { 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.