- consolidate all card adding/removing logic so all paths update the stats correctly

- set focus on the catalog table when the deck editor opens so the arrow keys work immediately without having to click the mouse
- if multiple cards are selected, apply the add/remove operation to all of them, not just the first one
- hide the non-functional 'remove' buttons in draft mode
- protect against NPE when the cursor is hovering above a row that disappears just as swing is trying to get the tooltip
- add note to add button tooltip that the spacebar can be used as a shortcut
This commit is contained in:
myk
2013-02-01 00:50:12 +00:00
parent 519fe84f71
commit fbf6f177e8
21 changed files with 190 additions and 149 deletions

View File

@@ -252,7 +252,7 @@ public final class BoosterDraft implements IBoosterDraft {
} }
this.computerChoose(); this.computerChoose();
return ItemPool.createFrom(this.pack.get(this.getCurrentBoosterIndex()), CardPrinted.class); return ItemPool.createFrom(this.pack.get(this.getCurrentBoosterIndex()), CardPrinted.class, false);
} }
/** /**

View File

@@ -109,7 +109,8 @@ public class CustomLimited extends DeckBase {
final String deckName = data.get("DeckFile"); final String deckName = data.get("DeckFile");
final Deck deckCube = cubes.get(deckName); final Deck deckCube = cubes.get(deckName);
cd.cardPool = deckCube == null ? ItemPool.createFrom(CardDb.instance().getAllUniqueCards(), CardPrinted.class) cd.cardPool = deckCube == null ? ItemPool.createFrom(
CardDb.instance().getAllUniqueCards(), CardPrinted.class, false)
: deckCube.getMain(); : deckCube.getMain();
return cd; return cd;

View File

@@ -21,12 +21,16 @@ import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.util.List;
import forge.Card; import forge.Card;
import forge.deck.DeckBase; import forge.deck.DeckBase;
import forge.gui.CardContainer; import forge.gui.CardContainer;
import forge.gui.deckeditor.SEditorIO.EditorPreference; import forge.gui.deckeditor.SEditorIO.EditorPreference;
import forge.gui.deckeditor.controllers.ACEditorBase; import forge.gui.deckeditor.controllers.ACEditorBase;
import forge.gui.deckeditor.controllers.CProbabilities;
import forge.gui.deckeditor.controllers.CStatistics;
import forge.gui.deckeditor.tables.EditorTableView;
import forge.gui.match.controllers.CDetail; import forge.gui.match.controllers.CDetail;
import forge.gui.match.controllers.CPicture; import forge.gui.match.controllers.CPicture;
import forge.item.InventoryItem; import forge.item.InventoryItem;
@@ -80,6 +84,7 @@ public enum CDeckEditorUI implements CardContainer {
/** /**
* Set controller for current configuration of editor. * Set controller for current configuration of editor.
*
* @param editor0 &emsp; {@link forge.gui.deckeditor.controllers.ACEditorBase}<?, ?> * @param editor0 &emsp; {@link forge.gui.deckeditor.controllers.ACEditorBase}<?, ?>
*/ */
public void setCurrentEditorController(ACEditorBase<?, ?> editor0) { public void setCurrentEditorController(ACEditorBase<?, ?> editor0) {
@@ -95,6 +100,46 @@ public enum CDeckEditorUI implements CardContainer {
} }
} }
private interface _MoveAction {
void move(InventoryItem item);
}
private void moveSelectedCards(
EditorTableView<InventoryItem> table, _MoveAction moveAction, boolean moveFour) {
List<InventoryItem> items = table.getSelectedCards();
for (InventoryItem item : items) {
final int numToMove = Math.min(moveFour? 4 : 1, table.getCardCount(item));
for (int count = 0; numToMove > count; ++count) {
moveAction.move(item);
}
}
CStatistics.SINGLETON_INSTANCE.update();
CProbabilities.SINGLETON_INSTANCE.update();
}
@SuppressWarnings("unchecked")
public void addSelectedCards(boolean addFour) {
moveSelectedCards((EditorTableView<InventoryItem>)childController.getTableCatalog(),
new _MoveAction() {
@Override
public void move(InventoryItem item) {
childController.addCard(item);
}
}, addFour);
}
@SuppressWarnings("unchecked")
public void removeSelectedCards(boolean removeFour) {
moveSelectedCards((EditorTableView<InventoryItem>)childController.getTableDeck(),
new _MoveAction() {
@Override
public void move(InventoryItem item) {
childController.removeCard(item);
}
}, removeFour);
}
//========== Other methods //========== Other methods
/** /**
* Updates listeners for current controller. * Updates listeners for current controller.
@@ -103,28 +148,28 @@ public enum CDeckEditorUI implements CardContainer {
childController.getTableCatalog().getTable().addKeyListener(new KeyAdapter() { childController.getTableCatalog().getTable().addKeyListener(new KeyAdapter() {
@Override @Override
public void keyPressed(final KeyEvent e) { public void keyPressed(final KeyEvent e) {
if (e.getKeyChar() == ' ') { childController.addCard(); } if (e.getKeyChar() == ' ') { addSelectedCards(false); }
} }
}); });
childController.getTableDeck().getTable().addKeyListener(new KeyAdapter() { childController.getTableDeck().getTable().addKeyListener(new KeyAdapter() {
@Override @Override
public void keyPressed(final KeyEvent e) { public void keyPressed(final KeyEvent e) {
if (e.getKeyChar() == ' ') { childController.removeCard(); } if (e.getKeyChar() == ' ') { removeSelectedCards(false); }
} }
}); });
childController.getTableCatalog().getTable().addMouseListener(new MouseAdapter() { childController.getTableCatalog().getTable().addMouseListener(new MouseAdapter() {
@Override @Override
public void mouseClicked(final MouseEvent e) { public void mouseClicked(final MouseEvent e) {
if (e.getClickCount() == 2) { childController.addCard(); } if (e.getClickCount() == 2) { addSelectedCards(false); }
} }
}); });
childController.getTableDeck().getTable().addMouseListener(new MouseAdapter() { childController.getTableDeck().getTable().addMouseListener(new MouseAdapter() {
@Override @Override
public void mouseClicked(final MouseEvent e) { public void mouseClicked(final MouseEvent e) {
if (e.getClickCount() == 2) { childController.removeCard(); } if (e.getClickCount() == 2) { removeSelectedCards(false); }
} }
}); });

View File

@@ -3,6 +3,7 @@ package forge.gui.deckeditor;
import javax.swing.SwingWorker; import javax.swing.SwingWorker;
import forge.gui.deckeditor.controllers.CCardCatalog; import forge.gui.deckeditor.controllers.CCardCatalog;
import forge.gui.deckeditor.views.VCardCatalog;
import forge.gui.framework.IVTopLevelUI; import forge.gui.framework.IVTopLevelUI;
import forge.gui.framework.SLayoutIO; import forge.gui.framework.SLayoutIO;
@@ -36,6 +37,7 @@ public enum VDeckEditorUI implements IVTopLevelUI {
@Override @Override
public Void doInBackground() { public Void doInBackground() {
SLayoutIO.loadLayout(null); SLayoutIO.loadLayout(null);
VCardCatalog.SINGLETON_INSTANCE.focusTable();
return null; return null;
} }
}; };

View File

@@ -41,15 +41,16 @@ public abstract class ACEditorBase<TItem extends InventoryItem, TModel extends D
private EditorTableView<TItem> tblCatalog; private EditorTableView<TItem> tblCatalog;
private EditorTableView<TItem> tblDeck; private EditorTableView<TItem> tblDeck;
/** /**
* Operation to add one of selected card to current deck. * Operation to add one of selected card to current deck.
*/ */
public abstract void addCard(); public abstract void addCard(InventoryItem item);
/** /**
* Operation to remove one of selected card from current deck. * Operation to remove one of selected card from current deck.
*/ */
public abstract void removeCard(); public abstract void removeCard(InventoryItem item);
/** /**
* Resets the cards in the catalog table and current deck table. * Resets the cards in the catalog table and current deck table.

View File

@@ -42,7 +42,6 @@ import forge.gui.home.quest.DialogChooseSets;
import forge.gui.toolbox.FLabel; import forge.gui.toolbox.FLabel;
import forge.gui.toolbox.FSpinner; import forge.gui.toolbox.FSpinner;
import forge.item.CardPrinted; import forge.item.CardPrinted;
import forge.item.InventoryItem;
import forge.item.ItemPredicate; import forge.item.ItemPredicate;
import forge.quest.QuestWorld; import forge.quest.QuestWorld;
import forge.quest.data.GameFormatQuest; import forge.quest.data.GameFormatQuest;
@@ -87,26 +86,13 @@ public enum CCardCatalog implements ICDoc {
VCardCatalog.SINGLETON_INSTANCE.getBtnAdd().setCommand(new Command() { VCardCatalog.SINGLETON_INSTANCE.getBtnAdd().setCommand(new Command() {
@Override @Override
public void execute() { public void execute() {
CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController().addCard(); CDeckEditorUI.SINGLETON_INSTANCE.addSelectedCards(false);
CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController().getTableCatalog().getTable().requestFocusInWindow();
CStatistics.SINGLETON_INSTANCE.update();
CProbabilities.SINGLETON_INSTANCE.update();
} }
}); });
VCardCatalog.SINGLETON_INSTANCE.getBtnAdd4().setCommand(new Command() { VCardCatalog.SINGLETON_INSTANCE.getBtnAdd4().setCommand(new Command() {
@Override @Override
public void execute() { public void execute() {
final InventoryItem item = CDeckEditorUI.SINGLETON_INSTANCE CDeckEditorUI.SINGLETON_INSTANCE.addSelectedCards(true);
.getCurrentEditorController().getTableCatalog().getSelectedCard();
for (int i = 0; i < 4; i++) {
if (item != null && item.equals(CDeckEditorUI.SINGLETON_INSTANCE
.getCurrentEditorController().getTableCatalog().getSelectedCard())) {
CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController().addCard();
}
}
CStatistics.SINGLETON_INSTANCE.update();
CProbabilities.SINGLETON_INSTANCE.update();
} }
}); });
@@ -328,8 +314,10 @@ public enum CCardCatalog implements ICDoc {
// Apply to table // Apply to table
// TODO: is there really no way to make this type safe? // TODO: is there really no way to make this type safe?
((ACEditorBase<CardPrinted, DeckBase>)CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController()) ACEditorBase<?, ?> editor = CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController();
.getTableCatalog().setFilter(filter); if (null != editor) {
((ACEditorBase<CardPrinted, DeckBase>)editor).getTableCatalog().setFilter(filter);
}
} }
private boolean canSearch() { private boolean canSearch() {

View File

@@ -4,10 +4,10 @@ import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent; import java.awt.event.FocusEvent;
import java.io.File; import java.io.File;
import javax.swing.filechooser.FileFilter;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
import javax.swing.JTextField; import javax.swing.JTextField;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.filechooser.FileFilter;
import forge.Command; import forge.Command;
import forge.deck.Deck; import forge.deck.Deck;
@@ -20,7 +20,6 @@ import forge.gui.deckeditor.tables.DeckController;
import forge.gui.deckeditor.views.VCurrentDeck; import forge.gui.deckeditor.views.VCurrentDeck;
import forge.gui.framework.ICDoc; import forge.gui.framework.ICDoc;
import forge.gui.toolbox.FLabel; import forge.gui.toolbox.FLabel;
import forge.item.InventoryItem;
import forge.properties.ForgeProps; import forge.properties.ForgeProps;
import forge.properties.NewConstants; import forge.properties.NewConstants;
@@ -104,22 +103,12 @@ public enum CCurrentDeck implements ICDoc {
((FLabel) VCurrentDeck.SINGLETON_INSTANCE.getBtnRemove()).setCommand(new Command() { ((FLabel) VCurrentDeck.SINGLETON_INSTANCE.getBtnRemove()).setCommand(new Command() {
@Override public void execute() { @Override public void execute() {
CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController().removeCard(); CDeckEditorUI.SINGLETON_INSTANCE.removeSelectedCards(false);
} }); } });
((FLabel) VCurrentDeck.SINGLETON_INSTANCE.getBtnRemove4()).setCommand(new Command() { ((FLabel) VCurrentDeck.SINGLETON_INSTANCE.getBtnRemove4()).setCommand(new Command() {
@Override public void execute() { @Override public void execute() {
final InventoryItem item = CDeckEditorUI.SINGLETON_INSTANCE CDeckEditorUI.SINGLETON_INSTANCE.removeSelectedCards(true);
.getCurrentEditorController().getTableDeck().getSelectedCard();
if (item == null) { return; }
for (int i = 0; i < 4; i++) {
if (item.equals(CDeckEditorUI.SINGLETON_INSTANCE
.getCurrentEditorController().getTableDeck().getSelectedCard())) {
CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController().removeCard();
}
}
} }
}); });
} }

View File

@@ -91,8 +91,7 @@ public final class CEditorConstructed extends ACEditorBase<CardPrinted, Deck> {
* @see forge.gui.deckeditor.ACEditorBase#addCard() * @see forge.gui.deckeditor.ACEditorBase#addCard()
*/ */
@Override @Override
public void addCard() { public void addCard(InventoryItem item) {
final InventoryItem item = this.getTableCatalog().getSelectedCard();
if ((item == null) || !(item instanceof CardPrinted)) { if ((item == null) || !(item instanceof CardPrinted)) {
return; return;
} }
@@ -110,8 +109,7 @@ public final class CEditorConstructed extends ACEditorBase<CardPrinted, Deck> {
* @see forge.gui.deckeditor.ACEditorBase#removeCard() * @see forge.gui.deckeditor.ACEditorBase#removeCard()
*/ */
@Override @Override
public void removeCard() { public void removeCard(InventoryItem item) {
final InventoryItem item = this.getTableDeck().getSelectedCard();
if ((item == null) || !(item instanceof CardPrinted)) { if ((item == null) || !(item instanceof CardPrinted)) {
return; return;
} }
@@ -133,7 +131,7 @@ public final class CEditorConstructed extends ACEditorBase<CardPrinted, Deck> {
@Override @Override
public void resetTables() { public void resetTables() {
// Constructed mode can use all cards, no limitations. // Constructed mode can use all cards, no limitations.
this.getTableCatalog().setDeck(ItemPool.createFrom(CardDb.instance().getAllTraditionalCards(), CardPrinted.class)); this.getTableCatalog().setDeck(ItemPool.createFrom(CardDb.instance().getAllTraditionalCards(), CardPrinted.class, true));
this.getTableDeck().setDeck(this.controller.getModel().getMain()); this.getTableDeck().setDeck(this.controller.getModel().getMain());
} }
@@ -161,7 +159,7 @@ public final class CEditorConstructed extends ACEditorBase<CardPrinted, Deck> {
} else { } else {
lstCatalogCols.remove(SColumnUtil.getColumn(ColumnName.CAT_QUANTITY)); lstCatalogCols.remove(SColumnUtil.getColumn(ColumnName.CAT_QUANTITY));
this.getTableCatalog().setAvailableColumns(lstCatalogCols); this.getTableCatalog().setAvailableColumns(lstCatalogCols);
this.getTableCatalog().setDeck(ItemPool.createFrom(CardDb.instance().getAllTraditionalCards(), CardPrinted.class)); this.getTableCatalog().setDeck(ItemPool.createFrom(CardDb.instance().getAllTraditionalCards(), CardPrinted.class, true));
this.getTableDeck().setDeck(this.controller.getModel().getMain()); this.getTableDeck().setDeck(this.controller.getModel().getMain());
} }

View File

@@ -116,8 +116,7 @@ public class CEditorDraftingProcess extends ACEditorBase<CardPrinted, DeckGroup>
* @see forge.gui.deckeditor.ACEditorBase#addCard() * @see forge.gui.deckeditor.ACEditorBase#addCard()
*/ */
@Override @Override
public void addCard() { public void addCard(InventoryItem item) {
final InventoryItem item = this.getTableCatalog().getSelectedCard();
if ((item == null) || !(item instanceof CardPrinted)) { if ((item == null) || !(item instanceof CardPrinted)) {
return; return;
} }
@@ -142,7 +141,7 @@ public class CEditorDraftingProcess extends ACEditorBase<CardPrinted, DeckGroup>
* @see forge.gui.deckeditor.ACEditorBase#removeCard() * @see forge.gui.deckeditor.ACEditorBase#removeCard()
*/ */
@Override @Override
public void removeCard() { public void removeCard(InventoryItem item) {
} }
/** /**
@@ -269,6 +268,8 @@ public class CEditorDraftingProcess extends ACEditorBase<CardPrinted, DeckGroup>
//Remove buttons //Remove buttons
VCardCatalog.SINGLETON_INSTANCE.getBtnAdd4().setVisible(false); VCardCatalog.SINGLETON_INSTANCE.getBtnAdd4().setVisible(false);
VCurrentDeck.SINGLETON_INSTANCE.getBtnRemove().setVisible(false);
VCurrentDeck.SINGLETON_INSTANCE.getBtnRemove4().setVisible(false);
VCurrentDeck.SINGLETON_INSTANCE.getBtnDoSideboard().setVisible(false); VCurrentDeck.SINGLETON_INSTANCE.getBtnDoSideboard().setVisible(false);

View File

@@ -91,8 +91,7 @@ public final class CEditorLimited extends ACEditorBase<CardPrinted, DeckGroup> {
* @see forge.gui.deckeditor.ACEditorBase#addCard() * @see forge.gui.deckeditor.ACEditorBase#addCard()
*/ */
@Override @Override
public void addCard() { public void addCard(InventoryItem item) {
final InventoryItem item = this.getTableCatalog().getSelectedCard();
if ((item == null) || !(item instanceof CardPrinted)) { if ((item == null) || !(item instanceof CardPrinted)) {
return; return;
} }
@@ -109,8 +108,7 @@ public final class CEditorLimited extends ACEditorBase<CardPrinted, DeckGroup> {
* @see forge.gui.deckeditor.ACEditorBase#removeCard() * @see forge.gui.deckeditor.ACEditorBase#removeCard()
*/ */
@Override @Override
public void removeCard() { public void removeCard(InventoryItem item) {
final InventoryItem item = this.getTableDeck().getSelectedCard();
if ((item == null) || !(item instanceof CardPrinted)) { if ((item == null) || !(item instanceof CardPrinted)) {
return; return;
} }

View File

@@ -141,8 +141,7 @@ public final class CEditorQuest extends ACEditorBase<CardPrinted, Deck> {
* @see forge.gui.deckeditor.ACEditorBase#addCard() * @see forge.gui.deckeditor.ACEditorBase#addCard()
*/ */
@Override @Override
public void addCard() { public void addCard(InventoryItem item) {
final InventoryItem item = this.getTableCatalog().getSelectedCard();
if ((item == null) || !(item instanceof CardPrinted)) { if ((item == null) || !(item instanceof CardPrinted)) {
return; return;
} }
@@ -157,8 +156,7 @@ public final class CEditorQuest extends ACEditorBase<CardPrinted, Deck> {
* @see forge.gui.deckeditor.ACEditorBase#removeCard() * @see forge.gui.deckeditor.ACEditorBase#removeCard()
*/ */
@Override @Override
public void removeCard() { public void removeCard(InventoryItem item) {
final InventoryItem item = this.getTableDeck().getSelectedCard();
if ((item == null) || !(item instanceof CardPrinted)) { if ((item == null) || !(item instanceof CardPrinted)) {
return; return;
} }

View File

@@ -90,7 +90,7 @@ public final class CEditorQuestCardShop extends ACEditorBase<InventoryItem, Deck
private ItemPoolView<InventoryItem> cardsForSale; private ItemPoolView<InventoryItem> cardsForSale;
private final ItemPool<InventoryItem> fullCatalogCards = private final ItemPool<InventoryItem> fullCatalogCards =
ItemPool.createFrom(CardDb.instance().getAllTraditionalCards(), InventoryItem.class); ItemPool.createFrom(CardDb.instance().getAllTraditionalCards(), InventoryItem.class, true);
private boolean showingFullCatalog = false; private boolean showingFullCatalog = false;
// get pricelist: // get pricelist:
@@ -287,20 +287,22 @@ public final class CEditorQuestCardShop extends ACEditorBase<InventoryItem, Deck
* @see forge.gui.deckeditor.ACEditorBase#addCard() * @see forge.gui.deckeditor.ACEditorBase#addCard()
*/ */
@Override @Override
public void addCard() { public void addCard(InventoryItem item) {
if (showingFullCatalog) { if (showingFullCatalog) {
// no "buying" from the full catalog // no "buying" from the full catalog
return; return;
} }
final InventoryItem item = this.getTableCatalog().getSelectedCard();
if (item == null) { if (item == null) {
return; return;
} }
final int value = this.getCardValue(item); final int value = this.getCardValue(item);
if (value <= this.questData.getAssets().getCredits()) { if (value > this.questData.getAssets().getCredits()) {
JOptionPane.showMessageDialog(null, "Not enough credits!");
return;
}
if (item instanceof CardPrinted) { if (item instanceof CardPrinted) {
this.getTableCatalog().removeCard(item); this.getTableCatalog().removeCard(item);
@@ -336,28 +338,25 @@ public final class CEditorQuestCardShop extends ACEditorBase<InventoryItem, Deck
for (final CardPrinted card : deck.getDeck().getMain().toFlatList()) { for (final CardPrinted card : deck.getDeck().getMain().toFlatList()) {
this.getTableDeck().addCard(card); this.getTableDeck().addCard(card);
} }
JOptionPane.showMessageDialog(null, String.format( JOptionPane.showMessageDialog(null, String.format(
"Deck '%s' was added to your decklist.%n%nCards from it were also added to your pool.", "Deck '%s' was added to your decklist.%n%nCards from it were also added to your pool.",
deck.getName()), "Thanks for purchasing!", JOptionPane.INFORMATION_MESSAGE); deck.getName()), "Thanks for purchasing!", JOptionPane.INFORMATION_MESSAGE);
} }
this.creditsLabel.setText("Credits: " + this.questData.getAssets().getCredits()); this.creditsLabel.setText("Credits: " + this.questData.getAssets().getCredits());
} else {
JOptionPane.showMessageDialog(null, "Not enough credits!");
}
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see forge.gui.deckeditor.ACEditorBase#removeCard() * @see forge.gui.deckeditor.ACEditorBase#removeCard()
*/ */
@Override @Override
public void removeCard() { public void removeCard(InventoryItem item) {
if (showingFullCatalog) { if (showingFullCatalog) {
// no "selling" to the full catalog // no "selling" to the full catalog
return; return;
} }
final InventoryItem item = this.getTableDeck().getSelectedCard();
if ((item == null) || !(item instanceof CardPrinted)) { if ((item == null) || !(item instanceof CardPrinted)) {
return; return;
} }
@@ -398,19 +397,12 @@ public final class CEditorQuestCardShop extends ACEditorBase<InventoryItem, Deck
*/ */
@Override @Override
public void init() { public void init() {
this.setup(); setup();
this.decksUsingMyCards = this.countDecksForEachCard(); this.decksUsingMyCards = this.countDecksForEachCard();
this.multiplier = this.questData.getCards().getSellMultiplier(); this.multiplier = this.questData.getCards().getSellMultiplier();
this.cardsForSale = this.questData.getCards().getShopList();
cardsForSale = this.questData.getCards().getShopList();
if (cardsForSale.isEmpty()) {
this.questData.getCards().generateCardsInShop();
cardsForSale = this.questData.getCards().getShopList();
}
// newCardsList = questData.getCards().getNewCards();
final ItemPool<InventoryItem> ownedItems = new ItemPool<InventoryItem>(InventoryItem.class); final ItemPool<InventoryItem> ownedItems = new ItemPool<InventoryItem>(InventoryItem.class);
ownedItems.addAll(this.questData.getCards().getCardpool().getView()); ownedItems.addAll(this.questData.getCards().getCardpool().getView());

View File

@@ -93,8 +93,7 @@ public final class CEditorVariant extends ACEditorBase<CardPrinted, Deck> {
* @see forge.gui.deckeditor.ACEditorBase#addCard() * @see forge.gui.deckeditor.ACEditorBase#addCard()
*/ */
@Override @Override
public void addCard() { public void addCard(InventoryItem item) {
final InventoryItem item = this.getTableCatalog().getSelectedCard();
if ((item == null) || !(item instanceof CardPrinted)) { if ((item == null) || !(item instanceof CardPrinted)) {
return; return;
} }
@@ -109,8 +108,7 @@ public final class CEditorVariant extends ACEditorBase<CardPrinted, Deck> {
* @see forge.gui.deckeditor.ACEditorBase#removeCard() * @see forge.gui.deckeditor.ACEditorBase#removeCard()
*/ */
@Override @Override
public void removeCard() { public void removeCard(InventoryItem item) {
final InventoryItem item = this.getTableDeck().getSelectedCard();
if ((item == null) || !(item instanceof CardPrinted)) { if ((item == null) || !(item instanceof CardPrinted)) {
return; return;
} }
@@ -132,7 +130,7 @@ public final class CEditorVariant extends ACEditorBase<CardPrinted, Deck> {
Iterable<CardPrinted> allNT = CardDb.instance().getAllNonTraditionalCards(); Iterable<CardPrinted> allNT = CardDb.instance().getAllNonTraditionalCards();
allNT = Iterables.filter(allNT, cardPoolCondition); allNT = Iterables.filter(allNT, cardPoolCondition);
this.getTableCatalog().setDeck(ItemPool.createFrom(allNT, CardPrinted.class)); this.getTableCatalog().setDeck(ItemPool.createFrom(allNT, CardPrinted.class, true));
this.getTableDeck().setDeck(this.controller.getModel().getSideboard()); this.getTableDeck().setDeck(this.controller.getModel().getSideboard());
} }

View File

@@ -64,7 +64,7 @@ public enum CProbabilities implements ICDoc {
CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController(); CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController();
final ItemPoolView<CardPrinted> deck = ItemPool.createFrom( final ItemPoolView<CardPrinted> deck = ItemPool.createFrom(
ed.getTableDeck().getCards(), CardPrinted.class); ed.getTableDeck().getCards(), CardPrinted.class, false);
final List<String> cardProbabilities = new ArrayList<String>(); final List<String> cardProbabilities = new ArrayList<String>();

View File

@@ -74,7 +74,7 @@ public enum CStatistics implements ICDoc {
if (ed == null) { return; } if (ed == null) { return; }
final ItemPoolView<CardPrinted> deck = ItemPool.createFrom( final ItemPoolView<CardPrinted> deck = ItemPool.createFrom(
ed.getTableDeck().getCards(), CardPrinted.class); ed.getTableDeck().getCards(), CardPrinted.class, false);
int total = deck.countAll(); int total = deck.countAll();

View File

@@ -21,6 +21,7 @@ import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Point; import java.awt.Point;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
@@ -157,9 +158,11 @@ public final class EditorTableView<T extends InventoryItem> {
Point p = e.getPoint(); Point p = e.getPoint();
int row = rowAtPoint(p); int row = rowAtPoint(p);
int col = columnAtPoint(p); int col = columnAtPoint(p);
Object val = table.getValueAt(row, col); if (col >= table.getColumnCount() || row >= table.getRowCount()) {
return null;
}
return _getCellTooltip(getCellRenderer(row, col), row, col, val); return _getCellTooltip(getCellRenderer(row, col), row, col, table.getValueAt(row, col));
} }
}; };
@@ -252,7 +255,7 @@ public final class EditorTableView<T extends InventoryItem> {
* an Iterable<InventoryITem> * an Iterable<InventoryITem>
*/ */
public void setDeck(final Iterable<InventoryItem> cards) { public void setDeck(final Iterable<InventoryItem> cards) {
this.setDeckImpl(ItemPool.createFrom(cards, this.genericType)); this.setDeckImpl(ItemPool.createFrom(cards, this.genericType, false));
} }
/** /**
@@ -262,7 +265,7 @@ public final class EditorTableView<T extends InventoryItem> {
* an ItemPoolView * an ItemPoolView
*/ */
public void setDeck(final ItemPoolView<T> poolView) { public void setDeck(final ItemPoolView<T> poolView) {
this.setDeckImpl(ItemPool.createFrom(poolView, this.genericType)); this.setDeckImpl(ItemPool.createFrom(poolView, this.genericType, false));
} }
/** /**
@@ -300,6 +303,17 @@ public final class EditorTableView<T extends InventoryItem> {
return iRow >= 0 ? this.model.rowToCard(iRow).getKey() : null; return iRow >= 0 ? this.model.rowToCard(iRow).getKey() : null;
} }
/**
* returns all selected cards
*/
public List<InventoryItem> getSelectedCards() {
List<InventoryItem> items = new ArrayList<InventoryItem>();
for (int row : table.getSelectedRows()) {
items.add(model.rowToCard(row).getKey());
}
return items;
}
private boolean isUnfiltered() { private boolean isUnfiltered() {
return this.filter == null; return this.filter == null;
} }
@@ -313,8 +327,10 @@ public final class EditorTableView<T extends InventoryItem> {
*/ */
public void setFilter(final Predicate<T> filterToSet) { public void setFilter(final Predicate<T> filterToSet) {
this.filter = filterToSet; this.filter = filterToSet;
if (null != pool) {
this.updateView(true); this.updateView(true);
} }
}
/** /**
* *
@@ -349,6 +365,10 @@ public final class EditorTableView<T extends InventoryItem> {
this.fixSelection(n); this.fixSelection(n);
} }
public int getCardCount(final T card) {
return this.pool.count(card);
}
/** /**
* *
* updateView. * updateView.

View File

@@ -63,7 +63,7 @@ public enum VCardCatalog implements IVDoc<CCardCatalog>, ITableContainer {
private final FLabel btnAdd = new FLabel.Builder() private final FLabel btnAdd = new FLabel.Builder()
.fontSize(14) .fontSize(14)
.text("Add card") .text("Add card")
.tooltip("Add selected card to current deck (or double click the row)") .tooltip("Add selected card to current deck (or double click the row or hit the spacebar)")
.icon(FSkin.getIcon(FSkin.InterfaceIcons.ICO_PLUS)) .icon(FSkin.getIcon(FSkin.InterfaceIcons.ICO_PLUS))
.iconScaleAuto(false).hoverable(true).build(); .iconScaleAuto(false).hoverable(true).build();
private final FLabel btnAdd4 = new FLabel.Builder() private final FLabel btnAdd4 = new FLabel.Builder()
@@ -239,6 +239,16 @@ public enum VCardCatalog implements IVDoc<CCardCatalog>, ITableContainer {
.build(); .build();
} }
public void focusTable() {
if (null != tblCards) {
tblCards.requestFocusInWindow();
if (0 < tblCards.getRowCount()) {
tblCards.changeSelection(0, 0, false, false);
}
}
}
@SuppressWarnings("serial") @SuppressWarnings("serial")
public void addRestrictionWidget(JComponent component, final Command onRemove) { public void addRestrictionWidget(JComponent component, final Command onRemove) {
final JPanel pnl = new JPanel(new MigLayout("insets 2, gap 2, h 30!")); final JPanel pnl = new JPanel(new MigLayout("insets 2, gap 2, h 30!"));

View File

@@ -43,6 +43,10 @@ public class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
super(cls); super(cls);
} }
public ItemPool(final Class<T> cls, boolean infiniteStock) {
super(cls, infiniteStock);
}
/** /**
* createFrom method. * createFrom method.
* *
@@ -58,8 +62,8 @@ public class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <Tin extends InventoryItem, Tout extends InventoryItem> ItemPool<Tout> createFrom( public static <Tin extends InventoryItem, Tout extends InventoryItem> ItemPool<Tout> createFrom(
final ItemPoolView<Tin> from, final Class<Tout> clsHint) { final ItemPoolView<Tin> from, final Class<Tout> clsHint, boolean infiniteStock) {
final ItemPool<Tout> result = new ItemPool<Tout>(clsHint); final ItemPool<Tout> result = new ItemPool<Tout>(clsHint, infiniteStock);
if (from != null) { if (from != null) {
for (final Entry<Tin, Integer> e : from) { for (final Entry<Tin, Integer> e : from) {
final Tin srcKey = e.getKey(); final Tin srcKey = e.getKey();
@@ -86,8 +90,8 @@ public class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <Tin extends InventoryItem, Tout extends InventoryItem> ItemPool<Tout> createFrom( public static <Tin extends InventoryItem, Tout extends InventoryItem> ItemPool<Tout> createFrom(
final Iterable<Tin> from, final Class<Tout> clsHint) { final Iterable<Tin> from, final Class<Tout> clsHint, boolean infiniteStock) {
final ItemPool<Tout> result = new ItemPool<Tout>(clsHint); final ItemPool<Tout> result = new ItemPool<Tout>(clsHint, infiniteStock);
if (from != null) { if (from != null) {
for (final Tin srcKey : from) { for (final Tin srcKey : from) {
if (clsHint.isInstance(srcKey)) { if (clsHint.isInstance(srcKey)) {

View File

@@ -76,33 +76,28 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
}; };
// Constructors // Constructors
/**
*
* ItemPoolView.
*
* @param cls
* a Class<T>
*/
public ItemPoolView(final Class<T> cls) { public ItemPoolView(final Class<T> cls) {
this.cards = new Hashtable<T, Integer>(); this(cls, false);
this.myClass = cls; }
public ItemPoolView(final Class<T> cls, boolean infiniteStock) {
this(new Hashtable<T, Integer>(), cls, infiniteStock);
} }
/**
*
* ItemPoolView.
*
* @param inMap
* a Map<T, Integer>
* @param cls
* a Class<T>
*/
public ItemPoolView(final Map<T, Integer> inMap, final Class<T> cls) { public ItemPoolView(final Map<T, Integer> inMap, final Class<T> cls) {
this(inMap, cls, false);
}
public ItemPoolView(final Map<T, Integer> inMap, final Class<T> cls, boolean infiniteStock) {
this.cards = inMap; this.cards = inMap;
this.myClass = cls; this.myClass = cls;
this.infiniteStock = infiniteStock;
} }
// Data members // Data members
// if this is true, queries for card count will return INT_MAX
private final boolean infiniteStock;
/** The cards. */ /** The cards. */
private final Map<T, Integer> cards; private final Map<T, Integer> cards;
@@ -157,7 +152,7 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
return 0; return 0;
} }
final Integer boxed = this.getCards().get(card); final Integer boxed = this.getCards().get(card);
return boxed == null ? 0 : boxed.intValue(); return boxed == null ? 0 : (infiniteStock ? Integer.MAX_VALUE : boxed.intValue());
} }
/** /**

View File

@@ -504,7 +504,8 @@ public final class QuestUtilCards {
if (qc.getFormat() == null) { if (qc.getFormat() == null) {
cardList = CardDb.instance().getAllTraditionalCards(); } cardList = CardDb.instance().getAllTraditionalCards(); }
else { else {
cardList = Iterables.filter(CardDb.instance().getAllTraditionalCards(), qc.getFormat().getFilterPrinted()); cardList = Iterables.filter(CardDb.instance().getAllTraditionalCards(),
qc.getFormat().getFilterPrinted());
} }
final BoosterGenerator pack = new BoosterGenerator(cardList); final BoosterGenerator pack = new BoosterGenerator(cardList);

View File

@@ -51,7 +51,7 @@ public class BoosterDraftTest implements IBoosterDraft {
this.n--; this.n--;
BoosterData booster = Singletons.getModel().getBoosters().get("M11"); BoosterData booster = Singletons.getModel().getBoosters().get("M11");
final BoosterGenerator pack = new BoosterGenerator(booster.getEditionFilter()); final BoosterGenerator pack = new BoosterGenerator(booster.getEditionFilter());
return ItemPool.createFrom(pack.getBoosterPack(booster), CardPrinted.class); return ItemPool.createFrom(pack.getBoosterPack(booster), CardPrinted.class, false);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */