mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
Deckeditors use a unified component for TableWithCards, sorting issues fixed
This commit is contained in:
13
.gitattributes
vendored
13
.gitattributes
vendored
@@ -9769,24 +9769,25 @@ 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/CardColumnPresets.java -text
|
||||
src/main/java/forge/gui/deckeditor/CardDisplay.java -text
|
||||
src/main/java/forge/gui/deckeditor/CardShop.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/deckeditor/CardViewPanel.java -text
|
||||
src/main/java/forge/gui/deckeditor/CardViewPanelLite.java -text
|
||||
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/DeckDisplay.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/deckeditor/DeckEditor.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/deckeditor/DeckEditorBase.java -text
|
||||
src/main/java/forge/gui/deckeditor/DeckEditorDraft.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/deckeditor/DeckEditorMenu.java svneol=native#text/plain
|
||||
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/FilterCheckBoxes.java -text
|
||||
src/main/java/forge/gui/deckeditor/GuiFilterCheckBox.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/deckeditor/Gui_BoosterDraft.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/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
|
||||
|
||||
@@ -235,38 +235,6 @@ public class CardFilter {
|
||||
return listFilter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter a sequence Generator of cards by rarity.
|
||||
*
|
||||
* @param inputGenerator the sequence to filter (at a later time); must
|
||||
* not be null
|
||||
*
|
||||
* @param rarity a valid value for Card.getSVar("Rarity"); must not be
|
||||
* null. If equal to Constant.Rarity.Rare, the result will also contain
|
||||
* mythic cards.
|
||||
*
|
||||
* @return a sequence Generator whose cards only have the given rarity
|
||||
*/
|
||||
public static Generator<Card> getRarity(final Generator<Card> inputGenerator, final String rarity) {
|
||||
UtilFunctions.checkNotNull("inputGenerator", inputGenerator);
|
||||
UtilFunctions.checkNotNull("rarity", rarity);
|
||||
|
||||
Lambda1<Boolean, Card> predicate = new Lambda1<Boolean, Card>() {
|
||||
public Boolean apply(final Card c) {
|
||||
if (c == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO spin off Mythic from Rare when the time comes
|
||||
String r = c.getSVar("Rarity");
|
||||
return (r != null
|
||||
&& (r.equals(rarity) || rarity.equals(Constant.Rarity.Rare)
|
||||
&& r.equals(Constant.Rarity.Mythic)));
|
||||
}
|
||||
};
|
||||
|
||||
return GeneratorFunctions.filterGenerator(predicate, inputGenerator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter an iterable sequence of Cards; note this is a static method
|
||||
|
||||
@@ -415,23 +415,6 @@ public class CardList implements Iterable<Card> {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getRarity.</p>
|
||||
*
|
||||
* @param rarity a {@link java.lang.String} object.
|
||||
* @return a {@link forge.CardList} object.
|
||||
*/
|
||||
public final CardList getRarity(final String rarity) {
|
||||
return this.filter(new CardListFilter() {
|
||||
public boolean addCard(final Card c) {
|
||||
// TODO spin off Mythic from Rare when the time comes
|
||||
String r = c.getSVar("Rarity");
|
||||
return r.equals(rarity)
|
||||
|| rarity.equals(Constant.Rarity.Rare) && r.equals(Constant.Rarity.Mythic);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//cardType is like "Land" or "Goblin", returns a new CardList that is a subset of current CardList
|
||||
/**
|
||||
* <p>getType.</p>
|
||||
|
||||
@@ -99,7 +99,7 @@ public class GUI_DeckAnalysis extends javax.swing.JDialog {
|
||||
// private ButtonGroup buttonGroup1;
|
||||
|
||||
public CardList filterCardList;
|
||||
public TableModel tModel;
|
||||
public CardPoolView deck;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -111,9 +111,9 @@ public class GUI_DeckAnalysis extends javax.swing.JDialog {
|
||||
* @param tb
|
||||
* a {@link forge.gui.deckeditor.TableModel} object.
|
||||
*/
|
||||
public GUI_DeckAnalysis(JFrame g, TableModel tb) {
|
||||
public GUI_DeckAnalysis(JFrame g, CardPoolView deckView) {
|
||||
super(g);
|
||||
tModel = tb;
|
||||
deck = deckView;
|
||||
|
||||
jF = g;
|
||||
initGUI();
|
||||
@@ -179,9 +179,8 @@ public class GUI_DeckAnalysis extends javax.swing.JDialog {
|
||||
mFive = 0;
|
||||
mSixMore = 0;
|
||||
tManaCost = 0;
|
||||
CardPoolView cardList = tModel.getCards();
|
||||
|
||||
for (Entry<CardPrinted, Integer> e : cardList) {
|
||||
for (Entry<CardPrinted, Integer> e : deck) {
|
||||
c = e.getKey().getCard();
|
||||
int cnt = e.getValue();
|
||||
|
||||
@@ -222,7 +221,7 @@ public class GUI_DeckAnalysis extends javax.swing.JDialog {
|
||||
|
||||
tManaCost = tManaCost + cmc * cnt;
|
||||
}
|
||||
int total = cardList.countAll();
|
||||
int total = deck.countAll();
|
||||
BigDecimal aManaCost = new BigDecimal(tManaCost / total);
|
||||
aManaCost = aManaCost.setScale(2, BigDecimal.ROUND_HALF_UP);
|
||||
|
||||
@@ -920,7 +919,7 @@ public class GUI_DeckAnalysis extends javax.swing.JDialog {
|
||||
* @return a {@link javax.swing.JList} object.
|
||||
*/
|
||||
private JList getJList1() {
|
||||
List<CardPrinted> rList = tModel.getCards().toFlatList();
|
||||
List<CardPrinted> rList = deck.toFlatList();
|
||||
|
||||
Collections.shuffle(rList, MyRandom.random);
|
||||
Collections.shuffle(rList, MyRandom.random);
|
||||
@@ -1029,9 +1028,9 @@ public class GUI_DeckAnalysis extends javax.swing.JDialog {
|
||||
* @return a {@link javax.swing.JButton} object.
|
||||
*/
|
||||
private JButton getJButton1() {
|
||||
CardPoolView rList = tModel.getCards();
|
||||
|
||||
if (jButtonRegenerate == null) {
|
||||
if (rList.countAll() >= 40) {
|
||||
if (deck.countAll() >= 40) {
|
||||
jButtonRegenerate = new JButton();
|
||||
jButtonRegenerate.setLayout(null);
|
||||
jButtonRegenerate.setText("Regenerate hand");
|
||||
@@ -1106,7 +1105,7 @@ public class GUI_DeckAnalysis extends javax.swing.JDialog {
|
||||
"6th", "7th" });
|
||||
|
||||
jTable1 = new JTable(dm);
|
||||
List<CardPrinted> rList = tModel.getCards().toFlatList();
|
||||
List<CardPrinted> rList = deck.toFlatList();
|
||||
String[] cardsName = new String[rList.size()];
|
||||
int cCount;
|
||||
float fCount;
|
||||
|
||||
@@ -16,11 +16,10 @@ public final class CardPool extends CardPoolView {
|
||||
public CardPool(final List<String> names) { super(); addAllCards(CardDb.instance().getCards(names)); }
|
||||
|
||||
// Copy ctor will create its own modifiable pool
|
||||
@SuppressWarnings("unchecked")
|
||||
public CardPool(final CardPoolView from) {
|
||||
super();
|
||||
cards = new Hashtable<CardPrinted, Integer>();
|
||||
cards.putAll(from.cards);
|
||||
if (from != null) { cards.putAll(from.cards); }
|
||||
}
|
||||
public CardPool(final Iterable<CardPrinted> list) {
|
||||
this(); addAllCards(list);
|
||||
|
||||
@@ -194,6 +194,7 @@ public class Deck implements Comparable<Deck>, Serializable {
|
||||
*/
|
||||
public final void addSideboard(final String cardName) { addSideboard(CardDb.instance().getCard(cardName)); }
|
||||
public final void addSideboard(final CardPrinted card) { sideboard.add(card); }
|
||||
public final void addSideboard(final CardPrinted card, final int amount) { sideboard.add(card, amount); }
|
||||
public final void addSideboard(final CardPoolView cards) { sideboard.addAll(cards); }
|
||||
|
||||
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package forge.gui.deckeditor;
|
||||
|
||||
import forge.card.CardPrinted;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public interface CardDisplay {
|
||||
void showCard(CardPrinted card);
|
||||
|
||||
// Sorry, this is for JPanel initialization
|
||||
void jbInit();
|
||||
}
|
||||
15
src/main/java/forge/gui/deckeditor/CardPanelBase.java
Normal file
15
src/main/java/forge/gui/deckeditor/CardPanelBase.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package forge.gui.deckeditor;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import forge.card.CardPrinted;
|
||||
|
||||
/**
|
||||
* Base class for any cardView panel
|
||||
*
|
||||
*/
|
||||
public abstract class CardPanelBase extends JPanel {
|
||||
private static final long serialVersionUID = -2230733670423143126L;
|
||||
|
||||
public abstract void showCard(CardPrinted card);
|
||||
|
||||
}
|
||||
@@ -28,7 +28,7 @@ import forge.view.swing.OldGuiNewGame;
|
||||
* This panel is to be placed in the right part of a deck editor
|
||||
*
|
||||
*/
|
||||
public class CardViewPanel extends JPanel implements CardDisplay {
|
||||
public class CardPanelHeavy extends CardPanelBase {
|
||||
|
||||
private static final long serialVersionUID = -7134546689397508597L;
|
||||
|
||||
@@ -45,8 +45,7 @@ public class CardViewPanel extends JPanel implements CardDisplay {
|
||||
/** Constant <code>previousDirectory</code> */
|
||||
protected static File previousDirectory = null;
|
||||
|
||||
|
||||
public void jbInit() {
|
||||
public CardPanelHeavy() {
|
||||
changePictureButton.setText("Change picture...");
|
||||
changePictureButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
@@ -1,9 +1,5 @@
|
||||
package forge.gui.deckeditor;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
import forge.Card;
|
||||
@@ -15,7 +11,7 @@ import forge.gui.game.CardPicturePanel;
|
||||
* This panel is to be placed in the right part of a deck editor
|
||||
*
|
||||
*/
|
||||
public class CardViewPanelLite extends JPanel implements CardDisplay {
|
||||
public class CardPanelLite extends CardPanelBase {
|
||||
|
||||
private static final long serialVersionUID = -7134546689397508597L;
|
||||
|
||||
@@ -23,11 +19,7 @@ public class CardViewPanelLite extends JPanel implements CardDisplay {
|
||||
protected CardDetailPanel detail = new CardDetailPanel(null);
|
||||
private CardPicturePanel picture = new CardPicturePanel(null);
|
||||
|
||||
/** Constant <code>previousDirectory</code> */
|
||||
protected static File previousDirectory = null;
|
||||
|
||||
|
||||
public void jbInit() {
|
||||
public CardPanelLite() {
|
||||
this.setLayout(new MigLayout("fill, ins 0"));
|
||||
this.add(detail, "w 239, h 323, grow, flowy, wrap");
|
||||
this.add(picture, "wmin 239, hmin 323, grow");
|
||||
@@ -35,8 +27,7 @@ public class CardViewPanelLite extends JPanel implements CardDisplay {
|
||||
|
||||
public void showCard(CardPrinted card) {
|
||||
picture.setCard(card);
|
||||
Card card2 = card.toForgeCard();
|
||||
detail.setCard(card2);
|
||||
detail.setCard(card != null ? card.toForgeCard() : null);
|
||||
}
|
||||
|
||||
public Card getCard() { return detail.getCard(); }
|
||||
@@ -34,8 +34,6 @@ import forge.Constant;
|
||||
import forge.SetInfoUtil;
|
||||
import forge.card.CardRules;
|
||||
import forge.card.CardDb;
|
||||
import forge.card.CardPool;
|
||||
import forge.card.CardPoolView;
|
||||
import forge.card.CardPrinted;
|
||||
import forge.deck.Deck;
|
||||
import forge.error.ErrorViewer;
|
||||
@@ -50,7 +48,7 @@ import forge.view.swing.OldGuiNewGame;
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class DeckEditor extends DeckEditorBase implements NewConstants {
|
||||
public final class DeckEditor extends DeckEditorBase implements NewConstants {
|
||||
/** Constant <code>serialVersionUID=130339644136746796L</code> */
|
||||
private static final long serialVersionUID = 130339644136746796L;
|
||||
|
||||
@@ -80,26 +78,10 @@ public class DeckEditor extends DeckEditorBase implements NewConstants {
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void setTitle(String message) {
|
||||
public void setTitle(final String message) {
|
||||
super.setTitle(message);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void setDecks(CardPoolView topPool, CardPoolView bottomPool) {
|
||||
top = new CardPool(topPool);
|
||||
topModel.clear();
|
||||
topModel.addCards(buildFilter().select(top, CardPoolView.fnToCard));
|
||||
topModel.resort();
|
||||
topTable.repaint();
|
||||
|
||||
bottom = bottomPool;
|
||||
bottomModel.clear();
|
||||
bottomModel.addCards(bottom);
|
||||
bottomModel.resort();
|
||||
bottomTable.repaint();
|
||||
}// updateDisplay
|
||||
|
||||
|
||||
public void show(final Command exitCommand) {
|
||||
final Command exit = new Command() {
|
||||
private static final long serialVersionUID = 5210924838133689758L;
|
||||
@@ -116,7 +98,7 @@ public class DeckEditor extends DeckEditorBase implements NewConstants {
|
||||
// do not change this!!!!
|
||||
this.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent ev) {
|
||||
public void windowClosing(final WindowEvent ev) {
|
||||
customMenu.close();
|
||||
}
|
||||
});
|
||||
@@ -130,24 +112,26 @@ public class DeckEditor extends DeckEditorBase implements NewConstants {
|
||||
customMenu.newConstructed();
|
||||
}
|
||||
|
||||
topModel.sort(1, true);
|
||||
bottomModel.sort(1, true);
|
||||
top.sort(1, true);
|
||||
bottom.sort(1, true);
|
||||
|
||||
}// show(Command)
|
||||
} // show(Command)
|
||||
|
||||
|
||||
private void setup() {
|
||||
List<TableColumnInfo<CardPrinted>> columns = new ArrayList<TableColumnInfo<CardPrinted>>();
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Qty", 30, CardColumnPresets.fnQtyCompare, CardColumnPresets.fnQtyGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Name", 180, CardColumnPresets.fnNameCompare, CardColumnPresets.fnNameGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Cost", 70, CardColumnPresets.fnCostCompare, CardColumnPresets.fnCostGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Color", 50, CardColumnPresets.fnColorCompare, CardColumnPresets.fnColorGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Type", 100, CardColumnPresets.fnTypeCompare, CardColumnPresets.fnTypeGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Stats", 40, CardColumnPresets.fnStatsCompare, CardColumnPresets.fnStatsGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("R", 35, CardColumnPresets.fnRarityCompare, CardColumnPresets.fnRarityGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Set", 40, CardColumnPresets.fnSetCompare, CardColumnPresets.fnSetGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("AI", 30, CardColumnPresets.fnAiStatusCompare, CardColumnPresets.fnAiStatusGet));
|
||||
setupTables(columns, true);
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Qty", 30, PresetColumns.fnQtyCompare, PresetColumns.fnQtyGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Name", 180, PresetColumns.fnNameCompare, PresetColumns.fnNameGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Cost", 70, PresetColumns.fnCostCompare, PresetColumns.fnCostGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Color", 50, PresetColumns.fnColorCompare, PresetColumns.fnColorGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Type", 100, PresetColumns.fnTypeCompare, PresetColumns.fnTypeGet));
|
||||
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>("Set", 40, PresetColumns.fnSetCompare, PresetColumns.fnSetGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("AI", 30, PresetColumns.fnAiStatusCompare, PresetColumns.fnAiStatusGet));
|
||||
|
||||
top.setup(columns, cardView);
|
||||
bottom.setup(columns, cardView);
|
||||
|
||||
// TODO use this as soon the deck editor has resizable GUI
|
||||
// Use both so that when "un"maximizing, the frame isn't tiny
|
||||
@@ -175,83 +159,71 @@ public class DeckEditor extends DeckEditorBase implements NewConstants {
|
||||
* </p>
|
||||
*/
|
||||
public DeckEditor() {
|
||||
super(true, true);
|
||||
try {
|
||||
filterBoxes = new FilterCheckBoxes(true);
|
||||
top = new TableWithCards("Avaliable Cards", true);
|
||||
bottom = new TableWithCards("Deck", true);
|
||||
cardView = new CardPanelHeavy();
|
||||
|
||||
jbInit();
|
||||
} catch (Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* jbInit.
|
||||
* </p>
|
||||
*
|
||||
* @throws java.lang.Exception
|
||||
* if any.
|
||||
*/
|
||||
private void jbInit() throws Exception {
|
||||
jbInitTables("All Cards", "Deck");
|
||||
|
||||
private void jbInit() {
|
||||
// removeButton.setIcon(upIcon);
|
||||
if (!OldGuiNewGame.useLAFFonts.isSelected())
|
||||
if (!OldGuiNewGame.useLAFFonts.isSelected()) {
|
||||
removeButton.setFont(new java.awt.Font("Dialog", 0, 13));
|
||||
}
|
||||
removeButton.setText("Remove from Deck");
|
||||
removeButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
removeButton_actionPerformed(e);
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
removeButtonClicked(e);
|
||||
}
|
||||
});
|
||||
addButton.setText("Add to Deck");
|
||||
addButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
addButton_actionPerformed(e);
|
||||
}
|
||||
});
|
||||
// addButton.setIcon(downIcon);
|
||||
if (!OldGuiNewGame.useLAFFonts.isSelected())
|
||||
if (!OldGuiNewGame.useLAFFonts.isSelected()) {
|
||||
addButton.setFont(new java.awt.Font("Dialog", 0, 13));
|
||||
|
||||
}
|
||||
clearFilterButton.setText("Clear Filter");
|
||||
clearFilterButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
clearFilterButton_actionPerformed(e);
|
||||
}
|
||||
});
|
||||
if (!OldGuiNewGame.useLAFFonts.isSelected())
|
||||
if (!OldGuiNewGame.useLAFFonts.isSelected()) {
|
||||
clearFilterButton.setFont(new java.awt.Font("Dialog", 0, 13));
|
||||
|
||||
}
|
||||
analysisButton.setText("Deck Analysis");
|
||||
analysisButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
analysisButton_actionPerformed(e);
|
||||
}
|
||||
});
|
||||
if (!OldGuiNewGame.useLAFFonts.isSelected())
|
||||
if (!OldGuiNewGame.useLAFFonts.isSelected()) {
|
||||
analysisButton.setFont(new java.awt.Font("Dialog", 0, 13));
|
||||
}
|
||||
|
||||
/**
|
||||
* Type filtering
|
||||
*/
|
||||
// Type filtering
|
||||
Font f = new Font("Tahoma", Font.PLAIN, 10);
|
||||
for (JCheckBox box : filterBoxes.allTypes) {
|
||||
if (!OldGuiNewGame.useLAFFonts.isSelected()) { box.setFont(f); }
|
||||
box.setOpaque(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Color filtering
|
||||
*/
|
||||
// Color filtering
|
||||
for (JCheckBox box : filterBoxes.allColors) {
|
||||
box.setOpaque(false);
|
||||
}
|
||||
|
||||
|
||||
// picture.addMouseListener(new CustomListener());
|
||||
if (!OldGuiNewGame.useLAFFonts.isSelected())
|
||||
statsLabel.setFont(new java.awt.Font("Dialog", 0, 13));
|
||||
statsLabel.setText("Total: 0, Creatures: 0, Land: 0");
|
||||
// Do not lower statsLabel any lower, we want this to be visible at 1024
|
||||
// x 768 screen size
|
||||
this.setTitle("Deck Editor");
|
||||
@@ -259,13 +231,6 @@ public class DeckEditor extends DeckEditorBase implements NewConstants {
|
||||
jPanel3.setLayout(gridLayout1);
|
||||
gridLayout1.setColumns(1);
|
||||
gridLayout1.setRows(0);
|
||||
statsLabel2.setText("Total: 0, Creatures: 0, Land: 0");
|
||||
if (!OldGuiNewGame.useLAFFonts.isSelected())
|
||||
statsLabel2.setFont(new java.awt.Font("Dialog", 0, 13));
|
||||
/*
|
||||
* jLabel1.setText(
|
||||
* "Click on the column name (like name or color) to sort the cards");
|
||||
*/
|
||||
|
||||
Container pane = this.getContentPane();
|
||||
MigLayout layout = new MigLayout("fill");
|
||||
@@ -293,12 +258,10 @@ public class DeckEditor extends DeckEditorBase implements NewConstants {
|
||||
//this.getContentPane().add(filterButton, "wmin 100, hmin 25, wmax 140, hmax 25, grow");
|
||||
this.getContentPane().add(clearFilterButton, "wmin 100, hmin 25, wmax 140, hmax 25, grow");
|
||||
|
||||
this.getContentPane().add(jScrollPane1, "cell 0 2 1 2, pushy, grow");
|
||||
this.getContentPane().add(top.getTableDecorated(), "cell 0 2 1 2, pushy, grow");
|
||||
|
||||
cardView.jbInit();
|
||||
this.getContentPane().add(cardView, "cell 1 0 1 8, flowy, grow");
|
||||
|
||||
|
||||
labelFilterName.setText("Name:");
|
||||
labelFilterName.setToolTipText("Card names must include the text in this field");
|
||||
this.getContentPane().add(labelFilterName, "cell 0 1, split 7");
|
||||
@@ -331,7 +294,7 @@ public class DeckEditor extends DeckEditorBase implements NewConstants {
|
||||
|
||||
this.getContentPane().add(searchSetCombo, "wmin 150, grow");
|
||||
|
||||
this.getContentPane().add(statsLabel2, "cell 0 4");
|
||||
this.getContentPane().add(top.getLabel(), "cell 0 4");
|
||||
|
||||
this.getContentPane().add(addButton, "w 100, h 49, sg button, cell 0 5, split 4");
|
||||
this.getContentPane().add(removeButton, "w 100, h 49, sg button");
|
||||
@@ -343,12 +306,12 @@ public class DeckEditor extends DeckEditorBase implements NewConstants {
|
||||
|
||||
this.getContentPane().add(analysisButton, "w 100, h 49, wrap");
|
||||
|
||||
this.getContentPane().add(jScrollPane2, "cell 0 6, grow");
|
||||
this.getContentPane().add(statsLabel, "cell 0 7");
|
||||
this.getContentPane().add(bottom.getTableDecorated(), "cell 0 6, grow");
|
||||
this.getContentPane().add(bottom.getLabel(), "cell 0 7");
|
||||
|
||||
topTable.addMouseListener(new MouseAdapter() {
|
||||
top.getTable().addMouseListener(new MouseAdapter() {
|
||||
@Override public void mouseClicked(final MouseEvent e) {
|
||||
if (e.getClickCount() == 2) { addCardFromTopTableToBottom(); }
|
||||
if (e.getClickCount() == 2) { addCardToDeck(); }
|
||||
}
|
||||
});
|
||||
|
||||
@@ -392,11 +355,10 @@ public class DeckEditor extends DeckEditorBase implements NewConstants {
|
||||
txtCardRules.setText("");
|
||||
searchSetCombo.setSelectedIndex(0);
|
||||
|
||||
// restore automatics ...
|
||||
isFiltersChangeFiringUpdate = true;
|
||||
// ... and force update
|
||||
updateDisplay();
|
||||
} // clearFilterButton_actionPerformed
|
||||
|
||||
top.setFilter(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -407,29 +369,21 @@ public class DeckEditor extends DeckEditorBase implements NewConstants {
|
||||
* a {@link java.awt.event.ActionEvent} object.
|
||||
*/
|
||||
void addButton_actionPerformed(ActionEvent e) {
|
||||
addCardFromTopTableToBottom();
|
||||
}// addButton_actionPerformed
|
||||
addCardToDeck();
|
||||
}
|
||||
|
||||
void addCardToDeck() {
|
||||
CardPrinted card = top.getSelectedCard();
|
||||
if (card == null) { return; }
|
||||
|
||||
void addCardFromTopTableToBottom() {
|
||||
setTitle("Deck Editor : " + customMenu.getDeckName() + " : unsaved");
|
||||
|
||||
int n = topTable.getSelectedRow();
|
||||
if (n != -1) {
|
||||
CardPrinted c = topModel.rowToCard(n).getKey();
|
||||
bottomModel.addCard(c);
|
||||
bottomModel.resort();
|
||||
|
||||
if (!customMenu.getGameType().equals(Constant.GameType.Constructed)) {
|
||||
top.remove(c);
|
||||
topModel.removeCard(c);
|
||||
topModel.resort();
|
||||
bottom.addCard(card);
|
||||
if (!isConstructed) {
|
||||
top.removeCard(card);
|
||||
}
|
||||
fixSelection(topModel, topTable, n);
|
||||
}// if(valid row)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* removeButton_actionPerformed.
|
||||
@@ -438,22 +392,17 @@ public class DeckEditor extends DeckEditorBase implements NewConstants {
|
||||
* @param e
|
||||
* a {@link java.awt.event.ActionEvent} object.
|
||||
*/
|
||||
void removeButton_actionPerformed(ActionEvent e) {
|
||||
void removeButtonClicked(ActionEvent e) {
|
||||
CardPrinted card = bottom.getSelectedCard();
|
||||
if (card == null) { return; }
|
||||
|
||||
setTitle("Deck Editor : " + customMenu.getDeckName() + " : unsaved");
|
||||
|
||||
int n = bottomTable.getSelectedRow();
|
||||
if (n != -1) {
|
||||
CardPrinted c = bottomModel.rowToCard(n).getKey();
|
||||
bottomModel.removeCard(c);
|
||||
|
||||
if (!Constant.GameType.Constructed.equals(customMenu.getGameType())) {
|
||||
topModel.addCard(c);
|
||||
topModel.resort();
|
||||
bottom.removeCard(card);
|
||||
if (!isConstructed) {
|
||||
top.addCard(card);
|
||||
}
|
||||
}
|
||||
|
||||
fixSelection(bottomModel, bottomTable, n);
|
||||
}// if(valid row)
|
||||
}//
|
||||
|
||||
// refresh Gui from deck, Gui shows the cards in the deck
|
||||
/**
|
||||
@@ -468,20 +417,14 @@ public class DeckEditor extends DeckEditorBase implements NewConstants {
|
||||
if (deck == null) // this is just a patch, i know
|
||||
deck = new Deck(Constant.Runtime.GameType[0]);
|
||||
|
||||
topModel.clear();
|
||||
bottomModel.clear();
|
||||
|
||||
bottomModel.addCards(deck.getMain());
|
||||
bottom.setDeck(deck.getMain());
|
||||
|
||||
if (deck.isSealed() || deck.isDraft()) {
|
||||
topModel.addCards(deck.getSideboard()); // add sideboard to GUI
|
||||
top.setDeck(deck.getSideboard()); // add sideboard to GUI
|
||||
} else {
|
||||
topModel.addAllCards(CardDb.instance().getAllUniqueCards());
|
||||
top.setDeck(CardDb.instance().getAllUniqueCards());
|
||||
}
|
||||
}
|
||||
|
||||
topModel.resort();
|
||||
bottomModel.resort();
|
||||
} // //refreshGui()
|
||||
|
||||
protected class OnChangeTextUpdateDisplay implements DocumentListener {
|
||||
//private String lastText = "";
|
||||
|
||||
@@ -28,108 +28,25 @@ import forge.card.CardPoolView;
|
||||
public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
|
||||
private static final long serialVersionUID = -401223933343539977L;
|
||||
|
||||
//public JCheckBox whiteCheckBox = new GuiFilterCheckBox("white", "White");
|
||||
|
||||
public final FilterCheckBoxes filterBoxes;
|
||||
protected FilterCheckBoxes filterBoxes;
|
||||
// set this to false when resetting filter from code (like "clearFiltersPressed"), reset when done.
|
||||
protected boolean isFiltersChangeFiringUpdate = true;
|
||||
public final CardViewPanel cardView = new CardViewPanel();
|
||||
|
||||
|
||||
protected CardPanelBase cardView;
|
||||
|
||||
// CardPools and Table data for top and bottom lists
|
||||
protected CardPool top;
|
||||
protected TableModel topModel;
|
||||
protected JTable topTable = new JTable();
|
||||
protected JScrollPane jScrollPane1 = new JScrollPane();
|
||||
protected JLabel statsLabel = new JLabel();
|
||||
|
||||
|
||||
protected CardPoolView bottom;
|
||||
protected TableModel bottomModel;
|
||||
protected JTable bottomTable = new JTable();
|
||||
protected JScrollPane jScrollPane2 = new JScrollPane();
|
||||
protected JLabel statsLabel2 = new JLabel();
|
||||
protected TableWithCards top;
|
||||
protected TableWithCards bottom;
|
||||
|
||||
// top shows available card pool
|
||||
// if constructed, top shows all cards
|
||||
// if sealed, top shows N booster packs
|
||||
// if draft, top shows cards that were chosen
|
||||
public final TableModel getTopTableModel() { return topModel; }
|
||||
public final CardPool getTop() { return top; }
|
||||
|
||||
// bottom shows cards that the user has chosen for his library
|
||||
public final CardPoolView getBottom() { return bottomModel.getCards(); }
|
||||
|
||||
protected DeckEditorBase(final boolean useFilters, final boolean areGraphicalFilters) {
|
||||
filterBoxes = useFilters ? new FilterCheckBoxes(areGraphicalFilters) : null;
|
||||
}
|
||||
|
||||
protected final void setupTables(List<TableColumnInfo<CardPrinted>> columns, boolean trackStats ) {
|
||||
// construct topTable, get all cards
|
||||
|
||||
topModel = new TableModel(cardView, columns);
|
||||
topModel.addListeners(topTable);
|
||||
topTable.setModel(topModel);
|
||||
topModel.resizeCols(topTable);
|
||||
|
||||
// construct bottomModel
|
||||
bottomModel = new TableModel(cardView, columns);
|
||||
bottomModel.addListeners(bottomTable);
|
||||
bottomTable.setModel(bottomModel);
|
||||
bottomModel.resizeCols(bottomTable);
|
||||
|
||||
if (trackStats)
|
||||
{
|
||||
// get stats from deck
|
||||
bottomModel.addTableModelListener(new TableModelListener() {
|
||||
public void tableChanged(final TableModelEvent ev) {
|
||||
CardPoolView deck = bottomModel.getCards();
|
||||
statsLabel.setText(getStats(deck));
|
||||
}
|
||||
});
|
||||
|
||||
// get stats from all cards
|
||||
topModel.addTableModelListener(new TableModelListener() {
|
||||
public void tableChanged(final TableModelEvent ev) {
|
||||
CardPoolView deck = topModel.getCards();
|
||||
statsLabel2.setText(getStats(deck));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected final void jbInitTables(String topTitle, String bottomTitle)
|
||||
{
|
||||
Color gray = new Color(148, 145, 140);
|
||||
TitledBorder titledBorder1 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white, gray), topTitle);
|
||||
TitledBorder titledBorder2 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white, gray), bottomTitle);
|
||||
this.getContentPane().setLayout(null);
|
||||
String tableToolTip = "Click on the column name (like name or color) to sort the cards";
|
||||
jScrollPane1.setBorder(titledBorder1);
|
||||
jScrollPane1.setToolTipText(tableToolTip);
|
||||
jScrollPane2.setBorder(titledBorder2);
|
||||
jScrollPane2.setToolTipText(tableToolTip);
|
||||
|
||||
jScrollPane2.getViewport().add(bottomTable, null);
|
||||
jScrollPane1.getViewport().add(topTable, null);
|
||||
}
|
||||
|
||||
|
||||
// This should not be here, but still found no better place
|
||||
public static String getStats(CardPoolView deck) {
|
||||
int total = deck.countAll();
|
||||
int creature = CardRules.Predicates.Presets.isCreature.aggregate(deck, CardPoolView.fnToCard, CardPoolView.fnToCount);
|
||||
int land = CardRules.Predicates.Presets.isLand.aggregate(deck, CardPoolView.fnToCard, CardPoolView.fnToCount);
|
||||
|
||||
StringBuffer show = new StringBuffer();
|
||||
show.append("Total - ").append(total).append(", Creatures - ").append(creature).append(", Land - ").append(land);
|
||||
String[] color = Constant.Color.onlyColors;
|
||||
List<Predicate<CardRules>> predicates = CardRules.Predicates.Presets.colors;
|
||||
for (int i = 0; i < color.length; ++i) {
|
||||
show.append(String.format(", %s - %d", color[i], predicates.get(i).count(deck, CardPoolView.fnToCard)));
|
||||
}
|
||||
|
||||
return show.toString();
|
||||
}// getStats()
|
||||
public final TableWithCards getTopTableModel() { return top; }
|
||||
public final CardPoolView getTop() { return top.getCards(); }
|
||||
// bottom shows player's choice - be it deck or draft
|
||||
public final CardPoolView getBottom() { return bottom.getCards(); }
|
||||
|
||||
// THIS IS HERE FOR OVERLOADING!!!1
|
||||
// or may be return abstract getFilter from derived class + this filter ... virtual protected member, but later
|
||||
@@ -140,14 +57,14 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
|
||||
return filterBoxes.buildFilter();
|
||||
}
|
||||
|
||||
|
||||
void analysisButton_actionPerformed(ActionEvent e) {
|
||||
if (bottomModel.getRowCount() == 0) {
|
||||
CardPoolView deck = bottom.getCards();
|
||||
if (deck.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(null, "Cards in deck not found.", "Analysis Deck",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
} else {
|
||||
DeckEditorBase g = DeckEditorBase.this;
|
||||
GUI_DeckAnalysis dAnalysis = new GUI_DeckAnalysis(g, bottomModel);
|
||||
GUI_DeckAnalysis dAnalysis = new GUI_DeckAnalysis(g, deck);
|
||||
dAnalysis.setVisible(true);
|
||||
g.setEnabled(false);
|
||||
}
|
||||
@@ -159,25 +76,14 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
|
||||
}
|
||||
};
|
||||
|
||||
public void setDecks(CardPoolView topParam, CardPoolView bottomParam) {
|
||||
top.setDeck(topParam);
|
||||
bottom.setDeck(bottomParam);
|
||||
}
|
||||
|
||||
public void updateDisplay() {
|
||||
topModel.clear();
|
||||
Predicate<CardRules> currentFilter = buildFilter();
|
||||
topModel.addCards(currentFilter.select(top, CardPoolView.fnToCard));
|
||||
topModel.resort();
|
||||
top.setFilter(buildFilter());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Call this after deleting an item from table
|
||||
protected void fixSelection(TableModel model, JTable table, int rowLastSelected) {
|
||||
// 3 cases: 0 cards left, select the same row, select prev row
|
||||
int cntRowsAbove = model.getRowCount();
|
||||
if (cntRowsAbove != 0) {
|
||||
if (cntRowsAbove == rowLastSelected) { rowLastSelected--; } // move selection away from the last, already missing, option
|
||||
table.setRowSelectionInterval(rowLastSelected, rowLastSelected);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
260
src/main/java/forge/gui/deckeditor/DeckEditorDraft.java
Normal file
260
src/main/java/forge/gui/deckeditor/DeckEditorDraft.java
Normal file
@@ -0,0 +1,260 @@
|
||||
package forge.gui.deckeditor;
|
||||
|
||||
import forge.AllZone;
|
||||
import forge.BoosterDraft;
|
||||
import forge.Constant;
|
||||
import forge.FileUtil;
|
||||
import forge.HttpUtil;
|
||||
import forge.card.CardDb;
|
||||
import forge.card.CardPoolView;
|
||||
import forge.card.CardPrinted;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckManager;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
import forge.view.swing.OldGuiNewGame;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.TitledBorder;
|
||||
import javax.swing.event.TableModelEvent;
|
||||
import javax.swing.event.TableModelListener;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Gui_BoosterDraft class.</p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class DeckEditorDraft extends DeckEditorBase implements NewConstants, NewConstants.LANG.Gui_BoosterDraft {
|
||||
/**
|
||||
* Constant <code>serialVersionUID=-6055633915602448260L</code>
|
||||
*/
|
||||
private static final long serialVersionUID = -6055633915602448260L;
|
||||
|
||||
private BoosterDraft boosterDraft;
|
||||
|
||||
private JButton jButton1 = new JButton();
|
||||
|
||||
private CardPanelLite cardView = new CardPanelLite();
|
||||
|
||||
/**
|
||||
* <p>showGui.</p>
|
||||
*
|
||||
* @param in_boosterDraft a {@link forge.BoosterDraft} object.
|
||||
*/
|
||||
public void showGui(BoosterDraft in_boosterDraft) {
|
||||
boosterDraft = in_boosterDraft;
|
||||
|
||||
setup();
|
||||
showChoices(boosterDraft.nextChoice());
|
||||
bottom.setDeck((CardPoolView)null);
|
||||
|
||||
top.sort(1, true);
|
||||
bottom.sort(1, true);
|
||||
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>addListeners.</p>
|
||||
*/
|
||||
private void addListeners() {
|
||||
this.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent ev) {
|
||||
int n = JOptionPane.showConfirmDialog(null, ForgeProps.getLocalized(CLOSE_MESSAGE), "",
|
||||
JOptionPane.YES_NO_OPTION);
|
||||
if (n == JOptionPane.YES_OPTION) {
|
||||
dispose();
|
||||
new OldGuiNewGame();
|
||||
}
|
||||
}//windowClosing()
|
||||
});
|
||||
}//addListeners()
|
||||
|
||||
/**
|
||||
* <p>setup.</p>
|
||||
*/
|
||||
private void setup() {
|
||||
addListeners();
|
||||
// setupMenu();
|
||||
|
||||
List<TableColumnInfo<CardPrinted>> columns = new ArrayList<TableColumnInfo<CardPrinted>>();
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Qty", 30, PresetColumns.fnQtyCompare, PresetColumns.fnQtyGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Name", 180, PresetColumns.fnNameCompare, PresetColumns.fnNameGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Cost", 70, PresetColumns.fnCostCompare, PresetColumns.fnCostGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Color", 50, PresetColumns.fnColorCompare, PresetColumns.fnColorGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Type", 100, PresetColumns.fnTypeCompare, PresetColumns.fnTypeGet));
|
||||
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>("Set", 40, PresetColumns.fnSetCompare, PresetColumns.fnSetGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("AI", 30, PresetColumns.fnAiStatusCompare, PresetColumns.fnAiStatusGet));
|
||||
|
||||
top.setup(columns, cardView);
|
||||
bottom.setup(columns, cardView);
|
||||
|
||||
//Use both so that when "un"maximizing, the frame isn't tiny
|
||||
setSize(1024, 740);
|
||||
//setExtendedState(Frame.MAXIMIZED_BOTH);
|
||||
}
|
||||
|
||||
public DeckEditorDraft() {
|
||||
try {
|
||||
top = new TableWithCards("Choose one card", false);
|
||||
bottom = new TableWithCards("Previously Picked Cards", true);
|
||||
filterBoxes = null;
|
||||
cardView = new CardPanelLite();
|
||||
jbInit();
|
||||
} catch (Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>jbInit.</p>
|
||||
*
|
||||
* @throws java.lang.Exception if any.
|
||||
*/
|
||||
private void jbInit() throws Exception {
|
||||
this.getContentPane().setLayout(null);
|
||||
|
||||
top.getTableDecorated().setBounds(new Rectangle(19, 28, 661, 344));
|
||||
bottom.getTableDecorated().setBounds(new Rectangle(19, 478, 661, 184));
|
||||
cardView.setBounds(new Rectangle(693, 23, 239, 665));
|
||||
|
||||
bottom.getLabel().setBounds(new Rectangle(19, 665, 665, 31));
|
||||
|
||||
this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||
this.setTitle("Booster Draft");
|
||||
|
||||
jButton1.setBounds(new Rectangle(238, 418, 147, 44));
|
||||
jButton1.setFont(new java.awt.Font("Dialog", 0, 16));
|
||||
jButton1.setText("Choose Card");
|
||||
jButton1.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
jButton1_actionPerformed(e);
|
||||
}
|
||||
});
|
||||
|
||||
this.getContentPane().add(cardView, null);
|
||||
this.getContentPane().add(top.getTableDecorated(), null);
|
||||
this.getContentPane().add(bottom.getLabel(), null);
|
||||
this.getContentPane().add(bottom.getTableDecorated(), null);
|
||||
this.getContentPane().add(jButton1, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>jButton1_actionPerformed.</p>
|
||||
*
|
||||
* @param e a {@link java.awt.event.ActionEvent} object.
|
||||
*/
|
||||
void jButton1_actionPerformed(ActionEvent e) {
|
||||
CardPrinted card = top.getSelectedCard();
|
||||
if ( null == card ) { return; }
|
||||
|
||||
bottom.addCard(card);
|
||||
|
||||
//get next booster pack
|
||||
boosterDraft.setChoice(card);
|
||||
if (boosterDraft.hasNextChoice()) {
|
||||
showChoices(boosterDraft.nextChoice());
|
||||
} else {
|
||||
if (Constant.Runtime.UpldDrft[0]) {
|
||||
if (BoosterDraft.draftPicks.size() > 1) {
|
||||
ArrayList<String> outDraftData = new ArrayList<String>();
|
||||
|
||||
String keys[] = {""};
|
||||
keys = BoosterDraft.draftPicks.keySet().toArray(keys);
|
||||
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
outDraftData.add(keys[i] + "|" + BoosterDraft.draftPicks.get(keys[i]));
|
||||
}
|
||||
|
||||
FileUtil.writeFile("res/draft/tmpDraftData.txt", outDraftData);
|
||||
|
||||
HttpUtil poster = new HttpUtil();
|
||||
poster.upload("http://cardforge.org/draftAI/submitDraftData.php?fmt=" + BoosterDraft.draftFormat[0], "res/draft/tmpDraftData.txt");
|
||||
}
|
||||
}
|
||||
|
||||
//quit
|
||||
saveDraft();
|
||||
dispose();
|
||||
}
|
||||
}/*OK Button*/
|
||||
|
||||
/**
|
||||
* <p>showChoices.</p>
|
||||
*
|
||||
* @param list a {@link forge.CardList} object.
|
||||
*/
|
||||
private void showChoices(CardPoolView list) {
|
||||
top.setDeck(list);
|
||||
cardView.showCard(null);
|
||||
|
||||
}//showChoices()
|
||||
|
||||
/**
|
||||
* <p>getPlayersDeck.</p>
|
||||
*
|
||||
* @return a {@link forge.deck.Deck} object.
|
||||
*/
|
||||
private Deck getPlayersDeck() {
|
||||
Deck deck = new Deck(Constant.GameType.Draft);
|
||||
Constant.Runtime.HumanDeck[0] = deck;
|
||||
|
||||
//add sideboard to deck
|
||||
CardPoolView list = bottom.getCards();
|
||||
deck.addSideboard(list);
|
||||
|
||||
String landSet = BoosterDraft.LandSetCode[0];
|
||||
final int LANDS_COUNT = 20;
|
||||
deck.addSideboard(CardDb.instance().getCard("Forest", landSet), LANDS_COUNT);
|
||||
deck.addSideboard(CardDb.instance().getCard("Mountain", landSet), LANDS_COUNT);
|
||||
deck.addSideboard(CardDb.instance().getCard("Swamp", landSet), LANDS_COUNT);
|
||||
deck.addSideboard(CardDb.instance().getCard("Island", landSet), LANDS_COUNT);
|
||||
deck.addSideboard(CardDb.instance().getCard("Plains", landSet), LANDS_COUNT);
|
||||
|
||||
return deck;
|
||||
}//getPlayersDeck()
|
||||
|
||||
/**
|
||||
* <p>saveDraft.</p>
|
||||
*/
|
||||
private void saveDraft() {
|
||||
String s = "";
|
||||
while (s == null || s.length() == 0) {
|
||||
s = JOptionPane.showInputDialog(null, ForgeProps.getLocalized(SAVE_DRAFT_MESSAGE),
|
||||
ForgeProps.getLocalized(SAVE_DRAFT_TITLE), JOptionPane.QUESTION_MESSAGE);
|
||||
}
|
||||
//TODO: check if overwriting the same name, and let the user delete old drafts
|
||||
|
||||
//construct computer's decks
|
||||
//save draft
|
||||
Deck[] computer = boosterDraft.getDecks();
|
||||
|
||||
Deck human = getPlayersDeck();
|
||||
human.setName(s);
|
||||
|
||||
Deck[] all = {
|
||||
human, computer[0], computer[1], computer[2], computer[3], computer[4], computer[5], computer[6]};
|
||||
|
||||
//DeckManager deckManager = new DeckManager(ForgeProps.getFile(NEW_DECKS));
|
||||
DeckManager deckManager = AllZone.getDeckManager();
|
||||
deckManager.addDraftDeck(all);
|
||||
|
||||
//write file
|
||||
deckManager.close();
|
||||
|
||||
//close and open next screen
|
||||
dispose();
|
||||
new OldGuiNewGame();
|
||||
}/*saveDraft()*/
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package forge.gui.deckeditor;
|
||||
import forge.AllZone;
|
||||
import forge.Command;
|
||||
import forge.Constant;
|
||||
import forge.card.CardDb;
|
||||
import forge.card.CardPool;
|
||||
import forge.card.CardPoolView;
|
||||
import forge.card.CardPrinted;
|
||||
@@ -28,7 +29,7 @@ import java.util.ArrayList;
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class DeckEditorQuest extends DeckEditorBase implements NewConstants {
|
||||
public final class DeckEditorQuest extends DeckEditorBase implements NewConstants {
|
||||
/** Constant <code>serialVersionUID=152061168634545L</code> */
|
||||
private static final long serialVersionUID = 152061168634545L;
|
||||
|
||||
@@ -51,23 +52,6 @@ public class DeckEditorQuest extends DeckEditorBase implements NewConstants {
|
||||
super.setTitle(message);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void setDecks(CardPoolView top, CardPoolView bottom) {
|
||||
|
||||
this.top = new CardPool( top );
|
||||
this.bottom = bottom;
|
||||
|
||||
topModel.clear();
|
||||
topModel.addCards(top);
|
||||
|
||||
bottomModel.clear();
|
||||
bottomModel.addCards(bottom);
|
||||
|
||||
topModel.resort();
|
||||
bottomModel.resort();
|
||||
}// updateDisplay
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* show.
|
||||
@@ -125,10 +109,10 @@ public class DeckEditorQuest extends DeckEditorBase implements NewConstants {
|
||||
setDecks(cardpool, bottomPool);
|
||||
|
||||
// this affects the card pool
|
||||
topModel.sort(4, true);// sort by type
|
||||
topModel.sort(3, true);// then sort by color
|
||||
top.sort(4, true);// sort by type
|
||||
top.sort(3, true);// then sort by color
|
||||
|
||||
bottomModel.sort(1, true);
|
||||
bottom.sort(1, true);
|
||||
}// show(Command)
|
||||
|
||||
|
||||
@@ -139,17 +123,18 @@ public class DeckEditorQuest extends DeckEditorBase implements NewConstants {
|
||||
*/
|
||||
public void setup() {
|
||||
List<TableColumnInfo<CardPrinted>> columns = new ArrayList<TableColumnInfo<CardPrinted>>();
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Qty", 30, CardColumnPresets.fnQtyCompare, CardColumnPresets.fnQtyGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Name", 180, CardColumnPresets.fnNameCompare, CardColumnPresets.fnNameGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Cost", 70, CardColumnPresets.fnCostCompare, CardColumnPresets.fnCostGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Color", 50, CardColumnPresets.fnColorCompare, CardColumnPresets.fnColorGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Type", 100, CardColumnPresets.fnTypeCompare, CardColumnPresets.fnTypeGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Stats", 40, CardColumnPresets.fnStatsCompare, CardColumnPresets.fnStatsGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("R", 35, CardColumnPresets.fnRarityCompare, CardColumnPresets.fnRarityGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Set", 40, CardColumnPresets.fnSetCompare, CardColumnPresets.fnSetGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Qty", 30, PresetColumns.fnQtyCompare, PresetColumns.fnQtyGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Name", 180, PresetColumns.fnNameCompare, PresetColumns.fnNameGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Cost", 70, PresetColumns.fnCostCompare, PresetColumns.fnCostGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Color", 50, PresetColumns.fnColorCompare, PresetColumns.fnColorGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Type", 100, PresetColumns.fnTypeCompare, PresetColumns.fnTypeGet));
|
||||
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>("Set", 40, PresetColumns.fnSetCompare, PresetColumns.fnSetGet));
|
||||
// Add NEW column here
|
||||
setupTables(columns, true);
|
||||
|
||||
top.setup(columns, cardView);
|
||||
bottom.setup(columns, cardView);
|
||||
|
||||
setSize(1024, 768);
|
||||
this.setResizable(false);
|
||||
@@ -168,8 +153,11 @@ public class DeckEditorQuest extends DeckEditorBase implements NewConstants {
|
||||
}// setupAndDisplay()
|
||||
|
||||
public DeckEditorQuest() {
|
||||
super(true, false);
|
||||
try {
|
||||
filterBoxes = new FilterCheckBoxes(false);
|
||||
top = new TableWithCards("All Cards", true);
|
||||
bottom = new TableWithCards("Your deck", true);
|
||||
cardView = new CardPanelHeavy();
|
||||
jbInit();
|
||||
} catch (Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
@@ -178,11 +166,10 @@ public class DeckEditorQuest extends DeckEditorBase implements NewConstants {
|
||||
|
||||
|
||||
private void jbInit() throws Exception {
|
||||
this.setLayout(null);
|
||||
|
||||
jbInitTables("All Cards", "Your deck");
|
||||
|
||||
jScrollPane1.setBounds(new Rectangle(19, 20, 726, 346));
|
||||
jScrollPane2.setBounds(new Rectangle(19, 458, 726, 218));
|
||||
top.getTableDecorated().setBounds(new Rectangle(19, 20, 726, 346));
|
||||
bottom.getTableDecorated().setBounds(new Rectangle(19, 458, 726, 218));
|
||||
|
||||
removeButton.setBounds(new Rectangle(180, 403, 146, 49));
|
||||
// removeButton.setIcon(upIcon);
|
||||
@@ -215,9 +202,6 @@ public class DeckEditorQuest extends DeckEditorBase implements NewConstants {
|
||||
analysisButton.setFont(new java.awt.Font("Dialog", 0, 13));
|
||||
analysisButton.setBounds(new Rectangle(578, 426, 166, 25));
|
||||
|
||||
cardView.jbInit();
|
||||
|
||||
|
||||
/**
|
||||
* Type filtering
|
||||
*/
|
||||
@@ -255,30 +239,25 @@ public class DeckEditorQuest extends DeckEditorBase implements NewConstants {
|
||||
* Other
|
||||
*/
|
||||
cardView.setBounds(new Rectangle(765, 23, 239, 687));
|
||||
top.getLabel().setBounds(new Rectangle(19, 365, 720, 31));
|
||||
bottom.getLabel().setBounds(new Rectangle(19, 672, 720, 31));
|
||||
|
||||
if (!OldGuiNewGame.useLAFFonts.isSelected())
|
||||
statsLabel.setFont(new java.awt.Font("Dialog", 0, 14));
|
||||
statsLabel.setText("Total - 0, Creatures - 0 Land - 0");
|
||||
statsLabel.setBounds(new Rectangle(19, 672, 720, 31));
|
||||
// Do not lower statsLabel any lower, we want this to be visible at 1024
|
||||
// x 768 screen size
|
||||
this.setTitle("Deck Editor");
|
||||
gridLayout1.setColumns(1);
|
||||
gridLayout1.setRows(0);
|
||||
statsLabel2.setBounds(new Rectangle(19, 365, 720, 31));
|
||||
statsLabel2.setText("Total - 0, Creatures - 0 Land - 0");
|
||||
if (!OldGuiNewGame.useLAFFonts.isSelected())
|
||||
statsLabel2.setFont(new java.awt.Font("Dialog", 0, 14));
|
||||
|
||||
jLabel1.setText("Click on the column name (like name or color) to sort the cards");
|
||||
jLabel1.setBounds(new Rectangle(20, 1, 400, 19));
|
||||
|
||||
this.getContentPane().add(jScrollPane1, null);
|
||||
this.getContentPane().add(jScrollPane2, null);
|
||||
this.getContentPane().add(top.getTableDecorated(), null);
|
||||
this.getContentPane().add(bottom.getTableDecorated(), null);
|
||||
this.getContentPane().add(addButton, null);
|
||||
this.getContentPane().add(removeButton, null);
|
||||
this.getContentPane().add(analysisButton, null);
|
||||
this.getContentPane().add(statsLabel2, null);
|
||||
this.getContentPane().add(statsLabel, null);
|
||||
this.getContentPane().add(bottom.getLabel(), null);
|
||||
this.getContentPane().add(top.getLabel(), null);
|
||||
this.getContentPane().add(jLabel1, null);
|
||||
this.getContentPane().add(cardView, null);
|
||||
|
||||
@@ -292,37 +271,31 @@ public class DeckEditorQuest extends DeckEditorBase implements NewConstants {
|
||||
}
|
||||
|
||||
|
||||
final void addButtonActionPerformed(final ActionEvent e) {
|
||||
private void addButtonActionPerformed(final ActionEvent e) {
|
||||
CardPrinted card = top.getSelectedCard();
|
||||
if (card == null) { return; }
|
||||
|
||||
setTitle("Deck Editor : " + customMenu.getDeckName() + " : unsaved");
|
||||
|
||||
int n = topTable.getSelectedRow();
|
||||
if (n == -1) { return; }
|
||||
|
||||
CardPrinted c = topModel.rowToCard(n).getKey();
|
||||
bottomModel.addCard(c);
|
||||
bottomModel.resort();
|
||||
|
||||
// remove from cardpool
|
||||
top.remove(c);
|
||||
|
||||
// redraw top after deletion
|
||||
updateDisplay();
|
||||
fixSelection(topModel, topTable, n);
|
||||
top.removeCard(card);
|
||||
bottom.addCard(card);
|
||||
}
|
||||
|
||||
|
||||
final void removeButtonActionPerformed(final ActionEvent e) {
|
||||
private void removeButtonActionPerformed(final ActionEvent e) {
|
||||
CardPrinted card = bottom.getSelectedCard();
|
||||
if (card == null) { return; }
|
||||
|
||||
setTitle("Deck Editor : " + customMenu.getDeckName() + " : unsaved");
|
||||
|
||||
int n = bottomTable.getSelectedRow();
|
||||
if (n == -1) { return; }
|
||||
top.addCard(card);
|
||||
bottom.removeCard(card);
|
||||
}
|
||||
|
||||
CardPrinted c = bottomModel.rowToCard(n).getKey();
|
||||
bottomModel.removeCard(c);
|
||||
fixSelection(bottomModel, bottomTable, n);
|
||||
|
||||
top.add(c);
|
||||
updateDisplay();
|
||||
public void addCheatCard(CardPrinted card) {
|
||||
top.addCard(card);
|
||||
AllZone.getQuestData().getCardpool().add(card);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -135,7 +135,6 @@ public class DeckEditorQuestMenu extends JMenuBar {
|
||||
|
||||
deck.setName(filename.getName());
|
||||
|
||||
|
||||
try {
|
||||
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(filename));
|
||||
out.writeObject(deck);
|
||||
@@ -335,9 +334,7 @@ public class DeckEditorQuestMenu extends JMenuBar {
|
||||
if (c.show()) {
|
||||
String cardName = c.getSelectedValue();
|
||||
DeckEditorQuest g = (DeckEditorQuest) deckDisplay;
|
||||
g.getTop().add(CardDb.instance().getCard(cardName));
|
||||
AllZone.getQuestData().getCardpool().add(CardDb.instance().getCard(cardName));
|
||||
g.updateDisplay();
|
||||
g.addCheatCard(CardDb.instance().getCard(cardName));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -23,11 +23,11 @@ import net.slightlymagic.braids.util.lambda.Lambda1;
|
||||
|
||||
import forge.Command;
|
||||
import forge.ReadPriceList;
|
||||
import forge.card.CardPool;
|
||||
import forge.card.CardPoolView;
|
||||
import forge.card.CardPrinted;
|
||||
import forge.deck.Deck;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.quest.data.QuestData;
|
||||
import forge.view.swing.OldGuiNewGame;
|
||||
|
||||
/**
|
||||
@@ -38,7 +38,7 @@ import forge.view.swing.OldGuiNewGame;
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class CardShop extends DeckEditorBase {
|
||||
public class DeckEditorShop extends DeckEditorBase {
|
||||
|
||||
/** Constant <code>serialVersionUID=3988857075791576483L</code> */
|
||||
private static final long serialVersionUID = 3988857075791576483L;
|
||||
@@ -55,7 +55,7 @@ public class CardShop extends DeckEditorBase {
|
||||
|
||||
private double multiplier;
|
||||
|
||||
private forge.quest.data.QuestData questData;
|
||||
private QuestData questData;
|
||||
|
||||
// get pricelist:
|
||||
private ReadPriceList r = new ReadPriceList();
|
||||
@@ -63,20 +63,6 @@ public class CardShop extends DeckEditorBase {
|
||||
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void setDecks(CardPoolView topParam, CardPoolView bottomParam) {
|
||||
this.top = new CardPool(topParam);
|
||||
this.bottom = bottomParam;
|
||||
|
||||
topModel.clear();
|
||||
bottomModel.clear();
|
||||
|
||||
// update top
|
||||
topModel.addCards(topParam);
|
||||
bottomModel.addCards(bottomParam);
|
||||
|
||||
topModel.resort();
|
||||
bottomModel.resort();
|
||||
}// updateDisplay
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -91,7 +77,7 @@ public class CardShop extends DeckEditorBase {
|
||||
private static final long serialVersionUID = -7428793574300520612L;
|
||||
|
||||
public void execute() {
|
||||
CardShop.this.dispose();
|
||||
DeckEditorShop.this.dispose();
|
||||
exitCommand.execute();
|
||||
}
|
||||
};
|
||||
@@ -125,8 +111,8 @@ public class CardShop extends DeckEditorBase {
|
||||
if (maxSellPrice < Integer.MAX_VALUE) { maxSellingPrice = String.format(" Max selling price: %d", maxSellPrice); }
|
||||
sellPercentageLabel.setText("(Sell percentage: " + formatter.format(multiPercent) + "% of value)" + maxSellingPrice);
|
||||
|
||||
topModel.sort(1, true);
|
||||
bottomModel.sort(1, true);
|
||||
top.sort(1, true);
|
||||
bottom.sort(1, true);
|
||||
}// show(Command)
|
||||
|
||||
/**
|
||||
@@ -136,17 +122,18 @@ public class CardShop extends DeckEditorBase {
|
||||
*/
|
||||
private void setup() {
|
||||
List<TableColumnInfo<CardPrinted>> columns = new ArrayList<TableColumnInfo<CardPrinted>>();
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Qty", 30, CardColumnPresets.fnQtyCompare, CardColumnPresets.fnQtyGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Name", 180, CardColumnPresets.fnNameCompare, CardColumnPresets.fnNameGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Cost", 70, CardColumnPresets.fnCostCompare, CardColumnPresets.fnCostGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Color", 50, CardColumnPresets.fnColorCompare, CardColumnPresets.fnColorGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Type", 100, CardColumnPresets.fnTypeCompare, CardColumnPresets.fnTypeGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Stats", 40, CardColumnPresets.fnStatsCompare, CardColumnPresets.fnStatsGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("R", 35, CardColumnPresets.fnRarityCompare, CardColumnPresets.fnRarityGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Set", 40, CardColumnPresets.fnSetCompare, CardColumnPresets.fnSetGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Qty", 30, PresetColumns.fnQtyCompare, PresetColumns.fnQtyGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Name", 180, PresetColumns.fnNameCompare, PresetColumns.fnNameGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Cost", 70, PresetColumns.fnCostCompare, PresetColumns.fnCostGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Color", 50, PresetColumns.fnColorCompare, PresetColumns.fnColorGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Type", 100, PresetColumns.fnTypeCompare, PresetColumns.fnTypeGet));
|
||||
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>("Set", 40, PresetColumns.fnSetCompare, PresetColumns.fnSetGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Price", 40, fnPriceCompare, fnPriceGet));
|
||||
|
||||
setupTables(columns, false);
|
||||
top.setup(columns, cardView);
|
||||
bottom.setup(columns, cardView);
|
||||
|
||||
setSize(1024, 768);
|
||||
this.setResizable(false);
|
||||
@@ -171,10 +158,13 @@ public class CardShop extends DeckEditorBase {
|
||||
* @param qd
|
||||
* a {@link forge.quest.data.QuestData} object.
|
||||
*/
|
||||
public CardShop(forge.quest.data.QuestData qd) {
|
||||
super(false, false);
|
||||
public DeckEditorShop(forge.quest.data.QuestData qd) {
|
||||
questData = qd;
|
||||
try {
|
||||
filterBoxes = null;
|
||||
top = new TableWithCards("Cards for sale", false);
|
||||
bottom = new TableWithCards("Owned Cards", false);
|
||||
cardView = new CardPanelLite();
|
||||
jbInit();
|
||||
} catch (Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
@@ -192,10 +182,9 @@ public class CardShop extends DeckEditorBase {
|
||||
*/
|
||||
private void jbInit() throws Exception {
|
||||
|
||||
jbInitTables("Cards for sale", "Owned Cards");
|
||||
|
||||
jScrollPane1.setBounds(new Rectangle(19, 20, 726, 346));
|
||||
jScrollPane2.setBounds(new Rectangle(19, 458, 726, 276));
|
||||
this.setLayout(null);
|
||||
top.getTableDecorated().setBounds(new Rectangle(19, 20, 726, 346));
|
||||
bottom.getTableDecorated().setBounds(new Rectangle(19, 458, 726, 276));
|
||||
|
||||
sellButton.setBounds(new Rectangle(180, 403, 146, 49));
|
||||
// removeButton.setIcon(upIcon);
|
||||
@@ -218,7 +207,6 @@ public class CardShop extends DeckEditorBase {
|
||||
buyButton.setFont(new java.awt.Font("Dialog", 0, 13));
|
||||
buyButton.setBounds(new Rectangle(23, 403, 146, 49));
|
||||
|
||||
cardView.jbInit();
|
||||
cardView.setBounds(new Rectangle(765, 23, 239, 710));
|
||||
// Do not lower statsLabel any lower, we want this to be visible at 1024
|
||||
// x 768 screen size
|
||||
@@ -240,8 +228,8 @@ public class CardShop extends DeckEditorBase {
|
||||
jLabel1.setText("Click on the column name (like name or color) to sort the cards");
|
||||
jLabel1.setBounds(new Rectangle(20, 1, 400, 19));
|
||||
this.getContentPane().add(cardView, null);
|
||||
this.getContentPane().add(jScrollPane1, null);
|
||||
this.getContentPane().add(jScrollPane2, null);
|
||||
this.getContentPane().add(top.getTableDecorated(), null);
|
||||
this.getContentPane().add(bottom.getTableDecorated(), null);
|
||||
this.getContentPane().add(creditsLabel, null);
|
||||
this.getContentPane().add(buyButton, null);
|
||||
this.getContentPane().add(sellButton, null);
|
||||
@@ -266,27 +254,22 @@ public class CardShop extends DeckEditorBase {
|
||||
}
|
||||
|
||||
private void buyButton_actionPerformed(ActionEvent e) {
|
||||
int n = topTable.getSelectedRow();
|
||||
if (n != -1) {
|
||||
CardPrinted c = topModel.rowToCard(n).getKey();
|
||||
CardPrinted c = top.getSelectedCard();
|
||||
if (c == null) { return; }
|
||||
|
||||
int value = getCardValue(c);
|
||||
|
||||
if (value <= questData.getCredits()) {
|
||||
bottomModel.addCard(c);
|
||||
bottomModel.resort();
|
||||
|
||||
topModel.removeCard(c);
|
||||
bottom.addCard(c);
|
||||
top.removeCard(c);
|
||||
|
||||
questData.buyCard(c, value);
|
||||
|
||||
creditsLabel.setText("Total credits: " + questData.getCredits());
|
||||
fixSelection(topModel, topTable, n);
|
||||
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "Not enough credits!");
|
||||
}
|
||||
}// if(valid row)
|
||||
}// buyButton_actionPerformed
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -297,21 +280,16 @@ public class CardShop extends DeckEditorBase {
|
||||
* a {@link java.awt.event.ActionEvent} object.
|
||||
*/
|
||||
void sellButton_actionPerformed(ActionEvent e) {
|
||||
CardPrinted c = bottom.getSelectedCard();
|
||||
if (c == null) { return; }
|
||||
|
||||
int n = bottomTable.getSelectedRow();
|
||||
if (n != -1) {
|
||||
CardPrinted c = bottomModel.rowToCard(n).getKey();
|
||||
bottomModel.removeCard(c);
|
||||
|
||||
topModel.addCard(c);
|
||||
topModel.resort();
|
||||
|
||||
// bottomModel.removeCard(c);
|
||||
questData.addCardToShopList(c);
|
||||
bottom.removeCard(c);
|
||||
top.addCard(c);
|
||||
|
||||
int price = Math.min((int) (multiplier * getCardValue(c)), questData.getSellPriceLimit());
|
||||
|
||||
questData.sellCard(c, price);
|
||||
questData.addCardToShopList(c);
|
||||
|
||||
creditsLabel.setText("Total credits: " + questData.getCredits());
|
||||
|
||||
int leftInPool = questData.getCardpool().count(c);
|
||||
@@ -322,19 +300,14 @@ public class CardShop extends DeckEditorBase {
|
||||
deck.removeMain(c);
|
||||
}
|
||||
}
|
||||
|
||||
fixSelection(bottomModel, bottomTable, n);
|
||||
|
||||
}// if(valid row)
|
||||
}// sellButton_actionPerformed
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected final Lambda1<Comparable, Entry<CardPrinted, Integer>> fnPriceCompare =
|
||||
private final Lambda1<Comparable, Entry<CardPrinted, Integer>> fnPriceCompare =
|
||||
new Lambda1<Comparable, Entry<CardPrinted, Integer>>() { @Override
|
||||
public Comparable apply(final Entry<CardPrinted, Integer> from) { return getCardValue(from.getKey()); } };
|
||||
protected final Lambda1<Object, Entry<CardPrinted, Integer>> fnPriceGet =
|
||||
private final Lambda1<Object, Entry<CardPrinted, Integer>> fnPriceGet =
|
||||
new Lambda1<Object, Entry<CardPrinted, Integer>>() { @Override
|
||||
public Object apply(final Entry<CardPrinted, Integer> from) { return getCardValue(from.getKey()); } };
|
||||
|
||||
|
||||
}
|
||||
@@ -1,416 +0,0 @@
|
||||
package forge.gui.deckeditor;
|
||||
|
||||
import forge.AllZone;
|
||||
import forge.BoosterDraft;
|
||||
import forge.Constant;
|
||||
import forge.FileUtil;
|
||||
import forge.HttpUtil;
|
||||
import forge.card.CardPoolView;
|
||||
import forge.card.CardPrinted;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckManager;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
import forge.view.swing.OldGuiNewGame;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.TitledBorder;
|
||||
import javax.swing.event.TableModelEvent;
|
||||
import javax.swing.event.TableModelListener;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Gui_BoosterDraft class.</p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class Gui_BoosterDraft extends JFrame implements NewConstants, NewConstants.LANG.Gui_BoosterDraft {
|
||||
/**
|
||||
* Constant <code>serialVersionUID=-6055633915602448260L</code>
|
||||
*/
|
||||
private static final long serialVersionUID = -6055633915602448260L;
|
||||
|
||||
private BoosterDraft boosterDraft;
|
||||
|
||||
/**
|
||||
* Constant <code>limitedDeckEditor=true</code>
|
||||
*/
|
||||
private static final boolean limitedDeckEditor = true;
|
||||
|
||||
private TableModel allCardModel;
|
||||
private TableModel deckModel;
|
||||
|
||||
private JScrollPane jScrollPane1 = new JScrollPane();
|
||||
private JScrollPane jScrollPane2 = new JScrollPane();
|
||||
private TitledBorder titledBorder1;
|
||||
private TitledBorder titledBorder2;
|
||||
|
||||
private JLabel statsLabel = new JLabel();
|
||||
private JTable allCardTable = new JTable();
|
||||
private JTable deckTable = new JTable();
|
||||
private JScrollPane jScrollPane3 = new JScrollPane();
|
||||
private JPanel jPanel3 = new JPanel();
|
||||
private GridLayout gridLayout1 = new GridLayout();
|
||||
private JLabel statsLabel2 = new JLabel();
|
||||
private JButton jButton1 = new JButton();
|
||||
|
||||
private CardViewPanelLite cardView = new CardViewPanelLite();
|
||||
|
||||
/**
|
||||
* <p>showGui.</p>
|
||||
*
|
||||
* @param in_boosterDraft a {@link forge.BoosterDraft} object.
|
||||
*/
|
||||
public void showGui(BoosterDraft in_boosterDraft) {
|
||||
boosterDraft = in_boosterDraft;
|
||||
|
||||
setup();
|
||||
showChoices(boosterDraft.nextChoice());
|
||||
|
||||
allCardModel.sort(1, true);
|
||||
deckModel.sort(1, true);
|
||||
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>addListeners.</p>
|
||||
*/
|
||||
private void addListeners() {
|
||||
this.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent ev) {
|
||||
int n = JOptionPane.showConfirmDialog(null, ForgeProps.getLocalized(CLOSE_MESSAGE), "",
|
||||
JOptionPane.YES_NO_OPTION);
|
||||
if (n == JOptionPane.YES_OPTION) {
|
||||
dispose();
|
||||
new OldGuiNewGame();
|
||||
}
|
||||
}//windowClosing()
|
||||
});
|
||||
}//addListeners()
|
||||
|
||||
/**
|
||||
* <p>setup.</p>
|
||||
*/
|
||||
private void setup() {
|
||||
addListeners();
|
||||
// setupMenu();
|
||||
|
||||
|
||||
List<TableColumnInfo<CardPrinted>> columns = new ArrayList<TableColumnInfo<CardPrinted>>();
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Qty", 30, CardColumnPresets.fnQtyCompare, CardColumnPresets.fnQtyGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Name", 180, CardColumnPresets.fnNameCompare, CardColumnPresets.fnNameGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Cost", 70, CardColumnPresets.fnCostCompare, CardColumnPresets.fnCostGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Color", 50, CardColumnPresets.fnColorCompare, CardColumnPresets.fnColorGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Type", 100, CardColumnPresets.fnTypeCompare, CardColumnPresets.fnTypeGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Stats", 40, CardColumnPresets.fnStatsCompare, CardColumnPresets.fnStatsGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("R", 35, CardColumnPresets.fnRarityCompare, CardColumnPresets.fnRarityGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("Set", 40, CardColumnPresets.fnSetCompare, CardColumnPresets.fnSetGet));
|
||||
columns.add(new TableColumnInfo<CardPrinted>("AI", 30, CardColumnPresets.fnAiStatusCompare, CardColumnPresets.fnAiStatusGet));
|
||||
|
||||
//construct allCardTable, get all cards
|
||||
allCardModel = new TableModel(cardView, columns);
|
||||
allCardModel.addListeners(allCardTable);
|
||||
allCardTable.setModel(allCardModel);
|
||||
allCardModel.resizeCols(allCardTable);
|
||||
|
||||
//construct deckModel
|
||||
deckModel = new TableModel(cardView, columns);
|
||||
deckModel.addListeners(deckTable);
|
||||
deckTable.setModel(deckModel);
|
||||
deckModel.resizeCols(deckTable);
|
||||
|
||||
//add cards to GUI from deck
|
||||
// refreshGui();
|
||||
|
||||
allCardTable.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(final MouseEvent e) {
|
||||
if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0) jButton1_actionPerformed(null);
|
||||
}
|
||||
});//MouseListener
|
||||
|
||||
|
||||
//get stats from deck
|
||||
deckModel.addTableModelListener(new TableModelListener() {
|
||||
public void tableChanged(TableModelEvent ev) {
|
||||
statsLabel.setText(getStats(deckModel.getCards()));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//get stats from all cards
|
||||
allCardModel.addTableModelListener(new TableModelListener() {
|
||||
public void tableChanged(TableModelEvent ev) {
|
||||
|
||||
statsLabel2.setText(getStats(allCardModel.getCards()));
|
||||
}
|
||||
});
|
||||
|
||||
//Use both so that when "un"maximizing, the frame isn't tiny
|
||||
setSize(1024, 740);
|
||||
//setExtendedState(Frame.MAXIMIZED_BOTH);
|
||||
}//setupAndDisplay()
|
||||
|
||||
|
||||
private String getStats(final CardPoolView deck) {
|
||||
return DeckEditorBase.getStats(deck);
|
||||
}
|
||||
|
||||
public Gui_BoosterDraft() {
|
||||
try {
|
||||
jbInit();
|
||||
} catch (Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>jbInit.</p>
|
||||
*
|
||||
* @throws java.lang.Exception if any.
|
||||
*/
|
||||
private void jbInit() throws Exception {
|
||||
titledBorder1 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white, new Color(148, 145, 140)),
|
||||
"Previously Picked Cards");
|
||||
titledBorder2 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white, new Color(148, 145, 140)),
|
||||
"Choose one card");
|
||||
|
||||
this.getContentPane().setLayout(null);
|
||||
jScrollPane1.setBorder(titledBorder2);
|
||||
jScrollPane1.setBounds(new Rectangle(19, 28, 661, 344));
|
||||
jScrollPane2.setBorder(titledBorder1);
|
||||
jScrollPane2.setBounds(new Rectangle(19, 478, 661, 184));
|
||||
|
||||
cardView.jbInit();
|
||||
cardView.setBounds(new Rectangle(693, 23, 239, 665));
|
||||
|
||||
statsLabel.setFont(new java.awt.Font("Dialog", 0, 16));
|
||||
statsLabel.setText("Total - 0, Creatures - 0 Land - 0");
|
||||
statsLabel.setBounds(new Rectangle(19, 665, 665, 31));
|
||||
this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||
this.setTitle("Booster Draft");
|
||||
jScrollPane3.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
||||
jScrollPane3.setBounds(new Rectangle(6, 168, 225, 143));
|
||||
jPanel3.setBounds(new Rectangle(7, 21, 224, 141));
|
||||
jPanel3.setLayout(gridLayout1);
|
||||
gridLayout1.setColumns(1);
|
||||
gridLayout1.setRows(0);
|
||||
statsLabel2.setBounds(new Rectangle(19, 378, 665, 31));
|
||||
statsLabel2.setText("Total - 0, Creatures - 0 Land - 0");
|
||||
statsLabel2.setFont(new java.awt.Font("Dialog", 0, 16));
|
||||
jButton1.setBounds(new Rectangle(238, 418, 147, 44));
|
||||
jButton1.setFont(new java.awt.Font("Dialog", 0, 16));
|
||||
jButton1.setText("Choose Card");
|
||||
jButton1.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
jButton1_actionPerformed(e);
|
||||
}
|
||||
});
|
||||
this.getContentPane().add(cardView, null);
|
||||
this.getContentPane().add(jScrollPane1, null);
|
||||
this.getContentPane().add(statsLabel2, null);
|
||||
this.getContentPane().add(statsLabel, null);
|
||||
this.getContentPane().add(jScrollPane2, null);
|
||||
this.getContentPane().add(jButton1, null);
|
||||
jScrollPane2.getViewport().add(deckTable, null);
|
||||
jScrollPane1.getViewport().add(allCardTable, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>addButton_actionPerformed.</p>
|
||||
*
|
||||
* @param e a {@link java.awt.event.ActionEvent} object.
|
||||
*/
|
||||
void addButton_actionPerformed(ActionEvent e) {
|
||||
int n = allCardTable.getSelectedRow();
|
||||
if (n != -1) {
|
||||
setTitle("Deck Editor - " + Constant.Runtime.HumanDeck[0].getName() + " - changed");
|
||||
|
||||
CardPrinted c = allCardModel.rowToCard(n).getKey();
|
||||
deckModel.addCard(c);
|
||||
deckModel.resort();
|
||||
|
||||
allCardModel.removeCard(c);
|
||||
|
||||
//3 conditions" 0 cards left, select the same row, select next row
|
||||
int size = allCardModel.getRowCount();
|
||||
if (size != 0) {
|
||||
if (size == n) n--;
|
||||
allCardTable.addRowSelectionInterval(n, n);
|
||||
}
|
||||
}//if(valid row)
|
||||
}//addButton_actionPerformed
|
||||
|
||||
/**
|
||||
* <p>removeButton_actionPerformed.</p>
|
||||
*
|
||||
* @param e a {@link java.awt.event.ActionEvent} object.
|
||||
*/
|
||||
void removeButton_actionPerformed(ActionEvent e) {
|
||||
int n = deckTable.getSelectedRow();
|
||||
if (n != -1) {
|
||||
setTitle("Deck Editor - " + Constant.Runtime.HumanDeck[0].getName() + " - changed");
|
||||
|
||||
CardPrinted c = deckModel.rowToCard(n).getKey();
|
||||
deckModel.removeCard(c);
|
||||
|
||||
if (limitedDeckEditor) {
|
||||
allCardModel.addCard(c);
|
||||
allCardModel.resort();
|
||||
}
|
||||
|
||||
//3 conditions" 0 cards left, select the same row, select next row
|
||||
int size = deckModel.getRowCount();
|
||||
if (size != 0) {
|
||||
if (size == n) n--;
|
||||
deckTable.addRowSelectionInterval(n, n);
|
||||
}
|
||||
}//if(valid row)
|
||||
}//removeButton_actionPerformed
|
||||
|
||||
//if true, don't do anything else
|
||||
|
||||
|
||||
/**
|
||||
* <p>refreshDeck.</p>
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
// refreshDeck
|
||||
private void refreshDeck() {
|
||||
//make new Deck
|
||||
Deck deck = new Deck(Constant.Runtime.GameType[0]);
|
||||
deck.setName(Constant.Runtime.HumanDeck[0].getName());
|
||||
Constant.Runtime.HumanDeck[0] = deck;
|
||||
|
||||
//update Deck with cards shown in GUI
|
||||
|
||||
deck.addMain(deckModel.getCards());
|
||||
if (deck.isSealed()) {
|
||||
deck.addSideboard(allCardModel.getCards());
|
||||
}
|
||||
}/* refreshDeck() */
|
||||
|
||||
/**
|
||||
* <p>jButton1_actionPerformed.</p>
|
||||
*
|
||||
* @param e a {@link java.awt.event.ActionEvent} object.
|
||||
*/
|
||||
void jButton1_actionPerformed(ActionEvent e) {
|
||||
//pick card
|
||||
int n = allCardTable.getSelectedRow();
|
||||
if (n == -1) //is valid selection?
|
||||
return;
|
||||
|
||||
CardPrinted c = allCardModel.rowToCard(n).getKey();
|
||||
|
||||
deckModel.addCard(c);
|
||||
deckModel.resort();
|
||||
|
||||
//get next booster pack
|
||||
boosterDraft.setChoice(c);
|
||||
if (boosterDraft.hasNextChoice()) {
|
||||
showChoices(boosterDraft.nextChoice());
|
||||
} else {
|
||||
if (Constant.Runtime.UpldDrft[0]) {
|
||||
if (BoosterDraft.draftPicks.size() > 1) {
|
||||
ArrayList<String> outDraftData = new ArrayList<String>();
|
||||
|
||||
String keys[] = {""};
|
||||
keys = BoosterDraft.draftPicks.keySet().toArray(keys);
|
||||
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
outDraftData.add(keys[i] + "|" + BoosterDraft.draftPicks.get(keys[i]));
|
||||
}
|
||||
|
||||
FileUtil.writeFile("res/draft/tmpDraftData.txt", outDraftData);
|
||||
|
||||
HttpUtil poster = new HttpUtil();
|
||||
poster.upload("http://cardforge.org/draftAI/submitDraftData.php?fmt=" + BoosterDraft.draftFormat[0], "res/draft/tmpDraftData.txt");
|
||||
}
|
||||
}
|
||||
|
||||
//quit
|
||||
saveDraft();
|
||||
dispose();
|
||||
}
|
||||
}/*OK Button*/
|
||||
|
||||
/**
|
||||
* <p>showChoices.</p>
|
||||
*
|
||||
* @param list a {@link forge.CardList} object.
|
||||
*/
|
||||
private void showChoices(CardPoolView list) {
|
||||
allCardModel.clear();
|
||||
allCardModel.addCards(list);
|
||||
allCardModel.resort();
|
||||
allCardTable.setRowSelectionInterval(0, 0);
|
||||
|
||||
}//showChoices()
|
||||
|
||||
/**
|
||||
* <p>getPlayersDeck.</p>
|
||||
*
|
||||
* @return a {@link forge.deck.Deck} object.
|
||||
*/
|
||||
private Deck getPlayersDeck() {
|
||||
Deck deck = new Deck(Constant.GameType.Draft);
|
||||
Constant.Runtime.HumanDeck[0] = deck;
|
||||
|
||||
//add sideboard to deck
|
||||
CardPoolView list = deckModel.getCards();
|
||||
deck.addSideboard(list);
|
||||
|
||||
for (int i = 0; i < 20; i++) {
|
||||
deck.addSideboard("Forest|" + BoosterDraft.LandSetCode[0]);
|
||||
deck.addSideboard("Mountain|" + BoosterDraft.LandSetCode[0]);
|
||||
deck.addSideboard("Swamp|" + BoosterDraft.LandSetCode[0]);
|
||||
deck.addSideboard("Island|" + BoosterDraft.LandSetCode[0]);
|
||||
deck.addSideboard("Plains|" + BoosterDraft.LandSetCode[0]);
|
||||
}
|
||||
|
||||
return deck;
|
||||
}//getPlayersDeck()
|
||||
|
||||
/**
|
||||
* <p>saveDraft.</p>
|
||||
*/
|
||||
private void saveDraft() {
|
||||
String s = "";
|
||||
while (s == null || s.length() == 0) {
|
||||
s = JOptionPane.showInputDialog(null, ForgeProps.getLocalized(SAVE_DRAFT_MESSAGE),
|
||||
ForgeProps.getLocalized(SAVE_DRAFT_TITLE), JOptionPane.QUESTION_MESSAGE);
|
||||
}
|
||||
//TODO: check if overwriting the same name, and let the user delete old drafts
|
||||
|
||||
//construct computer's decks
|
||||
//save draft
|
||||
Deck[] computer = boosterDraft.getDecks();
|
||||
|
||||
Deck human = getPlayersDeck();
|
||||
human.setName(s);
|
||||
|
||||
Deck[] all = {
|
||||
human, computer[0], computer[1], computer[2], computer[3], computer[4], computer[5], computer[6]};
|
||||
|
||||
//DeckManager deckManager = new DeckManager(ForgeProps.getFile(NEW_DECKS));
|
||||
DeckManager deckManager = AllZone.getDeckManager();
|
||||
deckManager.addDraftDeck(all);
|
||||
|
||||
//write file
|
||||
deckManager.close();
|
||||
|
||||
//close and open next screen
|
||||
dispose();
|
||||
new OldGuiNewGame();
|
||||
}/*saveDraft()*/
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import forge.card.CardPrinted;
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public abstract class CardColumnPresets {
|
||||
public abstract class PresetColumns {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static final Lambda1<Comparable, Entry<CardPrinted, Integer>> fnQtyCompare =
|
||||
@@ -9,8 +9,6 @@ import javax.swing.table.AbstractTableModel;
|
||||
import javax.swing.table.TableColumn;
|
||||
import javax.swing.table.TableColumnModel;
|
||||
|
||||
import net.slightlymagic.braids.util.lambda.Lambda1;
|
||||
|
||||
import forge.card.CardPool;
|
||||
import forge.card.CardPoolView;
|
||||
import forge.card.CardPrinted;
|
||||
@@ -27,23 +25,21 @@ import java.util.Map.Entry;
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class TableModel extends AbstractTableModel {
|
||||
public final class TableModel extends AbstractTableModel {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -6896726613116254828L;
|
||||
|
||||
@SuppressWarnings("rawtypes") // We use raw comparables to provide fields for sorting
|
||||
|
||||
private final class SortOrders {
|
||||
private class Order {
|
||||
public final int sortColumn;
|
||||
public boolean isSortAsc = true;
|
||||
public Order(int col) { sortColumn = col; }
|
||||
public Order(final int col) { sortColumn = col; }
|
||||
};
|
||||
|
||||
private final int MAX_DEPTH = 3;
|
||||
Order[] orders = new Order[] {null, null, null};
|
||||
private Order[] orders = new Order[] {null, null, null};
|
||||
private TableSorterCascade sorter = null;
|
||||
private boolean isSorterReady = false;
|
||||
private int indexOfColumn(final int column) {
|
||||
@@ -57,7 +53,7 @@ public class TableModel extends AbstractTableModel {
|
||||
}
|
||||
|
||||
// index of column to sort by, desired direction
|
||||
public void add(final int column, boolean wantAsc) {
|
||||
public void add(final int column, final boolean wantAsc) {
|
||||
add(column);
|
||||
orders[0].isSortAsc = wantAsc;
|
||||
isSorterReady = false;
|
||||
@@ -100,34 +96,17 @@ public class TableModel extends AbstractTableModel {
|
||||
}
|
||||
|
||||
private CardPool data = new CardPool();
|
||||
private final CardDisplay cardDisplay;
|
||||
private final CardPanelBase cardDisplay;
|
||||
private final List<TableColumnInfo<CardPrinted>> columns;
|
||||
private final SortOrders sortOrders = new SortOrders();
|
||||
|
||||
public TableModel(final CardDisplay cd, List<TableColumnInfo<CardPrinted>> columnsToShow ) {
|
||||
public TableModel(final CardPanelBase cd, final List<TableColumnInfo<CardPrinted>> columnsToShow) {
|
||||
cardDisplay = cd;
|
||||
columns = columnsToShow;
|
||||
columns.get(4).isMinMaxApplied = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private final TableColumnInfo<CardPrinted> columnAI = new TableColumnInfo<CardPrinted>("AI", 30,
|
||||
new Lambda1<Comparable, Entry<CardPrinted, Integer>>() {
|
||||
@Override public Comparable apply(final Entry<CardPrinted, Integer> from) {
|
||||
return "n/a"; } },
|
||||
new Lambda1<Object, Entry<CardPrinted, Integer>>() {
|
||||
@Override public Object apply(final Entry<CardPrinted, Integer> from) {
|
||||
return "n/a"; } });
|
||||
|
||||
/*
|
||||
columnQty, columnName, columnCost,
|
||||
columnColor, columnType, columnStats,
|
||||
columnRarity, columnSet, columnAI
|
||||
*/
|
||||
|
||||
|
||||
public void resizeCols(final JTable table) {
|
||||
TableColumn tableColumn = null;
|
||||
for (int i = 0; i < table.getColumnCount(); i++) {
|
||||
@@ -139,7 +118,7 @@ public class TableModel extends AbstractTableModel {
|
||||
tableColumn.setMinWidth(colInfo.minWidth);
|
||||
tableColumn.setMaxWidth(colInfo.maxWidth);
|
||||
}
|
||||
}//for
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() { data.clear(); }
|
||||
@@ -181,7 +160,8 @@ public class TableModel extends AbstractTableModel {
|
||||
}
|
||||
|
||||
public Entry<CardPrinted, Integer> rowToCard(final int row) {
|
||||
return data.getOrderedList().get(row);
|
||||
List<Entry<CardPrinted, Integer>> model = data.getOrderedList();
|
||||
return row >= 0 && row < model.size() ? model.get(row) : null;
|
||||
}
|
||||
public int getRowCount() {
|
||||
return data.countDistinct();
|
||||
@@ -193,12 +173,12 @@ public class TableModel extends AbstractTableModel {
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public String getColumnName(int n) {
|
||||
public String getColumnName(final int n) {
|
||||
return columns.get(n).getName();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public Object getValueAt(int row, int column) {
|
||||
public Object getValueAt(final int row, final int column) {
|
||||
return columns.get(column).fnDisplay.apply(rowToCard(row));
|
||||
}
|
||||
|
||||
@@ -206,9 +186,9 @@ public class TableModel extends AbstractTableModel {
|
||||
class ColumnListener extends MouseAdapter {
|
||||
protected JTable table;
|
||||
|
||||
public ColumnListener(JTable t) { table = t; }
|
||||
public ColumnListener(final JTable t) { table = t; }
|
||||
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
public void mouseClicked(final MouseEvent e) {
|
||||
TableColumnModel colModel = table.getColumnModel();
|
||||
int columnModelIndex = colModel.getColumnIndexAtX(e.getX());
|
||||
int modelIndex = colModel.getColumn(columnModelIndex).getModelIndex();
|
||||
@@ -230,9 +210,7 @@ public class TableModel extends AbstractTableModel {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void showSelectedCard(JTable table)
|
||||
{
|
||||
public void showSelectedCard(final JTable table) {
|
||||
int row = table.getSelectedRow();
|
||||
if (row != -1) {
|
||||
CardPrinted cp = rowToCard(row).getKey();
|
||||
@@ -250,20 +228,18 @@ public class TableModel extends AbstractTableModel {
|
||||
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
|
||||
|
||||
@Override
|
||||
public void valueChanged(ListSelectionEvent arg0) {
|
||||
public void valueChanged(final ListSelectionEvent arg0) {
|
||||
showSelectedCard(table);
|
||||
}
|
||||
});
|
||||
table.addFocusListener(new FocusListener() {
|
||||
|
||||
@Override public void focusLost(FocusEvent e) {}
|
||||
@Override public void focusGained(FocusEvent e) {
|
||||
@Override public void focusLost(final FocusEvent e) {}
|
||||
@Override public void focusGained(final FocusEvent e) {
|
||||
showSelectedCard(table);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
table.getTableHeader().addMouseListener(new ColumnListener(table));
|
||||
|
||||
}//addCardListener()
|
||||
|
||||
163
src/main/java/forge/gui/deckeditor/TableWithCards.java
Normal file
163
src/main/java/forge/gui/deckeditor/TableWithCards.java
Normal file
@@ -0,0 +1,163 @@
|
||||
package forge.gui.deckeditor;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.border.TitledBorder;
|
||||
import javax.swing.event.TableModelEvent;
|
||||
import javax.swing.event.TableModelListener;
|
||||
|
||||
import net.slightlymagic.maxmtg.Predicate;
|
||||
|
||||
import forge.Constant;
|
||||
import forge.card.CardPool;
|
||||
import forge.card.CardPoolView;
|
||||
import forge.card.CardPrinted;
|
||||
import forge.card.CardRules;
|
||||
import forge.view.swing.OldGuiNewGame;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public final class TableWithCards {
|
||||
|
||||
protected CardPool pool;
|
||||
protected TableModel model;
|
||||
protected JTable table = new JTable();
|
||||
protected JScrollPane jScrollPane = new JScrollPane();
|
||||
protected JLabel statsLabel = new JLabel();
|
||||
protected Predicate<CardRules> filter = null;
|
||||
protected boolean isTrackingStats = false;
|
||||
|
||||
// need this to allow users place its contents
|
||||
public JComponent getTableDecorated() { return jScrollPane; }
|
||||
public JComponent getTable() { return table; }
|
||||
public JComponent getLabel() { return statsLabel; }
|
||||
|
||||
public TableWithCards(final String title, final boolean showStats) {
|
||||
// components
|
||||
Color gray = new Color(148, 145, 140);
|
||||
TitledBorder titledBorder = new TitledBorder(BorderFactory.createEtchedBorder(Color.white, gray), title);
|
||||
|
||||
String tableToolTip = "Click on the column name (like name or color) to sort the cards";
|
||||
jScrollPane.setBorder(titledBorder);
|
||||
jScrollPane.setToolTipText(tableToolTip);
|
||||
jScrollPane.getViewport().add(table, null);
|
||||
|
||||
if (!OldGuiNewGame.useLAFFonts.isSelected()) { statsLabel.setFont(new java.awt.Font("Dialog", 0, 13)); }
|
||||
statsLabel.setText("Total: 0, Creatures: 0, Land: 0");
|
||||
|
||||
// class data
|
||||
isTrackingStats = showStats;
|
||||
}
|
||||
|
||||
public void setup(final List<TableColumnInfo<CardPrinted>> columns, final CardPanelBase cardView)
|
||||
{
|
||||
model = new TableModel(cardView, columns);
|
||||
model.addListeners(table);
|
||||
table.setModel(model);
|
||||
model.resizeCols(table);
|
||||
|
||||
if (isTrackingStats) {
|
||||
// get stats from deck
|
||||
model.addTableModelListener(new TableModelListener() {
|
||||
public void tableChanged(final TableModelEvent ev) {
|
||||
CardPoolView deck = model.getCards();
|
||||
statsLabel.setText(getStats(deck));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// This should not be here, but still found no better place
|
||||
public static String getStats(final CardPoolView deck) {
|
||||
int total = deck.countAll();
|
||||
int creature = CardRules.Predicates.Presets.isCreature.aggregate(deck, CardPoolView.fnToCard, CardPoolView.fnToCount);
|
||||
int land = CardRules.Predicates.Presets.isLand.aggregate(deck, CardPoolView.fnToCard, CardPoolView.fnToCount);
|
||||
|
||||
StringBuffer show = new StringBuffer();
|
||||
show.append("Total - ").append(total).append(", Creatures - ").append(creature).append(", Land - ").append(land);
|
||||
String[] color = Constant.Color.onlyColors;
|
||||
List<Predicate<CardRules>> predicates = CardRules.Predicates.Presets.colors;
|
||||
for (int i = 0; i < color.length; ++i) {
|
||||
show.append(String.format(", %s - %d", color[i], predicates.get(i).count(deck, CardPoolView.fnToCard)));
|
||||
}
|
||||
|
||||
return show.toString();
|
||||
} // getStats()
|
||||
|
||||
public void sort(final int iCol, final boolean isAsc) {
|
||||
model.sort(iCol, isAsc);
|
||||
}
|
||||
|
||||
// Call this after deleting an item from table
|
||||
public void fixSelection(final int rowLastSelected) {
|
||||
// 3 cases: 0 cards left, select the same row, select prev row
|
||||
int newRow = rowLastSelected;
|
||||
int cntRowsAbove = model.getRowCount();
|
||||
if (cntRowsAbove != 0) {
|
||||
if (cntRowsAbove == newRow) { newRow--; } // move selection away from the last, already missing, option
|
||||
table.setRowSelectionInterval(newRow, newRow);
|
||||
}
|
||||
}
|
||||
|
||||
public void setDeck(final Iterable<CardPrinted> cards) {
|
||||
model.clear();
|
||||
pool = new CardPool(cards);
|
||||
model.addCards(pool);
|
||||
updateView();
|
||||
}
|
||||
|
||||
public void setDeck(final CardPoolView poolView) {
|
||||
model.clear();
|
||||
pool = new CardPool(poolView);
|
||||
model.addCards(pool);
|
||||
updateView();
|
||||
}
|
||||
|
||||
public CardPrinted getSelectedCard() {
|
||||
int iRow = table.getSelectedRow();
|
||||
return iRow >= 0 ? model.rowToCard(iRow).getKey() : null;
|
||||
}
|
||||
|
||||
private boolean isUnfiltered() { return filter == null || filter.is1(); }
|
||||
private boolean isFiltered() { return filter != null && !filter.is1(); }
|
||||
|
||||
public void setFilter(final Predicate<CardRules> filterToSet) {
|
||||
filter = filterToSet;
|
||||
updateView();
|
||||
}
|
||||
|
||||
public void addCard(final CardPrinted card) {
|
||||
int n = table.getSelectedRow();
|
||||
pool.add(card);
|
||||
if (isUnfiltered()) { model.addCard(card); }
|
||||
updateView();
|
||||
}
|
||||
|
||||
public void removeCard(final CardPrinted card) {
|
||||
int n = table.getSelectedRow();
|
||||
pool.remove(card);
|
||||
if (isUnfiltered()) { model.removeCard(card); }
|
||||
updateView();
|
||||
fixSelection(n);
|
||||
}
|
||||
|
||||
public void updateView() {
|
||||
if (isFiltered()) {
|
||||
model.clear();
|
||||
model.addCards(filter.select(pool, CardPoolView.fnToCard));
|
||||
}
|
||||
model.resort();
|
||||
}
|
||||
|
||||
public CardPoolView getCards() {
|
||||
return pool;
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ package forge.quest.gui.main;
|
||||
import forge.*;
|
||||
import forge.deck.Deck;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.gui.deckeditor.CardShop;
|
||||
import forge.gui.deckeditor.DeckEditorShop;
|
||||
import forge.gui.deckeditor.DeckEditorQuest;
|
||||
import forge.quest.data.QuestBattleManager;
|
||||
import forge.quest.data.QuestData;
|
||||
@@ -619,7 +619,7 @@ public class QuestMainPanel extends QuestAbstractPanel {
|
||||
}
|
||||
};
|
||||
|
||||
CardShop g = new CardShop(questData);
|
||||
DeckEditorShop g = new DeckEditorShop(questData);
|
||||
|
||||
g.show(exit);
|
||||
g.setVisible(true);
|
||||
|
||||
@@ -11,7 +11,7 @@ import forge.error.BugzReporter;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.gui.ListChooser;
|
||||
import forge.gui.deckeditor.Gui_BoosterDraft;
|
||||
import forge.gui.deckeditor.DeckEditorDraft;
|
||||
import forge.gui.deckeditor.DeckEditor;
|
||||
import forge.properties.ForgePreferences;
|
||||
import forge.properties.ForgePreferences.CardSizeType;
|
||||
@@ -365,7 +365,7 @@ public class OldGuiNewGame extends JFrame implements NewConstants, NewConstants.
|
||||
* </p>
|
||||
*/
|
||||
private void setupDraft() {
|
||||
Gui_BoosterDraft draft = new Gui_BoosterDraft();
|
||||
DeckEditorDraft draft = new DeckEditorDraft();
|
||||
|
||||
// determine what kind of booster draft to run
|
||||
ArrayList<String> draftTypes = new ArrayList<String>();
|
||||
|
||||
@@ -35,7 +35,13 @@ public abstract class Predicate<T> {
|
||||
*/
|
||||
public enum StringOp { CONTAINS, NOT_CONTAINS, EQUALS }
|
||||
|
||||
// This is the main method, predicates were made for.
|
||||
public abstract boolean isTrue(T subject);
|
||||
// These are checks against constants, they will let build simpler expressions
|
||||
// Overloaded only in LeafConstant
|
||||
public boolean is1() { return false; }
|
||||
public boolean is0() { return false; }
|
||||
|
||||
// 1. operations on pure T ... check(T card), list.add(card)
|
||||
// 2. operations on something U containing CardOracles ... check(accessor(U)), list.add(U)
|
||||
// 3. gets T from U, saves U transformed into v ... check(accessor(U)), list.add(transformer(U))
|
||||
@@ -269,8 +275,9 @@ public abstract class Predicate<T> {
|
||||
protected static class LeafConstant<T> extends Predicate<T> {
|
||||
private final boolean bValue;
|
||||
|
||||
@Override
|
||||
public boolean isTrue(final T card) { return bValue; }
|
||||
@Override public boolean is1() { return bValue; }
|
||||
@Override public boolean is0() { return !bValue; }
|
||||
@Override public boolean isTrue(final T card) { return bValue; }
|
||||
public LeafConstant(final boolean value) { bValue = value; }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user