diff options
author | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-06-12 12:17:43 +0200 |
---|---|---|
committer | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-06-12 12:17:43 +0200 |
commit | 0f853804ef7c626e9c31749d6f948aa6bb23f4db (patch) | |
tree | 31cce815049d969cacf8e2daeb95b16f7c27153e /src/main/java/cc/polyfrost/oneconfig/internal | |
parent | 7f28a19a6e11ab7cddeb51caffa76b1ad71cfeae (diff) | |
download | OneConfig-0f853804ef7c626e9c31749d6f948aa6bb23f4db.tar.gz OneConfig-0f853804ef7c626e9c31749d6f948aa6bb23f4db.tar.bz2 OneConfig-0f853804ef7c626e9c31749d6f948aa6bb23f4db.zip |
prefernces, keybinds, scrolling fixes
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/internal')
7 files changed, 110 insertions, 27 deletions
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(); |