Now 'new' is present in quest deckbuider too.

This commit is contained in:
Maxmtg
2011-09-04 11:49:14 +00:00
parent 5428c2a8f5
commit 96556ebfa0
5 changed files with 55 additions and 50 deletions

View File

@@ -1,6 +1,5 @@
package forge.gui.deckeditor; package forge.gui.deckeditor;
import forge.AllZone;
import forge.Command; import forge.Command;
import forge.Constant; import forge.Constant;
import forge.card.CardPool; import forge.card.CardPool;
@@ -10,15 +9,25 @@ import forge.deck.Deck;
import forge.error.ErrorViewer; import forge.error.ErrorViewer;
import forge.gui.GuiUtils; import forge.gui.GuiUtils;
import forge.properties.NewConstants; import forge.properties.NewConstants;
import forge.quest.data.QuestData;
import forge.view.swing.OldGuiNewGame; import forge.view.swing.OldGuiNewGame;
import javax.swing.*;
import java.awt.*; import java.awt.Font;
import java.awt.event.*; import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
//import forge.quest.data.QuestBoosterPack; //import forge.quest.data.QuestBoosterPack;
/** /**
@@ -41,9 +50,10 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
private JButton addButton = new JButton(); private JButton addButton = new JButton();
private JButton removeButton = new JButton(); private JButton removeButton = new JButton();
private JButton analysisButton = new JButton(); private JButton analysisButton = new JButton();
private JLabel labelSortHint = new JLabel(); private JLabel labelSortHint = new JLabel();
private QuestData questData;
public void show(final Command exitCommand) { public void show(final Command exitCommand) {
final Command exit = new Command() { final Command exit = new Command() {
@@ -58,17 +68,16 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
// do not change this!!!! // do not change this!!!!
this.addWindowListener(new WindowAdapter() { this.addWindowListener(new WindowAdapter() {
@Override @Override
public void windowClosing(WindowEvent ev) { public void windowClosing(final WindowEvent ev) {
customMenu.close(); customMenu.close();
} }
}); });
setup(); setup();
customMenu = new DeckEditorQuestMenu(this, exit); customMenu = new DeckEditorQuestMenu(questData, this, exit);
this.setJMenuBar(customMenu); this.setJMenuBar(customMenu);
forge.quest.data.QuestData questData = AllZone.getQuestData();
Deck deck = null; Deck deck = null;
// open deck that the player used if QuestData has it // open deck that the player used if QuestData has it
@@ -85,7 +94,7 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
CardPoolView bottomPool = deck.getMain(); CardPoolView bottomPool = deck.getMain();
CardPool cardpool = new CardPool(); CardPool cardpool = new CardPool();
cardpool.addAll(AllZone.getQuestData().getCards().getCardpool()); cardpool.addAll(questData.getCards().getCardpool());
// remove bottom cards that are in the deck from the card pool // remove bottom cards that are in the deck from the card pool
cardpool.removeAll(bottomPool); cardpool.removeAll(bottomPool);
@@ -98,7 +107,7 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
top.sort(3, true);// then sort by color top.sort(3, true);// then sort by color
bottom.sort(1, true); bottom.sort(1, true);
}// show(Command) } // show(Command)
/** /**
@@ -116,6 +125,7 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
columns.add(new TableColumnInfo<CardPrinted>("Stats", 40, PresetColumns.fnStatsCompare, PresetColumns.fnStatsGet)); columns.add(new TableColumnInfo<CardPrinted>("Stats", 40, PresetColumns.fnStatsCompare, PresetColumns.fnStatsGet));
columns.add(new TableColumnInfo<CardPrinted>("R", 35, PresetColumns.fnRarityCompare, PresetColumns.fnRarityGet)); columns.add(new TableColumnInfo<CardPrinted>("R", 35, PresetColumns.fnRarityCompare, PresetColumns.fnRarityGet));
columns.add(new TableColumnInfo<CardPrinted>("Set", 40, PresetColumns.fnSetCompare, PresetColumns.fnSetGet)); columns.add(new TableColumnInfo<CardPrinted>("Set", 40, PresetColumns.fnSetCompare, PresetColumns.fnSetGet));
columns.add(new TableColumnInfo<CardPrinted>("New", 30, questData.getCards().fnNewCompare, questData.getCards().fnNewGet));
// Add NEW column here // Add NEW column here
top.setup(columns, cardView); top.setup(columns, cardView);
@@ -131,7 +141,8 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
// setExtendedState(Frame.MAXIMIZED_BOTH); // setExtendedState(Frame.MAXIMIZED_BOTH);
} // setupAndDisplay() } // setupAndDisplay()
public DeckEditorQuest() { public DeckEditorQuest(QuestData questData2) {
questData = questData2;
try { try {
filterBoxes = new FilterCheckBoxes(false); filterBoxes = new FilterCheckBoxes(false);
top = new TableWithCards("All Cards", true); top = new TableWithCards("All Cards", true);
@@ -155,14 +166,14 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
if (!OldGuiNewGame.useLAFFonts.isSelected()) if (!OldGuiNewGame.useLAFFonts.isSelected())
removeButton.setFont(new java.awt.Font("Dialog", 0, 13)); removeButton.setFont(new java.awt.Font("Dialog", 0, 13));
removeButton.setText("Remove Card"); removeButton.setText("Remove Card");
removeButton.addActionListener(new java.awt.event.ActionListener() { removeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(final ActionEvent e) {
removeButtonActionPerformed(e); removeButtonActionPerformed(e);
} }
}); });
addButton.setText("Add Card"); addButton.setText("Add Card");
addButton.addActionListener(new java.awt.event.ActionListener() { addButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(final ActionEvent e) {
addButtonActionPerformed(e); addButtonActionPerformed(e);
} }
}); });
@@ -172,8 +183,8 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
addButton.setBounds(new Rectangle(23, 403, 146, 49)); addButton.setBounds(new Rectangle(23, 403, 146, 49));
analysisButton.setText("Deck Analysis"); analysisButton.setText("Deck Analysis");
analysisButton.addActionListener(new java.awt.event.ActionListener() { analysisButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(final ActionEvent e) {
analysisButton_actionPerformed(e); analysisButton_actionPerformed(e);
} }
}); });
@@ -276,9 +287,9 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
} }
public void addCheatCard(CardPrinted card) { public void addCheatCard(final CardPrinted card) {
top.addCard(card); top.addCard(card);
AllZone.getQuestData().getCards().getCardpool().add(card); questData.getCards().getCardpool().add(card);
} }
} }

View File

@@ -1,7 +1,6 @@
package forge.gui.deckeditor; package forge.gui.deckeditor;
import forge.AllZone;
import forge.Command; import forge.Command;
import forge.Constant; import forge.Constant;
import forge.card.CardRules; import forge.card.CardRules;
@@ -14,6 +13,7 @@ import forge.deck.DeckManager;
import forge.error.ErrorViewer; import forge.error.ErrorViewer;
import forge.gui.GuiUtils; import forge.gui.GuiUtils;
import forge.gui.ListChooser; import forge.gui.ListChooser;
import forge.quest.data.QuestData;
import javax.swing.*; import javax.swing.*;
import javax.swing.filechooser.FileFilter; import javax.swing.filechooser.FileFilter;
@@ -44,10 +44,6 @@ public class DeckEditorQuestMenu extends JMenuBar {
/** Constant <code>serialVersionUID=-4052319220021158574L</code>. */ /** Constant <code>serialVersionUID=-4052319220021158574L</code>. */
private static final long serialVersionUID = -4052319220021158574L; private static final long serialVersionUID = -4052319220021158574L;
//this should be false in the public version
//if true, the Quest Deck editor will let you edit the computer's decks
private final boolean canEditComputerDecks;
/** Constant <code>deckEditorName="Deck Editor"</code>. */ /** Constant <code>deckEditorName="Deck Editor"</code>. */
private static final String deckEditorName = "Deck Editor"; private static final String deckEditorName = "Deck Editor";
@@ -69,21 +65,12 @@ public class DeckEditorQuestMenu extends JMenuBar {
* @param d a {@link forge.gui.deckeditor.DeckDisplay} object. * @param d a {@link forge.gui.deckeditor.DeckDisplay} object.
* @param exit a {@link forge.Command} object. * @param exit a {@link forge.Command} object.
*/ */
public DeckEditorQuestMenu(final DeckDisplay d, final Command exit) { public DeckEditorQuestMenu(QuestData q, final DeckDisplay d, final Command exit) {
//is a file named "edit" in this directory
//lame but it works, I don't like 2 versions of Forge floating around
//one that lets you edit the AI decks and one that doesn't
File f = new File("edit");
if (f.exists()) {
canEditComputerDecks = true;
} else {
canEditComputerDecks = false;
}
deckDisplay = d; deckDisplay = d;
d.setTitle(deckEditorName); questData = q;
questData = AllZone.getQuestData(); d.setTitle(deckEditorName);
exitCommand = exit; exitCommand = exit;

View File

@@ -142,7 +142,7 @@ public final class DeckEditorShop extends DeckEditorBase {
top.setup(columns, cardView); top.setup(columns, cardView);
columnsBelow.add(new TableColumnInfo<CardPrinted>("#Dk", 30, fnDeckCompare, fnDeckGet)); columnsBelow.add(new TableColumnInfo<CardPrinted>("#Dk", 30, fnDeckCompare, fnDeckGet));
columnsBelow.add(new TableColumnInfo<CardPrinted>("New", 30, fnNewCompare, fnNewGet)); columnsBelow.add(new TableColumnInfo<CardPrinted>("New", 30, questData.getCards().fnNewCompare, questData.getCards().fnNewGet));
columnsBelow.add(new TableColumnInfo<CardPrinted>("Price", 40, fnPriceCompare, fnPriceGet)); columnsBelow.add(new TableColumnInfo<CardPrinted>("Price", 40, fnPriceCompare, fnPriceGet));
bottom.setup(columnsBelow, cardView); bottom.setup(columnsBelow, cardView);
@@ -304,15 +304,5 @@ public final class DeckEditorShop extends DeckEditorBase {
return iValue == null ? "" : iValue.toString(); return iValue == null ? "" : iValue.toString();
} }; } };
@SuppressWarnings("rawtypes")
private final Lambda1<Comparable, Entry<CardPrinted, Integer>> fnNewCompare =
new Lambda1<Comparable, Entry<CardPrinted, Integer>>() { @Override
public Comparable apply(final Entry<CardPrinted, Integer> from) {
return newCardsList.contains(from.getKey()) ? Integer.valueOf(1) : Integer.valueOf(0);
} };
private final Lambda1<Object, Entry<CardPrinted, Integer>> fnNewGet =
new Lambda1<Object, Entry<CardPrinted, Integer>>() { @Override
public Object apply(final Entry<CardPrinted, Integer> from) {
return newCardsList.contains(from.getKey()) ? "NEW" : "";
} };
} }

