mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
Removed DeckManager, refactored deck editors, unified deck serialization, new deck storage model (convertor included). limited cubes may be broken for now
This commit is contained in:
68
.gitattributes
vendored
68
.gitattributes
vendored
@@ -11199,12 +11199,19 @@ src/main/java/forge/control/match/ControlTabber.java -text
|
||||
src/main/java/forge/control/match/ControlWinLose.java -text
|
||||
src/main/java/forge/control/match/package-info.java -text
|
||||
src/main/java/forge/control/package-info.java -text
|
||||
src/main/java/forge/deck/CardCollections.java -text
|
||||
src/main/java/forge/deck/CustomLimited.java svneol=native#text/plain
|
||||
src/main/java/forge/deck/Deck.java svneol=native#text/plain
|
||||
src/main/java/forge/deck/DeckGeneration.java -text
|
||||
src/main/java/forge/deck/DeckIO.java -text
|
||||
src/main/java/forge/deck/DeckManager.java svneol=native#text/plain
|
||||
src/main/java/forge/deck/DeckBase.java -text
|
||||
src/main/java/forge/deck/DeckRecognizer.java -text
|
||||
src/main/java/forge/deck/DeckSection.java -text
|
||||
src/main/java/forge/deck/DeckSet.java -text
|
||||
src/main/java/forge/deck/FolderMap.java svneol=native#text/plain
|
||||
src/main/java/forge/deck/FolderMapView.java -text
|
||||
src/main/java/forge/deck/IFolderMap.java -text
|
||||
src/main/java/forge/deck/IFolderMapView.java -text
|
||||
src/main/java/forge/deck/OldDeckParser.java -text
|
||||
src/main/java/forge/deck/generate/DeckGenerator.java -text
|
||||
src/main/java/forge/deck/generate/Generate2ColorDeck.java svneol=native#text/plain
|
||||
src/main/java/forge/deck/generate/Generate3ColorDeck.java svneol=native#text/plain
|
||||
src/main/java/forge/deck/generate/Generate5ColorDeck.java svneol=native#text/plain
|
||||
@@ -11213,6 +11220,14 @@ src/main/java/forge/deck/generate/GenerateConstructedMultiColorDeck.java svneol=
|
||||
src/main/java/forge/deck/generate/GenerateDeckUtil.java -text
|
||||
src/main/java/forge/deck/generate/GenerateThemeDeck.java svneol=native#text/plain
|
||||
src/main/java/forge/deck/generate/package-info.java svneol=native#text/plain
|
||||
src/main/java/forge/deck/io/CubeSerializer.java -text
|
||||
src/main/java/forge/deck/io/DeckFileHeader.java -text
|
||||
src/main/java/forge/deck/io/DeckIOCore.java -text
|
||||
src/main/java/forge/deck/io/DeckSerializer.java -text
|
||||
src/main/java/forge/deck/io/DeckSerializerBase.java -text
|
||||
src/main/java/forge/deck/io/DeckSetSerializer.java -text
|
||||
src/main/java/forge/deck/io/IDeckReader.java -text
|
||||
src/main/java/forge/deck/io/IDeckSerializer.java -text
|
||||
src/main/java/forge/deck/package-info.java svneol=native#text/plain
|
||||
src/main/java/forge/error/BugzReporter.java svneol=native#text/plain
|
||||
src/main/java/forge/error/ErrorViewer.java svneol=native#text/plain
|
||||
@@ -11229,7 +11244,6 @@ src/main/java/forge/game/limited/BoosterDraftAI.java svneol=native#text/plain
|
||||
src/main/java/forge/game/limited/CCnt.java svneol=native#text/plain
|
||||
src/main/java/forge/game/limited/CardPoolLimitation.java -text
|
||||
src/main/java/forge/game/limited/CardRatings.java -text
|
||||
src/main/java/forge/game/limited/CustomLimited.java svneol=native#text/plain
|
||||
src/main/java/forge/game/limited/DeckColors.java svneol=native#text/plain
|
||||
src/main/java/forge/game/limited/IBoosterDraft.java svneol=native#text/plain
|
||||
src/main/java/forge/game/limited/SealedDeck.java svneol=native#text/plain
|
||||
@@ -11242,29 +11256,35 @@ src/main/java/forge/gui/ListChooser.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/MultiLineLabel.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/MultiLineLabelUI.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/MultiPhaseProgressMonitorWithETA.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/deckeditor/CardPanelBase.java -text
|
||||
src/main/java/forge/gui/deckeditor/CardPanelHeavy.java -text
|
||||
src/main/java/forge/gui/deckeditor/CardPanelLite.java -text
|
||||
src/main/java/forge/gui/deckeditor/CheckBoxWithIcon.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/deckeditor/DeckAnalysis.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/deckeditor/DeckDisplay.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/deckeditor/DeckEditorBase.java -text
|
||||
src/main/java/forge/gui/deckeditor/DeckEditorCommon.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/deckeditor/DeckEditorCommonMenu.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/deckeditor/DeckEditorDraft.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/deckeditor/DeckEditorConstructed.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/deckeditor/DeckEditorLimited.java -text
|
||||
src/main/java/forge/gui/deckeditor/DeckEditorQuest.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/deckeditor/DeckEditorQuestMenu.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/deckeditor/DeckEditorShop.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/deckeditor/DeckImport.java -text
|
||||
src/main/java/forge/gui/deckeditor/FilterCheckBoxes.java -text
|
||||
src/main/java/forge/gui/deckeditor/FilterNameTypeSetPanel.java -text
|
||||
src/main/java/forge/gui/deckeditor/ManaCostRenderer.java -text
|
||||
src/main/java/forge/gui/deckeditor/DeckManagerOnDisk.java -text
|
||||
src/main/java/forge/gui/deckeditor/DeckManagerQuest.java -text
|
||||
src/main/java/forge/gui/deckeditor/DraftingProcess.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/deckeditor/IDeckManager.java -text
|
||||
src/main/java/forge/gui/deckeditor/MenuBase.java -text
|
||||
src/main/java/forge/gui/deckeditor/MenuCommon.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/deckeditor/MenuLimited.java -text
|
||||
src/main/java/forge/gui/deckeditor/MenuQuest.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/deckeditor/PresetColumns.java -text
|
||||
src/main/java/forge/gui/deckeditor/TableColumnInfo.java -text
|
||||
src/main/java/forge/gui/deckeditor/TableModel.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/deckeditor/TableSorter.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/deckeditor/TableSorterCascade.java -text
|
||||
src/main/java/forge/gui/deckeditor/TableWithCards.java -text
|
||||
src/main/java/forge/gui/deckeditor/QuestCardShop.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/deckeditor/elements/CardPanelBase.java -text
|
||||
src/main/java/forge/gui/deckeditor/elements/CardPanelHeavy.java -text
|
||||
src/main/java/forge/gui/deckeditor/elements/CardPanelLite.java -text
|
||||
src/main/java/forge/gui/deckeditor/elements/CheckBoxWithIcon.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/deckeditor/elements/DeckAnalysis.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/deckeditor/elements/FilterCheckBoxes.java -text
|
||||
src/main/java/forge/gui/deckeditor/elements/FilterNameTypeSetPanel.java -text
|
||||
src/main/java/forge/gui/deckeditor/elements/ManaCostRenderer.java -text
|
||||
src/main/java/forge/gui/deckeditor/elements/TableColumnInfo.java -text
|
||||
src/main/java/forge/gui/deckeditor/elements/TableModel.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/deckeditor/elements/TableSorter.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/deckeditor/elements/TableSorterCascade.java -text
|
||||
src/main/java/forge/gui/deckeditor/elements/TableView.java -text
|
||||
src/main/java/forge/gui/deckeditor/elements/package-info.java -text
|
||||
src/main/java/forge/gui/deckeditor/package-info.java -text
|
||||
src/main/java/forge/gui/game/CardDetailPanel.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/game/CardPanel.java svneol=native#text/plain
|
||||
@@ -11275,6 +11295,7 @@ src/main/java/forge/item/BoosterPack.java -text
|
||||
src/main/java/forge/item/CardDb.java -text
|
||||
src/main/java/forge/item/CardPrinted.java -text
|
||||
src/main/java/forge/item/CardPrintedCharacteristics.java -text
|
||||
src/main/java/forge/item/IHasName.java -text
|
||||
src/main/java/forge/item/InventoryItem.java -text
|
||||
src/main/java/forge/item/InventoryItemFromSet.java -text
|
||||
src/main/java/forge/item/ItemPool.java -text
|
||||
@@ -11428,7 +11449,6 @@ src/test/java/forge/BoosterDraftTest.java svneol=native#text/plain
|
||||
src/test/java/forge/CardColorTest.java svneol=native#text/plain
|
||||
src/test/java/forge/CardReaderTest.java svneol=native#text/plain
|
||||
src/test/java/forge/GameActionTest.java svneol=native#text/plain
|
||||
src/test/java/forge/GuiBoosterDraftTest.java svneol=native#text/plain
|
||||
src/test/java/forge/GuiDownloadPicturesLQTest.java svneol=native#text/plain
|
||||
src/test/java/forge/GuiDownloadSetPicturesLQTest.java svneol=native#text/plain
|
||||
src/test/java/forge/GuiMigrateLocalMWSSetPicturesHQTest.java svneol=native#text/plain
|
||||
|
||||
@@ -26,8 +26,8 @@ import forge.card.cardfactory.CardFactoryInterface;
|
||||
import forge.card.cardfactory.PreloadingCardFactory;
|
||||
import forge.card.replacement.ReplacementHandler;
|
||||
import forge.card.trigger.TriggerHandler;
|
||||
import forge.deck.CardCollections;
|
||||
import forge.control.input.InputControl;
|
||||
import forge.deck.DeckManager;
|
||||
import forge.game.limited.CardRatings;
|
||||
import forge.model.FGameState;
|
||||
import forge.model.FMatchState;
|
||||
@@ -86,12 +86,20 @@ public final class AllZone {
|
||||
// shared between Input_Attack, Input_Block, Input_CombatDamage ,
|
||||
// InputState_Computer
|
||||
|
||||
/** Constant <code>DECK_MGR</code>. */
|
||||
private static DeckManager deckManager;
|
||||
|
||||
/** Constant <code>CARD_RATINGS</code>. */
|
||||
private static CardRatings cardRatings = new CardRatings();
|
||||
|
||||
|
||||
private static CardCollections collections;
|
||||
|
||||
public static final CardCollections getDecks() {
|
||||
if ( null == collections )
|
||||
{
|
||||
collections = new CardCollections(ForgeProps.getFile(NewConstants.NEW_DECKS));
|
||||
}
|
||||
return collections;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getHumanPlayer.
|
||||
@@ -564,20 +572,6 @@ public final class AllZone {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getDeckManager.
|
||||
* </p>
|
||||
*
|
||||
* @return dMgr
|
||||
*/
|
||||
public static DeckManager getDeckManager() {
|
||||
if (AllZone.deckManager == null) {
|
||||
AllZone.deckManager = new DeckManager(ForgeProps.getFile(NewConstants.NEW_DECKS));
|
||||
}
|
||||
return AllZone.deckManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and return the next timestamp.
|
||||
*
|
||||
|
||||
@@ -26,9 +26,9 @@ import java.util.Map.Entry;
|
||||
import net.slightlymagic.braids.util.lambda.Lambda1;
|
||||
import net.slightlymagic.maxmtg.Closure1;
|
||||
import net.slightlymagic.maxmtg.Predicate;
|
||||
import forge.deck.Deck;
|
||||
import forge.item.CardDb;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.ItemPoolView;
|
||||
import forge.util.MyRandom;
|
||||
|
||||
/**
|
||||
@@ -109,8 +109,8 @@ public class BoosterGenerator {
|
||||
* @param dPool
|
||||
* the d pool
|
||||
*/
|
||||
public BoosterGenerator(final Deck dPool) {
|
||||
for (final Entry<CardPrinted, Integer> e : dPool.getMain()) {
|
||||
public BoosterGenerator(final ItemPoolView<CardPrinted> dPool) {
|
||||
for (final Entry<CardPrinted, Integer> e : dPool) {
|
||||
this.addToRarity(e.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -126,7 +125,7 @@ public class ControlConstructed {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if (e.getClickCount() == 2) {
|
||||
int index = view.getLstDecksAI().locationToIndex(e.getPoint());
|
||||
showDecklist(AllZone.getDeckManager().getDeck(deckNames.get(index)));
|
||||
showDecklist(AllZone.getDecks().getConstructed().get(deckNames.get(index)));
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -136,7 +135,7 @@ public class ControlConstructed {
|
||||
if (e.getClickCount() == 2) {
|
||||
int index = view.getLstDecksHuman().locationToIndex(e.getPoint());
|
||||
if (index > 0) {
|
||||
showDecklist(AllZone.getDeckManager().getDeck(deckNames.get(index)));
|
||||
showDecklist(AllZone.getDecks().getConstructed().get(deckNames.get(index)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -366,35 +365,35 @@ public class ControlConstructed {
|
||||
//========= DECK GENERATION
|
||||
|
||||
/** Generates human deck from current list selection(s). */
|
||||
private void generateHumanDecks(String[] human0) {
|
||||
private void generateHumanDecks(String[] selectedLines) {
|
||||
CardList cards = null;
|
||||
|
||||
// Human: Color-based deck generation
|
||||
if (currentHumanSelection.getName().equals("lstColorsHuman")) {
|
||||
// Replace "random" with "AI" for deck generation code
|
||||
for (int i = 0; i < human0.length; i++) {
|
||||
human0[i] = colorVals.get(human0[i]);
|
||||
for (int i = 0; i < selectedLines.length; i++) {
|
||||
selectedLines[i] = colorVals.get(selectedLines[i]);
|
||||
}
|
||||
|
||||
// 2, 3, and 5 colors.
|
||||
if (human0.length == 2) {
|
||||
if (selectedLines.length == 2) {
|
||||
Generate2ColorDeck gen = new Generate2ColorDeck(
|
||||
human0[0], human0[1]);
|
||||
selectedLines[0], selectedLines[1]);
|
||||
cards = gen.get2ColorDeck(60, PlayerType.HUMAN);
|
||||
}
|
||||
else if (human0.length == 3) {
|
||||
else if (selectedLines.length == 3) {
|
||||
Generate3ColorDeck gen = new Generate3ColorDeck(
|
||||
human0[0], human0[1], human0[2]);
|
||||
selectedLines[0], selectedLines[1], selectedLines[2]);
|
||||
cards = gen.get3ColorDeck(60, PlayerType.HUMAN);
|
||||
}
|
||||
else {
|
||||
Generate5ColorDeck gen = new Generate5ColorDeck(
|
||||
human0[0], human0[1], human0[2], human0[3], human0[4]);
|
||||
selectedLines[0], selectedLines[1], selectedLines[2], selectedLines[3], selectedLines[4]);
|
||||
cards = gen.get5ColorDeck(60, PlayerType.HUMAN);
|
||||
}
|
||||
|
||||
// After generating card lists, convert to deck and save.
|
||||
final Deck deck = new Deck(GameType.Constructed);
|
||||
final Deck deck = new Deck();
|
||||
|
||||
deck.getMain().add(cards);
|
||||
|
||||
@@ -405,10 +404,10 @@ public class ControlConstructed {
|
||||
// Human: theme deck generation
|
||||
else if (currentHumanSelection.getName().equals("lstThemesHuman")) {
|
||||
GenerateThemeDeck gen = new GenerateThemeDeck();
|
||||
cards = gen.getThemeDeck(human0[0], 60);
|
||||
cards = gen.getThemeDeck(selectedLines[0], 60);
|
||||
|
||||
// After generating card lists, convert to deck and save.
|
||||
final Deck deck = new Deck(GameType.Constructed);
|
||||
final Deck deck = new Deck();
|
||||
deck.getMain().add(cards);
|
||||
|
||||
Constant.Runtime.HUMAN_DECK[0] = deck;
|
||||
@@ -416,7 +415,7 @@ public class ControlConstructed {
|
||||
|
||||
// Human: deck file
|
||||
else {
|
||||
Constant.Runtime.HUMAN_DECK[0] = AllZone.getDeckManager().getDeck(human0[0]);
|
||||
Constant.Runtime.HUMAN_DECK[0] = AllZone.getDecks().getConstructed().get(selectedLines[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -447,7 +446,7 @@ public class ControlConstructed {
|
||||
}
|
||||
|
||||
// After generating card lists, convert to deck and save.
|
||||
final Deck deck = new Deck(GameType.Constructed);
|
||||
final Deck deck = new Deck();
|
||||
deck.getMain().add(cards);
|
||||
|
||||
Constant.Runtime.COMPUTER_DECK[0] = deck;
|
||||
@@ -458,7 +457,7 @@ public class ControlConstructed {
|
||||
GenerateThemeDeck gen = new GenerateThemeDeck();
|
||||
|
||||
// After generating card lists, convert to deck and save.
|
||||
final Deck deck = new Deck(GameType.Constructed);
|
||||
final Deck deck = new Deck();
|
||||
deck.getMain().add(gen.getThemeDeck(ai0[0], 60));
|
||||
|
||||
Constant.Runtime.COMPUTER_DECK[0] = deck;
|
||||
@@ -466,7 +465,7 @@ public class ControlConstructed {
|
||||
|
||||
// AI: deck file
|
||||
else {
|
||||
Constant.Runtime.COMPUTER_DECK[0] = AllZone.getDeckManager().getDeck(ai0[0]);
|
||||
Constant.Runtime.COMPUTER_DECK[0] = AllZone.getDecks().getConstructed().get(ai0[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -569,8 +568,8 @@ public class ControlConstructed {
|
||||
deckNames = new ArrayList<String>();
|
||||
deckNames.add(0, "Random");
|
||||
|
||||
Collection<Deck> allDecks = AllZone.getDeckManager().getConstructedDecks();
|
||||
for (Deck d : allDecks) { deckNames.add(d.getName()); }
|
||||
|
||||
deckNames.addAll(AllZone.getDecks().getConstructed().getNames());
|
||||
|
||||
// No pre-constructed decks?
|
||||
if (deckNames.size() == 1) { deckNames = new ArrayList<String>(); }
|
||||
|
||||
@@ -4,7 +4,6 @@ import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
@@ -15,11 +14,12 @@ import forge.Constant;
|
||||
import forge.Singletons;
|
||||
import forge.control.FControl;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckSet;
|
||||
import forge.game.GameType;
|
||||
import forge.game.limited.BoosterDraft;
|
||||
import forge.game.limited.CardPoolLimitation;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.gui.deckeditor.DeckEditorDraft;
|
||||
import forge.gui.deckeditor.DraftingProcess;
|
||||
import forge.view.home.ViewDraft;
|
||||
import forge.view.toolbox.FSkin;
|
||||
|
||||
@@ -123,7 +123,7 @@ public class ControlDraft {
|
||||
}
|
||||
});
|
||||
|
||||
Deck[] opponentDecks = AllZone.getDeckManager().getDraftDeck(human.getName());
|
||||
DeckSet opponentDecks = AllZone.getDecks().getDraft().get(human.getName());
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
@@ -133,7 +133,7 @@ public class ControlDraft {
|
||||
});
|
||||
|
||||
Constant.Runtime.HUMAN_DECK[0] = human;
|
||||
Constant.Runtime.COMPUTER_DECK[0] = opponentDecks[aiIndex + 1]; //zero is human deck, so it must be +1
|
||||
Constant.Runtime.COMPUTER_DECK[0] = opponentDecks.getAiDecks().get(aiIndex); //zero is human deck, so it must be +1
|
||||
|
||||
if (Constant.Runtime.COMPUTER_DECK[0] == null) {
|
||||
throw new IllegalStateException("startButton() error - computer deck is null");
|
||||
@@ -156,7 +156,7 @@ public class ControlDraft {
|
||||
|
||||
/** */
|
||||
public void setupDraft() {
|
||||
final DeckEditorDraft draft = new DeckEditorDraft();
|
||||
final DraftingProcess draft = new DraftingProcess();
|
||||
|
||||
// Determine what kind of booster draft to run
|
||||
final ArrayList<String> draftTypes = new ArrayList<String>();
|
||||
@@ -183,9 +183,11 @@ public class ControlDraft {
|
||||
|
||||
/** Updates deck list in view. */
|
||||
public void updateHumanDecks() {
|
||||
Collection<Deck[]> temp = AllZone.getDeckManager().getDraftDecks().values();
|
||||
|
||||
List<Deck> human = new ArrayList<Deck>();
|
||||
for (Deck[] d : temp) { human.add(d[0]); }
|
||||
view.getLstHumanDecks().setDecks(human.toArray(new Deck[0]));
|
||||
for(DeckSet d : AllZone.getDecks().getDraft()) {
|
||||
human.add(d.getHumanDeck());
|
||||
}
|
||||
view.getLstHumanDecks().setDecks(human);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,9 @@ import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -24,7 +26,7 @@ import forge.deck.Deck;
|
||||
import forge.game.GameType;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.gui.deckeditor.DeckEditorQuest;
|
||||
import forge.gui.deckeditor.DeckEditorShop;
|
||||
import forge.gui.deckeditor.QuestCardShop;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
import forge.quest.data.QuestChallenge;
|
||||
@@ -397,7 +399,9 @@ public class ControlQuest {
|
||||
/** Resets decks, then retrieves and sets current deck. */
|
||||
public void refreshDecks() {
|
||||
// Retrieve and set all decks
|
||||
Deck[] temp = (qData == null ? new Deck[] {} : qData.getDecks().toArray(new Deck[0]));
|
||||
|
||||
List<Deck> temp = new ArrayList<Deck>();
|
||||
if (qData != null ) temp.addAll(qData.getMyDecks().values());
|
||||
view.getLstDecks().setDecks(temp);
|
||||
|
||||
// Look through list for preferred deck from prefs
|
||||
@@ -490,7 +494,7 @@ public class ControlQuest {
|
||||
}
|
||||
};
|
||||
|
||||
DeckEditorShop g = new DeckEditorShop(AllZone.getQuestData());
|
||||
QuestCardShop g = new QuestCardShop(AllZone.getQuestData());
|
||||
g.show(exit);
|
||||
g.setVisible(true);
|
||||
}
|
||||
|
||||
@@ -11,16 +11,16 @@ import java.util.Map;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import net.slightlymagic.braids.util.UtilFunctions;
|
||||
import forge.AllZone;
|
||||
import forge.Command;
|
||||
import forge.Constant;
|
||||
import forge.PlayerType;
|
||||
import forge.Singletons;
|
||||
import forge.control.FControl;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckIO;
|
||||
import forge.deck.DeckManager;
|
||||
import forge.deck.DeckSet;
|
||||
import forge.game.GameType;
|
||||
import forge.game.limited.SealedDeck;
|
||||
import forge.gui.GuiUtils;
|
||||
@@ -36,7 +36,6 @@ import forge.view.home.ViewSealed;
|
||||
*/
|
||||
public class ControlSealed {
|
||||
private ViewSealed view;
|
||||
private DeckManager deckManager;
|
||||
private Map<String, Deck> aiDecks;
|
||||
private final MouseListener madBuildDeck, madStartGame;
|
||||
|
||||
@@ -47,7 +46,6 @@ public class ControlSealed {
|
||||
*/
|
||||
public ControlSealed(ViewSealed v0) {
|
||||
view = v0;
|
||||
deckManager = AllZone.getDeckManager();
|
||||
Constant.Runtime.setGameType(GameType.Sealed);
|
||||
|
||||
madBuildDeck = new MouseAdapter() {
|
||||
@@ -117,7 +115,7 @@ public class ControlSealed {
|
||||
});
|
||||
|
||||
Constant.Runtime.HUMAN_DECK[0] = human;
|
||||
Constant.Runtime.COMPUTER_DECK[0] = aiDecks.get("AI_" + human.getName());
|
||||
Constant.Runtime.COMPUTER_DECK[0] = AllZone.getDecks().getSealed().get(human.getName()).getAiDecks().get(0);
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
@@ -140,24 +138,16 @@ public class ControlSealed {
|
||||
|
||||
// Since AI decks are tied directly to the human choice,
|
||||
// they're just mapped in a parallel map and grabbed when the game starts.
|
||||
for (Deck d : deckManager.getDecks()) {
|
||||
if (d.getDeckType().equals(GameType.Sealed)) {
|
||||
if (d.getPlayerType() == PlayerType.COMPUTER) {
|
||||
aiDecks.put(d.getName(), d);
|
||||
}
|
||||
else {
|
||||
humanDecks.add(d);
|
||||
}
|
||||
}
|
||||
for (DeckSet d : AllZone.getDecks().getSealed()) {
|
||||
aiDecks.put(d.getName(), d.getAiDecks().get(0));
|
||||
humanDecks.add(d.getHumanDeck());
|
||||
}
|
||||
|
||||
view.getLstHumanDecks().setDecks(humanDecks.toArray(new Deck[0]));
|
||||
view.getLstHumanDecks().setDecks(humanDecks);
|
||||
}
|
||||
|
||||
/** Build button has been pressed. */
|
||||
public void setupSealed() {
|
||||
Deck deck = new Deck(GameType.Sealed);
|
||||
|
||||
ArrayList<String> sealedTypes = new ArrayList<String>();
|
||||
sealedTypes.add("Full Cardpool");
|
||||
sealedTypes.add("Block / Set");
|
||||
@@ -184,40 +174,37 @@ public class ControlSealed {
|
||||
+ ">> does not equal any of the sealedTypes.");
|
||||
}
|
||||
|
||||
if (!sd.getCardpool().isEmpty()) {
|
||||
final ItemPool<CardPrinted> sDeck = sd.getCardpool();
|
||||
if (sd.getCardpool().isEmpty())
|
||||
return;
|
||||
|
||||
final String sDeckName = JOptionPane.showInputDialog(null,
|
||||
ForgeProps.getLocalized(NewConstants.Lang.OldGuiNewGame.NewGameText.SAVE_SEALED_MSG),
|
||||
ForgeProps.getLocalized(NewConstants.Lang.OldGuiNewGame.NewGameText.SAVE_SEALED_TTL),
|
||||
JOptionPane.QUESTION_MESSAGE);
|
||||
|
||||
if ( StringUtils.isBlank(sDeckName) )
|
||||
return;
|
||||
|
||||
// May check for name uniqueness here
|
||||
|
||||
deck.getSideboard().addAll(sDeck);
|
||||
final ItemPool<CardPrinted> sDeck = sd.getCardpool();
|
||||
|
||||
Deck deck = new Deck(sDeckName);
|
||||
deck.getSideboard().addAll(sDeck);
|
||||
|
||||
for (final String element : Constant.Color.BASIC_LANDS) {
|
||||
for (int j = 0; j < 18; j++) {
|
||||
deck.getSideboard().add(element, sd.getLandSetCode()[0]);
|
||||
}
|
||||
}
|
||||
|
||||
final String sDeckName = JOptionPane.showInputDialog(null,
|
||||
ForgeProps.getLocalized(NewConstants.Lang.OldGuiNewGame.NewGameText.SAVE_SEALED_MSG),
|
||||
ForgeProps.getLocalized(NewConstants.Lang.OldGuiNewGame.NewGameText.SAVE_SEALED_TTL),
|
||||
JOptionPane.QUESTION_MESSAGE);
|
||||
|
||||
if (sDeckName != null) {
|
||||
deck.setName(sDeckName);
|
||||
deck.setPlayerType(PlayerType.HUMAN);
|
||||
|
||||
// Bug here: if human adds no cards to the deck, then closes the deck
|
||||
// editor, an AI deck is still created and linked to the (now nonexistent)
|
||||
// human deck's name. The solution probably lies in the question,
|
||||
// why is this code not in SealedDeck to begin with? Doublestrike 19-12-11
|
||||
|
||||
Deck aiDeck = sd.buildAIDeck(sDeck.toForgeCardList());
|
||||
aiDeck.setName("AI_" + sDeckName);
|
||||
aiDeck.setPlayerType(PlayerType.COMPUTER);
|
||||
deckManager.addDeck(aiDeck);
|
||||
DeckIO.writeDeck(aiDeck, DeckIO.makeFileName(aiDeck));
|
||||
|
||||
view.getParentView().getUtilitiesController().showDeckEditor(GameType.Sealed, deck);
|
||||
}
|
||||
for (final String element : Constant.Color.BASIC_LANDS) {
|
||||
deck.getSideboard().add(element, sd.getLandSetCode()[0], 18);
|
||||
}
|
||||
|
||||
DeckSet sealed = new DeckSet(sDeckName);
|
||||
sealed.setHumanDeck(deck);
|
||||
sealed.addAiDeck(sd.buildAIDeck(sDeck.toForgeCardList()));
|
||||
AllZone.getDecks().getSealed().add(sealed);
|
||||
|
||||
|
||||
view.getParentView().getUtilitiesController().showDeckEditor(GameType.Sealed, sealed);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/** @return {@link forge.Command} What to do when the deck editor exits. */
|
||||
|
||||
@@ -8,16 +8,18 @@ import javax.swing.JOptionPane;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextArea;
|
||||
|
||||
import forge.AllZone;
|
||||
import forge.Command;
|
||||
import forge.GuiDownloadPicturesLQ;
|
||||
import forge.GuiDownloadPrices;
|
||||
import forge.GuiDownloadQuestImages;
|
||||
import forge.GuiDownloadSetPicturesLQ;
|
||||
import forge.GuiImportPicture;
|
||||
import forge.deck.Deck;
|
||||
import forge.error.BugzReporter;
|
||||
import forge.game.GameType;
|
||||
import forge.gui.deckeditor.DeckEditorCommon;
|
||||
import forge.gui.deckeditor.DeckEditorBase;
|
||||
import forge.gui.deckeditor.DeckEditorConstructed;
|
||||
import forge.gui.deckeditor.DeckEditorLimited;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants.Lang;
|
||||
import forge.view.home.ViewUtilities;
|
||||
@@ -59,7 +61,7 @@ public class ControlUtilities {
|
||||
};
|
||||
|
||||
cmdDeckEditor = new Command() { @Override
|
||||
public void execute() { showDeckEditor(null, null); } };
|
||||
public void execute() { showDeckEditor(GameType.Constructed, null); } };
|
||||
|
||||
cmdPicDownload = new Command() { @Override
|
||||
public void execute() { doDownloadPics(); } };
|
||||
@@ -149,27 +151,32 @@ public class ControlUtilities {
|
||||
* @param gt0   GameType
|
||||
* @param d0   Deck
|
||||
*/
|
||||
public void showDeckEditor(GameType gt0, Deck d0) {
|
||||
if (gt0 == null) {
|
||||
gt0 = GameType.Constructed;
|
||||
}
|
||||
|
||||
DeckEditorCommon editor = new DeckEditorCommon(gt0);
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> void showDeckEditor(GameType gt0, T d0) {
|
||||
|
||||
DeckEditorBase<?, T> editor = null;
|
||||
if ( gt0 == GameType.Constructed)
|
||||
editor = (DeckEditorBase<?, T>) new DeckEditorConstructed();
|
||||
if ( gt0 == GameType.Draft)
|
||||
editor = (DeckEditorBase<?, T>) new DeckEditorLimited(AllZone.getDecks().getDraft());
|
||||
if ( gt0 == GameType.Sealed)
|
||||
editor = (DeckEditorBase<?, T>) new DeckEditorLimited(AllZone.getDecks().getSealed());
|
||||
|
||||
|
||||
final Command exit = new Command() {
|
||||
private static final long serialVersionUID = -9133358399503226853L;
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
view.getParentView().getConstructedController().updateDeckNames();
|
||||
view.getParentView().getSealedController().updateDeckLists();
|
||||
//view.getParentView().getSealedController().updateDeckLists();
|
||||
}
|
||||
};
|
||||
|
||||
editor.show(exit);
|
||||
|
||||
if (d0 != null) {
|
||||
editor.getCustomMenu().showDeck(d0, gt0);
|
||||
editor.getController().setModel(d0);
|
||||
}
|
||||
|
||||
editor.setVisible(true);
|
||||
|
||||
53
src/main/java/forge/deck/CardCollections.java
Normal file
53
src/main/java/forge/deck/CardCollections.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package forge.deck;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import forge.deck.io.CubeSerializer;
|
||||
import forge.deck.io.DeckSerializer;
|
||||
import forge.deck.io.DeckSetSerializer;
|
||||
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public class CardCollections {
|
||||
private final IFolderMap<Deck> constructed;
|
||||
private final IFolderMap<DeckSet> draft;
|
||||
private final IFolderMap<DeckSet> sealed;
|
||||
private final IFolderMap<CustomLimited> cube;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for Constructor.
|
||||
* @param file
|
||||
*/
|
||||
public CardCollections(File file) {
|
||||
constructed = new FolderMap<Deck>(new DeckSerializer(new File(file, "constructed")));
|
||||
draft = new FolderMap<DeckSet>(new DeckSetSerializer(new File(file, "draft")));
|
||||
sealed = new FolderMap<DeckSet>(new DeckSetSerializer(new File(file, "sealed")));
|
||||
cube = new FolderMap<CustomLimited>(new CubeSerializer(new File(file, "cube")));
|
||||
|
||||
// remove this after most people have been switched to new layout
|
||||
OldDeckParser oldParser = new OldDeckParser(file, constructed, draft, sealed, cube);
|
||||
oldParser.tryParse();
|
||||
}
|
||||
|
||||
public final IFolderMap<Deck> getConstructed() {
|
||||
return constructed;
|
||||
}
|
||||
|
||||
public final IFolderMap<DeckSet> getDraft() {
|
||||
return draft;
|
||||
}
|
||||
|
||||
public final IFolderMap<CustomLimited> getCubes() {
|
||||
return cube;
|
||||
}
|
||||
|
||||
public IFolderMap<DeckSet> getSealed() {
|
||||
return sealed;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -15,11 +15,15 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.game.limited;
|
||||
package forge.deck;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import forge.AllZone;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.ItemPoolView;
|
||||
import forge.util.SectionUtil;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -29,10 +33,17 @@ import forge.AllZone;
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
class CustomLimited {
|
||||
public class CustomLimited extends DeckBase {
|
||||
|
||||
/** The Name. */
|
||||
private String name;
|
||||
/**
|
||||
* TODO: Write javadoc for Constructor.
|
||||
* @param name0
|
||||
*/
|
||||
public CustomLimited(String name0) {
|
||||
super(name0);
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 7435640939026612173L;
|
||||
|
||||
/** The Type. */
|
||||
// private String type;
|
||||
@@ -70,6 +81,8 @@ class CustomLimited {
|
||||
/** The Num packs. */
|
||||
private int numPacks = 3;
|
||||
|
||||
private DeckSection cardPool;
|
||||
|
||||
/** The Land set code. */
|
||||
private String landSetCode = AllZone.getCardFactory().getCard("Plains", AllZone.getHumanPlayer())
|
||||
.getMostRecentSet();
|
||||
@@ -92,19 +105,16 @@ class CustomLimited {
|
||||
* @return the custom limited
|
||||
*/
|
||||
public static CustomLimited parse(final List<String> dfData) {
|
||||
final CustomLimited cd = new CustomLimited();
|
||||
|
||||
Map<String, String> data = SectionUtil.parseKvPairs(dfData, ":");
|
||||
|
||||
final CustomLimited cd = new CustomLimited(data.get("Name"));
|
||||
|
||||
for (final String dd : dfData) {
|
||||
final String[] v = dd.split(":", 2);
|
||||
final String key = v[0];
|
||||
final String value = v.length > 1 ? v[1].trim() : "";
|
||||
|
||||
if (key.equalsIgnoreCase("Name")) {
|
||||
cd.setName(value);
|
||||
}
|
||||
if (key.equalsIgnoreCase("Type")) {
|
||||
// cd.type = value;
|
||||
}
|
||||
if (key.equalsIgnoreCase("DeckFile")) {
|
||||
cd.setDeckFile(value);
|
||||
}
|
||||
@@ -374,18 +384,22 @@ class CustomLimited {
|
||||
this.numDoubleFaced = numDoubleFacedIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
/* (non-Javadoc)
|
||||
* @see forge.item.CardCollectionBase#getCardPool()
|
||||
*/
|
||||
private String getName() {
|
||||
return this.name;
|
||||
@Override
|
||||
public ItemPoolView<CardPrinted> getCardPool() {
|
||||
return cardPool;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nameIn
|
||||
* the name to set
|
||||
/* (non-Javadoc)
|
||||
* @see forge.deck.DeckBase#getInstance(java.lang.String)
|
||||
*/
|
||||
private void setName(final String nameIn) {
|
||||
this.name = nameIn;
|
||||
@Override
|
||||
protected DeckBase newInstance(String name0) {
|
||||
return new CustomLimited(name0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -19,8 +19,9 @@ package forge.deck;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import forge.PlayerType;
|
||||
import forge.game.GameType;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.IHasName;
|
||||
import forge.item.ItemPoolView;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -34,155 +35,29 @@ import forge.game.GameType;
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public final class Deck implements Comparable<Deck>, Serializable {
|
||||
public class Deck extends DeckBase implements Serializable, IHasName {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -7478025567887481994L;
|
||||
|
||||
// gameType is from Constant.GameType, like GameType.Regular
|
||||
|
||||
private String name;
|
||||
private GameType deckType;
|
||||
private String comment = null;
|
||||
private PlayerType playerType = null;
|
||||
|
||||
private boolean customPool = false;
|
||||
|
||||
private final DeckSection main;
|
||||
private final DeckSection sideboard;
|
||||
|
||||
// gameType is from Constant.GameType, like GameType.Regular
|
||||
/**
|
||||
* <p>
|
||||
* Constructor for Deck.
|
||||
* Decks have their named finalled
|
||||
* </p>
|
||||
*/
|
||||
public Deck() {
|
||||
public Deck() { this(""); }
|
||||
|
||||
public Deck(String name0) {
|
||||
super(name0);
|
||||
this.main = new DeckSection();
|
||||
this.sideboard = new DeckSection();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Constructor for Deck.
|
||||
* </p>
|
||||
*
|
||||
* @param type
|
||||
* a {@link java.lang.String} object.
|
||||
*/
|
||||
public Deck(final GameType type) {
|
||||
this();
|
||||
this.setDeckType(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getDeckType.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
public GameType getDeckType() {
|
||||
return this.deckType;
|
||||
}
|
||||
|
||||
// can only call this method ONCE
|
||||
/**
|
||||
* <p>
|
||||
* setDeckType.
|
||||
* </p>
|
||||
*
|
||||
* @param deckType
|
||||
* a {@link java.lang.String} object.
|
||||
*/
|
||||
public void setDeckType(final GameType deckType) {
|
||||
if (this.getDeckType() != null) {
|
||||
throw new IllegalStateException("Deck : setDeckType() error, deck type has already been set");
|
||||
}
|
||||
|
||||
this.deckType = deckType;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* setName.
|
||||
* </p>
|
||||
*
|
||||
* @param s
|
||||
* a {@link java.lang.String} object.
|
||||
*/
|
||||
public void setName(final String s) {
|
||||
this.name = s;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getName.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* setComment.
|
||||
* </p>
|
||||
*
|
||||
* @param comment
|
||||
* a {@link java.lang.String} object.
|
||||
*/
|
||||
public void setComment(final String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getComment.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
public String getComment() {
|
||||
return this.comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* isDraft.
|
||||
* </p>
|
||||
*
|
||||
* @return a boolean.
|
||||
*/
|
||||
public boolean isDraft() {
|
||||
return this.getDeckType().equals(GameType.Draft);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* isSealed.
|
||||
* </p>
|
||||
*
|
||||
* @return a boolean.
|
||||
*/
|
||||
public boolean isSealed() {
|
||||
return this.getDeckType().equals(GameType.Sealed);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* isRegular.
|
||||
* </p>
|
||||
*
|
||||
* @return a boolean.
|
||||
*/
|
||||
public boolean isRegular() {
|
||||
return this.getDeckType().equals(GameType.Constructed);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* hashCode.
|
||||
@@ -201,67 +76,6 @@ public final class Deck implements Comparable<Deck>, Serializable {
|
||||
return this.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* compareTo.
|
||||
* </p>
|
||||
*
|
||||
* @param d
|
||||
* a {@link forge.deck.Deck} object.
|
||||
* @return a int.
|
||||
*/
|
||||
@Override
|
||||
public int compareTo(final Deck d) {
|
||||
return this.getName().compareTo(d.getName());
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
if (o instanceof Deck) {
|
||||
final Deck d = (Deck) o;
|
||||
return this.getName().equals(d.getName());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player type.
|
||||
*
|
||||
* @return the player type
|
||||
*/
|
||||
public PlayerType getPlayerType() {
|
||||
return this.playerType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the player type.
|
||||
*
|
||||
* @param recommendedPlayer0
|
||||
* the new player type
|
||||
*/
|
||||
public void setPlayerType(final PlayerType recommendedPlayer0) {
|
||||
this.playerType = recommendedPlayer0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is custom pool.
|
||||
*
|
||||
* @return true, if is custom pool
|
||||
*/
|
||||
public boolean isCustomPool() {
|
||||
return this.customPool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the custom pool.
|
||||
*
|
||||
* @param cp
|
||||
* the new custom pool
|
||||
*/
|
||||
public void setCustomPool(final boolean cp) {
|
||||
this.customPool = cp;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -284,4 +98,27 @@ public final class Deck implements Comparable<Deck>, Serializable {
|
||||
public DeckSection getSideboard() {
|
||||
return this.sideboard;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.item.CardCollectionBase#getCardPool()
|
||||
*/
|
||||
@Override
|
||||
public ItemPoolView<CardPrinted> getCardPool() {
|
||||
return main;
|
||||
}
|
||||
|
||||
protected void cloneFieldsTo(DeckBase clone) {
|
||||
super.cloneFieldsTo(clone);
|
||||
Deck result = (Deck)clone;
|
||||
result.main.addAll(this.main);
|
||||
result.sideboard.addAll(this.sideboard);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.deck.DeckBase#newInstance(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
protected DeckBase newInstance(String name0) {
|
||||
return new Deck(name0);
|
||||
}
|
||||
}
|
||||
|
||||
71
src/main/java/forge/deck/DeckBase.java
Normal file
71
src/main/java/forge/deck/DeckBase.java
Normal file
@@ -0,0 +1,71 @@
|
||||
package forge.deck;
|
||||
|
||||
import java.io.Serializable;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.IHasName;
|
||||
import forge.item.ItemPoolView;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public abstract class DeckBase implements IHasName, Serializable, Comparable<DeckBase> {
|
||||
private static final long serialVersionUID = -7538150536939660052L;
|
||||
// gameType is from Constant.GameType, like GameType.Regular
|
||||
|
||||
private final String name;
|
||||
private String comment = null;
|
||||
|
||||
public DeckBase(String name0) {
|
||||
name = name0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(final DeckBase d) {
|
||||
return this.getName().compareTo(d.getName());
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
if (o instanceof Deck) {
|
||||
final Deck d = (Deck) o;
|
||||
return this.getName().equals(d.getName());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public abstract ItemPoolView<CardPrinted> getCardPool();
|
||||
|
||||
public void setComment(final String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getComment.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
public String getComment() {
|
||||
return this.comment;
|
||||
}
|
||||
|
||||
protected abstract DeckBase newInstance(String name0);
|
||||
|
||||
protected void cloneFieldsTo(DeckBase clone) {
|
||||
clone.comment = this.comment;
|
||||
}
|
||||
|
||||
public DeckBase copyTo(String name0) {
|
||||
DeckBase obj = newInstance(name0);
|
||||
cloneFieldsTo(obj);
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
@@ -1,552 +0,0 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Nate
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.deck;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.TreeMap;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.Card;
|
||||
import forge.PlayerType;
|
||||
import forge.game.GameType;
|
||||
import forge.gui.deckeditor.TableSorter;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.ItemPoolView;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
import forge.util.FileUtil;
|
||||
import forge.util.SectionUtil;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.DefaultObjectWrapper;
|
||||
import freemarker.template.Template;
|
||||
import freemarker.template.TemplateException;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public class DeckIO {
|
||||
|
||||
private static final String NAME = "Name";
|
||||
private static final String DECK_TYPE = "Deck Type";
|
||||
private static final String COMMENT = "Comment";
|
||||
private static final String PLAYER = "Player";
|
||||
private static final String CSTM_POOL = "Custom Pool";
|
||||
/** Constant <code>BDKFileFilter</code>. */
|
||||
private static FilenameFilter bdkFileFilter = new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(final File dir, final String name) {
|
||||
return name.endsWith(".bdk");
|
||||
}
|
||||
};
|
||||
/** Constant <code>DCKFileFilter</code>. */
|
||||
public static final FilenameFilter DCK_FILE_FILTER = new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(final File dir, final String name) {
|
||||
return name.endsWith(".dck");
|
||||
}
|
||||
};
|
||||
/** The Constant DCK_FILTER. */
|
||||
public static final FileFilter DCK_FILTER = new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(final File f) {
|
||||
return f.getName().endsWith(".dck") || f.isDirectory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Simple Deck File .dck";
|
||||
}
|
||||
};
|
||||
/** The Constant HTML_FILTER. */
|
||||
public static final FileFilter HTML_FILTER = new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(final File f) {
|
||||
return f.getName().endsWith(".html") || f.isDirectory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Simple Deck File .html";
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* readDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param deckFile
|
||||
* a {@link java.io.File} object.
|
||||
* @return a {@link forge.deck.Deck} object.
|
||||
*/
|
||||
|
||||
public static Deck readDeck(final File deckFile) {
|
||||
return DeckIO.readDeck(FileUtil.readFile(deckFile));
|
||||
}
|
||||
|
||||
/**
|
||||
* Read deck.
|
||||
*
|
||||
* @param deckFileLines the deck file lines
|
||||
* @return the deck
|
||||
*/
|
||||
public static Deck readDeck(final List<String> deckFileLines) {
|
||||
final Map<String, List<String>> sections = SectionUtil.parseSections(deckFileLines);
|
||||
if (sections.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Deck d = new Deck();
|
||||
|
||||
final String firstLine = deckFileLines.get(0);
|
||||
if (!firstLine.startsWith("[") || firstLine.equalsIgnoreCase("[general]")) {
|
||||
DeckIO.readDeckOldMetadata(deckFileLines.iterator(), d);
|
||||
} else {
|
||||
DeckIO.readDeckMetadata(sections.get("metadata"), d);
|
||||
}
|
||||
d.getMain().set(DeckIO.readCardList(sections.get("main")));
|
||||
d.getSideboard().set(DeckIO.readCardList(sections.get("sideboard")));
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
private static void readDeckMetadata(final Iterable<String> lines, final Deck d) {
|
||||
if (lines == null) {
|
||||
return;
|
||||
}
|
||||
final Iterator<String> lineIterator = lines.iterator();
|
||||
while (lineIterator.hasNext()) {
|
||||
final String line = lineIterator.next();
|
||||
|
||||
final String[] linedata = line.split("=", 2);
|
||||
final String field = linedata[0].toLowerCase();
|
||||
String value = "";
|
||||
|
||||
if (linedata.length > 1) {
|
||||
value = linedata[1];
|
||||
}
|
||||
|
||||
if (DeckIO.NAME.equalsIgnoreCase(field)) {
|
||||
d.setName(value);
|
||||
|
||||
} else if (DeckIO.COMMENT.equalsIgnoreCase(field)) {
|
||||
d.setComment(value);
|
||||
|
||||
} else if (DeckIO.DECK_TYPE.equalsIgnoreCase(field)) {
|
||||
d.setDeckType(GameType.smartValueOf(value));
|
||||
|
||||
} else if (DeckIO.CSTM_POOL.equalsIgnoreCase(field)) {
|
||||
d.setCustomPool(value.equalsIgnoreCase("true"));
|
||||
|
||||
} else if (DeckIO.PLAYER.equalsIgnoreCase(field)) {
|
||||
if ("human".equalsIgnoreCase(value)) {
|
||||
d.setPlayerType(PlayerType.HUMAN);
|
||||
|
||||
} else {
|
||||
d.setPlayerType(PlayerType.COMPUTER);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* readDeckOld.
|
||||
* </p>
|
||||
*
|
||||
* @param iterator
|
||||
* a {@link java.util.ListIterator} object.
|
||||
* @return a {@link forge.deck.Deck} object.
|
||||
*/
|
||||
private static void readDeckOldMetadata(final Iterator<String> iterator, final Deck d) {
|
||||
|
||||
String line;
|
||||
// readDeck name
|
||||
final String name = iterator.next();
|
||||
|
||||
// readDeck comments
|
||||
String comment = null;
|
||||
while (iterator.hasNext()) {
|
||||
line = iterator.next();
|
||||
if ((line != null) && !line.equals("[general")) {
|
||||
if (comment == null) {
|
||||
comment = line;
|
||||
} else {
|
||||
comment += "\n" + line;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// readDeck deck type
|
||||
|
||||
final GameType deckType = iterator.hasNext() ? GameType.smartValueOf(iterator.next()) : GameType.Constructed;
|
||||
|
||||
d.setName(name);
|
||||
d.setComment(comment);
|
||||
d.setDeckType(deckType);
|
||||
}
|
||||
|
||||
// Precondition: iterator should point at the first line of cards list
|
||||
private static List<String> readCardList(final Iterable<String> lines) {
|
||||
final List<String> result = new ArrayList<String>();
|
||||
final Pattern p = Pattern.compile("((\\d+)\\s+)?(.*?)");
|
||||
|
||||
if (lines == null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
final Iterator<String> lineIterator = lines.iterator();
|
||||
while (lineIterator.hasNext()) {
|
||||
final String line = lineIterator.next();
|
||||
if (line.startsWith("[")) {
|
||||
break;
|
||||
} // there comes another section
|
||||
|
||||
final Matcher m = p.matcher(line.trim());
|
||||
m.matches();
|
||||
final String sCnt = m.group(2);
|
||||
final String cardName = m.group(3);
|
||||
if (StringUtils.isBlank(cardName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final int count = sCnt == null ? 1 : Integer.parseInt(sCnt);
|
||||
for (int i = 0; i < count; i++) {
|
||||
result.add(cardName);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static String deriveFileName(final String deckName) {
|
||||
// skips all but the listed characters
|
||||
return deckName.replaceAll("[^-_$#@.{[()]} a-zA-Z0-9]", "");
|
||||
}
|
||||
|
||||
// only accepts numbers, letters or dashes up to 20 characters in length
|
||||
/**
|
||||
*
|
||||
* Clean deck name.
|
||||
*
|
||||
* @param in
|
||||
* a String
|
||||
* @return a String
|
||||
*/
|
||||
public static String cleanDeckName(final String in) {
|
||||
final char[] c = in.toCharArray();
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; (i < c.length) && (i < 20); i++) {
|
||||
if (Character.isLetterOrDigit(c[i]) || (c[i] == '-')) {
|
||||
sb.append(c[i]);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Make file name.
|
||||
*
|
||||
* @param deckName
|
||||
* a String
|
||||
* @param deckType
|
||||
* a GameType
|
||||
* @return a File
|
||||
*/
|
||||
public static File makeFileName(final String deckName, final GameType deckType) {
|
||||
final File path = ForgeProps.getFile(NewConstants.NEW_DECKS);
|
||||
if (deckType == GameType.Draft) {
|
||||
return new File(path, DeckIO.deriveFileName(deckName) + ".bdk");
|
||||
} else {
|
||||
return new File(path, DeckIO.deriveFileName(deckName) + ".dck");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Make file name.
|
||||
*
|
||||
* @param deck
|
||||
* a Deck
|
||||
* @return a File
|
||||
*/
|
||||
public static File makeFileName(final Deck deck) {
|
||||
return DeckIO.makeFileName(deck.getName(), deck.getDeckType());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Write draft Decks.
|
||||
*
|
||||
* @param drafts
|
||||
* a Deck[]
|
||||
*/
|
||||
public static void writeDraftDecks(final Deck[] drafts) {
|
||||
final File f = DeckIO.makeFileName(drafts[0]);
|
||||
f.mkdir();
|
||||
for (int i = 0; i < drafts.length; i++) {
|
||||
FileUtil.writeFile(new File(f, i + ".dck"), DeckIO.serializeDeck(drafts[i]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* writeDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param d
|
||||
* a {@link forge.deck.Deck} object.
|
||||
* @param out
|
||||
* a {@link java.io.BufferedWriter} object.
|
||||
* @throws java.io.IOException
|
||||
* if any.
|
||||
*/
|
||||
private static List<String> serializeDeck(final Deck d) {
|
||||
final List<String> out = new ArrayList<String>();
|
||||
out.add(String.format("[metadata]"));
|
||||
|
||||
out.add(String.format("%s=%s", DeckIO.NAME, d.getName().replaceAll("\n", "")));
|
||||
out.add(String.format("%s=%s", DeckIO.DECK_TYPE, d.getDeckType()));
|
||||
// these are optional
|
||||
if (d.getComment() != null) {
|
||||
out.add(String.format("%s=%s", DeckIO.COMMENT, d.getComment().replaceAll("\n", "")));
|
||||
}
|
||||
if (d.getPlayerType() != null) {
|
||||
out.add(String.format("%s=%s", DeckIO.PLAYER, d.getPlayerType()));
|
||||
}
|
||||
|
||||
if (d.isCustomPool()) {
|
||||
out.add(String.format("%s=%s", DeckIO.CSTM_POOL, "true"));
|
||||
}
|
||||
|
||||
out.add(String.format("%s", "[main]"));
|
||||
out.addAll(DeckIO.writeCardPool(d.getMain()));
|
||||
|
||||
out.add(String.format("%s", "[sideboard]"));
|
||||
out.addAll(DeckIO.writeCardPool(d.getSideboard()));
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* writeDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param d
|
||||
* a {@link forge.deck.Deck} object.
|
||||
* @param out
|
||||
* a {@link java.io.BufferedWriter} object.
|
||||
* @throws java.io.IOException
|
||||
* if any.
|
||||
*/
|
||||
private static void writeDeckHtml(final Deck d, final BufferedWriter out) throws IOException {
|
||||
Template temp = null;
|
||||
final int cardBorder = 0;
|
||||
final int height = 319;
|
||||
final int width = 222;
|
||||
|
||||
/* Create and adjust the configuration */
|
||||
final Configuration cfg = new Configuration();
|
||||
try {
|
||||
cfg.setClassForTemplateLoading(d.getClass(), "/");
|
||||
cfg.setObjectWrapper(new DefaultObjectWrapper());
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------------------
|
||||
* -
|
||||
*/
|
||||
/*
|
||||
* You usually do these for many times in the application
|
||||
* life-cycle:
|
||||
*/
|
||||
|
||||
/* Get or create a template */
|
||||
temp = cfg.getTemplate("proxy-template.ftl");
|
||||
|
||||
/* Create a data-model */
|
||||
final Map<String, Object> root = new HashMap<String, Object>();
|
||||
root.put("title", d.getName());
|
||||
final List<String> list = new ArrayList<String>();
|
||||
for (final Card card : d.getMain().toForgeCardList().toArray()) {
|
||||
// System.out.println(card.getSets().get(card.getSets().size() -
|
||||
// 1).URL);
|
||||
list.add(card.getSets().get(card.getSets().size() - 1).getUrl());
|
||||
}
|
||||
/*
|
||||
* List<String> nameList = new ArrayList<String>(); for (Card card :
|
||||
* d.getMain().toForgeCardList().toArray()) {
|
||||
* //System.out.println(card.getSets().get(card.getSets().size() -
|
||||
* 1).URL); nameList.add(card.getName()); }
|
||||
*/
|
||||
|
||||
final TreeMap<String, Integer> map = new TreeMap<String, Integer>();
|
||||
for (final Entry<CardPrinted, Integer> entry : d.getMain().getOrderedList()) {
|
||||
map.put(entry.getKey().getName(), entry.getValue());
|
||||
// System.out.println(entry.getValue() + " " +
|
||||
// entry.getKey().getName());
|
||||
}
|
||||
|
||||
root.put("urls", list);
|
||||
root.put("cardBorder", cardBorder);
|
||||
root.put("height", height);
|
||||
root.put("width", width);
|
||||
root.put("cardlistWidth", width - 11);
|
||||
// root.put("nameList", nameList);
|
||||
root.put("cardList", map);
|
||||
|
||||
/* Merge data-model with template */
|
||||
// StringWriter sw = new StringWriter();
|
||||
temp.process(root, out);
|
||||
out.flush();
|
||||
} catch (final IOException e) {
|
||||
System.out.println(e.toString());
|
||||
} catch (final TemplateException e) {
|
||||
System.out.println(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> writeCardPool(final ItemPoolView<CardPrinted> pool) {
|
||||
final List<Entry<CardPrinted, Integer>> main2sort = pool.getOrderedList();
|
||||
Collections.sort(main2sort, TableSorter.BY_NAME_THEN_SET);
|
||||
final List<String> out = new ArrayList<String>();
|
||||
for (final Entry<CardPrinted, Integer> e : main2sort) {
|
||||
final CardPrinted card = e.getKey();
|
||||
final boolean hasBadSetInfo = "???".equals(card.getSet()) || StringUtils.isBlank(card.getSet());
|
||||
if (hasBadSetInfo) {
|
||||
out.add(String.format("%d %s", e.getValue(), card.getName()));
|
||||
} else {
|
||||
out.add(String.format("%d %s|%s", e.getValue(), card.getName(), card.getSet()));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* writeDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param d
|
||||
* a {@link forge.deck.Deck} object.
|
||||
* @param f
|
||||
* a {@link java.io.File} object.
|
||||
*/
|
||||
public static void writeDeck(final Deck d, final File f) {
|
||||
FileUtil.writeFile(f, DeckIO.serializeDeck(d));
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Write deck to HTML.
|
||||
* </p>
|
||||
*
|
||||
* @param d
|
||||
* a {@link forge.deck.Deck} object.
|
||||
* @param f
|
||||
* a {@link java.io.File} object.
|
||||
*/
|
||||
public static void writeDeckHtml(final Deck d, final File f) {
|
||||
try {
|
||||
final BufferedWriter writer = new BufferedWriter(new FileWriter(f));
|
||||
DeckIO.writeDeckHtml(d, writer);
|
||||
writer.close();
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* readAllDecks.
|
||||
* </p>
|
||||
*
|
||||
* @param deckDir the deck dir
|
||||
* @return the map
|
||||
*/
|
||||
public static final Map<String, Deck> readAllDecks(final File deckDir) {
|
||||
final Map<String, Deck> result = new HashMap<String, Deck>();
|
||||
final List<String> decksThatFailedToLoad = new ArrayList<String>();
|
||||
final File[] files = deckDir.listFiles(DeckIO.DCK_FILE_FILTER);
|
||||
for (final File file : files) {
|
||||
try {
|
||||
final Deck newDeck = DeckIO.readDeck(file);
|
||||
result.put(newDeck.getName(), newDeck);
|
||||
} catch (final NoSuchElementException ex) {
|
||||
final String message = String.format("%s failed to load because ---- %s", file.getName(),
|
||||
ex.getMessage());
|
||||
decksThatFailedToLoad.add(message);
|
||||
}
|
||||
}
|
||||
|
||||
if (!decksThatFailedToLoad.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(null,
|
||||
StringUtils.join(decksThatFailedToLoad, System.getProperty("line.separator")),
|
||||
"Some of your decks were not loaded.", JOptionPane.WARNING_MESSAGE);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read all draft decks.
|
||||
*
|
||||
* @param deckDir the deck dir
|
||||
* @return the map
|
||||
*/
|
||||
public static final Map<String, Deck[]> readAllDraftDecks(final File deckDir) {
|
||||
final Map<String, Deck[]> result = new HashMap<String, Deck[]>();
|
||||
final File[] files = deckDir.listFiles(DeckIO.bdkFileFilter);
|
||||
for (final File file : files) {
|
||||
final Deck[] d = new Deck[8];
|
||||
|
||||
boolean gotError = false;
|
||||
for (int i = 0; i < d.length; i++) {
|
||||
d[i] = DeckIO.readDeck(new File(file, i + ".dck"));
|
||||
if (d[i] == null) {
|
||||
gotError = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!gotError) {
|
||||
result.put(d[0].getName(), d);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,268 +0,0 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.deck;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.game.GameType;
|
||||
|
||||
//reads and writeDeck Deck objects
|
||||
/**
|
||||
* <p>
|
||||
* DeckManager class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class DeckManager {
|
||||
private Map<String, Deck> deckMap;
|
||||
private Map<String, Deck[]> draftMap;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Constructor for DeckManager.
|
||||
* </p>
|
||||
*
|
||||
* @param deckDir
|
||||
* a {@link java.io.File} object.
|
||||
*/
|
||||
public DeckManager(final File deckDir) {
|
||||
if (deckDir == null) {
|
||||
throw new IllegalArgumentException("No deck directory specified");
|
||||
}
|
||||
try {
|
||||
if (deckDir.isFile()) {
|
||||
throw new IOException("Not a directory");
|
||||
} else {
|
||||
deckDir.mkdirs();
|
||||
if (!deckDir.isDirectory()) {
|
||||
throw new IOException("Directory can't be created");
|
||||
}
|
||||
this.deckMap = DeckIO.readAllDecks(deckDir);
|
||||
this.draftMap = DeckIO.readAllDraftDecks(deckDir);
|
||||
}
|
||||
} catch (final IOException ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("DeckManager : writeDeck() error, " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* isUnique.
|
||||
* </p>
|
||||
*
|
||||
* @param deckName
|
||||
* a {@link java.lang.String} object.
|
||||
* @return a boolean.
|
||||
*/
|
||||
public final boolean isUnique(final String deckName) {
|
||||
return !this.deckMap.containsKey(deckName);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* isUniqueDraft.
|
||||
* </p>
|
||||
*
|
||||
* @param deckName
|
||||
* a {@link java.lang.String} object.
|
||||
* @return a boolean.
|
||||
*/
|
||||
public final boolean isUniqueDraft(final String deckName) {
|
||||
return !this.draftMap.keySet().contains(deckName);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param deckName
|
||||
* a {@link java.lang.String} object.
|
||||
* @return a {@link forge.deck.Deck} object.
|
||||
*/
|
||||
public final Deck getDeck(final String deckName) {
|
||||
return this.deckMap.get(deckName);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* addDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param deck
|
||||
* a {@link forge.deck.Deck} object.
|
||||
*/
|
||||
public final void addDeck(final Deck deck) {
|
||||
if (deck.getDeckType().equals(GameType.Draft)) {
|
||||
throw new RuntimeException("DeckManager : addDeck() error, deck type is Draft");
|
||||
}
|
||||
|
||||
this.deckMap.put(deck.getName(), deck);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* deleteDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param deckName
|
||||
* a {@link java.lang.String} object.
|
||||
*/
|
||||
public final void deleteDeck(final String deckName) {
|
||||
this.deckMap.remove(deckName);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getDraftDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param deckName
|
||||
* a {@link java.lang.String} object.
|
||||
* @return an array of {@link forge.deck.Deck} objects.
|
||||
*/
|
||||
public final Deck[] getDraftDeck(final String deckName) {
|
||||
if (!this.draftMap.containsKey(deckName)) {
|
||||
throw new RuntimeException("DeckManager : getDraftDeck() error, deck name not found - " + deckName);
|
||||
}
|
||||
|
||||
return this.draftMap.get(deckName);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* addDraftDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param deck
|
||||
* an array of {@link forge.deck.Deck} objects.
|
||||
*/
|
||||
public final void addDraftDeck(final Deck[] deck) {
|
||||
this.checkDraftDeck(deck);
|
||||
|
||||
this.draftMap.put(deck[0].toString(), deck);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* deleteDraftDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param deckName
|
||||
* a {@link java.lang.String} object.
|
||||
*/
|
||||
public final void deleteDraftDeck(final String deckName) {
|
||||
if (!this.draftMap.containsKey(deckName)) {
|
||||
throw new RuntimeException("DeckManager : deleteDraftDeck() error, deck name not found - " + deckName);
|
||||
}
|
||||
|
||||
this.draftMap.remove(deckName);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* checkDraftDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param deck
|
||||
* an array of {@link forge.deck.Deck} objects.
|
||||
*/
|
||||
private void checkDraftDeck(final Deck[] deck) {
|
||||
if ((deck == null) || (deck.length != 8) || deck[0].getName().equals("")
|
||||
|| (!deck[0].getDeckType().equals(GameType.Draft))) {
|
||||
throw new RuntimeException("DeckManager : checkDraftDeck() error, invalid deck");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Get Decks.
|
||||
*
|
||||
* @return a Collection<Deck>
|
||||
*/
|
||||
public final Collection<Deck> getDecks() {
|
||||
return this.deckMap.values();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Get Constructed Decks.
|
||||
*
|
||||
* @return a Collection<Deck>
|
||||
*/
|
||||
public final Collection<Deck> getConstructedDecks() {
|
||||
final ArrayList<Deck> list = new ArrayList<Deck>();
|
||||
for (final Deck l : this.deckMap.values()) {
|
||||
if (l.getDeckType().equals(GameType.Constructed) && !l.isCustomPool()) {
|
||||
list.add(l);
|
||||
}
|
||||
}
|
||||
Collections.sort(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Get draft decks.
|
||||
*
|
||||
* @return a Map<String, Deck[]>
|
||||
*/
|
||||
public final Map<String, Deck[]> getDraftDecks() {
|
||||
return new HashMap<String, Deck[]>(this.draftMap);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Get names of decks.
|
||||
*
|
||||
* @param deckType
|
||||
* a GameType
|
||||
* @return a ArrayList<String>
|
||||
*/
|
||||
public final ArrayList<String> getDeckNames(final GameType deckType) {
|
||||
final ArrayList<String> list = new ArrayList<String>();
|
||||
|
||||
// only get decks according to the OldGuiNewGame screen option
|
||||
if (deckType.equals(GameType.Draft)) {
|
||||
for (final String s : this.getDraftDecks().keySet()) {
|
||||
list.add(s);
|
||||
}
|
||||
} else {
|
||||
for (final Deck deck : this.getDecks()) {
|
||||
if (deckType.equals(deck.getDeckType())) {
|
||||
list.add(deck.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(list);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,8 @@
|
||||
*/
|
||||
package forge.deck;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import forge.Card;
|
||||
import forge.CardList;
|
||||
import forge.item.CardDb;
|
||||
@@ -24,7 +26,7 @@ import forge.item.CardPrinted;
|
||||
import forge.item.ItemPool;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
* Deck section
|
||||
*
|
||||
*/
|
||||
public class DeckSection extends ItemPool<CardPrinted> {
|
||||
@@ -35,13 +37,10 @@ public class DeckSection extends ItemPool<CardPrinted> {
|
||||
public DeckSection() {
|
||||
super(CardPrinted.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear main.
|
||||
*/
|
||||
public void clearMain() {
|
||||
this.clear();
|
||||
|
||||
|
||||
public DeckSection(Iterable<Entry<CardPrinted, Integer>> cards) {
|
||||
this();
|
||||
addAll(cards);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,7 +50,7 @@ public class DeckSection extends ItemPool<CardPrinted> {
|
||||
*/
|
||||
public void set(final Iterable<String> cardNames) {
|
||||
this.clear();
|
||||
this.addAllCards(CardDb.instance().getCards(cardNames));
|
||||
this.addAllFlat(CardDb.instance().getCards(cardNames));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,6 +72,16 @@ public class DeckSection extends ItemPool<CardPrinted> {
|
||||
this.add(CardDb.instance().getCard(cardName, setCode));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the.
|
||||
*
|
||||
* @param cardName the card name
|
||||
* @param setCode the set code
|
||||
*/
|
||||
public void add(final String cardName, final String setCode, int amount) {
|
||||
this.add(CardDb.instance().getCard(cardName, setCode), amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the.
|
||||
*
|
||||
@@ -84,4 +93,12 @@ public class DeckSection extends ItemPool<CardPrinted> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this method.
|
||||
* @param string
|
||||
*/
|
||||
public void add(String cardName) {
|
||||
this.add(CardDb.instance().getCard(cardName));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
52
src/main/java/forge/deck/DeckSet.java
Normal file
52
src/main/java/forge/deck/DeckSet.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package forge.deck;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.IHasName;
|
||||
import forge.item.ItemPoolView;
|
||||
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public class DeckSet extends DeckBase implements IHasName {
|
||||
|
||||
public DeckSet(String name0) {
|
||||
super(name0);
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = -1628725522049635829L;
|
||||
private Deck humanDeck;
|
||||
private List<Deck> aiDecks = new ArrayList<Deck>();
|
||||
|
||||
public final Deck getHumanDeck() {
|
||||
return humanDeck;
|
||||
}
|
||||
public final List<Deck> getAiDecks() {
|
||||
return aiDecks;
|
||||
}
|
||||
public final void setHumanDeck(Deck humanDeck) { this.humanDeck = humanDeck; }
|
||||
|
||||
public final void addAiDeck(Deck aiDeck) { if ( aiDeck != null ) this.aiDecks.add(aiDeck); }
|
||||
|
||||
@Override
|
||||
public ItemPoolView<CardPrinted> getCardPool() {
|
||||
return getHumanDeck().getMain();
|
||||
}
|
||||
|
||||
public void addAiDecks(Deck[] computer) {
|
||||
for(int i = 0; i < computer.length; i++)
|
||||
aiDecks.add(computer[i]);
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see forge.deck.DeckBase#newInstance(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
protected DeckBase newInstance(String name0) {
|
||||
return new DeckSet(name0);
|
||||
}
|
||||
|
||||
}
|
||||
70
src/main/java/forge/deck/FolderMap.java
Normal file
70
src/main/java/forge/deck/FolderMap.java
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.deck;
|
||||
|
||||
import forge.deck.io.IDeckSerializer;
|
||||
import forge.item.IHasName;
|
||||
|
||||
//reads and writeDeck Deck objects
|
||||
/**
|
||||
* <p>
|
||||
* DeckManager class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class FolderMap<T extends IHasName> extends FolderMapView<T> implements IFolderMap<T> {
|
||||
|
||||
private IDeckSerializer<T> serializer;
|
||||
/**
|
||||
* <p>
|
||||
* Constructor for DeckManager.
|
||||
* </p>
|
||||
*
|
||||
* @param deckDir
|
||||
* a {@link java.io.File} object.
|
||||
*/
|
||||
public FolderMap(IDeckSerializer<T> io ) {
|
||||
super(io);
|
||||
serializer = io;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.deck.IFolderMap#add(T)
|
||||
*/
|
||||
@Override
|
||||
public final void add(final T deck) {
|
||||
this.getMap().put(deck.getName(), deck);
|
||||
serializer.save(deck);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.deck.IFolderMap#delete(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public final void delete(final String deckName) {
|
||||
serializer.erase(this.getMap().remove(deckName));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
90
src/main/java/forge/deck/FolderMapView.java
Normal file
90
src/main/java/forge/deck/FolderMapView.java
Normal file
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.deck;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import forge.deck.io.IDeckReader;
|
||||
import forge.item.IHasName;
|
||||
|
||||
//reads and writeDeck Deck objects
|
||||
/**
|
||||
* <p>
|
||||
* DeckManager class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id: DeckManager.java 13590 2012-01-27 20:46:27Z Max mtg $
|
||||
*/
|
||||
public class FolderMapView<T extends IHasName> implements Iterable<T>, IFolderMapView<T> {
|
||||
private final Map<String, T> map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Constructor for DeckManager.
|
||||
* </p>
|
||||
*
|
||||
* @param deckDir
|
||||
* a {@link java.io.File} object.
|
||||
*/
|
||||
public FolderMapView(IDeckReader<T> io ) {
|
||||
this.map = io.readAll();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.deck.IFolderMapView#isUnique(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public final boolean isUnique(final String name) {
|
||||
return !this.map.containsKey(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.deck.IFolderMapView#get(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public final T get(final String name) {
|
||||
return this.map.get(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.deck.IFolderMapView#getNames()
|
||||
*/
|
||||
@Override
|
||||
public final Collection<String> getNames() {
|
||||
return new ArrayList<String>(map.keySet());
|
||||
}
|
||||
|
||||
protected final Map<String, T> getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Iterable#iterator()
|
||||
*/
|
||||
/* (non-Javadoc)
|
||||
* @see forge.deck.IFolderMapView#iterator()
|
||||
*/
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return this.map.values().iterator();
|
||||
}
|
||||
}
|
||||
32
src/main/java/forge/deck/IFolderMap.java
Normal file
32
src/main/java/forge/deck/IFolderMap.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package forge.deck;
|
||||
|
||||
import forge.item.IHasName;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public interface IFolderMap<T extends IHasName> extends IFolderMapView<T> {
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* addDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param deck
|
||||
* a {@link forge.deck.Deck} object.
|
||||
*/
|
||||
public abstract void add(final T deck);
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* deleteDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param deckName
|
||||
* a {@link java.lang.String} object.
|
||||
*/
|
||||
public abstract void delete(final String deckName);
|
||||
|
||||
}
|
||||
48
src/main/java/forge/deck/IFolderMapView.java
Normal file
48
src/main/java/forge/deck/IFolderMapView.java
Normal file
@@ -0,0 +1,48 @@
|
||||
package forge.deck;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import forge.item.IHasName;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public interface IFolderMapView<T extends IHasName> extends Iterable<T> {
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* isUnique.
|
||||
* </p>
|
||||
*
|
||||
* @param deckName
|
||||
* a {@link java.lang.String} object.
|
||||
* @return a boolean.
|
||||
*/
|
||||
public abstract boolean isUnique(final String name);
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param deckName
|
||||
* a {@link java.lang.String} object.
|
||||
* @return a {@link forge.deck.Deck} object.
|
||||
*/
|
||||
public abstract T get(final String name);
|
||||
|
||||
/**
|
||||
*
|
||||
* Get names of decks.
|
||||
*
|
||||
* @param deckType
|
||||
* a GameType
|
||||
* @return a ArrayList<String>
|
||||
*/
|
||||
public abstract Collection<String> getNames();
|
||||
|
||||
|
||||
}
|
||||
206
src/main/java/forge/deck/OldDeckParser.java
Normal file
206
src/main/java/forge/deck/OldDeckParser.java
Normal file
@@ -0,0 +1,206 @@
|
||||
package forge.deck;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.apache.commons.lang3.tuple.MutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import forge.PlayerType;
|
||||
import forge.deck.io.DeckFileHeader;
|
||||
import forge.deck.io.DeckIOCore;
|
||||
import forge.deck.io.DeckSetSerializer;
|
||||
import forge.util.FileUtil;
|
||||
import forge.util.SectionUtil;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public class OldDeckParser {
|
||||
|
||||
/** Constant <code>BDKFileFilter</code>. */
|
||||
public final static FilenameFilter bdkFileFilter = new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(final File dir, final String name) {
|
||||
return name.endsWith(".bdk");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for Constructor.
|
||||
* @param file
|
||||
* @param constructed2
|
||||
* @param draft2
|
||||
* @param sealed2
|
||||
* @param cube2
|
||||
*/
|
||||
public OldDeckParser(File file, IFolderMap<Deck> constructed2, IFolderMap<DeckSet> draft2,
|
||||
IFolderMap<DeckSet> sealed2, IFolderMap<CustomLimited> cube2) {
|
||||
deckDir = file;
|
||||
sealed = sealed2;
|
||||
constructed = constructed2;
|
||||
cube = cube2;
|
||||
draft = draft2;
|
||||
}
|
||||
|
||||
protected final IFolderMap<DeckSet> getSealed() {
|
||||
return sealed;
|
||||
}
|
||||
protected final IFolderMap<Deck> getConstructed() {
|
||||
return constructed;
|
||||
}
|
||||
protected final IFolderMap<DeckSet> getDraft() {
|
||||
return draft;
|
||||
}
|
||||
protected final IFolderMap<CustomLimited> getCube() {
|
||||
return cube;
|
||||
}
|
||||
protected final File getDeckDir() {
|
||||
return deckDir;
|
||||
}
|
||||
|
||||
private final IFolderMap<DeckSet> sealed;
|
||||
private final IFolderMap<Deck> constructed;
|
||||
private final IFolderMap<DeckSet> draft;
|
||||
private final IFolderMap<CustomLimited> cube;
|
||||
private final File deckDir;
|
||||
/**
|
||||
* TODO: Write javadoc for this method.
|
||||
*/
|
||||
public void tryParse() {
|
||||
convertConstructedAndSealed();
|
||||
convertDrafts();
|
||||
}
|
||||
|
||||
private void convertDrafts()
|
||||
{
|
||||
for( File f : deckDir.listFiles(bdkFileFilter))
|
||||
{
|
||||
boolean gotError = false;
|
||||
Deck human = DeckIOCore.readDeck(new File(f, "0.dck"));
|
||||
final DeckSet d = new DeckSet(human.getName());
|
||||
d.setHumanDeck(human);
|
||||
|
||||
|
||||
for (int i = 1; i < DeckSetSerializer.MAX_DRAFT_PLAYERS; i++) {
|
||||
Deck nextAi = DeckIOCore.readDeck(new File(f, i + ".dck"));
|
||||
if (nextAi == null) {
|
||||
gotError = true;
|
||||
break;
|
||||
}
|
||||
d.addAiDeck(nextAi);
|
||||
}
|
||||
|
||||
boolean mayDelete = !gotError;
|
||||
if (!gotError) {
|
||||
draft.add(d);
|
||||
} else {
|
||||
String msg = String.format("Draft '%s' lacked some decks.%n%nShould it be deleted?");
|
||||
mayDelete = JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(null, msg, "Draft loading error", JOptionPane.YES_NO_OPTION);
|
||||
}
|
||||
|
||||
if( mayDelete ) {
|
||||
for( File f1 : f.listFiles() )
|
||||
f1.delete();
|
||||
f.delete();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void convertConstructedAndSealed()
|
||||
{
|
||||
boolean allowDeleteUnsupportedConstructed = false;
|
||||
Map<String, Pair<DeckSet, MutablePair<File,File>>> sealedDecks = new TreeMap<String, Pair<DeckSet, MutablePair<File,File>>>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
for( File f : deckDir.listFiles(DeckIOCore.DCK_FILE_FILTER))
|
||||
{
|
||||
boolean importedOk = false;
|
||||
|
||||
List<String> fileLines = FileUtil.readFile(f);
|
||||
Map<String, List<String>> sections = SectionUtil.parseSections(fileLines);
|
||||
DeckFileHeader dh = DeckIOCore.readDeckMetadata(sections);
|
||||
String name = dh.getName();
|
||||
if ( dh.isCustomPool() ) { continue; }
|
||||
|
||||
switch(dh.getDeckType()) {
|
||||
case Constructed:
|
||||
try {
|
||||
constructed.add(DeckIOCore.readDeck(fileLines));
|
||||
importedOk = true;
|
||||
} catch( NoSuchElementException ex) {
|
||||
if( !allowDeleteUnsupportedConstructed ) {
|
||||
String msg = String.format("Can not convert deck '%s' for some unsupported cards it contains. %n%s%n%nMay Forge delete all such decks?", name, ex.getMessage());
|
||||
allowDeleteUnsupportedConstructed = JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(null, msg, "Problem converting decks", JOptionPane.YES_NO_OPTION);
|
||||
}
|
||||
}
|
||||
if( importedOk || allowDeleteUnsupportedConstructed )
|
||||
f.delete();
|
||||
break;
|
||||
|
||||
case Sealed:
|
||||
boolean isAi = dh.getPlayerType() == PlayerType.COMPUTER;
|
||||
name = name.startsWith("AI_") ? name.replace("AI_", "") : name;
|
||||
|
||||
Pair<DeckSet, MutablePair<File,File>> stored = sealedDecks.get(name);
|
||||
if( null == stored )
|
||||
stored = ImmutablePair.of(new DeckSet(name), MutablePair.of((File)null, (File)null));
|
||||
|
||||
Deck deck = DeckIOCore.readDeck(fileLines);
|
||||
if( isAi ) {
|
||||
stored.getLeft().addAiDeck(deck);
|
||||
stored.getRight().setRight(f);
|
||||
} else {
|
||||
stored.getLeft().setHumanDeck(deck);
|
||||
stored.getRight().setLeft(f);
|
||||
}
|
||||
|
||||
if( stored.getLeft().getHumanDeck() != null && !stored.getLeft().getAiDecks().isEmpty() ) {
|
||||
// have both parts of sealed deck, may convert
|
||||
sealed.add(stored.getLeft());
|
||||
stored.getRight().getLeft().delete();
|
||||
stored.getRight().getRight().delete();
|
||||
|
||||
// there stay only orphans
|
||||
sealedDecks.remove(name);
|
||||
} else
|
||||
sealedDecks.put(name, stored);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// advise to kill orphaned decks
|
||||
if( !sealedDecks.isEmpty() )
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for(Pair<DeckSet, MutablePair<File, File>> s : sealedDecks.values()) {
|
||||
String missingPart = s.getRight().getLeft() == null ? "human" : "computer";
|
||||
sb.append(String.format("Sealed deck '%s' has no matching '%s' deck.%n", s.getKey().getName(), missingPart));
|
||||
}
|
||||
sb.append(System.getProperty("line.separator"));
|
||||
sb.append("May Forge delete these decks?");
|
||||
int response = JOptionPane.showConfirmDialog(null, sb.toString(), "Some of your sealed decks are orphaned", JOptionPane.YES_NO_OPTION);
|
||||
if( response == JOptionPane.YES_OPTION )
|
||||
{
|
||||
for(Pair<DeckSet, MutablePair<File, File>> s : sealedDecks.values()) {
|
||||
if( s.getRight().getLeft() != null ) { s.getRight().getLeft().delete(); }
|
||||
if( s.getRight().getRight() != null ) { s.getRight().getRight().delete(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the deckDir
|
||||
*/
|
||||
|
||||
}
|
||||
@@ -15,20 +15,14 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.deck;
|
||||
package forge.deck.generate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
import forge.Constant;
|
||||
import forge.PlayerType;
|
||||
import forge.deck.generate.Generate2ColorDeck;
|
||||
import forge.deck.generate.Generate3ColorDeck;
|
||||
import forge.deck.generate.Generate5ColorDeck;
|
||||
import forge.deck.generate.GenerateConstructedDeck;
|
||||
import forge.deck.generate.GenerateConstructedMultiColorDeck;
|
||||
import forge.deck.generate.GenerateThemeDeck;
|
||||
import forge.game.GameType;
|
||||
import forge.deck.Deck;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.util.MyRandom;
|
||||
|
||||
@@ -37,7 +31,7 @@ import forge.util.MyRandom;
|
||||
* OldGuiNewGame.
|
||||
*
|
||||
*/
|
||||
public abstract class DeckGeneration {
|
||||
public abstract class DeckGenerator {
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -66,19 +60,19 @@ public abstract class DeckGeneration {
|
||||
final Object o = GuiUtils.getChoice(prompt, decks.toArray());
|
||||
|
||||
if (o.toString().equals(decks.get(0))) {
|
||||
d = DeckGeneration.generate2ColorDeck(playerType);
|
||||
d = DeckGenerator.generate2ColorDeck(playerType);
|
||||
} else if (o.toString().equals(decks.get(1))) {
|
||||
d = DeckGeneration.generate3ColorDeck(playerType);
|
||||
d = DeckGenerator.generate3ColorDeck(playerType);
|
||||
} else if (o.toString().equals(decks.get(2))) {
|
||||
d = DeckGeneration.generate5ColorDeck(playerType);
|
||||
d = DeckGenerator.generate5ColorDeck(playerType);
|
||||
} else if (o.toString().equals(decks.get(3))) {
|
||||
d = DeckGeneration.generateConstructedDeck();
|
||||
d = DeckGenerator.generateConstructedDeck();
|
||||
} else if (o.toString().equals(decks.get(4))) {
|
||||
d = DeckGeneration.generateConstructed3ColorDeck();
|
||||
d = DeckGenerator.generateConstructed3ColorDeck();
|
||||
} else if (o.toString().equals(decks.get(5))) {
|
||||
d = DeckGeneration.generateConstructed5ColorDeck();
|
||||
d = DeckGenerator.generateConstructed5ColorDeck();
|
||||
} else if (o.toString().equals(decks.get(6))) {
|
||||
d = DeckGeneration.generateConstructedThemeDeck();
|
||||
d = DeckGenerator.generateConstructedThemeDeck();
|
||||
}
|
||||
|
||||
if (playerType.equals(PlayerType.HUMAN)) {
|
||||
@@ -97,7 +91,7 @@ public abstract class DeckGeneration {
|
||||
*/
|
||||
private static Deck generateConstructedDeck() {
|
||||
final GenerateConstructedDeck gen = new GenerateConstructedDeck();
|
||||
final Deck deck = new Deck(GameType.Constructed);
|
||||
final Deck deck = new Deck();
|
||||
deck.getMain().add(gen.generateDeck());
|
||||
return deck;
|
||||
}
|
||||
@@ -111,7 +105,7 @@ public abstract class DeckGeneration {
|
||||
*/
|
||||
private static Deck generateConstructed3ColorDeck() {
|
||||
final GenerateConstructedMultiColorDeck gen = new GenerateConstructedMultiColorDeck();
|
||||
final Deck deck = new Deck(GameType.Constructed);
|
||||
final Deck deck = new Deck();
|
||||
deck.getMain().add(gen.generate3ColorDeck());
|
||||
return deck;
|
||||
}
|
||||
@@ -125,7 +119,7 @@ public abstract class DeckGeneration {
|
||||
*/
|
||||
private static Deck generateConstructed5ColorDeck() {
|
||||
final GenerateConstructedMultiColorDeck gen = new GenerateConstructedMultiColorDeck();
|
||||
final Deck deck = new Deck(GameType.Constructed);
|
||||
final Deck deck = new Deck();
|
||||
deck.getMain().add(gen.generate5ColorDeck());
|
||||
return deck;
|
||||
}
|
||||
@@ -151,7 +145,7 @@ public abstract class DeckGeneration {
|
||||
stDeck = o.toString();
|
||||
}
|
||||
|
||||
final Deck deck = new Deck(GameType.Constructed);
|
||||
final Deck deck = new Deck();
|
||||
deck.getMain().add(gen.getThemeDeck(stDeck, 60));
|
||||
|
||||
return deck;
|
||||
@@ -201,7 +195,7 @@ public abstract class DeckGeneration {
|
||||
}
|
||||
final Generate2ColorDeck gen = new Generate2ColorDeck(c1, c2);
|
||||
|
||||
final Deck deck = new Deck(GameType.Constructed);
|
||||
final Deck deck = new Deck();
|
||||
deck.getMain().add(gen.get2ColorDeck(60, p));
|
||||
return deck;
|
||||
}
|
||||
@@ -260,7 +254,7 @@ public abstract class DeckGeneration {
|
||||
c3 = colors.get(r.nextInt(colors.size() - 1) + 1);
|
||||
}
|
||||
final Generate3ColorDeck gen = new Generate3ColorDeck(c1, c2, c3);
|
||||
final Deck deck = new Deck(GameType.Constructed);
|
||||
final Deck deck = new Deck();
|
||||
deck.getMain().add(gen.get3ColorDeck(60, p));
|
||||
return deck;
|
||||
}
|
||||
@@ -286,7 +280,7 @@ public abstract class DeckGeneration {
|
||||
// colors.add("green");
|
||||
|
||||
final Generate5ColorDeck gen = new Generate5ColorDeck("white", "blue", "black", "red", "green");
|
||||
final Deck deck = new Deck(GameType.Constructed);
|
||||
final Deck deck = new Deck();
|
||||
deck.getMain().add(gen.get5ColorDeck(60, p));
|
||||
return deck;
|
||||
|
||||
89
src/main/java/forge/deck/io/CubeSerializer.java
Normal file
89
src/main/java/forge/deck/io/CubeSerializer.java
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Nate
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.deck.io;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
|
||||
import forge.deck.CustomLimited;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public class CubeSerializer extends DeckSerializerBase<CustomLimited> {
|
||||
|
||||
public CubeSerializer(File deckDir0)
|
||||
{
|
||||
super(deckDir0);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.deck.IDeckSerializer#save(forge.item.CardCollectionBase, java.io.File)
|
||||
*/
|
||||
@Override
|
||||
public void save(CustomLimited unit) {
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.deck.IDeckSerializer#erase(forge.item.CardCollectionBase, java.io.File)
|
||||
*/
|
||||
@Override
|
||||
public void erase(CustomLimited unit) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Make file name.
|
||||
*
|
||||
* @param deckName
|
||||
* @param deckType
|
||||
* a GameType
|
||||
* @return a File
|
||||
*/
|
||||
public File makeFileFor(final CustomLimited deck) {
|
||||
return new File(getDirectory(), DeckIOCore.deriveFileName(cleanDeckName(deck.getName())) + ".cub");
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.deck.io.DeckSerializerBase#read(java.io.File)
|
||||
*/
|
||||
@Override
|
||||
protected CustomLimited read(File file) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.deck.io.DeckSerializerBase#getFileFilter()
|
||||
*/
|
||||
@Override
|
||||
protected FilenameFilter getFileFilter() {
|
||||
return new FilenameFilter() {
|
||||
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return dir.getPath().endsWith(".cub");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
62
src/main/java/forge/deck/io/DeckFileHeader.java
Normal file
62
src/main/java/forge/deck/io/DeckFileHeader.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package forge.deck.io;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import forge.PlayerType;
|
||||
import forge.game.GameType;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public class DeckFileHeader {
|
||||
|
||||
private static final String NAME = "Name";
|
||||
private static final String DECK_TYPE = "Deck Type";
|
||||
private static final String COMMENT = "Comment";
|
||||
private static final String PLAYER = "Player";
|
||||
private static final String CSTM_POOL = "Custom Pool";
|
||||
private static final String PLAYER_TYPE = "PlayerType";
|
||||
|
||||
private final GameType deckType;
|
||||
private final PlayerType playerType;
|
||||
private final boolean customPool;
|
||||
|
||||
private final String name;
|
||||
private final String comment;
|
||||
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for Constructor.
|
||||
* @param parseKvPairs
|
||||
*/
|
||||
public DeckFileHeader(Map<String, String> kvPairs) {
|
||||
name = kvPairs.get(NAME);
|
||||
comment = kvPairs.get(COMMENT);
|
||||
deckType = GameType.smartValueOf(kvPairs.get(DECK_TYPE), GameType.Constructed);
|
||||
customPool = "true".equalsIgnoreCase(kvPairs.get(CSTM_POOL));
|
||||
playerType = "computer".equalsIgnoreCase(kvPairs.get(PLAYER)) || "ai".equalsIgnoreCase(kvPairs.get(PLAYER_TYPE)) ? PlayerType.COMPUTER : PlayerType.HUMAN;
|
||||
}
|
||||
|
||||
|
||||
public final PlayerType getPlayerType() {
|
||||
return playerType;
|
||||
}
|
||||
public final boolean isCustomPool() {
|
||||
return customPool;
|
||||
}
|
||||
public final String getName() {
|
||||
return name;
|
||||
}
|
||||
public final String getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
|
||||
public final GameType getDeckType() {
|
||||
return deckType;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
241
src/main/java/forge/deck/io/DeckIOCore.java
Normal file
241
src/main/java/forge/deck/io/DeckIOCore.java
Normal file
@@ -0,0 +1,241 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Nate
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.deck.io;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.deck.Deck;
|
||||
import forge.game.GameType;
|
||||
import forge.gui.deckeditor.elements.TableSorter;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.ItemPoolView;
|
||||
import forge.util.FileUtil;
|
||||
import forge.util.SectionUtil;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public class DeckIOCore {
|
||||
|
||||
private static final String NAME = "Name";
|
||||
private static final String DECK_TYPE = "Deck Type";
|
||||
private static final String COMMENT = "Comment";
|
||||
/** Constant <code>DCKFileFilter</code>. */
|
||||
public static final FilenameFilter DCK_FILE_FILTER = new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(final File dir, final String name) {
|
||||
return name.endsWith(".dck");
|
||||
}
|
||||
};
|
||||
/** The Constant DCK_FILTER. */
|
||||
public static final FileFilter DCK_FILTER = new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(final File f) {
|
||||
return f.getName().endsWith(".dck") || f.isDirectory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Simple Deck File .dck";
|
||||
}
|
||||
};
|
||||
/** The Constant HTML_FILTER. */
|
||||
public static final FileFilter HTML_FILTER = new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(final File f) {
|
||||
return f.getName().endsWith(".html") || f.isDirectory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Simple Deck File .html";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public static DeckFileHeader readDeckMetadata(final Map<String,List<String>> map) {
|
||||
List<String> lines = map.get("metadata");
|
||||
if (lines == null) {
|
||||
return null;
|
||||
}
|
||||
DeckFileHeader d = new DeckFileHeader(SectionUtil.parseKvPairs(lines, "="));
|
||||
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
// Precondition: iterator should point at the first line of cards list
|
||||
public static List<String> readCardList(final Iterable<String> lines) {
|
||||
final List<String> result = new ArrayList<String>();
|
||||
final Pattern p = Pattern.compile("((\\d+)\\s+)?(.*?)");
|
||||
|
||||
if (lines == null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
final Iterator<String> lineIterator = lines.iterator();
|
||||
while (lineIterator.hasNext()) {
|
||||
final String line = lineIterator.next();
|
||||
if (line.startsWith("[")) {
|
||||
break;
|
||||
} // there comes another section
|
||||
|
||||
final Matcher m = p.matcher(line.trim());
|
||||
m.matches();
|
||||
final String sCnt = m.group(2);
|
||||
final String cardName = m.group(3);
|
||||
if (StringUtils.isBlank(cardName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final int count = sCnt == null ? 1 : Integer.parseInt(sCnt);
|
||||
for (int i = 0; i < count; i++) {
|
||||
result.add(cardName);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String deriveFileName(final String deckName) {
|
||||
// skips all but the listed characters
|
||||
return deckName.replaceAll("[^-_$#@.{[()]} a-zA-Z0-9]", "");
|
||||
}
|
||||
|
||||
// only accepts numbers, letters or dashes up to 20 characters in length
|
||||
/**
|
||||
*
|
||||
* Clean deck name.
|
||||
*
|
||||
* @param in
|
||||
* a String
|
||||
* @return a String
|
||||
*/
|
||||
public static String cleanDeckName(final String in) {
|
||||
final char[] c = in.toCharArray();
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; (i < c.length) && (i < 20); i++) {
|
||||
if (Character.isLetterOrDigit(c[i]) || (c[i] == '-')) {
|
||||
sb.append(c[i]);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static List<String> writeCardPool(final ItemPoolView<CardPrinted> pool) {
|
||||
final List<Entry<CardPrinted, Integer>> main2sort = pool.getOrderedList();
|
||||
Collections.sort(main2sort, TableSorter.BY_NAME_THEN_SET);
|
||||
final List<String> out = new ArrayList<String>();
|
||||
for (final Entry<CardPrinted, Integer> e : main2sort) {
|
||||
final CardPrinted card = e.getKey();
|
||||
final boolean hasBadSetInfo = "???".equals(card.getSet()) || StringUtils.isBlank(card.getSet());
|
||||
if (hasBadSetInfo) {
|
||||
out.add(String.format("%d %s", e.getValue(), card.getName()));
|
||||
} else {
|
||||
out.add(String.format("%d %s|%s", e.getValue(), card.getName(), card.getSet()));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* readDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param deckFile
|
||||
* a {@link java.io.File} object.
|
||||
* @return a {@link forge.deck.Deck} object.
|
||||
*/
|
||||
|
||||
public static Deck readDeck(final File deckFile) {
|
||||
return readDeck(FileUtil.readFile(deckFile));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read deck.
|
||||
*
|
||||
* @param deckFileLines the deck file lines
|
||||
* @return the deck
|
||||
*/
|
||||
public static Deck readDeck(final List<String> deckFileLines) {
|
||||
final Map<String, List<String>> sections = SectionUtil.parseSections(deckFileLines);
|
||||
if (sections.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
DeckFileHeader dh = readDeckMetadata(sections);
|
||||
|
||||
final Deck d = new Deck(dh.getName());
|
||||
d.setComment(dh.getComment());
|
||||
d.getMain().set(readCardList(sections.get("main")));
|
||||
d.getSideboard().set(readCardList(sections.get("sideboard")));
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* writeDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param d
|
||||
* a {@link forge.deck.Deck} object.
|
||||
* @param out
|
||||
* a {@link java.io.BufferedWriter} object.
|
||||
* @throws java.io.IOException
|
||||
* if any.
|
||||
*/
|
||||
public static List<String> saveDeck(final Deck d) {
|
||||
final List<String> out = new ArrayList<String>();
|
||||
out.add(String.format("[metadata]"));
|
||||
|
||||
out.add(String.format("%s=%s", NAME, d.getName().replaceAll("\n", "")));
|
||||
// these are optional
|
||||
if (d.getComment() != null) {
|
||||
out.add(String.format("%s=%s", COMMENT, d.getComment().replaceAll("\n", "")));
|
||||
}
|
||||
|
||||
out.add(String.format("%s", "[main]"));
|
||||
out.addAll(writeCardPool(d.getMain()));
|
||||
|
||||
out.add(String.format("%s", "[sideboard]"));
|
||||
out.addAll(writeCardPool(d.getSideboard()));
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
248
src/main/java/forge/deck/io/DeckSerializer.java
Normal file
248
src/main/java/forge/deck/io/DeckSerializer.java
Normal file
@@ -0,0 +1,248 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Nate
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.deck.io;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
|
||||
import forge.Card;
|
||||
import forge.deck.Deck;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.util.FileUtil;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.DefaultObjectWrapper;
|
||||
import freemarker.template.Template;
|
||||
import freemarker.template.TemplateException;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public class DeckSerializer extends DeckSerializerBase<Deck> {
|
||||
|
||||
public DeckSerializer(File deckDir0)
|
||||
{
|
||||
super(deckDir0);
|
||||
}
|
||||
|
||||
|
||||
/** Constant <code>DCKFileFilter</code>. */
|
||||
public static final FilenameFilter DCK_FILE_FILTER = new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(final File dir, final String name) {
|
||||
return name.endsWith(".dck");
|
||||
}
|
||||
};
|
||||
/** The Constant DCK_FILTER. */
|
||||
public static final FileFilter DCK_FILTER = new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(final File f) {
|
||||
return f.getName().endsWith(".dck") || f.isDirectory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Simple Deck File .dck";
|
||||
}
|
||||
};
|
||||
/** The Constant HTML_FILTER. */
|
||||
public static final FileFilter HTML_FILTER = new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(final File f) {
|
||||
return f.getName().endsWith(".html") || f.isDirectory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Simple Deck File .html";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* writeDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param d
|
||||
* a {@link forge.deck.Deck} object.
|
||||
* @param out
|
||||
* a {@link java.io.BufferedWriter} object.
|
||||
* @throws java.io.IOException
|
||||
* if any.
|
||||
*/
|
||||
private static void writeDeckHtml(final Deck d, final BufferedWriter out) throws IOException {
|
||||
Template temp = null;
|
||||
final int cardBorder = 0;
|
||||
final int height = 319;
|
||||
final int width = 222;
|
||||
|
||||
/* Create and adjust the configuration */
|
||||
final Configuration cfg = new Configuration();
|
||||
try {
|
||||
cfg.setClassForTemplateLoading(d.getClass(), "/");
|
||||
cfg.setObjectWrapper(new DefaultObjectWrapper());
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------------------
|
||||
* -
|
||||
*/
|
||||
/*
|
||||
* You usually do these for many times in the application
|
||||
* life-cycle:
|
||||
*/
|
||||
|
||||
/* Get or create a template */
|
||||
temp = cfg.getTemplate("proxy-template.ftl");
|
||||
|
||||
/* Create a data-model */
|
||||
final Map<String, Object> root = new HashMap<String, Object>();
|
||||
root.put("title", d.getName());
|
||||
final List<String> list = new ArrayList<String>();
|
||||
for (final Card card : d.getMain().toForgeCardList().toArray()) {
|
||||
// System.out.println(card.getSets().get(card.getSets().size() -
|
||||
// 1).URL);
|
||||
list.add(card.getSets().get(card.getSets().size() - 1).getUrl());
|
||||
}
|
||||
/*
|
||||
* List<String> nameList = new ArrayList<String>(); for (Card card :
|
||||
* d.getMain().toForgeCardList().toArray()) {
|
||||
* //System.out.println(card.getSets().get(card.getSets().size() -
|
||||
* 1).URL); nameList.add(card.getName()); }
|
||||
*/
|
||||
|
||||
final TreeMap<String, Integer> map = new TreeMap<String, Integer>();
|
||||
for (final Entry<CardPrinted, Integer> entry : d.getMain().getOrderedList()) {
|
||||
map.put(entry.getKey().getName(), entry.getValue());
|
||||
// System.out.println(entry.getValue() + " " +
|
||||
// entry.getKey().getName());
|
||||
}
|
||||
|
||||
root.put("urls", list);
|
||||
root.put("cardBorder", cardBorder);
|
||||
root.put("height", height);
|
||||
root.put("width", width);
|
||||
root.put("cardlistWidth", width - 11);
|
||||
// root.put("nameList", nameList);
|
||||
root.put("cardList", map);
|
||||
|
||||
/* Merge data-model with template */
|
||||
// StringWriter sw = new StringWriter();
|
||||
temp.process(root, out);
|
||||
out.flush();
|
||||
} catch (final IOException e) {
|
||||
System.out.println(e.toString());
|
||||
} catch (final TemplateException e) {
|
||||
System.out.println(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* writeDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param d
|
||||
* a {@link forge.deck.Deck} object.
|
||||
* @param f
|
||||
* a {@link java.io.File} object.
|
||||
*/
|
||||
public static void writeDeck(final Deck d, final File f) {
|
||||
FileUtil.writeFile(f, DeckIOCore.saveDeck(d));
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Write deck to HTML.
|
||||
* </p>
|
||||
*
|
||||
* @param d
|
||||
* a {@link forge.deck.Deck} object.
|
||||
* @param f
|
||||
* a {@link java.io.File} object.
|
||||
*/
|
||||
public static void writeDeckHtml(final Deck d, final File f) {
|
||||
try {
|
||||
final BufferedWriter writer = new BufferedWriter(new FileWriter(f));
|
||||
DeckSerializer.writeDeckHtml(d, writer);
|
||||
writer.close();
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.deck.IDeckSerializer#save(forge.item.CardCollectionBase, java.io.File)
|
||||
*/
|
||||
@Override
|
||||
public void save(Deck unit) {
|
||||
FileUtil.writeFile(makeFileFor(unit), DeckIOCore.saveDeck(unit));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.deck.IDeckSerializer#erase(forge.item.CardCollectionBase, java.io.File)
|
||||
*/
|
||||
@Override
|
||||
public void erase(Deck unit) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Make file name.
|
||||
*
|
||||
* @param deckName
|
||||
* a String
|
||||
* @param deckType
|
||||
* a GameType
|
||||
* @return a File
|
||||
*/
|
||||
public File makeFileFor(final Deck deck) {
|
||||
return new File(getDirectory(), DeckIOCore.deriveFileName(cleanDeckName(deck.getName())) + ".dck");
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.deck.io.DeckSerializerBase#read(java.io.File)
|
||||
*/
|
||||
@Override
|
||||
protected Deck read(File file) {
|
||||
return DeckIOCore.readDeck(file);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.deck.io.DeckSerializerBase#getFileFilter()
|
||||
*/
|
||||
@Override
|
||||
protected FilenameFilter getFileFilter() {
|
||||
return DCK_FILE_FILTER;
|
||||
}
|
||||
|
||||
}
|
||||
134
src/main/java/forge/deck/io/DeckSerializerBase.java
Normal file
134
src/main/java/forge/deck/io/DeckSerializerBase.java
Normal file
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Nate
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.deck.io;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.item.IHasName;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public abstract class DeckSerializerBase<T extends IHasName> implements IDeckSerializer<T> {
|
||||
|
||||
private final File directory;
|
||||
|
||||
protected final File getDirectory() {
|
||||
return directory;
|
||||
}
|
||||
|
||||
|
||||
public DeckSerializerBase(File deckDir0)
|
||||
{
|
||||
directory = deckDir0;
|
||||
|
||||
if (directory == null) {
|
||||
throw new IllegalArgumentException("No deck directory specified");
|
||||
}
|
||||
try {
|
||||
if (directory.isFile()) {
|
||||
throw new IOException("Not a directory");
|
||||
} else {
|
||||
directory.mkdirs();
|
||||
if (!directory.isDirectory()) {
|
||||
throw new IOException("Directory can't be created");
|
||||
}
|
||||
}
|
||||
} catch (final IOException ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("DeckManager : writeDeck() error, " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// only accepts numbers, letters or dashes up to 20 characters in length
|
||||
/**
|
||||
*
|
||||
* Clean deck name.
|
||||
*
|
||||
* @param in
|
||||
* a String
|
||||
* @return a String
|
||||
*/
|
||||
protected String cleanDeckName(final String in) {
|
||||
final char[] c = in.toCharArray();
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; (i < c.length) && (i < 20); i++) {
|
||||
if (Character.isLetterOrDigit(c[i]) || (c[i] == '-')) {
|
||||
sb.append(c[i]);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String, T> readAll() {
|
||||
final Map<String, T> result = new TreeMap<String, T>();
|
||||
final List<String> decksThatFailedToLoad = new ArrayList<String>();
|
||||
final File[] files = directory.listFiles(getFileFilter());
|
||||
for (final File file : files) {
|
||||
try {
|
||||
final T newDeck = read(file);
|
||||
result.put(newDeck.getName(), newDeck);
|
||||
} catch (final NoSuchElementException ex) {
|
||||
final String message = String.format("%s failed to load because ---- %s", file.getName(),
|
||||
ex.getMessage());
|
||||
decksThatFailedToLoad.add(message);
|
||||
}
|
||||
}
|
||||
|
||||
if (!decksThatFailedToLoad.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(null,
|
||||
StringUtils.join(decksThatFailedToLoad, System.getProperty("line.separator")),
|
||||
"Some of your decks were not loaded.", JOptionPane.WARNING_MESSAGE);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this method.
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
protected abstract T read(File file);
|
||||
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this method.
|
||||
* @return
|
||||
*/
|
||||
protected abstract FilenameFilter getFileFilter();
|
||||
|
||||
}
|
||||
107
src/main/java/forge/deck/io/DeckSetSerializer.java
Normal file
107
src/main/java/forge/deck/io/DeckSetSerializer.java
Normal file
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Nate
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.deck.io;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.List;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckSet;
|
||||
import forge.util.FileUtil;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public class DeckSetSerializer extends DeckSerializerBase<DeckSet> {
|
||||
/**
|
||||
* TODO: Write javadoc for Constructor.
|
||||
* @param deckDir0
|
||||
*/
|
||||
public DeckSetSerializer(File deckDir0) {
|
||||
super(deckDir0);
|
||||
}
|
||||
|
||||
public final static int MAX_DRAFT_PLAYERS = 8;
|
||||
|
||||
/**
|
||||
*
|
||||
* Write draft Decks.
|
||||
*
|
||||
* @param drafts
|
||||
* a Deck[]
|
||||
*/
|
||||
@Override
|
||||
public void save(DeckSet unit) {
|
||||
final File f = makeFileFor(unit);
|
||||
f.mkdir();
|
||||
FileUtil.writeFile(new File(f, "human.dck"), DeckIOCore.saveDeck(unit.getHumanDeck()));
|
||||
List<Deck> aiDecks = unit.getAiDecks();
|
||||
for (int i = 1; i <= aiDecks.size(); i++) {
|
||||
FileUtil.writeFile(new File(f, "ai-" + i + ".dck"), DeckIOCore.saveDeck(aiDecks.get(i-1)));
|
||||
}
|
||||
}
|
||||
|
||||
protected final DeckSet read(File file)
|
||||
{
|
||||
Deck human = DeckIOCore.readDeck(new File(file, "human.dck"));
|
||||
final DeckSet d = new DeckSet(human.getName());
|
||||
d.setHumanDeck(human);
|
||||
for (int i = 1; i < MAX_DRAFT_PLAYERS; i++) {
|
||||
File theFile = new File(file, "ai-" + i + ".dck");
|
||||
if( !theFile.exists() )
|
||||
break;
|
||||
|
||||
d.addAiDeck(DeckIOCore.readDeck(theFile));
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.deck.IDeckSerializer#erase(forge.item.CardCollectionBase, java.io.File)
|
||||
*/
|
||||
@Override
|
||||
public void erase(DeckSet unit) {
|
||||
File dir = makeFileFor(unit);
|
||||
final File[] files = dir.listFiles();
|
||||
for(File f : files) {
|
||||
f.delete();
|
||||
}
|
||||
dir.delete();
|
||||
}
|
||||
|
||||
public File makeFileFor(final DeckSet decks) {
|
||||
return new File(getDirectory(), DeckIOCore.deriveFileName(decks.getName()));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.deck.io.DeckSerializerBase#getFileFilter()
|
||||
*/
|
||||
@Override
|
||||
protected FilenameFilter getFileFilter() {
|
||||
return new FilenameFilter() {
|
||||
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return dir.isDirectory();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
12
src/main/java/forge/deck/io/IDeckReader.java
Normal file
12
src/main/java/forge/deck/io/IDeckReader.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package forge.deck.io;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import forge.item.IHasName;
|
||||
|
||||
|
||||
public interface IDeckReader<T extends IHasName> {
|
||||
Map<String, T> readAll();
|
||||
//T read(File file);
|
||||
}
|
||||
|
||||
15
src/main/java/forge/deck/io/IDeckSerializer.java
Normal file
15
src/main/java/forge/deck/io/IDeckSerializer.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package forge.deck.io;
|
||||
|
||||
import forge.item.IHasName;
|
||||
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public interface IDeckSerializer<T extends IHasName> extends IDeckReader<T> {
|
||||
void save(T unit);
|
||||
void erase(T unit);
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,9 @@ public enum GameType {
|
||||
* the value
|
||||
* @return the game type
|
||||
*/
|
||||
public static GameType smartValueOf(final String value) {
|
||||
public static GameType smartValueOf(final String value, GameType defaultValue) {
|
||||
if ( null == value ) return defaultValue;
|
||||
|
||||
final String valToCompate = value.trim();
|
||||
for (final GameType v : GameType.values()) {
|
||||
if (v.name().compareToIgnoreCase(valToCompate) == 0) {
|
||||
|
||||
@@ -31,7 +31,6 @@ import javax.swing.JOptionPane;
|
||||
import net.slightlymagic.braids.util.lambda.Lambda1;
|
||||
import net.slightlymagic.maxmtg.Closure1;
|
||||
|
||||
import forge.AllZone;
|
||||
import forge.Card;
|
||||
import forge.CardList;
|
||||
import forge.Constant;
|
||||
@@ -39,8 +38,8 @@ import forge.SetUtils;
|
||||
import forge.card.BoosterGenerator;
|
||||
import forge.card.CardBlock;
|
||||
import forge.card.CardSet;
|
||||
import forge.deck.CustomLimited;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckManager;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.item.CardDb;
|
||||
import forge.item.CardPrinted;
|
||||
@@ -161,8 +160,7 @@ public final class BoosterDraft implements IBoosterDraft {
|
||||
}
|
||||
|
||||
private void setupCustomDraft(final CustomLimited draft) {
|
||||
final DeckManager dio = AllZone.getDeckManager();
|
||||
final Deck dPool = dio.getDeck(draft.getDeckFile());
|
||||
final ItemPoolView<CardPrinted> dPool = draft.getCardPool();
|
||||
if (dPool == null) {
|
||||
throw new RuntimeException("BoosterGenerator : deck not found - " + draft.getDeckFile());
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ import forge.CardListUtil;
|
||||
import forge.Constant;
|
||||
import forge.card.spellability.AbilityMana;
|
||||
import forge.deck.Deck;
|
||||
import forge.game.GameType;
|
||||
import forge.util.MyRandom;
|
||||
|
||||
/**
|
||||
@@ -361,7 +360,7 @@ public class BoosterDraftAI {
|
||||
* @return a {@link forge.deck.Deck} object.
|
||||
*/
|
||||
private Deck buildDeck(final CardList dList, final DeckColors pClrs) {
|
||||
final Deck out = new Deck(GameType.Draft);
|
||||
|
||||
final CardList outList = new CardList();
|
||||
int cardsNeeded = 22;
|
||||
int landsNeeded = 18;
|
||||
@@ -618,15 +617,13 @@ public class BoosterDraftAI {
|
||||
}
|
||||
}
|
||||
if (outList.size() == 40) {
|
||||
final Deck out = new Deck();
|
||||
out.getMain().add(outList);
|
||||
out.getSideboard().add(aiPlayables);
|
||||
out.getSideboard().add(dList);
|
||||
|
||||
} else {
|
||||
throw new RuntimeException("BoosterDraftAI : buildDeck() error, decksize not 40");
|
||||
}
|
||||
|
||||
return out;
|
||||
return out;
|
||||
}
|
||||
throw new RuntimeException("BoosterDraftAI : buildDeck() error, decksize not 40");
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -36,9 +36,8 @@ import forge.card.BoosterGenerator;
|
||||
import forge.card.CardBlock;
|
||||
import forge.card.CardSet;
|
||||
import forge.card.spellability.AbilityMana;
|
||||
import forge.deck.CustomLimited;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckManager;
|
||||
import forge.game.GameType;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.item.CardDb;
|
||||
import forge.item.CardPrinted;
|
||||
@@ -154,13 +153,7 @@ public class SealedDeck {
|
||||
final CustomLimited draft = (CustomLimited) GuiUtils.getChoice("Choose Custom Sealed Pool",
|
||||
customs.toArray());
|
||||
|
||||
final DeckManager dio = AllZone.getDeckManager();
|
||||
final Deck dPool = dio.getDeck(draft.getDeckFile());
|
||||
if (dPool == null) {
|
||||
throw new RuntimeException("BoosterGenerator : deck not found - " + draft.getDeckFile());
|
||||
}
|
||||
|
||||
final BoosterGenerator bpCustom = new BoosterGenerator(dPool);
|
||||
final BoosterGenerator bpCustom = new BoosterGenerator(draft.getCardPool());
|
||||
final Lambda1<List<CardPrinted>, BoosterGenerator> fnPick = new Lambda1<List<CardPrinted>, BoosterGenerator>() {
|
||||
@Override
|
||||
public List<CardPrinted> apply(final BoosterGenerator pack) {
|
||||
@@ -200,7 +193,7 @@ public class SealedDeck {
|
||||
final ItemPool<CardPrinted> pool = new ItemPool<CardPrinted>(CardPrinted.class);
|
||||
|
||||
for (int i = 0; i < this.packs.size(); i++) {
|
||||
pool.addAllCards(this.packs.get(i).apply());
|
||||
pool.addAllFlat(this.packs.get(i).apply());
|
||||
}
|
||||
|
||||
return pool;
|
||||
@@ -433,7 +426,7 @@ public class SealedDeck {
|
||||
}
|
||||
}
|
||||
|
||||
final Deck aiDeck = new Deck(GameType.Sealed);
|
||||
final Deck aiDeck = new Deck();
|
||||
|
||||
for (i = 0; i < deck.size(); i++) {
|
||||
if (deck.get(i).getName().equals("Plains") || deck.get(i).getName().equals("Island")
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.gui.deckeditor;
|
||||
|
||||
import forge.deck.Deck;
|
||||
import forge.game.GameType;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.ItemPoolView;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA. User: dhudson Date: 6/24/11
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public interface DeckDisplay {
|
||||
/**
|
||||
*
|
||||
* setDeck.
|
||||
*
|
||||
* @param top
|
||||
* ItemPoolView<CardPrinted>
|
||||
* @param bottom
|
||||
* ItemPoolView<CardPrinted>
|
||||
* @param gameType
|
||||
* GameType
|
||||
*/
|
||||
void setDeck(ItemPoolView<CardPrinted> top, ItemPoolView<CardPrinted> bottom, GameType gameType);
|
||||
|
||||
/**
|
||||
*
|
||||
* setItems.
|
||||
*
|
||||
* @param <T>
|
||||
* InventoryItem
|
||||
* @param topParam
|
||||
* ItemPoolView<T>
|
||||
* @param bottomParam
|
||||
* ItemPoolView<T>
|
||||
* @param gt
|
||||
* GameType
|
||||
*/
|
||||
<T extends InventoryItem> void setItems(ItemPoolView<T> topParam, ItemPoolView<T> bottomParam, GameType gt);
|
||||
|
||||
/**
|
||||
*
|
||||
* Top shows available card pool. if constructed, top shows all cards if
|
||||
* sealed, top shows 5 booster packs if draft, top shows cards that were
|
||||
* chosen
|
||||
*
|
||||
* @return ItemPoolView<InventoryItem>
|
||||
*/
|
||||
ItemPoolView<InventoryItem> getTop();
|
||||
|
||||
//
|
||||
/**
|
||||
*
|
||||
* Bottom shows cards that the user has chosen for his library.
|
||||
*
|
||||
* @return ItemPoolView<InventoryItem>
|
||||
*/
|
||||
ItemPoolView<InventoryItem> getBottom();
|
||||
|
||||
/**
|
||||
*
|
||||
* Set title.
|
||||
*
|
||||
* @param message
|
||||
* String
|
||||
*/
|
||||
void setTitle(String message);
|
||||
|
||||
/**
|
||||
*
|
||||
* Get deck.
|
||||
*
|
||||
* @return Deck
|
||||
*/
|
||||
Deck getDeck();
|
||||
|
||||
/**
|
||||
*
|
||||
* Get game type.
|
||||
*
|
||||
* @return GameType
|
||||
*/
|
||||
GameType getGameType();
|
||||
}
|
||||
@@ -27,8 +27,11 @@ import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
|
||||
import net.slightlymagic.maxmtg.Predicate;
|
||||
import forge.deck.Deck;
|
||||
import forge.game.GameType;
|
||||
import forge.Command;
|
||||
import forge.gui.deckeditor.elements.CardPanelBase;
|
||||
import forge.gui.deckeditor.elements.DeckAnalysis;
|
||||
import forge.gui.deckeditor.elements.FilterCheckBoxes;
|
||||
import forge.gui.deckeditor.elements.TableView;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.ItemPool;
|
||||
@@ -37,7 +40,7 @@ import forge.item.ItemPoolView;
|
||||
/**
|
||||
* The Class DeckEditorBase.
|
||||
*/
|
||||
public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
|
||||
public abstract class DeckEditorBase<T extends InventoryItem, TModel> extends JFrame {
|
||||
private static final long serialVersionUID = -401223933343539977L;
|
||||
|
||||
/** The filter boxes. */
|
||||
@@ -52,22 +55,10 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
|
||||
|
||||
// CardPools and Table data for top and bottom lists
|
||||
/** The top. */
|
||||
private TableWithCards topTableWithCards;
|
||||
private TableView<T> topTableWithCards;
|
||||
|
||||
/** The bottom. */
|
||||
private TableWithCards bottomTableWithCards;
|
||||
|
||||
private GameType gameType;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.gui.deckeditor.DeckDisplay#getGameType()
|
||||
*/
|
||||
@Override
|
||||
public final GameType getGameType() {
|
||||
return this.gameType;
|
||||
}
|
||||
private TableView<T> bottomTableWithCards;
|
||||
|
||||
// top shows available card pool
|
||||
// if constructed, top shows all cards
|
||||
@@ -78,7 +69,7 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
|
||||
*
|
||||
* @return the top table model
|
||||
*/
|
||||
public final TableWithCards getTopTableModel() {
|
||||
public final TableView<T> getTopTableModel() {
|
||||
return this.getTopTableWithCards();
|
||||
}
|
||||
|
||||
@@ -87,8 +78,7 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
|
||||
*
|
||||
* @see forge.gui.deckeditor.DeckDisplay#getTop()
|
||||
*/
|
||||
@Override
|
||||
public final ItemPoolView<InventoryItem> getTop() {
|
||||
public final ItemPoolView<T> getTop() {
|
||||
return this.getTopTableWithCards().getCards();
|
||||
}
|
||||
|
||||
@@ -98,11 +88,13 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
|
||||
*
|
||||
* @see forge.gui.deckeditor.DeckDisplay#getBottom()
|
||||
*/
|
||||
@Override
|
||||
public final ItemPoolView<InventoryItem> getBottom() {
|
||||
public final ItemPoolView<T> getBottom() {
|
||||
return this.getBottomTableWithCards().getCards();
|
||||
}
|
||||
|
||||
|
||||
public abstract IDeckManager<TModel> getController();
|
||||
|
||||
// THIS IS HERE FOR OVERLOADING!!!1
|
||||
// or may be return abstract getFilter from derived class + this filter ...
|
||||
// virtual protected member, but later
|
||||
@@ -111,8 +103,9 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
|
||||
*
|
||||
* @return the predicate
|
||||
*/
|
||||
protected abstract Predicate<InventoryItem> buildFilter();
|
||||
protected abstract Predicate<T> buildFilter();
|
||||
|
||||
public abstract void show(final Command exitCommand);
|
||||
/**
|
||||
* Analysis button_action performed.
|
||||
*
|
||||
@@ -126,36 +119,13 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
|
||||
JOptionPane.showMessageDialog(null, "Cards in deck not found.", "Analysis Deck",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
} else {
|
||||
final DeckEditorBase g = DeckEditorBase.this;
|
||||
final DeckEditorBase<T, TModel> g = DeckEditorBase.this;
|
||||
final DeckAnalysis dAnalysis = new DeckAnalysis(g, deck);
|
||||
dAnalysis.setVisible(true);
|
||||
g.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new deck editor base.
|
||||
*
|
||||
* @param gametype
|
||||
* the gametype
|
||||
*/
|
||||
public DeckEditorBase(final GameType gametype) {
|
||||
this.gameType = gametype;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.gui.deckeditor.DeckDisplay#setDeck(forge.item.ItemPoolView,
|
||||
* forge.item.ItemPoolView, forge.game.GameType)
|
||||
*/
|
||||
@Override
|
||||
public void setDeck(final ItemPoolView<CardPrinted> topParam, final ItemPoolView<CardPrinted> bottomParam,
|
||||
final GameType gt) {
|
||||
this.gameType = gt;
|
||||
this.getTopTableWithCards().setDeck(topParam);
|
||||
this.getBottomTableWithCards().setDeck(bottomParam);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
@@ -163,13 +133,9 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
|
||||
* @see forge.gui.deckeditor.DeckDisplay#setItems(forge.item.ItemPoolView,
|
||||
* forge.item.ItemPoolView, forge.game.GameType)
|
||||
*/
|
||||
@Override
|
||||
public final <T extends InventoryItem> void setItems(final ItemPoolView<T> topParam,
|
||||
final ItemPoolView<T> bottomParam, final GameType gt) {
|
||||
this.gameType = gt;
|
||||
this.getTopTableWithCards().setDeck(topParam);
|
||||
this.getBottomTableWithCards().setDeck(bottomParam);
|
||||
}
|
||||
public abstract void updateView();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Update display.
|
||||
@@ -235,23 +201,6 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
|
||||
} // Happend only on ENTER pressed
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.gui.deckeditor.DeckDisplay#getDeck()
|
||||
*/
|
||||
@Override
|
||||
public final Deck getDeck() {
|
||||
final Deck deck = new Deck(this.gameType);
|
||||
deck.getMain().addAll(this.getBottom());
|
||||
|
||||
// if sealed or draft, move "top" to sideboard
|
||||
if (this.gameType.isLimited() && (this.gameType != GameType.Quest)) {
|
||||
deck.getSideboard().addAll(this.getTop());
|
||||
}
|
||||
return deck;
|
||||
} // getDeck()
|
||||
|
||||
/**
|
||||
* Gets the item listener updates display.
|
||||
*
|
||||
@@ -313,7 +262,7 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
|
||||
* @param cardView0
|
||||
* the cardView to set
|
||||
*/
|
||||
public void setCardView(final CardPanelBase cardView0) {
|
||||
protected void setCardView(final CardPanelBase cardView0) {
|
||||
this.cardView = cardView0;
|
||||
}
|
||||
|
||||
@@ -341,7 +290,7 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
|
||||
*
|
||||
* @return the bottomTableWithCards
|
||||
*/
|
||||
public TableWithCards getBottomTableWithCards() {
|
||||
public TableView<T> getBottomTableWithCards() {
|
||||
return this.bottomTableWithCards;
|
||||
}
|
||||
|
||||
@@ -351,7 +300,7 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
|
||||
* @param bottomTableWithCards0
|
||||
* the bottomTableWithCards to set
|
||||
*/
|
||||
public void setBottomTableWithCards(final TableWithCards bottomTableWithCards0) {
|
||||
public void setBottomTableWithCards(final TableView<T> bottomTableWithCards0) {
|
||||
this.bottomTableWithCards = bottomTableWithCards0;
|
||||
}
|
||||
|
||||
@@ -360,7 +309,7 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
|
||||
*
|
||||
* @return the topTableWithCards
|
||||
*/
|
||||
public TableWithCards getTopTableWithCards() {
|
||||
public TableView<T> getTopTableWithCards() {
|
||||
return this.topTableWithCards;
|
||||
}
|
||||
|
||||
@@ -370,7 +319,7 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
|
||||
* @param topTableWithCards0
|
||||
* the topTableWithCards to set
|
||||
*/
|
||||
public void setTopTableWithCards(final TableWithCards topTableWithCards0) {
|
||||
public void setTopTableWithCards(final TableView<T> topTableWithCards0) {
|
||||
this.topTableWithCards = topTableWithCards0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,859 +0,0 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.gui.deckeditor;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.Card;
|
||||
import forge.CardList;
|
||||
import forge.Command;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckIO;
|
||||
import forge.deck.DeckManager;
|
||||
import forge.deck.generate.GenerateConstructedDeck;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.game.GameType;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.item.CardDb;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.ItemPool;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Gui_DeckEditor_Menu class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public final class DeckEditorCommonMenu extends JMenuBar {
|
||||
|
||||
/** Constant <code>serialVersionUID=-4037993759604768755L</code>. */
|
||||
private static final long serialVersionUID = -4037993759604768755L;
|
||||
|
||||
/** Constant <code>previousDirectory</code>. */
|
||||
private static File previousDirectory = null;
|
||||
|
||||
private final DeckManager deckManager;
|
||||
|
||||
private boolean isDeckSaved = true;
|
||||
|
||||
private String currentDeckName;
|
||||
private final DeckDisplay deckDisplay;
|
||||
|
||||
private final Command exitCommand;
|
||||
|
||||
/**
|
||||
*
|
||||
* Menu for Deck Editor.
|
||||
*
|
||||
* @param inDisplay
|
||||
* a DeckDisplay
|
||||
* @param dckManager
|
||||
* a DeckManager
|
||||
* @param exit
|
||||
* a Command
|
||||
*/
|
||||
public DeckEditorCommonMenu(final DeckDisplay inDisplay, final DeckManager dckManager, final Command exit) {
|
||||
this.deckDisplay = inDisplay;
|
||||
this.exitCommand = exit;
|
||||
this.deckManager = dckManager;
|
||||
|
||||
// this is added just to make save() and saveAs() work ok
|
||||
// when first started up, just a silly patch
|
||||
this.setDeckData("", true);
|
||||
|
||||
this.setupMenu();
|
||||
this.setupSortMenu();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* setupSortMenu.
|
||||
* </p>
|
||||
*/
|
||||
private void setupSortMenu() {
|
||||
final JMenuItem name = new JMenuItem("Card Name");
|
||||
final JMenuItem cost = new JMenuItem("Cost");
|
||||
final JMenuItem color = new JMenuItem("Color");
|
||||
final JMenuItem type = new JMenuItem("Type");
|
||||
final JMenuItem stats = new JMenuItem("Power/Toughness");
|
||||
final JMenuItem rarity = new JMenuItem("Rarity");
|
||||
|
||||
final JMenu menu = new JMenu("Sort By");
|
||||
menu.add(name);
|
||||
menu.add(cost);
|
||||
menu.add(color);
|
||||
menu.add(type);
|
||||
menu.add(stats);
|
||||
menu.add(rarity);
|
||||
|
||||
this.add(menu);
|
||||
|
||||
name.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
((DeckEditorCommon) DeckEditorCommonMenu.this.deckDisplay).getTopTableModel().sort(1, true);
|
||||
}
|
||||
});
|
||||
|
||||
// 0 1 2 3 4 5 6
|
||||
// private String column[] = {"Qty", "Name", "Cost", "Color", "Type",
|
||||
// "Stats", "Rarity"};
|
||||
cost.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
((DeckEditorCommon) DeckEditorCommonMenu.this.deckDisplay).getTopTableModel().sort(4).sort(3).sort(2);
|
||||
}
|
||||
});
|
||||
|
||||
color.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
((DeckEditorCommon) DeckEditorCommonMenu.this.deckDisplay).getTopTableModel().sort(4).sort(2).sort(3);
|
||||
}
|
||||
});
|
||||
|
||||
type.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
((DeckEditorCommon) DeckEditorCommonMenu.this.deckDisplay).getTopTableModel().sort(2).sort(3).sort(4);
|
||||
}
|
||||
});
|
||||
|
||||
stats.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
((DeckEditorCommon) DeckEditorCommonMenu.this.deckDisplay).getTopTableModel().sort(4).sort(2).sort(3)
|
||||
.sort(5);
|
||||
}
|
||||
});
|
||||
|
||||
rarity.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
// sort by cost, type, color, rarity
|
||||
((DeckEditorCommon) DeckEditorCommonMenu.this.deckDisplay).getTopTableModel().sort(2).sort(4).sort(3)
|
||||
.sort(6);
|
||||
}
|
||||
});
|
||||
} // setupSortMenu()
|
||||
|
||||
/**
|
||||
* New constructed.
|
||||
*
|
||||
* @param careAboutOldDeck
|
||||
* a boolean
|
||||
*/
|
||||
public void newConstructed(final boolean careAboutOldDeck) {
|
||||
if (careAboutOldDeck && !this.canLeaveCurrentDeck()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setDeckData("", true);
|
||||
|
||||
this.deckDisplay.setDeck(null, null, GameType.Constructed);
|
||||
}
|
||||
|
||||
private void newRandomConstructed() {
|
||||
if (!this.canLeaveCurrentDeck()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setDeckData("", false);
|
||||
|
||||
// The only remaining reference to global variable!
|
||||
final CardList random = new CardList(forge.AllZone.getCardFactory().getRandomCombinationWithoutRepetition(
|
||||
15 * 5));
|
||||
|
||||
final ItemPool<CardPrinted> cpRandom = new ItemPool<CardPrinted>(CardPrinted.class);
|
||||
for (final Card c : random) {
|
||||
cpRandom.add(CardDb.instance().getCard(c));
|
||||
}
|
||||
cpRandom.add(CardDb.instance().getCard("Forest"));
|
||||
cpRandom.add(CardDb.instance().getCard("Island"));
|
||||
cpRandom.add(CardDb.instance().getCard("Plains"));
|
||||
cpRandom.add(CardDb.instance().getCard("Swamp"));
|
||||
cpRandom.add(CardDb.instance().getCard("Mountain"));
|
||||
cpRandom.add(CardDb.instance().getCard("Terramorphic Expanse"));
|
||||
|
||||
this.deckDisplay.setDeck(cpRandom, null, GameType.Constructed);
|
||||
}
|
||||
|
||||
private void newGenerateConstructed() {
|
||||
if (!this.canLeaveCurrentDeck()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setDeckData("", false);
|
||||
|
||||
final GenerateConstructedDeck gen = new GenerateConstructedDeck();
|
||||
|
||||
final ItemPool<CardPrinted> generated = new ItemPool<CardPrinted>(CardPrinted.class);
|
||||
for (final Card c : gen.generateDeck()) {
|
||||
generated.add(CardDb.instance().getCard(c));
|
||||
}
|
||||
this.deckDisplay.setDeck(null, generated, GameType.Constructed);
|
||||
}
|
||||
|
||||
private File getImportFilename() {
|
||||
final JFileChooser chooser = new JFileChooser(DeckEditorCommonMenu.previousDirectory);
|
||||
|
||||
chooser.addChoosableFileFilter(DeckIO.DCK_FILTER);
|
||||
final int returnVal = chooser.showOpenDialog(null);
|
||||
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
final File file = chooser.getSelectedFile();
|
||||
DeckEditorCommonMenu.previousDirectory = file.getParentFile();
|
||||
return file;
|
||||
}
|
||||
return null;
|
||||
} // openFileDialog()
|
||||
|
||||
private void importDeck() {
|
||||
final File file = this.getImportFilename();
|
||||
|
||||
if (file == null) {
|
||||
} else if (file.getName().endsWith(".dck")) {
|
||||
try {
|
||||
final FileChannel srcChannel = new FileInputStream(file).getChannel();
|
||||
final File dst = new File(ForgeProps.getFile(NewConstants.NEW_DECKS).getAbsolutePath(), file.getName());
|
||||
if (!dst.createNewFile()) {
|
||||
JOptionPane.showMessageDialog(null, "Cannot import deck " + file.getName()
|
||||
+ ", a deck currently has that name.");
|
||||
return;
|
||||
}
|
||||
final FileChannel dstChannel = new FileOutputStream(dst).getChannel();
|
||||
dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
|
||||
srcChannel.close();
|
||||
dstChannel.close();
|
||||
|
||||
final Deck newDeck = DeckIO.readDeck(file);
|
||||
this.deckManager.addDeck(newDeck);
|
||||
this.showDeck(newDeck, newDeck.getDeckType());
|
||||
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : importDeck() error, " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* exportDeck.
|
||||
* </p>
|
||||
*/
|
||||
private void exportDeck() {
|
||||
final File filename = this.getExportFilename();
|
||||
if (filename == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Deck deck = this.getDeck();
|
||||
try {
|
||||
DeckIO.writeDeck(deck, filename);
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : exportDeck() error, " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
private File getExportFilename() {
|
||||
final JFileChooser save = new JFileChooser(DeckEditorCommonMenu.previousDirectory);
|
||||
save.setDialogTitle("Export Deck Filename");
|
||||
save.setDialogType(JFileChooser.SAVE_DIALOG);
|
||||
save.setFileFilter(DeckIO.DCK_FILTER);
|
||||
|
||||
if (save.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
|
||||
final File file = save.getSelectedFile();
|
||||
final String check = file.getAbsolutePath();
|
||||
|
||||
DeckEditorCommonMenu.previousDirectory = file.getParentFile();
|
||||
|
||||
return check.endsWith(".dck") ? file : new File(check + ".dck");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Generate Proxy for a Deck.
|
||||
* </p>
|
||||
*/
|
||||
private void generateProxies() {
|
||||
final File filename = this.getProxiesFilename();
|
||||
if (filename == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Deck deck = this.getDeck();
|
||||
try {
|
||||
DeckIO.writeDeckHtml(deck, filename);
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : printProxies() error, " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
private File getProxiesFilename() {
|
||||
final JFileChooser save = new JFileChooser(DeckEditorCommonMenu.previousDirectory);
|
||||
save.setDialogTitle("Proxy HTML Filename");
|
||||
save.setDialogType(JFileChooser.SAVE_DIALOG);
|
||||
save.setFileFilter(DeckIO.HTML_FILTER);
|
||||
|
||||
if (save.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
|
||||
final File file = save.getSelectedFile();
|
||||
final String check = file.getAbsolutePath();
|
||||
|
||||
DeckEditorCommonMenu.previousDirectory = file.getParentFile();
|
||||
|
||||
return check.endsWith(".html") ? file : new File(check + ".html");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void openDeck(final GameType gameType) {
|
||||
if (!this.canLeaveCurrentDeck()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String name = this.getUserInputOpenDeck(gameType);
|
||||
|
||||
if (StringUtils.isBlank(name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Deck deck = gameType == GameType.Draft ? this.deckManager.getDraftDeck(name)[0] : this.deckManager
|
||||
.getDeck(name);
|
||||
this.showDeck(deck, gameType);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* showDeck.
|
||||
*
|
||||
* @param deck
|
||||
* a Deck
|
||||
* @param gameType
|
||||
* a GameType
|
||||
*/
|
||||
public void showDeck(final Deck deck, final GameType gameType) {
|
||||
this.setDeckData(deck.getName(), true);
|
||||
if (gameType.isLimited()) {
|
||||
this.deckDisplay.setDeck(deck.getSideboard(), deck.getMain(), gameType);
|
||||
} else {
|
||||
this.deckDisplay.setDeck(null, deck.getMain(), gameType);
|
||||
}
|
||||
}
|
||||
|
||||
private void save() {
|
||||
|
||||
if (this.currentDeckName.equals("")) {
|
||||
this.saveAs();
|
||||
return;
|
||||
}
|
||||
|
||||
final Deck deck = this.getDeck();
|
||||
if (this.deckDisplay.getGameType().equals(GameType.Draft)) {
|
||||
this.setDeckData(this.currentDeckName, true);
|
||||
// write booster deck
|
||||
final Deck[] all = this.deckManager.getDraftDeck(this.currentDeckName);
|
||||
all[0] = deck;
|
||||
this.deckManager.addDraftDeck(all);
|
||||
DeckIO.writeDraftDecks(all);
|
||||
} else { // constructed or sealed
|
||||
this.setDeckData(this.currentDeckName, true);
|
||||
this.deckManager.addDeck(deck);
|
||||
DeckIO.writeDeck(deck, DeckIO.makeFileName(deck));
|
||||
}
|
||||
this.isDeckSaved = true;
|
||||
}
|
||||
|
||||
private void saveAs() {
|
||||
final String name = this.getDeckNameFromDialog();
|
||||
|
||||
if (name.equals("")) {
|
||||
return;
|
||||
}
|
||||
this.setDeckData(name, true);
|
||||
|
||||
final Deck deck = this.getDeck();
|
||||
if (this.deckDisplay.getGameType().equals(GameType.Draft)) {
|
||||
// MUST copy array
|
||||
final Deck[] read = this.deckManager.getDraftDeck(this.currentDeckName);
|
||||
final Deck[] all = new Deck[read.length];
|
||||
|
||||
System.arraycopy(read, 0, all, 0, read.length);
|
||||
|
||||
all[0] = deck;
|
||||
this.deckManager.addDraftDeck(all);
|
||||
DeckIO.writeDraftDecks(all);
|
||||
} else { // constructed and sealed
|
||||
this.deckManager.addDeck(deck);
|
||||
DeckIO.writeDeck(deck, DeckIO.makeFileName(deck));
|
||||
}
|
||||
this.isDeckSaved = true;
|
||||
}
|
||||
|
||||
private void delete() {
|
||||
if (StringUtils.isBlank(this.currentDeckName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int n = JOptionPane.showConfirmDialog(null, "Do you want to delete this deck " + this.currentDeckName
|
||||
+ " ?", "Delete", JOptionPane.YES_NO_OPTION);
|
||||
|
||||
if (n == JOptionPane.NO_OPTION) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.deckDisplay.getGameType().equals(GameType.Draft)) {
|
||||
this.deckManager.deleteDraftDeck(this.currentDeckName);
|
||||
} else {
|
||||
this.deckManager.deleteDeck(this.currentDeckName);
|
||||
}
|
||||
|
||||
this.setDeckData("", true);
|
||||
this.deckDisplay.setDeck(null, null, this.deckDisplay.getGameType());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* close window.
|
||||
*/
|
||||
public void close() {
|
||||
if (!this.canLeaveCurrentDeck()) {
|
||||
return;
|
||||
}
|
||||
this.exitCommand.execute();
|
||||
}
|
||||
|
||||
private boolean canLeaveCurrentDeck() {
|
||||
if (this.isSaved()) {
|
||||
return true;
|
||||
}
|
||||
final String message = String.format("Do you wish to save changes you made to your current deck '%s'?",
|
||||
this.currentDeckName);
|
||||
final int choice = JOptionPane
|
||||
.showConfirmDialog((Component) this.deckDisplay, message, "You have unsaved changes in your deck",
|
||||
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
|
||||
if (JOptionPane.CANCEL_OPTION == choice) {
|
||||
return false;
|
||||
}
|
||||
if (JOptionPane.NO_OPTION == choice) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final Deck deck = this.getDeck();
|
||||
deck.setName(this.currentDeckName);
|
||||
DeckIO.writeDeck(deck, DeckIO.makeFileName(deck));
|
||||
return true;
|
||||
}
|
||||
|
||||
private Deck getDeck() {
|
||||
final Deck deck = this.deckDisplay.getDeck();
|
||||
deck.setName(this.currentDeckName);
|
||||
return deck;
|
||||
}
|
||||
|
||||
private void setDeckData(final String deckName, final boolean inDeckSaved) {
|
||||
this.currentDeckName = deckName;
|
||||
this.isDeckSaved = inDeckSaved;
|
||||
|
||||
this.deckDisplay.setTitle("Deck Editor : " + this.currentDeckName);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Get Deck Name.
|
||||
*
|
||||
* @return a String
|
||||
*/
|
||||
public String getDeckName() {
|
||||
return this.currentDeckName;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Is Saved.
|
||||
*
|
||||
* @return a boolean
|
||||
*/
|
||||
public boolean isSaved() {
|
||||
return this.isDeckSaved;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getUserInput_GetDeckName.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
private String getDeckNameFromDialog() {
|
||||
final Object o = JOptionPane.showInputDialog(null, "Save As", "Deck Name", JOptionPane.OK_CANCEL_OPTION);
|
||||
|
||||
if (o == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
final String deckName = DeckIO.cleanDeckName(o.toString());
|
||||
final boolean isDraft = this.deckDisplay.getGameType() == GameType.Draft;
|
||||
final boolean isUniqueName = isDraft ? this.deckManager.isUniqueDraft(deckName) : this.deckManager
|
||||
.isUnique(deckName);
|
||||
final boolean isGoodName = isUniqueName && StringUtils.isNotBlank(deckName);
|
||||
|
||||
if (isGoodName) {
|
||||
return deckName;
|
||||
}
|
||||
|
||||
JOptionPane.showMessageDialog(null, "Please pick another deck name, another deck currently has that name.");
|
||||
return this.getDeckNameFromDialog();
|
||||
}
|
||||
|
||||
private String getUserInputOpenDeck(final GameType deckType) {
|
||||
final ArrayList<String> choices = this.deckManager.getDeckNames(deckType);
|
||||
if (choices.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(null, "No decks found", "Open Deck", JOptionPane.PLAIN_MESSAGE);
|
||||
return null;
|
||||
}
|
||||
|
||||
final Object o = GuiUtils.getChoiceOptional("Open Deck", choices.toArray());
|
||||
return o == null ? null : o.toString();
|
||||
}
|
||||
|
||||
// deck.setName(currentDeckName);
|
||||
|
||||
/**
|
||||
*
|
||||
* Notify of a Deck Change.
|
||||
*/
|
||||
public void notifyDeckChange() {
|
||||
this.isDeckSaved = false;
|
||||
}
|
||||
|
||||
private void setupMenu() {
|
||||
final JMenuItem newConstructed = new JMenuItem("New Deck - Constructed");
|
||||
|
||||
// JMenuItem newSealed = new JMenuItem("New Deck - Sealed");
|
||||
// JMenuItem newDraft = new JMenuItem("New Deck - Draft");
|
||||
|
||||
final JMenuItem newRandomConstructed = new JMenuItem("New Deck - Generate Random Constructed Cardpool");
|
||||
final JMenuItem newGenerateConstructed = new JMenuItem("New Deck - Generate Constructed Deck");
|
||||
|
||||
final JMenuItem importDeck = new JMenuItem("Import Deck...");
|
||||
final JMenuItem exportDeck = new JMenuItem("Export Deck...");
|
||||
// JMenuItem downloadDeck = new JMenuItem("Download Deck");
|
||||
|
||||
final JMenuItem openConstructed = new JMenuItem("Open Deck - Constructed...");
|
||||
final JMenuItem openSealed = new JMenuItem("Open Deck - Sealed");
|
||||
final JMenuItem openDraft = new JMenuItem("Open Deck - Draft");
|
||||
|
||||
// newDraftItem = newDraft;
|
||||
// newDraftItem.setEnabled(false);
|
||||
|
||||
final JMenuItem save = new JMenuItem("Save");
|
||||
final JMenuItem saveAs = new JMenuItem("Save As...");
|
||||
final JMenuItem delete = new JMenuItem("Delete");
|
||||
final JMenuItem close = new JMenuItem("Close");
|
||||
|
||||
final JMenu fileMenu = new JMenu("Deck Actions");
|
||||
fileMenu.add(newConstructed);
|
||||
|
||||
// fileMenu.add(newSealed);
|
||||
// fileMenu.add(newDraft);
|
||||
fileMenu.addSeparator();
|
||||
|
||||
fileMenu.add(openConstructed);
|
||||
fileMenu.add(openSealed);
|
||||
fileMenu.add(openDraft);
|
||||
fileMenu.addSeparator();
|
||||
|
||||
fileMenu.add(importDeck);
|
||||
fileMenu.add(exportDeck);
|
||||
|
||||
final JMenuItem generateProxies = new JMenuItem("Generate Proxies...");
|
||||
fileMenu.add(generateProxies);
|
||||
|
||||
generateProxies.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DeckEditorCommonMenu.this.generateProxies();
|
||||
}
|
||||
});
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : generateProxies() error - " + ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
// fileMenu.add(downloadDeck);
|
||||
fileMenu.addSeparator();
|
||||
|
||||
fileMenu.add(newRandomConstructed);
|
||||
fileMenu.add(newGenerateConstructed);
|
||||
fileMenu.addSeparator();
|
||||
|
||||
fileMenu.add(save);
|
||||
fileMenu.add(saveAs);
|
||||
fileMenu.add(delete);
|
||||
fileMenu.addSeparator();
|
||||
|
||||
fileMenu.add(close);
|
||||
|
||||
this.add(fileMenu);
|
||||
|
||||
// add listeners
|
||||
exportDeck.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DeckEditorCommonMenu.this.exportDeck();
|
||||
}
|
||||
});
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : exportDeck() error - " + ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
importDeck.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DeckEditorCommonMenu.this.importDeck();
|
||||
}
|
||||
});
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : importDeck() error - " + ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* downloadDeck.addActionListener(new ActionListener() { public void
|
||||
* actionPerformed(final ActionEvent ev) { try {
|
||||
* SwingUtilities.invokeLater(new Runnable() { public void run() {
|
||||
* downloadDeck(); } }); } catch (Exception ex) {
|
||||
* ErrorViewer.showError(ex); throw new
|
||||
* RuntimeException("Gui_DeckEditor_Menu : downloadDeck() error - " +
|
||||
* ex); } } });
|
||||
*/
|
||||
newConstructed.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DeckEditorCommonMenu.this.newConstructed(true);
|
||||
}
|
||||
});
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : newConstructed() error - " + ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
newRandomConstructed.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DeckEditorCommonMenu.this.newRandomConstructed();
|
||||
}
|
||||
});
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : newRandomConstructed() error - " + ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
newGenerateConstructed.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DeckEditorCommonMenu.this.newGenerateConstructed();
|
||||
}
|
||||
});
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : newRandomConstructed() error - " + ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
openConstructed.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DeckEditorCommonMenu.this.openDeck(GameType.Constructed);
|
||||
}
|
||||
});
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : openConstructed() error - " + ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
openSealed.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DeckEditorCommonMenu.this.openDeck(GameType.Sealed);
|
||||
}
|
||||
});
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : openSealed() error - " + ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
openDraft.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DeckEditorCommonMenu.this.openDeck(GameType.Draft);
|
||||
}
|
||||
});
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : openDraft() error - " + ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
save.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DeckEditorCommonMenu.this.save();
|
||||
}
|
||||
});
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : save() error - " + ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
saveAs.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DeckEditorCommonMenu.this.saveAs();
|
||||
}
|
||||
});
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : saveAs() error - " + ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
delete.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DeckEditorCommonMenu.this.delete();
|
||||
}
|
||||
});
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : delete() error - " + ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
close.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DeckEditorCommonMenu.this.close();
|
||||
}
|
||||
});
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : close() error - " + ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
} // setupMenu()
|
||||
}
|
||||
@@ -36,16 +36,22 @@ import javax.swing.JCheckBox;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import net.slightlymagic.braids.util.lambda.Lambda0;
|
||||
import net.slightlymagic.maxmtg.Predicate;
|
||||
import forge.AllZone;
|
||||
import forge.Command;
|
||||
import forge.deck.Deck;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.game.GameType;
|
||||
import forge.gui.deckeditor.elements.CardPanelHeavy;
|
||||
import forge.gui.deckeditor.elements.FilterCheckBoxes;
|
||||
import forge.gui.deckeditor.elements.FilterNameTypeSetPanel;
|
||||
import forge.gui.deckeditor.elements.ManaCostRenderer;
|
||||
import forge.gui.deckeditor.elements.TableColumnInfo;
|
||||
import forge.gui.deckeditor.elements.TableView;
|
||||
import forge.item.CardDb;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.ItemPool;
|
||||
import forge.item.ItemPoolView;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -55,13 +61,10 @@ import forge.item.ItemPoolView;
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public final class DeckEditorCommon extends DeckEditorBase {
|
||||
public final class DeckEditorConstructed extends DeckEditorBase<CardPrinted, Deck> {
|
||||
/** Constant <code>serialVersionUID=130339644136746796L</code>. */
|
||||
private static final long serialVersionUID = 130339644136746796L;
|
||||
|
||||
/** The custom menu. */
|
||||
private DeckEditorCommonMenu customMenu;
|
||||
|
||||
private final JButton removeButton = new JButton();
|
||||
private final JButton addButton = new JButton();
|
||||
private final JButton importButton = new JButton();
|
||||
@@ -72,6 +75,7 @@ public final class DeckEditorCommon extends DeckEditorBase {
|
||||
private final JLabel jLabelAnalysisGap = new JLabel("");
|
||||
private FilterNameTypeSetPanel filterNameTypeSet;
|
||||
|
||||
private final IDeckManager<Deck> controller;
|
||||
/**
|
||||
* Show.
|
||||
*
|
||||
@@ -84,29 +88,24 @@ public final class DeckEditorCommon extends DeckEditorBase {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
DeckEditorCommon.this.dispose();
|
||||
DeckEditorConstructed.this.dispose();
|
||||
exitCommand.execute();
|
||||
}
|
||||
};
|
||||
|
||||
this.setCustomMenu(new DeckEditorCommonMenu(this, AllZone.getDeckManager(), exit));
|
||||
this.setJMenuBar(this.getCustomMenu());
|
||||
final MenuCommon menu = new MenuCommon(getController(), exit);
|
||||
this.setJMenuBar(menu);
|
||||
|
||||
// do not change this!!!!
|
||||
this.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(final WindowEvent ev) {
|
||||
DeckEditorCommon.this.getCustomMenu().close();
|
||||
}
|
||||
public void windowClosing(final WindowEvent ev) {menu.close(); }
|
||||
});
|
||||
|
||||
this.setup();
|
||||
|
||||
// show cards, makes this user friendly
|
||||
if (!this.getGameType().isLimited()) {
|
||||
this.getCustomMenu().newConstructed(false);
|
||||
}
|
||||
|
||||
|
||||
this.controller.newModel();
|
||||
|
||||
this.getTopTableWithCards().sort(1, true);
|
||||
this.getBottomTableWithCards().sort(1, true);
|
||||
|
||||
@@ -114,24 +113,15 @@ public final class DeckEditorCommon extends DeckEditorBase {
|
||||
|
||||
private void setup() {
|
||||
final List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>();
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Qty", 30, PresetColumns.FN_QTY_COMPARE,
|
||||
PresetColumns.FN_QTY_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Name", 175, PresetColumns.FN_NAME_COMPARE,
|
||||
PresetColumns.FN_NAME_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Cost", 75, PresetColumns.FN_COST_COMPARE,
|
||||
PresetColumns.FN_COST_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Color", 60, PresetColumns.FN_COLOR_COMPARE,
|
||||
PresetColumns.FN_COLOR_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.FN_TYPE_COMPARE,
|
||||
PresetColumns.FN_TYPE_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Stats", 60, PresetColumns.FN_STATS_COMPARE,
|
||||
PresetColumns.FN_STATS_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("R", 25, PresetColumns.FN_RARITY_COMPARE,
|
||||
PresetColumns.FN_RARITY_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Set", 40, PresetColumns.FN_SET_COMPARE,
|
||||
PresetColumns.FN_SET_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("AI", 30, PresetColumns.FN_AI_STATUS_COMPARE,
|
||||
PresetColumns.FN_AI_STATUS_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Qty", 30, PresetColumns.FN_QTY_COMPARE, PresetColumns.FN_QTY_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Name", 175, PresetColumns.FN_NAME_COMPARE, PresetColumns.FN_NAME_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Cost", 75, PresetColumns.FN_COST_COMPARE, PresetColumns.FN_COST_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Color", 60, PresetColumns.FN_COLOR_COMPARE, PresetColumns.FN_COLOR_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.FN_TYPE_COMPARE, PresetColumns.FN_TYPE_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Stats", 60, PresetColumns.FN_STATS_COMPARE, PresetColumns.FN_STATS_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("R", 25, PresetColumns.FN_RARITY_COMPARE, PresetColumns.FN_RARITY_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Set", 40, PresetColumns.FN_SET_COMPARE, PresetColumns.FN_SET_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("AI", 30, PresetColumns.FN_AI_STATUS_COMPARE, PresetColumns.FN_AI_STATUS_GET));
|
||||
columns.get(2).setCellRenderer(new ManaCostRenderer());
|
||||
|
||||
this.getTopTableWithCards().setup(columns, this.getCardView());
|
||||
@@ -150,12 +140,11 @@ public final class DeckEditorCommon extends DeckEditorBase {
|
||||
* @param gameType
|
||||
* the game type
|
||||
*/
|
||||
public DeckEditorCommon(final GameType gameType) {
|
||||
super(gameType);
|
||||
public DeckEditorConstructed() {
|
||||
try {
|
||||
this.setFilterBoxes(new FilterCheckBoxes(true));
|
||||
this.setTopTableWithCards(new TableWithCards("Avaliable Cards", true, true));
|
||||
this.setBottomTableWithCards(new TableWithCards("Deck", true));
|
||||
this.setTopTableWithCards(new TableView<CardPrinted>("Avaliable Cards", true, true, CardPrinted.class));
|
||||
this.setBottomTableWithCards(new TableView<CardPrinted>("Deck", true, CardPrinted.class));
|
||||
this.setCardView(new CardPanelHeavy());
|
||||
this.filterNameTypeSet = new FilterNameTypeSetPanel();
|
||||
|
||||
@@ -163,6 +152,9 @@ public final class DeckEditorCommon extends DeckEditorBase {
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
}
|
||||
|
||||
Lambda0<Deck> newCreator = new Lambda0<Deck>(){ @Override public Deck apply() { return new Deck(); } };
|
||||
controller = new DeckManagerOnDisk<Deck>(AllZone.getDecks().getConstructed(), this, newCreator);
|
||||
}
|
||||
|
||||
private void jbInit() {
|
||||
@@ -183,31 +175,31 @@ public final class DeckEditorCommon extends DeckEditorBase {
|
||||
this.removeButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
DeckEditorCommon.this.removeButtonClicked(e);
|
||||
DeckEditorConstructed.this.removeButtonClicked(e);
|
||||
}
|
||||
});
|
||||
this.addButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
DeckEditorCommon.this.addButtonActionPerformed(e);
|
||||
DeckEditorConstructed.this.addButtonActionPerformed(e);
|
||||
}
|
||||
});
|
||||
this.importButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
DeckEditorCommon.this.importButtonActionPerformed(e);
|
||||
DeckEditorConstructed.this.importButtonActionPerformed(e);
|
||||
}
|
||||
});
|
||||
this.clearFilterButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
DeckEditorCommon.this.clearFilterButtonActionPerformed(e);
|
||||
DeckEditorConstructed.this.clearFilterButtonActionPerformed(e);
|
||||
}
|
||||
});
|
||||
this.analysisButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
DeckEditorCommon.this.analysisButtonActionPerformed(e);
|
||||
DeckEditorConstructed.this.analysisButtonActionPerformed(e);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -270,7 +262,7 @@ public final class DeckEditorCommon extends DeckEditorBase {
|
||||
@Override
|
||||
public void mouseClicked(final MouseEvent e) {
|
||||
if (e.getClickCount() == 2) {
|
||||
DeckEditorCommon.this.addCardToDeck();
|
||||
DeckEditorConstructed.this.addCardToDeck();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -278,7 +270,7 @@ public final class DeckEditorCommon extends DeckEditorBase {
|
||||
@Override
|
||||
public void keyPressed(final KeyEvent e) {
|
||||
if (e.getKeyChar() == ' ') {
|
||||
DeckEditorCommon.this.addCardToDeck();
|
||||
DeckEditorConstructed.this.addCardToDeck();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -293,29 +285,12 @@ public final class DeckEditorCommon extends DeckEditorBase {
|
||||
* @see forge.gui.deckeditor.DeckEditorBase#buildFilter()
|
||||
*/
|
||||
@Override
|
||||
protected Predicate<InventoryItem> buildFilter() {
|
||||
protected Predicate<CardPrinted> buildFilter() {
|
||||
final Predicate<CardPrinted> cardFilter = Predicate.and(this.getFilterBoxes().buildFilter(),
|
||||
this.filterNameTypeSet.buildFilter());
|
||||
return Predicate.instanceOf(cardFilter, CardPrinted.class);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.gui.deckeditor.DeckEditorBase#setDeck(forge.item.ItemPoolView,
|
||||
* forge.item.ItemPoolView, forge.game.GameType)
|
||||
*/
|
||||
@Override
|
||||
public void setDeck(final ItemPoolView<CardPrinted> topParam, final ItemPoolView<CardPrinted> bottomParam,
|
||||
final GameType gt) {
|
||||
final boolean keepRecievedCards = gt.isLimited() || (topParam != null);
|
||||
// if constructed, can add the all cards above
|
||||
final ItemPoolView<CardPrinted> top = keepRecievedCards ? topParam : ItemPool.createFrom(CardDb.instance()
|
||||
.getAllCards(), CardPrinted.class);
|
||||
this.importButton.setVisible(!gt.isLimited());
|
||||
super.setDeck(top, bottomParam, gt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear filter button_action performed.
|
||||
*
|
||||
@@ -364,14 +339,8 @@ public final class DeckEditorCommon extends DeckEditorBase {
|
||||
}
|
||||
|
||||
final CardPrinted card = (CardPrinted) item;
|
||||
this.setTitle("Deck Editor : " + this.getCustomMenu().getDeckName() + " : unsaved");
|
||||
|
||||
this.getBottomTableWithCards().addCard(card);
|
||||
if (this.getGameType().isLimited()) {
|
||||
this.getTopTableWithCards().removeCard(card);
|
||||
}
|
||||
|
||||
this.getCustomMenu().notifyDeckChange();
|
||||
this.controller.notifyModelChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -387,15 +356,8 @@ public final class DeckEditorCommon extends DeckEditorBase {
|
||||
}
|
||||
|
||||
final CardPrinted card = (CardPrinted) item;
|
||||
|
||||
this.setTitle("Deck Editor : " + this.getCustomMenu().getDeckName() + " : unsaved");
|
||||
|
||||
this.getBottomTableWithCards().removeCard(card);
|
||||
if (this.getGameType().isLimited()) {
|
||||
this.getTopTableWithCards().addCard(card);
|
||||
}
|
||||
|
||||
this.getCustomMenu().notifyDeckChange();
|
||||
this.controller.notifyModelChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -405,29 +367,29 @@ public final class DeckEditorCommon extends DeckEditorBase {
|
||||
* the e
|
||||
*/
|
||||
void importButtonActionPerformed(final ActionEvent e) {
|
||||
final DeckEditorBase g = this;
|
||||
final DeckEditorConstructed g = this;
|
||||
final DeckImport dImport = new DeckImport(g);
|
||||
dImport.setModalityType(ModalityType.APPLICATION_MODAL);
|
||||
dImport.setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the custom menu.
|
||||
*
|
||||
* @return the customMenu
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.DeckEditorBase#updateView()
|
||||
*/
|
||||
public DeckEditorCommonMenu getCustomMenu() {
|
||||
return this.customMenu;
|
||||
@Override
|
||||
public void updateView() {
|
||||
// if constructed, can add the all cards above
|
||||
getTopTableWithCards().setDeck(ItemPool.createFrom(CardDb.instance().getAllCards(), CardPrinted.class));
|
||||
getBottomTableWithCards().setDeck(controller.getModel().getMain());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the custom menu.
|
||||
*
|
||||
* @param customMenu0
|
||||
* the customMenu to set
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.DeckEditorBase#getController()
|
||||
*/
|
||||
public void setCustomMenu(final DeckEditorCommonMenu customMenu0) {
|
||||
this.customMenu = customMenu0;
|
||||
@Override
|
||||
public IDeckManager<Deck> getController() {
|
||||
return controller;
|
||||
}
|
||||
|
||||
}
|
||||
397
src/main/java/forge/gui/deckeditor/DeckEditorLimited.java
Normal file
397
src/main/java/forge/gui/deckeditor/DeckEditorLimited.java
Normal file
@@ -0,0 +1,397 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.gui.deckeditor;
|
||||
|
||||
import java.awt.Container;
|
||||
import java.awt.Font;
|
||||
import java.awt.Frame;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import net.slightlymagic.braids.util.lambda.Lambda0;
|
||||
import net.slightlymagic.maxmtg.Predicate;
|
||||
import forge.Command;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckSet;
|
||||
import forge.deck.IFolderMap;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.gui.deckeditor.elements.CardPanelHeavy;
|
||||
import forge.gui.deckeditor.elements.FilterCheckBoxes;
|
||||
import forge.gui.deckeditor.elements.FilterNameTypeSetPanel;
|
||||
import forge.gui.deckeditor.elements.ManaCostRenderer;
|
||||
import forge.gui.deckeditor.elements.TableColumnInfo;
|
||||
import forge.gui.deckeditor.elements.TableView;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.InventoryItem;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Gui_DeckEditor class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id: DeckEditorCommon.java 12850 2011-12-26 14:55:09Z slapshot5 $
|
||||
*/
|
||||
public final class DeckEditorLimited extends DeckEditorBase<CardPrinted, DeckSet> {
|
||||
/** Constant <code>serialVersionUID=130339644136746796L</code>. */
|
||||
private static final long serialVersionUID = 130339644136746796L;
|
||||
|
||||
private final JButton removeButton = new JButton();
|
||||
private final JButton addButton = new JButton();
|
||||
|
||||
private final JButton analysisButton = new JButton();
|
||||
private final JButton clearFilterButton = new JButton();
|
||||
|
||||
private final JLabel jLabelAnalysisGap = new JLabel("");
|
||||
private FilterNameTypeSetPanel filterNameTypeSet;
|
||||
|
||||
private final DeckManagerOnDisk<DeckSet> controller;
|
||||
|
||||
/**
|
||||
* Show.
|
||||
*
|
||||
* @param exitCommand
|
||||
* the exit command
|
||||
*/
|
||||
public void show(final Command exitCommand) {
|
||||
final Command exit = new Command() {
|
||||
private static final long serialVersionUID = 5210924838133689758L;
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
DeckEditorLimited.this.dispose();
|
||||
exitCommand.execute();
|
||||
}
|
||||
};
|
||||
|
||||
final MenuLimited menu = new MenuLimited(getController(), exit);
|
||||
|
||||
this.setJMenuBar(menu);
|
||||
|
||||
// do not change this!!!!
|
||||
this.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(final WindowEvent ev) {
|
||||
menu.close();
|
||||
}
|
||||
});
|
||||
|
||||
this.setup();
|
||||
|
||||
this.getTopTableWithCards().sort(1, true);
|
||||
this.getBottomTableWithCards().sort(1, true);
|
||||
|
||||
} // show(Command)
|
||||
|
||||
private void setup() {
|
||||
final List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>();
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Qty", 30, PresetColumns.FN_QTY_COMPARE, PresetColumns.FN_QTY_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Name", 175, PresetColumns.FN_NAME_COMPARE, PresetColumns.FN_NAME_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Cost", 75, PresetColumns.FN_COST_COMPARE, PresetColumns.FN_COST_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Color", 60, PresetColumns.FN_COLOR_COMPARE, PresetColumns.FN_COLOR_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.FN_TYPE_COMPARE, PresetColumns.FN_TYPE_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Stats", 60, PresetColumns.FN_STATS_COMPARE, PresetColumns.FN_STATS_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("R", 25, PresetColumns.FN_RARITY_COMPARE, PresetColumns.FN_RARITY_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Set", 40, PresetColumns.FN_SET_COMPARE, PresetColumns.FN_SET_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("AI", 30, PresetColumns.FN_AI_STATUS_COMPARE, PresetColumns.FN_AI_STATUS_GET));
|
||||
columns.get(2).setCellRenderer(new ManaCostRenderer());
|
||||
|
||||
this.getTopTableWithCards().setup(columns, this.getCardView());
|
||||
this.getBottomTableWithCards().setup(columns, this.getCardView());
|
||||
|
||||
this.filterNameTypeSet.setListeners(new OnChangeTextUpdateDisplay(), this.getItemListenerUpdatesDisplay());
|
||||
|
||||
this.setSize(1024, 740);
|
||||
this.setExtendedState(Frame.MAXIMIZED_BOTH);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new deck editor common.
|
||||
*
|
||||
* @param gameType
|
||||
* the game type
|
||||
*/
|
||||
public DeckEditorLimited(IFolderMap<DeckSet> deckMap) {
|
||||
try {
|
||||
this.setFilterBoxes(new FilterCheckBoxes(true));
|
||||
this.setTopTableWithCards(new TableView<CardPrinted>("Avaliable Cards", true, true, CardPrinted.class));
|
||||
this.setBottomTableWithCards(new TableView<CardPrinted>("Deck", true, CardPrinted.class));
|
||||
this.setCardView(new CardPanelHeavy());
|
||||
this.filterNameTypeSet = new FilterNameTypeSetPanel();
|
||||
|
||||
this.jbInit();
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
}
|
||||
|
||||
Lambda0<DeckSet> newCreator = new Lambda0<DeckSet>(){ @Override public DeckSet apply() { return new DeckSet(""); } };
|
||||
controller = new DeckManagerOnDisk<DeckSet>(deckMap, this, newCreator);
|
||||
}
|
||||
|
||||
private void jbInit() {
|
||||
|
||||
final Font fButtons = new java.awt.Font("Dialog", 0, 13);
|
||||
this.removeButton.setFont(fButtons);
|
||||
this.addButton.setFont(fButtons);
|
||||
this.clearFilterButton.setFont(fButtons);
|
||||
this.analysisButton.setFont(fButtons);
|
||||
|
||||
this.addButton.setText("Add to Deck");
|
||||
this.removeButton.setText("Remove from Deck");
|
||||
this.clearFilterButton.setText("Clear Filter");
|
||||
this.analysisButton.setText("Deck Analysis");
|
||||
|
||||
this.removeButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
DeckEditorLimited.this.removeButtonClicked(e);
|
||||
}
|
||||
});
|
||||
this.addButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
DeckEditorLimited.this.addButtonActionPerformed(e);
|
||||
}
|
||||
});
|
||||
this.clearFilterButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
DeckEditorLimited.this.clearFilterButtonActionPerformed(e);
|
||||
}
|
||||
});
|
||||
this.analysisButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
DeckEditorLimited.this.analysisButtonActionPerformed(e);
|
||||
}
|
||||
});
|
||||
|
||||
// Type filtering
|
||||
final Font f = new Font("Tahoma", Font.PLAIN, 10);
|
||||
for (final JCheckBox box : this.getFilterBoxes().getAllTypes()) {
|
||||
box.setFont(f);
|
||||
box.setOpaque(false);
|
||||
}
|
||||
|
||||
// Color filtering
|
||||
for (final JCheckBox box : this.getFilterBoxes().getAllColors()) {
|
||||
box.setOpaque(false);
|
||||
}
|
||||
|
||||
// Do not lower statsLabel any lower, we want this to be visible at 1024
|
||||
// x 768 screen size
|
||||
this.setTitle("Deck Editor");
|
||||
|
||||
final Container content = this.getContentPane();
|
||||
final MigLayout layout = new MigLayout("fill");
|
||||
content.setLayout(layout);
|
||||
|
||||
boolean isFirst = true;
|
||||
for (final JCheckBox box : this.getFilterBoxes().getAllTypes()) {
|
||||
String growParameter = "grow";
|
||||
if (isFirst) {
|
||||
growParameter = "cell 0 0, egx checkbox, grow, split 14";
|
||||
isFirst = false;
|
||||
}
|
||||
content.add(box, growParameter);
|
||||
box.addItemListener(this.getItemListenerUpdatesDisplay());
|
||||
}
|
||||
|
||||
for (final JCheckBox box : this.getFilterBoxes().getAllColors()) {
|
||||
content.add(box, "grow");
|
||||
box.addItemListener(this.getItemListenerUpdatesDisplay());
|
||||
}
|
||||
|
||||
content.add(this.clearFilterButton, "wmin 100, hmin 25, wmax 140, hmax 25, grow");
|
||||
|
||||
content.add(this.filterNameTypeSet, "cell 0 1, grow");
|
||||
content.add(this.getTopTableWithCards().getTableDecorated(), "cell 0 2 1 2, pushy, grow");
|
||||
content.add(this.getTopTableWithCards().getLabel(), "cell 0 4");
|
||||
|
||||
content.add(this.addButton, "w 100, h 49, sg button, cell 0 5, split 5");
|
||||
content.add(this.removeButton, "w 100, h 49, sg button");
|
||||
// Label is used to push the analysis button to the right to separate
|
||||
// analysis button from add/remove card ones
|
||||
content.add(this.jLabelAnalysisGap, "wmin 75, growx");
|
||||
content.add(this.analysisButton, "w 100, h 49, wrap");
|
||||
|
||||
content.add(this.getBottomTableWithCards().getTableDecorated(), "cell 0 6, grow");
|
||||
content.add(this.getBottomTableWithCards().getLabel(), "cell 0 7");
|
||||
|
||||
content.add(this.getCardView(), "cell 1 0 1 8, flowy, grow");
|
||||
|
||||
this.getTopTableWithCards().getTable().addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(final MouseEvent e) {
|
||||
if (e.getClickCount() == 2) {
|
||||
DeckEditorLimited.this.addCardToDeck();
|
||||
}
|
||||
}
|
||||
});
|
||||
this.getTopTableWithCards().getTable().addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(final KeyEvent e) {
|
||||
if (e.getKeyChar() == ' ') {
|
||||
DeckEditorLimited.this.addCardToDeck();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// javax.swing.JRootPane rootPane = this.getRootPane();
|
||||
// rootPane.setDefaultButton(filterButton);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.gui.deckeditor.DeckEditorBase#buildFilter()
|
||||
*/
|
||||
@Override
|
||||
protected Predicate<CardPrinted> buildFilter() {
|
||||
final Predicate<CardPrinted> cardFilter = Predicate.and(this.getFilterBoxes().buildFilter(),
|
||||
this.filterNameTypeSet.buildFilter());
|
||||
return Predicate.instanceOf(cardFilter, CardPrinted.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear filter button_action performed.
|
||||
*
|
||||
* @param e
|
||||
* the e
|
||||
*/
|
||||
void clearFilterButtonActionPerformed(final ActionEvent e) {
|
||||
// disable automatic update triggered by listeners
|
||||
this.setFiltersChangeFiringUpdate(false);
|
||||
|
||||
for (final JCheckBox box : this.getFilterBoxes().getAllTypes()) {
|
||||
if (!box.isSelected()) {
|
||||
box.doClick();
|
||||
}
|
||||
}
|
||||
for (final JCheckBox box : this.getFilterBoxes().getAllColors()) {
|
||||
if (!box.isSelected()) {
|
||||
box.doClick();
|
||||
}
|
||||
}
|
||||
|
||||
this.filterNameTypeSet.clearFilters();
|
||||
|
||||
this.setFiltersChangeFiringUpdate(true);
|
||||
|
||||
this.getTopTableWithCards().setFilter(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the button_action performed.
|
||||
*
|
||||
* @param e
|
||||
* the e
|
||||
*/
|
||||
void addButtonActionPerformed(final ActionEvent e) {
|
||||
this.addCardToDeck();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the card to deck.
|
||||
*/
|
||||
void addCardToDeck() {
|
||||
final InventoryItem item = this.getTopTableWithCards().getSelectedCard();
|
||||
if ((item == null) || !(item instanceof CardPrinted)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// update view
|
||||
final CardPrinted card = (CardPrinted) item;
|
||||
this.getBottomTableWithCards().addCard(card);
|
||||
this.getTopTableWithCards().removeCard(card);
|
||||
|
||||
/* update model
|
||||
Deck model = getSelectedDeck(getController().getModel());
|
||||
model.getMain().add(card);
|
||||
model.getSideboard().remove(card); */
|
||||
|
||||
this.getController().notifyModelChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this method.
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
private Deck getSelectedDeck(DeckSet model) {
|
||||
return model.getHumanDeck();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the button clicked.
|
||||
*
|
||||
* @param e
|
||||
* the e
|
||||
*/
|
||||
void removeButtonClicked(final ActionEvent e) {
|
||||
final InventoryItem item = this.getBottomTableWithCards().getSelectedCard();
|
||||
if ((item == null) || !(item instanceof CardPrinted)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// update view
|
||||
final CardPrinted card = (CardPrinted) item;
|
||||
this.getBottomTableWithCards().removeCard(card);
|
||||
this.getTopTableWithCards().addCard(card);
|
||||
|
||||
/* update model
|
||||
Deck model = getSelectedDeck(getController().getModel());
|
||||
model.getMain().remove(card);
|
||||
model.getSideboard().add(card);*/
|
||||
|
||||
this.getController().notifyModelChanged();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.DeckEditorBase#getController()
|
||||
*/
|
||||
@Override
|
||||
public IDeckManager<DeckSet> getController() {
|
||||
return controller;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.DeckEditorBase#updateView()
|
||||
*/
|
||||
@Override
|
||||
public void updateView() {
|
||||
getTopTableWithCards().setDeck(getSelectedDeck(controller.getModel()).getSideboard());
|
||||
getBottomTableWithCards().setDeck(getSelectedDeck(controller.getModel()).getMain());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
@@ -36,12 +37,16 @@ import forge.Command;
|
||||
import forge.Constant;
|
||||
import forge.deck.Deck;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.game.GameType;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.gui.deckeditor.elements.CardPanelHeavy;
|
||||
import forge.gui.deckeditor.elements.FilterCheckBoxes;
|
||||
import forge.gui.deckeditor.elements.FilterNameTypeSetPanel;
|
||||
import forge.gui.deckeditor.elements.ManaCostRenderer;
|
||||
import forge.gui.deckeditor.elements.TableColumnInfo;
|
||||
import forge.gui.deckeditor.elements.TableView;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.ItemPool;
|
||||
import forge.item.ItemPoolView;
|
||||
import forge.quest.data.QuestData;
|
||||
|
||||
//import forge.quest.data.QuestBoosterPack;
|
||||
@@ -54,13 +59,11 @@ import forge.quest.data.QuestData;
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public final class DeckEditorQuest extends DeckEditorBase {
|
||||
public final class DeckEditorQuest extends DeckEditorBase<CardPrinted, Deck> {
|
||||
/** Constant <code>serialVersionUID=152061168634545L</code>. */
|
||||
private static final long serialVersionUID = 152061168634545L;
|
||||
|
||||
/** The custom menu. */
|
||||
private DeckEditorQuestMenu customMenu;
|
||||
|
||||
// private ImageIcon upIcon = Constant.IO.upIcon;
|
||||
// private ImageIcon downIcon = Constant.IO.downIcon;
|
||||
|
||||
@@ -72,7 +75,8 @@ public final class DeckEditorQuest extends DeckEditorBase {
|
||||
private FilterNameTypeSetPanel filterNameTypeSet;
|
||||
|
||||
private final QuestData questData;
|
||||
|
||||
private final DeckManagerQuest controller;
|
||||
|
||||
/**
|
||||
* Show.
|
||||
*
|
||||
@@ -90,47 +94,29 @@ public final class DeckEditorQuest extends DeckEditorBase {
|
||||
}
|
||||
};
|
||||
|
||||
this.setup();
|
||||
|
||||
final MenuQuest menu = new MenuQuest(this.getController(), exit);
|
||||
this.setJMenuBar(menu);
|
||||
|
||||
// do not change this!!!!
|
||||
this.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(final WindowEvent ev) {
|
||||
DeckEditorQuest.this.customMenu.close();
|
||||
}
|
||||
});
|
||||
public void windowClosing(final WindowEvent ev) { menu.close(); }
|
||||
});
|
||||
|
||||
Deck deck = Constant.Runtime.HUMAN_DECK[0] == null ? null : this.questData.getMyDecks().get(Constant.Runtime.HUMAN_DECK[0].getName());
|
||||
|
||||
this.setup();
|
||||
|
||||
this.customMenu = new DeckEditorQuestMenu(this.questData, this, exit);
|
||||
this.setJMenuBar(this.customMenu);
|
||||
|
||||
Deck deck = null;
|
||||
|
||||
// open deck that the player used if QuestData has it
|
||||
if ((Constant.Runtime.HUMAN_DECK[0] != null)
|
||||
&& this.questData.getDeckNames().contains(Constant.Runtime.HUMAN_DECK[0].getName())) {
|
||||
deck = this.questData.getDeck(Constant.Runtime.HUMAN_DECK[0].getName());
|
||||
} else {
|
||||
deck = new Deck(GameType.Sealed);
|
||||
deck.setName("");
|
||||
}
|
||||
if ( deck == null ) deck = new Deck();
|
||||
|
||||
// tell Gui_Quest_DeckEditor the name of the deck
|
||||
this.customMenu.setPlayerDeckName(deck.getName());
|
||||
|
||||
final ItemPoolView<CardPrinted> bottomPool = deck.getMain();
|
||||
final ItemPool<CardPrinted> cardpool = new ItemPool<CardPrinted>(CardPrinted.class);
|
||||
cardpool.addAll(this.questData.getCards().getCardpool());
|
||||
|
||||
// remove bottom cards that are in the deck from the card pool
|
||||
cardpool.removeAll(bottomPool);
|
||||
|
||||
// show cards, makes this user friendly
|
||||
this.setDeck(cardpool, bottomPool, GameType.Quest);
|
||||
|
||||
this.getController().setModel(deck);
|
||||
|
||||
// this affects the card pool
|
||||
this.getTopTableWithCards().sort(4, true); // sort by type
|
||||
this.getTopTableWithCards().sort(3, true); // then sort by color
|
||||
|
||||
this.getBottomTableWithCards().sort(1, true);
|
||||
} // show(Command)
|
||||
|
||||
@@ -188,18 +174,20 @@ public final class DeckEditorQuest extends DeckEditorBase {
|
||||
* the quest data2
|
||||
*/
|
||||
public DeckEditorQuest(final QuestData questData2) {
|
||||
super(GameType.Quest);
|
||||
|
||||
this.questData = questData2;
|
||||
try {
|
||||
this.setFilterBoxes(new FilterCheckBoxes(false));
|
||||
this.setTopTableWithCards(new TableWithCards("All Cards", true));
|
||||
this.setBottomTableWithCards(new TableWithCards("Your deck", true));
|
||||
this.setTopTableWithCards(new TableView<CardPrinted>("All Cards", true, CardPrinted.class));
|
||||
this.setBottomTableWithCards(new TableView<CardPrinted>("Your deck", true, CardPrinted.class));
|
||||
this.setCardView(new CardPanelHeavy());
|
||||
this.filterNameTypeSet = new FilterNameTypeSetPanel();
|
||||
this.jbInit();
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
}
|
||||
|
||||
controller = new DeckManagerQuest(questData2, this);
|
||||
}
|
||||
|
||||
private void jbInit() throws Exception {
|
||||
@@ -321,7 +309,7 @@ public final class DeckEditorQuest extends DeckEditorBase {
|
||||
* @see forge.gui.deckeditor.DeckEditorBase#buildFilter()
|
||||
*/
|
||||
@Override
|
||||
protected Predicate<InventoryItem> buildFilter() {
|
||||
protected Predicate<CardPrinted> buildFilter() {
|
||||
final Predicate<CardPrinted> cardFilter = Predicate.and(this.getFilterBoxes().buildFilter(),
|
||||
this.filterNameTypeSet.buildFilter());
|
||||
return Predicate.instanceOf(cardFilter, CardPrinted.class);
|
||||
@@ -334,9 +322,6 @@ public final class DeckEditorQuest extends DeckEditorBase {
|
||||
}
|
||||
|
||||
final CardPrinted card = (CardPrinted) item;
|
||||
|
||||
this.setTitle("Deck Editor : " + this.customMenu.getDeckName() + " : unsaved");
|
||||
|
||||
this.getTopTableWithCards().removeCard(card);
|
||||
this.getBottomTableWithCards().addCard(card);
|
||||
}
|
||||
@@ -348,9 +333,6 @@ public final class DeckEditorQuest extends DeckEditorBase {
|
||||
}
|
||||
|
||||
final CardPrinted card = (CardPrinted) item;
|
||||
|
||||
this.setTitle("Deck Editor : " + this.customMenu.getDeckName() + " : unsaved");
|
||||
|
||||
this.getTopTableWithCards().addCard(card);
|
||||
this.getBottomTableWithCards().removeCard(card);
|
||||
}
|
||||
@@ -366,4 +348,28 @@ public final class DeckEditorQuest extends DeckEditorBase {
|
||||
this.questData.getCards().getCardpool().add(card);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.DeckEditorBase#getController()
|
||||
*/
|
||||
@Override
|
||||
public IDeckManager<Deck> getController() {
|
||||
return controller;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.DeckEditorBase#updateView()
|
||||
*/
|
||||
@Override
|
||||
public void updateView() {
|
||||
Deck deck = controller.getModel();
|
||||
|
||||
final ItemPool<CardPrinted> cardpool = new ItemPool<CardPrinted>(CardPrinted.class);
|
||||
cardpool.addAll(this.questData.getCards().getCardpool());
|
||||
// remove bottom cards that are in the deck from the card pool
|
||||
cardpool.removeAll(deck.getMain());
|
||||
// show cards, makes this user friendly
|
||||
getTopTableWithCards().setDeck(cardpool);
|
||||
getBottomTableWithCards().setDeck(deck.getMain());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,704 +0,0 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.gui.deckeditor;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.Command;
|
||||
import forge.Constant;
|
||||
import forge.card.CardRules;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckIO;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.game.GameType;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.gui.ListChooser;
|
||||
import forge.item.CardDb;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.ItemPool;
|
||||
import forge.item.ItemPoolView;
|
||||
import forge.quest.data.QuestData;
|
||||
|
||||
//presumes AllZone.getQuestData() is not null
|
||||
/**
|
||||
* <p>
|
||||
* Gui_Quest_DeckEditor_Menu class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class DeckEditorQuestMenu extends JMenuBar {
|
||||
/** Constant <code>serialVersionUID=-4052319220021158574L</code>. */
|
||||
private static final long serialVersionUID = -4052319220021158574L;
|
||||
|
||||
/** Constant <code>deckEditorName="Deck Editor"</code>. */
|
||||
private static final String DECK_EDITOR_NAME = "Deck Editor";
|
||||
|
||||
// used for import and export, try to made the gui user friendly
|
||||
/** Constant <code>previousDirectory</code>. */
|
||||
private static File previousDirectory = null;
|
||||
|
||||
private final Command exitCommand;
|
||||
private final forge.quest.data.QuestData questData;
|
||||
private Deck currentDeck;
|
||||
|
||||
// the class DeckDisplay is in the file "Gui_DeckEditor_Menu.java"
|
||||
private final DeckDisplay deckDisplay;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Constructor for Gui_Quest_DeckEditor_Menu.
|
||||
* </p>
|
||||
*
|
||||
* @param q
|
||||
* the q
|
||||
* @param d
|
||||
* a {@link forge.gui.deckeditor.DeckDisplay} object.
|
||||
* @param exit
|
||||
* a {@link forge.Command} object.
|
||||
*/
|
||||
public DeckEditorQuestMenu(final QuestData q, final DeckDisplay d, final Command exit) {
|
||||
|
||||
this.deckDisplay = d;
|
||||
this.questData = q;
|
||||
|
||||
d.setTitle(DeckEditorQuestMenu.DECK_EDITOR_NAME);
|
||||
|
||||
this.exitCommand = exit;
|
||||
|
||||
this.setupMenu();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* addImportExport.
|
||||
* </p>
|
||||
*
|
||||
* @param menu
|
||||
* a {@link javax.swing.JMenu} object.
|
||||
* @param isHumanMenu
|
||||
* a boolean.
|
||||
*/
|
||||
private void addImportExport(final JMenu menu, final boolean isHumanMenu) {
|
||||
final JMenuItem import2 = new JMenuItem("Import");
|
||||
final JMenuItem export = new JMenuItem("Export");
|
||||
|
||||
import2.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent a) {
|
||||
DeckEditorQuestMenu.this.importDeck(); // importDeck(isHumanMenu);
|
||||
}
|
||||
}); // import
|
||||
|
||||
export.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent a) {
|
||||
DeckEditorQuestMenu.this.exportDeck();
|
||||
}
|
||||
}); // export
|
||||
|
||||
menu.add(import2);
|
||||
menu.add(export);
|
||||
|
||||
} // addImportExport()
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* exportDeck.
|
||||
* </p>
|
||||
*/
|
||||
private void exportDeck() {
|
||||
final File filename = this.getExportFilename();
|
||||
|
||||
if (filename == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// write is an Object variable because you might just
|
||||
// write one Deck object
|
||||
final Deck deck = this.cardPoolToDeck(this.deckDisplay.getBottom());
|
||||
|
||||
deck.setName(filename.getName());
|
||||
|
||||
try {
|
||||
final ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(filename));
|
||||
out.writeObject(deck);
|
||||
out.flush();
|
||||
out.close();
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_Quest_DeckEditor_Menu : exportDeck() error, " + ex);
|
||||
}
|
||||
|
||||
this.exportDeckText(this.getExportDeckText(deck), filename.getAbsolutePath());
|
||||
|
||||
} // exportDeck()
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* exportDeckText.
|
||||
* </p>
|
||||
*
|
||||
* @param deckText
|
||||
* a {@link java.lang.String} object.
|
||||
* @param filename
|
||||
* a {@link java.lang.String} object.
|
||||
*/
|
||||
private void exportDeckText(final String deckText, String filename) {
|
||||
|
||||
// remove ".deck" extension
|
||||
final int cut = filename.indexOf(".");
|
||||
filename = filename.substring(0, cut);
|
||||
|
||||
try {
|
||||
final FileWriter writer = new FileWriter(filename + ".txt");
|
||||
writer.write(deckText);
|
||||
|
||||
writer.flush();
|
||||
writer.close();
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_Quest_DeckEditor_Menu : exportDeckText() error, " + ex.getMessage() + " : "
|
||||
+ Arrays.toString(ex.getStackTrace()));
|
||||
}
|
||||
} // exportDeckText()
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getExportDeckText.
|
||||
* </p>
|
||||
*
|
||||
* @param aDeck
|
||||
* a {@link forge.deck.Deck} object.
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
private String getExportDeckText(final Deck aDeck) {
|
||||
// convert Deck into CardList
|
||||
final ItemPoolView<CardPrinted> all = aDeck.getMain();
|
||||
// sort by card name
|
||||
Collections.sort(all.getOrderedList(), TableSorter.BY_NAME_THEN_SET);
|
||||
|
||||
final StringBuffer sb = new StringBuffer();
|
||||
final String newLine = "\r\n";
|
||||
|
||||
sb.append(String.format("%d Total Cards%n%n", all.countAll()));
|
||||
|
||||
// creatures
|
||||
|
||||
sb.append(String.format("%d Creatures%n-------------%n",
|
||||
CardRules.Predicates.Presets.IS_CREATURE.aggregate(all, all.getFnToCard(), all.getFnToCount())));
|
||||
for (final Entry<CardPrinted, Integer> e : CardRules.Predicates.Presets.IS_CREATURE.select(all,
|
||||
all.getFnToCard())) {
|
||||
sb.append(String.format("%d x %s%n", e.getValue(), e.getKey().getName()));
|
||||
}
|
||||
|
||||
// spells
|
||||
sb.append(String.format("%d Spells%n----------%n", CardRules.Predicates.Presets.IS_NON_CREATURE_SPELL
|
||||
.aggregate(all, all.getFnToCard(), all.getFnToCount())));
|
||||
for (final Entry<CardPrinted, Integer> e : CardRules.Predicates.Presets.IS_NON_CREATURE_SPELL.select(all,
|
||||
all.getFnToCard())) {
|
||||
sb.append(String.format("%d x %s%n", e.getValue(), e.getKey().getName()));
|
||||
}
|
||||
|
||||
// lands
|
||||
sb.append(String.format("%d Land%n--------%n",
|
||||
CardRules.Predicates.Presets.IS_LAND.aggregate(all, all.getFnToCard(), all.getFnToCount())));
|
||||
for (final Entry<CardPrinted, Integer> e : CardRules.Predicates.Presets.IS_LAND.select(all, all.getFnToCard())) {
|
||||
sb.append(String.format("%d x %s%n", e.getValue(), e.getKey().getName()));
|
||||
}
|
||||
|
||||
sb.append(newLine);
|
||||
|
||||
return sb.toString();
|
||||
} // getExportDeckText
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getFileFilter.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link javax.swing.filechooser.FileFilter} object.
|
||||
*/
|
||||
private FileFilter getFileFilter() {
|
||||
final FileFilter filter = new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(final File f) {
|
||||
return f.getName().endsWith(".dck") || f.isDirectory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Deck File .dck";
|
||||
}
|
||||
};
|
||||
|
||||
return filter;
|
||||
} // getFileFilter()
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getExportFilename.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.io.File} object.
|
||||
*/
|
||||
private File getExportFilename() {
|
||||
// Object o = null; // unused
|
||||
|
||||
final JFileChooser save = new JFileChooser(DeckEditorQuestMenu.previousDirectory);
|
||||
|
||||
save.setDialogTitle("Export Deck Filename");
|
||||
save.setDialogType(JFileChooser.SAVE_DIALOG);
|
||||
save.addChoosableFileFilter(this.getFileFilter());
|
||||
save.setSelectedFile(new File(this.currentDeck.getName() + ".deck"));
|
||||
|
||||
final int returnVal = save.showSaveDialog(null);
|
||||
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
final File file = save.getSelectedFile();
|
||||
final String check = file.getAbsolutePath();
|
||||
|
||||
DeckEditorQuestMenu.previousDirectory = file.getParentFile();
|
||||
|
||||
if (check.endsWith(".deck")) {
|
||||
return file;
|
||||
} else {
|
||||
return new File(check + ".deck");
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
} // getExportFilename()
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* importDeck.
|
||||
* </p>
|
||||
*/
|
||||
private void importDeck() {
|
||||
final File file = this.getImportFilename();
|
||||
|
||||
if (file == null) {
|
||||
} else if (file.getName().endsWith(".dck")) {
|
||||
try {
|
||||
final Deck newDeck = DeckIO.readDeck(file);
|
||||
this.questData.addDeck(newDeck);
|
||||
|
||||
final ItemPool<CardPrinted> cardpool = ItemPool.createFrom(this.questData.getCards().getCardpool(),
|
||||
CardPrinted.class);
|
||||
final ItemPool<CardPrinted> decklist = new ItemPool<CardPrinted>(CardPrinted.class);
|
||||
for (final Entry<CardPrinted, Integer> s : newDeck.getMain()) {
|
||||
final CardPrinted cp = s.getKey();
|
||||
decklist.add(cp, s.getValue());
|
||||
cardpool.add(cp, s.getValue());
|
||||
this.questData.getCards().getCardpool().add(cp, s.getValue());
|
||||
}
|
||||
this.deckDisplay.setDeck(cardpool, decklist, GameType.Quest);
|
||||
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : importDeck() error, " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
} // importDeck()
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getImportFilename.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.io.File} object.
|
||||
*/
|
||||
private File getImportFilename() {
|
||||
final JFileChooser chooser = new JFileChooser(DeckEditorQuestMenu.previousDirectory);
|
||||
|
||||
chooser.addChoosableFileFilter(this.getFileFilter());
|
||||
final int returnVal = chooser.showOpenDialog(null);
|
||||
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
final File file = chooser.getSelectedFile();
|
||||
DeckEditorQuestMenu.previousDirectory = file.getParentFile();
|
||||
return file;
|
||||
}
|
||||
|
||||
return null;
|
||||
} // openFileDialog()
|
||||
|
||||
private final ActionListener addCardActionListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent a) {
|
||||
|
||||
// Provide a model here: all unique cards to be displayed by only
|
||||
// name (unlike default toString)
|
||||
final Iterable<CardPrinted> uniqueCards = CardDb.instance().getAllUniqueCards();
|
||||
final List<String> cards = new ArrayList<String>();
|
||||
for (final CardPrinted c : uniqueCards) {
|
||||
cards.add(c.getName());
|
||||
}
|
||||
Collections.sort(cards);
|
||||
|
||||
// use standard forge's list selection dialog
|
||||
final ListChooser<String> c = new ListChooser<String>("Cheat - Add Card to Your Cardpool", 0, 1, cards);
|
||||
if (c.show()) {
|
||||
final String cardName = c.getSelectedValue();
|
||||
final DeckEditorQuest g = (DeckEditorQuest) DeckEditorQuestMenu.this.deckDisplay;
|
||||
g.addCheatCard(CardDb.instance().getCard(cardName));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private final ActionListener openDeckActionListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent a) {
|
||||
final String deckName = DeckEditorQuestMenu.this.getUserInputOpenDeck(DeckEditorQuestMenu.this.questData
|
||||
.getDeckNames());
|
||||
|
||||
// check if user selected "cancel"
|
||||
if (StringUtils.isBlank(deckName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
DeckEditorQuestMenu.this.setPlayerDeckName(deckName);
|
||||
final ItemPool<CardPrinted> cards = ItemPool.createFrom(DeckEditorQuestMenu.this.questData.getCards()
|
||||
.getCardpool().getView(), CardPrinted.class);
|
||||
final ItemPoolView<CardPrinted> deck = DeckEditorQuestMenu.this.questData.getDeck(deckName).getMain();
|
||||
|
||||
// show in pool all cards except ones used in deck
|
||||
cards.removeAll(deck);
|
||||
DeckEditorQuestMenu.this.deckDisplay.setDeck(cards, deck, GameType.Quest);
|
||||
}
|
||||
};
|
||||
|
||||
private final ActionListener newDeckActionListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent a) {
|
||||
DeckEditorQuestMenu.this.deckDisplay.setItems(DeckEditorQuestMenu.this.questData.getCards().getCardpool()
|
||||
.getView(), null, GameType.Quest);
|
||||
DeckEditorQuestMenu.this.setPlayerDeckName("");
|
||||
}
|
||||
};
|
||||
|
||||
private final ActionListener renameDeckActionListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent a) {
|
||||
final String deckName = DeckEditorQuestMenu.this.getUserInputGetDeckName(DeckEditorQuestMenu.this.questData
|
||||
.getDeckNames());
|
||||
|
||||
// check if user cancels
|
||||
if (StringUtils.isBlank(deckName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// is the current deck already saved and in QuestData?
|
||||
if (DeckEditorQuestMenu.this.questData.getDeckNames().contains(
|
||||
DeckEditorQuestMenu.this.currentDeck.getName())) {
|
||||
DeckEditorQuestMenu.this.questData.removeDeck(DeckEditorQuestMenu.this.currentDeck.getName());
|
||||
}
|
||||
|
||||
DeckEditorQuestMenu.this.currentDeck.setName(deckName);
|
||||
|
||||
final Deck deck = DeckEditorQuestMenu.this.cardPoolToDeck(DeckEditorQuestMenu.this.deckDisplay.getBottom());
|
||||
deck.setName(deckName);
|
||||
DeckEditorQuestMenu.this.questData.addDeck(deck);
|
||||
|
||||
DeckEditorQuestMenu.this.setPlayerDeckName(deckName);
|
||||
}
|
||||
};
|
||||
|
||||
private final ActionListener saveDeckActionListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent a) {
|
||||
String name = DeckEditorQuestMenu.this.currentDeck.getName();
|
||||
|
||||
// check to see if name is set
|
||||
if (name.equals("")) {
|
||||
name = DeckEditorQuestMenu.this.getUserInputGetDeckName(DeckEditorQuestMenu.this.questData
|
||||
.getDeckNames());
|
||||
|
||||
// check if user cancels
|
||||
if (name.equals("")) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
DeckEditorQuestMenu.this.setPlayerDeckName(name);
|
||||
|
||||
final Deck deck = DeckEditorQuestMenu.this.cardPoolToDeck(DeckEditorQuestMenu.this.deckDisplay.getBottom());
|
||||
deck.setName(name);
|
||||
|
||||
DeckEditorQuestMenu.this.questData.addDeck(deck);
|
||||
}
|
||||
};
|
||||
|
||||
private final ActionListener copyDeckActionListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent a) {
|
||||
final String name = DeckEditorQuestMenu.this.getUserInputGetDeckName(DeckEditorQuestMenu.this.questData
|
||||
.getDeckNames());
|
||||
|
||||
// check if user cancels
|
||||
if (name.equals("")) {
|
||||
return;
|
||||
}
|
||||
|
||||
DeckEditorQuestMenu.this.setPlayerDeckName(name);
|
||||
|
||||
final Deck deck = DeckEditorQuestMenu.this.cardPoolToDeck(DeckEditorQuestMenu.this.deckDisplay.getBottom());
|
||||
deck.setName(name);
|
||||
|
||||
DeckEditorQuestMenu.this.questData.addDeck(deck);
|
||||
}
|
||||
};
|
||||
|
||||
private final ActionListener deleteDeckActionListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent a) {
|
||||
if (DeckEditorQuestMenu.this.currentDeck.getName().equals("")) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int check = JOptionPane.showConfirmDialog(null, "Do you really want to delete this deck?", "Delete",
|
||||
JOptionPane.YES_NO_OPTION);
|
||||
if (check == JOptionPane.NO_OPTION) {
|
||||
return; // stop here
|
||||
}
|
||||
|
||||
DeckEditorQuestMenu.this.questData.removeDeck(DeckEditorQuestMenu.this.currentDeck.getName());
|
||||
|
||||
// show card pool
|
||||
DeckEditorQuestMenu.this.deckDisplay.setItems(DeckEditorQuestMenu.this.questData.getCards().getCardpool()
|
||||
.getView(), null, GameType.Quest);
|
||||
|
||||
DeckEditorQuestMenu.this.setPlayerDeckName("");
|
||||
}
|
||||
};
|
||||
|
||||
// the usual menu options that will be used
|
||||
/**
|
||||
* <p>
|
||||
* setupMenu.
|
||||
* </p>
|
||||
*/
|
||||
private void setupMenu() {
|
||||
final JMenuItem openDeck = new JMenuItem("Open");
|
||||
final JMenuItem newDeck = new JMenuItem("New");
|
||||
final JMenuItem rename = new JMenuItem("Rename");
|
||||
final JMenuItem save = new JMenuItem("Save");
|
||||
final JMenuItem copy = new JMenuItem("Copy");
|
||||
final JMenuItem delete = new JMenuItem("Delete");
|
||||
final JMenuItem exit = new JMenuItem("Exit");
|
||||
|
||||
final JMenuItem addCard = new JMenuItem("Cheat - Add Card");
|
||||
|
||||
addCard.addActionListener(this.addCardActionListener);
|
||||
openDeck.addActionListener(this.openDeckActionListener);
|
||||
newDeck.addActionListener(this.newDeckActionListener);
|
||||
rename.addActionListener(this.renameDeckActionListener);
|
||||
save.addActionListener(this.saveDeckActionListener);
|
||||
copy.addActionListener(this.copyDeckActionListener);
|
||||
delete.addActionListener(this.deleteDeckActionListener);
|
||||
|
||||
// human
|
||||
exit.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent a) {
|
||||
DeckEditorQuestMenu.this.close();
|
||||
}
|
||||
});
|
||||
|
||||
final JMenu deckMenu = new JMenu("Deck");
|
||||
deckMenu.add(openDeck);
|
||||
deckMenu.add(newDeck);
|
||||
deckMenu.add(rename);
|
||||
deckMenu.add(save);
|
||||
deckMenu.add(copy);
|
||||
|
||||
if (Constant.Runtime.DEV_MODE[0]) {
|
||||
deckMenu.addSeparator();
|
||||
deckMenu.add(addCard);
|
||||
}
|
||||
|
||||
deckMenu.addSeparator();
|
||||
this.addImportExport(deckMenu, true);
|
||||
|
||||
deckMenu.addSeparator();
|
||||
deckMenu.add(delete);
|
||||
deckMenu.addSeparator();
|
||||
deckMenu.add(exit);
|
||||
|
||||
this.add(deckMenu);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* convertCardPoolToDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param list
|
||||
* a {@link forge.CardPool} object.
|
||||
* @return a {@link forge.deck.Deck} object.
|
||||
*/
|
||||
private Deck cardPoolToDeck(final ItemPoolView<InventoryItem> list) {
|
||||
// put CardPool into Deck main
|
||||
final Deck deck = new Deck(GameType.Sealed);
|
||||
deck.getMain().addAll(list);
|
||||
return deck;
|
||||
}
|
||||
|
||||
// needs to be public because Gui_Quest_DeckEditor.show(Command) uses it
|
||||
/**
|
||||
* <p>
|
||||
* setHumanPlayer.
|
||||
* </p>
|
||||
*
|
||||
* @param deckName
|
||||
* a {@link java.lang.String} object.
|
||||
*/
|
||||
public final void setPlayerDeckName(final String deckName) {
|
||||
// the gui uses this, Gui_Quest_DeckEditor
|
||||
this.currentDeck = new Deck(GameType.Sealed);
|
||||
this.currentDeck.setName(deckName);
|
||||
|
||||
this.deckDisplay.setTitle(DeckEditorQuestMenu.DECK_EDITOR_NAME + " - " + deckName);
|
||||
}
|
||||
|
||||
// only accepts numbers, letters or dashes up to 20 characters in length
|
||||
/**
|
||||
* <p>
|
||||
* cleanString.
|
||||
* </p>
|
||||
*
|
||||
* @param in
|
||||
* a {@link java.lang.String} object.
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
private 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();
|
||||
}
|
||||
|
||||
// if user cancels, returns ""
|
||||
/**
|
||||
* <p>
|
||||
* getUserInput_GetDeckName.
|
||||
* </p>
|
||||
*
|
||||
* @param nameList
|
||||
* a {@link java.util.List} object.
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
private String getUserInputGetDeckName(final List<String> nameList) {
|
||||
final Object o = JOptionPane.showInputDialog(null, "", "Deck Name", JOptionPane.OK_CANCEL_OPTION);
|
||||
|
||||
if (o == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
final String deckName = this.cleanString(o.toString());
|
||||
|
||||
if (nameList.contains(deckName) || deckName.equals("")) {
|
||||
JOptionPane.showMessageDialog(null, "Please pick another deck name, a deck currently has that name.");
|
||||
return this.getUserInputGetDeckName(nameList);
|
||||
}
|
||||
|
||||
return deckName;
|
||||
} // getUserInput_GetDeckName()
|
||||
|
||||
// if user cancels, it will return ""
|
||||
/**
|
||||
* <p>
|
||||
* getUserInput_OpenDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param deckNameList
|
||||
* a {@link java.util.List} object.
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
private String getUserInputOpenDeck(final List<String> deckNameList) {
|
||||
final List<String> choices = deckNameList;
|
||||
if (choices.size() == 0) {
|
||||
JOptionPane.showMessageDialog(null, "No decks found", "Open Deck", JOptionPane.PLAIN_MESSAGE);
|
||||
return "";
|
||||
}
|
||||
|
||||
// Object o = JOptionPane.showInputDialog(null, "Deck Name",
|
||||
// "Open Deck", JOptionPane.OK_CANCEL_OPTION, null,
|
||||
// choices.toArray(), choices.toArray()[0]);
|
||||
final Object o = GuiUtils.getChoiceOptional("Select Deck", choices.toArray());
|
||||
|
||||
if (o == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return o.toString();
|
||||
} // getUserInput_OpenDeck()
|
||||
|
||||
// used by Gui_Quest_DeckEditor
|
||||
/**
|
||||
* <p>
|
||||
* close.
|
||||
* </p>
|
||||
*/
|
||||
public final void close() {
|
||||
this.exitCommand.execute();
|
||||
}
|
||||
|
||||
// used by Gui_Quest_DeckEditor
|
||||
/**
|
||||
* <p>
|
||||
* getDeckName.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
public final String getDeckName() {
|
||||
return this.currentDeck.getName();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -43,7 +43,6 @@ import net.miginfocom.swing.MigLayout;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckRecognizer;
|
||||
import forge.deck.DeckRecognizer.TokenType;
|
||||
import forge.game.GameType;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.item.CardPrinted;
|
||||
|
||||
@@ -85,7 +84,7 @@ public class DeckImport extends JDialog {
|
||||
/** The tokens. */
|
||||
private final List<DeckRecognizer.Token> tokens = new ArrayList<DeckRecognizer.Token>();
|
||||
|
||||
private final DeckEditorBase host;
|
||||
private final DeckEditorConstructed host;
|
||||
|
||||
/**
|
||||
* Instantiates a new deck import.
|
||||
@@ -93,7 +92,7 @@ public class DeckImport extends JDialog {
|
||||
* @param g
|
||||
* the g
|
||||
*/
|
||||
public DeckImport(final DeckEditorBase g) {
|
||||
public DeckImport(final DeckEditorConstructed g) {
|
||||
this.host = g;
|
||||
|
||||
final int wWidth = 600;
|
||||
@@ -147,7 +146,7 @@ public class DeckImport extends JDialog {
|
||||
return;
|
||||
}
|
||||
final Deck toSet = DeckImport.this.buildDeck();
|
||||
DeckImport.this.host.setDeck(null, toSet.getMain(), toSet.getDeckType());
|
||||
DeckImport.this.host.getController().setModel(toSet);
|
||||
DeckImport.this.processWindowEvent(new WindowEvent(DeckImport.this, WindowEvent.WINDOW_CLOSING));
|
||||
}
|
||||
});
|
||||
@@ -207,7 +206,7 @@ public class DeckImport extends JDialog {
|
||||
}
|
||||
|
||||
private Deck buildDeck() {
|
||||
final Deck result = new Deck(GameType.Constructed);
|
||||
final Deck result = new Deck();
|
||||
boolean isMain = true;
|
||||
for (final DeckRecognizer.Token t : this.tokens) {
|
||||
final DeckRecognizer.TokenType type = t.getType();
|
||||
|
||||
202
src/main/java/forge/gui/deckeditor/DeckManagerOnDisk.java
Normal file
202
src/main/java/forge/gui/deckeditor/DeckManagerOnDisk.java
Normal file
@@ -0,0 +1,202 @@
|
||||
package forge.gui.deckeditor;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.util.ArrayList;
|
||||
import net.slightlymagic.braids.util.lambda.Lambda0;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.deck.DeckBase;
|
||||
import forge.deck.FolderMap;
|
||||
import forge.deck.IFolderMap;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public class DeckManagerOnDisk<T extends DeckBase> implements IDeckManager<T> {
|
||||
|
||||
private T model;
|
||||
private boolean saved;
|
||||
private boolean modelInStore;
|
||||
private final IFolderMap<T> folder;
|
||||
private final DeckEditorBase<?, T> view;
|
||||
private final Lambda0<T> newModelCreator;
|
||||
|
||||
public DeckManagerOnDisk(IFolderMap<T> folder0, DeckEditorBase<?, T> view0, Lambda0<T> newModelCreator0)
|
||||
{
|
||||
folder = folder0;
|
||||
view = view0;
|
||||
model = null;
|
||||
saved = true;
|
||||
modelInStore = false;
|
||||
newModelCreator = newModelCreator0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the document
|
||||
*/
|
||||
public T getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param document0 the document to set
|
||||
*/
|
||||
public void setModel(T document) {
|
||||
setModel( document, false );
|
||||
}
|
||||
|
||||
public void setModel(T document, boolean isStored) {
|
||||
modelInStore = isStored;
|
||||
this.model = document;
|
||||
view.updateView();
|
||||
saved = true; // unless set to false in notify
|
||||
if ( !isModelInSyncWithFolder() ) {
|
||||
notifyModelChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isModelInSyncWithFolder() {
|
||||
T modelStored = folder.get(model.getName());
|
||||
// checks presence in dictionary only.
|
||||
if (modelStored == model) return true;
|
||||
if (null == modelStored) return false;
|
||||
|
||||
return modelStored.equals(model);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the view
|
||||
*/
|
||||
public DeckEditorBase<?, T> getView() {
|
||||
return view;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.IDeckController#notifyModelChanged()
|
||||
*/
|
||||
@Override
|
||||
public void notifyModelChanged() {
|
||||
saved = false;
|
||||
//view.setTitle();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.IDeckController#getOwnerWindow()
|
||||
*/
|
||||
@Override
|
||||
public Component getOwnerWindow() {
|
||||
return getView();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.IDeckController#getSavedModelNames()
|
||||
*/
|
||||
@Override
|
||||
public ArrayList<String> getSavedNames() {
|
||||
return new ArrayList<String>(folder.getNames());
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.IDeckController#load(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void load(String name) {
|
||||
setModel(folder.get(name), true);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.IDeckController#save()
|
||||
*/
|
||||
@Override
|
||||
public void save() {
|
||||
folder.add(model);
|
||||
saved = true;
|
||||
modelInStore = true;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.IDeckController#rename(java.lang.String)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void saveAs(String name0) {
|
||||
setModel((T)model.copyTo(name0), false);
|
||||
save();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.IDeckController#isSaved()
|
||||
*/
|
||||
@Override
|
||||
public boolean isSaved() {
|
||||
return saved;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.IDeckController#delete()
|
||||
*/
|
||||
@Override
|
||||
public void delete() {
|
||||
if ( StringUtils.isNotBlank(model.getName())) {
|
||||
folder.delete(model.getName());
|
||||
}
|
||||
modelInStore = false;
|
||||
newModel();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.IDeckController#isGoodName(java.lang.String)
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean fileExists(String deckName) {
|
||||
return !folder.isUnique(deckName);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isGoodName(String deckName) {
|
||||
return StringUtils.isNotBlank(deckName) && folder.isUnique(deckName);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.IDeckController#importDeck(forge.deck.Deck)
|
||||
*/
|
||||
@Override
|
||||
public void importDeck(T newDeck) {
|
||||
setModel(newDeck);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.IDeckController#isModelInStore()
|
||||
*/
|
||||
@Override
|
||||
public boolean isModelInStore() {
|
||||
return modelInStore;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.IDeckController#newModel()
|
||||
*/
|
||||
@Override
|
||||
public void newModel() {
|
||||
model = newModelCreator.apply();
|
||||
saved = true;
|
||||
view.updateView();
|
||||
}
|
||||
}
|
||||
173
src/main/java/forge/gui/deckeditor/DeckManagerQuest.java
Normal file
173
src/main/java/forge/gui/deckeditor/DeckManagerQuest.java
Normal file
@@ -0,0 +1,173 @@
|
||||
package forge.gui.deckeditor;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.deck.Deck;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.quest.data.QuestData;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public class DeckManagerQuest implements IDeckManager<Deck>{
|
||||
|
||||
private Deck model;
|
||||
private boolean saved;
|
||||
private boolean modelInStore;
|
||||
private final Map<String, Deck> decks;
|
||||
private final DeckEditorBase<?, Deck> view;
|
||||
|
||||
public DeckManagerQuest(QuestData questData0, DeckEditorBase<?, Deck> view0)
|
||||
{
|
||||
decks = questData0.getMyDecks();
|
||||
view = view0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Deck getModel() { return model; }
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.IDeckManager#newModel()
|
||||
*/
|
||||
@Override
|
||||
public void newModel() {
|
||||
setModel(new Deck());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param document0 the document to set
|
||||
*/
|
||||
public void setModel(Deck document) {
|
||||
setModel( document, false );
|
||||
}
|
||||
|
||||
public void setModel(Deck document, boolean isStored) {
|
||||
modelInStore = isStored;
|
||||
this.model = document;
|
||||
view.updateView();
|
||||
saved = true; // unless set to false in notify
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.IDeckManager#getModel()
|
||||
*/
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.IDeckManager#notifyModelChanged()
|
||||
*/
|
||||
@Override
|
||||
public void notifyModelChanged() {
|
||||
saved = false;
|
||||
// view.setTitle()
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.IDeckManager#getOwnerWindow()
|
||||
*/
|
||||
@Override
|
||||
public Component getOwnerWindow() {
|
||||
return view;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.IDeckManager#getView()
|
||||
*/
|
||||
@Override
|
||||
public DeckEditorBase<?, Deck> getView() {
|
||||
return view;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.IDeckManager#getSavedNames()
|
||||
*/
|
||||
@Override
|
||||
public List<String> getSavedNames() {
|
||||
return new ArrayList<String>(decks.keySet());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.IDeckManager#load(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void load(String name) {
|
||||
Deck deck = decks.get(name);
|
||||
if ( null != deck )
|
||||
setModel(deck, true);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.IDeckManager#save()
|
||||
*/
|
||||
@Override
|
||||
public void save() {
|
||||
decks.put(model.getName(), model);
|
||||
// save to disk is done from outside
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.IDeckManager#isSaved()
|
||||
*/
|
||||
@Override
|
||||
public boolean isSaved() {
|
||||
return saved;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.IDeckManager#delete()
|
||||
*/
|
||||
@Override
|
||||
public void delete() {
|
||||
if ( StringUtils.isNotBlank(model.getName())) {
|
||||
decks.remove(model.getName());
|
||||
}
|
||||
modelInStore = false;
|
||||
newModel();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.IDeckManager#isGoodName(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public boolean isGoodName(String deckName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.IDeckManager#importDeck(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public void importDeck(Deck newDeck) {
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.IDeckManager#isModelInStore()
|
||||
*/
|
||||
@Override
|
||||
public boolean isModelInStore() {
|
||||
return modelInStore;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.IDeckManager#saveAs(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void saveAs(String name0) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.IDeckManager#fileExists(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public boolean fileExists(String deckName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -38,15 +38,18 @@ import javax.swing.WindowConstants;
|
||||
|
||||
import net.slightlymagic.maxmtg.Predicate;
|
||||
import forge.AllZone;
|
||||
import forge.Command;
|
||||
import forge.Constant;
|
||||
import forge.Singletons;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckIO;
|
||||
import forge.deck.DeckManager;
|
||||
import forge.deck.DeckSet;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.game.GameType;
|
||||
import forge.game.limited.IBoosterDraft;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.gui.deckeditor.elements.CardPanelLite;
|
||||
import forge.gui.deckeditor.elements.ManaCostRenderer;
|
||||
import forge.gui.deckeditor.elements.TableColumnInfo;
|
||||
import forge.gui.deckeditor.elements.TableView;
|
||||
import forge.item.CardDb;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.InventoryItem;
|
||||
@@ -62,7 +65,7 @@ import forge.properties.NewConstants.Lang.GuiBoosterDraft;
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class DeckEditorDraft extends DeckEditorBase {
|
||||
public class DraftingProcess extends DeckEditorBase<CardPrinted, DeckSet> {
|
||||
/**
|
||||
* Constant <code>serialVersionUID=-6055633915602448260L</code>.
|
||||
*/
|
||||
@@ -79,10 +82,10 @@ public class DeckEditorDraft extends DeckEditorBase {
|
||||
public void mouseClicked(final MouseEvent e) {
|
||||
// Pick on left-button double click
|
||||
if (((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0) && (e.getClickCount() == 2)) {
|
||||
DeckEditorDraft.this.jButtonPickClicked(null);
|
||||
DraftingProcess.this.jButtonPickClicked(null);
|
||||
} else if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0) {
|
||||
// pick on right click
|
||||
final JTable table = DeckEditorDraft.this.getTopTableWithCards().getTable();
|
||||
final JTable table = DraftingProcess.this.getTopTableWithCards().getTable();
|
||||
final int rowNumber = table.rowAtPoint(e.getPoint());
|
||||
// after hittest - if it was outside of rows - discard this
|
||||
// click
|
||||
@@ -94,7 +97,7 @@ public class DeckEditorDraft extends DeckEditorBase {
|
||||
if (rowNumber != table.getSelectedRow()) {
|
||||
table.getSelectionModel().setSelectionInterval(rowNumber, rowNumber);
|
||||
} else {
|
||||
DeckEditorDraft.this.jButtonPickClicked(null);
|
||||
DraftingProcess.this.jButtonPickClicked(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -108,15 +111,8 @@ public class DeckEditorDraft extends DeckEditorBase {
|
||||
*/
|
||||
public final void showGui(final IBoosterDraft inBoosterDraft) {
|
||||
this.boosterDraft = inBoosterDraft;
|
||||
this.show(null);
|
||||
|
||||
this.setup();
|
||||
this.showChoices(this.boosterDraft.nextChoice());
|
||||
this.getBottomTableWithCards().setDeck((Iterable<InventoryItem>) null);
|
||||
|
||||
this.getTopTableWithCards().sort(1, true);
|
||||
this.getBottomTableWithCards().sort(1, true);
|
||||
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,7 +127,7 @@ public class DeckEditorDraft extends DeckEditorBase {
|
||||
final int n = JOptionPane.showConfirmDialog(null,
|
||||
ForgeProps.getLocalized(GuiBoosterDraft.CLOSE_MESSAGE), "", JOptionPane.YES_NO_OPTION);
|
||||
if (n == JOptionPane.YES_OPTION) {
|
||||
DeckEditorDraft.this.dispose();
|
||||
DraftingProcess.this.dispose();
|
||||
Singletons.getView().getHomeView().getDraftController().updateHumanDecks();
|
||||
}
|
||||
} // windowClosing()
|
||||
@@ -180,7 +176,7 @@ public class DeckEditorDraft extends DeckEditorBase {
|
||||
@Override
|
||||
public void keyPressed(final KeyEvent e) {
|
||||
if (e.getKeyChar() == ' ') {
|
||||
DeckEditorDraft.this.jButtonPickClicked(null);
|
||||
DraftingProcess.this.jButtonPickClicked(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -190,11 +186,11 @@ public class DeckEditorDraft extends DeckEditorBase {
|
||||
/**
|
||||
* Instantiates a new deck editor draft.
|
||||
*/
|
||||
public DeckEditorDraft() {
|
||||
super(GameType.Draft);
|
||||
public DraftingProcess() {
|
||||
|
||||
try {
|
||||
this.setTopTableWithCards(new TableWithCards("Choose one card", false));
|
||||
this.setBottomTableWithCards(new TableWithCards("Previously picked cards", true));
|
||||
this.setTopTableWithCards(new TableView<CardPrinted>("Choose one card", false, CardPrinted.class));
|
||||
this.setBottomTableWithCards(new TableView<CardPrinted>("Previously picked cards", true, CardPrinted.class));
|
||||
this.setFilterBoxes(null);
|
||||
this.cardView = new CardPanelLite();
|
||||
this.jbInit();
|
||||
@@ -229,7 +225,7 @@ public class DeckEditorDraft extends DeckEditorBase {
|
||||
this.jButtonPick.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
DeckEditorDraft.this.jButtonPickClicked(e);
|
||||
DraftingProcess.this.jButtonPickClicked(e);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -293,7 +289,7 @@ public class DeckEditorDraft extends DeckEditorBase {
|
||||
* @return a {@link forge.deck.Deck} object.
|
||||
*/
|
||||
private Deck getPlayersDeck() {
|
||||
final Deck deck = new Deck(GameType.Draft);
|
||||
final Deck deck = new Deck();
|
||||
Constant.Runtime.HUMAN_DECK[0] = deck;
|
||||
|
||||
// add sideboard to deck
|
||||
@@ -329,22 +325,14 @@ public class DeckEditorDraft extends DeckEditorBase {
|
||||
final Deck[] computer = this.boosterDraft.getDecks();
|
||||
|
||||
final Deck human = this.getPlayersDeck();
|
||||
human.setName(s);
|
||||
|
||||
final Deck[] all = { human, computer[0], computer[1], computer[2], computer[3], computer[4], computer[5],
|
||||
computer[6] };
|
||||
|
||||
for (int i = 1; i < all.length; i++) {
|
||||
all[i].setName(String.format("Draft %s - Computer %d", s, i));
|
||||
}
|
||||
final DeckSet all = new DeckSet("Draft " + s);
|
||||
all.setHumanDeck(human);
|
||||
all.addAiDecks(computer);
|
||||
|
||||
// DeckManager deckManager = new
|
||||
// DeckManager(ForgeProps.getFile(NEW_DECKS));
|
||||
final DeckManager deckManager = AllZone.getDeckManager();
|
||||
deckManager.addDraftDeck(all);
|
||||
|
||||
// write file
|
||||
DeckIO.writeDraftDecks(all);
|
||||
AllZone.getDecks().getDraft().add(all); // write file right here
|
||||
|
||||
// close and open next screen
|
||||
this.dispose();
|
||||
@@ -359,7 +347,37 @@ public class DeckEditorDraft extends DeckEditorBase {
|
||||
* @see forge.gui.deckeditor.DeckEditorBase#buildFilter()
|
||||
*/
|
||||
@Override
|
||||
protected final Predicate<InventoryItem> buildFilter() {
|
||||
return Predicate.getTrue(InventoryItem.class);
|
||||
protected final Predicate<CardPrinted> buildFilter() {
|
||||
return Predicate.getTrue(CardPrinted.class);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.DeckEditorBase#getController()
|
||||
*/
|
||||
@Override
|
||||
public IDeckManager<DeckSet> getController() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.DeckEditorBase#updateView()
|
||||
*/
|
||||
@Override
|
||||
public void updateView() {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.DeckEditorBase#show(forge.Command)
|
||||
*/
|
||||
@Override
|
||||
public void show(Command exitCommand) {
|
||||
this.setup();
|
||||
this.showChoices(this.boosterDraft.nextChoice());
|
||||
this.getBottomTableWithCards().setDeck((Iterable<InventoryItem>) null);
|
||||
|
||||
this.getTopTableWithCards().sort(1, true);
|
||||
this.getBottomTableWithCards().sort(1, true);
|
||||
|
||||
this.setVisible(true);
|
||||
}
|
||||
}
|
||||
55
src/main/java/forge/gui/deckeditor/IDeckManager.java
Normal file
55
src/main/java/forge/gui/deckeditor/IDeckManager.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package forge.gui.deckeditor;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public interface IDeckManager<T> {
|
||||
|
||||
void newModel();
|
||||
void setModel(T model);
|
||||
T getModel();
|
||||
/** Call this anytime model becomes different from the saved on disk state*/
|
||||
void notifyModelChanged();
|
||||
Component getOwnerWindow();
|
||||
DeckEditorBase<?, T> getView();
|
||||
/** Gets names of saved models in folder / questData */
|
||||
List<String> getSavedNames();
|
||||
void load(String name);
|
||||
void save();
|
||||
void saveAs(String name0);
|
||||
boolean isSaved();
|
||||
void delete();
|
||||
/** Returns true if no object exists with that name */
|
||||
boolean isGoodName(String deckName);
|
||||
/** Import in quest adds add cards to pool, unlike constructed */
|
||||
void importDeck(T newDeck);
|
||||
/** Tells if this deck was already saved to disk / questData */
|
||||
boolean isModelInStore();
|
||||
/**
|
||||
* TODO: Write javadoc for this method.
|
||||
* @param deckName
|
||||
* @return
|
||||
*/
|
||||
boolean fileExists(String deckName);
|
||||
|
||||
/*
|
||||
// IMPORT DECK CODE
|
||||
this.questData.addDeck(newDeck);
|
||||
|
||||
final ItemPool<CardPrinted> cardpool = ItemPool.createFrom(this.questData.getCards().getCardpool(),
|
||||
CardPrinted.class);
|
||||
final ItemPool<CardPrinted> decklist = new ItemPool<CardPrinted>(CardPrinted.class);
|
||||
for (final Entry<CardPrinted, Integer> s : newDeck.getMain()) {
|
||||
final CardPrinted cp = s.getKey();
|
||||
decklist.add(cp, s.getValue());
|
||||
cardpool.add(cp, s.getValue());
|
||||
this.questData.getCards().getCardpool().add(cp, s.getValue());
|
||||
}
|
||||
this.controller.showItems(cardpool, decklist);
|
||||
*/
|
||||
}
|
||||
414
src/main/java/forge/gui/deckeditor/MenuBase.java
Normal file
414
src/main/java/forge/gui/deckeditor/MenuBase.java
Normal file
@@ -0,0 +1,414 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.gui.deckeditor;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.Command;
|
||||
import forge.deck.DeckBase;
|
||||
import forge.deck.io.DeckIOCore;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.gui.GuiUtils;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Gui_DeckEditor_Menu class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id: DeckEditorCommonMenu.java 13590 2012-01-27 20:46:27Z Max mtg $
|
||||
*/
|
||||
public class MenuBase<T extends DeckBase> extends JMenuBar {
|
||||
|
||||
private static final long serialVersionUID = -4037993759604768755L;
|
||||
private final Command exitCommand;
|
||||
private final IDeckManager<T> controller;
|
||||
|
||||
/**
|
||||
*
|
||||
* Menu for Deck Editor.
|
||||
*
|
||||
* @param inDisplay
|
||||
* a DeckDisplay
|
||||
* @param dckManager
|
||||
* a DeckManager
|
||||
* @param exit
|
||||
* a Command
|
||||
*/
|
||||
public MenuBase(final IDeckManager<T> ctrl, final Command exit) {
|
||||
this.controller = ctrl;
|
||||
this.exitCommand = exit;
|
||||
|
||||
this.setupMenu();
|
||||
}
|
||||
|
||||
protected final IDeckManager<T> getController() {
|
||||
return controller;
|
||||
}
|
||||
|
||||
protected void setupMenu()
|
||||
{
|
||||
this.add(getDefaultFileMenu());
|
||||
this.add(getSortMenu());
|
||||
}
|
||||
|
||||
/**
|
||||
* New constructed.
|
||||
*
|
||||
* @param careAboutOldDeck
|
||||
* a boolean
|
||||
*/
|
||||
protected final void newDocument(final boolean careAboutOldDeck) {
|
||||
if (careAboutOldDeck && !this.canLeaveCurrentDeck()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.controller.newModel();
|
||||
}
|
||||
|
||||
protected final String getUserInputOpenDeck() {
|
||||
final List<String> choices = this.controller.getSavedNames();
|
||||
if (choices.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(null, "No decks found", "Open Deck", JOptionPane.PLAIN_MESSAGE);
|
||||
return null;
|
||||
}
|
||||
|
||||
final Object o = GuiUtils.getChoiceOptional("Open Deck", choices.toArray());
|
||||
return o == null ? null : o.toString();
|
||||
}
|
||||
|
||||
// deck.setName(currentDeckName);
|
||||
|
||||
|
||||
protected final void open() {
|
||||
if (!this.canLeaveCurrentDeck()) { return; }
|
||||
final String name = this.getUserInputOpenDeck();
|
||||
if (StringUtils.isBlank(name)) { return; }
|
||||
controller.load(name);
|
||||
}
|
||||
|
||||
protected final void save() {
|
||||
if (StringUtils.isBlank(controller.getModel().getName())) {
|
||||
this.saveAs();
|
||||
return;
|
||||
}
|
||||
|
||||
this.controller.save();
|
||||
}
|
||||
|
||||
protected final void saveAs() {
|
||||
final String name = this.getDeckNameFromDialog();
|
||||
|
||||
if (StringUtils.isBlank(name)) {
|
||||
final int n = JOptionPane.showConfirmDialog(null, "This name is incorrect. Enter another one?", "Cannot save", JOptionPane.YES_NO_OPTION);
|
||||
|
||||
if (n == JOptionPane.NO_OPTION) return;
|
||||
}
|
||||
|
||||
if (controller.fileExists(name)) {
|
||||
final int m = JOptionPane.showConfirmDialog(null, "There is already saved an item named '"+name+"'. Would you like to overwrite it?", "Confirm overwrite", JOptionPane.YES_NO_OPTION);
|
||||
|
||||
if (m == JOptionPane.NO_OPTION) return;
|
||||
}
|
||||
|
||||
this.controller.saveAs(name);
|
||||
}
|
||||
|
||||
protected final void delete() {
|
||||
if (!controller.isModelInStore()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int n = JOptionPane.showConfirmDialog(null, "Do you want to delete this deck " + controller.getModel().getName()
|
||||
+ " ?", "Delete", JOptionPane.YES_NO_OPTION);
|
||||
|
||||
if (n == JOptionPane.NO_OPTION) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.controller.delete();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* close window.
|
||||
*/
|
||||
public final void close() {
|
||||
if (!this.canLeaveCurrentDeck()) {
|
||||
return;
|
||||
}
|
||||
this.exitCommand.execute();
|
||||
}
|
||||
|
||||
protected final boolean canLeaveCurrentDeck() {
|
||||
if (controller.isSaved()) {
|
||||
return true;
|
||||
}
|
||||
final String message = String.format("Do you wish to save changes you made to your current deck '%s'?",
|
||||
this.controller.getModel().getName());
|
||||
final int choice = JOptionPane
|
||||
.showConfirmDialog(this.controller.getOwnerWindow(), message, "You have unsaved changes in your deck",
|
||||
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
|
||||
if (JOptionPane.CANCEL_OPTION == choice) {
|
||||
return false;
|
||||
}
|
||||
if (JOptionPane.NO_OPTION == choice) {
|
||||
return true;
|
||||
}
|
||||
|
||||
save();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getUserInput_GetDeckName.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
protected final String getDeckNameFromDialog() {
|
||||
final Object o = JOptionPane.showInputDialog(null, "Save As", "Deck Name", JOptionPane.OK_CANCEL_OPTION);
|
||||
|
||||
if (o == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
final String deckName = DeckIOCore.cleanDeckName(o.toString());
|
||||
final boolean isGoodName = controller.isGoodName(deckName);
|
||||
|
||||
if (isGoodName) {
|
||||
return deckName;
|
||||
}
|
||||
|
||||
JOptionPane.showMessageDialog(null, "Please pick another deck name, another deck currently has that name.");
|
||||
return this.getDeckNameFromDialog();
|
||||
}
|
||||
|
||||
protected JMenu getDefaultFileMenu() {
|
||||
final JMenu fileMenu = new JMenu("Deck");
|
||||
|
||||
final JMenuItem newDoc = new JMenuItem("New");
|
||||
final JMenuItem open = new JMenuItem("Open");
|
||||
final JMenuItem save = new JMenuItem("Save");
|
||||
final JMenuItem saveAs = new JMenuItem("Save As...");
|
||||
final JMenuItem delete = new JMenuItem("Delete");
|
||||
|
||||
|
||||
fileMenu.add(newDoc);
|
||||
fileMenu.add(open);
|
||||
fileMenu.addSeparator();
|
||||
|
||||
fileMenu.add(save);
|
||||
fileMenu.add(saveAs);
|
||||
fileMenu.add(delete);
|
||||
|
||||
newDoc.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MenuBase.this.newDocument(true);
|
||||
}
|
||||
});
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : newConstructed() error - " + ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
open.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MenuBase.this.open();
|
||||
}
|
||||
});
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : open() error - " + ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
save.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MenuBase.this.save();
|
||||
}
|
||||
});
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : save() error - " + ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
saveAs.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MenuBase.this.saveAs();
|
||||
}
|
||||
});
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : saveAs() error - " + ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
delete.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MenuBase.this.delete();
|
||||
}
|
||||
});
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : delete() error - " + ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
return fileMenu;
|
||||
}
|
||||
|
||||
protected void appendCloseMenuItemTo(JMenu fileMenu)
|
||||
{
|
||||
final JMenuItem close = new JMenuItem("Close");
|
||||
fileMenu.addSeparator();
|
||||
fileMenu.add(close);
|
||||
|
||||
close.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MenuBase.this.close();
|
||||
}
|
||||
});
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : close() error - " + ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
} // setupMenu()
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* setupSortMenu.
|
||||
* </p>
|
||||
*/
|
||||
protected final JMenuItem getSortMenu() {
|
||||
final JMenuItem name = new JMenuItem("Card Name");
|
||||
final JMenuItem cost = new JMenuItem("Cost");
|
||||
final JMenuItem color = new JMenuItem("Color");
|
||||
final JMenuItem type = new JMenuItem("Type");
|
||||
final JMenuItem stats = new JMenuItem("Power/Toughness");
|
||||
final JMenuItem rarity = new JMenuItem("Rarity");
|
||||
|
||||
final JMenu menu = new JMenu("Sort By");
|
||||
menu.add(name);
|
||||
menu.add(cost);
|
||||
menu.add(color);
|
||||
menu.add(type);
|
||||
menu.add(stats);
|
||||
menu.add(rarity);
|
||||
|
||||
name.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
(MenuBase.this.controller).getView().getTopTableModel().sort(1, true);
|
||||
}
|
||||
});
|
||||
|
||||
// 0 1 2 3 4 5 6
|
||||
// private String column[] = {"Qty", "Name", "Cost", "Color", "Type",
|
||||
// "Stats", "Rarity"};
|
||||
cost.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
(MenuBase.this.controller).getView().getTopTableModel().sort(4).sort(3).sort(2);
|
||||
}
|
||||
});
|
||||
|
||||
color.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
(MenuBase.this.controller).getView().getTopTableModel().sort(4).sort(2).sort(3);
|
||||
}
|
||||
});
|
||||
|
||||
type.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
(MenuBase.this.controller).getView().getTopTableModel().sort(2).sort(3).sort(4);
|
||||
}
|
||||
});
|
||||
|
||||
stats.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
(MenuBase.this.controller).getView().getTopTableModel().sort(4).sort(2).sort(3).sort(5);
|
||||
}
|
||||
});
|
||||
|
||||
rarity.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
// sort by cost, type, color, rarity
|
||||
(MenuBase.this.controller).getView().getTopTableModel().sort(2).sort(4).sort(3).sort(6);
|
||||
}
|
||||
});
|
||||
|
||||
return menu;
|
||||
} // setupSortMenu()
|
||||
}
|
||||
335
src/main/java/forge/gui/deckeditor/MenuCommon.java
Normal file
335
src/main/java/forge/gui/deckeditor/MenuCommon.java
Normal file
@@ -0,0 +1,335 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.gui.deckeditor;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import forge.CardList;
|
||||
import forge.Command;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.generate.GenerateConstructedDeck;
|
||||
import forge.deck.io.DeckIOCore;
|
||||
import forge.deck.io.DeckSerializer;
|
||||
import forge.error.ErrorViewer;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Gui_DeckEditor_Menu class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public final class MenuCommon extends MenuBase<Deck> {
|
||||
|
||||
/** Constant <code>serialVersionUID=-4037993759604768755L</code>. */
|
||||
private static final long serialVersionUID = -4037993759604768755L;
|
||||
/** Constant <code>previousDirectory</code>. */
|
||||
private static File previousDirectory = null;
|
||||
|
||||
/**
|
||||
*
|
||||
* Menu for Deck Editor.
|
||||
*
|
||||
* @param inDisplay
|
||||
* a DeckDisplay
|
||||
* @param dckManager
|
||||
* a DeckManager
|
||||
* @param exit
|
||||
* a Command
|
||||
*/
|
||||
public MenuCommon(final IDeckManager<Deck> ctrl, final Command exit) {
|
||||
super(ctrl, exit);
|
||||
|
||||
// this is added just to make save() and saveAs() work ok
|
||||
// when first started up, just a silly patch
|
||||
|
||||
}
|
||||
|
||||
|
||||
private final void newRandomConstructed() {
|
||||
if (!this.canLeaveCurrentDeck()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Deck randomDeck = new Deck();
|
||||
|
||||
// The only remaining reference to global variable!
|
||||
final CardList random = new CardList(forge.AllZone.getCardFactory().getRandomCombinationWithoutRepetition(
|
||||
15 * 5));
|
||||
|
||||
randomDeck.getMain().add(random);
|
||||
randomDeck.getMain().add("Plains");
|
||||
randomDeck.getMain().add("Island");
|
||||
randomDeck.getMain().add("Swamp");
|
||||
randomDeck.getMain().add("Mountain");
|
||||
randomDeck.getMain().add("Forest");
|
||||
randomDeck.getMain().add("Terramorphic Expanse");
|
||||
|
||||
getController().setModel(randomDeck);
|
||||
}
|
||||
|
||||
private final void newGenerateConstructed() {
|
||||
if (!this.canLeaveCurrentDeck()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Deck genConstructed = new Deck();
|
||||
genConstructed.getMain().add((new GenerateConstructedDeck()).generateDeck());
|
||||
getController().setModel(genConstructed);
|
||||
}
|
||||
|
||||
private final File getImportFilename() {
|
||||
final JFileChooser chooser = new JFileChooser(MenuCommon.previousDirectory);
|
||||
|
||||
chooser.addChoosableFileFilter(DeckSerializer.DCK_FILTER);
|
||||
final int returnVal = chooser.showOpenDialog(null);
|
||||
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
final File file = chooser.getSelectedFile();
|
||||
MenuCommon.previousDirectory = file.getParentFile();
|
||||
return file;
|
||||
}
|
||||
return null;
|
||||
} // openFileDialog()
|
||||
|
||||
private final void importDeck() {
|
||||
final File file = this.getImportFilename();
|
||||
if (file == null) {
|
||||
} else if (file.getName().endsWith(".dck")) {
|
||||
try {
|
||||
getController().setModel(DeckIOCore.readDeck(file));
|
||||
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : importDeck() error, " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* exportDeck.
|
||||
* </p>
|
||||
*/
|
||||
private final void exportDeck() {
|
||||
final File filename = this.getExportFilename();
|
||||
if (filename == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
DeckSerializer.writeDeck(getController().getModel(), filename);
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : exportDeck() error, " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
private final File getExportFilename() {
|
||||
final JFileChooser save = new JFileChooser(MenuCommon.previousDirectory);
|
||||
save.setDialogTitle("Export Deck Filename");
|
||||
save.setDialogType(JFileChooser.SAVE_DIALOG);
|
||||
save.setFileFilter(DeckSerializer.DCK_FILTER);
|
||||
|
||||
if (save.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
|
||||
final File file = save.getSelectedFile();
|
||||
final String check = file.getAbsolutePath();
|
||||
|
||||
MenuCommon.previousDirectory = file.getParentFile();
|
||||
|
||||
return check.endsWith(".dck") ? file : new File(check + ".dck");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Generate Proxy for a Deck.
|
||||
* </p>
|
||||
*/
|
||||
private final void generateProxies() {
|
||||
final File filename = this.getProxiesFilename();
|
||||
if (filename == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
DeckSerializer.writeDeckHtml(getController().getModel(), filename);
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : printProxies() error, " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
private final File getProxiesFilename() {
|
||||
final JFileChooser save = new JFileChooser(MenuCommon.previousDirectory);
|
||||
save.setDialogTitle("Proxy HTML Filename");
|
||||
save.setDialogType(JFileChooser.SAVE_DIALOG);
|
||||
save.setFileFilter(DeckSerializer.HTML_FILTER);
|
||||
|
||||
if (save.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
|
||||
final File file = save.getSelectedFile();
|
||||
final String check = file.getAbsolutePath();
|
||||
|
||||
MenuCommon.previousDirectory = file.getParentFile();
|
||||
|
||||
return check.endsWith(".html") ? file : new File(check + ".html");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// deck.setName(currentDeckName);
|
||||
|
||||
|
||||
protected JMenu getDefaultFileMenu() {
|
||||
final JMenu fileMenu = super.getDefaultFileMenu();
|
||||
|
||||
|
||||
final JMenuItem newRandomConstructed = new JMenuItem("New Deck - Generate Random Constructed Cardpool");
|
||||
final JMenuItem newGenerateConstructed = new JMenuItem("New Deck - Generate Constructed Deck");
|
||||
|
||||
final JMenuItem importDeck = new JMenuItem("Import Deck...");
|
||||
final JMenuItem exportDeck = new JMenuItem("Export Deck...");
|
||||
// JMenuItem downloadDeck = new JMenuItem("Download Deck");
|
||||
|
||||
|
||||
// newDraftItem = newDraft;
|
||||
// newDraftItem.setEnabled(false);
|
||||
|
||||
|
||||
|
||||
// fileMenu.add(newSealed);
|
||||
// fileMenu.add(newDraft);
|
||||
fileMenu.addSeparator();
|
||||
|
||||
fileMenu.add(importDeck);
|
||||
fileMenu.add(exportDeck);
|
||||
|
||||
final JMenuItem generateProxies = new JMenuItem("Generate Proxies...");
|
||||
fileMenu.add(generateProxies);
|
||||
|
||||
|
||||
// fileMenu.add(downloadDeck);
|
||||
fileMenu.addSeparator();
|
||||
|
||||
fileMenu.add(newRandomConstructed);
|
||||
fileMenu.add(newGenerateConstructed);
|
||||
|
||||
appendCloseMenuItemTo(fileMenu);
|
||||
|
||||
generateProxies.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MenuCommon.this.generateProxies();
|
||||
}
|
||||
});
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : generateProxies() error - " + ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// add listeners
|
||||
exportDeck.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MenuCommon.this.exportDeck();
|
||||
}
|
||||
});
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : exportDeck() error - " + ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
importDeck.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MenuCommon.this.importDeck();
|
||||
}
|
||||
});
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : importDeck() error - " + ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
newRandomConstructed.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MenuCommon.this.newRandomConstructed();
|
||||
}
|
||||
});
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : newRandomConstructed() error - " + ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
newGenerateConstructed.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MenuCommon.this.newGenerateConstructed();
|
||||
}
|
||||
});
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : newRandomConstructed() error - " + ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return fileMenu;
|
||||
} // setupMenu()
|
||||
}
|
||||
53
src/main/java/forge/gui/deckeditor/MenuLimited.java
Normal file
53
src/main/java/forge/gui/deckeditor/MenuLimited.java
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.gui.deckeditor;
|
||||
|
||||
import forge.Command;
|
||||
import forge.deck.DeckSet;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Gui_DeckEditor_Menu class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id: DeckEditorCommonMenu.java 13590 2012-01-27 20:46:27Z Max mtg $
|
||||
*/
|
||||
public final class MenuLimited extends MenuBase<DeckSet> {
|
||||
|
||||
/** Constant <code>serialVersionUID=-4037993759604768755L</code>. */
|
||||
private static final long serialVersionUID = -4037993759604768755L;
|
||||
|
||||
/**
|
||||
*
|
||||
* Menu for Deck Editor.
|
||||
*
|
||||
* @param inDisplay
|
||||
* a DeckDisplay
|
||||
* @param dckManager
|
||||
* a DeckManager
|
||||
* @param exit
|
||||
* a Command
|
||||
*/
|
||||
public MenuLimited(final IDeckManager<DeckSet> ctrl, final Command exit) {
|
||||
super( ctrl, exit );
|
||||
}
|
||||
|
||||
// deck.setName(currentDeckName);
|
||||
|
||||
}
|
||||
228
src/main/java/forge/gui/deckeditor/MenuQuest.java
Normal file
228
src/main/java/forge/gui/deckeditor/MenuQuest.java
Normal file
@@ -0,0 +1,228 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.gui.deckeditor;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuItem;
|
||||
|
||||
import forge.Command;
|
||||
import forge.Constant;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.io.DeckIOCore;
|
||||
import forge.deck.io.DeckSerializer;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.gui.ListChooser;
|
||||
import forge.item.CardDb;
|
||||
import forge.item.CardPrinted;
|
||||
|
||||
//presumes AllZone.getQuestData() is not null
|
||||
/**
|
||||
* <p>
|
||||
* Gui_Quest_DeckEditor_Menu class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class MenuQuest extends MenuBase<Deck> {
|
||||
/** Constant <code>serialVersionUID=-4052319220021158574L</code>. */
|
||||
private static final long serialVersionUID = -4052319220021158574L;
|
||||
|
||||
|
||||
// used for import and export, try to made the gui user friendly
|
||||
/** Constant <code>previousDirectory</code>. */
|
||||
private static File previousDirectory = null;
|
||||
/**
|
||||
* <p>
|
||||
* Constructor for Gui_Quest_DeckEditor_Menu.
|
||||
* </p>
|
||||
*
|
||||
* @param q
|
||||
* the q
|
||||
* @param d
|
||||
* a {@link forge.gui.deckeditor.IDeckDisplay} object.
|
||||
* @param exit
|
||||
* a {@link forge.Command} object.
|
||||
*/
|
||||
public MenuQuest(final IDeckManager<Deck> d, final Command exit) {
|
||||
|
||||
super(d, exit);
|
||||
|
||||
this.setupMenu();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* importDeck.
|
||||
* </p>
|
||||
*/
|
||||
private final void importDeck() {
|
||||
final File file = this.getImportFilename();
|
||||
|
||||
if (file != null && file.getName().endsWith(".dck")) {
|
||||
try {
|
||||
final Deck newDeck = DeckIOCore.readDeck(file);
|
||||
getController().importDeck(newDeck);
|
||||
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : importDeck() error, " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
} // importDeck()
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getImportFilename.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.io.File} object.
|
||||
*/
|
||||
private final File getImportFilename() {
|
||||
final JFileChooser chooser = new JFileChooser(MenuQuest.previousDirectory);
|
||||
|
||||
chooser.addChoosableFileFilter(DeckIOCore.DCK_FILTER);
|
||||
final int returnVal = chooser.showOpenDialog(null);
|
||||
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
final File file = chooser.getSelectedFile();
|
||||
MenuQuest.previousDirectory = file.getParentFile();
|
||||
return file;
|
||||
}
|
||||
|
||||
return null;
|
||||
} // openFileDialog()
|
||||
|
||||
private final ActionListener addCardActionListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent a) {
|
||||
|
||||
// Provide a model here: all unique cards to be displayed by only
|
||||
// name (unlike default toString)
|
||||
final Iterable<CardPrinted> uniqueCards = CardDb.instance().getAllUniqueCards();
|
||||
final List<String> cards = new ArrayList<String>();
|
||||
for (final CardPrinted c : uniqueCards) {
|
||||
cards.add(c.getName());
|
||||
}
|
||||
Collections.sort(cards);
|
||||
|
||||
// use standard forge's list selection dialog
|
||||
final ListChooser<String> c = new ListChooser<String>("Cheat - Add Card to Your Cardpool", 0, 1, cards);
|
||||
if (c.show()) {
|
||||
((DeckEditorQuest)getController().getView()).addCheatCard(CardDb.instance().getCard(c.getSelectedValue()));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
protected JMenu getDefaultFileMenu() {
|
||||
final JMenu deckMenu = super.getDefaultFileMenu();
|
||||
|
||||
final JMenuItem addCard = new JMenuItem("Cheat - Add Card");
|
||||
|
||||
addCard.addActionListener(this.addCardActionListener);
|
||||
|
||||
|
||||
if (Constant.Runtime.DEV_MODE[0]) {
|
||||
deckMenu.addSeparator();
|
||||
deckMenu.add(addCard);
|
||||
}
|
||||
|
||||
deckMenu.addSeparator();
|
||||
this.addImportExport(deckMenu, true);
|
||||
|
||||
appendCloseMenuItemTo(deckMenu);
|
||||
return deckMenu;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* addImportExport.
|
||||
* </p>
|
||||
*
|
||||
* @param menu
|
||||
* a {@link javax.swing.JMenu} object.
|
||||
* @param isHumanMenu
|
||||
* a boolean.
|
||||
*/
|
||||
private final void addImportExport(final JMenu menu, final boolean isHumanMenu) {
|
||||
final JMenuItem import2 = new JMenuItem("Import");
|
||||
final JMenuItem export = new JMenuItem("Export");
|
||||
|
||||
import2.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent a) {
|
||||
MenuQuest.this.importDeck(); // importDeck(isHumanMenu);
|
||||
}
|
||||
}); // import
|
||||
|
||||
export.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent a) {
|
||||
MenuQuest.this.exportDeck();
|
||||
}
|
||||
}); // export
|
||||
|
||||
menu.add(import2);
|
||||
menu.add(export);
|
||||
|
||||
} // addImportExport()
|
||||
|
||||
private final void exportDeck() {
|
||||
final File filename = this.getExportFilename();
|
||||
if (filename == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
DeckSerializer.writeDeck(getController().getModel(), filename);
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : exportDeck() error, " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
private final File getExportFilename() {
|
||||
final JFileChooser save = new JFileChooser(previousDirectory);
|
||||
save.setDialogTitle("Export Deck Filename");
|
||||
save.setDialogType(JFileChooser.SAVE_DIALOG);
|
||||
save.setFileFilter(DeckSerializer.DCK_FILTER);
|
||||
|
||||
if (save.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
|
||||
final File file = save.getSelectedFile();
|
||||
final String check = file.getAbsolutePath();
|
||||
|
||||
previousDirectory = file.getParentFile();
|
||||
|
||||
return check.endsWith(".dck") ? file : new File(check + ".dck");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -98,7 +98,8 @@ public abstract class PresetColumns {
|
||||
public static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_NAME_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return from.getKey().getName();
|
||||
String name = from.getKey().getName();
|
||||
return name.contains("AE") ? name.replace("AE", "Æ") : name;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -38,12 +38,16 @@ import net.slightlymagic.maxmtg.Predicate;
|
||||
import forge.Command;
|
||||
import forge.deck.Deck;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.game.GameType;
|
||||
import forge.gui.CardListViewer;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.gui.deckeditor.elements.CardPanelLite;
|
||||
import forge.gui.deckeditor.elements.ManaCostRenderer;
|
||||
import forge.gui.deckeditor.elements.TableColumnInfo;
|
||||
import forge.gui.deckeditor.elements.TableView;
|
||||
import forge.item.BoosterPack;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.ItemPool;
|
||||
import forge.item.ItemPoolView;
|
||||
import forge.item.PreconDeck;
|
||||
import forge.quest.ReadPriceList;
|
||||
@@ -57,7 +61,7 @@ import forge.quest.data.QuestData;
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public final class DeckEditorShop extends DeckEditorBase {
|
||||
public final class QuestCardShop extends DeckEditorBase<InventoryItem, Object> {
|
||||
|
||||
/** Constant <code>serialVersionUID=3988857075791576483L</code>. */
|
||||
private static final long serialVersionUID = 3988857075791576483L;
|
||||
@@ -91,7 +95,7 @@ public final class DeckEditorShop extends DeckEditorBase {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
DeckEditorShop.this.dispose();
|
||||
QuestCardShop.this.dispose();
|
||||
exitCommand.execute();
|
||||
}
|
||||
};
|
||||
@@ -115,10 +119,12 @@ public final class DeckEditorShop extends DeckEditorBase {
|
||||
this.questData.getCards().generateCardsInShop();
|
||||
forSale = this.questData.getCards().getShopList();
|
||||
}
|
||||
final ItemPoolView<InventoryItem> owned = this.questData.getCards().getCardpool().getView();
|
||||
// newCardsList = questData.getCards().getNewCards();
|
||||
|
||||
this.setItems(forSale, owned, GameType.Quest);
|
||||
final ItemPool<InventoryItem> ownedItems = new ItemPool<InventoryItem>(InventoryItem.class);
|
||||
ownedItems.addAll(this.questData.getCards().getCardpool().getView());
|
||||
|
||||
getTopTableModel().setDeck(forSale);
|
||||
getBottomTableWithCards().setDeck(ownedItems);
|
||||
|
||||
final double multiPercent = this.multiplier * 100;
|
||||
final NumberFormat formatter = new DecimalFormat("#0.00");
|
||||
@@ -138,13 +144,11 @@ public final class DeckEditorShop extends DeckEditorBase {
|
||||
// fills number of decks using each card
|
||||
private Map<CardPrinted, Integer> countDecksForEachCard() {
|
||||
final Map<CardPrinted, Integer> result = new HashMap<CardPrinted, Integer>();
|
||||
for (final String deckName : this.questData.getDeckNames()) {
|
||||
final Deck deck = this.questData.getDeck(deckName);
|
||||
for (final Deck deck : this.questData.getMyDecks().values()) {
|
||||
for (final Entry<CardPrinted, Integer> e : deck.getMain()) {
|
||||
final CardPrinted card = e.getKey();
|
||||
final Integer iValue = result.get(card);
|
||||
final int cntDecks = iValue == null ? 1 : 1 + iValue.intValue();
|
||||
result.put(card, Integer.valueOf(cntDecks));
|
||||
final Integer amount = result.get(card);
|
||||
result.put(card, Integer.valueOf(amount == null ? 1 : 1 + amount.intValue()));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -200,13 +204,12 @@ public final class DeckEditorShop extends DeckEditorBase {
|
||||
* @param qd
|
||||
* a {@link forge.quest.data.QuestData} object.
|
||||
*/
|
||||
public DeckEditorShop(final QuestData qd) {
|
||||
super(GameType.Quest);
|
||||
public QuestCardShop(final QuestData qd) {
|
||||
this.questData = qd;
|
||||
try {
|
||||
this.setFilterBoxes(null);
|
||||
this.setTopTableWithCards(new TableWithCards("Cards for sale", false));
|
||||
this.setBottomTableWithCards(new TableWithCards("Owned Cards", false));
|
||||
this.setTopTableWithCards(new TableView<InventoryItem>("Cards for sale", false, InventoryItem.class));
|
||||
this.setBottomTableWithCards(new TableView<InventoryItem>("Owned Cards", false, InventoryItem.class));
|
||||
this.setCardView(new CardPanelLite());
|
||||
this.jbInit();
|
||||
} catch (final Exception ex) {
|
||||
@@ -235,14 +238,14 @@ public final class DeckEditorShop extends DeckEditorBase {
|
||||
this.sellButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
DeckEditorShop.this.sellButtonActionPerformed(e);
|
||||
QuestCardShop.this.sellButtonActionPerformed(e);
|
||||
}
|
||||
});
|
||||
this.buyButton.setText("Buy Card");
|
||||
this.buyButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
DeckEditorShop.this.buyButtonActionPerformed(e);
|
||||
QuestCardShop.this.buyButtonActionPerformed(e);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -381,19 +384,19 @@ public final class DeckEditorShop extends DeckEditorBase {
|
||||
private final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnPriceCompare = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return DeckEditorShop.this.getCardValue(from.getKey());
|
||||
return QuestCardShop.this.getCardValue(from.getKey());
|
||||
}
|
||||
};
|
||||
private final Lambda1<Object, Entry<InventoryItem, Integer>> fnPriceGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return DeckEditorShop.this.getCardValue(from.getKey());
|
||||
return QuestCardShop.this.getCardValue(from.getKey());
|
||||
}
|
||||
};
|
||||
private final Lambda1<Object, Entry<InventoryItem, Integer>> fnPriceSellGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return (int) (DeckEditorShop.this.multiplier * DeckEditorShop.this.getCardValue(from.getKey()));
|
||||
return (int) (QuestCardShop.this.multiplier * QuestCardShop.this.getCardValue(from.getKey()));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -401,16 +404,31 @@ public final class DeckEditorShop extends DeckEditorBase {
|
||||
private final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnDeckCompare = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
final Integer iValue = DeckEditorShop.this.decksUsingMyCards.get(from.getKey());
|
||||
final Integer iValue = QuestCardShop.this.decksUsingMyCards.get(from.getKey());
|
||||
return iValue == null ? Integer.valueOf(0) : iValue;
|
||||
}
|
||||
};
|
||||
private final Lambda1<Object, Entry<InventoryItem, Integer>> fnDeckGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
final Integer iValue = DeckEditorShop.this.decksUsingMyCards.get(from.getKey());
|
||||
final Integer iValue = QuestCardShop.this.decksUsingMyCards.get(from.getKey());
|
||||
return iValue == null ? "" : iValue.toString();
|
||||
}
|
||||
};
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.DeckEditorBase#getController()
|
||||
*/
|
||||
@Override
|
||||
public IDeckManager<Object> getController() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.DeckEditorBase#updateView()
|
||||
*/
|
||||
@Override
|
||||
public void updateView() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.gui.deckeditor;
|
||||
package forge.gui.deckeditor.elements;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.gui.deckeditor;
|
||||
package forge.gui.deckeditor.elements;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.io.File;
|
||||
@@ -15,7 +15,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.gui.deckeditor;
|
||||
package forge.gui.deckeditor.elements;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.ActionEvent;
|
||||
@@ -15,7 +15,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.gui.deckeditor;
|
||||
package forge.gui.deckeditor.elements;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
@@ -15,7 +15,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.gui.deckeditor;
|
||||
package forge.gui.deckeditor.elements;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
@@ -15,7 +15,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.gui.deckeditor;
|
||||
package forge.gui.deckeditor.elements;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -32,7 +32,7 @@ import forge.item.CardPrinted;
|
||||
* JPanel to store boxes on Checkboxes are public so the using class should
|
||||
* place them in some container.
|
||||
*/
|
||||
class FilterCheckBoxes {
|
||||
public class FilterCheckBoxes {
|
||||
|
||||
/** The white. */
|
||||
private final JCheckBox white;
|
||||
@@ -15,7 +15,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.gui.deckeditor;
|
||||
package forge.gui.deckeditor.elements;
|
||||
|
||||
import java.awt.event.ItemListener;
|
||||
import java.util.ArrayList;
|
||||
@@ -15,7 +15,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.gui.deckeditor;
|
||||
package forge.gui.deckeditor.elements;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Graphics;
|
||||
@@ -15,7 +15,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.gui.deckeditor;
|
||||
package forge.gui.deckeditor.elements;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.gui.deckeditor;
|
||||
package forge.gui.deckeditor.elements;
|
||||
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.FocusListener;
|
||||
@@ -23,6 +23,7 @@ import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@@ -66,7 +67,7 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
|
||||
|
||||
private final int maxDepth = 3;
|
||||
private final List<Order> orders = new ArrayList<Order>(3);
|
||||
private TableSorterCascade<T> sorter = null;
|
||||
private TableSorterCascade<InventoryItem> sorter = null;
|
||||
private boolean isSorterReady = false;
|
||||
|
||||
private int indexOfColumn(final int column) {
|
||||
@@ -109,14 +110,14 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
|
||||
this.isSorterReady = false;
|
||||
}
|
||||
|
||||
public TableSorterCascade<T> getSorter() {
|
||||
public TableSorterCascade<InventoryItem> getSorter() {
|
||||
if (!this.isSorterReady) {
|
||||
final List<TableSorter<T>> oneColSorters = new ArrayList<TableSorter<T>>(this.maxDepth);
|
||||
final List<TableSorter<InventoryItem>> oneColSorters = new ArrayList<TableSorter<InventoryItem>>(this.maxDepth);
|
||||
for (final Order order : this.orders) {
|
||||
oneColSorters.add(new TableSorter<T>(TableModel.this.columns.get(order.sortColumn).getFnSort(),
|
||||
oneColSorters.add(new TableSorter<InventoryItem>(TableModel.this.columns.get(order.sortColumn).getFnSort(),
|
||||
order.isSortAsc));
|
||||
}
|
||||
this.sorter = new TableSorterCascade<T>(oneColSorters);
|
||||
this.sorter = new TableSorterCascade<InventoryItem>(oneColSorters);
|
||||
}
|
||||
return this.sorter;
|
||||
}
|
||||
@@ -124,7 +125,7 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
|
||||
|
||||
private final ItemPool<T> data;
|
||||
private final CardPanelBase cardDisplay;
|
||||
private final List<TableColumnInfo<T>> columns;
|
||||
private final List<TableColumnInfo<InventoryItem>> columns;
|
||||
private final SortOrders sortOrders = new SortOrders();
|
||||
|
||||
/**
|
||||
@@ -137,7 +138,7 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
|
||||
* @param cls
|
||||
* the cls
|
||||
*/
|
||||
public TableModel(final CardPanelBase cd, final List<TableColumnInfo<T>> columnsToShow, final Class<T> cls) {
|
||||
public TableModel(final CardPanelBase cd, final List<TableColumnInfo<InventoryItem>> columnsToShow, final Class<T> cls) {
|
||||
this.data = new ItemPool<T>(cls);
|
||||
this.cardDisplay = cd;
|
||||
this.columns = columnsToShow;
|
||||
@@ -154,7 +155,7 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
|
||||
TableColumn tableColumn = null;
|
||||
for (int i = 0; i < table.getColumnCount(); i++) {
|
||||
tableColumn = table.getColumnModel().getColumn(i);
|
||||
final TableColumnInfo<T> colInfo = this.columns.get(i);
|
||||
final TableColumnInfo<InventoryItem> colInfo = this.columns.get(i);
|
||||
|
||||
tableColumn.setPreferredWidth(colInfo.getNominalWidth());
|
||||
if (colInfo.isMinMaxApplied()) {
|
||||
@@ -249,7 +250,7 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
|
||||
* the c
|
||||
*/
|
||||
public void addAllCards(final Iterable<T> c) {
|
||||
this.data.addAllCards(c);
|
||||
this.data.addAllFlat(c);
|
||||
this.fireTableDataChanged();
|
||||
}
|
||||
|
||||
@@ -302,9 +303,10 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Object getValueAt(final int row, final int column) {
|
||||
return this.columns.get(column).getFnDisplay().apply(this.rowToCard(row));
|
||||
return this.columns.get(column).getFnDisplay().apply((Entry<InventoryItem, Integer>) this.rowToCard(row));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -414,11 +416,23 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
|
||||
|
||||
} // addCardListener()
|
||||
|
||||
private class MyComparator implements Comparator<Entry<T, Integer>> {
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
TableSorterCascade<InventoryItem> sorter = TableModel.this.sortOrders.getSorter();
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public int compare(Entry<T, Integer> o1, Entry<T, Integer> o2) {
|
||||
return sorter.compare((Entry<InventoryItem, Integer>)o1, (Entry<InventoryItem, Integer>)o2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resort.
|
||||
*/
|
||||
public void resort() {
|
||||
Collections.sort(this.data.getOrderedList(), this.sortOrders.getSorter());
|
||||
Collections.sort(this.data.getOrderedList(), new MyComparator());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -15,7 +15,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.gui.deckeditor;
|
||||
package forge.gui.deckeditor.elements;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Map.Entry;
|
||||
@@ -15,7 +15,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.gui.deckeditor;
|
||||
package forge.gui.deckeditor.elements;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
@@ -15,7 +15,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.gui.deckeditor;
|
||||
package forge.gui.deckeditor.elements;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.List;
|
||||
@@ -41,13 +41,13 @@ import forge.item.ItemPoolView;
|
||||
* TableWithCards.
|
||||
*
|
||||
*/
|
||||
public final class TableWithCards {
|
||||
public final class TableView<T extends InventoryItem> {
|
||||
|
||||
/** The pool. */
|
||||
private ItemPool<InventoryItem> pool;
|
||||
private ItemPool<T> pool;
|
||||
|
||||
/** The model. */
|
||||
private TableModel<InventoryItem> model;
|
||||
private TableModel<T> model;
|
||||
|
||||
/** The table. */
|
||||
private final JTable table = new JTable();
|
||||
@@ -59,7 +59,7 @@ public final class TableWithCards {
|
||||
private final JLabel statsLabel = new JLabel();
|
||||
|
||||
/** The filter. */
|
||||
private Predicate<InventoryItem> filter = null;
|
||||
private Predicate<T> filter = null;
|
||||
|
||||
/** The is tracking stats. */
|
||||
private boolean isTrackingStats = false;
|
||||
@@ -67,6 +67,9 @@ public final class TableWithCards {
|
||||
/** The want unique. */
|
||||
private boolean wantUnique = false;
|
||||
|
||||
|
||||
private final Class<T> genericType;
|
||||
|
||||
// need this to allow users place its contents
|
||||
/**
|
||||
*
|
||||
@@ -107,8 +110,8 @@ public final class TableWithCards {
|
||||
* @param showStats
|
||||
* a boolean
|
||||
*/
|
||||
public TableWithCards(final String title, final boolean showStats) {
|
||||
this(title, showStats, false);
|
||||
public TableView(final String title, final boolean showStats, Class<T> cls) {
|
||||
this(title, showStats, false, cls);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,8 +125,10 @@ public final class TableWithCards {
|
||||
* @param forceUnique
|
||||
* a boolean
|
||||
*/
|
||||
public TableWithCards(final String title, final boolean showStats, final boolean forceUnique) {
|
||||
public TableView(final String title, final boolean showStats, final boolean forceUnique, Class<T> cls) {
|
||||
// components
|
||||
genericType = cls;
|
||||
|
||||
final Color gray = new Color(148, 145, 140);
|
||||
final TitledBorder titledBorder = new TitledBorder(BorderFactory.createEtchedBorder(Color.white, gray), title);
|
||||
|
||||
@@ -150,7 +155,7 @@ public final class TableWithCards {
|
||||
* a CardPanelBase
|
||||
*/
|
||||
public void setup(final List<TableColumnInfo<InventoryItem>> columns, final CardPanelBase cardView) {
|
||||
this.model = new TableModel<InventoryItem>(cardView, columns, InventoryItem.class);
|
||||
this.model = new TableModel<T>(cardView, columns, genericType);
|
||||
this.model.addListeners(this.table);
|
||||
this.table.setModel(this.model);
|
||||
this.model.resizeCols(this.table);
|
||||
@@ -167,8 +172,8 @@ public final class TableWithCards {
|
||||
this.model.addTableModelListener(new TableModelListener() {
|
||||
@Override
|
||||
public void tableChanged(final TableModelEvent ev) {
|
||||
final ItemPoolView<InventoryItem> deck = TableWithCards.this.model.getCards();
|
||||
TableWithCards.this.statsLabel.setText(TableWithCards.getStats(deck));
|
||||
final ItemPoolView<T> deck = TableView.this.model.getCards();
|
||||
TableView.this.statsLabel.setText(TableView.getStats(deck));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -183,7 +188,7 @@ public final class TableWithCards {
|
||||
* an ItemPoolView<InventoryITem>
|
||||
* @return String
|
||||
*/
|
||||
public static String getStats(final ItemPoolView<InventoryItem> deck) {
|
||||
public static <T extends InventoryItem> String getStats(final ItemPoolView<T> deck) {
|
||||
final int total = deck.countAll();
|
||||
final int creature = CardRules.Predicates.Presets.IS_CREATURE.aggregate(deck, deck.getFnToCard(),
|
||||
deck.getFnToCount());
|
||||
@@ -209,7 +214,7 @@ public final class TableWithCards {
|
||||
* an int
|
||||
* @return TableWithCards
|
||||
*/
|
||||
public TableWithCards sort(final int iCol) {
|
||||
public TableView<T> sort(final int iCol) {
|
||||
return this.sort(iCol, true);
|
||||
}
|
||||
|
||||
@@ -223,7 +228,7 @@ public final class TableWithCards {
|
||||
* a boolean
|
||||
* @return TableWithCards
|
||||
*/
|
||||
public TableWithCards sort(final int iCol, final boolean isAsc) {
|
||||
public TableView<T> sort(final int iCol, final boolean isAsc) {
|
||||
this.model.sort(iCol, isAsc);
|
||||
return this;
|
||||
}
|
||||
@@ -255,21 +260,24 @@ public final class TableWithCards {
|
||||
* an Iterable<InventoryITem>
|
||||
*/
|
||||
public void setDeck(final Iterable<InventoryItem> cards) {
|
||||
this.setDeckImpl(ItemPool.createFrom(cards, InventoryItem.class));
|
||||
this.setDeckImpl(ItemPool.createFrom(cards, genericType));
|
||||
}
|
||||
|
||||
/**
|
||||
* setDeck.
|
||||
*
|
||||
* @param <T>
|
||||
* an Object
|
||||
* @param poolView
|
||||
* an ItemPoolView
|
||||
*/
|
||||
public <T extends InventoryItem> void setDeck(final ItemPoolView<T> poolView) {
|
||||
this.setDeckImpl(ItemPool.createFrom(poolView, InventoryItem.class));
|
||||
public void setDeck(final ItemPoolView<T> poolView) {
|
||||
this.setDeckImpl(ItemPool.createFrom(poolView, genericType));
|
||||
}
|
||||
|
||||
public void setDeck(final ItemPool<T> pool) {
|
||||
this.setDeckImpl(pool);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* setDeckImpl.
|
||||
@@ -277,7 +285,7 @@ public final class TableWithCards {
|
||||
* @param thePool
|
||||
* an ItemPool
|
||||
*/
|
||||
protected void setDeckImpl(final ItemPool<InventoryItem> thePool) {
|
||||
protected void setDeckImpl(final ItemPool<T> thePool) {
|
||||
this.model.clear();
|
||||
this.pool = thePool;
|
||||
this.model.addCards(this.pool);
|
||||
@@ -306,7 +314,7 @@ public final class TableWithCards {
|
||||
* @param filterToSet
|
||||
* a Predicate
|
||||
*/
|
||||
public void setFilter(final Predicate<InventoryItem> filterToSet) {
|
||||
public void setFilter(final Predicate<T> filterToSet) {
|
||||
this.filter = filterToSet;
|
||||
this.updateView(true);
|
||||
}
|
||||
@@ -318,7 +326,7 @@ public final class TableWithCards {
|
||||
* @param card
|
||||
* an InventoryItem
|
||||
*/
|
||||
public void addCard(final InventoryItem card) {
|
||||
public void addCard(final T card) {
|
||||
// int n = table.getSelectedRow();
|
||||
this.pool.add(card);
|
||||
if (this.isUnfiltered()) {
|
||||
@@ -334,7 +342,7 @@ public final class TableWithCards {
|
||||
* @param card
|
||||
* an InventoryItem
|
||||
*/
|
||||
public void removeCard(final InventoryItem card) {
|
||||
public void removeCard(final T card) {
|
||||
final int n = this.table.getSelectedRow();
|
||||
this.pool.remove(card);
|
||||
if (this.isUnfiltered()) {
|
||||
@@ -377,7 +385,7 @@ public final class TableWithCards {
|
||||
*
|
||||
* @return ItemPoolView
|
||||
*/
|
||||
public ItemPoolView<InventoryItem> getCards() {
|
||||
public ItemPoolView<T> getCards() {
|
||||
return this.pool;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
/** Forge Card Game. */
|
||||
package forge.gui.deckeditor.elements;
|
||||
|
||||
9
src/main/java/forge/item/IHasName.java
Normal file
9
src/main/java/forge/item/IHasName.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package forge.item;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public interface IHasName {
|
||||
String getName();
|
||||
}
|
||||
@@ -21,7 +21,7 @@ package forge.item;
|
||||
* Interface to define a player's inventory may hold. Should include
|
||||
* CardPrinted, Booster, Pets, Plants... etc
|
||||
*/
|
||||
public interface InventoryItem {
|
||||
public interface InventoryItem extends IHasName {
|
||||
|
||||
/**
|
||||
* An inventory item has to provide a name.
|
||||
|
||||
@@ -152,7 +152,7 @@ public class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
|
||||
* a Iterable<U>
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <U extends InventoryItem> void addAllCards(final Iterable<U> cards) {
|
||||
public <U extends InventoryItem> void addAllFlat(final Iterable<U> cards) {
|
||||
for (final U cr : cards) {
|
||||
if (this.getMyClass().isInstance(cr)) {
|
||||
this.add((T) cr);
|
||||
@@ -171,8 +171,9 @@ public class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <U extends InventoryItem> void addAll(final Iterable<Entry<U, Integer>> map) {
|
||||
Class<T> myClass = this.getMyClass();
|
||||
for (final Entry<U, Integer> e : map) {
|
||||
if (this.getMyClass().isInstance(e.getKey())) {
|
||||
if (myClass.isInstance(e.getKey())) {
|
||||
this.add((T) e.getKey(), e.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
||||
* a Class<T>
|
||||
*/
|
||||
public ItemPoolView(final Class<T> cls) {
|
||||
this.setCards(new Hashtable<T, Integer>());
|
||||
this.cards = new Hashtable<T, Integer>();
|
||||
this.myClass = cls;
|
||||
}
|
||||
|
||||
@@ -97,13 +97,13 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
||||
* a Class<T>
|
||||
*/
|
||||
public ItemPoolView(final Map<T, Integer> inMap, final Class<T> cls) {
|
||||
this.setCards(inMap);
|
||||
this.cards = inMap;
|
||||
this.myClass = cls;
|
||||
}
|
||||
|
||||
// Data members
|
||||
/** The cards. */
|
||||
private Map<T, Integer> cards;
|
||||
private final Map<T, Integer> cards;
|
||||
|
||||
/** The my class. */
|
||||
private final Class<T> myClass; // class does not keep this in runtime by
|
||||
@@ -257,20 +257,10 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
||||
*
|
||||
* @return the cards
|
||||
*/
|
||||
public Map<T, Integer> getCards() {
|
||||
protected Map<T, Integer> getCards() {
|
||||
return this.cards;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cards.
|
||||
*
|
||||
* @param cards0
|
||||
* the cards to set
|
||||
*/
|
||||
public void setCards(final Map<T, Integer> cards0) {
|
||||
this.cards = cards0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the my class.
|
||||
*
|
||||
@@ -295,7 +285,7 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
||||
* @param isListInSync0
|
||||
* the isListInSync to set
|
||||
*/
|
||||
public void setListInSync(final boolean isListInSync0) {
|
||||
protected void setListInSync(final boolean isListInSync0) {
|
||||
this.isListInSync = isListInSync0;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.Map;
|
||||
|
||||
import forge.SetUtils;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckIO;
|
||||
import forge.deck.io.DeckIOCore;
|
||||
import forge.quest.SellRules;
|
||||
import forge.util.FileUtil;
|
||||
import forge.util.SectionUtil;
|
||||
@@ -80,7 +80,7 @@ public class PreconDeck implements InventoryItemFromSet {
|
||||
public PreconDeck(final File f) {
|
||||
final List<String> deckLines = FileUtil.readFile(f);
|
||||
final Map<String, List<String>> sections = SectionUtil.parseSections(deckLines);
|
||||
this.deck = DeckIO.readDeck(deckLines);
|
||||
this.deck = DeckIOCore.readDeck(deckLines);
|
||||
|
||||
String filenameProxy = null;
|
||||
String setProxy = "n/a";
|
||||
|
||||
@@ -30,6 +30,7 @@ import forge.error.ErrorViewer;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.ItemPool;
|
||||
import forge.item.ItemPoolView;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
import forge.quest.data.QuestPreferences.QPref;
|
||||
@@ -114,11 +115,11 @@ public final class QuestData {
|
||||
|
||||
// Decks collected by player
|
||||
/** The my decks. */
|
||||
private Map<String, Deck> myDecks = new HashMap<String, Deck>();
|
||||
private final Map<String, Deck> myDecks = new HashMap<String, Deck>();
|
||||
|
||||
// Cards associated with quest
|
||||
/** The card pool. */
|
||||
private ItemPool<InventoryItem> cardPool = new ItemPool<InventoryItem>(InventoryItem.class); // player's
|
||||
private ItemPool<CardPrinted> cardPool = new ItemPool<CardPrinted>(CardPrinted.class); // player's
|
||||
// belonging
|
||||
/** The shop list. */
|
||||
private ItemPool<InventoryItem> shopList = new ItemPool<InventoryItem>(InventoryItem.class); // the
|
||||
@@ -195,9 +196,9 @@ public final class QuestData {
|
||||
this.initTransients();
|
||||
this.setName(s0);
|
||||
|
||||
this.myCards.addBasicLands(this.getCardPool(),
|
||||
Singletons.getModel().getQuestPreferences().getPreferenceInt(QPref.STARTING_BASIC_LANDS),
|
||||
Singletons.getModel().getQuestPreferences().getPreferenceInt(QPref.STARTING_BASIC_LANDS));
|
||||
QuestPreferences prefs = Singletons.getModel().getQuestPreferences();
|
||||
ItemPoolView<CardPrinted> lands = QuestUtilCards.generateBasicLands( prefs.getPreferenceInt(QPref.STARTING_BASIC_LANDS), prefs.getPreferenceInt(QPref.STARTING_BASIC_LANDS) );
|
||||
this.getCardPool().addAll(lands);
|
||||
this.randomizeOpponents();
|
||||
}
|
||||
|
||||
@@ -546,14 +547,7 @@ public final class QuestData {
|
||||
return this.winstreakCurrent;
|
||||
}
|
||||
// decks management
|
||||
/**
|
||||
* Gets the deck names.
|
||||
*
|
||||
* @return the deck names
|
||||
*/
|
||||
public List<String> getDeckNames() {
|
||||
return new ArrayList<String>(this.getMyDecks().keySet());
|
||||
}
|
||||
|
||||
|
||||
/** @return List<Deck> */
|
||||
public List<Deck> getDecks() {
|
||||
@@ -570,16 +564,6 @@ public final class QuestData {
|
||||
this.getMyDecks().remove(deckName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the deck.
|
||||
*
|
||||
* @param d
|
||||
* the d
|
||||
*/
|
||||
public void addDeck(final Deck d) {
|
||||
this.getMyDecks().put(d.getName(), d);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getDeck.
|
||||
@@ -593,6 +577,7 @@ public final class QuestData {
|
||||
if (!this.getMyDecks().containsKey(deckName)) {
|
||||
ErrorViewer.showError(new Exception(),
|
||||
"QuestData : getDeckFromMap(String deckName) error, deck name not found - %s", deckName);
|
||||
return null;
|
||||
}
|
||||
final Deck d = this.getMyDecks().get(deckName);
|
||||
d.getSideboard().clear();
|
||||
@@ -641,19 +626,10 @@ public final class QuestData {
|
||||
*
|
||||
* @return the cardPool
|
||||
*/
|
||||
public ItemPool<InventoryItem> getCardPool() {
|
||||
public ItemPool<CardPrinted> getCardPool() {
|
||||
return this.cardPool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the card pool.
|
||||
*
|
||||
* @param cardPool0
|
||||
* the cardPool to set
|
||||
*/
|
||||
public void setCardPool(final ItemPool<InventoryItem> cardPool0) {
|
||||
this.cardPool = cardPool0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the shop list.
|
||||
@@ -702,15 +678,6 @@ public final class QuestData {
|
||||
return this.myDecks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the my decks.
|
||||
*
|
||||
* @param myDecks0
|
||||
* the myDecks to set
|
||||
*/
|
||||
public void setMyDecks(final Map<String, Deck> myDecks0) {
|
||||
this.myDecks = myDecks0;
|
||||
}
|
||||
|
||||
/** @return QuestPreconManager */
|
||||
public static QuestPreconManager getPreconManager() {
|
||||
|
||||
@@ -258,7 +258,7 @@ public class QuestDataIO {
|
||||
@Override
|
||||
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
|
||||
final String value = reader.getValue();
|
||||
return GameType.smartValueOf(value);
|
||||
return GameType.smartValueOf(value, GameType.Quest); // does not matter - this field is deprecated anyway
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,7 +25,8 @@ import java.util.Random;
|
||||
|
||||
import forge.AllZone;
|
||||
import forge.Singletons;
|
||||
import forge.deck.DeckIO;
|
||||
import forge.deck.io.DeckIOCore;
|
||||
import forge.deck.io.DeckSerializer;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
import forge.quest.data.QuestPreferences.QPref;
|
||||
@@ -80,7 +81,7 @@ public class QuestEventManager {
|
||||
List<String> contents;
|
||||
QuestEvent tempEvent;
|
||||
|
||||
final File[] allFiles = ForgeProps.getFile(NewConstants.Quest.DECKS).listFiles(DeckIO.DCK_FILE_FILTER);
|
||||
final File[] allFiles = ForgeProps.getFile(NewConstants.Quest.DECKS).listFiles(DeckSerializer.DCK_FILE_FILTER);
|
||||
|
||||
for (final File f : allFiles) {
|
||||
contents = FileUtil.readFile(f);
|
||||
@@ -98,7 +99,7 @@ public class QuestEventManager {
|
||||
|
||||
// Assemble metadata (may not be necessary later) and deck object.
|
||||
this.assembleEventMetadata(contents, tempEvent);
|
||||
tempEvent.setEventDeck(DeckIO.readDeck(contents));
|
||||
tempEvent.setEventDeck(DeckIOCore.readDeck(contents));
|
||||
} // End for(allFiles)
|
||||
|
||||
this.assembleDuelDifficultyLists();
|
||||
|
||||
@@ -26,7 +26,7 @@ import javax.swing.JOptionPane;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.deck.DeckIO;
|
||||
import forge.deck.io.DeckSerializer;
|
||||
import forge.item.PreconDeck;
|
||||
|
||||
/**
|
||||
@@ -45,7 +45,7 @@ public class QuestPreconManager {
|
||||
*/
|
||||
public QuestPreconManager(final File deckDir) {
|
||||
final List<String> decksThatFailedToLoad = new ArrayList<String>();
|
||||
final File[] files = deckDir.listFiles(DeckIO.DCK_FILE_FILTER);
|
||||
final File[] files = deckDir.listFiles(DeckSerializer.DCK_FILE_FILTER);
|
||||
for (final File file : files) {
|
||||
try {
|
||||
this.decks.add(new PreconDeck(file));
|
||||
|
||||
@@ -69,8 +69,9 @@ public final class QuestUtilCards {
|
||||
* @param nSnow
|
||||
* the n snow
|
||||
*/
|
||||
public void addBasicLands(final ItemPool<InventoryItem> pool, final int nBasic, final int nSnow) {
|
||||
public static ItemPoolView<CardPrinted> generateBasicLands(final int nBasic, final int nSnow) {
|
||||
final CardDb db = CardDb.instance();
|
||||
ItemPool<CardPrinted> pool = new ItemPool<CardPrinted>(CardPrinted.class);
|
||||
pool.add(db.getCard("Forest", "M10"), nBasic);
|
||||
pool.add(db.getCard("Mountain", "M10"), nBasic);
|
||||
pool.add(db.getCard("Swamp", "M10"), nBasic);
|
||||
@@ -82,6 +83,7 @@ public final class QuestUtilCards {
|
||||
pool.add(db.getCard("Snow-Covered Swamp", "ICE"), nSnow);
|
||||
pool.add(db.getCard("Snow-Covered Island", "ICE"), nSnow);
|
||||
pool.add(db.getCard("Snow-Covered Plains", "ICE"), nSnow);
|
||||
return pool;
|
||||
}
|
||||
|
||||
// adds 11 cards, to the current card pool
|
||||
@@ -221,7 +223,7 @@ public final class QuestUtilCards {
|
||||
if (this.q.getCredits() >= value) {
|
||||
this.q.setCredits(this.q.getCredits() - value);
|
||||
this.q.getShopList().remove(precon);
|
||||
this.q.addDeck(precon.getDeck());
|
||||
this.q.getMyDecks().put(precon.getDeck().getName(), precon.getDeck());
|
||||
this.addAllCards(precon.getDeck().getMain().toFlatList());
|
||||
}
|
||||
}
|
||||
@@ -340,7 +342,7 @@ public final class QuestUtilCards {
|
||||
final int rollD100 = MyRandom.getRandom().nextInt(100);
|
||||
final Predicate<CardSet> filter = rollD100 < 40 ? this.filterT2booster
|
||||
: (rollD100 < 75 ? this.filterExtButT2 : this.filterNotExt);
|
||||
this.q.getShopList().addAllCards(filter.random(SetUtils.getAllSets(), 1, BoosterPack.FN_FROM_SET));
|
||||
this.q.getShopList().addAllFlat(filter.random(SetUtils.getAllSets(), 1, BoosterPack.FN_FROM_SET));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -352,7 +354,7 @@ public final class QuestUtilCards {
|
||||
*/
|
||||
public void generatePreconsInShop(final int count) {
|
||||
final List<PreconDeck> validDecks = QuestData.getPreconManager().getDecksForCurrent(this.q);
|
||||
this.q.getShopList().addAllCards(Predicate.getTrue(PreconDeck.class).random(validDecks, count));
|
||||
this.q.getShopList().addAllFlat(Predicate.getTrue(PreconDeck.class).random(validDecks, count));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -376,13 +378,12 @@ public final class QuestUtilCards {
|
||||
|
||||
this.q.getShopList().clear();
|
||||
for (int i = 0; i < totalPacks; i++) {
|
||||
this.q.getShopList().addAllCards(pack.getBoosterPack(common, uncommon, rare, 0, 0, 0, 0, 0, 0));
|
||||
this.q.getShopList().addAllFlat(pack.getBoosterPack(common, uncommon, rare, 0, 0, 0, 0, 0, 0));
|
||||
}
|
||||
|
||||
this.generateBoostersInShop(totalPacks);
|
||||
this.generatePreconsInShop(totalPacks);
|
||||
|
||||
this.addBasicLands(this.q.getShopList(), 10, 5);
|
||||
this.q.getShopList().addAll(QuestUtilCards.generateBasicLands(10, 5));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -390,7 +391,7 @@ public final class QuestUtilCards {
|
||||
*
|
||||
* @return the cardpool
|
||||
*/
|
||||
public ItemPool<InventoryItem> getCardpool() {
|
||||
public ItemPool<CardPrinted> getCardpool() {
|
||||
return this.q.getCardPool();
|
||||
}
|
||||
|
||||
|
||||
@@ -147,11 +147,12 @@ public final class FileUtil {
|
||||
while ((line = in.readLine()) != null) {
|
||||
list.add(line);
|
||||
}
|
||||
in.close();
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("FileUtil : readFile() error, " + ex);
|
||||
}
|
||||
|
||||
|
||||
return list;
|
||||
} // readFile()
|
||||
|
||||
|
||||
@@ -85,11 +85,11 @@ public class SectionUtil {
|
||||
* @param lines the lines
|
||||
* @return the map
|
||||
*/
|
||||
public static Map<String, String> parseKvPairs(final List<String> lines) {
|
||||
public static Map<String, String> parseKvPairs(final List<String> lines, String separator ) {
|
||||
final Map<String, String> result = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
for (final String dd : lines) {
|
||||
final String[] v = dd.split(":", 2);
|
||||
final String[] v = dd.split(separator, 2);
|
||||
result.put(v[0], v.length > 1 ? v[1].trim() : "");
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ import forge.control.home.ControlConstructed;
|
||||
import forge.control.home.ControlDraft;
|
||||
import forge.control.home.ControlSealed;
|
||||
import forge.control.home.ControlUtilities;
|
||||
import forge.game.GameType;
|
||||
import forge.properties.ForgePreferences;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
import forge.view.home.ViewConstructed;
|
||||
@@ -137,7 +138,7 @@ public class ViewHomeUI extends FPanel {
|
||||
btnDeckEditor = new FButton();
|
||||
btnDeckEditor.setAction(new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
ViewHomeUI.this.getUtilitiesController().showDeckEditor(null, null);
|
||||
ViewHomeUI.this.getUtilitiesController().showDeckEditor(GameType.Constructed, null);
|
||||
}
|
||||
});
|
||||
btnDeckEditor.setText("Deck Editor");
|
||||
|
||||
@@ -5,7 +5,6 @@ import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -23,10 +22,9 @@ import forge.Command;
|
||||
import forge.Constant;
|
||||
import forge.Singletons;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckIO;
|
||||
import forge.deck.DeckManager;
|
||||
import forge.game.GameType;
|
||||
import forge.gui.deckeditor.DeckEditorCommon;
|
||||
import forge.gui.deckeditor.DeckEditorConstructed;
|
||||
import forge.gui.deckeditor.DeckEditorLimited;
|
||||
import forge.gui.deckeditor.DeckEditorQuest;
|
||||
|
||||
/**
|
||||
@@ -82,7 +80,7 @@ public class DeckLister extends JPanel {
|
||||
}
|
||||
|
||||
/** @param decks0 {@link forge.deck.Deck}[] */
|
||||
public void setDecks(Deck[] decks0) {
|
||||
public void setDecks(Iterable<Deck> decks0) {
|
||||
this.removeAll();
|
||||
List<RowPanel> tempRows = new ArrayList<RowPanel>();
|
||||
|
||||
@@ -355,17 +353,31 @@ public class DeckLister extends JPanel {
|
||||
}
|
||||
|
||||
private void editDeck(Deck d0) {
|
||||
if (gametype == GameType.Quest) {
|
||||
switch(gametype) {
|
||||
case Quest:
|
||||
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.setVisible(true);
|
||||
break;
|
||||
case Constructed:
|
||||
final DeckEditorConstructed cEditor = new DeckEditorConstructed();
|
||||
cEditor.show(cmdEditorExit);
|
||||
cEditor.getController().load(d0.getName());
|
||||
cEditor.setVisible(true);
|
||||
break;
|
||||
case Sealed:
|
||||
final DeckEditorLimited sEditor = new DeckEditorLimited(AllZone.getDecks().getSealed());
|
||||
sEditor.show(cmdEditorExit);
|
||||
sEditor.getController().load(d0.getName());
|
||||
sEditor.setVisible(true);
|
||||
break;
|
||||
case Draft:
|
||||
final DeckEditorLimited dEditor = new DeckEditorLimited(AllZone.getDecks().getDraft());
|
||||
dEditor.show(cmdEditorExit);
|
||||
dEditor.getController().load(d0.getName());
|
||||
dEditor.setVisible(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -380,30 +392,11 @@ public class DeckLister extends JPanel {
|
||||
return;
|
||||
}
|
||||
|
||||
DeckManager deckmanager = AllZone.getDeckManager();
|
||||
|
||||
if (gametype.equals(GameType.Draft)) {
|
||||
deckmanager.deleteDraftDeck(d0.getName());
|
||||
|
||||
// Since draft deck files are really directories, must delete all children first.
|
||||
File dir = DeckIO.makeFileName(d0.getName(), GameType.Draft);
|
||||
String[] children = dir.list();
|
||||
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
new File(dir.getAbsolutePath() + File.separator + children[i]).delete();
|
||||
}
|
||||
|
||||
dir.delete();
|
||||
AllZone.getDecks().getDraft().delete(d0.getName());
|
||||
}
|
||||
else if (gametype.equals(GameType.Sealed)) {
|
||||
deckmanager.deleteDeck(d0.getName());
|
||||
|
||||
File address1 = DeckIO.makeFileName(d0.getName(), GameType.Sealed);
|
||||
File address2 = DeckIO.makeFileName("AI_" + d0.getName(), GameType.Sealed);
|
||||
|
||||
// not working??!!
|
||||
address1.delete();
|
||||
address2.delete();
|
||||
AllZone.getDecks().getSealed().delete(d0.getName());
|
||||
}
|
||||
else if (gametype.equals(GameType.Quest)) {
|
||||
AllZone.getQuestData().removeDeck(d0.getName());
|
||||
@@ -411,10 +404,7 @@ public class DeckLister extends JPanel {
|
||||
Singletons.getView().getHomeView().getBtnQuest().grabFocus();
|
||||
}
|
||||
else {
|
||||
deckmanager.deleteDeck(d0.getName());
|
||||
|
||||
File address1 = DeckIO.makeFileName(d0.getName(), GameType.Constructed);
|
||||
address1.delete();
|
||||
AllZone.getDecks().getConstructed().delete(d0.getName());
|
||||
}
|
||||
|
||||
this.remove(r0);
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
package forge;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import forge.deck.Deck;
|
||||
import forge.game.GameType;
|
||||
import forge.game.limited.BoosterDraft;
|
||||
import forge.game.limited.CardPoolLimitation;
|
||||
import forge.gui.deckeditor.DeckEditorDraft;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA. User: dhudson
|
||||
*/
|
||||
@Test(groups = { "UnitTest" }, enabled = false)
|
||||
public class GuiBoosterDraftTest {
|
||||
|
||||
/**
|
||||
* Gui booster draft test1.
|
||||
*/
|
||||
@Test(groups = { "UnitTest", "fast" }, enabled = false)
|
||||
public void guiBoosterDraftTest1() {
|
||||
Constant.Runtime.setGameType(GameType.Draft);
|
||||
Constant.Runtime.HUMAN_DECK[0] = new Deck(GameType.Sealed);
|
||||
|
||||
final DeckEditorDraft g = new DeckEditorDraft();
|
||||
g.showGui(new BoosterDraft(CardPoolLimitation.Full));
|
||||
Assert.assertNotNull(g);
|
||||
g.dispose();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user