Improve display of advanced color filters

This commit is contained in:
drdev
2015-09-06 03:47:20 +00:00
parent e7bda18d52
commit 23f65a2b9e
4 changed files with 57 additions and 22 deletions

View File

@@ -1,5 +1,6 @@
package forge.card;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@@ -153,19 +154,20 @@ public final class MagicColor {
}
public enum Color {
WHITE(Constant.WHITE, MagicColor.WHITE),
BLUE(Constant.BLUE, MagicColor.BLUE),
BLACK(Constant.BLACK, MagicColor.BLACK),
RED(Constant.RED, MagicColor.RED),
GREEN(Constant.GREEN, MagicColor.GREEN),
COLORLESS(Constant.COLORLESS, MagicColor.COLORLESS);
WHITE(Constant.WHITE, MagicColor.WHITE, "{W}"),
BLUE(Constant.BLUE, MagicColor.BLUE, "{U}"),
BLACK(Constant.BLACK, MagicColor.BLACK, "{B}"),
RED(Constant.RED, MagicColor.RED, "{R}"),
GREEN(Constant.GREEN, MagicColor.GREEN, "{G}"),
COLORLESS(Constant.COLORLESS, MagicColor.COLORLESS, "{X}");
private final String name;
private final String name, symbol;
private final byte colormask;
private Color(String name0, byte colormask0) {
private Color(String name0, byte colormask0, String symbol0) {
name = name0;
colormask = colormask0;
symbol = symbol0;
}
public String getName() {
@@ -174,9 +176,19 @@ public final class MagicColor {
public byte getColormask() {
return colormask;
}
public String getSymbol() {
return symbol;
}
@Override
public String toString() {
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;
}
};
}

View File

@@ -120,7 +120,7 @@ public class AdvancedSearchFilter<T extends InventoryItem> extends ItemFilter<T>
private void updateLabel() {
StringBuilder builder = new StringBuilder();
builder.append("Filters: ");
builder.append("Filter: ");
if (expression.isEmpty()) {
builder.append("(none)");
}
@@ -136,7 +136,7 @@ public class AdvancedSearchFilter<T extends InventoryItem> extends ItemFilter<T>
if (expression.isEmpty()) { return ""; }
StringBuilder builder = new StringBuilder();
builder.append("Filters:\n");
builder.append("Filter:\n");
String indent = "";
@@ -181,7 +181,7 @@ public class AdvancedSearchFilter<T extends InventoryItem> extends ItemFilter<T>
private class FiltersLabel extends FLabel {
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
@@ -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());
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
public void handleEvent(FEvent e) {
FThreads.invokeInBackgroundThread(new Runnable() {

View File

@@ -9,6 +9,7 @@ import forge.UiCommand;
import forge.assets.FImage;
import forge.assets.FSkinColor;
import forge.assets.FSkinProp;
import forge.assets.TextRenderer;
import forge.assets.FSkinColor.Colors;
import forge.assets.FSkinFont;
import forge.interfaces.IButton;
@@ -33,6 +34,7 @@ public class FLabel extends FDisplayObject implements IButton {
private boolean bldIconInBackground = false;
private boolean bldIconScaleAuto = true;
private boolean bldEnabled = true;
private boolean bldParseSymbols = true;
private String bldText;
private FImage bldIcon;
@@ -63,6 +65,8 @@ public class FLabel extends FDisplayObject implements IButton {
public Builder iconInBackground() { iconInBackground(true); 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 parseSymbols() { parseSymbols(true); return this; }
public Builder parseSymbols(final boolean b0) { this.bldParseSymbols = b0; return this; }
}
// sets better defaults for button labels
@@ -105,6 +109,7 @@ public class FLabel extends FDisplayObject implements IButton {
private FImage icon;
private FSkinColor textColor, pressedColor;
private FEventHandler command;
private TextRenderer textRenderer;
// Call this using FLabel.Builder()...
protected FLabel(final Builder b0) {
@@ -123,6 +128,9 @@ public class FLabel extends FDisplayObject implements IButton {
textColor = b0.bldTextColor;
pressedColor = b0.bldPressedColor;
command = b0.bldCommand;
if (b0.bldParseSymbols) {
textRenderer = new TextRenderer();
}
setEnabled(b0.bldEnabled);
}
@@ -328,7 +336,7 @@ public class FLabel extends FDisplayObject implements IButton {
if (alignment == HAlignment.CENTER) {
float dx;
while (true) {
dx = (w - iconOffset - font.getMultiLineBounds(text).width) / 2;
dx = (w - iconOffset - getTextWidth()) / 2;
if (dx > 0) {
x += dx;
break;
@@ -342,7 +350,7 @@ public class FLabel extends FDisplayObject implements IButton {
else if (alignment == HAlignment.RIGHT) {
float dx;
while (true) {
dx = (w - iconWidth - font.getMultiLineBounds(text).width - insets.x);
dx = (w - iconWidth - getTextWidth() - insets.x);
if (dx > 0) {
x += dx;
break;
@@ -365,18 +373,33 @@ public class FLabel extends FDisplayObject implements IButton {
}
x += iconOffset;
w -= iconOffset;
g.startClip(x, y, w, h);
g.drawText(text, font, textColor, x, y, w, h, false, HAlignment.LEFT, true);
g.endClip();
drawText(g, x, y, w, h, HAlignment.LEFT);
}
}
else if (!text.isEmpty()) {
g.startClip(x, y, w, h);
g.drawText(text, font, textColor, x, y, w, h, false, alignment, true);
g.endClip();
drawText(g, x, y, w, h, alignment);
}
}
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
@Override
public void setCommand(final UiCommand command0) {

View File

@@ -55,7 +55,7 @@ public class AdvancedSearch {
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
protected MagicColor.Color getItemValue(PaperCard input) {
throw new RuntimeException("getItemValues should be called instead");
@@ -65,7 +65,7 @@ public class AdvancedSearch {
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
protected MagicColor.Color getItemValue(PaperCard input) {
throw new RuntimeException("getItemValues should be called instead");