aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc
diff options
context:
space:
mode:
authorDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-06-12 12:17:43 +0200
committerDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-06-12 12:17:43 +0200
commit0f853804ef7c626e9c31749d6f948aa6bb23f4db (patch)
tree31cce815049d969cacf8e2daeb95b16f7c27153e /src/main/java/cc
parent7f28a19a6e11ab7cddeb51caffa76b1ad71cfeae (diff)
downloadOneConfig-0f853804ef7c626e9c31749d6f948aa6bb23f4db.tar.gz
OneConfig-0f853804ef7c626e9c31749d6f948aa6bb23f4db.tar.bz2
OneConfig-0f853804ef7c626e9c31749d6f948aa6bb23f4db.zip
prefernces, keybinds, scrolling fixes
Diffstat (limited to 'src/main/java/cc')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java22
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java3
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java3
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/pages/CreditsPage.java5
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java16
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java3
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java4
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java6
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/config/InternalConfig.java47
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/config/OneConfigConfig.java28
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/config/Preferences.java25
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java1
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/config/core/KeyBindHandler.java27
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/gui/BlurHandler.java3
14 files changed, 158 insertions, 35 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java b/src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java
index d62247c..229e4d1 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java
@@ -5,22 +5,38 @@ import cc.polyfrost.oneconfig.libs.universal.UKeyboard;
import java.util.ArrayList;
public class OneKeyBind {
- private final ArrayList<Integer> keyBinds = new ArrayList<>();
+ protected final ArrayList<Integer> keyBinds = new ArrayList<>();
+ protected final Runnable runnable;
+ protected boolean hasRun;
- public OneKeyBind(int... keys) {
+ public OneKeyBind(Runnable runnable, int... keys) {
+ this.runnable = runnable;
for (int key : keys) {
keyBinds.add(key);
}
}
+ public OneKeyBind(int... keys) {
+ this(null, keys);
+ }
+
public boolean isActive() {
if (keyBinds.size() == 0) return false;
for (int keyBind : keyBinds) {
- if (!UKeyboard.isKeyDown(keyBind)) return false;
+ if (!UKeyboard.isKeyDown(keyBind)) {
+ hasRun = false;
+ return false;
+ }
}
return true;
}
+ public void run() {
+ if (runnable == null || hasRun) return;
+ runnable.run();
+ hasRun = true;
+ }
+
public String getDisplay() {
StringBuilder sb = new StringBuilder();
for (int keyBind : keyBinds) {
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java
index bda24a2..4652ae0 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java
@@ -5,7 +5,9 @@ import cc.polyfrost.oneconfig.gui.animations.DummyAnimation;
import cc.polyfrost.oneconfig.gui.animations.EaseInOutQuart;
import cc.polyfrost.oneconfig.gui.elements.BasicButton;
import cc.polyfrost.oneconfig.gui.pages.CreditsPage;
+import cc.polyfrost.oneconfig.gui.pages.ModConfigPage;
import cc.polyfrost.oneconfig.gui.pages.ModsPage;
+import cc.polyfrost.oneconfig.internal.OneConfig;
import cc.polyfrost.oneconfig.internal.assets.Colors;
import cc.polyfrost.oneconfig.renderer.RenderManager;
import cc.polyfrost.oneconfig.renderer.font.Fonts;
@@ -40,6 +42,7 @@ public class SideBar {
public SideBar() {
buttons.get(0).setClickAction(new CreditsPage());
buttons.get(2).setClickAction(new ModsPage());
+ buttons.get(8).setClickAction(new ModConfigPage(OneConfig.preferences.mod.defaultPage, true));
HUDButton.setClickAction(() -> GuiUtils.displayScreen(new HudGui()));
CloseButton.setClickAction(GuiUtils::closeScreen);
for (BasicButton button : buttons) {
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java
index b7d1a68..1aa5d66 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java
@@ -6,6 +6,7 @@ import cc.polyfrost.oneconfig.config.core.OneKeyBind;
import cc.polyfrost.oneconfig.config.elements.BasicOption;
import cc.polyfrost.oneconfig.gui.OneConfigGui;
import cc.polyfrost.oneconfig.gui.elements.BasicButton;
+import cc.polyfrost.oneconfig.internal.config.core.KeyBindHandler;
import cc.polyfrost.oneconfig.renderer.RenderManager;
import cc.polyfrost.oneconfig.renderer.font.Fonts;
import cc.polyfrost.oneconfig.internal.assets.SVGs;
@@ -22,6 +23,7 @@ public class ConfigKeyBind extends BasicOption {
super(field, parent, name, category, subcategory, size);
button = new BasicButton(256, 32, "", SVGs.KEYSTROKE, null, BasicButton.ALIGNMENT_JUSTIFIED, ColorPalette.SECONDARY);
button.setToggleable(true);
+ KeyBindHandler.addKeyBind(getKeyBind());
}
public static ConfigKeyBind create(Field field, Object parent) {
@@ -71,6 +73,7 @@ public class ConfigKeyBind extends BasicOption {
private OneKeyBind getKeyBind() {
OneKeyBind keyBind = new OneKeyBind();
try {
+ field.setAccessible(true);
keyBind = (OneKeyBind) get();
} catch (IllegalAccessException ignored) {
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/CreditsPage.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/CreditsPage.java
index 455a538..a101071 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/CreditsPage.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/CreditsPage.java
@@ -32,4 +32,9 @@ public class CreditsPage extends Page {
RenderManager.drawText(vg, " - Quiltflower (Quilt Team) - Gradle decompiler", x + 20, y + 415, -1, 12, Fonts.REGULAR);
RenderManager.drawText(vg, " - Seraph (Scherso) - Locraw and Multithreading utilities", x + 20, y + 430, -1, 12, Fonts.REGULAR);
}
+
+ @Override
+ public boolean isBase() {
+ return true;
+ }
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java
index 3e8fbf8..fb04dc2 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java
@@ -3,6 +3,7 @@ package cc.polyfrost.oneconfig.gui.pages;
import cc.polyfrost.oneconfig.config.elements.OptionPage;
import cc.polyfrost.oneconfig.config.elements.OptionSubcategory;
import cc.polyfrost.oneconfig.config.elements.BasicOption;
+import cc.polyfrost.oneconfig.gui.animations.DummyAnimation;
import cc.polyfrost.oneconfig.gui.elements.BasicButton;
import cc.polyfrost.oneconfig.renderer.RenderManager;
import cc.polyfrost.oneconfig.renderer.font.Fonts;
@@ -17,10 +18,12 @@ public class ModConfigPage extends Page {
private final ArrayList<BasicButton> categories = new ArrayList<>();
private String selectedCategory;
private int totalSize = 724;
+ private final boolean base;
- public ModConfigPage(OptionPage page) {
+ public ModConfigPage(OptionPage page, boolean base) {
super(page.name);
this.page = page;
+ this.base = base;
if (page.categories.size() == 0) return;
for (String category : page.categories.keySet()) {
selectedCategory = category;
@@ -36,6 +39,10 @@ public class ModConfigPage extends Page {
}
}
+ public ModConfigPage(OptionPage page) {
+ this(page, false);
+ }
+
@Override
public void draw(long vg, int x, int y) {
if (page.categories.size() == 0) return;
@@ -84,6 +91,8 @@ public class ModConfigPage extends Page {
for (BasicButton button : categories) {
if (button.getText().equals(newCategory)) continue;
button.setToggled(false);
+ scrollTarget = 0;
+ scrollAnimation = null;
}
}
@@ -91,4 +100,9 @@ public class ModConfigPage extends Page {
public int getMaxScrollHeight() {
return totalSize;
}
+
+ @Override
+ public boolean isBase() {
+ return base;
+ }
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java
index 797512f..10852ab 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java
@@ -100,8 +100,7 @@ public class ModsPage extends Page {
@Override
public int getMaxScrollHeight() {
- //return size;
- return 3298046;
+ return size;
}
@Override
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java
index d884814..fff9482 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java
@@ -16,9 +16,9 @@ import org.lwjgl.input.Mouse;
*/
public abstract class Page {
protected final String title;
- private Animation scrollAnimation;
+ protected Animation scrollAnimation;
private final ColorAnimation colorAnimation = new ColorAnimation(new ColorPalette(Colors.TRANSPARENT, Colors.GRAY_400_60, Colors.GRAY_400_60));
- private float scrollTarget;
+ protected float scrollTarget;
private long scrollTime;
private boolean mouseWasDown, dragging;
private float yStart;
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java b/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java
index 5f3b669..c3e2750 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java
@@ -5,12 +5,15 @@ import cc.polyfrost.oneconfig.config.data.ModType;
import cc.polyfrost.oneconfig.events.EventManager;
import cc.polyfrost.oneconfig.internal.command.OneConfigCommand;
import cc.polyfrost.oneconfig.internal.config.OneConfigConfig;
+import cc.polyfrost.oneconfig.internal.config.Preferences;
import cc.polyfrost.oneconfig.internal.config.core.ConfigCore;
+import cc.polyfrost.oneconfig.internal.config.core.KeyBindHandler;
import cc.polyfrost.oneconfig.internal.gui.BlurHandler;
import cc.polyfrost.oneconfig.internal.hud.HudCore;
import cc.polyfrost.oneconfig.utils.commands.CommandManager;
import cc.polyfrost.oneconfig.utils.gui.GuiUtils;
import cc.polyfrost.oneconfig.utils.hypixel.HypixelUtils;
+import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.DummyModContainer;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.ModContainer;
@@ -33,6 +36,7 @@ public class OneConfig {
public static final List<ModMetadata> loadedOtherMods = new ArrayList<>();
public static final Logger LOGGER = LogManager.getLogger("@NAME@");
public static OneConfigConfig config;
+ public static Preferences preferences;
private static boolean preLaunched = false;
private static boolean initialized = false;
private static boolean isObfuscated = true;
@@ -55,6 +59,7 @@ public class OneConfig {
oneConfigDir.mkdirs();
new File(oneConfigDir, "profiles").mkdirs();
config = new OneConfigConfig();
+ preferences = new Preferences();
preLaunched = true;
}
@@ -70,6 +75,7 @@ public class OneConfig {
CommandManager.INSTANCE.registerCommand(OneConfigCommand.class);
EventManager.INSTANCE.register(new HudCore());
EventManager.INSTANCE.register(HypixelUtils.INSTANCE);
+ MinecraftForge.EVENT_BUS.register(new KeyBindHandler());
reloadModsList();
initialized = true;
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/config/InternalConfig.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/InternalConfig.java
new file mode 100644
index 0000000..f0b065e
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/InternalConfig.java
@@ -0,0 +1,47 @@
+package cc.polyfrost.oneconfig.internal.config;
+
+import cc.polyfrost.oneconfig.config.Config;
+import cc.polyfrost.oneconfig.config.data.Mod;
+import cc.polyfrost.oneconfig.utils.JsonUtils;
+
+import java.io.*;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+public abstract class InternalConfig extends Config {
+ /**
+ * @param title title that is displayed
+ * @param configFile file where config is stored
+ */
+ public InternalConfig(String title, String configFile) {
+ super(new Mod(title, null), configFile);
+ }
+
+ @Override
+ public void init(Mod mod) {
+ if (new File("OneConfig/" + configFile).exists()) load();
+ else save();
+ generateOptionList(this, mod.defaultPage, mod, false);
+ mod.config = this;
+ this.mod = mod;
+ }
+
+ @Override
+ public void save() {
+ try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(Paths.get("OneConfig/" + configFile)), StandardCharsets.UTF_8))) {
+ writer.write(gson.toJson(this));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void load() {
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(Paths.get("OneConfig/" + configFile)), StandardCharsets.UTF_8))) {
+ deserializePart(JsonUtils.PARSER.parse(reader).getAsJsonObject(), this);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/config/OneConfigConfig.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/OneConfigConfig.java
index a0e25fc..1986e9e 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/config/OneConfigConfig.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/OneConfigConfig.java
@@ -11,7 +11,7 @@ import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
-public class OneConfigConfig extends Config {
+public class OneConfigConfig extends InternalConfig {
public static String currentProfile = "Default Profile";
public static boolean autoUpdate = true;
/**
@@ -26,30 +26,6 @@ public class OneConfigConfig extends Config {
public static boolean australia = false;
public OneConfigConfig() {
- super(null, "OneConfig.json");
- }
-
- @Override
- public void init(Mod mod) {
- if (new File("OneConfig/" + configFile).exists()) load();
- else save();
- }
-
- @Override
- public void save() {
- try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(Paths.get("OneConfig/" + configFile)), StandardCharsets.UTF_8))) {
- writer.write(gson.toJson(this));
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- @Override
- public void load() {
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(Paths.get("OneConfig/" + configFile)), StandardCharsets.UTF_8))) {
- deserializePart(JsonUtils.PARSER.parse(reader).getAsJsonObject(), this);
- } catch (IOException e) {
- e.printStackTrace();
- }
+ super("", "OneConfig.json");
}
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/config/Preferences.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/Preferences.java
new file mode 100644
index 0000000..10c14a8
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/Preferences.java
@@ -0,0 +1,25 @@
+package cc.polyfrost.oneconfig.internal.config;
+
+import cc.polyfrost.oneconfig.config.annotations.KeyBind;
+import cc.polyfrost.oneconfig.config.annotations.Switch;
+import cc.polyfrost.oneconfig.config.core.OneKeyBind;
+import cc.polyfrost.oneconfig.gui.OneConfigGui;
+import cc.polyfrost.oneconfig.libs.universal.UKeyboard;
+import cc.polyfrost.oneconfig.utils.gui.GuiUtils;
+
+public class Preferences extends InternalConfig {
+ @Switch(
+ name = "Enable Blur"
+ )
+ public static boolean enableBlur = true;
+
+ @KeyBind(
+ name = "OneConfig Keybind",
+ size = 2
+ )
+ public static OneKeyBind oneConfigKeyBind = new OneKeyBind(() -> GuiUtils.displayScreen(OneConfigGui.create()), UKeyboard.KEY_RSHIFT);
+
+ public Preferences() {
+ super("Preferences", "Preferences.json");
+ }
+}
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 02ac8f8..5a9dd0b 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
@@ -18,6 +18,7 @@ public class ConfigCore {
ArrayList<Mod> data = new ArrayList<>(oneConfigMods);
oneConfigMods.clear();
HudCore.huds.clear();
+ KeyBindHandler.clearKeyBinds();
for (Mod modData : data) {
modData.config.init(modData);
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/config/core/KeyBindHandler.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/core/KeyBindHandler.java
new file mode 100644
index 0000000..da82951
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/core/KeyBindHandler.java
@@ -0,0 +1,27 @@
+package cc.polyfrost.oneconfig.internal.config.core;
+
+import cc.polyfrost.oneconfig.config.core.OneKeyBind;
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
+import net.minecraftforge.fml.common.gameevent.InputEvent;
+
+import java.util.ArrayList;
+
+public class KeyBindHandler {
+ private static final ArrayList<OneKeyBind> keyBinds = new ArrayList<>();
+
+ @SubscribeEvent
+ public void onKeyPressed(InputEvent.KeyInputEvent event) {
+ for (OneKeyBind keyBind : keyBinds) {
+ if (keyBind.isActive()) keyBind.run();
+ }
+ }
+
+ public static void addKeyBind(OneKeyBind keyBind) {
+ if (keyBind == null) return;
+ keyBinds.add(keyBind);
+ }
+
+ public static void clearKeyBinds() {
+ keyBinds.clear();
+ }
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/gui/BlurHandler.java b/src/main/java/cc/polyfrost/oneconfig/internal/gui/BlurHandler.java
index 4aa94d9..697f2d4 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/gui/BlurHandler.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/gui/BlurHandler.java
@@ -5,6 +5,7 @@ import cc.polyfrost.oneconfig.events.event.RenderEvent;
import cc.polyfrost.oneconfig.events.event.ScreenOpenEvent;
import cc.polyfrost.oneconfig.events.event.Stage;
import cc.polyfrost.oneconfig.gui.OneConfigGui;
+import cc.polyfrost.oneconfig.internal.config.Preferences;
import cc.polyfrost.oneconfig.internal.mixin.ShaderGroupAccessor;
import cc.polyfrost.oneconfig.libs.universal.UMinecraft;
import cc.polyfrost.oneconfig.libs.universal.UScreen;
@@ -119,7 +120,7 @@ public class BlurHandler {
// If a shader is not already active and the UI is
// a one of ours, we should load our own blur!
- if (!UMinecraft.getMinecraft().entityRenderer.isShaderActive() && gui instanceof OneConfigGui) {
+ if (!UMinecraft.getMinecraft().entityRenderer.isShaderActive() && gui instanceof OneConfigGui && Preferences.enableBlur) {
UMinecraft.getMinecraft().entityRenderer.loadShader(this.blurShader);
this.start = System.currentTimeMillis();