From 288459c88b9e86aa33ae1109e5eaa12ce7c2070c Mon Sep 17 00:00:00 2001 From: James Seibel Date: Mon, 12 Jun 2023 20:24:56 -0500 Subject: [PATCH] Allow skipping config enums --- .../common/wrappers/gui/ClassicConfigGUI.java | 51 +++++++++++++++---- coreSubProjects | 2 +- 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/gui/ClassicConfigGUI.java b/common/src/main/java/com/seibel/lod/common/wrappers/gui/ClassicConfigGUI.java index a21c00c8a..e6fede427 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/gui/ClassicConfigGUI.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/gui/ClassicConfigGUI.java @@ -15,6 +15,7 @@ import java.util.regex.Pattern; // Logger (for debug stuff) +import com.seibel.lod.api.enums.config.DisallowSelectingViaConfigGui; import com.seibel.lod.common.wrappers.gui.updater.ChangelogScreen; import com.seibel.lod.core.config.types.*; @@ -27,10 +28,8 @@ import com.seibel.lod.core.config.*; // Minecraft imports import com.mojang.blaze3d.vertex.PoseStack; -import com.seibel.lod.core.dependencyInjection.SingletonInjector; -import com.seibel.lod.core.jar.installer.ModrinthGetter; import com.seibel.lod.core.jar.updater.SelfUpdater; -import com.seibel.lod.core.wrapperInterfaces.IVersionConstants; +import com.seibel.lod.core.util.AnnotationUtil; import com.seibel.lod.coreapi.ModInfo; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; @@ -52,6 +51,8 @@ import net.minecraft.client.gui.narration.NarratableEntry; import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.resources.ResourceLocation; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; #endif /** @@ -66,11 +67,14 @@ import net.minecraft.resources.ResourceLocation; // FLOATS DONT WORK WITH THIS /** This file is going to be removed sometime soon, please dont hook onto anything within this file until the new UI is compleated */ @SuppressWarnings("unchecked") -public class ClassicConfigGUI { +public class ClassicConfigGUI +{ /* This would be removed later on as it is going to be re-written in java swing */ - + + private static final Logger LOGGER = LogManager.getLogger(); + //==============// // Initializers // @@ -399,10 +403,39 @@ public class ClassicConfigGUI { Function func = value -> Component.translatable(translationPrefix + "enum." + fieldClass.getSimpleName() + "." + info.get().toString()); #endif ((EntryInfo) info.guiValue).widget = new AbstractMap.SimpleEntry>(button -> { - int index = values.indexOf(info.get()) + 1; - info.set(values.get(index >= values.size() ? 0 : index)); - button.setMessage(func.apply(info.get())); - }, func); + + // get the currently selected enum and enum index + int startingIndex = values.indexOf(info.get()); + Enum enumValue = (Enum) values.get(startingIndex); + + // search for the next enum that is selectable + int index = startingIndex+1; + index = (index >= values.size()) ? 0 : index; + while (index != startingIndex) + { + enumValue = (Enum) values.get(index); + if (!AnnotationUtil.doesEnumHaveAnnotation(enumValue, DisallowSelectingViaConfigGui.class)) + { + // this enum shouldn't be selectable via the UI, + // skip it + break; + } + + index++; + index = (index >= values.size()) ? 0 : index; + } + + if (index == startingIndex) + { + // none of the enums should be selectable, this is a programmer error + enumValue = (Enum) values.get(startingIndex); + LOGGER.warn("Enum ["+enumValue.getClass()+"] doesn't contain any values that should be selectable via the UI, sticking to the currently selected value ["+enumValue+"]."); + } + + + info.set(enumValue); + button.setMessage(func.apply(info.get())); + }, func); } } else if (ConfigCategory.class.isAssignableFrom(info.getClass())) { // if (!info.info.getName().equals("")) diff --git a/coreSubProjects b/coreSubProjects index a00671c2e..12d5d9e32 160000 --- a/coreSubProjects +++ b/coreSubProjects @@ -1 +1 @@ -Subproject commit a00671c2e5433a4a9ab39d5e64299b83abf2fe75 +Subproject commit 12d5d9e32bfed8b38443ea33e1b3eb4c3114f405