Releasing the beast: fully refactored quest submenu, featuring multiple quest support, preference editor, submenu tabs, and a host of other tools (and updates).

This commit is contained in:
Doublestrike
2012-01-29 06:32:11 +00:00
parent ca1d028913
commit 5754293e60
27 changed files with 2671 additions and 1454 deletions

9
.gitattributes vendored
View File

@@ -10235,6 +10235,8 @@ res/images/icons/GoldIcon.png -text svneol=unset#image/png
res/images/icons/GoldIconLarge.png -text svneol=unset#image/png res/images/icons/GoldIconLarge.png -text svneol=unset#image/png
res/images/icons/GoldIconSmall.png -text svneol=unset#image/png res/images/icons/GoldIconSmall.png -text svneol=unset#image/png
res/images/icons/HeartIcon.png -text svneol=unset#image/png res/images/icons/HeartIcon.png -text svneol=unset#image/png
res/images/icons/IconMinus.png -text
res/images/icons/IconPlus.png -text
res/images/icons/LeafIconSmall.png -text svneol=unset#image/png res/images/icons/LeafIconSmall.png -text svneol=unset#image/png
res/images/icons/Life.png -text svneol=unset#image/png res/images/icons/Life.png -text svneol=unset#image/png
res/images/icons/Mage01.jpg -text res/images/icons/Mage01.jpg -text
@@ -11330,12 +11332,15 @@ src/main/java/forge/view/Main.java -text
src/main/java/forge/view/editor/EditorTopLevel.java -text src/main/java/forge/view/editor/EditorTopLevel.java -text
src/main/java/forge/view/editor/package-info.java svneol=native#text/plain src/main/java/forge/view/editor/package-info.java svneol=native#text/plain
src/main/java/forge/view/home/HomeTopLevel.java -text src/main/java/forge/view/home/HomeTopLevel.java -text
src/main/java/forge/view/home/QuestFileLister.java -text
src/main/java/forge/view/home/SplashFrame.java -text src/main/java/forge/view/home/SplashFrame.java -text
src/main/java/forge/view/home/StartButton.java -text src/main/java/forge/view/home/StartButton.java -text
src/main/java/forge/view/home/SubButton.java -text src/main/java/forge/view/home/SubButton.java -text
src/main/java/forge/view/home/SubTab.java -text
src/main/java/forge/view/home/ViewConstructed.java -text src/main/java/forge/view/home/ViewConstructed.java -text
src/main/java/forge/view/home/ViewDraft.java -text src/main/java/forge/view/home/ViewDraft.java -text
src/main/java/forge/view/home/ViewQuest.java -text src/main/java/forge/view/home/ViewQuest.java -text
src/main/java/forge/view/home/ViewQuestPreferences.java -text
src/main/java/forge/view/home/ViewSealed.java -text src/main/java/forge/view/home/ViewSealed.java -text
src/main/java/forge/view/home/ViewSettings.java -text src/main/java/forge/view/home/ViewSettings.java -text
src/main/java/forge/view/home/ViewUtilities.java -text src/main/java/forge/view/home/ViewUtilities.java -text
@@ -11356,13 +11361,17 @@ src/main/java/forge/view/toolbox/CardFaceSymbols.java svneol=native#text/plain
src/main/java/forge/view/toolbox/CardViewer.java -text src/main/java/forge/view/toolbox/CardViewer.java -text
src/main/java/forge/view/toolbox/DeckLister.java -text src/main/java/forge/view/toolbox/DeckLister.java -text
src/main/java/forge/view/toolbox/FButton.java -text src/main/java/forge/view/toolbox/FButton.java -text
src/main/java/forge/view/toolbox/FCheckBox.java -text
src/main/java/forge/view/toolbox/FLabel.java -text
src/main/java/forge/view/toolbox/FList.java -text src/main/java/forge/view/toolbox/FList.java -text
src/main/java/forge/view/toolbox/FOverlay.java -text src/main/java/forge/view/toolbox/FOverlay.java -text
src/main/java/forge/view/toolbox/FPanel.java -text src/main/java/forge/view/toolbox/FPanel.java -text
src/main/java/forge/view/toolbox/FProgressBar.java -text src/main/java/forge/view/toolbox/FProgressBar.java -text
src/main/java/forge/view/toolbox/FRadioButton.java -text
src/main/java/forge/view/toolbox/FRoundedPanel.java -text src/main/java/forge/view/toolbox/FRoundedPanel.java -text
src/main/java/forge/view/toolbox/FScrollPane.java -text src/main/java/forge/view/toolbox/FScrollPane.java -text
src/main/java/forge/view/toolbox/FSkin.java -text src/main/java/forge/view/toolbox/FSkin.java -text
src/main/java/forge/view/toolbox/FTextArea.java -text
src/main/java/forge/view/toolbox/FVerticalTabPanel.java -text src/main/java/forge/view/toolbox/FVerticalTabPanel.java -text
src/main/java/forge/view/toolbox/package-info.java svneol=native#text/plain src/main/java/forge/view/toolbox/package-info.java svneol=native#text/plain
src/main/java/net/slightlymagic/braids/LICENSE.txt svneol=native#text/plain src/main/java/net/slightlymagic/braids/LICENSE.txt svneol=native#text/plain

1
.gitignore vendored
View File

@@ -96,6 +96,7 @@ res/pics/ZEN
res/pics/booster res/pics/booster
res/pics/icons res/pics/icons
res/pics/tokens res/pics/tokens
res/quest/data
res/quest/questData.dat res/quest/questData.dat
res/quest/questData.dat.xml res/quest/questData.dat.xml
res/reprintSetInfo.log res/reprintSetInfo.log

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

View File

@@ -1,30 +1,61 @@
difficultyString=Easy,Normal,Hard,Very Hard BOOSTER_COMMONS=11
# Num of Wins for each Difficulty to gain a Booster, Rank, Duel vs Tougher AI Decks BOOSTER_UNCOMMONS=3
winsForBooster=1,1,2,2 BOOSTER_RARES=1
winsForRankIncrease=3,4,5,6 REWARDS_BASE=30
winsForMediumAI=10,9,8,7 REWARDS_UNDEFEATED=25
winsForHardAI=20,18,16,14 REWARDS_WINS_MULTIPLIER=0.3
winsForVeryHardAI=40,36,32,28 REWARDS_POISON=50
# When starting a quest this is how much of each type you'll start with. Plus your starting Credits. REWARDS_MILLED=40
startingBasicLand=20 REWARDS_MULLIGAN0=500
startingSnowBasicLand=5 REWARDS_ALTERNATIVE=100
startingCommons=82,80,78,76 REWARDS_TURN15=5
startingUncommons=20,18,16,15 REWARDS_TURN10=50
startingRares=10,10,10,8 REWARDS_TURN5=250
startingCredits=250 REWARDS_TURN1=1500
# When winning a booster pack, this is what you'll expect to see in a pack. STARTING_BASIC_LANDS=20
boosterPackCommon=11 STARTING_SNOW_LANDS=5
boosterPackUncommon=3
boosterPackRare=1 STARTING_COMMONS_EASY=82
# Match rewards that are used by the quest system STARTING_COMMONS_MEDIUM=80
matchRewardBase=25 STARTING_COMMONS_HARD=78
matchRewardTotalWins=0.3 STARTING_COMMONS_EXPERT=76
matchRewardNoLosses=25
matchRewardPoisonWinBonus=50 STARTING_UNCOMMONS_EASY=40
matchRewardMilledWinBonus=40 STARTING_UNCOMMONS_MEDIUM=36
matchRewardAltWinBonus=100 STARTING_UNCOMMONS_HARD=32
matchRewardWinOnFirstTurn=1500 STARTING_UNCOMMONS_EXPERT=28
matchRewardWinByTurnFive=250
matchRewardWinByTurnTen=50 STARTING_RARES_EASY=20
matchRewardWinByTurnFifteen=5 STARTING_RARES_MEDIUM=18
matchRewardMullToZero=500 STARTING_RARES_HARD=16
STARTING_RARES_EXPERT=15
STARTING_CREDITS_EASY=250
STARTING_CREDITS_MEDIUM=200
STARTING_CREDITS_HARD=150
STARTING_CREDITS_EXPERT=100
WINS_BOOSTER_EASY=1
WINS_BOOSTER_MEDIUM=1
WINS_BOOSTER_HARD=2
WINS_BOOSTER_EXPERT=2
WINS_RANKUP_EASY=3
WINS_RANKUP_MEDIUM=4
WINS_RANKUP_HARD=5
WINS_RANKUP_EXPERT=6
WINS_MEDIUMAI_EASY=10
WINS_MEDIUMAI_MEDIUM=9
WINS_MEDIUMAI_HARD=8
WINS_MEDIUMAI_EXPERT=7
WINS_HARDAI_EASY=20
WINS_HARDAI_MEDIUM=18
WINS_HARDAI_HARD=16
WINS_HARDAI_EXPERT=14
WINS_EXPERTAI_EASY=40
WINS_EXPERTAI_MEDIUM=36
WINS_EXPERTAI_HARD=32
WINS_EXPERTAI_EXPERT=28

View File

