checkstyle

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

View File

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

View File

@@ -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;
/**
* <p>QuestFrame class.</p>
*
* <p>
* QuestFrame class.
* </p>
*
* @author Forge
* @version $Id$
*/
public class QuestFrame extends JFrame {
/** Constant <code>serialVersionUID=-2832625381531838412L</code> */
/** Constant <code>serialVersionUID=-2832625381531838412L</code>. */
private static final long serialVersionUID = -2832625381531838412L;
/** The visible panel. */
JPanel visiblePanel;
/** The quest layout. */
CardLayout questLayout;
/** Constant <code>MAIN_PANEL="Main"</code> */
/** Constant <code>MAIN_PANEL="Main"</code>. */
public static final String MAIN_PANEL = "Main";
/** Constant <code>BAZAAR_PANEL="Bazaar"</code> */
/** Constant <code>BAZAAR_PANEL="Bazaar"</code>. */
public static final String BAZAAR_PANEL = "Bazaar";
/** The sub panel map. */
Map<String, QuestAbstractPanel> subPanelMap = new HashMap<String, QuestAbstractPanel>();
/**
* <p>Constructor for QuestFrame.</p>
*
* @throws java.awt.HeadlessException if any.
* <p>
* Constructor for QuestFrame.
* </p>
*
* @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 {
}
/**
* <p>showPane.</p>
*
* @param paneName a {@link java.lang.String} object.
* <p>
* showPane.
* </p>
*
* @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);
}
/**
* <p>showMainPane.</p>
* <p>
* showMainPane.
* </p>
*/
public void showMainPane() {
public final void showMainPane() {
showPane(MAIN_PANEL);
}
/**
* <p>showBazaarPane.</p>
* <p>
* showBazaarPane.
* </p>
*/
public void showBazaarPane() {
public final void showBazaarPane() {
showPane(BAZAAR_PANEL);
}
/**
* <p>returnToMainMenu.</p>
* <p>
* returnToMainMenu.
* </p>
*/
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();

View File

@@ -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;
/**
* <p>QuestMainPanel class.</p>
* <p>
* QuestMainPanel class.
* </p>
* 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 <code>serialVersionUID=6142934729724012402L</code> */
/** Constant <code>serialVersionUID=6142934729724012402L</code>. */
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 <code>NO_DECKS_AVAILABLE="No decks available"</code> */
/** Constant <code>NO_DECKS_AVAILABLE="No decks available"</code>. */
private static final String NO_DECKS_AVAILABLE = "No decks available";
/** Constant <code>DUELS="Duels"</code> */
/** Constant <code>DUELS="Duels"</code>. */
private static final String DUELS = "Duels";
/** Constant <code>CHALLENGES="Challenges"</code> */
/** Constant <code>CHALLENGES="Challenges"</code>. */
private static final String CHALLENGES = "Challenges";
//TODO: Make this ordering permanent
/** Constant <code>lastUsedDeck="//TODO: Make this ordering permanent"</code> */
// TODO: Make this ordering permanent
/** Constant <code>lastUsedDeck="//TODO: Make this ordering permanent"</code>. */
private static String lastUsedDeck;
private JButton zeppelinButton = new JButton("<html>Launch<br>Zeppelin</html>",
GuiUtils.getResizedIcon(GuiUtils.getIconFromFile("ZeppelinIcon.png"), 40, 40));
private JButton zeppelinButton = new JButton("<html>Launch<br>Zeppelin</html>", GuiUtils.getResizedIcon(
GuiUtils.getIconFromFile("ZeppelinIcon.png"), 40, 40));
private JPanel zeppelinPanel = new JPanel();
/**
* <p>Constructor for QuestMainPanel.</p>
*
* @param mainFrame a {@link forge.quest.gui.QuestFrame} object.
* <p>
* Constructor for QuestMainPanel.
* </p>
*
* @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();
}
/**
* <p>initUI.</p>
* <p>
* initUI.
* </p>
*/
private void initUI() {
refresh();
@@ -126,14 +168,16 @@ public class QuestMainPanel extends QuestAbstractPanel {
}
/**
* <p>createStatusPanel.</p>
*
* <p>
* createStatusPanel.
* </p>
*
* @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 {
}
/**
* <p>createSidePanel.</p>
*
* <p>
* createSidePanel.
* </p>
*
* @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<Component> eastComponents = new ArrayList<Component>();
//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 {
}
/**
* <p>createOptionsPanel.</p>
*
* <p>
* createOptionsPanel.
* </p>
*
* @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 {
}
/**
* <p>createMatchSettingsPanel.</p>
*
* <p>
* createMatchSettingsPanel.
* </p>
*
* @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 {
}
/**
* <p>createDuelPanel.</p>
* Makes a parent panel, then selectable panel instances for all available duels.
*
* <p>
* createDuelPanel.
* </p>
* 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 {
}
/**
* <p>createChallengePanel.</p>
* Makes a parent panel, then selectable panel instances for all available challenges.
*
* <p>
* createChallengePanel.
* </p>
* 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<QuestChallenge> 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;
}
/**
* <p>refresh.</p>
* <p>
* refresh.
* </p>
*/
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<String> deckNames = new ArrayList<String>(questData.getDeckNames());
Collections.sort(deckNames, new Comparator<String>() {
public int compare(String s, String s1) {
public int compare(final String s, final String s1) {
return s.compareToIgnoreCase(s1);
}
});
@@ -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 {
}
/**
* <p>refreshNextMatchPanel.</p>
* <p>
* refreshNextMatchPanel.
* </p>
*/
private void refreshNextMatchPanel() {
nextMatchPanel.removeAll();
@@ -568,18 +620,22 @@ public class QuestMainPanel extends QuestAbstractPanel {
}
/**
* <p>nextChallengeInWins.</p>
*
* <p>
* nextChallengeInWins.
* </p>
*
* @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;
}
/**
* <p>showDeckEditor.</p>
* <p>
* showDeckEditor.
* </p>
*/
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
/**
* <p>showBazaar.</p>
* <p>
* showBazaar.
* </p>
*/
void showBazaar() {
final void showBazaar() {
mainFrame.showBazaarPane();
}
/**
* <p>showCardShop.</p>
* <p>
* showCardShop.
* </p>
*/
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
/**
* <p>launchGame.</p>
* <p>
* launchGame.
* </p>
*/
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();
}
/**
* <p>setupDuel.</p>
*
* @param humanDeck a {@link forge.deck.Deck} object.
* <p>
* setupDuel.
* </p>
*
* @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);
}
/**
* <p>setupChallenge.</p>
*
* @param humanDeck a {@link forge.deck.Deck} object.
* <p>
* setupChallenge.
* </p>
*
* @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);
}
/**
* <p>getEventIconFilename.</p>
*
* <p>
* getEventIconFilename.
* </p>
*
* @return a {@link java.lang.String} object.
*/
private String getEventIconFilename() {
@@ -749,9 +818,11 @@ public class QuestMainPanel extends QuestAbstractPanel {
}
/**
* <p>showChallenges.</p>
* <p>
* showChallenges.
* </p>
*/
void showChallenges() {
final void showChallenges() {
if (isShowingChallenges) {
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 {
}
/**
* <p>moveDeckToTop.</p>
*
* @param humanDeckName a {@link java.lang.String} object.
* <p>
* moveDeckToTop.
* </p>
*
* @param humanDeckName
* a {@link java.lang.String} object.
*/
private void moveDeckToTop(String humanDeckName) {
private void moveDeckToTop(final String humanDeckName) {
QuestMainPanel.lastUsedDeck = humanDeckName;
}
/**
* <p>canGameBeLaunched.</p>
*
* <p>
* canGameBeLaunched.
* </p>
*
* @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();
}

View File

@@ -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;
/**
* <p>Gui_QuestOptions class.</p>
*
* <p>
* Gui_QuestOptions class.
* </p>
*
* @author Forge
* @version $Id$
*/
public class QuestOptions extends JFrame {
/** Constant <code>serialVersionUID=2018518804206822235L</code> */
/** Constant <code>serialVersionUID=2018518804206822235L</code>. */
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();
/**
* <p>Constructor for Gui_QuestOptions.</p>
* <p>
* Constructor for Gui_QuestOptions.
* </p>
*/
public QuestOptions() {
try {
@@ -70,19 +87,20 @@ public class QuestOptions extends JFrame {
}
/**
* <p>setup.</p>
* <p>
* setup.
* </p>
*/
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
/**
* <p>setupRadioButtonText.</p>
* <p>
* setupRadioButtonText.
* </p>
*/
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()
/**
* <p>jbInit.</p>
*
* @throws java.lang.Exception if any.
* <p>
* jbInit.
* </p>
*
* @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 {
}
/**
* <p>continueQuestButton_actionPerformed.</p>
*
* @param e a {@link java.awt.event.ActionEvent} object.
* <p>
* continueQuestButton_actionPerformed.
* </p>
*
* @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 {
}
/**
* <p>newQuestButton_actionPerformed.</p>
*
* @param e a {@link java.awt.event.ActionEvent} object.
* <p>
* newQuestButton_actionPerformed.
* </p>
*
* @param e
* a {@link java.awt.event.ActionEvent} object.
*/
void newQuestButton_actionPerformed(ActionEvent e) {
final void newQuestButton_actionPerformed(final ActionEvent e) {
int difficulty = 0;
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();
}
}

View File

@@ -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<CardPrinted> 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<CardPrinted> list) {
/**
* Instantiates a new quest win lose card viewer.
*
* @param list
* the list
*/
public QuestWinLoseCardViewer(final List<CardPrinted> 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;
}
}
}
}

View File

@@ -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;
/** <p>QuestWinLoseHandler.</p>
* Processes win/lose presentation for Quest events. This presentation
* is displayed by WinLoseFrame. Components to be added to pnlCustom in
// TODO: Auto-generated Javadoc
/**
* <p>
* QuestWinLoseHandler.
* </p>
* Processes win/lose presentation for Quest events. This presentation is
* displayed by WinLoseFrame. Components to be added to pnlCustom in
* WinLoseFrame should use MigLayout.
*
*
*/
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());
}
/**
* <p>startNextRound.</p>
* <p>
* startNextRound.
* </p>
* 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();
}
}
/**
* <p>populateCustomPanel.</p>
* Checks conditions of win and fires various reward display methods accordingly.
*
* @param boolean indicating if custom panel has contents.
* <p>
* populateCustomPanel.
* </p>
* 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;
}
/**
* <p>actionOnQuit.</p>
* When "quit" button is pressed, this method adjusts quest data as appropriate and saves.
*
* <p>
* actionOnQuit.
* </p>
* 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();
}
/**
* <p>awardEventCredits.</p>
* <p>
* awardEventCredits.
* </p>
* 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("<html>");
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.<br>");
// 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: <u>%s</u>! " +
"Bonus: %d credits.<br>",
sb.append(String.format("Alternate win condition: <u>%s</u>! " + "Bonus: %d credits.<br>",
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.<br>", mulliganReward));
sb.append(String
.format("Mulliganed to zero and still won! " + "Bonus: %d credits.<br>", 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.<br>", 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.<br>", reward));
sb.append(String.format("You have not lost once! " + "Bonus: %d credits.<br>", 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%.<br>");
break;
case 2:
credEstates = (int)0.15*credTotal;
sb.append("Estates bonus: 15%.<br>");
break;
case 3:
credEstates = (int)0.2*credTotal;
sb.append("Estates bonus: 20%.<br>");
break;
default: break;
switch (model.qData.getInventory().getItemLevel("Estates")) {
case 1:
credEstates = (int) 0.1 * credTotal;
sb.append("Estates bonus: 10%.<br>");
break;
case 2:
credEstates = (int) 0.15 * credTotal;
sb.append("Estates bonus: 15%.<br>");
break;
case 3:
credEstates = (int) 0.2 * credTotal;
sb.append("Estates bonus: 20%.<br>");
break;
default:
break;
}
credTotal += credEstates;
// Final output
String congrats = "<br><h3>";
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 <b>%d credits</b> in total.</h3>", congrats, credTotal));
sb.append("</body></html>");
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");
}
/**
* <p>awardRandomRare.</p>
* <p>
* awardRandomRare.
* </p>
* 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<CardPrinted> cardsWon = new ArrayList<CardPrinted>();
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%!");
}
/**
* <p>awardJackpot.</p>
* <p>
* awardJackpot.
* </p>
* Generates and displays jackpot win case.
*
*
*/
private void awardJackpot() {
private void awardJackpot() {
List<CardPrinted> cardsWon = model.qData.getCards().addRandomRare(10);
// Generate Swing components and attach.
// Generate Swing components and attach.
lblTemp1 = new TitleLabel("You just won 10 random rares!");
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%!");
}
/**
* <p>awardBooster.</p>
* <p>
* awardBooster.
* </p>
* Generates and displays booster pack win case.
*
*
*/
private void awardBooster() {
ListChooser<GameFormat> ch = new ListChooser<GameFormat>("Choose bonus booster format", 1, SetUtils.getFormats());
ListChooser<GameFormat> ch = new ListChooser<GameFormat>("Choose bonus booster format", 1,
SetUtils.getFormats());
ch.show();
GameFormat selected = ch.getSelectedValue();
List<CardPrinted> cardsWon = model.qData.getCards().addCards(Predicate.and(selected.getFilterPrinted(),CardPrinted.Predicates.Presets.nonAlternate));
// Generate Swing components and attach.
lblTemp1 = new TitleLabel("Bonus booster pack from the \""+selected.getName()+"\" format!");
List<CardPrinted> cardsWon = model.qData.getCards().addCards(
Predicate.and(selected.getFilterPrinted(), CardPrinted.Predicates.Presets.nonAlternate));
// Generate Swing components and attach.
lblTemp1 = new TitleLabel("Bonus booster pack from the \"" + selected.getName() + "\" format!");
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%!");
}
/**
* <p>awardChallengeWin.</p>
* <p>
* awardChallengeWin.
* </p>
* 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<CardPrinted> cardsWon = ((QuestChallenge)model.qEvent).getCardRewardList();
long questRewardCredits = ((QuestChallenge)model.qEvent).getCreditsReward();
List<CardPrinted> cardsWon = ((QuestChallenge) model.qEvent).getCardRewardList();
long questRewardCredits = ((QuestChallenge) model.qEvent).getCreditsReward();
StringBuilder sb = new StringBuilder();
sb.append("<html>Challenge completed.<br><br>");
sb.append("Challenge bounty: <b>" + questRewardCredits + " credits.</b></html>");
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!");
}
/**
* <p>getLuckyCoinResult.</p>
* <p>
* getLuckyCoinResult.
* </p>
* 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);
}
/**
* <p>getCreditsRewardForAltWin.</p>
* <p>
* getCreditsRewardForAltWin.
* </p>
* 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;
}
}
/**
* <p>getCreditsRewardForWinByTurn.</p>
* <p>
* getCreditsRewardForWinByTurn.
* </p>
* 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));
}
}
}
}

View File

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