aboutsummaryrefslogtreecommitdiff
path: root/runtime/src
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2023-10-27 16:14:08 +0800
committershedaniel <daniel@shedaniel.me>2024-04-16 00:38:18 +0900
commit0ff828b4c53079de978824f54d73a6ac340ae9f9 (patch)
treeb405819d760066a04998cdadd130517af549bcec /runtime/src
parenta29cad8aff11877fd6fd17e929b6cc70a9136d85 (diff)
downloadRoughlyEnoughItems-0ff828b4c53079de978824f54d73a6ac340ae9f9.tar.gz
RoughlyEnoughItems-0ff828b4c53079de978824f54d73a6ac340ae9f9.tar.bz2
RoughlyEnoughItems-0ff828b4c53079de978824f54d73a6ac340ae9f9.zip
Add preview for accessibility tab sizes, and interface themes
Diffstat (limited to 'runtime/src')
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/ConfigAccess.java34
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/REIConfigScreen.java21
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigEntriesListWidget.java5
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigGroupWidget.java33
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigOptionValueWidget.java23
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigOptionWidget.java8
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigOptions.java4
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/ConfigUtils.java2
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/preview/AccessibilityDisplayPreviewer.java80
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/preview/InterfacePreviewer.java107
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/preview/ThemePreviewer.java65
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/preview/TooltipPreviewer.java (renamed from runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/preview/TooltipPreview.java)18
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java7
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/TabContainerWidget.java79
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/TabWidget.java4
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/ArrowWidget.java8
16 files changed, 344 insertions, 154 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/ConfigAccess.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/ConfigAccess.java
new file mode 100644
index 000000000..3c6391f69
--- /dev/null
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/ConfigAccess.java
@@ -0,0 +1,34 @@
+/*
+ * This file is licensed under the MIT License, part of Roughly Enough Items.
+ * Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 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.impl.client.gui.config;
+
+import me.shedaniel.rei.impl.client.gui.config.options.CompositeOption;
+
+public interface ConfigAccess {
+ <T> T get(CompositeOption<T> option);
+
+ <T> void set(CompositeOption<T> option, T value);
+
+ <T> T getDefault(CompositeOption<T> option);
+}
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 89bd772e3..3a0566b8e 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
@@ -52,7 +52,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-public class REIConfigScreen extends Screen {
+public class REIConfigScreen extends Screen implements ConfigAccess {
private final Screen parent;
private final List<OptionCategory> categories;
private final List<Widget> widgets = new ArrayList<>();
@@ -97,12 +97,12 @@ public class REIConfigScreen extends Screen {
int sideWidth = (int) (width / 4.2);
boolean singlePane = width - 20 - sideWidth <= 330;
int singleSideWidth = 32 + 6 + 4;
- Widget[] list = {ConfigEntriesListWidget.create(new Rectangle(singlePane ? 8 + singleSideWidth : 12 + sideWidth, 32, singlePane ? width - 16 - singleSideWidth : width - 20 - sideWidth, height - 32 - 32), activeCategory.getGroups())};
+ Widget[] list = {ConfigEntriesListWidget.create(this, new Rectangle(singlePane ? 8 + singleSideWidth : 12 + sideWidth, 32, singlePane ? width - 16 - singleSideWidth : width - 20 - sideWidth, height - 32 - 32), activeCategory.getGroups())};
IntValue selectedCategory = new IntValue() {
@Override
public void accept(int i) {
REIConfigScreen.this.activeCategory = categories.get(i);
- list[0] = ConfigEntriesListWidget.create(new Rectangle(singlePane ? 8 + singleSideWidth : 12 + sideWidth, 32, singlePane ? width - 16 - singleSideWidth : width - 20 - sideWidth, height - 32 - 32), activeCategory.getGroups());
+ list[0] = ConfigEntriesListWidget.create(REIConfigScreen.this, new Rectangle(singlePane ? 8 + singleSideWidth : 12 + sideWidth, 32, singlePane ? width - 16 - singleSideWidth : width - 20 - sideWidth, height - 32 - 32), activeCategory.getGroups());
}
@Override
@@ -202,4 +202,19 @@ public class REIConfigScreen extends Screen {
this.widgets.remove(menu);
this.menu = null;
}
+
+ @Override
+ public <T> T get(CompositeOption<T> option) {
+ return (T) getOptions().get(option);
+ }
+
+ @Override
+ public <T> void set(CompositeOption<T> option, T value) {
+ ((Map<CompositeOption<?>, Object>) getOptions()).put(option, value);
+ }
+
+ @Override
+ public <T> T getDefault(CompositeOption<T> option) {
+ return (T) getDefaultOptions().get(option);
+ }
}
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 de05300eb..b1ecca932 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
@@ -26,6 +26,7 @@ package me.shedaniel.rei.impl.client.gui.config.components;
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.impl.client.gui.config.ConfigAccess;
import me.shedaniel.rei.impl.client.gui.config.options.OptionGroup;
import me.shedaniel.rei.impl.client.gui.widget.ListWidget;
import me.shedaniel.rei.impl.client.gui.widget.ScrollableViewWidget;
@@ -34,9 +35,9 @@ import me.shedaniel.rei.impl.common.util.RectangleUtils;
import java.util.List;
public class ConfigEntriesListWidget {
- public static Widget create(Rectangle bounds, List<OptionGroup> groups) {
+ public static Widget create(ConfigAccess access, Rectangle bounds, List<OptionGroup> groups) {
WidgetWithBounds list = ListWidget.builderOf(RectangleUtils.inset(bounds, 6, 6), groups,
- (index, entry) -> ConfigGroupWidget.create(entry, bounds.width - 12 - 6))
+ (index, entry) -> ConfigGroupWidget.create(access, entry, bounds.width - 12 - 6))
.gap(7)
.calculateTotalHeightDynamically(true)
.build();
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 e23924ac7..bf9f48c55 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
@@ -30,10 +30,13 @@ 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.ConfigAccess;
import me.shedaniel.rei.impl.client.gui.config.options.AllREIConfigGroups;
import me.shedaniel.rei.impl.client.gui.config.options.CompositeOption;
import me.shedaniel.rei.impl.client.gui.config.options.OptionGroup;
-import me.shedaniel.rei.impl.client.gui.config.options.preview.TooltipPreview;
+import me.shedaniel.rei.impl.client.gui.config.options.preview.AccessibilityDisplayPreviewer;
+import me.shedaniel.rei.impl.client.gui.config.options.preview.InterfacePreviewer;
+import me.shedaniel.rei.impl.client.gui.config.options.preview.TooltipPreviewer;
import net.minecraft.client.gui.GuiComponent;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
@@ -47,14 +50,16 @@ public class ConfigGroupWidget {
private static final Map<OptionGroup, Pair<PreviewLocation, SpecialGroupConstructor>> SPECIAL_GROUPS = new HashMap<>();
static {
- addPreview(AllREIConfigGroups.APPEARANCE_TOOLTIPS, PreviewLocation.RIGHT, (entry, width, height) -> TooltipPreview.create(width, height));
+ addPreview(AllREIConfigGroups.APPEARANCE_INTERFACE, PreviewLocation.RIGHT, (access, entry, width, height) -> InterfacePreviewer.create(access, width, height));
+ addPreview(AllREIConfigGroups.APPEARANCE_TOOLTIPS, PreviewLocation.RIGHT, (access, entry, width, height) -> TooltipPreviewer.create(access, width, height));
+ addPreview(AllREIConfigGroups.ACCESSIBILITY_DISPLAY, PreviewLocation.BOTTOM, (access, entry, width, height) -> AccessibilityDisplayPreviewer.create(access, width));
}
public static void addPreview(OptionGroup group, PreviewLocation location, SpecialGroupConstructor constructor) {
SPECIAL_GROUPS.put(group, Pair.of(location, constructor));
}
- public static WidgetWithBounds create(OptionGroup entry, int width) {
+ public static WidgetWithBounds create(ConfigAccess access, OptionGroup entry, int width) {
WidgetWithBounds groupTitle = Widgets.createLabel(new Point(0, 3), entry.getGroupName().copy().withStyle(style -> style.withColor(0xFFC0C0C0).withUnderlined(true)))
.leftAligned()
.withPadding(0, 0, 0, 6);
@@ -64,30 +69,30 @@ public class ConfigGroupWidget {
Pair<PreviewLocation, SpecialGroupConstructor> pair = SPECIAL_GROUPS.get(entry);
PreviewLocation location = pair.getLeft();
int halfWidth = width * 6 / 10 - 2;
- if (halfWidth <= 200) location = PreviewLocation.TOP;
+ if (halfWidth <= 200 && location == PreviewLocation.RIGHT) location = PreviewLocation.TOP;
if (location == PreviewLocation.RIGHT) {
- WidgetWithBounds original = _create(entry, halfWidth);
+ WidgetWithBounds original = _create(access, entry, halfWidth);
Widget background = createBackgroundSlot(() -> new Rectangle(halfWidth + 2, 0, width - halfWidth - 4, original.getBounds().height));
- Widget right = Widgets.withTranslate(pair.getRight().create(entry, () -> width - halfWidth - 4, () -> original.getBounds().height), halfWidth + 2, 0, 0);
+ Widget right = Widgets.withTranslate(pair.getRight().create(access, entry, width - halfWidth - 4, () -> original.getBounds().height), halfWidth + 2, 0, 0);
contents = Widgets.concatWithBounds(() -> new Rectangle(0, 0, width, original.getBounds().height), original, background, right);
} else {
- WidgetWithBounds original = _create(entry, width);
+ WidgetWithBounds original = _create(access, entry, width);
if (location == PreviewLocation.TOP) {
- WidgetWithBounds widget = pair.getRight().create(entry, () -> width, null);
+ WidgetWithBounds widget = pair.getRight().create(access, entry, width, null);
Widget background = createBackgroundSlot(widget::getBounds);
WidgetWithBounds translatedOriginal = Widgets.withTranslate(original, () -> Matrix4f.createTranslateMatrix(0, widget.getBounds().height + 4, 0));
contents = Widgets.concatWithBounds(() -> new Rectangle(0, 0, width, widget.getBounds().height + 4 + translatedOriginal.getBounds().height), translatedOriginal, background, widget);
} else {
- WidgetWithBounds widget = pair.getRight().create(entry, () -> width, null);
+ WidgetWithBounds widget = pair.getRight().create(access, entry, width, null);
Widget background = createBackgroundSlot(widget::getBounds);
- contents = Widgets.concatWithBounds(() -> new Rectangle(0, 0, width, original.getBounds().getMaxY() + 4 + widget.getBounds().height), original,
+ contents = Widgets.concatWithBounds(() -> new Rectangle(0, 0, width, original.getBounds().getMaxY() + 2 + widget.getBounds().height), original,
Widgets.withTranslate(Widgets.concat(background, widget), () -> Matrix4f.createTranslateMatrix(0, original.getBounds().getMaxY() + 4, 0)));
}
}
} else {
- contents = _create(entry, width);
+ contents = _create(access, entry, width);
}
return Widgets.concatWithBounds(
@@ -97,13 +102,13 @@ public class ConfigGroupWidget {
);
}
- private static WidgetWithBounds _create(OptionGroup entry, int width) {
+ private static WidgetWithBounds _create(ConfigAccess access, OptionGroup entry, int width) {
List<Triple<Widget, Supplier<Rectangle>, Matrix4f[]>> widgets = new ArrayList<>();
int[] height = {0};
for (CompositeOption<?> option : entry.getOptions()) {
Matrix4f[] translation = new Matrix4f[]{Matrix4f.createTranslateMatrix(0, height[0], 0)};
- WidgetWithBounds widget = Widgets.withTranslate(ConfigOptionWidget.create(option, width), () -> translation[0]);
+ WidgetWithBounds widget = Widgets.withTranslate(ConfigOptionWidget.create(access, 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());
@@ -143,7 +148,7 @@ public class ConfigGroupWidget {
@FunctionalInterface
public interface SpecialGroupConstructor {
- WidgetWithBounds create(OptionGroup entry, IntSupplier width, @Nullable IntSupplier height);
+ WidgetWithBounds create(ConfigAccess access, OptionGroup entry, int width, @Nullable IntSupplier height);
}
public enum PreviewLocation {
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 e2d62eed3..fa7b6ea22 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,7 +23,6 @@
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;
@@ -33,6 +32,7 @@ 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.api.common.util.CollectionUtils;
+import me.shedaniel.rei.impl.client.gui.config.ConfigAccess;
import me.shedaniel.rei.impl.client.gui.config.REIConfigScreen;
import me.shedaniel.rei.impl.client.gui.config.options.CompositeOption;
import me.shedaniel.rei.impl.client.gui.config.options.OptionValueEntry;
@@ -43,18 +43,15 @@ import net.minecraft.client.Minecraft;
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;
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();
+ public static <T> WidgetWithBounds create(ConfigAccess access, CompositeOption<T> option) {
OptionValueEntry<T> entry = option.getEntry();
- T value = (T) options.get(option);
+ T value = access.get(option);
Component[] text = new Component[1];
if (entry instanceof OptionValueEntry.Selection<T> selection) {
@@ -63,7 +60,7 @@ public class ConfigOptionValueWidget {
text[0] = literal(value.toString());
}
- if (value.equals(Objects.requireNonNullElseGet(option.getDefaultValue(), () -> (T) defaultOptions.get(option)))) {
+ if (value.equals(Objects.requireNonNullElseGet(option.getDefaultValue(), () -> access.getDefault(option)))) {
text[0] = translatable("config.rei.value.default", text[0]);
}
@@ -83,10 +80,10 @@ public class ConfigOptionValueWidget {
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));
- text[0] = selection.getOption((T) options.get(option));
+ access.set(option, selection.getOptions().get((selection.getOptions().indexOf(access.get(option)) + 1) % 2));
+ text[0] = selection.getOption(access.get(option));
- if (options.get(option).equals(Objects.requireNonNullElseGet(option.getDefaultValue(), () -> (T) defaultOptions.get(option)))) {
+ if (access.get(option).equals(Objects.requireNonNullElseGet(option.getDefaultValue(), () -> access.getDefault(option)))) {
text[0] = translatable("config.rei.value.default", text[0]);
}
});
@@ -94,16 +91,16 @@ public class ConfigOptionValueWidget {
label.clickable().onClick($ -> {
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))) {
+ if (opt.equals(access.getDefault(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);
+ access.set(option, opt);
text[0] = selection.getOption(opt);
- if (options.get(option).equals(defaultOptions.get(option))) {
+ if (access.get(option).equals(access.getDefault(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 a8060b520..ba546edd1 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
@@ -35,7 +35,7 @@ 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.ConfigAccess;
import me.shedaniel.rei.impl.client.gui.config.options.CompositeOption;
import me.shedaniel.rei.impl.client.gui.config.options.ConfigUtils;
import net.minecraft.client.Minecraft;
@@ -50,13 +50,13 @@ import java.util.List;
import static me.shedaniel.rei.impl.client.gui.config.options.ConfigUtils.translatable;
public class ConfigOptionWidget {
- public static <T> WidgetWithBounds create(CompositeOption<T> option, int width) {
+ public static <T> WidgetWithBounds create(ConfigAccess access, 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());
- WidgetWithBounds optionValue = ConfigOptionValueWidget.create(option);
+ WidgetWithBounds optionValue = ConfigOptionValueWidget.create(access, option);
widgets.add(Widgets.withTranslate(optionValue, () -> Matrix4f.createTranslateMatrix(width - optionValue.getBounds().width - optionValue.getBounds().x, 0, 0)));
widgets.add(new WidgetWithBounds() {
final MutableComponent description = option.getDescription().copy().withStyle(style -> style.withColor(0xFF757575));
@@ -123,7 +123,7 @@ public class ConfigOptionWidget {
private void clickPreview() {
if (this.preview == null) {
- this.preview = option.getPreviewer().preview(width, () -> (T) ((REIConfigScreen) Minecraft.getInstance().screen).getOptions().get(option));
+ this.preview = option.getPreviewer().preview(width, () -> access.get(option));
this.preview = Widgets.withTranslate(this.preview, () -> this.previewTranslation);
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigOptions.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigOptions.java
index bcd3617fd..257088865 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigOptions.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigOptions.java
@@ -26,7 +26,6 @@ package me.shedaniel.rei.impl.client.gui.config.options;
import me.shedaniel.rei.api.client.gui.config.*;
import me.shedaniel.rei.impl.client.config.ConfigObjectImpl;
import me.shedaniel.rei.impl.client.gui.config.REIConfigScreen;
-import me.shedaniel.rei.impl.client.gui.config.options.preview.ThemePreviewer;
import net.minecraft.client.Minecraft;
import java.util.function.BiConsumer;
@@ -43,8 +42,7 @@ public interface AllREIConfigOptions {
}
CompositeOption<AppearanceTheme> THEME = make("appearance.theme", i -> i.appearance.theme, (i, v) -> i.appearance.theme = v)
- .enumOptions()
- .previewer(ThemePreviewer.INSTANCE);
+ .enumOptions();
CompositeOption<RecipeBorderType> RECIPE_BORDER = make("appearance.recipe_border", i -> i.appearance.recipeBorder, (i, v) -> i.appearance.recipeBorder = v)
.enumOptions();
CompositeOption<Boolean> REDUCED_MOTION = make("appearance.reduced_motion", i -> i.basics.reduceMotion, (i, v) -> i.basics.reduceMotion = v)
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/ConfigUtils.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/ConfigUtils.java
index b65826f23..539be5526 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/ConfigUtils.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/ConfigUtils.java
@@ -33,7 +33,7 @@ import net.minecraft.network.chat.TranslatableComponent;
public interface ConfigUtils {
static boolean isReducedMotion() {
if (Minecraft.getInstance().screen instanceof REIConfigScreen screen) {
- return ((Boolean) screen.getOptions().get(AllREIConfigOptions.REDUCED_MOTION)).booleanValue();
+ return screen.get(AllREIConfigOptions.REDUCED_MOTION);
} else {
return ConfigObject.getInstance().isReducedMotion();
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/preview/AccessibilityDisplayPreviewer.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/preview/AccessibilityDisplayPreviewer.java
new file mode 100644
index 000000000..ccebdab45
--- /dev/null
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/preview/AccessibilityDisplayPreviewer.java
@@ -0,0 +1,80 @@
+/*
+ * This file is licensed under the MIT License, part of Roughly Enough Items.
+ * Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 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.impl.client.gui.config.options.preview;
+
+import com.google.common.base.MoreObjects;
+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.common.entry.EntryStack;
+import me.shedaniel.rei.api.common.util.EntryStacks;
+import me.shedaniel.rei.impl.client.gui.config.ConfigAccess;
+import me.shedaniel.rei.impl.client.gui.config.options.AllREIConfigOptions;
+import me.shedaniel.rei.impl.client.gui.widget.TabContainerWidget;
+import me.shedaniel.rei.impl.client.gui.widget.TabWidget;
+import net.minecraft.world.item.Items;
+
+public class AccessibilityDisplayPreviewer {
+ public static WidgetWithBounds create(ConfigAccess access, int width) {
+ int[] selected = {0};
+ TabWidget[] tabs = new TabWidget[4];
+ Widget[] buttons = {null};
+ return Widgets.concatWithBounds(() -> new Rectangle(width, 36 + 17),
+ Widgets.delegate(() -> MoreObjects.firstNonNull(tabs[0], Widgets.noOp())),
+ Widgets.delegate(() -> MoreObjects.firstNonNull(tabs[1], Widgets.noOp())),
+ Widgets.delegate(() -> MoreObjects.firstNonNull(tabs[2], Widgets.noOp())),
+ Widgets.delegate(() -> MoreObjects.firstNonNull(tabs[3], Widgets.noOp())),
+ Widgets.scissored(new Rectangle(1, 1, width - 2, 34 + 17), Widgets.createCategoryBase(new Rectangle(width / 2 - 28 * 3 / 2 - 10, 30 + 17, 28 * 3 + 20, 28))),
+ Widgets.delegate(() -> MoreObjects.firstNonNull(selected[0] < 4 ? tabs[selected[0]] : null, Widgets.noOp())),
+ Widgets.delegate(() -> MoreObjects.firstNonNull(buttons[0], Widgets.noOp())),
+ Widgets.createDrawableWidget((helper, matrices, mouseX, mouseY, delta) -> {
+ boolean largerTabs = access.get(AllREIConfigOptions.LARGER_TABS);
+ boolean largerArrowButtons = access.get(AllREIConfigOptions.LARGER_ARROW_BUTTONS);
+ int tabSize = largerTabs ? 28 : 24;
+ for (int i = 0; i < 4; i++) {
+ tabs[i] = null;
+ }
+ for (int i = 0; i < (largerTabs ? 3 : 4); i++) {
+ int finalI = i;
+ tabs[i] = TabWidget.create(i, tabSize, width / 2 - tabSize * (largerTabs ? 3 : 4) / 2, 30 + 17, 0, !largerTabs ? 166 : 192, tabWidget -> {
+ selected[0] = finalI;
+ return true;
+ });
+ EntryStack<?> stack = i == 0 ? EntryStacks.of(Items.CRAFTING_TABLE) :
+ i == 1 ? EntryStacks.of(Items.FURNACE) :
+ i == 2 ? EntryStacks.of(Items.SMOKER) :
+ EntryStacks.of(Items.BLAST_FURNACE);
+ tabs[i].setRenderer(null, stack, null, selected[0] == i);
+ }
+ if (selected[0] >= (largerTabs ? 3 : 4)) selected[0] = 0;
+
+ buttons[0] = Widgets.concat(TabContainerWidget.getCategoryButtons(new Rectangle(width / 2 - 28 * 3 / 2 - 10, 2 + 16, 28 * 3 + 20, 28),
+ !largerArrowButtons, tabSize, largerArrowButtons ? 16 : 10, () -> {
+ }, () -> {
+ }));
+ })
+ );
+ }
+}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/preview/InterfacePreviewer.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/preview/InterfacePreviewer.java
new file mode 100644
index 000000000..80e493784
--- /dev/null
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/preview/InterfacePreviewer.java
@@ -0,0 +1,107 @@
+/*
+ * This file is licensed under the MIT License, part of Roughly Enough Items.
+ * Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 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.impl.client.gui.config.options.preview;
+
+import com.mojang.math.Matrix4f;
+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.config.AppearanceTheme;
+import me.shedaniel.rei.api.client.gui.config.RecipeBorderType;
+import me.shedaniel.rei.api.client.gui.widgets.Panel;
+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.common.util.EntryIngredients;
+import me.shedaniel.rei.api.common.util.EntryStacks;
+import me.shedaniel.rei.impl.client.gui.config.ConfigAccess;
+import me.shedaniel.rei.impl.client.gui.config.options.AllREIConfigOptions;
+import me.shedaniel.rei.impl.client.gui.widget.EntryWidget;
+import me.shedaniel.rei.impl.client.gui.widget.basewidgets.ArrowWidget;
+import me.shedaniel.rei.impl.client.gui.widget.basewidgets.PanelWidget;
+import net.minecraft.Util;
+import net.minecraft.world.item.Items;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.function.IntSupplier;
+
+public class InterfacePreviewer {
+ public static WidgetWithBounds create(ConfigAccess access, int width, @Nullable IntSupplier height) {
+ WidgetWithBounds widget = _create(access, width);
+ if (height == null) {
+ Widget background = Widgets.createCategoryBase(new Rectangle(2, 2, width - 4, widget.getBounds().height - 4));
+ return Widgets.concatWithBounds(widget::getBounds, background, widget);
+ }
+ Panel base = Widgets.createCategoryBase(new Rectangle(2, 2, width - 4, height.getAsInt() - 4));