Fix preset configs not applying after the UI screen changes

This commit is contained in:
James Seibel
2023-08-18 07:51:15 -05:00
parent 9a9aac64af
commit e43ee68508
3 changed files with 44 additions and 3 deletions
@@ -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);
}
}
@@ -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<Runnable> onScreenChangeListenerList = new ArrayList<>();
@Override
public void addOnScreenChangeListener(Runnable newListener) { this.onScreenChangeListenerList.add(newListener); }
@Override
public void removeOnScreenChangeListener(Runnable oldListener) { this.onScreenChangeListenerList.remove(oldListener); }
}
}