aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/polyfrost/oneconfig/config/interfaces
diff options
context:
space:
mode:
authornextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com>2022-04-25 13:12:22 +0100
committernextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com>2022-04-25 13:12:22 +0100
commit89d6576a7777a2949e04b2c6c8d2eb015a733529 (patch)
tree1a6906f9c71591aacbcbf5a32a1a1ed582b95fcb /src/main/java/io/polyfrost/oneconfig/config/interfaces
parent29156d83c4213e319149fa5e0a926dd913404528 (diff)
downloadOneConfig-89d6576a7777a2949e04b2c6c8d2eb015a733529.tar.gz
OneConfig-89d6576a7777a2949e04b2c6c8d2eb015a733529.tar.bz2
OneConfig-89d6576a7777a2949e04b2c6c8d2eb015a733529.zip
add size, do some config element stuff, fixes for cards, finish mods page and performance page, cleanup and some more
Diffstat (limited to 'src/main/java/io/polyfrost/oneconfig/config/interfaces')
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java21
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/interfaces/Option.java9
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/interfaces/Size.java6
3 files changed, 23 insertions, 13 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java b/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java
index 049ad3e..f0efcb0 100644
--- a/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java
+++ b/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java
@@ -13,6 +13,7 @@ import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
@@ -42,7 +43,7 @@ public class Config {
* Save current config to file
*/
public void save() {
- try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(Profiles.getProfileFile(configFile)), StandardCharsets.UTF_8))) {
+ try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(Profiles.getProfileFile(configFile).toPath()), StandardCharsets.UTF_8))) {
writer.write(gson.toJson(this.getClass()));
} catch (IOException e) {
e.printStackTrace();
@@ -53,7 +54,7 @@ public class Config {
* Load file and overwrite current values
*/
public void load() {
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(Profiles.getProfileFile(configFile)), StandardCharsets.UTF_8))) {
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(Profiles.getProfileFile(configFile).toPath()), StandardCharsets.UTF_8))) {
deserializePart(new JsonParser().parse(reader).getAsJsonObject(), this.getClass());
} catch (IOException e) {
e.printStackTrace();
@@ -71,31 +72,31 @@ public class Config {
for (Class<?> innerClass : clazz.getClasses()) {
if (innerClass.isAnnotationPresent(Category.class)) {
Category category = innerClass.getAnnotation(Category.class);
- options.add(new OConfigCategory(category.name(), category.description(), generateOptionList(innerClass)));
+ options.add(new OConfigCategory(category.name(), category.description(), generateOptionList(innerClass), category.size()));
}
}
for (Field field : clazz.getFields()) {
if (field.isAnnotationPresent(Button.class)) {
Button button = field.getAnnotation(Button.class);
- options.add(new OConfigButton(field, button.name(), button.description(), button.text()));
+ options.add(new OConfigButton(field, button.name(), button.description(), button.text(), button.size()));
} else if (field.isAnnotationPresent(ColorPicker.class)) {
ColorPicker colorPicker = field.getAnnotation(ColorPicker.class);
- options.add(new OConfigColor(field, colorPicker.name(), colorPicker.description(), colorPicker.allowAlpha()));
+ options.add(new OConfigColor(field, colorPicker.name(), colorPicker.description(), colorPicker.allowAlpha(), colorPicker.size()));
} else if (field.isAnnotationPresent(Selector.class)) {
Selector selector = field.getAnnotation(Selector.class);
- options.add(new OConfigSelector(field, selector.name(), selector.description(), selector.options(), selector.defaultSelection()));
+ options.add(new OConfigSelector(field, selector.name(), selector.description(), selector.options(), selector.defaultSelection(), selector.size()));
} else if (field.isAnnotationPresent(Slider.class)) {
Slider slider = field.getAnnotation(Slider.class);
- options.add(new OConfigSlider(field, slider.name(), slider.description(), slider.min(), slider.max(), slider.precision()));
+ options.add(new OConfigSlider(field, slider.name(), slider.description(), slider.min(), slider.max(), slider.precision(), slider.size()));
} else if (field.isAnnotationPresent(Switch.class)) {
Switch aSwitch = field.getAnnotation(Switch.class);
- options.add(new OConfigSwitch(field, aSwitch.name(), aSwitch.description()));
+ options.add(new OConfigSwitch(field, aSwitch.name(), aSwitch.description(), aSwitch.size()));
} else if (field.isAnnotationPresent(TextField.class)) {
TextField textField = field.getAnnotation(TextField.class);
- options.add(new OConfigText(field, textField.name(), textField.description(), textField.placeholder(), textField.hideText()));
+ options.add(new OConfigText(field, textField.name(), textField.description(), textField.placeholder(), textField.hideText(), textField.size()));
} else if (field.isAnnotationPresent(HudComponent.class)) {
HudComponent hudComponent = field.getAnnotation(HudComponent.class);
- options.add(new OConfigHud(field, hudComponent.name(), hudComponent.description()));
+ options.add(new OConfigHud(field, hudComponent.name(), hudComponent.description(), hudComponent.size()));
try {
Object hud = field.get(BasicHud.class);
HudCore.huds.add((BasicHud) hud);
diff --git a/src/main/java/io/polyfrost/oneconfig/config/interfaces/Option.java b/src/main/java/io/polyfrost/oneconfig/config/interfaces/Option.java
index 99cf656..bd9c034 100644
--- a/src/main/java/io/polyfrost/oneconfig/config/interfaces/Option.java
+++ b/src/main/java/io/polyfrost/oneconfig/config/interfaces/Option.java
@@ -7,6 +7,7 @@ public abstract class Option {
protected final Field field;
protected final String name;
protected final String description;
+ public final int size;
/**
* Initialize option
@@ -14,11 +15,13 @@ public abstract class Option {
* @param field variable attached to option (null for category)
* @param name name of option
* @param description description of option
+ * @param size size of option, 0 for single column, 1 for double.
*/
- public Option(Field field, String name, String description) {
+ public Option(Field field, String name, String description, int size) {
this.field = field;
this.name = name;
this.description = description;
+ this.size = size;
if (field != null) field.setAccessible(true);
}
@@ -46,13 +49,13 @@ public abstract class Option {
/**
* Function that gets called when drawing option
*
+ * @param vg NanoVG context
* @param x x position
* @param y y position
- * @param width width of menu
* @param mouseX x position of mouse
* @param mouseY y position of mouse
*/
- public abstract void draw(int x, int y, int width, int mouseX, int mouseY);
+ public abstract void draw(long vg, int x, int y, int mouseX, int mouseY);
/**
* Function that gets called when mouse is clicked
diff --git a/src/main/java/io/polyfrost/oneconfig/config/interfaces/Size.java b/src/main/java/io/polyfrost/oneconfig/config/interfaces/Size.java
new file mode 100644
index 0000000..4802ec5
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/config/interfaces/Size.java
@@ -0,0 +1,6 @@
+package io.polyfrost.oneconfig.config.interfaces;
+
+public enum Size {
+ SINGLE_COLUMN, // A single column, 480x32
+ DOUBLE_COLUMN // A double column, 992x32
+}