add pack filter in spell shop

This commit is contained in:
myk
2013-02-07 10:50:38 +00:00
parent e0a599fcbe
commit c0c541832e
10 changed files with 66 additions and 40 deletions

View File

@@ -338,6 +338,9 @@ public final class CardRulesPredicates {
@Override @Override
public boolean apply(final CardRules subject) { public boolean apply(final CardRules subject) {
if (null == subject) {
return true;
}
switch (this.op) { switch (this.op) {
case CountColors: case CountColors:
return subject.getColor().countColors() == this.color; return subject.getColor().countColors() == this.color;
@@ -413,6 +416,9 @@ public final class CardRulesPredicates {
@Override @Override
public boolean apply(final CardRules card) { public boolean apply(final CardRules card) {
if (null == card) {
return true;
}
return this.shouldBeEqual == card.getType().typeContains(this.operand); return this.shouldBeEqual == card.getType().typeContains(this.operand);
} }

View File

@@ -32,9 +32,7 @@ import forge.util.TextUtil;
public final class SEditorUtil { public final class SEditorUtil {
/** An enum to encapsulate metadata for the stats/filter objects. */ /** An enum to encapsulate metadata for the stats/filter objects. */
public static enum StatTypes { public static enum StatTypes {
TOTAL (FSkin.ZoneImages.ICO_HAND, null), TOTAL (FSkin.ZoneImages.ICO_HAND, null),
// PRODUCTS (FSkin.EditorImages.IMG_PRODUCTS, null),
WHITE (FSkin.ManaImages.IMG_WHITE, CardRulesPredicates.Presets.IS_WHITE), WHITE (FSkin.ManaImages.IMG_WHITE, CardRulesPredicates.Presets.IS_WHITE),
BLUE (FSkin.ManaImages.IMG_BLUE, CardRulesPredicates.Presets.IS_BLUE), BLUE (FSkin.ManaImages.IMG_BLUE, CardRulesPredicates.Presets.IS_BLUE),
BLACK (FSkin.ManaImages.IMG_BLACK, CardRulesPredicates.Presets.IS_BLACK), BLACK (FSkin.ManaImages.IMG_BLACK, CardRulesPredicates.Presets.IS_BLACK),
@@ -43,6 +41,7 @@ public final class SEditorUtil {
COLORLESS (FSkin.ManaImages.IMG_COLORLESS, CardRulesPredicates.Presets.IS_COLORLESS), COLORLESS (FSkin.ManaImages.IMG_COLORLESS, CardRulesPredicates.Presets.IS_COLORLESS),
MULTICOLOR (FSkin.EditorImages.IMG_MULTI, CardRulesPredicates.Presets.IS_MULTICOLOR), MULTICOLOR (FSkin.EditorImages.IMG_MULTI, CardRulesPredicates.Presets.IS_MULTICOLOR),
PACK (FSkin.EditorImages.IMG_PACK, null),
LAND (FSkin.EditorImages.IMG_LAND, CardRulesPredicates.Presets.IS_LAND), LAND (FSkin.EditorImages.IMG_LAND, CardRulesPredicates.Presets.IS_LAND),
ARTIFACT (FSkin.EditorImages.IMG_ARTIFACT, CardRulesPredicates.Presets.IS_ARTIFACT), ARTIFACT (FSkin.EditorImages.IMG_ARTIFACT, CardRulesPredicates.Presets.IS_ARTIFACT),
CREATURE (FSkin.EditorImages.IMG_CREATURE, CardRulesPredicates.Presets.IS_CREATURE), CREATURE (FSkin.EditorImages.IMG_CREATURE, CardRulesPredicates.Presets.IS_CREATURE),
@@ -60,6 +59,9 @@ public final class SEditorUtil {
} }
public String toLabelString() { public String toLabelString() {
if (this == PACK) {
return "Card packs and prebuilt decks";
}
return TextUtil.enumToLabel(this) + " cards"; return TextUtil.enumToLabel(this) + " cards";
} }
} }
@@ -79,21 +81,24 @@ public final class SEditorUtil {
* setStats. * setStats.
* *
* @param <T> &emsp; the generic type * @param <T> &emsp; the generic type
* @param deck &emsp; ItemPoolView<InventoryITem> * @param items &emsp; ItemPoolView<InventoryITem>
* @param view &emsp; {@link forge.gui.deckeditor.views.ITableContainer} * @param view &emsp; {@link forge.gui.deckeditor.views.ITableContainer}
*/ */
public static <T extends InventoryItem> void setStats(final ItemPoolView<T> deck, final ITableContainer view) { public static <T extends InventoryItem> void setStats(final ItemPoolView<T> items, final ITableContainer view) {
for (StatTypes s : StatTypes.values()) { for (StatTypes s : StatTypes.values()) {
switch (s) { switch (s) {
case TOTAL: case TOTAL:
view.getStatLabel(StatTypes.TOTAL).setText(String.valueOf(deck.countAll())); view.getStatLabel(s).setText(String.valueOf(items.countAll()));
break;
case PACK:
view.getStatLabel(s).setText(String.valueOf(items.countNonCards()));
break; break;
default: default:
view.getStatLabel(s).setText(String.valueOf( view.getStatLabel(s).setText(String.valueOf(
Aggregates.sum(Iterables.filter(deck, Predicates.compose(s.predicate, deck.getFnToCard())), deck.getFnToCount()))); Aggregates.sum(Iterables.filter(items, Predicates.compose(s.predicate, items.getFnToCard())), items.getFnToCount())));
} }
} }
} // getStats() }
/** /**
* Resets components that may have been changed * Resets components that may have been changed

View File

@@ -50,7 +50,7 @@ public class SFilterUtil {
if (statLabels.get(s).getSelected()) { types.add(s.predicate); } if (statLabels.get(s).getSelected()) { types.add(s.predicate); }
break; break;
case TOTAL: case TOTAL: case PACK:
// ignore // ignore
break; break;

View File

@@ -319,20 +319,23 @@ public enum CCardCatalog implements ICDoc {
VCardCatalog.SINGLETON_INSTANCE.getLblType().getSelected(), VCardCatalog.SINGLETON_INSTANCE.getLblType().getSelected(),
VCardCatalog.SINGLETON_INSTANCE.getLblText().getSelected())); VCardCatalog.SINGLETON_INSTANCE.getLblText().getSelected()));
Predicate<? super CardPrinted> cardFilter = Predicates.and(cardPredicates); Predicate<CardPrinted> cardFilter = Predicates.and(cardPredicates);
// Until this is filterable, always show packs and decks in the card shop. // show packs and decks in the card shop according to the toggle setting
List<Predicate<? super CardPrinted>> itemPredicates = new ArrayList<Predicate<? super CardPrinted>>(); // this is special-cased apart from the buildColorAndTypeFilter() above
itemPredicates.add(cardFilter); if (VCardCatalog.SINGLETON_INSTANCE.getStatLabel(SEditorUtil.StatTypes.PACK).getSelected()) {
itemPredicates.add(ItemPredicate.Presets.IS_PACK); List<Predicate<? super CardPrinted>> itemPredicates = new ArrayList<Predicate<? super CardPrinted>>();
itemPredicates.add(ItemPredicate.Presets.IS_DECK); itemPredicates.add(cardFilter);
Predicate<CardPrinted> filter = Predicates.or(itemPredicates); itemPredicates.add(ItemPredicate.Presets.IS_PACK);
itemPredicates.add(ItemPredicate.Presets.IS_DECK);
cardFilter = Predicates.or(itemPredicates);
}
// 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<?, ?> editor = CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController(); ACEditorBase<?, ?> editor = CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController();
if (null != editor) { if (null != editor) {
((ACEditorBase<CardPrinted, DeckBase>)editor).getTableCatalog().setFilter(filter); ((ACEditorBase<CardPrinted, DeckBase>)editor).getTableCatalog().setFilter(cardFilter);
} }
} }

View File

@@ -462,6 +462,8 @@ public final class CEditorQuestCardShop extends ACEditorBase<InventoryItem, Deck
VCardCatalog.SINGLETON_INSTANCE.getPnlAddButtons().add(sellPercentageLabel); VCardCatalog.SINGLETON_INSTANCE.getPnlAddButtons().add(sellPercentageLabel);
this.sellPercentageLabel.setText("<html>Selling cards at " + formatter.format(multiPercent) this.sellPercentageLabel.setText("<html>Selling cards at " + formatter.format(multiPercent)
+ "% of their value.<br>" + maxSellingPrice + "</html>"); + "% of their value.<br>" + maxSellingPrice + "</html>");
VCardCatalog.SINGLETON_INSTANCE.getStatLabel(SEditorUtil.StatTypes.PACK).setVisible(true);
} }
/* (non-Javadoc) /* (non-Javadoc)
@@ -492,6 +494,8 @@ public final class CEditorQuestCardShop extends ACEditorBase<InventoryItem, Deck
VCardCatalog.SINGLETON_INSTANCE.getBtnAdd().setText(CCAddLabel); VCardCatalog.SINGLETON_INSTANCE.getBtnAdd().setText(CCAddLabel);
VCurrentDeck.SINGLETON_INSTANCE.getBtnRemove().setText(CDRemLabel); VCurrentDeck.SINGLETON_INSTANCE.getBtnRemove().setText(CDRemLabel);
VCardCatalog.SINGLETON_INSTANCE.getStatLabel(SEditorUtil.StatTypes.PACK).setVisible(false);
return true; return true;
} }
} }

View File

@@ -44,7 +44,6 @@ import com.google.common.collect.Iterables;
import forge.gui.deckeditor.SEditorUtil; import forge.gui.deckeditor.SEditorUtil;
import forge.gui.deckeditor.views.ITableContainer; import forge.gui.deckeditor.views.ITableContainer;
import forge.gui.toolbox.FSkin; import forge.gui.toolbox.FSkin;
import forge.item.CardPrinted;
import forge.item.InventoryItem; import forge.item.InventoryItem;
import forge.item.ItemPool; import forge.item.ItemPool;
import forge.item.ItemPoolView; import forge.item.ItemPoolView;
@@ -188,7 +187,6 @@ public final class EditorTableView<T extends InventoryItem> {
* @param view0 &emsp; the {@link javax.gui.deckeditor.views.ITableCOntainer} * @param view0 &emsp; the {@link javax.gui.deckeditor.views.ITableCOntainer}
* @param cols0 &emsp; List<TableColumnInfo<InventoryItem>> of additional columns for this * @param cols0 &emsp; List<TableColumnInfo<InventoryItem>> of additional columns for this
*/ */
@SuppressWarnings("unchecked")
public void setup(final ITableContainer view0, final List<TableColumnInfo<InventoryItem>> cols0) { public void setup(final ITableContainer view0, final List<TableColumnInfo<InventoryItem>> cols0) {
final DefaultTableColumnModel colmodel = new DefaultTableColumnModel(); final DefaultTableColumnModel colmodel = new DefaultTableColumnModel();
@@ -211,17 +209,7 @@ public final class EditorTableView<T extends InventoryItem> {
this.model.addTableModelListener(new TableModelListener() { this.model.addTableModelListener(new TableModelListener() {
@Override @Override
public void tableChanged(final TableModelEvent ev) { public void tableChanged(final TableModelEvent ev) {
final List<T> deck = EditorTableView.this.model.getCards().toFlatList(); SEditorUtil.setStats(EditorTableView.this.model.getCards(), view0);
final ItemPool<T> filteredDeck = new ItemPool<T>((Class<T>) CardPrinted.class);
// Filter out non-card items (booster packs, etc.)
for (T item : deck) {
if (item instanceof CardPrinted) {
filteredDeck.add(item, 1);
}
}
SEditorUtil.setStats(filteredDeck, view0);
} }
}); });
} }

View File

@@ -54,6 +54,7 @@ public enum VCardCatalog implements IVDoc<CCardCatalog>, ITableContainer {
private final FLabel lblTitle = new FLabel.Builder().fontSize(14).build(); private final FLabel lblTitle = new FLabel.Builder().fontSize(14).build();
// Total and color count labels/filter toggles // Total and color count labels/filter toggles
private final Dimension labelSize = new Dimension(60, 24);
private final JPanel pnlStats = new JPanel(new WrapLayout(FlowLayout.LEFT)); private final JPanel pnlStats = new JPanel(new WrapLayout(FlowLayout.LEFT));
private final Map<SEditorUtil.StatTypes, FLabel> statLabels = private final Map<SEditorUtil.StatTypes, FLabel> statLabels =
new HashMap<SEditorUtil.StatTypes, FLabel>(); new HashMap<SEditorUtil.StatTypes, FLabel>();
@@ -125,12 +126,19 @@ public enum VCardCatalog implements IVDoc<CCardCatalog>, ITableContainer {
for (SEditorUtil.StatTypes s : SEditorUtil.StatTypes.values()) { for (SEditorUtil.StatTypes s : SEditorUtil.StatTypes.values()) {
FLabel label = buildToggleLabel(s, SEditorUtil.StatTypes.TOTAL != s); FLabel label = buildToggleLabel(s, SEditorUtil.StatTypes.TOTAL != s);
statLabels.put(s, label); statLabels.put(s, label);
JComponent component = label;
if (SEditorUtil.StatTypes.TOTAL == s) { if (SEditorUtil.StatTypes.TOTAL == s) {
label.setToolTipText("Total cards (click to toggle all filters)"); label.setToolTipText("Total cards (click to toggle all filters)");
} else if (9 == statLabels.size()) { } else if (SEditorUtil.StatTypes.PACK == s) {
pnlStats.add(buildToggleLabel(null, false)); // wrap in a constant-size panel so we can change its visibility without affecting layout
component = new JPanel(new MigLayout("insets 0, gap 0"));
component.setPreferredSize(labelSize);
component.setMinimumSize(labelSize);
component.setOpaque(false);
label.setVisible(false);
component.add(label);
} }
pnlStats.add(label); pnlStats.add(component);
} }
pnlAddButtons.setOpaque(false); pnlAddButtons.setOpaque(false);
@@ -235,13 +243,12 @@ public enum VCardCatalog implements IVDoc<CCardCatalog>, ITableContainer {
//========== Other methods //========== Other methods
private FLabel buildToggleLabel(SEditorUtil.StatTypes s, boolean selectable) { private FLabel buildToggleLabel(SEditorUtil.StatTypes s, boolean selectable) {
FLabel label = new FLabel.Builder() FLabel label = new FLabel.Builder()
.icon(null == s ? null : s.img).iconScaleAuto(false) .icon(s.img).iconScaleAuto(false)
.fontSize(11) .fontSize(11)
.tooltip(null == s ? null : s.toLabelString() + "(click to toggle the filter for this card type)") .tooltip(s.toLabelString() + " (click to toggle the filter)")
.hoverable(null != s).selectable(selectable).selected(selectable) .hoverable().selectable(selectable).selected(selectable)
.build(); .build();
Dimension labelSize = new Dimension(60, 24);
label.setPreferredSize(labelSize); label.setPreferredSize(labelSize);
label.setMinimumSize(labelSize); label.setMinimumSize(labelSize);

View File

@@ -153,10 +153,11 @@ public enum VCurrentDeck implements IVDoc<CCurrentDeck>, ITableContainer {
for (SEditorUtil.StatTypes s : SEditorUtil.StatTypes.values()) { for (SEditorUtil.StatTypes s : SEditorUtil.StatTypes.values()) {
FLabel label = buildLabel(s); FLabel label = buildLabel(s);
statLabels.put(s, label); statLabels.put(s, label);
if (9 == statLabels.size()) { if (SEditorUtil.StatTypes.PACK == s) {
pnlStats.add(buildLabel(null)); pnlStats.add(buildLabel(null));
} else {
pnlStats.add(label);
} }
pnlStats.add(label);
} }
pnlRemoveButtons.setOpaque(false); pnlRemoveButtons.setOpaque(false);

View File

@@ -324,7 +324,7 @@ public enum FSkin {
IMG_LAND (new int[] {120, 720, 40, 40}), /** */ IMG_LAND (new int[] {120, 720, 40, 40}), /** */
IMG_MULTI (new int[] {80, 720, 40, 40}), /** */ IMG_MULTI (new int[] {80, 720, 40, 40}), /** */
IMG_PLANESWALKER (new int[] {200, 720, 40, 40}), /** */ IMG_PLANESWALKER (new int[] {200, 720, 40, 40}), /** */
IMG_PRODUCTS (new int[] {80, 760, 40, 40}), /** */ IMG_PACK (new int[] {80, 760, 40, 40}), /** */
IMG_SORCERY (new int[] {160, 720, 40, 40}); IMG_SORCERY (new int[] {160, 720, 40, 40});
private int[] coords; private int[] coords;

View File

@@ -171,6 +171,18 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
return result; return result;
} }
public final int countNonCards() {
int result = 0;
if (this.getCards() != null) {
for (Map.Entry<T, Integer> e : cards.entrySet()) {
if (!(e.getKey() instanceof CardPrinted)) {
result += e.getValue();
}
}
}
return result;
}
/** /**
* *
* countDistinct. * countDistinct.