mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 03:08:02 +00:00
Start working on new format filters
This commit is contained in:
@@ -9,6 +9,7 @@ import forge.card.CardRenderer;
|
||||
import forge.card.CardZoom;
|
||||
import forge.item.PaperCard;
|
||||
import forge.itemmanager.filters.CardColorFilter;
|
||||
import forge.itemmanager.filters.CardFormatFilter;
|
||||
import forge.itemmanager.filters.CardSearchFilter;
|
||||
import forge.itemmanager.filters.CardTypeFilter;
|
||||
import forge.itemmanager.filters.TextSearchFilter;
|
||||
@@ -36,6 +37,7 @@ public class CardManager extends ItemManager<PaperCard> {
|
||||
|
||||
public static void addDefaultFilters(final ItemManager<? super PaperCard> itemManager) {
|
||||
itemManager.addFilter(new CardColorFilter(itemManager));
|
||||
itemManager.addFilter(new CardFormatFilter(itemManager));
|
||||
itemManager.addFilter(new CardTypeFilter(itemManager));
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import forge.deck.FDeckViewer;
|
||||
import forge.deck.io.DeckPreferences;
|
||||
import forge.game.GameType;
|
||||
import forge.itemmanager.filters.DeckColorFilter;
|
||||
import forge.itemmanager.filters.DeckFormatFilter;
|
||||
import forge.itemmanager.filters.DeckSearchFilter;
|
||||
import forge.itemmanager.filters.TextSearchFilter;
|
||||
import forge.toolbox.FList;
|
||||
@@ -61,6 +62,7 @@ public final class DeckManager extends ItemManager<DeckProxy> {
|
||||
if (getConfig() == ItemManagerConfig.STRING_ONLY) { return; }
|
||||
|
||||
addFilter(new DeckColorFilter(this));
|
||||
addFilter(new DeckFormatFilter(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,7 +2,6 @@ package forge.itemmanager.filters;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import forge.game.GameFormat;
|
||||
import forge.item.PaperCard;
|
||||
import forge.itemmanager.ItemManager;
|
||||
import forge.itemmanager.SFilterUtil;
|
||||
@@ -12,9 +11,6 @@ public class CardFormatFilter extends FormatFilter<PaperCard> {
|
||||
public CardFormatFilter(ItemManager<? super PaperCard> itemManager0) {
|
||||
super(itemManager0);
|
||||
}
|
||||
public CardFormatFilter(ItemManager<? super PaperCard> itemManager0, GameFormat format0) {
|
||||
super(itemManager0, format0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemFilter<PaperCard> createCopy() {
|
||||
@@ -25,6 +21,6 @@ public class CardFormatFilter extends FormatFilter<PaperCard> {
|
||||
|
||||
@Override
|
||||
protected final Predicate<PaperCard> buildPredicate() {
|
||||
return SFilterUtil.buildFormatFilter(this.formats, this.allowReprints);
|
||||
return SFilterUtil.buildFormatFilter(this.formats, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,16 +12,15 @@ import java.util.Set;
|
||||
public class CardSetFilter extends CardFormatFilter {
|
||||
private final Set<String> sets = new HashSet<String>();
|
||||
|
||||
public CardSetFilter(ItemManager<? super PaperCard> itemManager0, Collection<String> sets0, boolean allowReprints0) {
|
||||
public CardSetFilter(ItemManager<? super PaperCard> itemManager0, Collection<String> sets0) {
|
||||
super(itemManager0);
|
||||
this.sets.addAll(sets0);
|
||||
this.formats.add(new GameFormat(null, this.sets, null));
|
||||
this.allowReprints = allowReprints0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemFilter<PaperCard> createCopy() {
|
||||
return new CardSetFilter(itemManager, this.sets, this.allowReprints);
|
||||
return new CardSetFilter(itemManager, this.sets);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -39,38 +38,8 @@ public class CardSetFilter extends CardFormatFilter {
|
||||
public boolean merge(ItemFilter<?> filter) {
|
||||
CardSetFilter cardSetFilter = (CardSetFilter)filter;
|
||||
this.sets.addAll(cardSetFilter.sets);
|
||||
this.allowReprints = cardSetFilter.allowReprints;
|
||||
this.formats.clear();
|
||||
this.formats.add(new GameFormat(null, this.sets, null));
|
||||
return true;
|
||||
}
|
||||
|
||||
public void edit() {
|
||||
/*final DialogChooseSets dialog = new DialogChooseSets(this.sets, null, true);
|
||||
dialog.setOkCallback(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
sets.clear();
|
||||
sets.addAll(dialog.getSelectedSets());
|
||||
allowReprints = dialog.getWantReprints();
|
||||
formats.clear();
|
||||
formats.add(new GameFormat(null, sets, null));
|
||||
}
|
||||
});*/
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getCaption() {
|
||||
return "Set";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getCount() {
|
||||
return this.sets.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Iterable<String> getList() {
|
||||
return this.sets;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package forge.itemmanager.filters;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import forge.deck.DeckProxy;
|
||||
import forge.game.GameFormat;
|
||||
import forge.itemmanager.ItemManager;
|
||||
import forge.itemmanager.SFilterUtil;
|
||||
|
||||
@@ -12,9 +11,6 @@ public class DeckFormatFilter extends FormatFilter<DeckProxy> {
|
||||
public DeckFormatFilter(ItemManager<? super DeckProxy> itemManager0) {
|
||||
super(itemManager0);
|
||||
}
|
||||
public DeckFormatFilter(ItemManager<? super DeckProxy> itemManager0, GameFormat format0) {
|
||||
super(itemManager0, format0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemFilter<DeckProxy> createCopy() {
|
||||
@@ -25,6 +21,6 @@ public class DeckFormatFilter extends FormatFilter<DeckProxy> {
|
||||
|
||||
@Override
|
||||
protected final Predicate<DeckProxy> buildPredicate() {
|
||||
return DeckProxy.createPredicate(SFilterUtil.buildFormatFilter(this.formats, this.allowReprints));
|
||||
return DeckProxy.createPredicate(SFilterUtil.buildFormatFilter(this.formats, true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,16 +12,15 @@ import java.util.Set;
|
||||
public class DeckSetFilter extends DeckFormatFilter {
|
||||
private final Set<String> sets = new HashSet<String>();
|
||||
|
||||
public DeckSetFilter(ItemManager<? super DeckProxy> itemManager0, Collection<String> sets0, boolean allowReprints0) {
|
||||
public DeckSetFilter(ItemManager<? super DeckProxy> itemManager0, Collection<String> sets0) {
|
||||
super(itemManager0);
|
||||
this.sets.addAll(sets0);
|
||||
this.formats.add(new GameFormat(null, this.sets, null));
|
||||
this.allowReprints = allowReprints0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemFilter<DeckProxy> createCopy() {
|
||||
return new DeckSetFilter(itemManager, this.sets, this.allowReprints);
|
||||
return new DeckSetFilter(itemManager, this.sets);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -39,7 +38,6 @@ public class DeckSetFilter extends DeckFormatFilter {
|
||||
public boolean merge(ItemFilter<?> filter) {
|
||||
DeckSetFilter cardSetFilter = (DeckSetFilter)filter;
|
||||
this.sets.addAll(cardSetFilter.sets);
|
||||
this.allowReprints = cardSetFilter.allowReprints;
|
||||
this.formats.clear();
|
||||
this.formats.add(new GameFormat(null, this.sets, null));
|
||||
return true;
|
||||
@@ -58,19 +56,4 @@ public class DeckSetFilter extends DeckFormatFilter {
|
||||
}
|
||||
});*/
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getCaption() {
|
||||
return "Set";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getCount() {
|
||||
return this.sets.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Iterable<String> getList() {
|
||||
return this.sets;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,82 +1,50 @@
|
||||
package forge.itemmanager.filters;
|
||||
|
||||
import forge.card.CardEdition;
|
||||
import forge.game.GameFormat;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.itemmanager.ItemManager;
|
||||
import forge.model.FModel;
|
||||
import forge.toolbox.FComboBox;
|
||||
import forge.toolbox.FEvent;
|
||||
import forge.toolbox.FEvent.FEventHandler;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public abstract class FormatFilter<T extends InventoryItem> extends ListLabelFilter<T> {
|
||||
protected boolean allowReprints = true;
|
||||
public abstract class FormatFilter<T extends InventoryItem> extends ItemFilter<T> {
|
||||
protected final Set<GameFormat> formats = new HashSet<GameFormat>();
|
||||
private FComboBox<Object> cbxFormats = new FComboBox<Object>();
|
||||
|
||||
public FormatFilter(ItemManager<? super T> itemManager0) {
|
||||
super(itemManager0);
|
||||
}
|
||||
public FormatFilter(ItemManager<? super T> itemManager0, GameFormat format0) {
|
||||
super(itemManager0);
|
||||
this.formats.add(format0);
|
||||
}
|
||||
|
||||
cbxFormats.addItem("All Formats");
|
||||
for (GameFormat format : FModel.getFormats()) {
|
||||
cbxFormats.addItem(format);
|
||||
}
|
||||
cbxFormats.addItem("More...");
|
||||
cbxFormats.setChangedHandler(new FEventHandler() {
|
||||
@Override
|
||||
protected String getTooltip() {
|
||||
Set<String> sets = new HashSet<String>();
|
||||
Set<String> bannedCards = new HashSet<String>();
|
||||
|
||||
for (GameFormat format : this.formats) {
|
||||
List<String> formatSets = format.getAllowedSetCodes();
|
||||
if (formatSets != null) {
|
||||
sets.addAll(formatSets);
|
||||
public void handleEvent(FEvent e) {
|
||||
if (cbxFormats.getSelectedIndex() == 0) {
|
||||
formats.clear();
|
||||
}
|
||||
List<String> formatBannedCards = format.getBannedCardNames();
|
||||
if (formatBannedCards != null) {
|
||||
bannedCards.addAll(formatBannedCards);
|
||||
}
|
||||
}
|
||||
|
||||
//use HTML tooltips so we can insert line breaks
|
||||
StringBuilder tooltip = new StringBuilder("Sets:");
|
||||
if (sets.isEmpty()) {
|
||||
tooltip.append(" All");
|
||||
else if (cbxFormats.getSelectedIndex() < cbxFormats.getItemCount() - 1) {
|
||||
formats.clear();
|
||||
formats.add((GameFormat)cbxFormats.getSelectedItem());
|
||||
}
|
||||
else {
|
||||
CardEdition.Collection editions = FModel.getMagicDb().getEditions();
|
||||
|
||||
for (String code : sets) {
|
||||
CardEdition edition = editions.get(code);
|
||||
tooltip.append(" ").append(edition.getName()).append(" (").append(code).append("),");
|
||||
}
|
||||
|
||||
// chop off last comma
|
||||
tooltip.delete(tooltip.length() - 1, tooltip.length());
|
||||
|
||||
if (this.allowReprints) {
|
||||
tooltip.append("\n\nAllowing identical cards from other sets.");
|
||||
//TODO: Open screen to select one or more sets and/or formats
|
||||
}
|
||||
}
|
||||
|
||||
if (!bannedCards.isEmpty()) {
|
||||
tooltip.append("\n\nBanned:");
|
||||
|
||||
for (String cardName : bannedCards) {
|
||||
tooltip.append(" ").append(cardName).append(";");
|
||||
}
|
||||
|
||||
// chop off last semicolon
|
||||
tooltip.delete(tooltip.length() - 1, tooltip.length());
|
||||
}
|
||||
return tooltip.toString();
|
||||
});
|
||||
cbxFormats.setSelectedIndex(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
this.formats.clear();
|
||||
this.updateLabel();
|
||||
}
|
||||
|
||||
public static <T extends InventoryItem> boolean canAddFormat(GameFormat format, FormatFilter<T> existingFilter) {
|
||||
@@ -93,26 +61,21 @@ public abstract class FormatFilter<T extends InventoryItem> extends ListLabelFil
|
||||
public boolean merge(ItemFilter<?> filter) {
|
||||
FormatFilter<T> formatFilter = (FormatFilter<T>)filter;
|
||||
this.formats.addAll(formatFilter.formats);
|
||||
this.allowReprints = formatFilter.allowReprints;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getCaption() {
|
||||
return "Format";
|
||||
public boolean isEmpty() {
|
||||
return formats.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getCount() {
|
||||
return this.formats.size();
|
||||
protected void buildWidget(Widget widget) {
|
||||
widget.add(cbxFormats);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Iterable<String> getList() {
|
||||
Set<String> strings = new HashSet<String>();
|
||||
for (GameFormat f : this.formats) {
|
||||
strings.add(f.getName());
|
||||
}
|
||||
return strings;
|
||||
protected void doWidgetLayout(float width, float height) {
|
||||
cbxFormats.setSize(width, height);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user