diff options
5 files changed, 52 insertions, 16 deletions
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 39b230b93..5e9a98261 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,9 +35,9 @@ public enum CheatingMode { public String toString() { switch (this) { case ON: - return I18n.get("text.cloth-config.boolean.value.true"); + return I18n.get("config.rei.value.enabledDisabled.true"); case OFF: - return I18n.get("text.cloth-config.boolean.value.false"); + return I18n.get("config.rei.value.enabledDisabled.false"); case WHEN_CREATIVE: return I18n.get("config.roughlyenoughitems.cheating.when_creative"); default: diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/REIConfigScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/REIConfigScreen.java index f8262de4c..5b0929879 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/REIConfigScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/REIConfigScreen.java @@ -55,6 +55,7 @@ public class REIConfigScreen extends Screen { private final Screen parent; private final List<OptionCategory> categories; private final List<Widget> widgets = new ArrayList<>(); + private final Map<CompositeOption<?>, ?> defaultOptions = new HashMap<>(); private final Map<CompositeOption<?>, ?> options = new HashMap<>(); private OptionCategory activeCategory; @Nullable @@ -71,10 +72,12 @@ public class REIConfigScreen extends Screen { Preconditions.checkArgument(!categories.isEmpty(), "Categories cannot be empty!"); this.activeCategory = categories.get(0); + ConfigObjectImpl defaultConfig = new ConfigObjectImpl(); ConfigObjectImpl config = ConfigManagerImpl.getInstance().getConfig(); for (OptionCategory category : categories) { for (OptionGroup group : category.getGroups()) { for (CompositeOption<?> option : group.getOptions()) { + ((Map<CompositeOption<?>, Object>) this.defaultOptions).put(option, option.getBind().apply(defaultConfig)); ((Map<CompositeOption<?>, Object>) this.options).put(option, option.getBind().apply(config)); } } @@ -107,6 +110,10 @@ public class REIConfigScreen extends Screen { this.widgets.add(Widgets.delegate(() -> list[0])); } + public Map<CompositeOption<?>, ?> getDefaultOptions() { + return defaultOptions; + } + public Map<CompositeOption<?>, ?> getOptions() { return options; } 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 bfa7d66b7..f2764dd2d 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 @@ -26,6 +26,7 @@ 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.math.impl.PointHelper; import me.shedaniel.rei.api.client.gui.widgets.Label; import me.shedaniel.rei.api.client.gui.widgets.WidgetWithBounds; import me.shedaniel.rei.api.client.gui.widgets.Widgets; @@ -36,6 +37,7 @@ import me.shedaniel.rei.impl.client.gui.config.options.CompositeOption; import me.shedaniel.rei.impl.client.gui.config.options.OptionValueEntry; import me.shedaniel.rei.impl.client.gui.modules.Menu; import me.shedaniel.rei.impl.client.gui.modules.entries.ToggleMenuEntry; +import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; @@ -43,41 +45,67 @@ import net.minecraft.resources.ResourceLocation; import java.util.Map; import static me.shedaniel.rei.impl.client.gui.config.options.ConfigUtils.literal; +import static me.shedaniel.rei.impl.client.gui.config.options.ConfigUtils.translatable; public class ConfigOptionValueWidget { public static <T> WidgetWithBounds create(CompositeOption<T> option) { + Map<CompositeOption<?>, ?> defaultOptions = ((REIConfigScreen) Minecraft.getInstance().screen).getDefaultOptions(); Map<CompositeOption<?>, ?> options = ((REIConfigScreen) Minecraft.getInstance().screen).getOptions(); OptionValueEntry<T> entry = option.getEntry(); T value = (T) options.get(option); - Component text; + Component[] text = new Component[1]; if (entry instanceof OptionValueEntry.Selection<T> selection) { - text = selection.getOption(value); + text[0] = selection.getOption(value); } else { - text = literal(value.toString()); + text[0] = literal(value.toString()); + } + + if (value.equals(defaultOptions.get(option))) { + text[0] = translatable("config.rei.value.default", text[0]); } - Label label = Widgets.createLabel(new Point(), text).rightAligned() - .color(0xFFE0E0E0) - .hoveredColor(0xFFE0E0E0); Matrix4f[] matrix = {new Matrix4f()}; + Label label = Widgets.createLabel(new Point(), text[0]).rightAligned() + .color(0xFFE0E0E0) + .hoveredColor(0xFFE0E0E0) + .onRender((poses, l) -> { + if (MatrixUtils.transform(matrix[0], l.getBounds()).contains(PointHelper.ofMouse())) { + l.setMessage(text[0].copy().withStyle(ChatFormatting.UNDERLINE)); + } else { + l.setMessage(text[0]); + } + }); if (entry instanceof OptionValueEntry.Selection<T> selection) { int noOfOptions = selection.getOptions().size(); if (noOfOptions == 2) { label.clickable().onClick($ -> { ((Map<CompositeOption<?>, Object>) options).put(option, selection.getOptions().get((selection.getOptions().indexOf((T) options.get(option)) + 1) % 2)); - label.setMessage(selection.getOption((T) options.get(option))); + text[0] = selection.getOption((T) options.get(option)); + + if (options.get(option).equals(defaultOptions.get(option))) { + text[0] = translatable("config.rei.value.default", text[0]); + } }); } else if (noOfOptions >= 2) { label.clickable().onClick($ -> { - Menu menu = new Menu(MatrixUtils.transform(matrix[0], label.getBounds()), CollectionUtils.map(selection.getOptions(), - opt -> ToggleMenuEntry.of(selection.getOption(opt), () -> false, o -> { - ((REIConfigScreen) Minecraft.getInstance().screen).closeMenu(); - ((Map<CompositeOption<?>, Object>) options).put(option, opt); - label.setMessage(selection.getOption(opt)); - }) - .withActive(() -> true)), false); + Menu menu = new Menu(MatrixUtils.transform(matrix[0], label.getBounds()), CollectionUtils.map(selection.getOptions(), opt -> { + Component selectionOption = selection.getOption(opt); + if (opt.equals(defaultOptions.get(option))) { + selectionOption = translatable("config.rei.value.default", selectionOption); + } + + return ToggleMenuEntry.of(selectionOption, () -> false, o -> { + ((REIConfigScreen) Minecraft.getInstance().screen).closeMenu(); + ((Map<CompositeOption<?>, Object>) options).put(option, opt); + text[0] = selection.getOption(opt); + + if (options.get(option).equals(defaultOptions.get(option))) { + text[0] = translatable("config.rei.value.default", text[0]); + } + }); + }), false); ((REIConfigScreen) Minecraft.getInstance().screen).closeMenu(); ((REIConfigScreen) Minecraft.getInstance().screen).openMenu(menu); }); diff --git a/runtime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json b/runtime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json index 9eeddb001..883b778e2 100755 --- a/runtime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json +++ b/runtime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json @@ -372,6 +372,7 @@ "config.rei.options.groups.reset.reset": "Reset", "config.rei.options.reset.reset_all_options": "Reset All Options", "config.rei.options.reset.reset_all_options.desc": "This is an extremely destructive operation. This resets all REI options as the factory state, and cannot be reversed.", + "config.rei.value.default": "%s (Default)", "config.rei.value.trueFalse.false": "False", "config.rei.value.trueFalse.true": "True", "config.rei.value.enabledDisabled.false": "Disabled", diff --git a/runtime/src/main/resources/assets/roughlyenoughitems/textures/gui/config/selector.png b/runtime/src/main/resources/assets/roughlyenoughitems/textures/gui/config/selector.png Binary files differnew file mode 100644 index 000000000..231b3170f --- /dev/null +++ b/runtime/src/main/resources/assets/roughlyenoughitems/textures/gui/config/selector.png |
