aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/Config.java24
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java16
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/elements/OptionCategory.java8
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/elements/OptionPage.java7
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java7
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java12
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java1
7 files changed, 57 insertions, 18 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/Config.java b/src/main/java/cc/polyfrost/oneconfig/config/Config.java
index 9557728..3ca029e 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/Config.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/Config.java
@@ -38,6 +38,7 @@ public class Config {
transient protected final String configFile;
transient protected final Gson gson = new GsonBuilder().setExclusionStrategies(new ProfileExclusionStrategy()).excludeFieldsWithModifiers(Modifier.TRANSIENT).setPrettyPrinting().create();
transient protected final Gson nonProfileSpecificGson = new GsonBuilder().setExclusionStrategies(new NonProfileSpecificExclusionStrategy()).excludeFieldsWithModifiers(Modifier.TRANSIENT).setPrettyPrinting().create();
+ transient protected final HashMap<Field, Object> defaults = new HashMap<>();
transient public Mod mod;
public transient boolean hasBeenInitialized = false;
public boolean enabled;
@@ -45,7 +46,7 @@ public class Config {
/**
* @param modData information about the mod
* @param configFile file where config is stored
- * @param enabled whether the mod is enabled or not
+ * @param enabled whether the mod is enabled or not
*/
public Config(Mod modData, String configFile, boolean enabled) {
this.configFile = configFile;
@@ -306,18 +307,19 @@ public class Config {
}
/**
+ * @param field The field to get the default value from
+ * @return The default value of the given field
+ */
+ public Object getDefault(Field field) {
+ return defaults.get(field);
+ }
+
+ /**
* Reset this config file to its defaults.
- * @return true if successful, false if not.
- * @deprecated <b>not implemented yet.</b>
*/
- @Deprecated
- public boolean reset() {
- try {
- // TODO
- } catch (Exception e) {
- e.printStackTrace();
- return false;
+ public void reset() {
+ for (BasicOption option : optionNames.values()) {
+ option.reset(this);
}
- return true;
}
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java b/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java
index 86b339b..6f9b47a 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java
@@ -1,5 +1,7 @@
package cc.polyfrost.oneconfig.config.elements;
+import cc.polyfrost.oneconfig.config.Config;
+
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.function.Supplier;
@@ -86,6 +88,20 @@ public abstract class BasicOption {
}
/**
+ * Reset the field to its default value
+ *
+ * @param config The config the field is in
+ */
+ public void reset(Config config) {
+ Object object = config.getDefault(field);
+ if (object == null) return;
+ try {
+ set(object);
+ } catch (IllegalAccessException ignored) {
+ }
+ }
+
+ /**
* @return If the option is enabled, based on the dependencies
*/
public boolean isEnabled() {
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionCategory.java b/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionCategory.java
index 4a37bfc..f144f60 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionCategory.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionCategory.java
@@ -1,7 +1,15 @@
package cc.polyfrost.oneconfig.config.elements;
+import cc.polyfrost.oneconfig.config.Config;
+
import java.util.ArrayList;
public class OptionCategory {
public final ArrayList<OptionSubcategory> subcategories = new ArrayList<>();
+
+ public void reset(Config config) {
+ for (OptionSubcategory subcategory : subcategories) {
+ subcategory.reset(config);
+ }
+ }
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionPage.java b/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionPage.java
index 5eaac8b..916e1d9 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionPage.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionPage.java
@@ -1,5 +1,6 @@
package cc.polyfrost.oneconfig.config.elements;
+import cc.polyfrost.oneconfig.config.Config;
import cc.polyfrost.oneconfig.config.data.Mod;
import java.util.LinkedHashMap;
@@ -13,4 +14,10 @@ public class OptionPage {
this.name = name;
this.mod = mod;
}
+
+ public void reset(Config config) {
+ for (OptionCategory subcategory : categories.values()) {
+ subcategory.reset(config);
+ }
+ }
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java b/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java
index 365ddb6..e1342d4 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java
@@ -1,5 +1,6 @@
package cc.polyfrost.oneconfig.config.elements;
+import cc.polyfrost.oneconfig.config.Config;
import cc.polyfrost.oneconfig.internal.assets.Colors;
import cc.polyfrost.oneconfig.gui.OneConfigGui;
import cc.polyfrost.oneconfig.gui.elements.config.ConfigPageButton;
@@ -104,4 +105,10 @@ public class OptionSubcategory {
public String getName() {
return name;
}
+
+ public void reset(Config config) {
+ for (BasicOption option : options) {
+ options.remove(config);
+ }
+ }
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java
index 1095ae0..41d0b4f 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java
@@ -109,7 +109,8 @@ public class OneConfigGui extends UScreen implements GuiPause {
RenderManager.setAlpha(vg, 0.5f);
} else {
backArrow.disable(false);
- if (!backArrow.isHovered() || Platform.getMousePlatform().isButtonDown(0)) RenderManager.setAlpha(vg, 0.8f);
+ if (!backArrow.isHovered() || Platform.getMousePlatform().isButtonDown(0))
+ RenderManager.setAlpha(vg, 0.8f);
}
RenderManager.drawSvg(vg, SVGs.CARET_LEFT, x + 246, y + 22, 28, 28);
RenderManager.setAlpha(vg, 1f);
@@ -118,7 +119,8 @@ public class OneConfigGui extends UScreen implements GuiPause {
RenderManager.setAlpha(vg, 0.5f);
} else {
forwardArrow.disable(false);
- if (!forwardArrow.isHovered() || Platform.getMousePlatform().isButtonDown(0)) RenderManager.setAlpha(vg, 0.8f);
+ if (!forwardArrow.isHovered() || Platform.getMousePlatform().isButtonDown(0))
+ RenderManager.setAlpha(vg, 0.8f);
}
RenderManager.drawSvg(vg, SVGs.CARET_RIGHT, x + 294, y + 22, 28, 28);
RenderManager.setAlpha(vg, 1f);
@@ -140,7 +142,7 @@ public class OneConfigGui extends UScreen implements GuiPause {
}
ScissorManager.scissor(vg, x + 224, y + 72, 1056, 728);
- Scissor blockedClicks = InputUtils.blockInputArea(x + 224, y, 1056,72);
+ Scissor blockedClicks = InputUtils.blockInputArea(x + 224, y, 1056, 72);
if (prevPage != null && animation != null) {
float pageProgress = animation.get(GuiUtils.getDeltaTime());
if (!animation.isReversed()) {
@@ -188,9 +190,7 @@ public class OneConfigGui extends UScreen implements GuiPause {
public void onKeyPressed(int keyCode, char typedChar, @Nullable UKeyboard.Modifiers modifiers) {
UKeyboard.allowRepeatEvents(true);
try {
- if (keyCode == 1 && currentPage.parents.size() > 1) {
- openPage(currentPage.parents.get(currentPage.parents.size() - 2));
- } else if (allowClose) super.onKeyPressed(keyCode, typedChar, modifiers);
+ if (allowClose) super.onKeyPressed(keyCode, typedChar, modifiers);
textInputField.keyTyped(typedChar, keyCode);
if (currentColorSelector != null) currentColorSelector.keyTyped(typedChar, keyCode);
currentPage.keyTyped(typedChar, keyCode);
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java
index ab796c7..c5724e5 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java
@@ -40,7 +40,6 @@ public class ConfigCore {
}
public static void sortMods() {
-
ArrayList<Mod> mods = new ArrayList<>(ConfigCore.mods);
ConfigCore.mods = mods.stream().filter((mod -> OneConfigConfig.favoriteMods.contains(mod.name))).sorted().collect(Collectors.toList());
mods.removeAll(ConfigCore.mods);