From ffa9b01ebe45cfdcef15675ca30fae32f8673093 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Wed, 27 Jan 2021 23:55:14 +0800 Subject: New search syntax highlighting, small changes to dark theme, bump to 5.9.0 Signed-off-by: shedaniel --- .../java/me/shedaniel/rei/api/ConfigObject.java | 3 ++ .../rei/gui/config/SyntaxHighlightingMode.java | 43 ++++++++++++++++++++++ .../shedaniel/rei/gui/widget/TextFieldWidget.java | 24 +++++++----- 3 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/gui/config/SyntaxHighlightingMode.java (limited to 'RoughlyEnoughItems-api/src/main/java') diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ConfigObject.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ConfigObject.java index 59e3afe24..69b8852d3 100644 --- a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ConfigObject.java +++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ConfigObject.java @@ -186,4 +186,7 @@ public interface ConfigObject { @ApiStatus.Experimental double getVerticalEntriesBoundaries(); + + @ApiStatus.Experimental + SyntaxHighlightingMode getSyntaxHighlightingMode(); } diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/gui/config/SyntaxHighlightingMode.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/gui/config/SyntaxHighlightingMode.java new file mode 100644 index 000000000..23aac1f44 --- /dev/null +++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/gui/config/SyntaxHighlightingMode.java @@ -0,0 +1,43 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.gui.config; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.resources.language.I18n; + +import java.util.Locale; + +@Environment(EnvType.CLIENT) +public enum SyntaxHighlightingMode { + PLAIN, + PLAIN_UNDERSCORED, + COLORFUL, + COLORFUL_UNDERSCORED; + + @Override + public String toString() { + return I18n.get("config.roughlyenoughitems.syntaxHighlightingMode." + name().toLowerCase(Locale.ROOT)); + } +} diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/gui/widget/TextFieldWidget.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/gui/widget/TextFieldWidget.java index 5c73ed820..9b0486f7b 100644 --- a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/gui/widget/TextFieldWidget.java +++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/gui/widget/TextFieldWidget.java @@ -35,6 +35,8 @@ import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.util.SharedConstants; import net.minecraft.util.Util; +import net.minecraft.network.chat.Style; +import net.minecraft.util.FormattedCharSequence; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.vector.Matrix4f; import org.jetbrains.annotations.ApiStatus; @@ -42,7 +44,6 @@ import org.jetbrains.annotations.NotNull; import java.util.Collections; import java.util.List; -import java.util.function.BiFunction; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Predicate; @@ -61,7 +62,7 @@ public class TextFieldWidget extends WidgetWithBounds implements IScreen { protected int selectionEnd; protected int editableColor; protected int notEditableColor; - protected BiFunction renderTextProvider; + protected TextFormatter formatter; private Rectangle bounds; private String text; private int maxLength; @@ -84,9 +85,7 @@ public class TextFieldWidget extends WidgetWithBounds implements IScreen { this.notEditableColor = 7368816; this.visible = true; this.textPredicate = s -> true; - this.renderTextProvider = (string_1, integer_1) -> { - return string_1; - }; + this.formatter = TextFormatter.DEFAULT; this.bounds = rectangle; this.stripInvalid = SharedConstants::filterText; } @@ -113,8 +112,8 @@ public class TextFieldWidget extends WidgetWithBounds implements IScreen { this.changedListener = biConsumer_1; } - public void setRenderTextProvider(BiFunction biFunction_1) { - this.renderTextProvider = biFunction_1; + public void setFormatter(TextFormatter formatter) { + this.formatter = formatter; } @Override @@ -444,7 +443,7 @@ public class TextFieldWidget extends WidgetWithBounds implements IScreen { if (!string_1.isEmpty()) { String string_2 = boolean_1 ? string_1.substring(0, int_4) : string_1; - int_8 = this.font.drawShadow(matrices, this.renderTextProvider.apply(string_2, this.firstCharacterIndex), (float) x, (float) y, color); + int_8 = this.font.drawShadow(matrices, this.formatter.format(this, string_2, this.firstCharacterIndex), (float) x, (float) y, color); } boolean isCursorInsideText = this.selectionStart < this.text.length() || this.text.length() >= this.getMaxLength(); @@ -457,7 +456,7 @@ public class TextFieldWidget extends WidgetWithBounds implements IScreen { int_9--; if (!string_1.isEmpty() && boolean_1 && int_4 < string_1.length()) { - this.font.drawShadow(matrices, this.renderTextProvider.apply(string_1.substring(int_4), this.selectionStart), (float) int_8, (float) y, color); + this.font.drawShadow(matrices, this.formatter.format(this, string_1.substring(int_4), this.selectionStart), (float) int_8, (float) y, color); } if (!isCursorInsideText && text.isEmpty() && this.suggestion != null) { @@ -631,4 +630,11 @@ public class TextFieldWidget extends WidgetWithBounds implements IScreen { return index > this.text.length() ? this.bounds.x : this.bounds.x + this.font.width(this.text.substring(0, index)); } + public interface TextFormatter { + TextFormatter DEFAULT = (widget, text, index) -> { + return FormattedCharSequence.forward(text, Style.EMPTY); + }; + + FormattedCharSequence format(TextFieldWidget widget, String text, int index); + } } -- cgit