@@ -190,6 +190,11 @@ public class FControl {
return this.home; return this.home;
} }
/** @return HomeTopLevel */
public ControlHomeUI getHomeController() {
return this.home.getController();
}
/** /**
* Gets the match view. * Gets the match view.
* *

View File

@@ -4,23 +4,35 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import forge.AllZone; import forge.AllZone;
import forge.Command; import forge.Command;
import forge.Constant; import forge.Constant;
import forge.Singletons;
import forge.control.FControl; import forge.control.FControl;
import forge.deck.Deck; import forge.deck.Deck;
import forge.game.GameType; import forge.game.GameType;
import forge.gui.GuiUtils;
import forge.gui.deckeditor.DeckEditorQuest; import forge.gui.deckeditor.DeckEditorQuest;
import forge.gui.deckeditor.DeckEditorShop; import forge.gui.deckeditor.DeckEditorShop;
import forge.quest.data.QuestChallenge; import forge.quest.data.QuestChallenge;
import forge.quest.data.QuestData; import forge.quest.data.QuestData;
import forge.quest.data.QuestDataIO;
import forge.quest.data.QuestEvent; import forge.quest.data.QuestEvent;
import forge.quest.data.QuestEventManager;
import forge.quest.data.QuestPreferences;
import forge.quest.data.QuestPreferences.QPref;
import forge.quest.data.QuestUtil; import forge.quest.data.QuestUtil;
import forge.quest.data.item.QuestItemZeppelin; import forge.quest.data.item.QuestItemZeppelin;
import forge.quest.data.pet.QuestPetAbstract;
import forge.view.GuiTopLevel; import forge.view.GuiTopLevel;
import forge.view.home.ViewQuest; import forge.view.home.ViewQuest;
@@ -31,20 +43,34 @@ import forge.view.home.ViewQuest;
public class ControlQuest { public class ControlQuest {
private ViewQuest view; private ViewQuest view;
private QuestEvent event; private QuestEvent event;
private final ActionListener actPetSelect, actPlantSelect; private QuestData qData;
private final MouseAdapter madStartGame; private QuestPreferences qPrefs;
private QuestEventManager qem;
private JPanel selectedTab;
private final MouseAdapter madStartGame, madDuels, madChallenges,
madQuests, madDecks, madPreferences;
private final ActionListener actPetSelect, actPlantSelect,
actSpellShop, actBazaar, actEmbark, actNewDeck, actCurrentDeck;
private final Command cmdDeckExit, cmdDeckDelete, cmdDeckSelect,
cmdQuestSelect, cmdQuestDelete;
private Deck currentDeck;
private Map<String, QuestData> arrQuests;
/** /**
* Controls logic and listeners for quest mode in home screen. * Controls logic and listeners for quest mode in home screen.
* *
* @param v0 &emsp; ViewQuest * @param v0 &emsp; ViewQuest
*/ */
@SuppressWarnings("serial")
public ControlQuest(ViewQuest v0) { public ControlQuest(ViewQuest v0) {
// Inits
this.view = v0; this.view = v0;
this.qem = new QuestEventManager();
this.qPrefs = Singletons.getModel().getQuestPreferences();
AllZone.setQuestEventManager(this.qem);
if (view.hasPreviousQuest()) { //========= Listener inits
updateDeckList();
}
// Game start logic must happen outside of the EDT. // Game start logic must happen outside of the EDT.
madStartGame = new MouseAdapter() { madStartGame = new MouseAdapter() {
@@ -60,14 +86,33 @@ public class ControlQuest {
} }
}; };
madDuels = new MouseAdapter() { @Override
public void mouseClicked(MouseEvent e) { view.showDuelsTab(); } };
madChallenges = new MouseAdapter() { @Override
public void mouseClicked(MouseEvent e) { view.showChallengesTab(); } };
madQuests = new MouseAdapter() { @Override
public void mouseClicked(MouseEvent e) { view.showQuestsTab(); } };
madDecks = new MouseAdapter() { @Override
public void mouseClicked(MouseEvent e) {
view.showDecksTab();
if (ControlQuest.this.qem != null) { refreshDecks(); }
}
};
madPreferences = new MouseAdapter() { @Override
public void mouseClicked(MouseEvent e) { view.showPrefsTab(); } };
actPetSelect = new ActionListener() { actPetSelect = new ActionListener() {
@Override @Override
public void actionPerformed(final ActionEvent actionEvent) { public void actionPerformed(final ActionEvent actionEvent) {
if (view.getPetComboBox().getSelectedIndex() > 0) { if (view.getCbxPet().getSelectedIndex() > 0) {
view.getQuestData().getPetManager().setSelectedPet( qData.getPetManager().setSelectedPet(
(String) view.getPetComboBox().getSelectedItem()); (String) view.getCbxPet().getSelectedItem());
} else { } else {
view.getQuestData().getPetManager().setSelectedPet(null); qData.getPetManager().setSelectedPet(null);
} }
} }
}; };
@@ -75,98 +120,162 @@ public class ControlQuest {
actPlantSelect = new ActionListener() { actPlantSelect = new ActionListener() {
@Override @Override
public void actionPerformed(final ActionEvent actionEvent) { public void actionPerformed(final ActionEvent actionEvent) {
view.getQuestData().getPetManager() qData.getPetManager()
.setUsePlant(view.getPlantCheckBox().isSelected()); .setUsePlant(view.getCbPlant().isSelected());
} }
}; };
actSpellShop = new ActionListener() { @Override
public void actionPerformed(ActionEvent e) { showSpellShop(); } };
actBazaar = new ActionListener() { @Override
public void actionPerformed(ActionEvent e) { showBazaar(); } };
actEmbark = new ActionListener() { @Override
public void actionPerformed(ActionEvent e) { newQuest(); } };
actCurrentDeck = new ActionListener() { @Override
public void actionPerformed(ActionEvent e) { view.showDecksTab(); } };
actNewDeck = new ActionListener() { @Override
public void actionPerformed(ActionEvent e) {
final DeckEditorQuest editor = new DeckEditorQuest(qData);
editor.show(cmdDeckExit);
editor.setVisible(true);
}
};
cmdDeckExit = new Command() {
@Override
public void execute() {
AllZone.getQuestData().saveData();
refreshDecks();
GuiTopLevel g = ((GuiTopLevel) AllZone.getDisplay());
g.getController().getHomeView().getBtnQuest().grabFocus();
}
};
cmdDeckSelect = new Command() {
@Override
public void execute() {
currentDeck = view.getLstDecks().getSelectedDeck();
view.setCurrentDeckStatus();
}
};
cmdDeckDelete = new Command() { @Override
public void execute() { refreshDecks(); } };
cmdQuestSelect = new Command() { @Override
public void execute() { changeQuest(); } };
cmdQuestDelete = new Command() { @Override
public void execute() { refreshQuests(); } };
addListeners(); addListeners();
} }
private void addListeners() {
if (view.hasPreviousQuest()) {
view.getBtnStart().removeMouseListener(madStartGame);
view.getBtnStart().addMouseListener(madStartGame);
view.getPetComboBox().removeActionListener(actPetSelect);
view.getPetComboBox().addActionListener(actPetSelect);
view.getPlantCheckBox().removeActionListener(actPlantSelect);
view.getPlantCheckBox().addActionListener(actPlantSelect);
}
}
/** @return ViewQuest */ /** @return ViewQuest */
public ViewQuest getView() { public ViewQuest getView() {
return view; return view;
} }
/** */ /** @return {@link forge.quest.gui.main.QuestEventManager} */
private void updateDeckList() { public QuestEventManager getQEM() {
view.getLstDeckChooser().setListData(AllZone.getQuestData().getDeckNames().toArray()); return this.qem;
view.getLstDeckChooser().setSelectedIndex(0);
} }
/** */ /** @return {@link forge.Command} What to do when the deck editor exits. */
public void showDeckEditor() { public Command getExitCommand() {
final Command exit = new Command() { return cmdDeckExit;
private static final long serialVersionUID = -5110231879431074581L;
@Override
public void execute() {
// saves all deck data
AllZone.getQuestData().saveData();
updateDeckList();
}
};
DeckEditorQuest g = new DeckEditorQuest(AllZone.getQuestData());
g.show(exit);
g.setVisible(true);
} }
private void updateCredits() { /** @return String &emsp; indicates the rank of this current quest */
view.getLblCredits().setText(Long.toString(view.getQuestData().getCredits())); public String getRankString() {
return qData.getRank();
} }
private void updateLife() { /** @return forge.deck.Deck */
view.getLblLife().setText(Long.toString(view.getQuestData().getLife())); public Deck getCurrentDeck() {
return this.currentDeck;
} }
/** */ /** @return */
public void showCardShop() { public Map<String, QuestData> getAllQuests() {
final Command exit = new Command() { return arrQuests;
private static final long serialVersionUID = 8567193482568076362L;
@Override
public void execute() {
// saves all deck data
AllZone.getQuestData().saveData();
updateDeckList();
updateCredits();
//updateLife();
}
};
DeckEditorShop g = new DeckEditorShop(AllZone.getQuestData());
g.show(exit);
g.setVisible(true);
} }
/** */ /**
public void showBazaar() { * Updates visual state of tabber.
GuiTopLevel g = ((GuiTopLevel) AllZone.getDisplay()); * @param tab0 &emsp; JPanel tab object (can pass SubTab too).
*/
public void updateTabber(JPanel tab0) {
if (selectedTab != null) {
selectedTab.setEnabled(false);
}
g.getController().changeState(FControl.QUEST_BAZAAR); tab0.setEnabled(true);
g.validate(); selectedTab = tab0;
} // card shop button }
private void addListeners() {
view.getTabDuels().removeMouseListener(madDuels);
view.getTabDuels().addMouseListener(madDuels);
view.getTabChallenges().removeMouseListener(madChallenges);
view.getTabChallenges().addMouseListener(madChallenges);
view.getTabDecks().removeMouseListener(madDecks);
view.getTabDecks().addMouseListener(madDecks);
view.getTabQuests().removeMouseListener(madQuests);
view.getTabQuests().addMouseListener(madQuests);
view.getTabPreferences().removeMouseListener(madPreferences);
view.getTabPreferences().addMouseListener(madPreferences);
view.getBtnEmbark().removeActionListener(actEmbark);
view.getBtnEmbark().addActionListener(actEmbark);
view.getLstQuests().setSelectCommand(cmdQuestSelect);
view.getLstQuests().setEditCommand(cmdQuestDelete);
view.getLstQuests().setDeleteCommand(cmdQuestDelete);
if (this.qem != null) {
view.getBtnStart().removeMouseListener(madStartGame);
view.getBtnStart().addMouseListener(madStartGame);
view.getBtnBazaar().removeActionListener(actBazaar);
view.getBtnBazaar().addActionListener(actBazaar);
view.getBtnNewDeck().removeActionListener(actNewDeck);
view.getBtnNewDeck().addActionListener(actNewDeck);
view.getBtnCurrentDeck().removeActionListener(actCurrentDeck);
view.getBtnCurrentDeck().addActionListener(actCurrentDeck);
view.getBtnSpellShop().removeActionListener(actSpellShop);
view.getBtnSpellShop().addActionListener(actSpellShop);
view.getCbxPet().removeActionListener(actPetSelect);
view.getCbxPet().addActionListener(actPetSelect);
view.getCbPlant().removeActionListener(actPlantSelect);
view.getCbPlant().addActionListener(actPlantSelect);
view.getLstDecks().setSelectCommand(cmdDeckSelect);
view.getLstDecks().setDeleteCommand(cmdDeckDelete);
view.getLstDecks().setExitCommand(cmdDeckExit);
}
}
/** /**
* The actuator for new quests. * The actuator for new quests.
*/ */
public void newQuest() { private void newQuest() {
int difficulty = 0; int difficulty = 0;
QuestData questData = new QuestData(); QuestData newdata = new QuestData();
final String mode = view.getRadFantasy().isSelected() final String mode = view.getRadFantasy().isSelected()
? forge.quest.data.QuestData.FANTASY ? forge.quest.data.QuestData.FANTASY
@@ -181,32 +290,197 @@ public class ControlQuest {
} else if (view.getRadExpert().isSelected()) { } else if (view.getRadExpert().isSelected()) {
difficulty = 3; difficulty = 3;
} else { } else {
JOptionPane.showMessageDialog(null, throw new IllegalStateException(
"This should not be happening!", "ControlQuest() > newQuest(): Error starting new quest!");
"New Quest: Difficulty Bug!?", JOptionPane.ERROR_MESSAGE); }
final Object o = JOptionPane.showInputDialog(null, "Poets will remember your quest as:", "Quest Name", JOptionPane.OK_CANCEL_OPTION);
if (o == null) { return; }
final String questName = GuiUtils.cleanString(o.toString());
if (getAllQuests().get(questName) != null || questName.equals("")) {
JOptionPane.showMessageDialog(null, "Please pick another quest name, a quest already has that name.");
return; return;
} }
if (questData.hasSaveFile()) { // Give the user a few cards to build a deck
// this will overwrite your save file! newdata.newGame(difficulty, mode, view.getCbStandardStart().isSelected());
final Object[] possibleValues = { "Yes", "No" }; newdata.setName(questName);
final Object choice = JOptionPane.showOptionDialog(null, newdata.saveData();
"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)) {
return;
}
}
// give the user a few cards to build a deck
questData.newGame(difficulty, mode, view.getCbStandardStart().isSelected());
questData.saveData();
// set global variable
AllZone.setQuestData(questData);
view.getParentView().resetQuest(); view.getParentView().resetQuest();
} // New Quest
private void changeQuest() {
AllZone.setQuestData(view.getLstQuests().getSelectedQuest());
this.qData = AllZone.getQuestData();
this.qem = new QuestEventManager();
this.qem.assembleAllEvents();
AllZone.setQuestEventManager(this.qem);
refreshDecks();
refreshStats();
}
/** Resets quests, then retrieves and sets current quest. */
public void refreshQuests() {
File dirQuests = new File("res/quest/data/");
// Temporary transition code between v1.2.2 and v1.2.3.
// Can be safely deleted after release of 1.2.3.
if (!dirQuests.exists()) {
dirQuests.mkdirs();
}
File olddata = new File("res/quest/questData.dat");
File newpath = new File(dirQuests.getPath() + "questData.dat");
if (olddata.exists()) { olddata.renameTo(newpath); }
// end block which can be deleted
// Iterate over files and load quest datas for each.
File[] arrFiles = dirQuests.listFiles();
arrQuests = new HashMap<String, QuestData>();
for (File f : arrFiles) {
arrQuests.put(f.getName(), QuestDataIO.loadData(f));
}
// Populate list with available quest datas.
view.getLstQuests().setQuests(arrQuests.values().toArray(new QuestData[0]));
// If there are quests available, force select.
if (arrQuests.size() > 0) {
final String questname = qPrefs.getPreference(QPref.CURRENT_QUEST);
// Attempt to select previous quest.
if (arrQuests.get(questname) != null) {
view.getLstQuests().setSelectedQuestData(arrQuests.get(questname));
}
else {
view.getLstQuests().setSelectedIndex(0);
}
// Save in preferences.
qPrefs.setPreference(QPref.CURRENT_QUEST,
view.getLstQuests().getSelectedQuest().getName());
// Drop into AllZone.
AllZone.setQuestData(view.getLstQuests().getSelectedQuest());
}
else {
AllZone.setQuestData(null);
}
this.qData = AllZone.getQuestData();
if (qem.getAllDuels() == null) {
qem.assembleAllEvents();
}
}
/** Resets decks, then retrieves and sets current deck. */
public void refreshDecks() {
Deck[] temp = (qData == null ? new Deck[] {} : qData.getDecks().toArray(new Deck[0]));
view.getLstDecks().setDecks(temp);
if (!view.getLstDecks().setSelectedDeck(currentDeck)) {
if (!view.getLstDecks().setSelectedIndex(0)) {
currentDeck = null;
}
else {
currentDeck = view.getLstDecks().getSelectedDeck();
}
}
view.setCurrentDeckStatus();
}
/** Updates all statistics in several panels. */
public void refreshStats() {
if (qData == null) { return; }
// Stats panel
view.getLblCredits().setText("Credits: " + qData.getCredits());
view.getLblLife().setText("Life: " + qData.getLife());
view.getLblWins().setText("Wins: " + qData.getWin());
view.getLblLosses().setText("Losses: " + qData.getLost());
view.getBarProgress().setVisible(false);
view.setCurrentDeckStatus();
final int num = nextChallengeInWins();
if (num == 0) {
view.getLblNextChallengeInWins().setText("Next challenge available now.");
}
else {
view.getLblNextChallengeInWins().setText("Next challenge available in " + num + " wins.");
}
view.getLblWinStreak().setText(
"Win streak: " + qData.getWinStreakCurrent()
+ " (Best:" + qData.getWinStreakBest() + ")");
// Start panel: pet, plant, zep.
if (this.qData.getMode().equals(QuestData.FANTASY)) {
final Set<String> petList = this.qData.getPetManager().getAvailablePetNames();
final QuestPetAbstract currentPet = this.qData.getPetManager().getSelectedPet();
// Pet list visibility
if (petList.size() > 0) {
view.getCbxPet().setEnabled(true);
view.getCbxPet().addItem("Don't summon a pet");
for (final String pet : petList) {
view.getCbxPet().addItem("Summon " + pet);
}
if (currentPet != null) { view.getCbxPet().setSelectedItem(currentPet.getName()); }
} else {
view.getCbxPet().setVisible(false);
}
// Plant visiblity
if (this.qData.getPetManager().getPlant().getLevel() == 0) {
view.getCbPlant().setVisible(false);
}
else {
view.getCbPlant().setVisible(true);
view.getCbPlant().setSelected(this.qData.getPetManager().shouldPlantBeUsed());
}
// Zeppelin visibility
final QuestItemZeppelin zeppelin = (QuestItemZeppelin) this.qData.getInventory().getItem("Zeppelin");
view.getCbZep().setVisible(zeppelin.hasBeenUsed());
}
else {
view.getCbxPet().setVisible(false);
view.getCbPlant().setVisible(false);
view.getCbZep().setVisible(false);
}
}
/** */
@SuppressWarnings("serial")
private void showSpellShop() {
final Command exit = new Command() {
@Override
public void execute() {
AllZone.getQuestData().saveData();
refreshStats();
}
};
DeckEditorShop g = new DeckEditorShop(AllZone.getQuestData());
g.show(exit);
g.setVisible(true);
}
/** */
private void showBazaar() {
GuiTopLevel g = ((GuiTopLevel) AllZone.getDisplay());
g.getController().changeState(FControl.QUEST_BAZAAR);
g.validate();
} }
/** */ /** */
@@ -216,7 +490,7 @@ public class ControlQuest {
"ControlQuest() > startGame() must be accessed from outside the event dispatch thread."); "ControlQuest() > startGame() must be accessed from outside the event dispatch thread.");
} }
if (view.getLstDeckChooser().getSelectedIndex() == -1) { if (currentDeck == null) {
JOptionPane.showMessageDialog(null, JOptionPane.showMessageDialog(null,
"A mysterious wall blocks your way." "A mysterious wall blocks your way."
+ "\n\rAn unseen sepulchral voice booms:" + "\n\rAn unseen sepulchral voice booms:"
@@ -225,6 +499,8 @@ public class ControlQuest {
return; return;
} }
view.getBarProgress().setVisible(true);
// If everything is OK, show progress bar and start inits. // If everything is OK, show progress bar and start inits.
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override @Override
@@ -242,9 +518,9 @@ public class ControlQuest {
event = view.getSelectedOpponent().getEvent(); event = view.getSelectedOpponent().getEvent();
AllZone.setQuestEvent(event); AllZone.setQuestEvent(event);
Constant.Runtime.setGameType(GameType.Quest); Constant.Runtime.setGameType(GameType.Quest);
final QuestItemZeppelin zeppelin = (QuestItemZeppelin) view.getQuestData().getInventory().getItem("Zeppelin"); final QuestItemZeppelin zeppelin = (QuestItemZeppelin) qData.getInventory().getItem("Zeppelin");
zeppelin.setZeppelinUsed(false); zeppelin.setZeppelinUsed(false);
view.getQuestData().randomizeOpponents(); qData.randomizeOpponents();
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override @Override
@@ -253,13 +529,8 @@ public class ControlQuest {
} }
}); });
String deckname = (String) view.getLstDeckChooser().getSelectedValue(); Constant.Runtime.HUMAN_DECK[0] = currentDeck;
Constant.Runtime.HUMAN_DECK[0] = view.getQuestData().getDeck(deckname);
Constant.Runtime.COMPUTER_DECK[0] = event.getEventDeck(); Constant.Runtime.COMPUTER_DECK[0] = event.getEventDeck();
final Deck humanDeck = view.getQuestData().getDeck(deckname);
Constant.Runtime.HUMAN_DECK[0] = humanDeck;
Constant.Quest.OPP_ICON_NAME[0] = event.getIcon(); Constant.Quest.OPP_ICON_NAME[0] = event.getIcon();
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@@ -278,11 +549,11 @@ public class ControlQuest {
AllZone.getMatchState().reset(); AllZone.getMatchState().reset();
if (event.getEventType().equals("challenge")) { if (event.getEventType().equals("challenge")) {
setupChallenge(humanDeck); setupChallenge(currentDeck);
} else { } else {
setupDuel(humanDeck); setupDuel(currentDeck);
} }
view.getQuestData().saveData(); qData.saveData();
} }
}); });
} }
@@ -295,15 +566,15 @@ public class ControlQuest {
* @param humanDeck * @param humanDeck
* a {@link forge.deck.Deck} object. * a {@link forge.deck.Deck} object.
*/ */
final void setupDuel(final Deck humanDeck) { private void setupDuel(final Deck humanDeck) {
final Deck computer = event.getEventDeck(); final Deck computer = event.getEventDeck();
Constant.Runtime.COMPUTER_DECK[0] = computer; Constant.Runtime.COMPUTER_DECK[0] = computer;
AllZone.getGameAction().newGame( AllZone.getGameAction().newGame(
Constant.Runtime.HUMAN_DECK[0], Constant.Runtime.COMPUTER_DECK[0], Constant.Runtime.HUMAN_DECK[0], Constant.Runtime.COMPUTER_DECK[0],
QuestUtil.getHumanStartingCards(view.getQuestData()), QuestUtil.getHumanStartingCards(qData),
QuestUtil.getComputerStartingCards(view.getQuestData()), QuestUtil.getComputerStartingCards(qData),
view.getQuestData().getLife(), 20); qData.getLife(), 20);
} }
/** /**
@@ -317,15 +588,45 @@ public class ControlQuest {
private void setupChallenge(final Deck humanDeck) { private void setupChallenge(final Deck humanDeck) {
int extraLife = 0; int extraLife = 0;
if (view.getQuestData().getInventory().getItemLevel("Gear") == 2) { if (qData.getInventory().getItemLevel("Gear") == 2) {
extraLife = 3; extraLife = 3;
} }
AllZone.getGameAction().newGame( AllZone.getGameAction().newGame(
Constant.Runtime.HUMAN_DECK[0], Constant.Runtime.COMPUTER_DECK[0], Constant.Runtime.HUMAN_DECK[0], Constant.Runtime.COMPUTER_DECK[0],
QuestUtil.getHumanStartingCards(view.getQuestData(), event), QuestUtil.getHumanStartingCards(qData, event),
QuestUtil.getComputerStartingCards(view.getQuestData(), event), QuestUtil.getComputerStartingCards(qData, event),
view.getQuestData().getLife() + extraLife, ((QuestChallenge) event).getAILife()); qData.getLife() + extraLife, ((QuestChallenge) event).getAILife());
} }
/**
* <p>
* nextChallengeInWins.
* </p>
*
* @return a int.
*/
private int nextChallengeInWins() {
// Number of wins was 25, lowering the number to 20 to help short term
// questers.
if (qData.getWin() < 20) {
return 20 - qData.getWin();
}
// The int mul has been lowered by one, should face special opps more
// frequently.
final int challengesPlayed = qData.getChallengesPlayed();
int mul = 5;
if (qData.getInventory().hasItem("Zeppelin")) {
mul = 3;
} else if (qData.getInventory().hasItem("Map")) {
mul = 4;
}
final int delta = (challengesPlayed * mul) - qData.getWin();
return (delta > 0) ? delta : 0;
}
} }

