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