From 4e973099f93c29203450c1f6dd37df1a4b44d499 Mon Sep 17 00:00:00 2001 From: coolGi2007 Date: Fri, 17 Dec 2021 08:29:14 +0000 Subject: [PATCH] Updated my config --- .../lod/common/wrappers/config/ConfigGui.java | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/config/ConfigGui.java b/common/src/main/java/com/seibel/lod/common/wrappers/config/ConfigGui.java index f29a163a0..115d57f30 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/config/ConfigGui.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/config/ConfigGui.java @@ -30,6 +30,7 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.lang.reflect.Field; import java.lang.reflect.Modifier; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.*; @@ -111,11 +112,19 @@ public abstract class ConfigGui { Make wiki better Add a way to add min and max from another variable */ + /* + List of hacky things that are done that should be done properly + + The buttons that dont show are still loded but just not rendered + The screen with is set to double so the scroll bar dosnt show + */ private static final Pattern INTEGER_ONLY = Pattern.compile("(-?[0-9]*)"); private static final Pattern DECIMAL_ONLY = Pattern.compile("-?([\\d]+\\.?[\\d]*|[\\d]*\\.?[\\d]+|\\.)"); private static final List entries = new ArrayList<>(); + private static TomlWriter tomlWriter = new TomlWriter(); + private static class ConfigScreenConfigs { // This contains all the configs for the configs public static final int SpaceFromRightScreen = 10; @@ -136,13 +145,14 @@ public abstract class ConfigGui { String id; // ModID TranslatableComponent name; int index; + boolean hideOption = false; // Hides the button boolean button = false; // This asks if it is a button to goto a new screen String gotoScreen = ""; // This is only called if button is true String category; } public static final Map> configClass = new HashMap<>(); - // public static List nestedClasses = new ArrayList<>(); +// public static List nestedClasses = new ArrayList<>(); private static Path path; public static void init(String modid, Class config) { @@ -170,7 +180,6 @@ public abstract class ConfigGui { private static void initClass(String modid, Class config, String category) { String e = modid + (category != "" ? "." + category : ""); configClass.put(e, config); -// nestedClasses.add(e); for (Field field : config.getFields()) { EntryInfo info = new EntryInfo(); if (field.isAnnotationPresent(Entry.class) || field.isAnnotationPresent(Comment.class) || field.isAnnotationPresent(ScreenEntry.class)) @@ -277,8 +286,7 @@ public abstract class ConfigGui { try { if (!Files.exists(path)) Files.createFile(path); - - new TomlWriter().write(configClass.get(modid).getDeclaredConstructor().newInstance(), path.toFile()); + tomlWriter.write(configClass.get(modid).getDeclaredConstructor().newInstance()); } catch (Exception e) { e.printStackTrace(); } @@ -311,14 +319,11 @@ public abstract class ConfigGui { } } private void loadValues() { -// for (int i = 0; i < nestedClasses.size(); i++) { try { -// new Toml().read(Files.newBufferedReader(path)).to(configClass.get(nestedClasses.get(i))); new Toml().read(Files.newBufferedReader(path)).to(configClass.get(modid)); } catch (Exception e) { write(modid); } -// } for (EntryInfo info : entries) { if (info.field.isAnnotationPresent(Entry.class)) @@ -349,20 +354,19 @@ public abstract class ConfigGui { Objects.requireNonNull(minecraft).setScreen(parent); })); - this.list = new ConfigListWidget(this.minecraft, this.width, this.height, 32, this.height - 32, 25); + this.list = new ConfigListWidget(this.minecraft, this.width*2, this.height, 32, this.height - 32, 25); if (this.minecraft != null && this.minecraft.level != null) this.list.setRenderBackground(false); this.addWidget(this.list); for (EntryInfo info : entries) { - if (info.id.equals(modid) && info.category.matches(category)) { + if (info.id.equals(modid) && info.category.matches(category) && !info.hideOption) { +// if (info.id.equals(modid) && !info.hideOption) { TranslatableComponent name = Objects.requireNonNullElseGet(info.name, () -> new TranslatableComponent(translationPrefix + (info.category != "" ? info.category + "." : "") + info.field.getName())); Button resetButton = new Button(this.width - ConfigScreenConfigs.SpaceFromRightScreen - info.width - ConfigScreenConfigs.ButtonWidthSpacing - ConfigScreenConfigs.ResetButtonWidth, 0, ConfigScreenConfigs.ResetButtonWidth, 20, new TextComponent("Reset").withStyle(ChatFormatting.RED), (button -> { info.value = info.defaultValue; info.tempValue = info.defaultValue.toString(); info.index = 0; - double scrollAmount = list.getScrollAmount(); this.reload = true; Objects.requireNonNull(minecraft).setScreen(this); - list.setScrollAmount(scrollAmount); })); if (info.widget instanceof Map.Entry) { @@ -372,7 +376,7 @@ public abstract class ConfigGui { this.list.addButton(new Button(this.width - info.width - ConfigScreenConfigs.SpaceFromRightScreen, 0, info.width, 20, widget.getValue().apply(info.value), widget.getKey()), resetButton, null, name); } else if (info.field.getType() == List.class) { if (!reload) info.index = 0; - EditBox widget = new EditBox(font, this.width - info.width - ConfigScreenConfigs.SpaceFromRightScreen, 0, info.width, 20, null); + EditBox widget = new EditBox(font, this.width- info.width - ConfigScreenConfigs.SpaceFromRightScreen, 0, info.width, 20, null); widget.setMaxLength(info.width); if (info.index < ((List) info.value).size()) widget.insertText((String.valueOf(((List) info.value).get(info.index)))); @@ -383,12 +387,10 @@ public abstract class ConfigGui { resetButton.setMessage(new TextComponent("R").withStyle(ChatFormatting.RED)); Button cycleButton = new Button(this.width - 185, 0, 20, 20, new TextComponent(String.valueOf(info.index)).withStyle(ChatFormatting.GOLD), (button -> { ((List) info.value).remove(""); - double scrollAmount = list.getScrollAmount(); this.reload = true; info.index = info.index + 1; if (info.index > ((List) info.value).size()) info.index = 0; Objects.requireNonNull(minecraft).setScreen(this); - list.setScrollAmount(scrollAmount); })); this.list.addButton(widget, resetButton, cycleButton, name); } else if (info.widget != null) { @@ -450,8 +452,6 @@ public abstract class ConfigGui { this.centerListVertically = false; textRenderer = minecraftClient.font; } - // @Override - public int getScrollbarPositionX() { return this.width -7; } public void addButton(AbstractWidget button, AbstractWidget resetButton, AbstractWidget indexButton, Component text) { this.addEntry(ButtonEntry.create(button, text, resetButton, indexButton));