aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2023-10-26 15:49:00 +0800
committershedaniel <daniel@shedaniel.me>2024-04-16 00:38:18 +0900
commit598dfc5c1f5e532a34f09c7d8d398ec727a33ab3 (patch)
tree2f41015d23de0e2a18fce460619a9aeb40aceb36
parent881f8d146f15c2dfbe1292747f933d3c19cb429a (diff)
downloadRoughlyEnoughItems-598dfc5c1f5e532a34f09c7d8d398ec727a33ab3.tar.gz
RoughlyEnoughItems-598dfc5c1f5e532a34f09c7d8d398ec727a33ab3.tar.bz2
RoughlyEnoughItems-598dfc5c1f5e532a34f09c7d8d398ec727a33ab3.zip
Localise more values and add a basic theme previewer
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/gui/config/AppearanceTheme.java6
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/gui/config/CheatingMode.java6
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/gui/config/ConfigButtonPosition.java9
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/gui/config/DisplayPanelLocation.java7
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/gui/config/DisplayScreenType.java2
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/gui/config/EntryPanelOrderingConfig.java4
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/gui/config/ItemCheatingMode.java8
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/gui/config/ItemCheatingStyle.java7
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/gui/config/RecipeBorderType.java2
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/gui/config/SearchFieldLocation.java12
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/gui/config/SearchMode.java7
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/gui/config/SyntaxHighlightingMode.java2
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigEntriesListWidget.java1
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigGroupWidget.java57
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigOptionValueWidget.java6
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigOptionWidget.java58
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigGroups.java3
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigOptions.java24
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/CompositeOption.java18
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/OptionValueEntry.java38
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/preview/ThemePreviewer.java17
-rwxr-xr-xruntime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json39
22 files changed, 262 insertions, 71 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/config/AppearanceTheme.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/config/AppearanceTheme.java
index fc653861b..d5397ceb0 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/gui/config/AppearanceTheme.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/config/AppearanceTheme.java
@@ -31,12 +31,12 @@ import net.minecraft.client.resources.language.I18n;
import java.util.Locale;
@Environment(EnvType.CLIENT)
-public enum AppearanceTheme implements SelectionListEntry.Translatable {
+public enum AppearanceTheme {
LIGHT,
DARK;
@Override
- public String getKey() {
- return I18n.get("config.roughlyenoughitems.theme." + name().toLowerCase(Locale.ROOT));
+ public String toString() {
+ return I18n.get("config.rei.value.appearance.theme." + name().toLowerCase(Locale.ROOT));
}
}
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/config/CheatingMode.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/config/CheatingMode.java
index 5e9a98261..e8a456a0c 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/gui/config/CheatingMode.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/config/CheatingMode.java
@@ -35,11 +35,11 @@ public enum CheatingMode {
public String toString() {
switch (this) {
case ON:
- return I18n.get("config.rei.value.enabledDisabled.true");
+ return I18n.get("config.rei.value.trueFalse.true");
case OFF:
- return I18n.get("config.rei.value.enabledDisabled.false");
+ return I18n.get("config.rei.value.trueFalse.false");
case WHEN_CREATIVE:
- return I18n.get("config.roughlyenoughitems.cheating.when_creative");
+ return I18n.get("config.rei.value.cheats.mode.when_creative");
default:
throw new IllegalStateException("Unknown CheatingMode: " + this);
}
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/config/ConfigButtonPosition.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/config/ConfigButtonPosition.java
index fd9a7d9a0..b816899ab 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/gui/config/ConfigButtonPosition.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/config/ConfigButtonPosition.java
@@ -31,12 +31,13 @@ import net.minecraft.client.resources.language.I18n;
import java.util.Locale;
@Environment(EnvType.CLIENT)
-public enum ConfigButtonPosition implements SelectionListEntry.Translatable {
+public enum ConfigButtonPosition {
UPPER,
LOWER;
- @Override
- public String getKey() {
- return I18n.get("config.roughlyenoughitems.layout.configButtonLocation." + name().toLowerCase(Locale.ROOT));
+ public String toString(boolean right) {
+ if (this == UPPER && right) return I18n.get("config.rei.value.layout.config_button_location.top_right");
+ if (this == UPPER) return I18n.get("config.rei.value.layout.config_button_location.top_left");
+ return I18n.get("config.rei.value.layout.config_button_location.next_to_search");
}
}
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/config/DisplayPanelLocation.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/config/DisplayPanelLocation.java
index d91569291..6278c0d01 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/gui/config/DisplayPanelLocation.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/config/DisplayPanelLocation.java
@@ -23,7 +23,6 @@
package me.shedaniel.rei.api.client.gui.config;
-import me.shedaniel.clothconfig2.gui.entries.SelectionListEntry;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.resources.language.I18n;
@@ -31,7 +30,7 @@ import net.minecraft.client.resources.language.I18n;
import java.util.Locale;
@Environment(EnvType.CLIENT)
-public enum DisplayPanelLocation implements SelectionListEntry.Translatable {
+public enum DisplayPanelLocation {
LEFT,
RIGHT;
@@ -41,7 +40,7 @@ public enum DisplayPanelLocation implements SelectionListEntry.Translatable {
}
@Override
- public String getKey() {
- return I18n.get("config.roughlyenoughitems.accessibility.displayPanelLocation." + name().toLowerCase(Locale.ROOT));
+ public String toString() {
+ return I18n.get("config.rei.value.layout.location." + name().toLowerCase(Locale.ROOT));
}
}
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/config/DisplayScreenType.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/config/DisplayScreenType.java
index f647db2f4..90b4fb8bf 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/gui/config/DisplayScreenType.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/config/DisplayScreenType.java
@@ -37,6 +37,6 @@ public enum DisplayScreenType {
@Override
public String toString() {
- return I18n.get("config.roughlyenoughitems.recipeScreenType." + name().toLowerCase(Locale.ROOT));
+ return I18n.get("config.rei.value.appearance.recipe_lookup_style." + name().toLowerCase(Locale.ROOT));
}
}
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/config/EntryPanelOrderingConfig.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/config/EntryPanelOrderingConfig.java
index 407d9cb3c..9b706c889 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/gui/config/EntryPanelOrderingConfig.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/config/EntryPanelOrderingConfig.java
@@ -27,6 +27,8 @@ 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 EntryPanelOrderingConfig {
REGISTRY_ASCENDING(EntryPanelOrdering.REGISTRY, true),
@@ -59,6 +61,6 @@ public enum EntryPanelOrderingConfig {
@Override
public String toString() {
- return I18n.get("config.roughlyenoughitems.list_ordering_button", I18n.get(getOrdering().getNameTranslationKey()), I18n.get(isAscending ? "ordering.rei.ascending" : "ordering.rei.descending"));
+ return I18n.get("config.rei.value.list.ordering." + name().toLowerCase(Locale.ROOT));
}
}
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/config/ItemCheatingMode.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/config/ItemCheatingMode.java
index 910669225..fb4e228fc 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/gui/config/ItemCheatingMode.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/config/ItemCheatingMode.java
@@ -27,8 +27,6 @@ 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 ItemCheatingMode {
REI_LIKE,
@@ -36,6 +34,10 @@ public enum ItemCheatingMode {
@Override
public String toString() {
- return I18n.get("config.roughlyenoughitems.itemCheatingMode." + name().toLowerCase(Locale.ROOT));
+ if (this == REI_LIKE) {
+ return I18n.get("config.rei.value.cheats.amount.default");
+ } else {
+ return I18n.get("config.rei.value.cheats.amount.reversed");
+ }
}
}
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/config/ItemCheatingStyle.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/config/ItemCheatingStyle.java
index 59174011c..8c49960f7 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/gui/config/ItemCheatingStyle.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/config/ItemCheatingStyle.java
@@ -23,7 +23,6 @@
package me.shedaniel.rei.api.client.gui.config;
-import me.shedaniel.clothconfig2.gui.entries.SelectionListEntry;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.resources.language.I18n;
@@ -31,12 +30,12 @@ import net.minecraft.client.resources.language.I18n;
import java.util.Locale;
@Environment(EnvType.CLIENT)
-public enum ItemCheatingStyle implements SelectionListEntry.Translatable {
+public enum ItemCheatingStyle {
GRAB,
GIVE;
@Override
- public String getKey() {
- return I18n.get("config.roughlyenoughitems.cheatingStyle." + name().toLowerCase(Locale.ROOT));
+ public String toString() {
+ return I18n.get("config.rei.value.cheats.method." + name().toLowerCase(Locale.ROOT));
}
}
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/config/RecipeBorderType.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/config/RecipeBorderType.java
index 1bde0b058..86db371be 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/gui/config/RecipeBorderType.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/config/RecipeBorderType.java
@@ -57,6 +57,6 @@ public enum RecipeBorderType {
@Override
public String toString() {
- return I18n.get("config.roughlyenoughitems.recipeBorder." + name().toLowerCase(Locale.ROOT));
+ return I18n.get("config.rei.value.appearance.recipe_border." + name().toLowerCase(Locale.ROOT));
}
}
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/config/SearchFieldLocation.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/config/SearchFieldLocation.java
index f80cb4f1b..2653bbced 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/gui/config/SearchFieldLocation.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/config/SearchFieldLocation.java
@@ -25,6 +25,8 @@ package me.shedaniel.rei.api.client.gui.config;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.resources.language.I18n;
import java.util.Locale;
@@ -35,8 +37,12 @@ public enum SearchFieldLocation {
BOTTOM_SIDE,
TOP_SIDE;
- @Override
- public String toString() {
- return I18n.get("config.roughlyenoughitems.layout.searchFieldLocation.%s".formatted(name().toLowerCase(Locale.ROOT)));
+ public String toString(boolean right) {
+ if (this == CENTER) return I18n.get("config.rei.value.layout.search_field_location.center");
+ if (this == BOTTOM_SIDE && right) return I18n.get("config.rei.value.layout.search_field_location.bottom_right");
+ if (this == BOTTOM_SIDE) return I18n.get("config.rei.value.layout.search_field_location.bottom_left");
+ if (this == TOP_SIDE && right) return I18n.get("config.rei.value.layout.search_field_location.top_right");
+ if (this == TOP_SIDE) return I18n.get("config.rei.value.layout.search_field_location.top_left");
+ return "";
}
}
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/config/SearchMode.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/config/SearchMode.java
index ca634bc0b..77a9a2f88 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/gui/config/SearchMode.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/config/SearchMode.java
@@ -23,7 +23,6 @@
package me.shedaniel.rei.api.client.gui.config;
-import me.shedaniel.clothconfig2.gui.entries.SelectionListEntry;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.resources.language.I18n;
@@ -31,13 +30,13 @@ import net.minecraft.client.resources.language.I18n;
import java.util.Locale;
@Environment(EnvType.CLIENT)
-public enum SearchMode implements SelectionListEntry.Translatable {
+public enum SearchMode {
ALWAYS,
PREFIX,
NEVER;
@Override
- public String getKey() {
- return I18n.get("config.roughlyenoughitems.search_mode." + name().toLowerCase(Locale.ROOT));
+ public String toString() {
+ return I18n.get("config.rei.value.search.filters." + name().toLowerCase(Locale.ROOT));
}
}
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/config/SyntaxHighlightingMode.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/config/SyntaxHighlightingMode.java
index d8388687f..e034a5b14 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/gui/config/SyntaxHighlightingMode.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/config/SyntaxHighlightingMode.java
@@ -38,6 +38,6 @@ public enum SyntaxHighlightingMode {
@Override
public String toString() {
- return I18n.get("config.roughlyenoughitems.syntaxHighlightingMode." + name().toLowerCase(Locale.ROOT));
+ return I18n.get("config.rei.value.search.syntax_highlighting." + name().toLowerCase(Locale.ROOT));
}
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigEntriesListWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigEntriesListWidget.java
index 6f580d3a3..de05300eb 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigEntriesListWidget.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigEntriesListWidget.java
@@ -38,6 +38,7 @@ public class ConfigEntriesListWidget {
WidgetWithBounds list = ListWidget.builderOf(RectangleUtils.inset(bounds, 6, 6), groups,
(index, entry) -> ConfigGroupWidget.create(entry, bounds.width - 12 - 6))
.gap(7)
+ .calculateTotalHeightDynamically(true)
.build();
return ScrollableViewWidget.create(bounds, list.withPadding(0, 5), true);
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigGroupWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigGroupWidget.java
index 76d41e4f1..fdad7818d 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigGroupWidget.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigGroupWidget.java
@@ -23,45 +23,70 @@
package me.shedaniel.rei.impl.client.gui.config.components;
+import com.mojang.math.Matrix4f;
import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.client.gui.widgets.Widget;
import me.shedaniel.rei.api.client.gui.widgets.WidgetWithBounds;
import me.shedaniel.rei.api.client.gui.widgets.Widgets;
+import me.shedaniel.rei.api.client.util.MatrixUtils;
import me.shedaniel.rei.impl.client.gui.config.options.CompositeOption;
import me.shedaniel.rei.impl.client.gui.config.options.OptionGroup;
import net.minecraft.client.gui.GuiComponent;
+import org.apache.commons.lang3.tuple.Triple;
+import java.util.AbstractList;
import java.util.ArrayList;
import java.util.List;
+import java.util.function.Supplier;
public class ConfigGroupWidget {
public static WidgetWithBounds create(OptionGroup entry, int width) {
- List<Widget> widgets = new ArrayList<>();
- int height = 0;
+ List<Triple<Widget, Supplier<Rectangle>, Matrix4f[]>> widgets = new ArrayList<>();
+ int[] height = {0};
WidgetWithBounds groupTitle = Widgets.createLabel(new Point(0, 3), entry.getGroupName().copy().withStyle(style -> style.withColor(0xFFC0C0C0).withUnderlined(true)))
- .leftAligned();
- groupTitle = groupTitle.withPadding(0, 0, 0, 6);
- widgets.add(groupTitle);
- height = Math.max(height, groupTitle.getBounds().getMaxY());
+ .leftAligned()
+ .withPadding(0, 0, 0, 6);
+ widgets.add(Triple.of(groupTitle, groupTitle::getBounds, new Matrix4f[]{new Matrix4f()}));
+ height[0] = Math.max(height[0], groupTitle.getBounds().getMaxY());
for (CompositeOption<?> option : entry.getOptions()) {
- WidgetWithBounds widget = ConfigOptionWidget.create(option, width);
- widgets.add(Widgets.withTranslate(widget, 0, height, 0));
- height = Math.max(height, height + widget.getBounds().getMaxY());
+ Matrix4f[] translation = new Matrix4f[]{Matrix4f.createTranslateMatrix(0, height[0], 0)};
+ WidgetWithBounds widget = Widgets.withTranslate(ConfigOptionWidget.create(option, width), () -> translation[0]);
+ widgets.add(Triple.of(widget, () -> MatrixUtils.transform(translation[0], widget.getBounds()), translation));
+ height[0] = Math.max(height[0], widget.getBounds().getMaxY());
if (entry.getOptions().get(entry.getOptions().size() - 1) != option) {
- int y = height;
- widgets.add(Widgets.createDrawableWidget((helper, matrices, mouseX, mouseY, delta) -> {
+ Matrix4f[] translationDrawable = new Matrix4f[]{Matrix4f.createTranslateMatrix(0, height[0], 0)};
+ widgets.add(Triple.of(Widgets.withTranslate(Widgets.createDrawableWidget((helper, matrices, mouseX, mouseY, delta) -> {
for (int x = 0; x <= width; x += 4) {
- GuiComponent.fill(matrices, x, y + 1, x + 2, y + 2, 0xFF757575);
+ GuiComponent.fill(matrices, x, 1, x + 2, 2, 0xFF757575);
}
- }));
- height += 7;
+ }), () -> translationDrawable[0]), () ->
+ MatrixUtils.transform(translationDrawable[0], new Rectangle(0, 0, 1, 7)), translationDrawable));
+ height[0] += 7;
}
}
- Rectangle bounds = new Rectangle(0, 0, width, height);
- return Widgets.concatWithBounds(bounds, widgets);
+ widgets.add(Triple.of(Widgets.createDrawableWidget((helper, matrices, mouseX, mouseY, delta) -> {
+ int h = 0;
+ for (Triple<Widget, Supplier<Rectangle>, Matrix4f[]> widget : widgets) {
+ widget.getRight()[0] = Matrix4f.createTranslateMatrix(0, h, 0);
+ h = Math.max(h, widget.getMiddle().get().getMaxY());
+ }
+ height[0] = h;
+ }), Rectangle::new, new Matrix4f[]{new Matrix4f()}));
+
+ return Widgets.concatWithBounds(() -> new Rectangle(0, 0, width, height[0]), new AbstractList<>() {
+ @Override
+ public Widget get(int index) {
+ return widgets.get(index).getLeft();
+ }
+
+ @Override
+ public int size() {
+ return widgets.size();
+ }
+ });
}
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigOptionValueWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigOptionValueWidget.java
index f2764dd2d..e2d62eed3 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigOptionValueWidget.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigOptionValueWidget.java
@@ -23,6 +23,7 @@
package me.shedaniel.rei.impl.client.gui.config.components;
+import com.google.common.base.MoreObjects;
import com.mojang.math.Matrix4f;
import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
@@ -43,6 +44,7 @@ import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import java.util.Map;
+import java.util.Objects;
import static me.shedaniel.rei.impl.client.gui.config.options.ConfigUtils.literal;
import static me.shedaniel.rei.impl.client.gui.config.options.ConfigUtils.translatable;
@@ -61,7 +63,7 @@ public class ConfigOptionValueWidget {
text[0] = literal(value.toString());
}
- if (value.equals(defaultOptions.get(option))) {
+ if (value.equals(Objects.requireNonNullElseGet(option.getDefaultValue(), () -> (T) defaultOptions.get(option)))) {
text[0] = translatable("config.rei.value.default", text[0]);
}
@@ -84,7 +86,7 @@ public class ConfigOptionValueWidget {
((Map<CompositeOption<?>, Object>) options).put(option, selection.getOptions().get((selection.getOptions().indexOf((T) options.get(option)) + 1) % 2));
text[0] = selection.getOption((T) options.get(option));
- if (options.get(option).equals(defaultOptions.get(option))) {
+ if (options.get(option).equals(Objects.requireNonNullElseGet(option.getDefaultValue(), () -> (T) defaultOptions.get(option)))) {
text[0] = translatable("config.rei.value.default", text[0]);
}
});
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigOptionWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigOptionWidget.java
index 9707b3ab7..2c157767e 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigOptionWidget.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigOptionWidget.java
@@ -25,17 +25,25 @@ package me.shedaniel.rei.impl.client.gui.config.components;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Matrix4f;
+import me.shedaniel.clothconfig2.api.ScissorsHandler;
+import me.shedaniel.clothconfig2.api.animator.NumberAnimator;
+import me.shedaniel.clothconfig2.api.animator.ValueAnimator;
import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.client.gui.widgets.Label;
import me.shedaniel.rei.api.client.gui.widgets.Widget;
import me.shedaniel.rei.api.client.gui.widgets.WidgetWithBounds;
import me.shedaniel.rei.api.client.gui.widgets.Widgets;
+import me.shedaniel.rei.api.client.util.MatrixUtils;
+import me.shedaniel.rei.impl.client.gui.config.REIConfigScreen;
import me.shedaniel.rei.impl.client.gui.config.options.CompositeOption;
+import me.shedaniel.rei.impl.common.util.RectangleUtils;
import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.util.FormattedCharSequence;
+import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
@@ -43,8 +51,9 @@ import java.util.List;
import static me.shedaniel.rei.impl.client.gui.config.options.ConfigUtils.translatable;
public class ConfigOptionWidget {
- public static WidgetWithBounds create(CompositeOption<?> option, int width) {
+ public static <T> WidgetWithBounds create(CompositeOption<T> option, int width) {
List<Widget> widgets = new ArrayList<>();
+ int[] stableHeight = {12};
int[] height = {12};
widgets.add(Widgets.createLabel(new Point(0, 0), option.getName().copy().withStyle(style -> style.withColor(0xFFC0C0C0)))
.leftAligned());
@@ -54,21 +63,28 @@ public class ConfigOptionWidget {
final MutableComponent description = option.getDescription().copy().withStyle(style -> style.withColor(0xFF757575));
final List<FormattedCharSequence> split = Minecraft.getInstance().font.split(description, width);
final boolean hasPreview = option.hasPreview();
- final Label preview = Widgets.createLabel(new Point(), translatable("config.rei.texts.preview"))
+ final Label previewLabel = Widgets.createLabel(new Point(), translatable("config.rei.texts.preview"))
.color(0xFFA5F4FF)
.hoveredColor(0xFFD1FAFF)
.noShadow()
.clickable()
+ .onClick($ -> clickPreview())
.rightAligned();
+ @Nullable
+ WidgetWithBounds preview = null;
+ boolean previewVisible = false;
+ Matrix4f previewTranslation = new Matrix4f();
+ final NumberAnimator<Float> previewHeight = ValueAnimator.ofFloat()
+ .withConvention(() -> previewVisible ? preview.getBounds().getHeight() : 0f, ValueAnimator.typicalTransitionTime());
boolean nextLinePreview = false;
{
- height[0] += 12 * split.size();
+ stableHeight[0] += 12 * split.size();
if (hasPreview) {
int lastWidth = Minecraft.getInstance().font.width(split.get(split.size() - 1));
- if (lastWidth + preview.getBounds().width + 10 > width) {
+ if (lastWidth + this.previewLabel.getBounds().width + 10 > width) {
nextLinePreview = true;
- height[0] += 12;
+ stableHeight[0] += 12;
}
}
}
@@ -80,26 +96,48 @@ public class ConfigOptionWidget {
@Override
public void render(PoseStack poses, int mouseX, int mouseY, float delta) {
+ this.previewHeight.update(delta);
+ height[0] = stableHeight[0] + Math.round(this.previewHeight.value());
+
for (int i = 0; i < split.size(); i++) {
Minecraft.getInstance().font.draw(poses, split.get(i), 0, 12 + 12 * i, -1);
}
if (hasPreview) {
if (nextLinePreview) {
- this.preview.setPoint(new Point(width, 12 + 12 * split.size()));
+ this.previewLabel.setPoint(new Point(width, 12 + 12 * split.size()));
} else {
- this.preview.setPoint(new Point(width, 12 + 12 * split.size() - 12));
+ this.previewLabel.setPoint(new Point(width, 12 + 12 * split.size() - 12));
}
- this.preview.render(poses, mouseX, mouseY, delta);
+ this.previewLabel.render(poses, mouseX, mouseY, delta);
+
+ if (this.preview != null && this.previewHeight.value() > 0.1f) {
+ ScissorsHandler.INSTANCE.scissor(MatrixUtils.transform(poses.last().pose(), new Rectangle(0, 24 + 12 * split.size() - (nextLinePreview ? 0 : 12), width, this.previewHeight.value())));
+ this.previewTranslation = Matrix4f.createTranslateMatrix(0, 12 + 12 * split.size(), 100);
+ this.preview.render(poses, mouseX, mouseY, delta);
+ ScissorsHandler.INSTANCE.removeLastScissor();
+ }
}
}
+ private void clickPreview() {
+ if (this.preview == null) {
+ this.preview = option.getPreviewer().preview(width, () -> (T) ((REIConfigScreen) Minecraft.getInstance().screen).getOptions().get(option));
+ this.preview = Widgets.withTranslate(this.preview, () -> this.previewTranslation);
+ }
+
+ this.previewVisible = !this.previewVisible;
+ }
+
@Override
public List<? extends GuiEventListener> children() {
- return List.of(preview);
+ if (this.preview != null && this.previewHeight.value() > 0.1f) return List.of(this.previewLabel, this.preview);
+ return List.of(this.previewLabel);
}
});
- return Widgets.concatWithBounds(new Rectangle(0, 0, width, height[0]), widgets);
+
+ height[0] = stableHeight[0];
+ return Widgets.concatWithBounds(() -> new Rectangle(0, 0, width, height[0]), widgets);
}
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigGroups.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigGroups.java
index 60a78a657..87725f710 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigGroups.java
+++ b/