View File

@@ -409,4 +409,23 @@ public final class GuiUtils {
overlay.removeAll(); overlay.removeAll();
overlay.hideOverlay(); overlay.hideOverlay();
} }
/** Duplicate in DeckEditorQuestMenu and
* probably elsewhere...can streamline at some point.
*
* @param in &emsp; {@link java.lang.String}
* @return {@link java.lang.String}
*/
public static String cleanString(final String in) {
final StringBuffer out = new StringBuffer();
final char[] c = in.toCharArray();
for (int i = 0; (i < c.length) && (i < 20); i++) {
if (Character.isLetterOrDigit(c[i]) || (c[i] == '-') || (c[i] == '_') || (c[i] == ' ')) {
out.append(c[i]);
}
}
return out.toString();
}
} }

View File

@@ -36,6 +36,7 @@ import forge.gui.input.InputControl;
import forge.properties.ForgePreferences; import forge.properties.ForgePreferences;
import forge.properties.ForgeProps; import forge.properties.ForgeProps;
import forge.properties.NewConstants; import forge.properties.NewConstants;
import forge.quest.data.QuestPreferences;
import forge.util.FileUtil; import forge.util.FileUtil;
import forge.util.HttpUtil; import forge.util.HttpUtil;
@@ -57,7 +58,8 @@ public class FModel {
private BuildInfo buildInfo; private BuildInfo buildInfo;
/** The preferences. */ /** The preferences. */
private ForgePreferences preferences; private final QuestPreferences questPreferences;
private final ForgePreferences preferences;
private FGameState gameState; private FGameState gameState;
/** /**
@@ -84,12 +86,14 @@ public class FModel {
// Instantiate preferences // Instantiate preferences
try { try {
this.setPreferences(new ForgePreferences("forge.preferences")); this.preferences = new ForgePreferences("forge.preferences");
} catch (final Exception exn) { } catch (final Exception exn) {
// Log.error("Error loading preferences: " + exn);
throw new RuntimeException(exn); throw new RuntimeException(exn);
} }
// Instantiate quest preferences
this.questPreferences = new QuestPreferences();
// TODO this single setting from preferences should not be here, or, // TODO this single setting from preferences should not be here, or,
// it should be here with all the other settings at the same time. // it should be here with all the other settings at the same time.
// Unfortunately, they're tied up in legacy code in the Display interface, // Unfortunately, they're tied up in legacy code in the Display interface,
@@ -269,9 +273,9 @@ public class FModel {
return this.preferences; return this.preferences;
} }
/** @param fp0 {@link forge.properties.ForgePreferences} */ /** @return {@link forge.quest.data.QuestPreferences} */
public final void setPreferences(final ForgePreferences fp0) { public final QuestPreferences getQuestPreferences() {
this.preferences = fp0; return this.questPreferences;
} }
/** @return {@link forge.model.FGameState} */ /** @return {@link forge.model.FGameState} */

View File

@@ -24,6 +24,7 @@ import java.util.Map;
import net.slightlymagic.maxmtg.Predicate; import net.slightlymagic.maxmtg.Predicate;
import forge.SetUtils; import forge.SetUtils;
import forge.Singletons;
import forge.deck.Deck; import forge.deck.Deck;
import forge.error.ErrorViewer; import forge.error.ErrorViewer;
import forge.item.CardPrinted; import forge.item.CardPrinted;
@@ -31,6 +32,7 @@ import forge.item.InventoryItem;
import forge.item.ItemPool; import forge.item.ItemPool;
import forge.properties.ForgeProps; import forge.properties.ForgeProps;
import forge.properties.NewConstants; import forge.properties.NewConstants;
import forge.quest.data.QuestPreferences.QPref;
import forge.quest.data.item.QuestInventory; import forge.quest.data.item.QuestInventory;
import forge.quest.data.pet.QuestPetManager; import forge.quest.data.pet.QuestPetManager;
import forge.util.MyRandom; import forge.util.MyRandom;
@@ -68,6 +70,10 @@ public final class QuestData {
/** The lost. */ /** The lost. */
private int lost; private int lost;
private int winstreakBest = 0;
private int winstreakCurrent = 0;
/** The credits. */ /** The credits. */
private long credits; // this money is good for all modes private long credits; // this money is good for all modes
@@ -93,6 +99,9 @@ public final class QuestData {
/** The difficulty. */ /** The difficulty. */
private String difficulty; private String difficulty;
/** */
private String name = "";
// Quest mode - there should be an enum :( // Quest mode - there should be an enum :(
/** The mode. */ /** The mode. */
private String mode = ""; private String mode = "";
@@ -170,15 +179,25 @@ public final class QuestData {
"What Do You Do With The Other Hand?", "Freelance Sorcerer, Works Weekends", "What Do You Do With The Other Hand?", "Freelance Sorcerer, Works Weekends",
"Should We Hire Commentators?", "Saltblasted For Your Talent", "Serra Angel Is Your Girlfriend", }; "Should We Hire Commentators?", "Saltblasted For Your Talent", "Serra Angel Is Your Girlfriend", };
/** */
public QuestData() {
this("An Unknown Quest");
}
/** /**
* <p> * <p>
* Constructor for QuestData. * Constructor for QuestData.
* </p> * </p>
*
* @param s0 &emsp; String name
*/ */
public QuestData() { public QuestData(String s0) {
this.initTransients(); this.initTransients();
this.myCards.addBasicLands(this.getCardPool(), QuestPreferences.getStartingBasic(), this.setName(s0);
QuestPreferences.getStartingSnowBasic());
this.myCards.addBasicLands(this.getCardPool(),
Singletons.getModel().getQuestPreferences().getPreferenceInt(QPref.STARTING_BASIC_LANDS),
Singletons.getModel().getQuestPreferences().getPreferenceInt(QPref.STARTING_BASIC_LANDS));
this.randomizeOpponents(); this.randomizeOpponents();
} }
@@ -213,7 +232,7 @@ public final class QuestData {
: CardPrinted.Predicates.Presets.IS_TRUE; : CardPrinted.Predicates.Presets.IS_TRUE;
this.myCards.setupNewGameCardPool(filter, diff); this.myCards.setupNewGameCardPool(filter, diff);
this.setCredits(QuestPreferences.getStartingCredits()); this.setCredits(Singletons.getModel().getQuestPreferences().getPreferenceInt(QPref.STARTING_CREDITS, diff));
this.mode = m0de; this.mode = m0de;
this.life = this.mode.equals(QuestData.FANTASY) ? 15 : 20; this.life = this.mode.equals(QuestData.FANTASY) ? 15 : 20;
@@ -356,6 +375,12 @@ public final class QuestData {
*/ */
public void addLost() { public void addLost() {
this.lost++; this.lost++;
if (winstreakCurrent > winstreakBest) {
winstreakBest = winstreakCurrent;
}
winstreakCurrent = 0;
} }
/** /**
@@ -372,8 +397,13 @@ public final class QuestData {
*/ */
public void addWin() { // changes getRank() public void addWin() { // changes getRank()
this.win++; this.win++;
this.winstreakCurrent++;
final int winsToLvlUp = QuestPreferences.getWinsForRankIncrease(this.diffIndex); if (winstreakCurrent > winstreakBest) {
winstreakBest = winstreakCurrent;
}
final int winsToLvlUp = Singletons.getModel().getQuestPreferences().getPreferenceInt(QPref.WINS_RANKUP, this.diffIndex);
if ((this.win % winsToLvlUp) == 0) { if ((this.win % winsToLvlUp) == 0) {
this.rankIndex++; this.rankIndex++;
} }
@@ -480,14 +510,15 @@ public final class QuestData {
/** /**
* Guess difficulty index. * Guess difficulty index.
* NOTE: Used in old UI only, soon to be deprecated.
*/ */
public void guessDifficultyIndex() { public void guessDifficultyIndex() {
final String[] diffStr = QuestPreferences.getDifficulty(); /*final String[] diffStr = QuestPreferences.getDifficulty();
for (int i = 0; i < diffStr.length; i++) { for (int i = 0; i < diffStr.length; i++) {
if (this.difficulty.equals(diffStr[i])) { if (this.difficulty.equals(diffStr[i])) {
this.diffIndex = i; this.diffIndex = i;
} }
} }*/
} }
// Level, read-only ( note: it increments in addWin() ) // Level, read-only ( note: it increments in addWin() )
@@ -512,6 +543,15 @@ public final class QuestData {
return QuestData.RANK_TITLES[this.rankIndex]; return QuestData.RANK_TITLES[this.rankIndex];
} }
/** @return int */
public int getWinStreakBest() {
return this.winstreakBest;
}
/** @return int */
public int getWinStreakCurrent() {
return this.winstreakCurrent;
}
// decks management // decks management
/** /**
* Gets the deck names. * Gets the deck names.
@@ -522,6 +562,11 @@ public final class QuestData {
return new ArrayList<String>(this.getMyDecks().keySet()); return new ArrayList<String>(this.getMyDecks().keySet());
} }
/** @return List<Deck> */
public List<Deck> getDecks() {
return new ArrayList<Deck>(this.getMyDecks().values());
}
/** /**
* Removes the deck. * Removes the deck.
* *
@@ -684,7 +729,8 @@ public final class QuestData {
this.myDecks = myDecks0; this.myDecks = myDecks0;
} }
public static final QuestPreconManager getPreconManager() { /** @return QuestPreconManager */
public static QuestPreconManager getPreconManager() {
return preconManager; return preconManager;
} }
@@ -726,4 +772,14 @@ public final class QuestData {
public void setVersionNumber(final int versionNumber0) { public void setVersionNumber(final int versionNumber0) {
this.versionNumber = versionNumber0; this.versionNumber = versionNumber0;
} }
/** @param s0 &emsp; {@link java.lang.String} */
public void setName(String s0) {
this.name = s0;
}
/** @return {@link java.lang.String} */
public String getName() {
return this.name;
}
} }

View File

@@ -74,21 +74,27 @@ public class QuestDataIO {
public QuestDataIO() { public QuestDataIO() {
} }
/** @return {@link forge.quest.data.QuestData} */
public static QuestData loadData() {
return QuestDataIO.loadData(ForgeProps.getFile(NewConstants.Quest.XMLDATA));
}
/** /**
* <p> * <p>
* loadData. * loadData.
* </p> * </p>
* *
* @return a {@link forge.quest.data.QuestData} object. * @param xmlSaveFile &emsp; {@link java.io.File}
* @return {@link forge.quest.data.QuestData}
*/ */
public static QuestData loadData() { public static QuestData loadData(final File xmlSaveFile) {
try { try {
// read file "questData"
QuestData data = null; QuestData data = null;
String name = xmlSaveFile.getName()
.substring(0, xmlSaveFile.getName().length() - 4);
final File xmlSaveFile = ForgeProps.getFile(NewConstants.Quest.XMLDATA);
if (!xmlSaveFile.exists()) { if (!xmlSaveFile.exists()) {
return new QuestData(); return new QuestData(name);
} }
final GZIPInputStream zin = new GZIPInputStream(new FileInputStream(xmlSaveFile)); final GZIPInputStream zin = new GZIPInputStream(new FileInputStream(xmlSaveFile));
@@ -109,6 +115,7 @@ public class QuestDataIO {
xStream.registerConverter(new GameTypeToXml()); xStream.registerConverter(new GameTypeToXml());
xStream.alias("CardPool", ItemPool.class); xStream.alias("CardPool", ItemPool.class);
data = (QuestData) xStream.fromXML(xml.toString()); data = (QuestData) xStream.fromXML(xml.toString());
data.setName(name);
if (data.getVersionNumber() != QuestData.CURRENT_VERSION_NUMBER) { if (data.getVersionNumber() != QuestData.CURRENT_VERSION_NUMBER) {
QuestDataIO.updateSaveFile(data, xml.toString()); QuestDataIO.updateSaveFile(data, xml.toString());
@@ -193,7 +200,7 @@ public class QuestDataIO {
xStream.registerConverter(new CardPoolToXml()); xStream.registerConverter(new CardPoolToXml());
xStream.alias("CardPool", ItemPool.class); xStream.alias("CardPool", ItemPool.class);
final File f = ForgeProps.getFile(NewConstants.Quest.XMLDATA); final File f = new File("res/quest/data/" + qd.getName() + ".dat");
final BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(f)); final BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(f));
final GZIPOutputStream zout = new GZIPOutputStream(bout); final GZIPOutputStream zout = new GZIPOutputStream(bout);
xStream.toXML(qd, zout); xStream.toXML(qd, zout);

View File

@@ -24,9 +24,11 @@ import java.util.List;
import java.util.Random; import java.util.Random;
import forge.AllZone; import forge.AllZone;
import forge.Singletons;
import forge.deck.DeckIO; import forge.deck.DeckIO;
import forge.properties.ForgeProps; import forge.properties.ForgeProps;
import forge.properties.NewConstants; import forge.properties.NewConstants;
import forge.quest.data.QuestPreferences.QPref;
import forge.util.FileUtil; import forge.util.FileUtil;
/** /**
@@ -58,6 +60,12 @@ public class QuestEventManager {
/** The all challenges. */ /** The all challenges. */
private List<QuestChallenge> allChallenges = null; private List<QuestChallenge> allChallenges = null;
private final QuestPreferences qpref;
/** */
public QuestEventManager() {
this.qpref = Singletons.getModel().getQuestPreferences();
}
/** /**
* <p> * <p>
* assembleAllEvents. * assembleAllEvents.
@@ -354,31 +362,32 @@ public class QuestEventManager {
* @return an array of {@link java.lang.String} objects. * @return an array of {@link java.lang.String} objects.
*/ */
public final List<QuestDuel> generateDuels() { public final List<QuestDuel> generateDuels() {
if (AllZone.getQuestData() == null) { return null; }
final int index = AllZone.getQuestData().getDifficultyIndex(); final int index = AllZone.getQuestData().getDifficultyIndex();
final List<QuestDuel> duelOpponents = new ArrayList<QuestDuel>(); final List<QuestDuel> duelOpponents = new ArrayList<QuestDuel>();
if (AllZone.getQuestData().getWin() < QuestPreferences.getWinsForMediumAI(index)) { if (AllZone.getQuestData().getWin() < qpref.getPreferenceInt(QPref.WINS_MEDIUMAI, index)) {
duelOpponents.add(QuestEventManager.getDuelOpponentByNumber(this.easyAIduels, 0)); duelOpponents.add(QuestEventManager.getDuelOpponentByNumber(this.easyAIduels, 0));
duelOpponents.add(QuestEventManager.getDuelOpponentByNumber(this.easyAIduels, 1)); duelOpponents.add(QuestEventManager.getDuelOpponentByNumber(this.easyAIduels, 1));
duelOpponents.add(QuestEventManager.getDuelOpponentByNumber(this.easyAIduels, 2)); duelOpponents.add(QuestEventManager.getDuelOpponentByNumber(this.easyAIduels, 2));
} else if (AllZone.getQuestData().getWin() == QuestPreferences.getWinsForMediumAI(index)) { } else if (AllZone.getQuestData().getWin() == qpref.getPreferenceInt(QPref.WINS_MEDIUMAI, index)) {
duelOpponents.add(QuestEventManager.getDuelOpponentByNumber(this.easyAIduels, 0)); duelOpponents.add(QuestEventManager.getDuelOpponentByNumber(this.easyAIduels, 0));
duelOpponents.add(QuestEventManager.getDuelOpponentByNumber(this.mediumAIduels, 0)); duelOpponents.add(QuestEventManager.getDuelOpponentByNumber(this.mediumAIduels, 0));
duelOpponents.add(QuestEventManager.getDuelOpponentByNumber(this.mediumAIduels, 1)); duelOpponents.add(QuestEventManager.getDuelOpponentByNumber(this.mediumAIduels, 1));
} else if (AllZone.getQuestData().getWin() < QuestPreferences.getWinsForHardAI(index)) { } else if (AllZone.getQuestData().getWin() < qpref.getPreferenceInt(QPref.WINS_HARDAI, index)) {
duelOpponents.add(QuestEventManager.getDuelOpponentByNumber(this.mediumAIduels, 0)); duelOpponents.add(QuestEventManager.getDuelOpponentByNumber(this.mediumAIduels, 0));
duelOpponents.add(QuestEventManager.getDuelOpponentByNumber(this.mediumAIduels, 1)); duelOpponents.add(QuestEventManager.getDuelOpponentByNumber(this.mediumAIduels, 1));
duelOpponents.add(QuestEventManager.getDuelOpponentByNumber(this.mediumAIduels, 2)); duelOpponents.add(QuestEventManager.getDuelOpponentByNumber(this.mediumAIduels, 2));
} }
else if (AllZone.getQuestData().getWin() == QuestPreferences.getWinsForHardAI(index)) { else if (AllZone.getQuestData().getWin() == qpref.getPreferenceInt(QPref.WINS_HARDAI, index)) {
duelOpponents.add(QuestEventManager.getDuelOpponentByNumber(this.mediumAIduels, 0)); duelOpponents.add(QuestEventManager.getDuelOpponentByNumber(this.mediumAIduels, 0));
duelOpponents.add(QuestEventManager.getDuelOpponentByNumber(this.hardAIduels, 0)); duelOpponents.add(QuestEventManager.getDuelOpponentByNumber(this.hardAIduels, 0));
duelOpponents.add(QuestEventManager.getDuelOpponentByNumber(this.hardAIduels, 1)); duelOpponents.add(QuestEventManager.getDuelOpponentByNumber(this.hardAIduels, 1));
} }
else if (AllZone.getQuestData().getWin() < QuestPreferences.getWinsForVeryHardAI(index)) { else if (AllZone.getQuestData().getWin() < qpref.getPreferenceInt(QPref.WINS_EXPERTAI, index)) {
duelOpponents.add(QuestEventManager.getDuelOpponentByNumber(this.hardAIduels, 0)); duelOpponents.add(QuestEventManager.getDuelOpponentByNumber(this.hardAIduels, 0));
duelOpponents.add(QuestEventManager.getDuelOpponentByNumber(this.hardAIduels, 1)); duelOpponents.add(QuestEventManager.getDuelOpponentByNumber(this.hardAIduels, 1));
duelOpponents.add(QuestEventManager.getDuelOpponentByNumber(this.hardAIduels, 2)); duelOpponents.add(QuestEventManager.getDuelOpponentByNumber(this.hardAIduels, 2));
@@ -401,6 +410,8 @@ public class QuestEventManager {
* @return a {@link java.util.List} object. * @return a {@link java.util.List} object.
*/ */
public final List<QuestChallenge> generateChallenges() { public final List<QuestChallenge> generateChallenges() {
if (AllZone.getQuestData() == null) { return null; }
final forge.quest.data.QuestData questData = AllZone.getQuestData(); final forge.quest.data.QuestData questData = AllZone.getQuestData();
final List<QuestChallenge> challengeOpponents = new ArrayList<QuestChallenge>(); final List<QuestChallenge> challengeOpponents = new ArrayList<QuestChallenge>();

File diff suppressed because it is too large Load Diff

View File

@@ -24,6 +24,7 @@ import java.util.Map.Entry;
import net.slightlymagic.braids.util.lambda.Lambda1; import net.slightlymagic.braids.util.lambda.Lambda1;
import net.slightlymagic.maxmtg.Predicate; import net.slightlymagic.maxmtg.Predicate;
import forge.SetUtils; import forge.SetUtils;
import forge.Singletons;
import forge.card.BoosterGenerator; import forge.card.BoosterGenerator;
import forge.card.BoosterUtils; import forge.card.BoosterUtils;
import forge.card.CardRarity; import forge.card.CardRarity;
@@ -36,6 +37,7 @@ import forge.item.InventoryItem;
import forge.item.ItemPool; import forge.item.ItemPool;
import forge.item.ItemPoolView; import forge.item.ItemPoolView;
import forge.item.PreconDeck; import forge.item.PreconDeck;
import forge.quest.data.QuestPreferences.QPref;
import forge.util.MyRandom; import forge.util.MyRandom;
/** /**
@@ -44,6 +46,7 @@ import forge.util.MyRandom;
*/ */
public final class QuestUtilCards { public final class QuestUtilCards {
private final QuestData q; private final QuestData q;
private final QuestPreferences qpref;
/** /**
* Instantiates a new quest util cards. * Instantiates a new quest util cards.
@@ -53,6 +56,7 @@ public final class QuestUtilCards {
*/ */
public QuestUtilCards(final QuestData qd) { public QuestUtilCards(final QuestData qd) {
this.q = qd; this.q = qd;
this.qpref = Singletons.getModel().getQuestPreferences();
} }
/** /**
@@ -93,9 +97,9 @@ public final class QuestUtilCards {
* @return the array list * @return the array list
*/ */
public ArrayList<CardPrinted> addCards(final Predicate<CardPrinted> fSets) { public ArrayList<CardPrinted> addCards(final Predicate<CardPrinted> fSets) {
final int nCommon = QuestPreferences.getNumCommon(); final int nCommon = qpref.getPreferenceInt(QPref.BOOSTER_COMMONS);
final int nUncommon = QuestPreferences.getNumUncommon(); final int nUncommon = qpref.getPreferenceInt(QPref.BOOSTER_UNCOMMONS);
final int nRare = QuestPreferences.getNumRare(); final int nRare = qpref.getPreferenceInt(QPref.BOOSTER_RARES);
final ArrayList<CardPrinted> newCards = new ArrayList<CardPrinted>(); final ArrayList<CardPrinted> newCards = new ArrayList<CardPrinted>();
newCards.addAll(BoosterUtils.generateCards(fSets, nCommon, CardRarity.Common, null)); newCards.addAll(BoosterUtils.generateCards(fSets, nCommon, CardRarity.Common, null));
@@ -166,9 +170,9 @@ public final class QuestUtilCards {
* the idx difficulty * the idx difficulty
*/ */
public void setupNewGameCardPool(final Predicate<CardPrinted> filter, final int idxDifficulty) { public void setupNewGameCardPool(final Predicate<CardPrinted> filter, final int idxDifficulty) {
final int nC = QuestPreferences.getStartingCommons(idxDifficulty); final int nC = qpref.getPreferenceInt(QPref.STARTING_COMMONS, idxDifficulty);
final int nU = QuestPreferences.getStartingUncommons(idxDifficulty); final int nU = qpref.getPreferenceInt(QPref.STARTING_UNCOMMONS, idxDifficulty);
final int nR = QuestPreferences.getStartingRares(idxDifficulty); final int nR = qpref.getPreferenceInt(QPref.STARTING_RARES, idxDifficulty);
this.addAllCards(BoosterUtils.getQuestStarterDeck(filter, nC, nU, nR)); this.addAllCards(BoosterUtils.getQuestStarterDeck(filter, nC, nU, nR));
} }

View File

@@ -43,7 +43,6 @@ import forge.error.ErrorViewer;
import forge.gui.GuiUtils; import forge.gui.GuiUtils;
import forge.quest.data.QuestData; import forge.quest.data.QuestData;
import forge.quest.data.QuestDataIO; import forge.quest.data.QuestDataIO;
import forge.quest.data.QuestPreferences;
/** /**
* <p> * <p>
@@ -131,7 +130,7 @@ public class QuestOptions extends JFrame {
* </p> * </p>
*/ */
private void setupRadioButtonText() { private void setupRadioButtonText() {
final String[] diff = QuestPreferences.getDifficulty(); /*final String[] diff = QuestPreferences.getDifficulty();
final JRadioButton[] b = { this.easyRadio, this.mediumRadio, this.hardRadio, this.veryHardRadio }; final JRadioButton[] b = { this.easyRadio, this.mediumRadio, this.hardRadio, this.veryHardRadio };
for (int i = 0; i < diff.length; i++) { for (int i = 0; i < diff.length; i++) {
@@ -140,7 +139,7 @@ public class QuestOptions extends JFrame {
final int numGames = numberLevels * QuestPreferences.getWinsForRankIncrease(i); final int numGames = numberLevels * QuestPreferences.getWinsForRankIncrease(i);
b[i].setText(String.format("%s - %d", diff[i], numGames)); b[i].setText(String.format("%s - %d", diff[i], numGames));
} }*/
} // setupRadioButtonText() } // setupRadioButtonText()

View File

@@ -49,6 +49,7 @@ import forge.quest.data.QuestChallenge;
import forge.quest.data.QuestData; import forge.quest.data.QuestData;
import forge.quest.data.QuestEvent; import forge.quest.data.QuestEvent;
import forge.quest.data.QuestPreferences; import forge.quest.data.QuestPreferences;
import forge.quest.data.QuestPreferences.QPref;
import forge.quest.data.QuestUtil; import forge.quest.data.QuestUtil;
import forge.util.MyRandom; import forge.util.MyRandom;
import forge.view.GuiTopLevel; import forge.view.GuiTopLevel;
@@ -75,13 +76,14 @@ public class QuestWinLoseHandler extends ControlWinLose {
/** String constraint parameters for title blocks and cardviewer blocks. */ /** String constraint parameters for title blocks and cardviewer blocks. */
private final String constraintsTitle = "w 95%!, gap 0 0 20px 10px"; private final String constraintsTitle = "w 95%!, gap 0 0 20px 10px";
private final String constraintsText = "w 95%!,, h 150px!, gap 0 0 0 20px"; private final String constraintsText = "w 95%!,, h 180px!, gap 0 0 0 20px";
private final String constraintsCards = "w 95%!, h 330px!, gap 0 0 0 20px"; private final String constraintsCards = "w 95%!, h 330px!, gap 0 0 0 20px";
private class CommonObjects { private class CommonObjects {
private FMatchState matchState; private FMatchState matchState;
private QuestData qData; private QuestData qData;
private QuestEvent qEvent; private QuestEvent qEvent;
private QuestPreferences qPrefs;
} }
private final CommonObjects model; private final CommonObjects model;
@@ -98,6 +100,7 @@ public class QuestWinLoseHandler extends ControlWinLose {
this.model.matchState = AllZone.getMatchState(); this.model.matchState = AllZone.getMatchState();
this.model.qData = AllZone.getQuestData(); this.model.qData = AllZone.getQuestData();
this.model.qEvent = AllZone.getQuestEvent(); this.model.qEvent = AllZone.getQuestEvent();
this.model.qPrefs = Singletons.getModel().getQuestPreferences();
this.wonMatch = this.model.matchState.isMatchWonBy(AllZone.getHumanPlayer().getName()); this.wonMatch = this.model.matchState.isMatchWonBy(AllZone.getHumanPlayer().getName());
this.skin = Singletons.getView().getSkin(); this.skin = Singletons.getView().getSkin();
this.isAnte = Singletons.getModel().getPreferences().isPlayForAnte(); this.isAnte = Singletons.getModel().getPreferences().isPlayForAnte();
@@ -217,7 +220,7 @@ public class QuestWinLoseHandler extends ControlWinLose {
// Win or lose, still a chance to win a booster, frequency set in // Win or lose, still a chance to win a booster, frequency set in
// preferences // preferences
final int outcome = this.wonMatch ? this.model.qData.getWin() : this.model.qData.getLost(); final int outcome = this.wonMatch ? this.model.qData.getWin() : this.model.qData.getLost();
if ((outcome % QuestPreferences.getWinsForBooster(this.model.qData.getDifficultyIndex())) == 0) { if ((outcome % this.model.qPrefs.getPreferenceInt(QPref.WINS_BOOSTER, this.model.qData.getDifficultyIndex())) == 0) {
this.awardBooster(); this.awardBooster();
} }
@@ -274,12 +277,14 @@ public class QuestWinLoseHandler extends ControlWinLose {
*/ */
@Override @Override
public final void actionOnQuit() { public final void actionOnQuit() {
int x = Singletons.getModel().getQuestPreferences().getPreferenceInt(QPref.PENALTY_LOSS);
// Record win/loss in quest data // Record win/loss in quest data
if (this.wonMatch) { if (this.wonMatch) {
this.model.qData.addWin(); this.model.qData.addWin();
} else { } else {
this.model.qData.addLost(); this.model.qData.addLost();
this.model.qData.subtractCredits(15); this.model.qData.subtractCredits(x);
} }
this.model.qData.getCards().clearShopList(); this.model.qData.getCards().clearShopList();
@@ -317,7 +322,7 @@ public class QuestWinLoseHandler extends ControlWinLose {
int credEstates = 0; int credEstates = 0;
// Basic win bonus // Basic win bonus
final int base = QuestPreferences.getMatchRewardBase(); final int base = this.model.qPrefs.getPreferenceInt(QPref.REWARDS_BASE);
double multiplier = 1; double multiplier = 1;
String diff = AllZone.getQuestEvent().getDifficulty(); String diff = AllZone.getQuestEvent().getDifficulty();
@@ -332,8 +337,11 @@ public class QuestWinLoseHandler extends ControlWinLose {
} else if (diff.equalsIgnoreCase("expert")) { } else if (diff.equalsIgnoreCase("expert")) {
multiplier = 3; multiplier = 3;
} }
credBase += (int) ((base * multiplier) + (QuestPreferences.getMatchRewardTotalWins() * this.model.qData
.getWin())); credBase += (int) ((base * multiplier)
+ (Double.parseDouble(this.model.qPrefs.getPreference(QPref.REWARDS_WINS_MULTIPLIER))
* this.model.qData.getWin()));
sb.append(diff + " opponent: " + credBase + " credits.<br>"); sb.append(diff + " opponent: " + credBase + " credits.<br>");
// Gameplay bonuses (for each game win) // Gameplay bonuses (for each game win)
boolean hasNeverLost = true; boolean hasNeverLost = true;
@@ -375,7 +383,7 @@ public class QuestWinLoseHandler extends ControlWinLose {
} }
// Mulligan to zero // Mulligan to zero
final int cntCardsHumanStartedWith = humanRating.getOpeningHandSize(); final int cntCardsHumanStartedWith = humanRating.getOpeningHandSize();
final int mulliganReward = QuestPreferences.getMatchMullToZero(); final int mulliganReward = this.model.qPrefs.getPreferenceInt(QPref.REWARDS_MULLIGAN0);
if (0 == cntCardsHumanStartedWith) { if (0 == cntCardsHumanStartedWith) {
credGameplay += mulliganReward; credGameplay += mulliganReward;
@@ -407,8 +415,8 @@ public class QuestWinLoseHandler extends ControlWinLose {
// Undefeated bonus // Undefeated bonus
if (hasNeverLost) { if (hasNeverLost) {
credUndefeated += QuestPreferences.getMatchRewardNoLosses(); credUndefeated += this.model.qPrefs.getPreferenceInt(QPref.REWARDS_UNDEFEATED);
final int reward = QuestPreferences.getMatchRewardNoLosses(); final int reward = this.model.qPrefs.getPreferenceInt(QPref.REWARDS_UNDEFEATED);
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));
} }
@@ -581,11 +589,12 @@ public class QuestWinLoseHandler extends ControlWinLose {
} }
private void penalizeLoss() { private void penalizeLoss() {
int x = Singletons.getModel().getQuestPreferences().getPreferenceInt(QPref.PENALTY_LOSS);
this.icoTemp = GuiUtils.getResizedIcon("HeartIcon.png", 0.5); this.icoTemp = GuiUtils.getResizedIcon("HeartIcon.png", 0.5);
this.lblTemp1 = new TitleLabel("Gameplay Results"); this.lblTemp1 = new TitleLabel("Gameplay Results");
this.lblTemp2 = new JLabel("You lose! You have lost 15 credits."); this.lblTemp2 = new JLabel("You lose! You have lost " + x + " credits.");
this.lblTemp2.setFont(skin.getFont(14)); this.lblTemp2.setFont(skin.getFont(14));
this.lblTemp2.setForeground(Color.white); this.lblTemp2.setForeground(Color.white);
this.lblTemp2.setHorizontalAlignment(SwingConstants.CENTER); this.lblTemp2.setHorizontalAlignment(SwingConstants.CENTER);
@@ -625,18 +634,13 @@ public class QuestWinLoseHandler extends ControlWinLose {
case LifeReachedZero: case LifeReachedZero:
return 0; // nothing special here, ordinary kill return 0; // nothing special here, ordinary kill
case Milled: case Milled:
return QuestPreferences.getMatchRewardMilledWinBonus(); return this.model.qPrefs.getPreferenceInt(QPref.REWARDS_MILLED);
case Poisoned: case Poisoned:
return QuestPreferences.getMatchRewardPoisonWinBonus(); return this.model.qPrefs.getPreferenceInt(QPref.REWARDS_POISON);
case DidNotLoseYet: case DidNotLoseYet: // Felidar, Helix Pinnacle, etc.
return QuestPreferences.getMatchRewardAltWinBonus(); // Felidar, return this.model.qPrefs.getPreferenceInt(QPref.REWARDS_UNDEFEATED);
// Helix case SpellEffect: // Door to Nothingness, etc.
// Pinnacle, return this.model.qPrefs.getPreferenceInt(QPref.REWARDS_UNDEFEATED);
// etc.
case SpellEffect:
return QuestPreferences.getMatchRewardAltWinBonus(); // Door to
// Nothingness,
// etc.
default: default:
return 0; return 0;
} }
@@ -655,13 +659,13 @@ public class QuestWinLoseHandler extends ControlWinLose {
int credits = 0; int credits = 0;
if (iTurn == 1) { if (iTurn == 1) {
credits = QuestPreferences.getMatchRewardWinFirst(); credits = this.model.qPrefs.getPreferenceInt(QPref.REWARDS_TURN1);
} else if (iTurn <= 5) { } else if (iTurn <= 5) {
credits = QuestPreferences.getMatchRewardWinByFifth(); credits = this.model.qPrefs.getPreferenceInt(QPref.REWARDS_TURN5);
} else if (iTurn <= 10) { } else if (iTurn <= 10) {
credits = QuestPreferences.getMatchRewardWinByTen(); credits = this.model.qPrefs.getPreferenceInt(QPref.REWARDS_TURN10);
} else if (iTurn <= 15) { } else if (iTurn <= 15) {
credits = QuestPreferences.getMatchRewardWinByFifteen(); credits = this.model.qPrefs.getPreferenceInt(QPref.REWARDS_TURN15);
} }
return credits; return credits;

View File

@@ -22,6 +22,7 @@ import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent; import java.awt.event.ComponentEvent;
import javax.swing.AbstractAction; import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
@@ -262,4 +263,24 @@ public class HomeTopLevel extends FPanel {
public ControlHomeUI getController() { public ControlHomeUI getController() {
return control; return control;
} }
/** @return {@link javax.swing.JButton} */
public JButton getBtnConstructed() {
return this.btnConstructed;
}
/** @return {@link javax.swing.JButton} */
public JButton getBtnSealed() {
return this.btnSealed;
}
/** @return {@link javax.swing.JButton} */
public JButton getBtnDraft() {
return this.btnDraft;
}
/** @return {@link javax.swing.JButton} */
public JButton getBtnQuest() {
return this.btnQuest;
}
} }

View File

@@ -0,0 +1,335 @@
package forge.view.home;
import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.MatteBorder;
import net.miginfocom.swing.MigLayout;
import forge.Command;
import forge.Singletons;
import forge.gui.GuiUtils;
import forge.quest.data.QuestData;
import forge.view.toolbox.FLabel;
import forge.view.toolbox.FSkin;
/**
* Creates file list/table for quick deleting, editing, and basic info.
*
*/
@SuppressWarnings("serial")
public class QuestFileLister extends JPanel {
private ImageIcon icoDelete, icoDeleteOver, icoEdit, icoEditOver;
private FSkin skin;
private RowPanel previousSelect;
private RowPanel[] rows;
private Command cmdRowSelect, cmdRowDelete, cmdRowEdit;
private final Color clrDefault, clrHover, clrActive, clrBorders;
/** */
public QuestFileLister() {
this(true, true);
}
/**
* Creates deck list for selected decks for quick deleting, editing, and basic info.
* Set "selectable" and "editable" to show those buttons, or not.
*
* @param deletable {@link java.lang.Boolean}
* @param editable {@link java.lang.Boolean}
*/
public QuestFileLister(final boolean deletable, final boolean editable) {
super();
this.skin = Singletons.getView().getSkin();
this.clrDefault = new Color(0, 0, 0, 0);
this.clrHover = skin.getColor(FSkin.SkinProp.CLR_HOVER);
this.clrActive = skin.getColor(FSkin.SkinProp.CLR_ACTIVE);
this.clrBorders = skin.getColor(FSkin.SkinProp.CLR_BORDERS);
this.setOpaque(false);
this.setLayout(new MigLayout("insets 0, gap 0, wrap"));
icoDelete = new ImageIcon("res/images/icons/DeleteIcon.png");
icoDeleteOver = new ImageIcon("res/images/icons/DeleteIconOver.png");
icoEdit = new ImageIcon("res/images/icons/EditIcon.png");
icoEditOver = new ImageIcon("res/images/icons/EditIconOver.png");
}
/** @param qd0 &emsp; {@link forge.quest.data.QuestData}[] */
public void setQuests(QuestData[] qd0) {
this.removeAll();
List<RowPanel> tempRows = new ArrayList<RowPanel>();
// Title row
// Note: careful with the widths of the rows here;
// scroll panes will have difficulty dynamically resizing if 100% width is set.
final JPanel rowTitle = new JPanel();
rowTitle.setBackground(skin.getColor(FSkin.SkinProp.CLR_ZEBRA));
rowTitle.setLayout(new MigLayout("insets 0, gap 0"));
rowTitle.add(new FLabel("Delete", SwingConstants.CENTER), "w 15%!, h 20px!, gap 0 0 5px 0");
rowTitle.add(new FLabel("Edit", SwingConstants.CENTER), "w 15%!, h 20px!, gap 0 0 5px 0");
rowTitle.add(new FLabel("Name", SwingConstants.CENTER), "w 40%!, h 20px!, gap 0 0 5px 0");
rowTitle.add(new FLabel("Mode", SwingConstants.CENTER), "w 15%!, h 20px!, gap 0 0 5px 0");
rowTitle.add(new FLabel("Record", SwingConstants.CENTER), "w 15%!, h 20px!, gap 0 0 5px 0");
this.add(rowTitle, "w 98%!, h 30px!, gapleft 1%");
RowPanel row;
for (QuestData qd : qd0) {
row = new RowPanel(qd);
row.add(new DeleteButton(row), "w 15%!, h 20px!, gap 0 0 5px 0");
row.add(new EditButton(row), "w 15%!, h 20px!, gaptop 5px");
row.add(new FLabel(qd.getName()), "w 40%!, h 20px!, gap 0 0 5px 0");
row.add(new FLabel(qd.getMode(), SwingConstants.CENTER), "w 15%!, h 20px!, gap 0 0 5px 0");
row.add(new FLabel(qd.getWin() + "/" + qd.getLost(), SwingConstants.CENTER), "w 15%!, h 20px!, gap 0 0 5px 0");
this.add(row, "w 98%!, h 30px!, gap 1% 0 0 0");
tempRows.add(row);
}
rows = tempRows.toArray(new RowPanel[0]);
revalidate();
}
/** @return {@link forge.deck.Deck} */
public QuestData getSelectedQuest() {
return previousSelect.getQuestData();
}
private class DeleteButton extends JButton {
public DeleteButton(final RowPanel r0) {
super();
setRolloverEnabled(true);
setPressedIcon(icoDeleteOver);
setRolloverIcon(icoDeleteOver);
setIcon(icoDelete);
setOpaque(false);
setContentAreaFilled(false);
setBorder(null);
setBorderPainted(false);
setToolTipText("Delete this deck");
this.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
if (!r0.selected) {
r0.setBackground(clrHover);
r0.setOpaque(true);
}
}
@Override
public void mouseExited(MouseEvent e) {
if (!r0.selected) {
r0.setBackground(clrDefault);
r0.setOpaque(false);
}
}
@Override
public void mouseClicked(MouseEvent e) {
deleteFile(r0);
}
});
}
}
private class EditButton extends JButton {
public EditButton(final RowPanel r0) {
super();
setRolloverEnabled(true);
setPressedIcon(icoEditOver);
setRolloverIcon(icoEditOver);
setIcon(icoEdit);
setOpaque(false);
setContentAreaFilled(false);
setBorder(null);
setBorderPainted(false);
setToolTipText("Edit this deck");
this.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
if (!r0.selected) {
r0.setBackground(clrHover);
r0.setOpaque(true);
}
}
@Override
public void mouseExited(MouseEvent e) {
if (!r0.selected) {
r0.setBackground(clrDefault);
r0.setOpaque(false);
}
}
@Override
public void mouseClicked(MouseEvent e) {
editFileName(r0.getQuestData().getName());
}
});
}
}
private class RowPanel extends JPanel {
private boolean selected = false;
private QuestData questData;
public RowPanel(QuestData qd0) {
super();
setOpaque(false);
setBackground(new Color(0, 0, 0, 0));
setLayout(new MigLayout("insets 0, gap 0"));
setBorder(new MatteBorder(0, 0, 1, 0, clrBorders));
questData = qd0;
this.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
if (!selected) {
((RowPanel) e.getSource()).setBackground(clrHover);
((RowPanel) e.getSource()).setOpaque(true);
}
}
@Override
public void mouseExited(MouseEvent e) {
if (!selected) {
((RowPanel) e.getSource()).setBackground(clrDefault);
((RowPanel) e.getSource()).setOpaque(false);
}
}
@Override
public void mousePressed(MouseEvent e) {
selectHandler((RowPanel) e.getSource());
}
});
}
public void setSelected(boolean b0) {
selected = b0;
setOpaque(b0);
setBackground(b0 ? clrActive : clrHover);
}
public boolean isSelected() {
return selected;
}
public QuestData getQuestData() {
return questData;
}
}
/** @return {@link java.lang.Integer} */
public int getSelectedIndex() {
for (int i = 0; i < rows.length; i++) {
if (rows[i].isSelected()) { return i; }
}
return -1;
}
/** Selects a row programatically.
* @param i0 &emsp; int
* @return boolean success
*/
public boolean setSelectedIndex(int i0) {
if (i0 >= rows.length) { return false; }
selectHandler(rows[i0]);
return true;
}
/**
* @param qd0 &emsp; Quest data object to select (if exists in list)
* @return boolean success
*/
public boolean setSelectedQuestData(QuestData qd0) {
for (RowPanel r : rows) {
if (r.getQuestData().getName().equals(qd0.getName())) {
selectHandler(r);
return true;
}
}
return false;
}
/** @param c0 &emsp; {@link forge.Command} command executed on row select. */
public void setSelectCommand(Command c0) {
this.cmdRowSelect = c0;
}
/** @param c0 &emsp; {@link forge.Command} command executed on row edit. */
public void setEditCommand(Command c0) {
this.cmdRowEdit = c0;
}
/** @param c0 &emsp; {@link forge.Command} command executed on delete. */
public void setDeleteCommand(Command c0) {
this.cmdRowDelete = c0;
}
private void selectHandler(RowPanel r0) {
if (previousSelect != null) {
previousSelect.setSelected(false);
}
r0.setSelected(true);
previousSelect = r0;
if (cmdRowSelect != null) { cmdRowSelect.execute(); }
}
private void editFileName(String s0) {
final Object o = JOptionPane.showInputDialog(null,
"Rename Quest to:", "Quest Rename", JOptionPane.OK_CANCEL_OPTION);
if (o == null) { return; }
final String questName = GuiUtils.cleanString(o.toString());
boolean exists = false;
for (RowPanel r : rows) {
if (r.getQuestData().getName().equalsIgnoreCase(questName)) {
exists = true;
break;
}
}
if (exists || questName.equals("")) {
JOptionPane.showMessageDialog(null, "Please pick another quest name, a quest already has that name.");
return;
}
else {
File newpath = new File("res/quest/data/" + questName + ".dat");
File oldpath = new File("res/quest/data/" + s0 + ".dat");
oldpath.renameTo(newpath);
}
if (cmdRowEdit != null) { cmdRowEdit.execute(); }
}
private void deleteFile(RowPanel r0) {
final QuestData qd = r0.getQuestData();
final int n = JOptionPane.showConfirmDialog(null,
"Are you sure you want to delete \"" + qd.getName()
+ "\" ?", "Delete Deck", JOptionPane.YES_NO_OPTION);
if (n == JOptionPane.NO_OPTION) {
return;
}
new File("res/quest/data/" + r0.getQuestData().getName() + ".dat").delete();
if (cmdRowDelete != null) { cmdRowDelete.execute(); }
this.remove(r0);
this.repaint();
this.revalidate();
}
}

View File

@@ -0,0 +1,96 @@
package forge.view.home;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import forge.Singletons;
import forge.view.toolbox.FSkin;
/** Standardized tab for submenus in home screen. */
public class SubTab extends JPanel {
private static final long serialVersionUID = -2193833603356739321L;
private final Color clrBorders, clrHover;
private final MouseAdapter madHover;
private final FSkin skin;
private boolean enabled = false;
private boolean hovering = false;
private int w, h;
/** @param s0 &emsp; {@link java.lang.String} tab text */
public SubTab(String s0) {
super();
this.setOpaque(false);
this.skin = Singletons.getView().getSkin();
this.clrBorders = skin.getColor(FSkin.SkinProp.CLR_BORDERS);
this.clrHover = skin.getColor(FSkin.SkinProp.CLR_HOVER);
this.setCursor(new Cursor(Cursor.HAND_CURSOR));
this.madHover = new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
hovering = true;
repaint();
}
@Override
public void mouseExited(MouseEvent e) {
hovering = false;
repaint();
}
};
this.removeMouseListener(madHover);
this.addMouseListener(madHover);
final JLabel lbl = new JLabel(s0);
lbl.setForeground(skin.getColor(FSkin.SkinProp.CLR_TEXT));
lbl.setFont(skin.getFont(12));
this.add(lbl);
}
/** @param b0 &emsp; {@link java.lang.Boolean} */
public void setEnabled(boolean b0) {
this.enabled = b0;
this.repaint();
}
/** @return {@link java.lang.Boolean} */
public boolean isEnabled() {
return this.enabled;
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
w = getWidth();
h = getHeight();
g.setColor(clrBorders);
if (this.enabled) {
g.drawLine(0, h - 1, 3, h - 1); // SW
g.drawLine(3, 10, 3, h); // W
g.drawArc(3, 0, 20, 20, 90, 90); //NW
g.drawLine(13, 0, w - 13, 0); //N
g.drawArc(w - 23, 0, 20, 20, 90, -90); //NE
g.drawLine(w - 3, 10, w - 3, h); //E
g.drawLine(w - 3, h - 1, w, h - 1); //SE
}
else if (this.hovering) {
g.drawLine(0, h - 1, w, h - 1);
g.setColor(clrHover);
g.fillArc(3, 0, 20, 20, 90, 90); //NW
g.fillArc(w - 23, 0, 20, 20, 90, -90); //NE
g.fillRect(3, 10, w - 6, h - 12); // Bottom
g.fillRect(13, 0, w - 26, 10); // Top
}
else {
g.drawLine(0, h - 1, w, h - 1);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,386 @@
package forge.view.home;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import net.miginfocom.swing.MigLayout;
import forge.Singletons;
import forge.quest.data.QuestPreferences;
import forge.quest.data.QuestPreferences.QPref;
import forge.view.toolbox.FLabel;
import forge.view.toolbox.FSkin;
/**
* TODO: Write javadoc for this type.
*
*/
@SuppressWarnings("serial")
public class ViewQuestPreferences extends JPanel {
private final FSkin skin;
private final QuestPreferences prefs;
private final JPanel pnlDifficulty, pnlBooster, pnlRewards;
private final FLabel lblErrRewards, lblErrBooster, lblErrDifficulty;
private String constraints1, constraints2;
private enum ErrType {
REWARDS,
DIFFICULTY,
BOOSTER
}
/** */
public ViewQuestPreferences() {
this.setOpaque(false);
this.setLayout(new MigLayout("insets 0, gap 0, wrap"));
this.skin = Singletons.getView().getSkin();
this.prefs = Singletons.getModel().getQuestPreferences();
pnlRewards = new JPanel();
pnlDifficulty = new JPanel();
pnlBooster = new JPanel();
lblErrRewards = new FLabel("Rewards Error");
lblErrDifficulty = new FLabel("Difficulty Error");
lblErrBooster = new FLabel("Booster Error");
lblErrRewards.setForeground(Color.red);
lblErrRewards.setFontStyle(Font.BOLD);
lblErrDifficulty.setForeground(Color.red);
lblErrDifficulty.setFontStyle(Font.BOLD);
lblErrBooster.setForeground(Color.red);
lblErrBooster.setFontStyle(Font.BOLD);
// Rewards panel
pnlRewards.setOpaque(false);
pnlRewards.setLayout(new MigLayout("insets 0, gap 0, wrap 2"));
pnlRewards.add(new FLabel("Rewards", new ImageIcon("res/images/icons/CoinIcon.png")), "w 100%!, h 30px!, span 2 1");
pnlRewards.add(lblErrRewards, "w 100%!, h 30px!, span 2 1");
constraints1 = "w 60px, h 26px!";
constraints2 = "w 150px!, h 26px!";
pnlRewards.add(new FLabel("Base winnings"), constraints2);
pnlRewards.add(new PrefInput(QPref.REWARDS_BASE, ErrType.REWARDS), constraints1);
pnlRewards.add(new FLabel("No losses"), constraints2);
pnlRewards.add(new PrefInput(QPref.REWARDS_UNDEFEATED, ErrType.REWARDS), constraints1);
pnlRewards.add(new FLabel("Poison win"), constraints2);
pnlRewards.add(new PrefInput(QPref.REWARDS_POISON, ErrType.REWARDS), constraints1);
pnlRewards.add(new FLabel("Milling win"), constraints2);
pnlRewards.add(new PrefInput(QPref.REWARDS_MILLED, ErrType.REWARDS), constraints1);
pnlRewards.add(new FLabel("Mulligan 0 win"), constraints2);
pnlRewards.add(new PrefInput(QPref.REWARDS_MULLIGAN0, ErrType.REWARDS), constraints1);
pnlRewards.add(new FLabel("Alternative win"), constraints2);
pnlRewards.add(new PrefInput(QPref.REWARDS_ALTERNATIVE, ErrType.REWARDS), constraints1);
pnlRewards.add(new FLabel("Win by turn 15"), constraints2);
pnlRewards.add(new PrefInput(QPref.REWARDS_TURN15, ErrType.REWARDS), constraints1);
pnlRewards.add(new FLabel("Win by turn 10"), constraints2);
pnlRewards.add(new PrefInput(QPref.REWARDS_TURN10, ErrType.REWARDS), constraints1);
pnlRewards.add(new FLabel("Win by turn 5"), constraints2);
pnlRewards.add(new PrefInput(QPref.REWARDS_TURN5, ErrType.REWARDS), constraints1);
pnlRewards.add(new FLabel("First turn win"), constraints2);
pnlRewards.add(new PrefInput(QPref.REWARDS_TURN1, ErrType.REWARDS), constraints1);
// Difficulty table panel
pnlDifficulty.setOpaque(false);
pnlDifficulty.setLayout(new MigLayout("insets 0, gap 0, wrap 5"));
pnlDifficulty.add(new FLabel("Difficulty Adjustments", new ImageIcon("res/images/icons/NotesIcon.png")), "w 100%!, h 30px!, span 5 1");
pnlDifficulty.add(lblErrDifficulty, "w 100%!, h 30px!, span 5 1");
constraints1 = "w 60px!, h 26px!";
constraints2 = "w 150px!, h 26px!";
pnlDifficulty.add(new FLabel(""), constraints2);
pnlDifficulty.add(new FLabel("Easy"), constraints1);
pnlDifficulty.add(new FLabel("Medium"), constraints1);
pnlDifficulty.add(new FLabel("Hard"), constraints1);
pnlDifficulty.add(new FLabel("Expert"), constraints1);
pnlDifficulty.add(new FLabel("Wins For Booster"), constraints2);
pnlDifficulty.add(new PrefInput(QPref.WINS_BOOSTER_EASY, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.WINS_BOOSTER_MEDIUM, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.WINS_BOOSTER_HARD, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.WINS_BOOSTER_EXPERT, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new FLabel("Wins For Rank Increase"), constraints2);
pnlDifficulty.add(new PrefInput(QPref.WINS_RANKUP_EASY, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.WINS_RANKUP_MEDIUM, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.WINS_RANKUP_HARD, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.WINS_RANKUP_EXPERT, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new FLabel("Wins For Medium AI"), constraints2);
pnlDifficulty.add(new PrefInput(QPref.WINS_MEDIUMAI_EASY, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.WINS_MEDIUMAI_MEDIUM, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.WINS_MEDIUMAI_HARD, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.WINS_MEDIUMAI_EXPERT, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new FLabel("Wins For Hard AI"), constraints2);
pnlDifficulty.add(new PrefInput(QPref.WINS_HARDAI_EASY, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.WINS_HARDAI_MEDIUM, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.WINS_HARDAI_HARD, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.WINS_HARDAI_EXPERT, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new FLabel("Wins For Expert AI"), constraints2);
pnlDifficulty.add(new PrefInput(QPref.WINS_EXPERTAI_EASY, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.WINS_EXPERTAI_MEDIUM, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.WINS_EXPERTAI_HARD, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.WINS_EXPERTAI_EXPERT, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new FLabel("Starting commons"), constraints2);
pnlDifficulty.add(new PrefInput(QPref.STARTING_COMMONS_EASY, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.STARTING_COMMONS_MEDIUM, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.STARTING_COMMONS_HARD, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.STARTING_COMMONS_EXPERT, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new FLabel("Starting uncommons"), constraints2);
pnlDifficulty.add(new PrefInput(QPref.STARTING_UNCOMMONS_EASY, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.STARTING_UNCOMMONS_MEDIUM, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.STARTING_UNCOMMONS_HARD, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.STARTING_UNCOMMONS_EXPERT, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new FLabel("Starting rares"), constraints2);
pnlDifficulty.add(new PrefInput(QPref.STARTING_RARES_EASY, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.STARTING_RARES_MEDIUM, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.STARTING_RARES_HARD, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.STARTING_RARES_EXPERT, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new FLabel("Starting credits"), constraints2);
pnlDifficulty.add(new PrefInput(QPref.STARTING_CREDITS_EASY, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.STARTING_CREDITS_MEDIUM, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.STARTING_CREDITS_HARD, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.STARTING_CREDITS_EXPERT, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new FLabel("Starting basic lands"), constraints2);
pnlDifficulty.add(new PrefInput(QPref.STARTING_BASIC_LANDS, ErrType.DIFFICULTY), constraints1 + ", wrap");
pnlDifficulty.add(new FLabel("Starting snow lands"), constraints2);
pnlDifficulty.add(new PrefInput(QPref.STARTING_SNOW_LANDS, ErrType.DIFFICULTY), constraints1 + ", wrap");
pnlDifficulty.add(new FLabel("Penalty for loss"), constraints2);
pnlDifficulty.add(new PrefInput(QPref.PENALTY_LOSS, ErrType.DIFFICULTY), constraints1 + ", wrap");
// Booster breakdown panel
pnlBooster.setOpaque(false);
pnlBooster.setLayout(new MigLayout("insets 0, gap 0, wrap 2"));
pnlBooster.add(new FLabel("Booster Pack Ratios", new ImageIcon("res/images/icons/BookIcon.png")), "w 100%!, h 30px!, span 2 1");
pnlBooster.add(lblErrBooster, "w 100%!, h 30px!, span 2 1");
constraints1 = "w 60px!, h 26px!";
constraints2 = "w 150px!, h 26px!";
pnlBooster.add(new FLabel("Common"), constraints2);
pnlBooster.add(new PrefInput(QPref.BOOSTER_COMMONS, ErrType.BOOSTER), constraints1);
pnlBooster.add(new FLabel("Uncommon"), constraints2);
pnlBooster.add(new PrefInput(QPref.BOOSTER_UNCOMMONS, ErrType.BOOSTER), constraints1);
pnlBooster.add(new FLabel("Rare"), constraints2);
pnlBooster.add(new PrefInput(QPref.BOOSTER_RARES, ErrType.BOOSTER), constraints1);
constraints1 = "w 100%!, gap 0 0 20px 0";
this.add(pnlRewards, constraints1);
this.add(pnlDifficulty, constraints1);
this.add(pnlBooster, constraints1);
resetErrors();
}
private class PrefInput extends JTextField {
private final QPref qpref;
private final ErrType err;
private final Color clrHover, clrActive, clrText;
private boolean isFocus = false;
private String previousText = "";
/**
* @param qp1 &emsp; {@link forge.quest.data.QuestPreferences.QPref}
* preferences ident enum
* @param e0 &emsp; {@link forge.view.home.ViewQuestPreference.ErrType}
* where error should display to
*/
public PrefInput(QPref qp0, ErrType e0) {
super();
this.qpref = qp0;
this.err = e0;
this.clrHover = skin.getColor(FSkin.SkinProp.CLR_HOVER);
this.clrActive = skin.getColor(FSkin.SkinProp.CLR_ACTIVE);
this.clrText = skin.getColor(FSkin.SkinProp.CLR_TEXT);
this.setOpaque(false);
this.setBorder(null);
this.setFont(skin.getFont(13));
this.setForeground(clrText);
this.setCaretColor(clrText);
this.setBackground(clrHover);
this.setHorizontalAlignment(SwingConstants.CENTER);
this.setText(prefs.getPreference(qpref));
this.setPreviousText(prefs.getPreference(qpref));
this.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
if (isFocus) { return; }
setOpaque(true);
repaint();
}
@Override
public void mouseExited(MouseEvent e) {
if (isFocus) { return; }
setOpaque(false);
repaint();
}
});
this.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
isFocus = true;
setOpaque(true);
setBackground(clrActive);
}
@Override
public void focusLost(FocusEvent e) {
isFocus = false;
setOpaque(false);
setBackground(clrHover);
// TODO for slight performance improvement
// check if value has changed before validating
validateAndSave(PrefInput.this);
}
});
}
public QPref getQPref() {
return this.qpref;
}
public ErrType getErrType() {
return this.err;
}
public String getPreviousText() {
return this.previousText;
}
public void setPreviousText(String s0) {
this.previousText = s0;
}
}
private int temp1, temp2;
/**
* Checks validity of values entered into prefInputs.
* @param i0 &emsp; a PrefInput object
*/
private void validateAndSave(PrefInput i0) {
if (i0.getText().equals(i0.getPreviousText())) { return; }
int val = Integer.parseInt(i0.getText());
resetErrors();
switch (i0.getQPref()) {
case STARTING_CREDITS_EASY: case STARTING_CREDITS_MEDIUM:
case STARTING_CREDITS_HARD: case STARTING_CREDITS_EXPERT:
case REWARDS_MILLED: case REWARDS_MULLIGAN0:
case REWARDS_ALTERNATIVE: case REWARDS_TURN5:
if (val > 500) {
showError(i0, "Value too large (maximum 500).");
return;
}
break;
case BOOSTER_COMMONS:
temp1 = prefs.getPreferenceInt(QPref.BOOSTER_UNCOMMONS);
temp2 = prefs.getPreferenceInt(QPref.BOOSTER_RARES);
if (temp1 + temp2 + val > 15) {
showError(i0, "Booster packs must have maximum 15 cards.");
return;
}
break;
case BOOSTER_UNCOMMONS:
temp1 = prefs.getPreferenceInt(QPref.BOOSTER_COMMONS);
temp2 = prefs.getPreferenceInt(QPref.BOOSTER_RARES);
if (temp1 + temp2 + val > 15) {
showError(i0, "Booster packs must have maximum 15 cards.");
return;
}
break;
case BOOSTER_RARES:
temp1 = prefs.getPreferenceInt(QPref.BOOSTER_COMMONS);
temp2 = prefs.getPreferenceInt(QPref.BOOSTER_UNCOMMONS);
if (temp1 + temp2 + val > 15) {
showError(i0, "Booster packs must have maximum 15 cards.");
return;
}
break;
case REWARDS_TURN1:
if (val > 2000) {
showError(i0, "Value too large (maximum 2000).");
return;
}
break;
default:
if (val > 100) {
showError(i0, "Value too large (maximum 100).");
return;
}
break;
}
prefs.setPreference(i0.getQPref(), i0.getText());
prefs.save();
i0.setPreviousText(i0.getText());
}
private void showError(PrefInput i0, String s0) {
String s = "Save failed: " + s0;
switch(i0.getErrType()) {
case BOOSTER:
lblErrBooster.setVisible(true);
lblErrBooster.setText(s);
break;
case DIFFICULTY:
lblErrDifficulty.setVisible(true);
lblErrDifficulty.setText(s);
break;
case REWARDS:
lblErrRewards.setVisible(true);
lblErrRewards.setText(s);
break;
default:
}
i0.setText(i0.getPreviousText());
}
private void resetErrors() {
lblErrBooster.setVisible(false);
lblErrDifficulty.setVisible(false);
lblErrRewards.setVisible(false);
}
}

View File

@@ -1,6 +1,7 @@
package forge.view.toolbox; package forge.view.toolbox;
import java.awt.Color; import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.io.File; import java.io.File;
@@ -18,12 +19,15 @@ import javax.swing.border.MatteBorder;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
import forge.AllZone; import forge.AllZone;
import forge.Command; import forge.Command;
import forge.Constant;
import forge.Singletons; import forge.Singletons;
import forge.deck.Deck; import forge.deck.Deck;
import forge.deck.DeckIO; import forge.deck.DeckIO;
import forge.deck.DeckManager; import forge.deck.DeckManager;
import forge.game.GameType; import forge.game.GameType;
import forge.gui.deckeditor.DeckEditorCommon; import forge.gui.deckeditor.DeckEditorCommon;
import forge.gui.deckeditor.DeckEditorQuest;
import forge.view.GuiTopLevel;
/** /**
* Creates deck list for selected decks for quick deleting, editing, and basic info. * Creates deck list for selected decks for quick deleting, editing, and basic info.
@@ -36,20 +40,20 @@ public class DeckLister extends JPanel {
private ImageIcon icoEdit; private ImageIcon icoEdit;
private ImageIcon icoEditOver; private ImageIcon icoEditOver;
private FSkin skin; private FSkin skin;
private RowPanel previousSelection = null; private RowPanel previousSelect;
private RowPanel[] rows; private RowPanel[] rows;
private GameType gametype; private GameType gametype;
private Command cmdExit; private Command cmdEditorExit, cmdDelete, cmdRowSelect;
private final Color clrDefault, clrHover, clrActive, clrBorders;
/** /**
* Creates deck list for selected decks for quick deleting, editing, and basic info. * Creates deck list for selected decks for quick deleting, editing, and basic info.
* "selectable" and "editable" assumed true. * "selectable" and "editable" assumed true.
* *
* @param gt0 {@link forge.game.GameType} * @param gt0 {@link forge.game.GameType}
* @param cmd0 {@link forge.Command}, when exiting deck editor
*/ */
public DeckLister(GameType gt0, Command cmd0) { public DeckLister(GameType gt0) {
this(gt0, cmd0, true, true); this(gt0, null);
} }
/** /**
@@ -58,14 +62,18 @@ public class DeckLister extends JPanel {
* *
* @param gt0 {@link forge.game.GameType} * @param gt0 {@link forge.game.GameType}
* @param cmd0 {@link forge.Command}, when exiting deck editor * @param cmd0 {@link forge.Command}, when exiting deck editor
* @param deletable {@link java.lang.Boolean}
* @param editable {@link java.lang.Boolean}
*/ */
public DeckLister(GameType gt0, Command cmd0, boolean deletable, boolean editable) { public DeckLister(GameType gt0, Command cmd0) {
super(); super();
skin = Singletons.getView().getSkin(); this.skin = Singletons.getView().getSkin();
gametype = gt0; this.gametype = gt0;
cmdExit = cmd0; this.cmdEditorExit = cmd0;
this.clrDefault = new Color(0, 0, 0, 0);
this.clrHover = skin.getColor(FSkin.SkinProp.CLR_HOVER);
this.clrActive = skin.getColor(FSkin.SkinProp.CLR_ACTIVE);
this.clrBorders = skin.getColor(FSkin.SkinProp.CLR_BORDERS);
this.setOpaque(false); this.setOpaque(false);
this.setLayout(new MigLayout("insets 0, gap 0, wrap")); this.setLayout(new MigLayout("insets 0, gap 0, wrap"));
@@ -83,18 +91,20 @@ public class DeckLister extends JPanel {
// Title row // Title row
// Note: careful with the widths of the rows here; // Note: careful with the widths of the rows here;
// scroll panes will have difficulty dynamically resizing if 100% width is set. // scroll panes will have difficulty dynamically resizing if 100% width is set.
JPanel rowTitle = new JPanel(); JPanel rowTitle = new TitlePanel();
rowTitle.setBackground(skin.getColor(FSkin.SkinProp.CLR_INACTIVE)); rowTitle.setBackground(skin.getColor(FSkin.SkinProp.CLR_ZEBRA));
rowTitle.setLayout(new MigLayout("insets 0, gap 0")); rowTitle.setLayout(new MigLayout("insets 0, gap 0"));
rowTitle.add(new TitleLabel("Delete"), "w 10%!, h 20px!, gaptop 5px"); rowTitle.add(new FLabel("Delete", SwingConstants.CENTER), "w 10%!, h 20px!, gaptop 5px");
rowTitle.add(new TitleLabel("Edit"), "w 10%!, h 20px!, gaptop 5px"); rowTitle.add(new FLabel("Edit", SwingConstants.CENTER), "w 10%!, h 20px!, gaptop 5px");
rowTitle.add(new TitleLabel("Deck Name"), "w 60%!, h 20px!, gaptop 5px"); rowTitle.add(new FLabel("Deck Name", SwingConstants.CENTER), "w 60%!, h 20px!, gaptop 5px");
rowTitle.add(new TitleLabel("Main"), "w 10%!, h 20px!, gaptop 5px"); rowTitle.add(new FLabel("Main", SwingConstants.CENTER), "w 10%!, h 20px!, gaptop 5px");
rowTitle.add(new TitleLabel("Side"), "w 10%!, h 20px!, gaptop 5px"); rowTitle.add(new FLabel("Side", SwingConstants.CENTER), "w 10%!, h 20px!, gaptop 5px");
this.add(rowTitle, "w 98%!, h 30px!, gapleft 1%"); this.add(rowTitle, "w 98%!, h 30px!, gapleft 1%");
RowPanel row; RowPanel row;
for (Deck d : decks0) { for (Deck d : decks0) {
if (d.getName() == null) { continue; }
row = new RowPanel(d); row = new RowPanel(d);
row.add(new DeleteButton(row), "w 10%!, h 20px!, gaptop 5px"); row.add(new DeleteButton(row), "w 10%!, h 20px!, gaptop 5px");
row.add(new EditButton(row), "w 10%!, h 20px!, gaptop 5px"); row.add(new EditButton(row), "w 10%!, h 20px!, gaptop 5px");
@@ -136,10 +146,18 @@ public class DeckLister extends JPanel {
this.addMouseListener(new MouseAdapter() { this.addMouseListener(new MouseAdapter() {
@Override @Override
public void mouseEntered(MouseEvent e) { public void mouseEntered(MouseEvent e) {
if (r0.selected) { return; } if (!r0.selected) {
r0.setBackground(skin.getColor(FSkin.SkinProp.CLR_HOVER)); r0.setBackground(clrHover);
r0.setOpaque(true); r0.setOpaque(true);
} }
}
@Override
public void mouseExited(MouseEvent e) {
if (!r0.selected) {
r0.setBackground(clrDefault);
r0.setOpaque(false);
}
}
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
deleteDeck(r0); deleteDeck(r0);
@@ -164,10 +182,18 @@ public class DeckLister extends JPanel {
this.addMouseListener(new MouseAdapter() { this.addMouseListener(new MouseAdapter() {
@Override @Override
public void mouseEntered(MouseEvent e) { public void mouseEntered(MouseEvent e) {
if (r0.selected) { return; } if (!r0.selected) {
r0.setBackground(skin.getColor(FSkin.SkinProp.CLR_HOVER)); r0.setBackground(clrHover);
r0.setOpaque(true); r0.setOpaque(true);
} }
}
@Override
public void mouseExited(MouseEvent e) {
if (!r0.selected) {
r0.setBackground(clrDefault);
r0.setOpaque(false);
}
}
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
editDeck(r0.getDeck()); editDeck(r0.getDeck());
@@ -176,30 +202,43 @@ public class DeckLister extends JPanel {
} }
} }
// Here only to prevent visual artifact problems from translucent skin colors.
private class TitlePanel extends JPanel {
@Override
public void paintComponent(Graphics g) {
g.setColor(getBackground());
g.clearRect(0, 0, getWidth(), getHeight());
g.fillRect(0, 0, getWidth(), getHeight());
super.paintComponent(g);
}
}
private class RowPanel extends JPanel { private class RowPanel extends JPanel {
private Color bgDefault = null;
private boolean selected = false; private boolean selected = false;
private Deck deck; private Deck deck;
public RowPanel(Deck d0) { public RowPanel(Deck d0) {
super(); super();
setOpaque(false); setOpaque(false);
setBackground(new Color(0, 0, 0, 0));
setLayout(new MigLayout("insets 0, gap 0")); setLayout(new MigLayout("insets 0, gap 0"));
setBorder(new MatteBorder(0, 0, 1, 0, skin.getColor(FSkin.SkinProp.CLR_BORDERS))); setBorder(new MatteBorder(0, 0, 1, 0, clrBorders));
deck = d0; deck = d0;
this.addMouseListener(new MouseAdapter() { this.addMouseListener(new MouseAdapter() {
@Override @Override
public void mouseEntered(MouseEvent e) { public void mouseEntered(MouseEvent e) {
if (selected) { return; } if (!selected) {
setBackground(skin.getColor(FSkin.SkinProp.CLR_HOVER)); ((RowPanel) e.getSource()).setBackground(clrHover);
setOpaque(true); ((RowPanel) e.getSource()).setOpaque(true);
}
} }
@Override @Override
public void mouseExited(MouseEvent e) { public void mouseExited(MouseEvent e) {
if (selected) { return; } if (!selected) {
setBackground(bgDefault); ((RowPanel) e.getSource()).setBackground(clrDefault);
setOpaque(false); ((RowPanel) e.getSource()).setOpaque(false);
}
} }
@Override @Override
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {
@@ -209,9 +248,9 @@ public class DeckLister extends JPanel {
} }
public void setSelected(boolean b0) { public void setSelected(boolean b0) {
bgDefault = (b0 ? skin.getColor(FSkin.SkinProp.CLR_ACTIVE) : null);
selected = b0; selected = b0;
setBackground(bgDefault); setOpaque(b0);
setBackground(b0 ? clrActive : clrHover);
} }
public boolean isSelected() { public boolean isSelected() {
@@ -223,15 +262,6 @@ public class DeckLister extends JPanel {
} }
} }
private class TitleLabel extends JLabel {
public TitleLabel(String txt0) {
super(txt0);
setForeground(skin.getColor(FSkin.SkinProp.CLR_TEXT));
setFont(skin.getFont(11));
setHorizontalAlignment(SwingConstants.CENTER);
}
}
private class MainLabel extends JLabel { private class MainLabel extends JLabel {
public MainLabel(String txt0) { public MainLabel(String txt0) {
super(txt0); super(txt0);
@@ -254,7 +284,6 @@ public class DeckLister extends JPanel {
setHorizontalAlignment(SwingConstants.CENTER); setHorizontalAlignment(SwingConstants.CENTER);
setForeground(skin.getColor(FSkin.SkinProp.CLR_TEXT)); setForeground(skin.getColor(FSkin.SkinProp.CLR_TEXT));
setFont(skin.getBoldFont(12)); setFont(skin.getBoldFont(12));
setHorizontalAlignment(SwingConstants.CENTER);
} }
} }
@@ -267,20 +296,69 @@ public class DeckLister extends JPanel {
return -1; return -1;
} }
/** Selects a row programatically.
* @param i0 &emsp; int
* @return boolean Was able to select, or not.
*/
public boolean setSelectedIndex(int i0) {
if (i0 >= rows.length) { return false; }
selectHandler(rows[i0]);
return true;
}
/**
* @param d0 &emsp; Deck object to select (if exists in list)
* @return boolean Found deck, or didn't.
*/
public boolean setSelectedDeck(Deck d0) {
for (RowPanel r : rows) {
if (r.getDeck() == d0) {
selectHandler(r);
return true;
}
}
return false;
}
/** @param c0 &emsp; {@link forge.Command} command executed on delete. */
public void setDeleteCommand(Command c0) {
this.cmdDelete = c0;
}
/** @param c0 &emsp; {@link forge.Command} command executed on row select. */
public void setSelectCommand(Command c0) {
this.cmdRowSelect = c0;
}
/** @param c0 &emsp; {@link forge.Command} command executed on editor exit. */
public void setExitCommand(Command c0) {
this.cmdEditorExit = c0;
}
private void selectHandler(RowPanel r0) { private void selectHandler(RowPanel r0) {
if (previousSelection != null) { if (previousSelect != null) {
previousSelection.setSelected(false); previousSelect.setSelected(false);
} }
r0.setSelected(true); r0.setSelected(true);
previousSelection = r0; previousSelect = r0;
if (cmdRowSelect != null) { cmdRowSelect.execute(); }
} }
private void editDeck(Deck d0) { private void editDeck(Deck d0) {
DeckEditorCommon editor = new DeckEditorCommon(gametype); if (gametype == GameType.Quest) {
editor.show(cmdExit); Constant.Runtime.HUMAN_DECK[0] = d0;
final DeckEditorQuest editor = new DeckEditorQuest(AllZone.getQuestData());
editor.show(cmdEditorExit);
editor.setVisible(true);
}
else {
final DeckEditorCommon editor = new DeckEditorCommon(gametype);
editor.show(cmdEditorExit);
editor.getCustomMenu().showDeck(d0, gametype); editor.getCustomMenu().showDeck(d0, gametype);
editor.setVisible(true); editor.setVisible(true);
} }
}
private void deleteDeck(RowPanel r0) { private void deleteDeck(RowPanel r0) {
Deck d0 = r0.getDeck(); Deck d0 = r0.getDeck();
@@ -318,6 +396,11 @@ public class DeckLister extends JPanel {
address1.delete(); address1.delete();
address2.delete(); address2.delete();
} }
else if (gametype.equals(GameType.Quest)) {
AllZone.getQuestData().removeDeck(d0.getName());
AllZone.getQuestData().saveData();
((GuiTopLevel) AllZone.getDisplay()).getController().getHomeView().getBtnQuest().grabFocus();
}
else { else {
deckmanager.deleteDeck(d0.getName()); deckmanager.deleteDeck(d0.getName());
@@ -326,6 +409,9 @@ public class DeckLister extends JPanel {
} }
this.remove(r0); this.remove(r0);
this.repaint();
this.revalidate(); this.revalidate();
if (cmdDelete != null) { cmdDelete.execute(); }
} }
} }

View File

@@ -0,0 +1,43 @@
package forge.view.toolbox;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JCheckBox;
import forge.Singletons;
/**
* A custom instance of JCheckBox using Forge skin properties.
*/
public class FCheckBox extends JCheckBox {
private static final long serialVersionUID = -8633657166511001814L;
private final FSkin skin;
/** */
public FCheckBox() {
this("");
}
/** @param s0 &emsp; {@link java.lang.String} */
public FCheckBox(final String s0) {
super(s0);
this.skin = Singletons.getView().getSkin();
this.setForeground(skin.getColor(FSkin.SkinProp.CLR_TEXT));
this.setBackground(skin.getColor(FSkin.SkinProp.CLR_HOVER));
this.setFont(skin.getFont(14));
this.setOpaque(false);
this.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
setOpaque(true);
}
@Override
public void mouseExited(MouseEvent e) {
setOpaque(false);
}
});
}
}

View File

@@ -0,0 +1,143 @@
package forge.view.toolbox;
import java.awt.Font;
import java.awt.Image;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import forge.Singletons;
/**
* A custom instance of JLabel using Forge skin properties.
*
* Font size can be scaled to a percentage of label height (60% by default).
*
* Font scaling can be toggled.
*/
@SuppressWarnings("serial")
public class FLabel extends JLabel {
private final FSkin skin;
private final ComponentAdapter cadResize;
private boolean scaleAuto;
private double fontScaleFactor = 0.6;
private double iconScaleFactor = 0.8;
private double aspectRatio;
private Image img = null;
private int w, h;
private int fontStyle = Font.PLAIN;
/** */
public FLabel() {
this("");
}
/** @param i0 &emsp; {@link javax.swing.ImageIcon} */
public FLabel(final Icon i0) {
this("");
this.setIcon(i0);
}
/**
* @param s0 &emsp; {@link java.lang.String}
* @param i0 &emsp; {@link javax.swing.ImageIcon}
*/
public FLabel(final String s0, final Icon i0) {
this(s0);
this.setIcon(i0);
}
/**
* @param s0 &emsp; {@link java.lang.String} text
* @param align0 &emsp; Text alignment
*/
public FLabel(final String s0, final int align0) {
this(s0);
this.setHorizontalAlignment(align0);
}
/** @param s0 &emsp; {@link java.lang.String} */
public FLabel(final String s0) {
super(s0);
this.skin = Singletons.getView().getSkin();
this.setForeground(skin.getColor(FSkin.SkinProp.CLR_TEXT));
this.cadResize = new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
switch (fontStyle) {
case Font.BOLD:
setFont(skin.getBoldFont((int) (getHeight() * fontScaleFactor)));
break;
case Font.ITALIC:
setFont(skin.getItalicFont((int) (getHeight() * fontScaleFactor)));
break;
default:
setFont(skin.getFont((int) (getHeight() * fontScaleFactor)));
}
if (img == null) { return; }
aspectRatio = img.getWidth(null) / img.getHeight(null);
h = (int) (getHeight() * iconScaleFactor);
w = (int) (h * aspectRatio * iconScaleFactor);
if (w == 0 || h == 0) { return; }
FLabel.super.setIcon(new ImageIcon(img.getScaledInstance(w, h, Image.SCALE_SMOOTH)));
}
};
this.setScaleAuto(true);
}
/** @param b0 &emsp; {@link java.lang.boolean} */
public void setScaleAuto(final boolean b0) {
this.scaleAuto = b0;
if (scaleAuto) {
this.addComponentListener(cadResize);
}
else {
this.removeComponentListener(cadResize);
}
}
/**
* Sets whether bold or italic font should be used for this label.
*
* @param i0 &emsp; Font.BOLD or Font.ITALIC
*/
public void setFontStyle(int i0) {
this.fontStyle = i0;
}
/** @param d0 &emsp; Scale factor for font size relative to label height, percent. */
public void setFontScaleFactor(final double d0) {
this.fontScaleFactor = d0;
}
/** @param d0 &emsp; Scale factor for icon size relative to label height, percent. */
public void setIconScaleFactor(final double d0) {
this.iconScaleFactor = d0;
}
/** @return {@link java.lang.boolean} */
public boolean isScaleAuto() {
return this.scaleAuto;
}
@Override
public void setIcon(final Icon i0) {
if (scaleAuto) {
// Setting the icon in the usual way leads to scaling problems.
// So, only the image is saved, and scaled along with the font
// in the resize adapter.
if (i0 == null) { return; }
this.img = ((ImageIcon) i0).getImage();
}
else {
super.setIcon(i0);
}
}
}

View File

@@ -0,0 +1,45 @@
package forge.view.toolbox;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JRadioButton;
import forge.Singletons;
/**
* A custom instance of JRadioButton using Forge skin properties.
*/
public class FRadioButton extends JRadioButton {
private static final long serialVersionUID = -2366973722131882766L;
private final FSkin skin;
/** */
public FRadioButton() {
this("");
}
/** @param s0 &emsp; {@link java.lang.String} */
public FRadioButton(String s0) {
super();
this.setText(s0);
this.skin = Singletons.getView().getSkin();
this.setForeground(skin.getColor(FSkin.SkinProp.CLR_TEXT));
this.setBackground(skin.getColor(FSkin.SkinProp.CLR_HOVER));
this.setFont(skin.getFont(14));
this.setOpaque(false);
this.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
setOpaque(true);
}
@Override
public void mouseExited(MouseEvent e) {
setOpaque(false);
}
});
}
}

View File

@@ -25,6 +25,6 @@ public class FScrollPane extends JScrollPane {
skin = Singletons.getView().getSkin(); skin = Singletons.getView().getSkin();
setBorder(new LineBorder(skin.getColor(FSkin.SkinProp.CLR_BORDERS), 1)); setBorder(new LineBorder(skin.getColor(FSkin.SkinProp.CLR_BORDERS), 1));
setBackground(skin.getColor(FSkin.SkinProp.CLR_ZEBRA)); setOpaque(false);
} }
} }

View File

@@ -0,0 +1,25 @@
package forge.view.toolbox;
import javax.swing.JTextArea;
import forge.Singletons;
/**
* A custom instance of JTextArea using Forge skin properties.
*
*/
@SuppressWarnings("serial")
public class FTextArea extends JTextArea {
private final FSkin skin;
/** */
public FTextArea() {
super();
this.skin = Singletons.getView().getSkin();
this.setForeground(skin.getColor(FSkin.SkinProp.CLR_TEXT));
this.setOpaque(false);
this.setWrapStyleWord(true);
this.setLineWrap(true);
this.setFocusable(false);
this.setEditable(false);
}
}