aboutsummaryrefslogtreecommitdiff
path: root/runtime/src
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2023-08-08 21:09:34 +0800
committershedaniel <daniel@shedaniel.me>2024-04-16 00:38:18 +0900
commitc5705ad9e7195ae679bcebee5d0e876eec7c216d (patch)
treed3036855e60e90bf1799cb6355ae285321fabfb5 /runtime/src
parent8a9d2627450d0f496690ebd052f71d3b5b5eda4b (diff)
downloadRoughlyEnoughItems-c5705ad9e7195ae679bcebee5d0e876eec7c216d.tar.gz
RoughlyEnoughItems-c5705ad9e7195ae679bcebee5d0e876eec7c216d.tar.bz2
RoughlyEnoughItems-c5705ad9e7195ae679bcebee5d0e876eec7c216d.zip
Some work on options
Diffstat (limited to 'runtime/src')
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/REIConfigScreen.java4
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigCategoriesListWidget.java2
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigCategories.java (renamed from runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/ConfigCategories.java)5
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigGroups.java34
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigOptions.java (renamed from runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllOptions.java)20
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/CompositeOption.java4
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/OptionValueEntry.java17
7 files changed, 74 insertions, 12 deletions
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 35a1e7d20..3705e4aeb 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
@@ -30,7 +30,7 @@ import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.client.gui.widgets.Widgets;
import me.shedaniel.rei.impl.client.gui.config.components.ConfigCategoriesListWidget;
-import me.shedaniel.rei.impl.client.gui.config.options.ConfigCategories;
+import me.shedaniel.rei.impl.client.gui.config.options.AllREIConfigCategories;
import me.shedaniel.rei.impl.client.gui.config.options.OptionCategory;
import me.shedaniel.rei.impl.client.gui.credits.CreditsScreen;
import me.shedaniel.rei.impl.client.gui.widget.HoleWidget;
@@ -50,7 +50,7 @@ public class REIConfigScreen extends Screen {
private OptionCategory activeCategory;
public REIConfigScreen(Screen parent) {
- this(parent, ConfigCategories.CATEGORIES);
+ this(parent, AllREIConfigCategories.CATEGORIES);
}
public REIConfigScreen(Screen parent, List<OptionCategory> categories) {
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigCategoriesListWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigCategoriesListWidget.java
index 237cd64f7..e56e04f5f 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigCategoriesListWidget.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigCategoriesListWidget.java
@@ -43,6 +43,6 @@ public class ConfigCategoriesListWidget {
.isSelectable((index, entry) -> true)
.selected(selected)
.build();
- return ScrollableViewWidget.create(bounds, list, true);
+ return ScrollableViewWidget.create(bounds, list.withPadding(0, 5), true);
}
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/ConfigCategories.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigCategories.java
index 1fc11c535..dcba86395 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/ConfigCategories.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigCategories.java
@@ -30,13 +30,14 @@ import java.util.List;
import static me.shedaniel.rei.impl.client.gui.config.options.ConfigUtils.translatable;
-public interface ConfigCategories {
+public interface AllREIConfigCategories {
static OptionCategory make(String key) {
return OptionCategory.of(new ResourceLocation("roughlyenoughitems:textures/gui/config/" + key + ".png"),
translatable("config.rei.categories." + key));
}
- OptionCategory APPEARANCE = make("appearance");
+ OptionCategory APPEARANCE = make("appearance")
+ .add(AllREIConfigGroups.INTERFACE);
OptionCategory KEYBINDS = make("keybinds");
OptionCategory CHEATS = make("cheats");
OptionCategory LAYOUT = make("layout");
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
new file mode 100644
index 000000000..3c5bd7bf1
--- /dev/null
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigGroups.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.options;
+
+import static me.shedaniel.rei.impl.client.gui.config.options.ConfigUtils.translatable;
+
+interface AllREIConfigGroups {
+ static <T> OptionGroup make(String id) {
+ return new OptionGroup(translatable("config.rei.options.groups." + id));
+ }
+
+ OptionGroup INTERFACE = make("interface");
+}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllOptions.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigOptions.java
index f992d5a68..86442fafc 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllOptions.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigOptions.java
@@ -31,23 +31,29 @@ import java.util.function.Function;
import static me.shedaniel.rei.impl.client.gui.config.options.ConfigUtils.translatable;
-interface AllOptions {
+interface AllREIConfigOptions {
static <T> CompositeOption<T> make(String id, Function<ConfigObjectImpl, T> bind,
BiConsumer<ConfigObjectImpl, T> save) {
return new CompositeOption<>(translatable("config.rei.options." + id),
translatable("config.rei.options." + id + ".desc"), bind);
}
- CompositeOption<CheatingMode> CHEATING_MODE = make("cheating_mode", i -> i.basics.cheating, (i, v) -> i.basics.cheating = v);
+ CompositeOption<CheatingMode> CHEATING_MODE = make("cheating_mode", i -> i.basics.cheating, (i, v) -> i.basics.cheating = v)
+ .enumOptions();
CompositeOption<Boolean> FAVORITES = make("favorites", i -> i.basics.favoritesEnabled, (i, v) -> i.basics.favoritesEnabled = v)
.enabledDisabled();
CompositeOption<Boolean> REDUCED_MOTION = make("reduced_motion", i -> i.basics.reduceMotion, (i, v) -> i.basics.reduceMotion = v)
.trueFalse();
- CompositeOption<ItemCheatingStyle> CHEATING_STYLE = make("cheating_style", i -> i.basics.cheatingStyle, (i, v) -> i.basics.cheatingStyle = v);
- CompositeOption<DisplayScreenType> DISPLAY_SCREEN_TYPE = make("display_screen_type", i -> i.appearance.recipeScreenType, (i, v) -> i.appearance.recipeScreenType = v);
- CompositeOption<AppearanceTheme> THEME = make("theme", i -> i.appearance.theme, (i, v) -> i.appearance.theme = v);
- CompositeOption<SearchFieldLocation> SEARCH_FIELD_LOCATION = make("search_field_location", i -> i.appearance.layout.searchFieldLocation, (i, v) -> i.appearance.layout.searchFieldLocation = v);
- CompositeOption<ConfigButtonPosition> CONFIG_BUTTON_LOCATION = make("config_button_location", i -> i.appearance.layout.configButtonLocation, (i, v) -> i.appearance.layout.configButtonLocation = v);
+ CompositeOption<ItemCheatingStyle> CHEATING_STYLE = make("cheating_style", i -> i.basics.cheatingStyle, (i, v) -> i.basics.cheatingStyle = v)
+ .enumOptions();
+ CompositeOption<DisplayScreenType> DISPLAY_SCREEN_TYPE = make("display_screen_type", i -> i.appearance.recipeScreenType, (i, v) -> i.appearance.recipeScreenType = v)
+ .enumOptions();
+ CompositeOption<AppearanceTheme> THEME = make("theme", i -> i.appearance.theme, (i, v) -> i.appearance.theme = v)
+ .enumOptions();
+ CompositeOption<SearchFieldLocation> SEARCH_FIELD_LOCATION = make("search_field_location", i -> i.appearance.layout.searchFieldLocation, (i, v) -> i.appearance.layout.searchFieldLocation = v)
+ .enumOptions();
+ CompositeOption<ConfigButtonPosition> CONFIG_BUTTON_LOCATION = make("config_button_location", i -> i.appearance.layout.configButtonLocation, (i, v) -> i.appearance.layout.configButtonLocation = v)
+ .enumOptions();
CompositeOption<Boolean> CRAFTABLE_FILTER = make("craftable_filter", i -> i.appearance.layout.showCraftableOnlyButton, (i, v) -> i.appearance.layout.showCraftableOnlyButton = v)
.enabledDisabled();
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/CompositeOption.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/CompositeOption.java
index 5b77fad0c..7d7eb46af 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/CompositeOption.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/CompositeOption.java
@@ -56,4 +56,8 @@ public class CompositeOption<T> {
public CompositeOption<Boolean> enabledDisabled() {
return ((CompositeOption<Boolean>) this).entry(OptionValueEntry.enabledDisabled());
}
+
+ public CompositeOption<T> enumOptions(T... entry) {
+ return this.entry(OptionValueEntry.enumOptions(entry));
+ }
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/OptionValueEntry.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/OptionValueEntry.java
index 8edf740bc..43c918681 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/OptionValueEntry.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/OptionValueEntry.java
@@ -23,6 +23,7 @@
package me.shedaniel.rei.impl.client.gui.config.options;
+import me.shedaniel.rei.api.common.util.CollectionUtils;
import net.minecraft.network.chat.Component;
import java.util.List;
@@ -59,6 +60,22 @@ public interface OptionValueEntry<T> {
translatable("config.rei.value.enabledDisabled.true"));
}
+ static <T> OptionValueEntry<T> enumOptions(T... array) {
+ Class<?> type = array.getClass().getComponentType();
+ Object[] constants = type.getEnumConstants();
+ return new Selection<T>() {
+ @Override
+ public List<Component> getOptions() {
+ return CollectionUtils.map(constants, o -> getOption((T) o));
+ }
+
+ @Override
+ public Component getOption(T value) {
+ return null;
+ }
+ };
+ }
+
interface Selection<T> extends OptionValueEntry<T> {
List<Component> getOptions();