Fixed ui modify, and made file handeler use its own set function
This commit is contained in:
-3
@@ -122,9 +122,6 @@ public abstract class AbstractPresetConfigEventHandler<TPresetEnum extends Enum<
|
||||
LOGGER.info("preset active: " + newPresetEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUiModify() { /* do nothing, we only care about modified config values */ }
|
||||
|
||||
/**
|
||||
* listen for changed graphics settings and set the
|
||||
* quick quality to "custom" if anything was changed
|
||||
|
||||
+6
-14
@@ -175,19 +175,19 @@ public class ConfigFileHandling
|
||||
{
|
||||
if (entry.getType().isEnum())
|
||||
{
|
||||
entry.setWithoutSaving((T) (workConfig.getEnum(entry.getNameWCategory(), (Class<? extends Enum>) entry.getType())));
|
||||
entry.pureSet((T) (workConfig.getEnum(entry.getNameWCategory(), (Class<? extends Enum>) entry.getType())));
|
||||
return;
|
||||
}
|
||||
Class<?> originalClass = ConfigTypeConverters.isClassConvertable(entry.getType());
|
||||
if (originalClass != null)
|
||||
{
|
||||
entry.setWithoutSaving((T) ConfigTypeConverters.convertFromString(originalClass, workConfig.get(entry.getNameWCategory())));
|
||||
entry.pureSet((T) ConfigTypeConverters.convertFromString(originalClass, workConfig.get(entry.getNameWCategory())));
|
||||
return;
|
||||
}
|
||||
|
||||
if (entry.getType() == workConfig.get(entry.getNameWCategory()).getClass())
|
||||
{ // If the types are the same
|
||||
entry.setWithoutSaving((T) workConfig.get(entry.getNameWCategory()));
|
||||
entry.pureSet((T) workConfig.get(entry.getNameWCategory()));
|
||||
entry.clampWithinRange();
|
||||
return;
|
||||
}
|
||||
@@ -247,19 +247,11 @@ public class ConfigFileHandling
|
||||
Files.createDirectory(this.configPath.getParent());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
boolean fileDeleted = Files.deleteIfExists(this.configPath);
|
||||
System.out.println("File at [" + this.configPath + "] was " + (fileDeleted ? "" : "not ") + "able to be deleted.");
|
||||
}
|
||||
catch (AccessDeniedException ignored) { /* temporary fix due to windows/Intellij issues either locking or changing the permissions of the file */ }
|
||||
boolean fileDeleted = Files.deleteIfExists(this.configPath);
|
||||
System.out.println("File at [" + this.configPath + "] was " + (fileDeleted ? "" : "not ") + "able to be deleted.");
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
Files.createFile(this.configPath);
|
||||
}
|
||||
catch (FileAlreadyExistsException ignore) { /* temporary fix due to windows/Intellij issues either locking or changing the permissions of the file */ }
|
||||
Files.createFile(this.configPath);
|
||||
|
||||
config.load();
|
||||
}
|
||||
|
||||
+3
-6
@@ -3,12 +3,9 @@ package com.seibel.distanthorizons.core.config.listeners;
|
||||
public interface IConfigListener
|
||||
{
|
||||
/** Called whenever the value is set (including in core DH code) */
|
||||
void onConfigValueSet();
|
||||
default void onConfigValueSet() {};
|
||||
|
||||
/**
|
||||
* TODO not implemented
|
||||
* Called whenever the value is changed through the UI (only when the done button is pressed)
|
||||
*/
|
||||
void onUiModify();
|
||||
/** Called whenever the value is changed through the UI */
|
||||
default void onUiModify() {};
|
||||
|
||||
}
|
||||
|
||||
@@ -66,18 +66,42 @@ public class ConfigEntry<T> extends AbstractConfigType<T, ConfigEntry<T>> implem
|
||||
public T getApiValue() { return this.apiValue; }
|
||||
@Override
|
||||
public boolean getAllowApiOverride() { return this.allowApiOverride; }
|
||||
|
||||
/**
|
||||
* DONT USE THIS IN YOUR CODE <br>
|
||||
* Sets the value without informing the rest of the code (ie, doesnt call listeners, or saves the value). <br>
|
||||
* Should only be used when loading the config from the file
|
||||
*/
|
||||
public void pureSet(T newValue) {
|
||||
super.set(newValue);
|
||||
}
|
||||
|
||||
/** Sets the value without saving */
|
||||
@Override
|
||||
public void setWithoutSaving(T newValue)
|
||||
{
|
||||
super.set(newValue);
|
||||
this.listenerList.forEach(IConfigListener::onConfigValueSet);
|
||||
}
|
||||
@Override
|
||||
public void set(T newValue)
|
||||
{
|
||||
super.set(newValue);
|
||||
this.setWithoutSaving(newValue);
|
||||
this.save();
|
||||
this.listenerList.forEach(IConfigListener::onConfigValueSet);
|
||||
}
|
||||
|
||||
public void uiSetWithoutSaving(T newValue)
|
||||
{
|
||||
this.setWithoutSaving(newValue);
|
||||
this.listenerList.forEach(IConfigListener::onUiModify);
|
||||
}
|
||||
public void uiSet(T newValue)
|
||||
{
|
||||
this.set(newValue);
|
||||
this.listenerList.forEach(IConfigListener::onUiModify);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public T get()
|
||||
{
|
||||
@@ -94,13 +118,6 @@ public class ConfigEntry<T> extends AbstractConfigType<T, ConfigEntry<T>> implem
|
||||
return super.get();
|
||||
}
|
||||
|
||||
/** Sets the value without saving */
|
||||
@Override
|
||||
public void setWithoutSaving(T newValue)
|
||||
{
|
||||
super.set(newValue);
|
||||
this.listenerList.forEach(IConfigListener::onConfigValueSet);
|
||||
}
|
||||
|
||||
/** Gets the min value */
|
||||
@Override
|
||||
@@ -301,7 +318,9 @@ public class ConfigEntry<T> extends AbstractConfigType<T, ConfigEntry<T>> implem
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<T> replaceListener(ArrayList<IConfigListener> newConfigListener)
|
||||
|
||||
|
||||
public Builder<T> replaceListeners(ArrayList<IConfigListener> newConfigListener)
|
||||
{
|
||||
this.tmpIConfigListener = newConfigListener;
|
||||
return this;
|
||||
|
||||
Reference in New Issue
Block a user