mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
Add rarity long names
Support clearing filter
This commit is contained in:
@@ -17,31 +17,42 @@
|
||||
*/
|
||||
package forge.card;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
public enum CardRarity {
|
||||
BasicLand("L"),
|
||||
Common("C"),
|
||||
Uncommon("U"),
|
||||
Rare("R"),
|
||||
MythicRare("M"),
|
||||
Special("S"), // Timeshifted
|
||||
Unknown("?"); // In development
|
||||
BasicLand("L", "Basic Land"),
|
||||
Common("C", "Common"),
|
||||
Uncommon("U", "Uncommon"),
|
||||
Rare("R", "Rare"),
|
||||
MythicRare("M", "Mythic Rare"),
|
||||
Special("S", "Special"), // Timeshifted
|
||||
Unknown("?", "Unknown"); // In development
|
||||
|
||||
private final String strValue;
|
||||
private final String shortName, longName;
|
||||
|
||||
private CardRarity(final String sValue) {
|
||||
this.strValue = sValue;
|
||||
private CardRarity(final String shortName0, final String longName0) {
|
||||
shortName = shortName0;
|
||||
longName = longName0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.strValue;
|
||||
return shortName;
|
||||
}
|
||||
|
||||
public static CardRarity smartValueOf(String input) {
|
||||
for(CardRarity r : CardRarity.values()) {
|
||||
if( r.name().equalsIgnoreCase(input) || r.strValue.equalsIgnoreCase(input))
|
||||
for (CardRarity r : CardRarity.values()) {
|
||||
if (r.name().equalsIgnoreCase(input) || r.shortName.equalsIgnoreCase(input) || r.longName.equalsIgnoreCase(input)) {
|
||||
return r;
|
||||
}
|
||||
}
|
||||
return Unknown;
|
||||
}
|
||||
|
||||
public static final Function<CardRarity, String> FN_GET_LONG_NAME = new Function<CardRarity, String>() {
|
||||
@Override
|
||||
public String apply(final CardRarity rarity) {
|
||||
return rarity.longName;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -224,6 +224,7 @@ public class AdvancedSearchFilter<T extends InventoryItem> extends ItemFilter<T>
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void removeNextFilter(Filter fromFilter) {
|
||||
int index = scroller.indexOf(fromFilter);
|
||||
if (index < scroller.getChildCount() - 1) {
|
||||
@@ -254,12 +255,17 @@ public class AdvancedSearchFilter<T extends InventoryItem> extends ItemFilter<T>
|
||||
@Override
|
||||
public void run() {
|
||||
final AdvancedSearch.Filter<T> newFilter = AdvancedSearch.getFilter(itemManager.getGenericType(), filter);
|
||||
if (newFilter != null) {
|
||||
if (filter != newFilter) {
|
||||
FThreads.invokeInEdtLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
filter = newFilter;
|
||||
btnFilter.setText(filter.toString());
|
||||
if (filter != null) {
|
||||
btnFilter.setText(filter.toString());
|
||||
}
|
||||
else {
|
||||
btnFilter.setText(emptyFilterText);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import forge.util.gui.SOptionPane;
|
||||
|
||||
public class AdvancedSearch {
|
||||
private enum FilterOption {
|
||||
NONE("(none)", null, null, null),
|
||||
CARD_NAME("Name", PaperCard.class, FilterOperator.STRING_OPS, new StringEvaluator<PaperCard>() {
|
||||
@Override
|
||||
protected String getItemValue(PaperCard input) {
|
||||
@@ -140,7 +141,7 @@ public class AdvancedSearch {
|
||||
return input.getRules().getManaCost().toString();
|
||||
}
|
||||
}),
|
||||
CARD_RARITY("Rarity", PaperCard.class, FilterOperator.SINGLE_LIST_OPS, new CustomListEvaluator<PaperCard, CardRarity>(Arrays.asList(CardRarity.values())) {
|
||||
CARD_RARITY("Rarity", PaperCard.class, FilterOperator.SINGLE_LIST_OPS, new CustomListEvaluator<PaperCard, CardRarity>(Arrays.asList(CardRarity.values()), CardRarity.FN_GET_LONG_NAME, CardRarity.FN_GET_LONG_NAME) {
|
||||
@Override
|
||||
protected CardRarity getItemValue(PaperCard input) {
|
||||
return input.getRarity();
|
||||
@@ -567,6 +568,9 @@ public class AdvancedSearch {
|
||||
public static <T extends InventoryItem> Filter<T> getFilter(Class<? super T> type, Filter<T> editFilter) {
|
||||
//build list of filter options based on ItemManager type
|
||||
List<FilterOption> options = new ArrayList<FilterOption>();
|
||||
if (editFilter != null) {
|
||||
options.add(FilterOption.NONE); //provide option to clear existing filter
|
||||
}
|
||||
for (FilterOption opt : FilterOption.values()) {
|
||||
if (opt.type == type) {
|
||||
options.add(opt);
|
||||
@@ -575,11 +579,13 @@ public class AdvancedSearch {
|
||||
|
||||
final FilterOption defaultOption = editFilter == null ? null : editFilter.option;
|
||||
final FilterOption option = SGuiChoose.oneOrNone("Select a filter type", options, defaultOption, null);
|
||||
if (option == null) { return null; }
|
||||
if (option == null) { return editFilter; }
|
||||
|
||||
if (option == FilterOption.NONE) { return null; } //allow user to clear filter by selecting "(none)"
|
||||
|
||||
final FilterOperator defaultOperator = option == defaultOption ? editFilter.operator : null;
|
||||
final FilterOperator operator = SGuiChoose.oneOrNone("Select an operator for " + option.name, option.operatorOptions, defaultOperator, null);
|
||||
if (operator == null) { return null; }
|
||||
if (operator == null) { return editFilter; }
|
||||
|
||||
final String message = option.name + " " + operator.caption + " ?";
|
||||
return (Filter<T>)option.evaluator.createFilter(message, option, operator);
|
||||
|
||||
Reference in New Issue
Block a user