mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
Improve display of advanced color filters
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package forge.card;
|
package forge.card;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
@@ -153,19 +154,20 @@ public final class MagicColor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public enum Color {
|
public enum Color {
|
||||||
WHITE(Constant.WHITE, MagicColor.WHITE),
|
WHITE(Constant.WHITE, MagicColor.WHITE, "{W}"),
|
||||||
BLUE(Constant.BLUE, MagicColor.BLUE),
|
BLUE(Constant.BLUE, MagicColor.BLUE, "{U}"),
|
||||||
BLACK(Constant.BLACK, MagicColor.BLACK),
|
BLACK(Constant.BLACK, MagicColor.BLACK, "{B}"),
|
||||||
RED(Constant.RED, MagicColor.RED),
|
RED(Constant.RED, MagicColor.RED, "{R}"),
|
||||||
GREEN(Constant.GREEN, MagicColor.GREEN),
|
GREEN(Constant.GREEN, MagicColor.GREEN, "{G}"),
|
||||||
COLORLESS(Constant.COLORLESS, MagicColor.COLORLESS);
|
COLORLESS(Constant.COLORLESS, MagicColor.COLORLESS, "{X}");
|
||||||
|
|
||||||
private final String name;
|
private final String name, symbol;
|
||||||
private final byte colormask;
|
private final byte colormask;
|
||||||
|
|
||||||
private Color(String name0, byte colormask0) {
|
private Color(String name0, byte colormask0, String symbol0) {
|
||||||
name = name0;
|
name = name0;
|
||||||
colormask = colormask0;
|
colormask = colormask0;
|
||||||
|
symbol = symbol0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@@ -174,9 +176,19 @@ public final class MagicColor {
|
|||||||
public byte getColormask() {
|
public byte getColormask() {
|
||||||
return colormask;
|
return colormask;
|
||||||
}
|
}
|
||||||
|
public String getSymbol() {
|
||||||
|
return symbol;
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final Function<Color, String> FN_GET_SYMBOL = new Function<Color, String>() {
|
||||||
|
@Override
|
||||||
|
public String apply(final Color color) {
|
||||||
|
return color.symbol;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ public class AdvancedSearchFilter<T extends InventoryItem> extends ItemFilter<T>
|
|||||||
|
|
||||||
private void updateLabel() {
|
private void updateLabel() {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append("Filters: ");
|
builder.append("Filter: ");
|
||||||
if (expression.isEmpty()) {
|
if (expression.isEmpty()) {
|
||||||
builder.append("(none)");
|
builder.append("(none)");
|
||||||
}
|
}
|
||||||
@@ -136,7 +136,7 @@ public class AdvancedSearchFilter<T extends InventoryItem> extends ItemFilter<T>
|
|||||||
if (expression.isEmpty()) { return ""; }
|
if (expression.isEmpty()) { return ""; }
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append("Filters:\n");
|
builder.append("Filter:\n");
|
||||||
|
|
||||||
String indent = "";
|
String indent = "";
|
||||||
|
|
||||||
@@ -181,7 +181,7 @@ public class AdvancedSearchFilter<T extends InventoryItem> extends ItemFilter<T>
|
|||||||
|
|
||||||
private class FiltersLabel extends FLabel {
|
private class FiltersLabel extends FLabel {
|
||||||
private FiltersLabel() {
|
private FiltersLabel() {
|
||||||
super(new FLabel.Builder().align(HAlignment.LEFT).font(ListLabelFilter.LABEL_FONT));
|
super(new FLabel.Builder().align(HAlignment.LEFT).parseSymbols(true).font(ListLabelFilter.LABEL_FONT));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -294,7 +294,7 @@ public class AdvancedSearchFilter<T extends InventoryItem> extends ItemFilter<T>
|
|||||||
btnNotAfterParen = add(new FLabel.Builder().align(HAlignment.CENTER).text("NOT").selectable().build());
|
btnNotAfterParen = add(new FLabel.Builder().align(HAlignment.CENTER).text("NOT").selectable().build());
|
||||||
|
|
||||||
final String emptyFilterText = "Select Filter...";
|
final String emptyFilterText = "Select Filter...";
|
||||||
btnFilter = add(new FLabel.ButtonBuilder().text(emptyFilterText).command(new FEventHandler() {
|
btnFilter = add(new FLabel.ButtonBuilder().text(emptyFilterText).parseSymbols(true).command(new FEventHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void handleEvent(FEvent e) {
|
public void handleEvent(FEvent e) {
|
||||||
FThreads.invokeInBackgroundThread(new Runnable() {
|
FThreads.invokeInBackgroundThread(new Runnable() {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import forge.UiCommand;
|
|||||||
import forge.assets.FImage;
|
import forge.assets.FImage;
|
||||||
import forge.assets.FSkinColor;
|
import forge.assets.FSkinColor;
|
||||||
import forge.assets.FSkinProp;
|
import forge.assets.FSkinProp;
|
||||||
|
import forge.assets.TextRenderer;
|
||||||
import forge.assets.FSkinColor.Colors;
|
import forge.assets.FSkinColor.Colors;
|
||||||
import forge.assets.FSkinFont;
|
import forge.assets.FSkinFont;
|
||||||
import forge.interfaces.IButton;
|
import forge.interfaces.IButton;
|
||||||
@@ -33,6 +34,7 @@ public class FLabel extends FDisplayObject implements IButton {
|
|||||||
private boolean bldIconInBackground = false;
|
private boolean bldIconInBackground = false;
|
||||||
private boolean bldIconScaleAuto = true;
|
private boolean bldIconScaleAuto = true;
|
||||||
private boolean bldEnabled = true;
|
private boolean bldEnabled = true;
|
||||||
|
private boolean bldParseSymbols = true;
|
||||||
|
|
||||||
private String bldText;
|
private String bldText;
|
||||||
private FImage bldIcon;
|
private FImage bldIcon;
|
||||||
@@ -63,6 +65,8 @@ public class FLabel extends FDisplayObject implements IButton {
|
|||||||
public Builder iconInBackground() { iconInBackground(true); return this; }
|
public Builder iconInBackground() { iconInBackground(true); return this; }
|
||||||
public Builder textColor(final FSkinColor c0) { this.bldTextColor = c0; return this; }
|
public Builder textColor(final FSkinColor c0) { this.bldTextColor = c0; return this; }
|
||||||
public Builder pressedColor(final FSkinColor c0) { this.bldPressedColor = c0; return this; }
|
public Builder pressedColor(final FSkinColor c0) { this.bldPressedColor = c0; return this; }
|
||||||
|
public Builder parseSymbols() { parseSymbols(true); return this; }
|
||||||
|
public Builder parseSymbols(final boolean b0) { this.bldParseSymbols = b0; return this; }
|
||||||
}
|
}
|
||||||
|
|
||||||
// sets better defaults for button labels
|
// sets better defaults for button labels
|
||||||
@@ -105,6 +109,7 @@ public class FLabel extends FDisplayObject implements IButton {
|
|||||||
private FImage icon;
|
private FImage icon;
|
||||||
private FSkinColor textColor, pressedColor;
|
private FSkinColor textColor, pressedColor;
|
||||||
private FEventHandler command;
|
private FEventHandler command;
|
||||||
|
private TextRenderer textRenderer;
|
||||||
|
|
||||||
// Call this using FLabel.Builder()...
|
// Call this using FLabel.Builder()...
|
||||||
protected FLabel(final Builder b0) {
|
protected FLabel(final Builder b0) {
|
||||||
@@ -123,6 +128,9 @@ public class FLabel extends FDisplayObject implements IButton {
|
|||||||
textColor = b0.bldTextColor;
|
textColor = b0.bldTextColor;
|
||||||
pressedColor = b0.bldPressedColor;
|
pressedColor = b0.bldPressedColor;
|
||||||
command = b0.bldCommand;
|
command = b0.bldCommand;
|
||||||
|
if (b0.bldParseSymbols) {
|
||||||
|
textRenderer = new TextRenderer();
|
||||||
|
}
|
||||||
setEnabled(b0.bldEnabled);
|
setEnabled(b0.bldEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,7 +336,7 @@ public class FLabel extends FDisplayObject implements IButton {
|
|||||||
if (alignment == HAlignment.CENTER) {
|
if (alignment == HAlignment.CENTER) {
|
||||||
float dx;
|
float dx;
|
||||||
while (true) {
|
while (true) {
|
||||||
dx = (w - iconOffset - font.getMultiLineBounds(text).width) / 2;
|
dx = (w - iconOffset - getTextWidth()) / 2;
|
||||||
if (dx > 0) {
|
if (dx > 0) {
|
||||||
x += dx;
|
x += dx;
|
||||||
break;
|
break;
|
||||||
@@ -342,7 +350,7 @@ public class FLabel extends FDisplayObject implements IButton {
|
|||||||
else if (alignment == HAlignment.RIGHT) {
|
else if (alignment == HAlignment.RIGHT) {
|
||||||
float dx;
|
float dx;
|
||||||
while (true) {
|
while (true) {
|
||||||
dx = (w - iconWidth - font.getMultiLineBounds(text).width - insets.x);
|
dx = (w - iconWidth - getTextWidth() - insets.x);
|
||||||
if (dx > 0) {
|
if (dx > 0) {
|
||||||
x += dx;
|
x += dx;
|
||||||
break;
|
break;
|
||||||
@@ -365,18 +373,33 @@ public class FLabel extends FDisplayObject implements IButton {
|
|||||||
}
|
}
|
||||||
x += iconOffset;
|
x += iconOffset;
|
||||||
w -= iconOffset;
|
w -= iconOffset;
|
||||||
g.startClip(x, y, w, h);
|
|
||||||
g.drawText(text, font, textColor, x, y, w, h, false, HAlignment.LEFT, true);
|
drawText(g, x, y, w, h, HAlignment.LEFT);
|
||||||
g.endClip();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!text.isEmpty()) {
|
else if (!text.isEmpty()) {
|
||||||
g.startClip(x, y, w, h);
|
drawText(g, x, y, w, h, alignment);
|
||||||
g.drawText(text, font, textColor, x, y, w, h, false, alignment, true);
|
|
||||||
g.endClip();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void drawText(Graphics g, float x, float y, float w, float h, HAlignment align) {
|
||||||
|
g.startClip(x, y, w, h);
|
||||||
|
if (textRenderer == null) {
|
||||||
|
g.drawText(text, font, textColor, x, y, w, h, false, align, true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
textRenderer.drawText(g, text, font, textColor, x, y, w, h, y, h, false, align, true);
|
||||||
|
}
|
||||||
|
g.endClip();
|
||||||
|
}
|
||||||
|
|
||||||
|
private float getTextWidth() {
|
||||||
|
if (textRenderer == null) {
|
||||||
|
return font.getMultiLineBounds(text).width;
|
||||||
|
}
|
||||||
|
return textRenderer.getBounds(text, font).width;
|
||||||
|
}
|
||||||
|
|
||||||
//use FEventHandler one except when references as IButton
|
//use FEventHandler one except when references as IButton
|
||||||
@Override
|
@Override
|
||||||
public void setCommand(final UiCommand command0) {
|
public void setCommand(final UiCommand command0) {
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public class AdvancedSearch {
|
|||||||
return FModel.getFormats().getAllFormatsOfCard(input);
|
return FModel.getFormats().getAllFormatsOfCard(input);
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
CARD_COLOR("Color", PaperCard.class, FilterOperator.MULTI_LIST_OPS, new CustomListEvaluator<PaperCard, MagicColor.Color>(Arrays.asList(MagicColor.Color.values())) {
|
CARD_COLOR("Color", PaperCard.class, FilterOperator.MULTI_LIST_OPS, new CustomListEvaluator<PaperCard, MagicColor.Color>(Arrays.asList(MagicColor.Color.values()), MagicColor.FN_GET_SYMBOL) {
|
||||||
@Override
|
@Override
|
||||||
protected MagicColor.Color getItemValue(PaperCard input) {
|
protected MagicColor.Color getItemValue(PaperCard input) {
|
||||||
throw new RuntimeException("getItemValues should be called instead");
|
throw new RuntimeException("getItemValues should be called instead");
|
||||||
@@ -65,7 +65,7 @@ public class AdvancedSearch {
|
|||||||
return input.getRules().getColor().toEnumSet();
|
return input.getRules().getColor().toEnumSet();
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
CARD_COLOR_IDENTITY("Color Identity", PaperCard.class, FilterOperator.MULTI_LIST_OPS, new CustomListEvaluator<PaperCard, MagicColor.Color>(Arrays.asList(MagicColor.Color.values())) {
|
CARD_COLOR_IDENTITY("Color Identity", PaperCard.class, FilterOperator.MULTI_LIST_OPS, new CustomListEvaluator<PaperCard, MagicColor.Color>(Arrays.asList(MagicColor.Color.values()), MagicColor.FN_GET_SYMBOL) {
|
||||||
@Override
|
@Override
|
||||||
protected MagicColor.Color getItemValue(PaperCard input) {
|
protected MagicColor.Color getItemValue(PaperCard input) {
|
||||||
throw new RuntimeException("getItemValues should be called instead");
|
throw new RuntimeException("getItemValues should be called instead");
|
||||||
|
|||||||
Reference in New Issue
Block a user