View File

@@ -2,7 +2,9 @@ package forge.quest.data;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map.Entry;
import net.slightlymagic.braids.util.lambda.Lambda1;
import net.slightlymagic.maxmtg.Predicate; import net.slightlymagic.maxmtg.Predicate;
import forge.ReadBoosterPack; import forge.ReadBoosterPack;
@@ -168,4 +170,19 @@ public final class QuestUtilCards {
public void resetNewList() { public void resetNewList() {
q.newCardList.clear(); q.newCardList.clear();
} }
// These functions provide a way to sort and compare cards in a table according to their new-ness
// It might be a good idea to store them in a base class for both quest-mode deck editors
// Maybe we should consider doing so later
@SuppressWarnings("rawtypes")
public final Lambda1<Comparable, Entry<CardPrinted, Integer>> fnNewCompare =
new Lambda1<Comparable, Entry<CardPrinted, Integer>>() { @Override
public Comparable apply(final Entry<CardPrinted, Integer> from) {
return q.newCardList.contains(from.getKey()) ? Integer.valueOf(1) : Integer.valueOf(0);
} };
public final Lambda1<Object, Entry<CardPrinted, Integer>> fnNewGet =
new Lambda1<Object, Entry<CardPrinted, Integer>>() { @Override
public Object apply(final Entry<CardPrinted, Integer> from) {
return q.newCardList.contains(from.getKey()) ? "NEW" : "";
} };
} }

View File

@@ -590,7 +590,7 @@ public class QuestMainPanel extends QuestAbstractPanel {
} }
}; };
DeckEditorQuest g = new DeckEditorQuest(); DeckEditorQuest g = new DeckEditorQuest(AllZone.getQuestData());
g.show(exit); g.show(exit);
g.setVisible(true); g.setVisible(true);