From 05b6e7448279850047617e4e54faeb0fd558721c Mon Sep 17 00:00:00 2001 From: coolGi Date: Tue, 6 Jun 2023 18:01:49 +0930 Subject: [PATCH] Fixed and checked support for all available config types --- .../common/wrappers/gui/ClassicConfigGUI.java | 87 +++++++++++-------- 1 file changed, 49 insertions(+), 38 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 e68ad8ecf..76c3fe769 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 @@ -29,6 +29,7 @@ import com.seibel.lod.core.config.*; // Minecraft imports import com.mojang.blaze3d.vertex.PoseStack; +import com.seibel.lod.core.config.types.ConfigUIComment; import com.seibel.lod.core.dependencyInjection.SingletonInjector; import com.seibel.lod.core.jar.installer.ModrinthGetter; import com.seibel.lod.core.jar.updater.SelfUpdater; @@ -66,8 +67,9 @@ import net.minecraft.resources.ResourceLocation; * @version 5-21-2022 */ // 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 abstract class ClassicConfigGUI { +public class ClassicConfigGUI { /* This would be removed later on as it is going to be re-written in java swing */ @@ -253,49 +255,58 @@ public abstract class ClassicConfigGUI { this.list.setRenderBackground(false); this.addWidget(this.list); for (AbstractConfigType info : ConfigBase.INSTANCE.entries) { - if (info.getCategory().matches(category) && info.getAppearance().showInGui) { - initEntry(info, this.translationPrefix); - #if PRE_MC_1_19 - TranslatableComponent name = new TranslatableComponent(translationPrefix + info.getNameWCategory()); - #else - Component name = Component.translatable(translationPrefix + info.getNameWCategory()); - #endif - if (ConfigEntry.class.isAssignableFrom(info.getClass())) { + try { + if (info.getCategory().matches(category) && info.getAppearance().showInGui) { + initEntry(info, this.translationPrefix); #if PRE_MC_1_19 - Button resetButton = new Button(this.width - ConfigScreenConfigs.SpaceFromRightScreen - 150 - ConfigScreenConfigs.ButtonWidthSpacing - ConfigScreenConfigs.ResetButtonWidth, 0, ConfigScreenConfigs.ResetButtonWidth, 20, new TextComponent("Reset").withStyle(ChatFormatting.RED), (button -> { + TranslatableComponent name = new TranslatableComponent(translationPrefix + info.getNameWCategory()); #else - Button resetButton = new Button(this.width - ConfigScreenConfigs.SpaceFromRightScreen - 150 - ConfigScreenConfigs.ButtonWidthSpacing - ConfigScreenConfigs.ResetButtonWidth, 0, ConfigScreenConfigs.ResetButtonWidth, 20, Component.translatable("Reset").withStyle(ChatFormatting.RED), (button -> { + Component name = Component.translatable(translationPrefix + info.getNameWCategory()); #endif - ((ConfigEntry) info).setWithoutSaving(((ConfigEntry) info).getDefaultValue()); - ((EntryInfo) info.guiValue).index = 0; - this.reload = true; - Objects.requireNonNull(minecraft).setScreen(this); - })); + if (ConfigEntry.class.isAssignableFrom(info.getClass())) { + #if PRE_MC_1_19 + Button resetButton = new Button(this.width - ConfigScreenConfigs.SpaceFromRightScreen - 150 - ConfigScreenConfigs.ButtonWidthSpacing - ConfigScreenConfigs.ResetButtonWidth, 0, ConfigScreenConfigs.ResetButtonWidth, 20, new TextComponent("Reset").withStyle(ChatFormatting.RED), (button -> { + #else + Button resetButton = new Button(this.width - ConfigScreenConfigs.SpaceFromRightScreen - 150 - ConfigScreenConfigs.ButtonWidthSpacing - ConfigScreenConfigs.ResetButtonWidth, 0, ConfigScreenConfigs.ResetButtonWidth, 20, Component.translatable("Reset").withStyle(ChatFormatting.RED), (button -> { + #endif + ((ConfigEntry) info).setWithoutSaving(((ConfigEntry) info).getDefaultValue()); + ((EntryInfo) info.guiValue).index = 0; + this.reload = true; + Objects.requireNonNull(minecraft).setScreen(this); + })); - if (((EntryInfo) info.guiValue).widget instanceof Map.Entry) { - Map.Entry> widget = (Map.Entry>) ((EntryInfo) info.guiValue).widget; - if (info.getType().isEnum()) - #if PRE_MC_1_19 - widget.setValue(value -> new TranslatableComponent(translationPrefix + "enum." + info.getType().getSimpleName() + "." + info.get().toString())); - #else - widget.setValue(value -> Component.translatable(translationPrefix + "enum." + info.getType().getSimpleName() + "." + info.get().toString())); - #endif - this.list.addButton(new Button(this.width - 150 - ConfigScreenConfigs.SpaceFromRightScreen, 0, 150, 20, widget.getValue().apply(info.get()), widget.getKey()), resetButton, null, name); - } else if (((EntryInfo) info.guiValue).widget != null) { - EditBox widget = new EditBox(font, this.width - 150 - ConfigScreenConfigs.SpaceFromRightScreen + 2, 0, 150 - 4, 20, null); - widget.setMaxLength(150); - widget.insertText(String.valueOf(info.get())); - Predicate processor = ((BiFunction>) ((EntryInfo) info.guiValue).widget).apply(widget, done); - widget.setFilter(processor); - this.list.addButton(widget, resetButton, null, name); + if (((EntryInfo) info.guiValue).widget instanceof Map.Entry) { + Map.Entry> widget = (Map.Entry>) ((EntryInfo) info.guiValue).widget; + if (info.getType().isEnum()) + #if PRE_MC_1_19 + widget.setValue(value -> new TranslatableComponent(translationPrefix + "enum." + info.getType().getSimpleName() + "." + info.get().toString())); + #else + widget.setValue(value -> Component.translatable(translationPrefix + "enum." + info.getType().getSimpleName() + "." + info.get().toString())); + #endif + this.list.addButton(new Button(this.width - 150 - ConfigScreenConfigs.SpaceFromRightScreen, 0, 150, 20, widget.getValue().apply(info.get()), widget.getKey()), resetButton, null, name); + } else if (((EntryInfo) info.guiValue).widget != null) { + EditBox widget = new EditBox(font, this.width - 150 - ConfigScreenConfigs.SpaceFromRightScreen + 2, 0, 150 - 4, 20, null); + widget.setMaxLength(150); + widget.insertText(String.valueOf(info.get())); + Predicate processor = ((BiFunction>) ((EntryInfo) info.guiValue).widget).apply(widget, done); + widget.setFilter(processor); + this.list.addButton(widget, resetButton, null, name); + } + } else if (ConfigCategory.class.isAssignableFrom(info.getClass())) { + Button widget = new Button(this.width / 2 - 100, this.height - 28, 100 * 2, 20, name, (button -> { + ConfigBase.INSTANCE.configFileINSTANCE.saveToFile(); + Objects.requireNonNull(minecraft).setScreen(ClassicConfigGUI.getScreen(this.configBase, this, ((ConfigCategory) info).getDestination())); + })); + this.list.addButton(widget, null, null, null); + } else if (ConfigUIComment.class.isAssignableFrom(info.getClass())) { + this.list.addButton(null, null, null, name); } - } else if (ConfigCategory.class.isAssignableFrom(info.getClass())) { - Button widget = new Button(this.width / 2 - 100, this.height - 28, 100 * 2, 20, name, (button -> { - ConfigBase.INSTANCE.configFileINSTANCE.saveToFile(); - Objects.requireNonNull(minecraft).setScreen(ClassicConfigGUI.getScreen(this.configBase, this, ((ConfigCategory) info).getDestination())); - })); - this.list.addButton(widget, null, null, null); } + } catch (Exception e) { + System.out.println("ERROR: Failed to show ["+info.getNameWCategory()+"]"); + if (info.get() != null) + System.out.print(" with the value ["+info.get()+"] with type ["+info.getType()+"]"); + e.printStackTrace(); } } }