mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
- 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:
@@ -252,7 +252,7 @@ public final class BoosterDraft implements IBoosterDraft {
|
||||
}
|
||||
|
||||
this.computerChoose();
|
||||
return ItemPool.createFrom(this.pack.get(this.getCurrentBoosterIndex()), CardPrinted.class);
|
||||
return ItemPool.createFrom(this.pack.get(this.getCurrentBoosterIndex()), CardPrinted.class, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -109,7 +109,8 @@ public class CustomLimited extends DeckBase {
|
||||
|
||||
final String deckName = data.get("DeckFile");
|
||||
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();
|
||||
|
||||
return cd;
|
||||
|
||||
@@ -21,12 +21,16 @@ import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.List;
|
||||
|
||||
import forge.Card;
|
||||
import forge.deck.DeckBase;
|
||||
import forge.gui.CardContainer;
|
||||
import forge.gui.deckeditor.SEditorIO.EditorPreference;
|
||||
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.CPicture;
|
||||
import forge.item.InventoryItem;
|
||||
@@ -80,6 +84,7 @@ public enum CDeckEditorUI implements CardContainer {
|
||||
|
||||
/**
|
||||
* Set controller for current configuration of editor.
|
||||
*
|
||||
* @param editor0   {@link forge.gui.deckeditor.controllers.ACEditorBase}<?, ?>
|
||||
*/
|
||||
public void setCurrentEditorController(ACEditorBase<?, ?> editor0) {
|
||||
@@ -94,6 +99,46 @@ public enum CDeckEditorUI implements CardContainer {
|
||||
childController.getTableDeck().setWantUnique(wantUnique);
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
/**
|
||||
@@ -103,28 +148,28 @@ public enum CDeckEditorUI implements CardContainer {
|
||||
childController.getTableCatalog().getTable().addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(final KeyEvent e) {
|
||||
if (e.getKeyChar() == ' ') { childController.addCard(); }
|
||||
if (e.getKeyChar() == ' ') { addSelectedCards(false); }
|
||||
}
|
||||
});
|
||||
|
||||
childController.getTableDeck().getTable().addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(final KeyEvent e) {
|
||||
if (e.getKeyChar() == ' ') { childController.removeCard(); }
|
||||
if (e.getKeyChar() == ' ') { removeSelectedCards(false); }
|
||||
}
|
||||
});
|
||||
|
||||
childController.getTableCatalog().getTable().addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(final MouseEvent e) {
|
||||
if (e.getClickCount() == 2) { childController.addCard(); }
|
||||
if (e.getClickCount() == 2) { addSelectedCards(false); }
|
||||
}
|
||||
});
|
||||
|
||||
childController.getTableDeck().getTable().addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(final MouseEvent e) {
|
||||
if (e.getClickCount() == 2) { childController.removeCard(); }
|
||||
if (e.getClickCount() == 2) { removeSelectedCards(false); }
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package forge.gui.deckeditor;
|
||||
import javax.swing.SwingWorker;
|
||||
|
||||
import forge.gui.deckeditor.controllers.CCardCatalog;
|
||||
import forge.gui.deckeditor.views.VCardCatalog;
|
||||
import forge.gui.framework.IVTopLevelUI;
|
||||
import forge.gui.framework.SLayoutIO;
|
||||
|
||||
@@ -36,6 +37,7 @@ public enum VDeckEditorUI implements IVTopLevelUI {
|
||||
@Override
|
||||
public Void doInBackground() {
|
||||
SLayoutIO.loadLayout(null);
|
||||
VCardCatalog.SINGLETON_INSTANCE.focusTable();
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -41,15 +41,16 @@ public abstract class ACEditorBase<TItem extends InventoryItem, TModel extends D
|
||||
|
||||
private EditorTableView<TItem> tblCatalog;
|
||||
private EditorTableView<TItem> tblDeck;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public abstract void removeCard();
|
||||
public abstract void removeCard(InventoryItem item);
|
||||
|
||||
/**
|
||||
* Resets the cards in the catalog table and current deck table.
|
||||
|
||||
@@ -42,7 +42,6 @@ import forge.gui.home.quest.DialogChooseSets;
|
||||
import forge.gui.toolbox.FLabel;
|
||||
import forge.gui.toolbox.FSpinner;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.ItemPredicate;
|
||||
import forge.quest.QuestWorld;
|
||||
import forge.quest.data.GameFormatQuest;
|
||||
@@ -87,26 +86,13 @@ public enum CCardCatalog implements ICDoc {
|
||||
VCardCatalog.SINGLETON_INSTANCE.getBtnAdd().setCommand(new Command() {
|
||||
@Override
|
||||
public void execute() {
|
||||
CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController().addCard();
|
||||
CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController().getTableCatalog().getTable().requestFocusInWindow();
|
||||
CStatistics.SINGLETON_INSTANCE.update();
|
||||
CProbabilities.SINGLETON_INSTANCE.update();
|
||||
CDeckEditorUI.SINGLETON_INSTANCE.addSelectedCards(false);
|
||||
}
|
||||
});
|
||||
VCardCatalog.SINGLETON_INSTANCE.getBtnAdd4().setCommand(new Command() {
|
||||
@Override
|
||||
public void execute() {
|
||||
final InventoryItem item = CDeckEditorUI.SINGLETON_INSTANCE
|
||||
.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();
|
||||
CDeckEditorUI.SINGLETON_INSTANCE.addSelectedCards(true);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -328,8 +314,10 @@ public enum CCardCatalog implements ICDoc {
|
||||
|
||||
// Apply to table
|
||||
// TODO: is there really no way to make this type safe?
|
||||
((ACEditorBase<CardPrinted, DeckBase>)CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController())
|
||||
.getTableCatalog().setFilter(filter);
|
||||
ACEditorBase<?, ?> editor = CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController();
|
||||
if (null != editor) {
|
||||
((ACEditorBase<CardPrinted, DeckBase>)editor).getTableCatalog().setFilter(filter);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean canSearch() {
|
||||
|
||||
@@ -4,10 +4,10 @@ import java.awt.event.FocusAdapter;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.io.File;
|
||||
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
|
||||
import forge.Command;
|
||||
import forge.deck.Deck;
|
||||
@@ -20,7 +20,6 @@ import forge.gui.deckeditor.tables.DeckController;
|
||||
import forge.gui.deckeditor.views.VCurrentDeck;
|
||||
import forge.gui.framework.ICDoc;
|
||||
import forge.gui.toolbox.FLabel;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
|
||||
@@ -104,22 +103,12 @@ public enum CCurrentDeck implements ICDoc {
|
||||
|
||||
((FLabel) VCurrentDeck.SINGLETON_INSTANCE.getBtnRemove()).setCommand(new Command() {
|
||||
@Override public void execute() {
|
||||
CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController().removeCard();
|
||||
CDeckEditorUI.SINGLETON_INSTANCE.removeSelectedCards(false);
|
||||
} });
|
||||
|
||||
((FLabel) VCurrentDeck.SINGLETON_INSTANCE.getBtnRemove4()).setCommand(new Command() {
|
||||
@Override public void execute() {
|
||||
final InventoryItem item = CDeckEditorUI.SINGLETON_INSTANCE
|
||||
.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();
|
||||
}
|
||||
}
|
||||
CDeckEditorUI.SINGLETON_INSTANCE.removeSelectedCards(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -91,8 +91,7 @@ public final class CEditorConstructed extends ACEditorBase<CardPrinted, Deck> {
|
||||
* @see forge.gui.deckeditor.ACEditorBase#addCard()
|
||||
*/
|
||||
@Override
|
||||
public void addCard() {
|
||||
final InventoryItem item = this.getTableCatalog().getSelectedCard();
|
||||
public void addCard(InventoryItem item) {
|
||||
if ((item == null) || !(item instanceof CardPrinted)) {
|
||||
return;
|
||||
}
|
||||
@@ -110,8 +109,7 @@ public final class CEditorConstructed extends ACEditorBase<CardPrinted, Deck> {
|
||||
* @see forge.gui.deckeditor.ACEditorBase#removeCard()
|
||||
*/
|
||||
@Override
|
||||
public void removeCard() {
|
||||
final InventoryItem item = this.getTableDeck().getSelectedCard();
|
||||
public void removeCard(InventoryItem item) {
|
||||
if ((item == null) || !(item instanceof CardPrinted)) {
|
||||
return;
|
||||
}
|
||||
@@ -133,7 +131,7 @@ public final class CEditorConstructed extends ACEditorBase<CardPrinted, Deck> {
|
||||
@Override
|
||||
public void resetTables() {
|
||||
// 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());
|
||||
}
|
||||
|
||||
@@ -161,7 +159,7 @@ public final class CEditorConstructed extends ACEditorBase<CardPrinted, Deck> {
|
||||
} else {
|
||||
lstCatalogCols.remove(SColumnUtil.getColumn(ColumnName.CAT_QUANTITY));
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
@@ -116,8 +116,7 @@ public class CEditorDraftingProcess extends ACEditorBase<CardPrinted, DeckGroup>
|
||||
* @see forge.gui.deckeditor.ACEditorBase#addCard()
|
||||
*/
|
||||
@Override
|
||||
public void addCard() {
|
||||
final InventoryItem item = this.getTableCatalog().getSelectedCard();
|
||||
public void addCard(InventoryItem item) {
|
||||
if ((item == null) || !(item instanceof CardPrinted)) {
|
||||
return;
|
||||
}
|
||||
@@ -142,7 +141,7 @@ public class CEditorDraftingProcess extends ACEditorBase<CardPrinted, DeckGroup>
|
||||
* @see forge.gui.deckeditor.ACEditorBase#removeCard()
|
||||
*/
|
||||
@Override
|
||||
public void removeCard() {
|
||||
public void removeCard(InventoryItem item) {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -269,6 +268,8 @@ public class CEditorDraftingProcess extends ACEditorBase<CardPrinted, DeckGroup>
|
||||
|
||||
//Remove buttons
|
||||
VCardCatalog.SINGLETON_INSTANCE.getBtnAdd4().setVisible(false);
|
||||
VCurrentDeck.SINGLETON_INSTANCE.getBtnRemove().setVisible(false);
|
||||
VCurrentDeck.SINGLETON_INSTANCE.getBtnRemove4().setVisible(false);
|
||||
|
||||
VCurrentDeck.SINGLETON_INSTANCE.getBtnDoSideboard().setVisible(false);
|
||||
|
||||
|
||||
@@ -91,8 +91,7 @@ public final class CEditorLimited extends ACEditorBase<CardPrinted, DeckGroup> {
|
||||
* @see forge.gui.deckeditor.ACEditorBase#addCard()
|
||||
*/
|
||||
@Override
|
||||
public void addCard() {
|
||||
final InventoryItem item = this.getTableCatalog().getSelectedCard();
|
||||
public void addCard(InventoryItem item) {
|
||||
if ((item == null) || !(item instanceof CardPrinted)) {
|
||||
return;
|
||||
}
|
||||
@@ -109,8 +108,7 @@ public final class CEditorLimited extends ACEditorBase<CardPrinted, DeckGroup> {
|
||||
* @see forge.gui.deckeditor.ACEditorBase#removeCard()
|
||||
*/
|
||||
@Override
|
||||
public void removeCard() {
|
||||
final InventoryItem item = this.getTableDeck().getSelectedCard();
|
||||
public void removeCard(InventoryItem item) {
|
||||
if ((item == null) || !(item instanceof CardPrinted)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -141,8 +141,7 @@ public final class CEditorQuest extends ACEditorBase<CardPrinted, Deck> {
|
||||
* @see forge.gui.deckeditor.ACEditorBase#addCard()
|
||||
*/
|
||||
@Override
|
||||
public void addCard() {
|
||||
final InventoryItem item = this.getTableCatalog().getSelectedCard();
|
||||
public void addCard(InventoryItem item) {
|
||||
if ((item == null) || !(item instanceof CardPrinted)) {
|
||||
return;
|
||||
}
|
||||
@@ -157,8 +156,7 @@ public final class CEditorQuest extends ACEditorBase<CardPrinted, Deck> {
|
||||
* @see forge.gui.deckeditor.ACEditorBase#removeCard()
|
||||
*/
|
||||
@Override
|
||||
public void removeCard() {
|
||||
final InventoryItem item = this.getTableDeck().getSelectedCard();
|
||||
public void removeCard(InventoryItem item) {
|
||||
if ((item == null) || !(item instanceof CardPrinted)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public final class CEditorQuestCardShop extends ACEditorBase<InventoryItem, Deck
|
||||
|
||||
private ItemPoolView<InventoryItem> cardsForSale;
|
||||
private final ItemPool<InventoryItem> fullCatalogCards =
|
||||
ItemPool.createFrom(CardDb.instance().getAllTraditionalCards(), InventoryItem.class);
|
||||
ItemPool.createFrom(CardDb.instance().getAllTraditionalCards(), InventoryItem.class, true);
|
||||
private boolean showingFullCatalog = false;
|
||||
|
||||
// get pricelist:
|
||||
@@ -287,77 +287,76 @@ public final class CEditorQuestCardShop extends ACEditorBase<InventoryItem, Deck
|
||||
* @see forge.gui.deckeditor.ACEditorBase#addCard()
|
||||
*/
|
||||
@Override
|
||||
public void addCard() {
|
||||
public void addCard(InventoryItem item) {
|
||||
if (showingFullCatalog) {
|
||||
// no "buying" from the full catalog
|
||||
return;
|
||||
}
|
||||
|
||||
final InventoryItem item = this.getTableCatalog().getSelectedCard();
|
||||
if (item == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
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) {
|
||||
this.getTableCatalog().removeCard(item);
|
||||
|
||||
if (item instanceof CardPrinted) {
|
||||
this.getTableCatalog().removeCard(item);
|
||||
final CardPrinted card = (CardPrinted) item;
|
||||
this.getTableDeck().addCard(card);
|
||||
this.questData.getCards().buyCard(card, value);
|
||||
|
||||
final CardPrinted card = (CardPrinted) item;
|
||||
} else if (item instanceof OpenablePack) {
|
||||
this.getTableCatalog().removeCard(item);
|
||||
|
||||
OpenablePack booster = null;
|
||||
if (item instanceof BoosterPack) {
|
||||
booster = (BoosterPack) ((BoosterPack) item).clone();
|
||||
} else if (item instanceof TournamentPack) {
|
||||
booster = (TournamentPack) ((TournamentPack) item).clone();
|
||||
} else if (item instanceof FatPack) {
|
||||
booster = (FatPack) ((FatPack) item).clone();
|
||||
}
|
||||
this.questData.getCards().buyPack(booster, value);
|
||||
final List<CardPrinted> newCards = booster.getCards();
|
||||
for (final CardPrinted card : newCards) {
|
||||
this.getTableDeck().addCard(card);
|
||||
this.questData.getCards().buyCard(card, value);
|
||||
|
||||
} else if (item instanceof OpenablePack) {
|
||||
this.getTableCatalog().removeCard(item);
|
||||
|
||||
OpenablePack booster = null;
|
||||
if (item instanceof BoosterPack) {
|
||||
booster = (BoosterPack) ((BoosterPack) item).clone();
|
||||
} else if (item instanceof TournamentPack) {
|
||||
booster = (TournamentPack) ((TournamentPack) item).clone();
|
||||
} else if (item instanceof FatPack) {
|
||||
booster = (FatPack) ((FatPack) item).clone();
|
||||
}
|
||||
this.questData.getCards().buyPack(booster, value);
|
||||
final List<CardPrinted> newCards = booster.getCards();
|
||||
for (final CardPrinted card : newCards) {
|
||||
this.getTableDeck().addCard(card);
|
||||
}
|
||||
final CardListViewer c = new CardListViewer(booster.getName(),
|
||||
"You have found the following cards inside:", newCards);
|
||||
c.show();
|
||||
} else if (item instanceof PreconDeck) {
|
||||
this.getTableCatalog().removeCard(item);
|
||||
final PreconDeck deck = (PreconDeck) item;
|
||||
this.questData.getCards().buyPreconDeck(deck, value);
|
||||
|
||||
for (final CardPrinted card : deck.getDeck().getMain().toFlatList()) {
|
||||
this.getTableDeck().addCard(card);
|
||||
}
|
||||
JOptionPane.showMessageDialog(null, String.format(
|
||||
"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);
|
||||
}
|
||||
final CardListViewer c = new CardListViewer(booster.getName(),
|
||||
"You have found the following cards inside:", newCards);
|
||||
c.show();
|
||||
} else if (item instanceof PreconDeck) {
|
||||
this.getTableCatalog().removeCard(item);
|
||||
final PreconDeck deck = (PreconDeck) item;
|
||||
this.questData.getCards().buyPreconDeck(deck, value);
|
||||
|
||||
for (final CardPrinted card : deck.getDeck().getMain().toFlatList()) {
|
||||
this.getTableDeck().addCard(card);
|
||||
}
|
||||
|
||||
this.creditsLabel.setText("Credits: " + this.questData.getAssets().getCredits());
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "Not enough credits!");
|
||||
JOptionPane.showMessageDialog(null, String.format(
|
||||
"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);
|
||||
}
|
||||
|
||||
this.creditsLabel.setText("Credits: " + this.questData.getAssets().getCredits());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.ACEditorBase#removeCard()
|
||||
*/
|
||||
@Override
|
||||
public void removeCard() {
|
||||
public void removeCard(InventoryItem item) {
|
||||
if (showingFullCatalog) {
|
||||
// no "selling" to the full catalog
|
||||
return;
|
||||
}
|
||||
final InventoryItem item = this.getTableDeck().getSelectedCard();
|
||||
|
||||
if ((item == null) || !(item instanceof CardPrinted)) {
|
||||
return;
|
||||
}
|
||||
@@ -398,19 +397,12 @@ public final class CEditorQuestCardShop extends ACEditorBase<InventoryItem, Deck
|
||||
*/
|
||||
@Override
|
||||
public void init() {
|
||||
this.setup();
|
||||
setup();
|
||||
|
||||
this.decksUsingMyCards = this.countDecksForEachCard();
|
||||
|
||||
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);
|
||||
ownedItems.addAll(this.questData.getCards().getCardpool().getView());
|
||||
|
||||
|
||||
@@ -93,8 +93,7 @@ public final class CEditorVariant extends ACEditorBase<CardPrinted, Deck> {
|
||||
* @see forge.gui.deckeditor.ACEditorBase#addCard()
|
||||
*/
|
||||
@Override
|
||||
public void addCard() {
|
||||
final InventoryItem item = this.getTableCatalog().getSelectedCard();
|
||||
public void addCard(InventoryItem item) {
|
||||
if ((item == null) || !(item instanceof CardPrinted)) {
|
||||
return;
|
||||
}
|
||||
@@ -109,8 +108,7 @@ public final class CEditorVariant extends ACEditorBase<CardPrinted, Deck> {
|
||||
* @see forge.gui.deckeditor.ACEditorBase#removeCard()
|
||||
*/
|
||||
@Override
|
||||
public void removeCard() {
|
||||
final InventoryItem item = this.getTableDeck().getSelectedCard();
|
||||
public void removeCard(InventoryItem item) {
|
||||
if ((item == null) || !(item instanceof CardPrinted)) {
|
||||
return;
|
||||
}
|
||||
@@ -132,7 +130,7 @@ public final class CEditorVariant extends ACEditorBase<CardPrinted, Deck> {
|
||||
Iterable<CardPrinted> allNT = CardDb.instance().getAllNonTraditionalCards();
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ public enum CProbabilities implements ICDoc {
|
||||
CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController();
|
||||
|
||||
final ItemPoolView<CardPrinted> deck = ItemPool.createFrom(
|
||||
ed.getTableDeck().getCards(), CardPrinted.class);
|
||||
ed.getTableDeck().getCards(), CardPrinted.class, false);
|
||||
|
||||
final List<String> cardProbabilities = new ArrayList<String>();
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ public enum CStatistics implements ICDoc {
|
||||
if (ed == null) { return; }
|
||||
|
||||
final ItemPoolView<CardPrinted> deck = ItemPool.createFrom(
|
||||
ed.getTableDeck().getCards(), CardPrinted.class);
|
||||
ed.getTableDeck().getCards(), CardPrinted.class, false);
|
||||
|
||||
int total = deck.countAll();
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@@ -157,9 +158,11 @@ public final class EditorTableView<T extends InventoryItem> {
|
||||
Point p = e.getPoint();
|
||||
int row = rowAtPoint(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>
|
||||
*/
|
||||
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
|
||||
*/
|
||||
public void setDeck(final ItemPoolView<T> poolView) {
|
||||
this.setDeckImpl(ItemPool.createFrom(poolView, this.genericType));
|
||||
this.setDeckImpl(ItemPool.createFrom(poolView, this.genericType, false));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -299,6 +302,17 @@ public final class EditorTableView<T extends InventoryItem> {
|
||||
final int iRow = this.table.getSelectedRow();
|
||||
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() {
|
||||
return this.filter == null;
|
||||
@@ -313,7 +327,9 @@ public final class EditorTableView<T extends InventoryItem> {
|
||||
*/
|
||||
public void setFilter(final Predicate<T> filterToSet) {
|
||||
this.filter = filterToSet;
|
||||
this.updateView(true);
|
||||
if (null != pool) {
|
||||
this.updateView(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -328,7 +344,7 @@ public final class EditorTableView<T extends InventoryItem> {
|
||||
this.pool.add(card);
|
||||
if (this.isUnfiltered()) {
|
||||
this.model.addCard(card);
|
||||
}
|
||||
}
|
||||
this.updateView(false);
|
||||
}
|
||||
|
||||
@@ -348,6 +364,10 @@ public final class EditorTableView<T extends InventoryItem> {
|
||||
this.updateView(false);
|
||||
this.fixSelection(n);
|
||||
}
|
||||
|
||||
public int getCardCount(final T card) {
|
||||
return this.pool.count(card);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
@@ -63,7 +63,7 @@ public enum VCardCatalog implements IVDoc<CCardCatalog>, ITableContainer {
|
||||
private final FLabel btnAdd = new FLabel.Builder()
|
||||
.fontSize(14)
|
||||
.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))
|
||||
.iconScaleAuto(false).hoverable(true).build();
|
||||
private final FLabel btnAdd4 = new FLabel.Builder()
|
||||
@@ -239,6 +239,16 @@ public enum VCardCatalog implements IVDoc<CCardCatalog>, ITableContainer {
|
||||
.build();
|
||||
}
|
||||
|
||||
public void focusTable() {
|
||||
if (null != tblCards) {
|
||||
tblCards.requestFocusInWindow();
|
||||
|
||||
if (0 < tblCards.getRowCount()) {
|
||||
tblCards.changeSelection(0, 0, false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public void addRestrictionWidget(JComponent component, final Command onRemove) {
|
||||
final JPanel pnl = new JPanel(new MigLayout("insets 2, gap 2, h 30!"));
|
||||
|
||||
@@ -43,6 +43,10 @@ public class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
|
||||
super(cls);
|
||||
}
|
||||
|
||||
public ItemPool(final Class<T> cls, boolean infiniteStock) {
|
||||
super(cls, infiniteStock);
|
||||
}
|
||||
|
||||
/**
|
||||
* createFrom method.
|
||||
*
|
||||
@@ -58,8 +62,8 @@ public class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <Tin extends InventoryItem, Tout extends InventoryItem> ItemPool<Tout> createFrom(
|
||||
final ItemPoolView<Tin> from, final Class<Tout> clsHint) {
|
||||
final ItemPool<Tout> result = new ItemPool<Tout>(clsHint);
|
||||
final ItemPoolView<Tin> from, final Class<Tout> clsHint, boolean infiniteStock) {
|
||||
final ItemPool<Tout> result = new ItemPool<Tout>(clsHint, infiniteStock);
|
||||
if (from != null) {
|
||||
for (final Entry<Tin, Integer> e : from) {
|
||||
final Tin srcKey = e.getKey();
|
||||
@@ -86,8 +90,8 @@ public class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <Tin extends InventoryItem, Tout extends InventoryItem> ItemPool<Tout> createFrom(
|
||||
final Iterable<Tin> from, final Class<Tout> clsHint) {
|
||||
final ItemPool<Tout> result = new ItemPool<Tout>(clsHint);
|
||||
final Iterable<Tin> from, final Class<Tout> clsHint, boolean infiniteStock) {
|
||||
final ItemPool<Tout> result = new ItemPool<Tout>(clsHint, infiniteStock);
|
||||
if (from != null) {
|
||||
for (final Tin srcKey : from) {
|
||||
if (clsHint.isInstance(srcKey)) {
|
||||
|
||||
@@ -76,33 +76,28 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
||||
};
|
||||
|
||||
// Constructors
|
||||
/**
|
||||
*
|
||||
* ItemPoolView.
|
||||
*
|
||||
* @param cls
|
||||
* a Class<T>
|
||||
*/
|
||||
public ItemPoolView(final Class<T> cls) {
|
||||
this.cards = new Hashtable<T, Integer>();
|
||||
this.myClass = cls;
|
||||
this(cls, false);
|
||||
}
|
||||
|
||||
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) {
|
||||
this(inMap, cls, false);
|
||||
}
|
||||
|
||||
public ItemPoolView(final Map<T, Integer> inMap, final Class<T> cls, boolean infiniteStock) {
|
||||
this.cards = inMap;
|
||||
this.myClass = cls;
|
||||
this.infiniteStock = infiniteStock;
|
||||
}
|
||||
|
||||
// Data members
|
||||
// if this is true, queries for card count will return INT_MAX
|
||||
private final boolean infiniteStock;
|
||||
|
||||
/** The cards. */
|
||||
private final Map<T, Integer> cards;
|
||||
|
||||
@@ -157,7 +152,7 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
||||
return 0;
|
||||
}
|
||||
final Integer boxed = this.getCards().get(card);
|
||||
return boxed == null ? 0 : boxed.intValue();
|
||||
return boxed == null ? 0 : (infiniteStock ? Integer.MAX_VALUE : boxed.intValue());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -504,7 +504,8 @@ public final class QuestUtilCards {
|
||||
if (qc.getFormat() == null) {
|
||||
cardList = CardDb.instance().getAllTraditionalCards(); }
|
||||
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);
|
||||
|
||||
@@ -51,7 +51,7 @@ public class BoosterDraftTest implements IBoosterDraft {
|
||||
this.n--;
|
||||
BoosterData booster = Singletons.getModel().getBoosters().get("M11");
|
||||
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} */
|
||||
|
||||
Reference in New Issue
Block a user