mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
add pack filter in spell shop
This commit is contained in:
@@ -338,6 +338,9 @@ public final class CardRulesPredicates {
|
||||
|
||||
@Override
|
||||
public boolean apply(final CardRules subject) {
|
||||
if (null == subject) {
|
||||
return true;
|
||||
}
|
||||
switch (this.op) {
|
||||
case CountColors:
|
||||
return subject.getColor().countColors() == this.color;
|
||||
@@ -413,6 +416,9 @@ public final class CardRulesPredicates {
|
||||
|
||||
@Override
|
||||
public boolean apply(final CardRules card) {
|
||||
if (null == card) {
|
||||
return true;
|
||||
}
|
||||
return this.shouldBeEqual == card.getType().typeContains(this.operand);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,9 +32,7 @@ import forge.util.TextUtil;
|
||||
public final class SEditorUtil {
|
||||
/** An enum to encapsulate metadata for the stats/filter objects. */
|
||||
public static enum StatTypes {
|
||||
TOTAL (FSkin.ZoneImages.ICO_HAND, null),
|
||||
// PRODUCTS (FSkin.EditorImages.IMG_PRODUCTS, null),
|
||||
|
||||
TOTAL (FSkin.ZoneImages.ICO_HAND, null),
|
||||
WHITE (FSkin.ManaImages.IMG_WHITE, CardRulesPredicates.Presets.IS_WHITE),
|
||||
BLUE (FSkin.ManaImages.IMG_BLUE, CardRulesPredicates.Presets.IS_BLUE),
|
||||
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),
|
||||
MULTICOLOR (FSkin.EditorImages.IMG_MULTI, CardRulesPredicates.Presets.IS_MULTICOLOR),
|
||||
|
||||
PACK (FSkin.EditorImages.IMG_PACK, null),
|
||||
LAND (FSkin.EditorImages.IMG_LAND, CardRulesPredicates.Presets.IS_LAND),
|
||||
ARTIFACT (FSkin.EditorImages.IMG_ARTIFACT, CardRulesPredicates.Presets.IS_ARTIFACT),
|
||||
CREATURE (FSkin.EditorImages.IMG_CREATURE, CardRulesPredicates.Presets.IS_CREATURE),
|
||||
@@ -60,6 +59,9 @@ public final class SEditorUtil {
|
||||
}
|
||||
|
||||
public String toLabelString() {
|
||||
if (this == PACK) {
|
||||
return "Card packs and prebuilt decks";
|
||||
}
|
||||
return TextUtil.enumToLabel(this) + " cards";
|
||||
}
|
||||
}
|
||||
@@ -79,21 +81,24 @@ public final class SEditorUtil {
|
||||
* setStats.
|
||||
*
|
||||
* @param <T>   the generic type
|
||||
* @param deck   ItemPoolView<InventoryITem>
|
||||
* @param items   ItemPoolView<InventoryITem>
|
||||
* @param view   {@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()) {
|
||||
switch (s) {
|
||||
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;
|
||||
default:
|
||||
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
|
||||
|
||||
@@ -50,7 +50,7 @@ public class SFilterUtil {
|
||||
if (statLabels.get(s).getSelected()) { types.add(s.predicate); }
|
||||
break;
|
||||
|
||||
case TOTAL:
|
||||
case TOTAL: case PACK:
|
||||
// ignore
|
||||
break;
|
||||
|
||||
|
||||
@@ -319,20 +319,23 @@ public enum CCardCatalog implements ICDoc {
|
||||
VCardCatalog.SINGLETON_INSTANCE.getLblType().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.
|
||||
List<Predicate<? super CardPrinted>> itemPredicates = new ArrayList<Predicate<? super CardPrinted>>();
|
||||
itemPredicates.add(cardFilter);
|
||||
itemPredicates.add(ItemPredicate.Presets.IS_PACK);
|
||||
itemPredicates.add(ItemPredicate.Presets.IS_DECK);
|
||||
Predicate<CardPrinted> filter = Predicates.or(itemPredicates);
|
||||
// show packs and decks in the card shop according to the toggle setting
|
||||
// this is special-cased apart from the buildColorAndTypeFilter() above
|
||||
if (VCardCatalog.SINGLETON_INSTANCE.getStatLabel(SEditorUtil.StatTypes.PACK).getSelected()) {
|
||||
List<Predicate<? super CardPrinted>> itemPredicates = new ArrayList<Predicate<? super CardPrinted>>();
|
||||
itemPredicates.add(cardFilter);
|
||||
itemPredicates.add(ItemPredicate.Presets.IS_PACK);
|
||||
itemPredicates.add(ItemPredicate.Presets.IS_DECK);
|
||||
cardFilter = Predicates.or(itemPredicates);
|
||||
}
|
||||
|
||||
// Apply to table
|
||||
// TODO: is there really no way to make this type safe?
|
||||
ACEditorBase<?, ?> editor = CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController();
|
||||
if (null != editor) {
|
||||
((ACEditorBase<CardPrinted, DeckBase>)editor).getTableCatalog().setFilter(filter);
|
||||
((ACEditorBase<CardPrinted, DeckBase>)editor).getTableCatalog().setFilter(cardFilter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -462,6 +462,8 @@ public final class CEditorQuestCardShop extends ACEditorBase<InventoryItem, Deck
|
||||
VCardCatalog.SINGLETON_INSTANCE.getPnlAddButtons().add(sellPercentageLabel);
|
||||
this.sellPercentageLabel.setText("<html>Selling cards at " + formatter.format(multiPercent)
|
||||
+ "% of their value.<br>" + maxSellingPrice + "</html>");
|
||||
|
||||
VCardCatalog.SINGLETON_INSTANCE.getStatLabel(SEditorUtil.StatTypes.PACK).setVisible(true);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -492,6 +494,8 @@ public final class CEditorQuestCardShop extends ACEditorBase<InventoryItem, Deck
|
||||
VCardCatalog.SINGLETON_INSTANCE.getBtnAdd().setText(CCAddLabel);
|
||||
VCurrentDeck.SINGLETON_INSTANCE.getBtnRemove().setText(CDRemLabel);
|
||||
|
||||
VCardCatalog.SINGLETON_INSTANCE.getStatLabel(SEditorUtil.StatTypes.PACK).setVisible(false);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,6 @@ import com.google.common.collect.Iterables;
|
||||
import forge.gui.deckeditor.SEditorUtil;
|
||||
import forge.gui.deckeditor.views.ITableContainer;
|
||||
import forge.gui.toolbox.FSkin;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.ItemPool;
|
||||
import forge.item.ItemPoolView;
|
||||
@@ -188,7 +187,6 @@ public final class EditorTableView<T extends InventoryItem> {
|
||||
* @param view0   the {@link javax.gui.deckeditor.views.ITableCOntainer}
|
||||
* @param cols0   List<TableColumnInfo<InventoryItem>> of additional columns for this
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setup(final ITableContainer view0, final List<TableColumnInfo<InventoryItem>> cols0) {
|
||||
final DefaultTableColumnModel colmodel = new DefaultTableColumnModel();
|
||||
|
||||
@@ -211,17 +209,7 @@ public final class EditorTableView<T extends InventoryItem> {
|
||||
this.model.addTableModelListener(new TableModelListener() {
|
||||
@Override
|
||||
public void tableChanged(final TableModelEvent ev) {
|
||||
final List<T> deck = EditorTableView.this.model.getCards().toFlatList();
|
||||
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);
|
||||
SEditorUtil.setStats(EditorTableView.this.model.getCards(), view0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ public enum VCardCatalog implements IVDoc<CCardCatalog>, ITableContainer {
|
||||
private final FLabel lblTitle = new FLabel.Builder().fontSize(14).build();
|
||||
|
||||
// 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 Map<SEditorUtil.StatTypes, FLabel> statLabels =
|
||||
new HashMap<SEditorUtil.StatTypes, FLabel>();
|
||||
@@ -125,12 +126,19 @@ public enum VCardCatalog implements IVDoc<CCardCatalog>, ITableContainer {
|
||||
for (SEditorUtil.StatTypes s : SEditorUtil.StatTypes.values()) {
|
||||
FLabel label = buildToggleLabel(s, SEditorUtil.StatTypes.TOTAL != s);
|
||||
statLabels.put(s, label);
|
||||
JComponent component = label;
|
||||
if (SEditorUtil.StatTypes.TOTAL == s) {
|
||||
label.setToolTipText("Total cards (click to toggle all filters)");
|
||||
} else if (9 == statLabels.size()) {
|
||||
pnlStats.add(buildToggleLabel(null, false));
|
||||
} else if (SEditorUtil.StatTypes.PACK == s) {
|
||||
// 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);
|
||||
@@ -235,13 +243,12 @@ public enum VCardCatalog implements IVDoc<CCardCatalog>, ITableContainer {
|
||||
//========== Other methods
|
||||
private FLabel buildToggleLabel(SEditorUtil.StatTypes s, boolean selectable) {
|
||||
FLabel label = new FLabel.Builder()
|
||||
.icon(null == s ? null : s.img).iconScaleAuto(false)
|
||||
.icon(s.img).iconScaleAuto(false)
|
||||
.fontSize(11)
|
||||
.tooltip(null == s ? null : s.toLabelString() + "(click to toggle the filter for this card type)")
|
||||
.hoverable(null != s).selectable(selectable).selected(selectable)
|
||||
.tooltip(s.toLabelString() + " (click to toggle the filter)")
|
||||
.hoverable().selectable(selectable).selected(selectable)
|
||||
.build();
|
||||
|
||||
Dimension labelSize = new Dimension(60, 24);
|
||||
label.setPreferredSize(labelSize);
|
||||
label.setMinimumSize(labelSize);
|
||||
|
||||
|
||||
@@ -153,10 +153,11 @@ public enum VCurrentDeck implements IVDoc<CCurrentDeck>, ITableContainer {
|
||||
for (SEditorUtil.StatTypes s : SEditorUtil.StatTypes.values()) {
|
||||
FLabel label = buildLabel(s);
|
||||
statLabels.put(s, label);
|
||||
if (9 == statLabels.size()) {
|
||||
if (SEditorUtil.StatTypes.PACK == s) {
|
||||
pnlStats.add(buildLabel(null));
|
||||
} else {
|
||||
pnlStats.add(label);
|
||||
}
|
||||
pnlStats.add(label);
|
||||
}
|
||||
|
||||
pnlRemoveButtons.setOpaque(false);
|
||||
|
||||
@@ -324,7 +324,7 @@ public enum FSkin {
|
||||
IMG_LAND (new int[] {120, 720, 40, 40}), /** */
|
||||
IMG_MULTI (new int[] {80, 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});
|
||||
|
||||
private int[] coords;
|
||||
|
||||
@@ -171,6 +171,18 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user