Improve config gui object casting

This commit is contained in:
James Seibel
2025-10-13 07:33:27 -05:00
parent 656971b0b9
commit 8f0217185f
5 changed files with 21 additions and 7 deletions
@@ -39,8 +39,7 @@ public abstract class AbstractPresetConfigEventHandler<TPresetEnum extends Enum<
private static final long MS_DELAY_BEFORE_APPLYING_PRESET = 3_000;
@Nullable
private static IConfigGui configGui = SingletonInjector.INSTANCE.get(IConfigGui.class);
private static boolean guiListenersAdded = false;
private static final IConfigGui CONFIG_GUI = SingletonInjector.INSTANCE.get(IConfigGui.class);
protected final ArrayList<ConfigPresetOptions<TPresetEnum, ?>> configList = new ArrayList<>();
/** this timer is used so each preset isn't applied while a user is clicking through the config options */
@@ -59,9 +58,9 @@ public abstract class AbstractPresetConfigEventHandler<TPresetEnum extends Enum<
public AbstractPresetConfigEventHandler()
{
// don't update the UI when running on a server
if (configGui != null)
if (CONFIG_GUI != null)
{
configGui.addOnScreenChangeListener(this::onConfigUiClosed);
CONFIG_GUI.addOnScreenChangeListener(this::onConfigUiClosed);
}
}
@@ -0,0 +1,10 @@
package com.seibel.distanthorizons.core.config.gui;
/**
* Points to a Common object that holds the GUI state.
* Having this interface allows for cleaner casting.
*/
public interface IConfigGuiInfo
{
}
@@ -19,6 +19,7 @@
package com.seibel.distanthorizons.core.config.types;
import com.seibel.distanthorizons.core.config.gui.IConfigGuiInfo;
import com.seibel.distanthorizons.core.config.types.enums.EConfigEntryAppearance;
/**
@@ -34,8 +35,11 @@ public abstract class AbstractConfigBase<T>
protected final boolean isFloatingPointNumber;
protected T value;
@Deprecated
public Object guiValue; // This is a storage variable something like the gui can use
/**
* This stores information related to the GUI state.
* This is set during config UI setup.
*/
public IConfigGuiInfo guiValue;
protected EConfigEntryAppearance appearance;
@@ -223,7 +223,7 @@ public class ConfigEntry<T> extends AbstractConfigBase<T>
/** Checks if the given value is valid */
public EConfigValidity getValidity(@Nullable T value, @Nullable T min, @Nullable T max)
{
if (ConfigHandler.INSTANCE.runMinMaxValidation)
if (!ConfigHandler.INSTANCE.runMinMaxValidation)
{
return EConfigValidity.VALID;
}
@@ -21,6 +21,7 @@ package com.seibel.distanthorizons.core.wrapperInterfaces.config;
import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindable;
/** handles communication between DH Core and the currently active config screen */
public interface IConfigGui extends IBindable
{