Implement the Quick enable render toggle

Also improve the logic for setting UI only config values
This commit is contained in:
James Seibel
2023-06-12 22:18:52 -05:00
parent 12d5d9e32b
commit 24a335565e
4 changed files with 54 additions and 16 deletions
@@ -36,10 +36,15 @@ import java.util.*;
/**
* This handles any configuration the user has access to.
* This handles any configuration the user has access to. <br><br>
*
* Note: <br>
* Only add simpler listeners here (IE listeners that only depend on 1 config entry).
* For listeners that depend on 2 or more config entries, add them before the config menu is opened.
* Otherwise, you will have issues where only some of the config entries will exist when your listener is created.
*
* @author coolGi
* @version 2023-6-7
* @version 2023-6-12
*/
public class Config
@@ -68,14 +73,12 @@ public class Config
public static class Client
{
// TODO modify debugging.rendererMode
public static ConfigEntry<Boolean> quickEnableRendering = new ConfigEntry.Builder<Boolean>()
.set(true)
.comment(""
+ "If true, Distant Horizons will render LODs beyond the vanilla render distance."
+ "")
.setAppearance(EConfigEntryAppearance.ONLY_IN_GUI) // TODO set when the game boots
//.addListener(null) // TODO add listener
.setAppearance(EConfigEntryAppearance.ONLY_IN_GUI)
.build();
public static ConfigLinkedEntry quickLodChunkRenderDistance = new ConfigLinkedEntry(Advanced.Graphics.Quality.lodChunkRenderDistance);
@@ -1077,10 +1080,11 @@ public class Config
{
public static ConfigUIComment resetConfirmationNote = new ConfigUIComment();
// TODO implement
public static ConfigEntry<Boolean> resetAllSettings = new ConfigEntry.Builder<Boolean>()
.set(false)
.setAppearance(EConfigEntryAppearance.ONLY_IN_GUI)
//.addListener(null) // TODO add listener
//.addListener(null)
.build();
}
@@ -0,0 +1,32 @@
package com.seibel.lod.core.config.eventHandlers;
import com.seibel.lod.api.enums.rendering.ERendererMode;
import com.seibel.lod.core.config.Config;
import com.seibel.lod.core.config.listeners.ConfigChangeListener;
public class QuickRenderToggleConfigEventHandler
{
public static QuickRenderToggleConfigEventHandler INSTANCE = new QuickRenderToggleConfigEventHandler();
private final ConfigChangeListener<Boolean> quickRenderChangeListener;
private final ConfigChangeListener<ERendererMode> rendererModeChangeListener;
/** private since we only ever need one handler at a time */
private QuickRenderToggleConfigEventHandler()
{
this.quickRenderChangeListener = new ConfigChangeListener<>(Config.Client.quickEnableRendering, (val) -> { Config.Client.Advanced.Debugging.rendererMode.set(Config.Client.quickEnableRendering.get() ? ERendererMode.DEFAULT : ERendererMode.DISABLED); });
this.rendererModeChangeListener = new ConfigChangeListener<>(Config.Client.Advanced.Debugging.rendererMode, (val) -> { Config.Client.quickEnableRendering.set(Config.Client.Advanced.Debugging.rendererMode.get() != ERendererMode.DISABLED); });
}
/**
* Set the UI only config based on what is set in the file. <br>
* This should only be called once.
*/
public void setUiOnlyConfigValues()
{
Config.Client.quickEnableRendering.set(Config.Client.Advanced.Debugging.rendererMode.get() != ERendererMode.DISABLED);
}
}
@@ -20,6 +20,17 @@ public abstract class AbstractPresetConfigEventHandler<TPresetEnum extends Enum<
/**
* Set the UI only config based on what is set in the file. <br>
* This should only be called once.
*/
public void setUiOnlyConfigValues()
{
TPresetEnum currentQualitySetting = this.getCurrentQualityPreset();
this.getPresetConfigEntry().set(currentQualitySetting);
}
//===========//
// listeners //
//===========//
@@ -28,15 +39,6 @@ public abstract class AbstractPresetConfigEventHandler<TPresetEnum extends Enum<
public void onConfigValueSet()
{
TPresetEnum qualityPreset = this.getPresetConfigEntry().get();
if (qualityPreset == null)
{
// the value will be null when the config menu is first opened,
// set the value to what it should be.
TPresetEnum currentQualitySetting = this.getCurrentQualityPreset();
this.getPresetConfigEntry().set(currentQualitySetting);
return;
}
// if the quick value is custom, nothing needs to be changed
if (qualityPreset == this.getCustomPresetEnum())
@@ -273,7 +273,7 @@ public class ConfigEntry<T> extends AbstractConfigType<T, ConfigEntry<T>> implem
public ConfigEntry<T> build()
{
return new ConfigEntry<T>(tmpAppearance, tmpValue, tmpComment, tmpMin, tmpMax, tmpUseApiOverwrite, tmpPerformance, tmpIConfigListener);
return new ConfigEntry<>(this.tmpAppearance, this.tmpValue, this.tmpComment, this.tmpMin, this.tmpMax, this.tmpUseApiOverwrite, this.tmpPerformance, this.tmpIConfigListener);
}
}