diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/DependencySetup.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/DependencySetup.java index 9fa88020f..0b8f7791a 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/DependencySetup.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/DependencySetup.java @@ -19,10 +19,12 @@ package com.seibel.distanthorizons.common.wrappers; +import com.seibel.distanthorizons.common.wrappers.gui.ClassicConfigGUI; import com.seibel.distanthorizons.common.wrappers.gui.LangWrapper; import com.seibel.distanthorizons.common.wrappers.level.KeyedClientLevelManager; import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftDedicatedServerWrapper; import com.seibel.distanthorizons.core.level.IKeyedClientLevelManager; +import com.seibel.distanthorizons.core.wrapperInterfaces.config.IConfigGui; import com.seibel.distanthorizons.core.wrapperInterfaces.config.ILangWrapper; import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftClientWrapper; import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftRenderWrapper; @@ -70,6 +72,7 @@ public class DependencySetup SingletonInjector.INSTANCE.bind(IMinecraftSharedWrapper.class, MinecraftClientWrapper.INSTANCE); SingletonInjector.INSTANCE.bind(IMinecraftRenderWrapper.class, MinecraftRenderWrapper.INSTANCE); SingletonInjector.INSTANCE.bind(IReflectionHandler.class, ReflectionHandler.INSTANCE); + SingletonInjector.INSTANCE.bind(IConfigGui.class, ClassicConfigGUI.CONFIG_CORE_INTERFACE); } } diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/ClassicConfigGUI.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/ClassicConfigGUI.java index 770e1a319..fd4057b53 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/ClassicConfigGUI.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/ClassicConfigGUI.java @@ -27,9 +27,10 @@ import com.seibel.distanthorizons.common.wrappers.gui.updater.ChangelogScreen; // Minecraft imports -import com.mojang.blaze3d.vertex.PoseStack; +import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector; import com.seibel.distanthorizons.core.jar.updater.SelfUpdater; import com.seibel.distanthorizons.core.util.AnnotationUtil; +import com.seibel.distanthorizons.core.wrapperInterfaces.config.IConfigGui; import com.seibel.distanthorizons.coreapi.ModInfo; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; @@ -79,6 +80,9 @@ public class ClassicConfigGUI private static final Logger LOGGER = LogManager.getLogger(); + public static final ConfigCoreInterface CONFIG_CORE_INTERFACE = new ConfigCoreInterface(); + + //==============// // Initializers // @@ -225,7 +229,9 @@ public class ClassicConfigGUI public void onClose() { ConfigBase.INSTANCE.configFileINSTANCE.saveToFile(); - Objects.requireNonNull(minecraft).setScreen(this.parent); + Objects.requireNonNull(this.minecraft).setScreen(this.parent); + + CONFIG_CORE_INTERFACE.onScreenChangeListenerList.forEach((listener) -> listener.run()); } @Override @@ -233,7 +239,9 @@ public class ClassicConfigGUI { super.init(); if (!reload) + { ConfigBase.INSTANCE.configFileINSTANCE.loadFromFile(); + } // Changelog button if (Config.Client.Advanced.AutoUpdater.enableAutoUpdater.get()) @@ -285,6 +293,11 @@ public class ClassicConfigGUI e.printStackTrace(); } } + + + + CONFIG_CORE_INTERFACE.onScreenChangeListenerList.forEach((listener) -> listener.run()); + } private void addMenuItem(AbstractConfigType info) @@ -611,4 +624,29 @@ public class ClassicConfigGUI #endif } + + + + + //================// + // event handling // + //================// + + private static class ConfigCoreInterface implements IConfigGui + { + /** + * in the future it would be good to pass in the current page and other variables, + * but for now just knowing when the page is closed is good enough + */ + public final ArrayList onScreenChangeListenerList = new ArrayList<>(); + + + + @Override + public void addOnScreenChangeListener(Runnable newListener) { this.onScreenChangeListenerList.add(newListener); } + @Override + public void removeOnScreenChangeListener(Runnable oldListener) { this.onScreenChangeListenerList.remove(oldListener); } + + } + } diff --git a/coreSubProjects b/coreSubProjects index c80136719..c7ac9facc 160000 --- a/coreSubProjects +++ b/coreSubProjects @@ -1 +1 @@ -Subproject commit c80136719dfbf227a5de5343ab322a9a431dfd59 +Subproject commit c7ac9faccd4a68de38919fff2aab5ac9bda580e9