From c5705ad9e7195ae679bcebee5d0e876eec7c216d Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 8 Aug 2023 21:09:34 +0800 Subject: Some work on options --- .../impl/client/gui/config/REIConfigScreen.java | 4 +- .../components/ConfigCategoriesListWidget.java | 2 +- .../impl/client/gui/config/options/AllOptions.java | 53 ------------------ .../gui/config/options/AllREIConfigCategories.java | 64 ++++++++++++++++++++++ .../gui/config/options/AllREIConfigGroups.java | 34 ++++++++++++ .../gui/config/options/AllREIConfigOptions.java | 59 ++++++++++++++++++++ .../client/gui/config/options/CompositeOption.java | 4 ++ .../gui/config/options/ConfigCategories.java | 63 --------------------- .../gui/config/options/OptionValueEntry.java | 17 ++++++ 9 files changed, 181 insertions(+), 119 deletions(-) delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllOptions.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigCategories.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigGroups.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigOptions.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/ConfigCategories.java 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 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/AllOptions.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllOptions.java deleted file mode 100644 index f992d5a68..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllOptions.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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 me.shedaniel.rei.api.client.gui.config.*; -import me.shedaniel.rei.impl.client.config.ConfigObjectImpl; - -import java.util.function.BiConsumer; -import java.util.function.Function; - -import static me.shedaniel.rei.impl.client.gui.config.options.ConfigUtils.translatable; - -interface AllOptions { - static CompositeOption make(String id, Function bind, - BiConsumer save) { - return new CompositeOption<>(translatable("config.rei.options." + id), - translatable("config.rei.options." + id + ".desc"), bind); - } - - CompositeOption CHEATING_MODE = make("cheating_mode", i -> i.basics.cheating, (i, v) -> i.basics.cheating = v); - CompositeOption FAVORITES = make("favorites", i -> i.basics.favoritesEnabled, (i, v) -> i.basics.favoritesEnabled = v) - .enabledDisabled(); - CompositeOption REDUCED_MOTION = make("reduced_motion", i -> i.basics.reduceMotion, (i, v) -> i.basics.reduceMotion = v) - .trueFalse(); - CompositeOption CHEATING_STYLE = make("cheating_style", i -> i.basics.cheatingStyle, (i, v) -> i.basics.cheatingStyle = v); - CompositeOption DISPLAY_SCREEN_TYPE = make("display_screen_type", i -> i.appearance.recipeScreenType, (i, v) -> i.appearance.recipeScreenType = v); - CompositeOption THEME = make("theme", i -> i.appearance.theme, (i, v) -> i.appearance.theme = v); - CompositeOption SEARCH_FIELD_LOCATION = make("search_field_location", i -> i.appearance.layout.searchFieldLocation, (i, v) -> i.appearance.layout.searchFieldLocation = v); - CompositeOption CONFIG_BUTTON_LOCATION = make("config_button_location", i -> i.appearance.layout.configButtonLocation, (i, v) -> i.appearance.layout.configButtonLocation = v); - CompositeOption 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/AllREIConfigCategories.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigCategories.java new file mode 100644 index 000000000..dcba86395 --- /dev/null +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigCategories.java @@ -0,0 +1,64 @@ +/* + * 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 com.google.common.collect.ImmutableList; +import net.minecraft.resources.ResourceLocation; + +import java.util.List; + +import static me.shedaniel.rei.impl.client.gui.config.options.ConfigUtils.translatable; + +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") + .add(AllREIConfigGroups.INTERFACE); + OptionCategory KEYBINDS = make("keybinds"); + OptionCategory CHEATS = make("cheats"); + OptionCategory LAYOUT = make("layout"); + OptionCategory ACCESSIBILITY = make("accessibility"); + OptionCategory FAVORITES = make("favorites"); + OptionCategory PERFORMANCE = make("performance"); + OptionCategory SEARCH = make("search"); + OptionCategory FILTERING = make("filtering"); + OptionCategory LIST = make("list"); + OptionCategory DEBUG = make("debug"); + List CATEGORIES = ImmutableList.of( + APPEARANCE, + KEYBINDS, + CHEATS, + LAYOUT, + ACCESSIBILITY, + FAVORITES, + PERFORMANCE, + SEARCH, + FILTERING, + LIST, + DEBUG + ); +} 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 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/AllREIConfigOptions.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigOptions.java new file mode 100644 index 000000000..86442fafc --- /dev/null +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigOptions.java @@ -0,0 +1,59 @@ +/* + * 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 me.shedaniel.rei.api.client.gui.config.*; +import me.shedaniel.rei.impl.client.config.ConfigObjectImpl; + +import java.util.function.BiConsumer; +import java.util.function.Function; + +import static me.shedaniel.rei.impl.client.gui.config.options.ConfigUtils.translatable; + +interface AllREIConfigOptions { + static CompositeOption make(String id, Function bind, + BiConsumer save) { + return new CompositeOption<>(translatable("config.rei.options." + id), + translatable("config.rei.options." + id + ".desc"), bind); + } + + CompositeOption CHEATING_MODE = make("cheating_mode", i -> i.basics.cheating, (i, v) -> i.basics.cheating = v) + .enumOptions(); + CompositeOption FAVORITES = make("favorites", i -> i.basics.favoritesEnabled, (i, v) -> i.basics.favoritesEnabled = v) + .enabledDisabled(); + CompositeOption REDUCED_MOTION = make("reduced_motion", i -> i.basics.reduceMotion, (i, v) -> i.basics.reduceMotion = v) + .trueFalse(); + CompositeOption CHEATING_STYLE = make("cheating_style", i -> i.basics.cheatingStyle, (i, v) -> i.basics.cheatingStyle = v) + .enumOptions(); + CompositeOption DISPLAY_SCREEN_TYPE = make("display_screen_type", i -> i.appearance.recipeScreenType, (i, v) -> i.appearance.recipeScreenType = v) + .enumOptions(); + CompositeOption THEME = make("theme", i -> i.appearance.theme, (i, v) -> i.appearance.theme = v) + .enumOptions(); + CompositeOption SEARCH_FIELD_LOCATION = make("search_field_location", i -> i.appearance.layout.searchFieldLocation, (i, v) -> i.appearance.layout.searchFieldLocation = v) + .enumOptions(); + CompositeOption CONFIG_BUTTON_LOCATION = make("config_button_location", i -> i.appearance.layout.configButtonLocation, (i, v) -> i.appearance.layout.configButtonLocation = v) + .enumOptions(); + CompositeOption 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 { public CompositeOption enabledDisabled() { return ((CompositeOption) this).entry(OptionValueEntry.enabledDisabled()); } + + public CompositeOption enumOptions(T... entry) { + return this.entry(OptionValueEntry.enumOptions(entry)); + } } 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/ConfigCategories.java deleted file mode 100644 index 1fc11c535..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/ConfigCategories.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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 com.google.common.collect.ImmutableList; -import net.minecraft.resources.ResourceLocation; - -import java.util.List; - -import static me.shedaniel.rei.impl.client.gui.config.options.ConfigUtils.translatable; - -public interface ConfigCategories { - 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 KEYBINDS = make("keybinds"); - OptionCategory CHEATS = make("cheats"); - OptionCategory LAYOUT = make("layout"); - OptionCategory ACCESSIBILITY = make("accessibility"); - OptionCategory FAVORITES = make("favorites"); - OptionCategory PERFORMANCE = make("performance"); - OptionCategory SEARCH = make("search"); - OptionCategory FILTERING = make("filtering"); - OptionCategory LIST = make("list"); - OptionCategory DEBUG = make("debug"); - List CATEGORIES = ImmutableList.of( - APPEARANCE, - KEYBINDS, - CHEATS, - LAYOUT, - ACCESSIBILITY, - FAVORITES, - PERFORMANCE, - SEARCH, - FILTERING, - LIST, - DEBUG - ); -} 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 { translatable("config.rei.value.enabledDisabled.true")); } + static OptionValueEntry enumOptions(T... array) { + Class type = array.getClass().getComponentType(); + Object[] constants = type.getEnumConstants(); + return new Selection() { + @Override + public List getOptions() { + return CollectionUtils.map(constants, o -> getOption((T) o)); + } + + @Override + public Component getOption(T value) { + return null; + } + }; + } + interface Selection extends OptionValueEntry { List getOptions(); -- cgit