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 { - /** Constant serialVersionUID=-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 { - /** Constant serialVersionUID=-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. */ Map subPanelMap = new HashMap(); /** - *

Constructor 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 { - /** Constant serialVersionUID=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("Launch
Zeppelin", - GuiUtils.getResizedIcon(GuiUtils.getIconFromFile("ZeppelinIcon.png"), 40, 40)); + private JButton zeppelinButton = new JButton("Launch
Zeppelin", GuiUtils.getResizedIcon( + GuiUtils.getIconFromFile("ZeppelinIcon.png"), 40, 40)); private JPanel zeppelinPanel = new JPanel(); /** - *

Constructor 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(); List eastComponents = new ArrayList(); - //Create buttons + // Create buttons JButton mainMenuButton = new JButton("Return to Main Menu"); mainMenuButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { + public void actionPerformed(final ActionEvent actionEvent) { mainFrame.returnToMainMenu(); } }); @@ -182,7 +228,7 @@ public class QuestMainPanel extends QuestAbstractPanel { JButton cardShopButton = new JButton("Card Shop"); cardShopButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { + public void actionPerformed(final ActionEvent actionEvent) { QuestMainPanel.this.showCardShop(); } }); @@ -194,7 +240,7 @@ public class QuestMainPanel extends QuestAbstractPanel { bazaarButton = new JButton("Bazaar"); bazaarButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { + public void actionPerformed(final ActionEvent actionEvent) { QuestMainPanel.this.showBazaar(); } }); @@ -202,9 +248,8 @@ public class QuestMainPanel extends QuestAbstractPanel { bazaarButton.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 20)); } - eventButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { + public void actionPerformed(final ActionEvent actionEvent) { QuestMainPanel.this.showChallenges(); } }); @@ -212,9 +257,8 @@ public class QuestMainPanel extends QuestAbstractPanel { eventButton.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 18)); eventButton.setPreferredSize(new Dimension(0, 60)); - playButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { + public void actionPerformed(final ActionEvent actionEvent) { QuestMainPanel.this.launchGame(); } }); @@ -222,7 +266,6 @@ public class QuestMainPanel extends QuestAbstractPanel { playButton.setFont(new Font(Font.DIALOG, Font.BOLD, 28)); playButton.setPreferredSize(new Dimension(0, 100)); - eastComponents.add(playButton); eastComponents.add(optionsPanel); @@ -266,8 +309,10 @@ public class QuestMainPanel extends QuestAbstractPanel { } /** - *

createOptionsPanel.

- * + *

+ * 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")); List challenges = qem.generateChallenges(); - + for (QuestChallenge qc : challenges) { selpan = new QuestChallengePanel(qc); ChallengePanel.add(selpan); @@ -443,14 +494,15 @@ public class QuestMainPanel extends QuestAbstractPanel { GuiUtils.addGap(ChallengePanel, 3); } - return ChallengePanel; } /** - *

refresh.

+ *

+ * 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 { List deckNames = new ArrayList(questData.getDeckNames()); Collections.sort(deckNames, new Comparator() { - public int compare(String s, String s1) { + public int compare(final String s, final String s1) { return s.compareToIgnoreCase(s1); } }); @@ -520,7 +572,6 @@ public class QuestMainPanel extends QuestAbstractPanel { petComboBox.setSelectedItem(questData.getPetManager().getSelectedPet().getName()); } - this.plantBox.setEnabled(questData.getPetManager().getPlant().getLevel() > 0); this.plantBox.setSelected(questData.getPetManager().shouldPlantBeUsed()); @@ -537,7 +588,6 @@ public class QuestMainPanel extends QuestAbstractPanel { zeppelinButton.setEnabled(false); } - } if (nextChallengeInWins() > 0) { @@ -552,7 +602,9 @@ public class QuestMainPanel extends QuestAbstractPanel { } /** - *

refreshNextMatchPanel.

+ *

+ * 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 { - /** Constant serialVersionUID=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 List list; - //initialized before; listeners may be added to it + // initialized before; listeners may be added to it private JList jList; private CardDetailPanel detail; private CardPicturePanel picture; - - public QuestWinLoseCardViewer(List list) { + + /** + * Instantiates a new quest win lose card viewer. + * + * @param list + * the list + */ + public QuestWinLoseCardViewer(final List list) { this.list = unmodifiableList(list); jList = new JList(new ChooserListModel()); detail = new CardDetailPanel(null); @@ -42,7 +50,7 @@ public class QuestWinLoseCardViewer extends JPanel { this.add(new JScrollPane(jList)); this.add(picture); 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 jList.getSelectionModel().addListSelectionListener(new SelListener()); @@ -53,14 +61,18 @@ public class QuestWinLoseCardViewer extends JPanel { private static final long serialVersionUID = 3871965346333840556L; - public int getSize() { return list.size(); } - public Object getElementAt(int index) { return list.get(index); } - } + public int getSize() { + return list.size(); + } + public Object getElementAt(final int index) { + return list.get(index); + } + } private class SelListener implements ListSelectionListener { private Card[] cache = null; - + public void valueChanged(final ListSelectionEvent e) { int row = jList.getSelectedIndex(); // (String) jList.getSelectedValue(); @@ -71,15 +83,17 @@ public class QuestWinLoseCardViewer extends JPanel { picture.setCard(cp); } } - - private void ensureCacheHas(int row, CardPrinted cp) { - if (cache == null) { cache = new Card[list.size()]; } + + private void ensureCacheHas(final int row, final CardPrinted cp) { + if (cache == null) { + cache = new Card[list.size()]; + } if (null == cache[row]) { Card card = AllZone.getCardFactory().getCard(cp.getName(), null); card.setCurSetCode(cp.getSet()); card.setImageFilename(CardUtil.buildFilename(card)); cache[row] = card; - } + } } } diff --git a/src/main/java/forge/quest/gui/QuestWinLoseHandler.java b/src/main/java/forge/quest/gui/QuestWinLoseHandler.java index 107f157b375..557ba9db811 100644 --- a/src/main/java/forge/quest/gui/QuestWinLoseHandler.java +++ b/src/main/java/forge/quest/gui/QuestWinLoseHandler.java @@ -12,7 +12,6 @@ import javax.swing.JLabel; import javax.swing.SwingConstants; import net.slightlymagic.maxmtg.Predicate; - import forge.AllZone; import forge.CardList; import forge.Constant; @@ -31,52 +30,61 @@ import forge.quest.data.QuestData; import forge.quest.data.QuestMatchState; import forge.quest.data.QuestPreferences; 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.QuestEvent; import forge.view.swing.WinLoseModeHandler; -/**

QuestWinLoseHandler.

- * 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.
"); - // Gameplay bonuses (for each game win) boolean hasNeverLost = true; - Player computer = AllZone.getComputerPlayer(); for (GameSummary game : model.qMatchState.getGamesPlayed()) { - if (game.isWinner(computer.getName())) { hasNeverLost = false; continue; // no rewards for losing a game } - // Alternate win GamePlayerRating aiRating = game.getPlayerRating(computer.getName()); GamePlayerRating humanRating = game.getPlayerRating(AllZone.getHumanPlayer().getName()); GameLossReason whyAiLost = aiRating.getLossReason(); int altReward = getCreditsRewardForAltWin(whyAiLost); - + if (altReward > 0) { String winConditionName = "Unknown (bug)"; if (game.getWinCondition() == GameEndReason.WinsGameSpellEffect) { winConditionName = game.getWinSpellEffect(); } else { - switch(whyAiLost) { - case Poisoned: winConditionName = "Poison"; break; - case Milled: winConditionName = "Milled"; break; - case SpellEffect: winConditionName = aiRating.getLossSpellName(); break; - default: break; + switch (whyAiLost) { + case Poisoned: + winConditionName = "Poison"; + break; + case Milled: + winConditionName = "Milled"; + break; + case SpellEffect: + winConditionName = aiRating.getLossSpellName(); + break; + default: + break; } } credGameplay += 50; - sb.append(String.format("Alternate win condition: %s! " + - "Bonus: %d credits.
", + sb.append(String.format("Alternate win condition: %s! " + "Bonus: %d credits.
", winConditionName, 50)); } - // Mulligan to zero int cntCardsHumanStartedWith = humanRating.getOpeningHandSize(); int mulliganReward = QuestPreferences.getMatchMullToZero(); - + if (0 == cntCardsHumanStartedWith) { credGameplay += mulliganReward; - sb.append(String.format("Mulliganed to zero and still won! " + - "Bonus: %d credits.
", mulliganReward)); + sb.append(String + .format("Mulliganed to zero and still won! " + "Bonus: %d credits.
", mulliganReward)); } - + // Early turn bonus int winTurn = game.getTurnGameEnded(); int turnCredits = getCreditsRewardForWinByTurn(winTurn); - if (winTurn == 0) { System.err.println("QuestWinLoseHandler > " + - "turn calculation error: Zero turn win"); - } else if (winTurn == 1) { sb.append("Won in one turn!"); - } else if (winTurn <= 5) { 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 (winTurn == 0) { + System.err.println("QuestWinLoseHandler > " + "turn calculation error: Zero turn win"); + } else if (winTurn == 1) { + sb.append("Won in one turn!"); + } else if (winTurn <= 5) { + 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) { @@ -296,46 +310,46 @@ public class QuestWinLoseHandler extends WinLoseModeHandler { sb.append(String.format(" Bonus: %d credits.
", turnCredits)); } } // End for(game) - + // Undefeated bonus if (hasNeverLost) { credUndefeated += QuestPreferences.getMatchRewardNoLosses(); int reward = QuestPreferences.getMatchRewardNoLosses(); - sb.append(String.format("You have not lost once! " + - "Bonus: %d credits.
", reward)); + sb.append(String.format("You have not lost once! " + "Bonus: %d credits.
", reward)); } - + // Estates bonus credTotal = credBase + credGameplay + credUndefeated; - switch(model.qData.getInventory().getItemLevel("Estates")) { - case 1: - credEstates = (int)0.1*credTotal; - sb.append("Estates bonus: 10%.
"); - break; - - case 2: - credEstates = (int)0.15*credTotal; - sb.append("Estates bonus: 15%.
"); - break; - - case 3: - credEstates = (int)0.2*credTotal; - sb.append("Estates bonus: 20%.
"); - break; - - default: break; + switch (model.qData.getInventory().getItemLevel("Estates")) { + case 1: + credEstates = (int) 0.1 * credTotal; + sb.append("Estates bonus: 10%.
"); + break; + + case 2: + credEstates = (int) 0.15 * credTotal; + sb.append("Estates bonus: 15%.
"); + break; + + case 3: + credEstates = (int) 0.2 * credTotal; + sb.append("Estates bonus: 20%.
"); + break; + + default: + break; } credTotal += credEstates; - + // Final output String congrats = "

"; - if(credTotal < 100) { + if (credTotal < 100) { congrats += "You've earned"; - } else if(credTotal < 250) { + } else if (credTotal < 250) { congrats += "Could be worse: "; - } else if(credTotal < 500) { + } else if (credTotal < 500) { congrats += "A respectable"; - } else if(credTotal < 750) { + } else if (credTotal < 750) { congrats += "An impressive"; } else { congrats += "Spectacular match!"; @@ -344,148 +358,154 @@ public class QuestWinLoseHandler extends WinLoseModeHandler { sb.append(String.format("%s %d credits in total.

", congrats, credTotal)); sb.append(""); model.qData.addCredits(credTotal); - + // Generate Swing components and attach. - icoTemp = GuiUtils.getResizedIcon("GoldIcon.png",0.5); - + icoTemp = GuiUtils.getResizedIcon("GoldIcon.png", 0.5); + lblTemp1 = new TitleLabel("Gameplay Results"); - + lblTemp2 = new JLabel(sb.toString()); 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.setIcon(icoTemp); lblTemp2.setIconTextGap(50); - - view.pnlCustom.add(lblTemp1,"align center, width 95%!"); - view.pnlCustom.add(lblTemp2,"align center, width 95%!, gaptop 10"); + view.pnlCustom.add(lblTemp1, "align center, width 95%!"); + view.pnlCustom.add(lblTemp2, "align center, width 95%!, gaptop 10"); } - + /** - *

awardRandomRare.

+ *

+ * awardRandomRare. + *

* 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(); List cardsWon = new ArrayList(); cardsWon.add(c); - + // Generate Swing components and attach. lblTemp1 = new TitleLabel(message); QuestWinLoseCardViewer cv = new QuestWinLoseCardViewer(cardsWon); - - view.pnlCustom.add(lblTemp1,"align center, width 95%!, " + - "gaptop " + spacer + ", gapbottom 10"); - view.pnlCustom.add(cv,"align center, width 95%!"); + + view.pnlCustom.add(lblTemp1, "align center, width 95%!, " + "gaptop " + spacer + ", gapbottom 10"); + view.pnlCustom.add(cv, "align center, width 95%!"); } - + /** - *

awardJackpot.

+ *

+ * awardJackpot. + *

* Generates and displays jackpot win case. - * + * */ - private void awardJackpot() { + private void awardJackpot() { List 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!"); QuestWinLoseCardViewer cv = new QuestWinLoseCardViewer(cardsWon); - - view.pnlCustom.add(lblTemp1,"align center, width 95%!, " + - "gaptop " + spacer + ", gapbottom 10"); - view.pnlCustom.add(cv,"align center, width 95%!"); + + view.pnlCustom.add(lblTemp1, "align center, width 95%!, " + "gaptop " + spacer + ", gapbottom 10"); + view.pnlCustom.add(cv, "align center, width 95%!"); } - + /** - *

awardBooster.

+ *

+ * awardBooster. + *

* Generates and displays booster pack win case. - * + * */ private void awardBooster() { - ListChooser ch = new ListChooser("Choose bonus booster format", 1, SetUtils.getFormats()); + ListChooser ch = new ListChooser("Choose bonus booster format", 1, + SetUtils.getFormats()); ch.show(); GameFormat selected = ch.getSelectedValue(); - - List 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!"); + + List 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!"); QuestWinLoseCardViewer cv = new QuestWinLoseCardViewer(cardsWon); - - view.pnlCustom.add(lblTemp1,"align center, width 95%!, " + - "gaptop " + spacer + ", gapbottom 10"); - view.pnlCustom.add(cv,"align center, width 95%!"); + + view.pnlCustom.add(lblTemp1, "align center, width 95%!, " + "gaptop " + spacer + ", gapbottom 10"); + view.pnlCustom.add(cv, "align center, width 95%!"); } - + /** - *

awardChallengeWin.

+ *

+ * awardChallengeWin. + *

* Generates and displays win case for challenge event. - * + * */ - private void awardChallengeWin() { - if(!((QuestChallenge)model.qEvent).getRepeatable()) { - model.qData.addCompletedChallenge(((QuestChallenge)model.qEvent).getId()); + private void awardChallengeWin() { + if (!((QuestChallenge) model.qEvent).getRepeatable()) { + model.qData.addCompletedChallenge(((QuestChallenge) model.qEvent).getId()); } - + // 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(); - List cardsWon = ((QuestChallenge)model.qEvent).getCardRewardList(); - long questRewardCredits = ((QuestChallenge)model.qEvent).getCreditsReward(); + List cardsWon = ((QuestChallenge) model.qEvent).getCardRewardList(); + long questRewardCredits = ((QuestChallenge) model.qEvent).getCreditsReward(); StringBuilder sb = new StringBuilder(); sb.append("Challenge completed.

"); sb.append("Challenge bounty: " + questRewardCredits + " credits."); model.qData.addCredits(questRewardCredits); - + // Generate Swing components and attach. - icoTemp = GuiUtils.getResizedIcon("BoxIcon.png",0.5); - lblTemp1 = new TitleLabel("Challenge Rewards for \"" + - ((QuestChallenge)model.qEvent).getTitle() + "\""); - + icoTemp = GuiUtils.getResizedIcon("BoxIcon.png", 0.5); + lblTemp1 = new TitleLabel("Challenge Rewards for \"" + ((QuestChallenge) model.qEvent).getTitle() + "\""); + 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.setHorizontalAlignment(SwingConstants.CENTER); lblTemp2.setIconTextGap(50); lblTemp2.setIcon(icoTemp); - view.pnlCustom.add(lblTemp1,"align center, width 95%!, " + - "gaptop " + spacer); - view.pnlCustom.add(lblTemp2,"align center, width 95%!, height 80!, gapbottom 10"); - + view.pnlCustom.add(lblTemp1, "align center, width 95%!, " + "gaptop " + spacer); + view.pnlCustom.add(lblTemp2, "align center, width 95%!, height 80!, gapbottom 10"); + if (cardsWon != null) { 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); } - } - - private void penalizeLoss() { - icoTemp = GuiUtils.getResizedIcon("HeartIcon.png",0.5); - + } + + private void penalizeLoss() { + icoTemp = GuiUtils.getResizedIcon("HeartIcon.png", 0.5); + lblTemp1 = new TitleLabel("Gameplay Results"); - + 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.setHorizontalAlignment(SwingConstants.CENTER); lblTemp2.setIconTextGap(50); lblTemp2.setIcon(icoTemp); - view.pnlCustom.add(lblTemp1,"align center, width 95%!"); - view.pnlCustom.add(lblTemp2,"align center, width 95%!, height 80!"); + view.pnlCustom.add(lblTemp1, "align center, width 95%!"); + view.pnlCustom.add(lblTemp2, "align center, width 95%!, height 80!"); } - + /** - *

getLuckyCoinResult.

+ *

+ * getLuckyCoinResult. + *

* A chance check, for rewards like random rares. - * + * * @return boolean */ private boolean getLuckyCoinResult() { @@ -493,65 +513,77 @@ public class QuestWinLoseHandler extends WinLoseModeHandler { return MyRandom.random.nextFloat() <= (hasCoin ? 0.65f : 0.5f); } - + /** - *

getCreditsRewardForAltWin.

+ *

+ * getCreditsRewardForAltWin. + *

* Retrieves credits for win under special conditions. - * - * @param GameLossReason why AI lost + * + * @param GameLossReason + * why AI lost * @return int */ private int getCreditsRewardForAltWin(final GameLossReason whyAiLost) { switch (whyAiLost) { - case LifeReachedZero: return 0; // nothing special here, ordinary kill - case Milled: return QuestPreferences.getMatchRewardMilledWinBonus(); - case Poisoned: return QuestPreferences.getMatchRewardPoisonWinBonus(); - case DidNotLoseYet: return QuestPreferences.getMatchRewardAltWinBonus(); // Felidar, Helix Pinnacle, etc. - case SpellEffect: return QuestPreferences.getMatchRewardAltWinBonus(); // Door to Nothingness, etc. - default: return 0; + case LifeReachedZero: + return 0; // nothing special here, ordinary kill + case Milled: + return QuestPreferences.getMatchRewardMilledWinBonus(); + case Poisoned: + return QuestPreferences.getMatchRewardPoisonWinBonus(); + case DidNotLoseYet: + return QuestPreferences.getMatchRewardAltWinBonus(); // Felidar, + // Helix + // Pinnacle, + // etc. + case SpellEffect: + return QuestPreferences.getMatchRewardAltWinBonus(); // Door to + // Nothingness, + // etc. + default: + return 0; } } /** - *

getCreditsRewardForWinByTurn.

+ *

+ * getCreditsRewardForWinByTurn. + *

* Retrieves credits for win on or under turn count. - * + * * @param int turn count * @return int credits won */ private int getCreditsRewardForWinByTurn(final int iTurn) { int credits = 0; - - if (iTurn == 1) { + + if (iTurn == 1) { credits = QuestPreferences.getMatchRewardWinFirst(); - } - else if (iTurn <= 5) { + } else if (iTurn <= 5) { credits = QuestPreferences.getMatchRewardWinByFifth(); - } - else if (iTurn <= 10) { + } else if (iTurn <= 10) { credits = QuestPreferences.getMatchRewardWinByTen(); - } - else if (iTurn <= 15) { + } else if (iTurn <= 15) { credits = QuestPreferences.getMatchRewardWinByFifteen(); } - + return credits; } - + /** - * JLabel header between reward sections. - * + * JLabel header between reward sections. + * */ @SuppressWarnings("serial") private class TitleLabel extends JLabel { - TitleLabel(String msg) { + TitleLabel(final String msg) { super(msg); - this.setFont(AllZone.getSkin().font2.deriveFont(Font.ITALIC,16)); - this.setPreferredSize(new Dimension(200,40)); + this.setFont(AllZone.getSkin().font2.deriveFont(Font.ITALIC, 16)); + this.setPreferredSize(new Dimension(200, 40)); this.setHorizontalAlignment(SwingConstants.CENTER); this.setForeground(Color.white); this.setBorder(BorderFactory.createMatteBorder(1, 0, 1, 0, Color.white)); } } - -} \ No newline at end of file +} diff --git a/src/main/java/forge/quest/gui/package-info.java b/src/main/java/forge/quest/gui/package-info.java index 4203d463e9d..6c04b7df520 100644 --- a/src/main/java/forge/quest/gui/package-info.java +++ b/src/main/java/forge/quest/gui/package-info.java @@ -1,2 +1,2 @@ -/** Forge Card Game */ +/** Forge Card Game. */ package forge.quest.gui;