From ab7256dff5d6d37488081ba7a01b36d3ee9ef563 Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Sun, 5 Jun 2022 17:43:23 +0200 Subject: refactor (#36) * refactor * fix vig compat * fix nanovg thingy * e * finalize * gui utils package thingy --- .../java/cc/polyfrost/oneconfig/OneConfig.java | 85 --- .../oneconfig/command/OneConfigCommand.java | 38 -- .../java/cc/polyfrost/oneconfig/config/Config.java | 263 +++++++ .../oneconfig/config/OneConfigConfig.java | 91 --- .../config/compatibility/VigilanceConfig.java | 202 ------ .../config/compatibility/VigilantAccessor.java | 11 - .../compatibility/vigilance/VigilanceConfig.java | 202 ++++++ .../compatibility/vigilance/VigilantAccessor.java | 11 + .../cc/polyfrost/oneconfig/config/data/Mod.java | 5 +- .../oneconfig/config/data/OptionCategory.java | 7 - .../oneconfig/config/data/OptionPage.java | 19 - .../oneconfig/config/data/OptionSubcategory.java | 122 ---- .../oneconfig/config/elements/BasicOption.java | 98 +++ .../oneconfig/config/elements/OptionCategory.java | 7 + .../oneconfig/config/elements/OptionPage.java | 16 + .../config/elements/OptionSubcategory.java | 122 ++++ .../oneconfig/config/interfaces/BasicOption.java | 98 --- .../oneconfig/config/interfaces/Config.java | 259 ------- .../oneconfig/config/migration/Migrator.java | 14 - .../config/migration/VigilanceMigrator.java | 84 --- .../config/migration/vigilance/Migrator.java | 14 + .../migration/vigilance/VigilanceMigrator.java | 84 +++ .../oneconfig/config/profiles/Profiles.java | 4 +- .../java/cc/polyfrost/oneconfig/gui/Colors.java | 46 ++ .../java/cc/polyfrost/oneconfig/gui/HudGui.java | 2 +- .../cc/polyfrost/oneconfig/gui/OneConfigGui.java | 39 +- .../java/cc/polyfrost/oneconfig/gui/SideBar.java | 15 +- .../oneconfig/gui/animations/Animation.java | 2 +- .../oneconfig/gui/elements/BasicButton.java | 10 +- .../oneconfig/gui/elements/BasicElement.java | 2 +- .../oneconfig/gui/elements/ColorSelector.java | 59 +- .../polyfrost/oneconfig/gui/elements/ModCard.java | 20 +- .../oneconfig/gui/elements/ModUpdateCard.java | 8 - .../polyfrost/oneconfig/gui/elements/Slider.java | 10 +- .../gui/elements/config/ConfigButton.java | 10 +- .../gui/elements/config/ConfigCheckbox.java | 18 +- .../gui/elements/config/ConfigColorElement.java | 14 +- .../gui/elements/config/ConfigDropdown.java | 42 +- .../gui/elements/config/ConfigDualOption.java | 18 +- .../gui/elements/config/ConfigHeader.java | 14 +- .../oneconfig/gui/elements/config/ConfigInfo.java | 14 +- .../gui/elements/config/ConfigKeyBind.java | 12 +- .../gui/elements/config/ConfigPageButton.java | 16 +- .../gui/elements/config/ConfigSlider.java | 20 +- .../gui/elements/config/ConfigSwitch.java | 12 +- .../gui/elements/config/ConfigTextBox.java | 14 +- .../gui/elements/text/NumberInputField.java | 8 +- .../oneconfig/gui/elements/text/SearchField.java | 14 - .../gui/elements/text/TextInputField.java | 36 +- .../polyfrost/oneconfig/gui/pages/CreditsPage.java | 6 +- .../cc/polyfrost/oneconfig/gui/pages/HomePage.java | 14 +- .../oneconfig/gui/pages/ModConfigPage.java | 10 +- .../cc/polyfrost/oneconfig/gui/pages/ModsPage.java | 11 +- .../cc/polyfrost/oneconfig/gui/pages/Page.java | 4 +- .../java/cc/polyfrost/oneconfig/hud/BasicHud.java | 2 +- .../java/cc/polyfrost/oneconfig/hud/TextHud.java | 2 +- .../cc/polyfrost/oneconfig/init/OneConfigInit.java | 24 - .../cc/polyfrost/oneconfig/internal/OneConfig.java | 85 +++ .../internal/command/OneConfigCommand.java | 38 ++ .../oneconfig/internal/config/OneConfigConfig.java | 48 ++ .../oneconfig/internal/gui/BlurHandler.java | 148 ++++ .../oneconfig/internal/init/OneConfigInit.java | 24 + .../internal/mixin/FontRendererMixin.java | 15 + .../internal/mixin/GuiIngameForgeMixin.java | 17 + .../oneconfig/internal/mixin/MinecraftMixin.java | 76 +++ .../internal/mixin/NetHandlerPlayClientMixin.java | 36 + .../internal/mixin/NetworkManagerMixin.java | 23 + .../internal/mixin/ShaderGroupAccessor.java | 14 + .../oneconfig/internal/mixin/WorldClientMixin.java | 21 + .../oneconfig/internal/plugin/LoadingPlugin.java | 53 ++ .../internal/plugin/Lwjgl2FunctionProvider.java | 39 ++ .../internal/plugin/OneConfigMixinPlugin.java | 52 ++ .../internal/plugin/asm/ClassTransformer.java | 64 ++ .../internal/plugin/asm/ITransformer.java | 9 + .../asm/tweakers/NanoVGGLConfigTransformer.java | 43 ++ .../plugin/asm/tweakers/VigilantTransformer.java | 105 +++ .../cc/polyfrost/oneconfig/lwjgl/BlurHandler.java | 148 ---- .../polyfrost/oneconfig/lwjgl/RenderManager.java | 755 --------------------- .../cc/polyfrost/oneconfig/lwjgl/font/Font.java | 41 -- .../oneconfig/lwjgl/font/FontManager.java | 31 - .../cc/polyfrost/oneconfig/lwjgl/font/Fonts.java | 15 - .../oneconfig/lwjgl/image/ImageLoader.java | 190 ------ .../cc/polyfrost/oneconfig/lwjgl/image/Images.java | 19 - .../cc/polyfrost/oneconfig/lwjgl/image/SVGs.java | 52 -- .../lwjgl/plugin/Lwjgl2FunctionProvider.java | 39 -- .../polyfrost/oneconfig/lwjgl/scissor/Scissor.java | 27 - .../oneconfig/lwjgl/scissor/ScissorManager.java | 69 -- .../oneconfig/mixin/FontRendererMixin.java | 15 - .../oneconfig/mixin/GuiIngameForgeMixin.java | 17 - .../polyfrost/oneconfig/mixin/MinecraftMixin.java | 76 --- .../oneconfig/mixin/NetHandlerPlayClientMixin.java | 36 - .../oneconfig/mixin/NetworkManagerMixin.java | 23 - .../oneconfig/mixin/ShaderGroupAccessor.java | 14 - .../oneconfig/mixin/WorldClientMixin.java | 21 - .../polyfrost/oneconfig/plugin/LoadingPlugin.java | 54 -- .../oneconfig/plugin/OneConfigMixinPlugin.java | 52 -- .../oneconfig/plugin/asm/ClassTransformer.java | 64 -- .../oneconfig/plugin/asm/ITransformer.java | 9 - .../asm/tweakers/NanoVGGLConfigTransformer.java | 43 -- .../plugin/asm/tweakers/VigilantTransformer.java | 105 --- .../oneconfig/renderer/RenderManager.java | 755 +++++++++++++++++++++ .../cc/polyfrost/oneconfig/renderer/font/Font.java | 41 ++ .../oneconfig/renderer/font/FontManager.java | 47 ++ .../polyfrost/oneconfig/renderer/font/Fonts.java | 15 + .../oneconfig/renderer/image/ImageLoader.java | 190 ++++++ .../polyfrost/oneconfig/renderer/image/Images.java | 19 + .../polyfrost/oneconfig/renderer/image/SVGs.java | 52 ++ .../oneconfig/renderer/scissor/Scissor.java | 27 + .../oneconfig/renderer/scissor/ScissorManager.java | 69 ++ .../polyfrost/oneconfig/test/ButtonTestPage.java | 2 +- .../cc/polyfrost/oneconfig/test/TestConfig.java | 5 +- .../oneconfig/test/TestNanoVGGui_Test.java | 4 +- .../cc/polyfrost/oneconfig/utils/GuiUtils.java | 62 -- .../cc/polyfrost/oneconfig/utils/OneUIScreen.java | 146 ---- .../cc/polyfrost/oneconfig/utils/TextUtils.java | 6 +- .../oneconfig/utils/color/ColorPalette.java | 10 +- .../utils/commands/annotations/Command.java | 3 +- .../cc/polyfrost/oneconfig/utils/gui/GuiUtils.java | 63 ++ .../polyfrost/oneconfig/utils/gui/OneUIScreen.java | 147 ++++ 119 files changed, 3447 insertions(+), 3445 deletions(-) delete mode 100644 src/main/java/cc/polyfrost/oneconfig/OneConfig.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/command/OneConfigCommand.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/config/Config.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilanceConfig.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilantAccessor.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilantAccessor.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/config/data/OptionCategory.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/config/data/OptionPage.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/config/data/OptionSubcategory.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/config/elements/OptionCategory.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/config/elements/OptionPage.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/config/interfaces/BasicOption.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/config/migration/Migrator.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/config/migration/VigilanceMigrator.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/config/migration/vigilance/Migrator.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/config/migration/vigilance/VigilanceMigrator.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/gui/Colors.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/gui/elements/ModUpdateCard.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/gui/elements/text/SearchField.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/init/OneConfigInit.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/internal/command/OneConfigCommand.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/internal/config/OneConfigConfig.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/internal/gui/BlurHandler.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/internal/init/OneConfigInit.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/internal/mixin/FontRendererMixin.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/internal/mixin/GuiIngameForgeMixin.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetHandlerPlayClientMixin.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetworkManagerMixin.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/internal/mixin/ShaderGroupAccessor.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/internal/mixin/WorldClientMixin.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/internal/plugin/LoadingPlugin.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/internal/plugin/Lwjgl2FunctionProvider.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/ClassTransformer.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/ITransformer.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/tweakers/NanoVGGLConfigTransformer.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/tweakers/VigilantTransformer.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/lwjgl/BlurHandler.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/lwjgl/font/Font.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/lwjgl/font/FontManager.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/lwjgl/font/Fonts.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/lwjgl/image/ImageLoader.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/lwjgl/image/Images.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/lwjgl/image/SVGs.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/lwjgl/plugin/Lwjgl2FunctionProvider.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/lwjgl/scissor/Scissor.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/lwjgl/scissor/ScissorManager.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/mixin/FontRendererMixin.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/mixin/GuiIngameForgeMixin.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/mixin/MinecraftMixin.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/mixin/NetHandlerPlayClientMixin.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/mixin/NetworkManagerMixin.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/mixin/ShaderGroupAccessor.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/mixin/WorldClientMixin.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/plugin/LoadingPlugin.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/plugin/OneConfigMixinPlugin.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/plugin/asm/ClassTransformer.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/plugin/asm/ITransformer.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/plugin/asm/tweakers/NanoVGGLConfigTransformer.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/plugin/asm/tweakers/VigilantTransformer.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/renderer/font/Font.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/renderer/font/FontManager.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/renderer/font/Fonts.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/renderer/image/ImageLoader.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/renderer/image/Images.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/renderer/image/SVGs.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/renderer/scissor/Scissor.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/renderer/scissor/ScissorManager.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/utils/GuiUtils.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/utils/OneUIScreen.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/utils/gui/GuiUtils.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/utils/gui/OneUIScreen.java (limited to 'src/main/java/cc') diff --git a/src/main/java/cc/polyfrost/oneconfig/OneConfig.java b/src/main/java/cc/polyfrost/oneconfig/OneConfig.java deleted file mode 100644 index e8612b6..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/OneConfig.java +++ /dev/null @@ -1,85 +0,0 @@ -package cc.polyfrost.oneconfig; - -import cc.polyfrost.oneconfig.command.OneConfigCommand; -import cc.polyfrost.oneconfig.config.OneConfigConfig; -import cc.polyfrost.oneconfig.config.core.ConfigCore; -import cc.polyfrost.oneconfig.config.data.Mod; -import cc.polyfrost.oneconfig.config.data.ModType; -import cc.polyfrost.oneconfig.events.EventManager; -import cc.polyfrost.oneconfig.hud.HudCore; -import cc.polyfrost.oneconfig.lwjgl.BlurHandler; -import cc.polyfrost.oneconfig.test.TestCommand; -import cc.polyfrost.oneconfig.test.TestConfig; -import cc.polyfrost.oneconfig.utils.GuiUtils; -import cc.polyfrost.oneconfig.utils.commands.CommandManager; -import cc.polyfrost.oneconfig.utils.hypixel.HypixelUtils; -import net.minecraftforge.fml.common.DummyModContainer; -import net.minecraftforge.fml.common.Loader; -import net.minecraftforge.fml.common.ModContainer; -import net.minecraftforge.fml.common.ModMetadata; - -import java.io.File; -import java.util.ArrayList; -import java.util.LinkedHashSet; -import java.util.List; - -/** - * The main class of OneConfig. - */ -@net.minecraftforge.fml.common.Mod(modid = "@ID@", name = "@NAME@", version = "@VER@") -public class OneConfig { - public static final File oneConfigDir = new File("./OneConfig"); - public static final List loadedMods = new ArrayList<>(); - public static final List loadedOtherMods = new ArrayList<>(); - public static OneConfigConfig config; - public static TestConfig testConfig; - private static boolean preLaunched = false; - private static boolean initialized = false; - - /** - * Called before mods are loaded. - *

SHOULD NOT BE CALLED!

- */ - public static void preLaunch() { - if (preLaunched) return; - if (!net.minecraft.launchwrapper.Launch.blackboard.containsKey("oneconfig.initialized")) { - throw new RuntimeException("OneConfig has not been initialized! Please add the OneConfig tweaker or call OneConfigInit via an ITweaker or a FMLLoadingPlugin!"); - } - oneConfigDir.mkdirs(); - new File(oneConfigDir, "profiles").mkdirs(); - config = new OneConfigConfig(); - preLaunched = true; - } - - /** - * Called after mods are loaded. - *

SHOULD NOT BE CALLED!

- */ - @SuppressWarnings("ResultOfMethodCallIgnored") - public static void init() { - if (initialized) return; - GuiUtils.getDeltaTime(); // called to make sure static initializer is called - BlurHandler.INSTANCE.load(); - testConfig = new TestConfig(); - CommandManager.INSTANCE.registerCommand(OneConfigCommand.class); - CommandManager.INSTANCE.registerCommand(TestCommand.class); - EventManager.INSTANCE.register(new HudCore()); - EventManager.INSTANCE.register(HypixelUtils.INSTANCE); - reloadModsList(); - initialized = true; - } - - public static void reloadModsList() { - loadedMods.addAll(ConfigCore.oneConfigMods); - LinkedHashSet modData = new LinkedHashSet<>(ConfigCore.oneConfigMods); - for (ModContainer mod : Loader.instance().getActiveModList()) { - ModMetadata metadata = mod.getMetadata(); - loadedOtherMods.add(metadata); - String imageName = Loader.instance().activeModContainer() == null || Loader.instance().activeModContainer().getMetadata().logoFile.trim().equals("") ? null : "/" + Loader.instance().activeModContainer().getMetadata().logoFile; - Mod newMod = new Mod(metadata.name, ModType.THIRD_PARTY, imageName); - newMod.isShortCut = true; - if (mod instanceof DummyModContainer || newMod.name.equals("OneConfig")) continue; - if (modData.add(newMod)) loadedMods.add(newMod); - } - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/command/OneConfigCommand.java b/src/main/java/cc/polyfrost/oneconfig/command/OneConfigCommand.java deleted file mode 100644 index d58c5a6..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/command/OneConfigCommand.java +++ /dev/null @@ -1,38 +0,0 @@ -package cc.polyfrost.oneconfig.command; - -import cc.polyfrost.oneconfig.gui.HudGui; -import cc.polyfrost.oneconfig.gui.OneConfigGui; -import cc.polyfrost.oneconfig.utils.GuiUtils; -import cc.polyfrost.oneconfig.utils.InputUtils; -import cc.polyfrost.oneconfig.utils.commands.annotations.Command; -import cc.polyfrost.oneconfig.utils.commands.annotations.Main; -import cc.polyfrost.oneconfig.utils.commands.annotations.SubCommand; - -/** - * The main OneConfig command. - */ -@Command(value = "oneconfig", aliases = {"ocfg", "oneconfig"}, description = "Access the OneConfig GUI.") -public class OneConfigCommand { - - @Main - private static void main() { - GuiUtils.displayScreen(OneConfigGui.create()); - } - - @SubCommand(value = "hud", description = "Open the OneConfig HUD config.") - private static class HUDSubCommand { - @Main - private static void main() { - GuiUtils.displayScreen(new HudGui()); - } - } - - @SubCommand(value = "destroy", description = "Destroy the cached OneConfig GUI.") - private static class DestroySubCommand { - @Main - private static void main() { - OneConfigGui.instanceToRestore = null; - InputUtils.blockClicks(false); - } - } -} \ No newline at end of file diff --git a/src/main/java/cc/polyfrost/oneconfig/config/Config.java b/src/main/java/cc/polyfrost/oneconfig/config/Config.java new file mode 100644 index 0000000..d0d8acf --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/config/Config.java @@ -0,0 +1,263 @@ +package cc.polyfrost.oneconfig.config; + +import cc.polyfrost.oneconfig.config.annotations.ConfigPage; +import cc.polyfrost.oneconfig.config.annotations.Option; +import cc.polyfrost.oneconfig.config.core.ConfigCore; +import cc.polyfrost.oneconfig.config.data.*; +import cc.polyfrost.oneconfig.config.elements.BasicOption; +import cc.polyfrost.oneconfig.config.elements.OptionCategory; +import cc.polyfrost.oneconfig.config.elements.OptionPage; +import cc.polyfrost.oneconfig.config.elements.OptionSubcategory; +import cc.polyfrost.oneconfig.config.profiles.Profiles; +import cc.polyfrost.oneconfig.gui.OneConfigGui; +import cc.polyfrost.oneconfig.gui.elements.config.*; +import cc.polyfrost.oneconfig.gui.pages.ModConfigPage; +import cc.polyfrost.oneconfig.hud.BasicHud; +import cc.polyfrost.oneconfig.hud.HudCore; +import cc.polyfrost.oneconfig.utils.gui.GuiUtils; +import com.google.gson.*; + +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.*; +import java.util.function.Supplier; + +public class Config { + public final transient HashMap optionNames = new HashMap<>(); + transient protected final String configFile; + transient protected final Gson gson = new GsonBuilder().excludeFieldsWithModifiers(Modifier.TRANSIENT).setPrettyPrinting().create(); + transient public Mod mod; + public transient boolean hasBeenInitialized = false; + public boolean enabled = true; + + /** + * @param modData information about the mod + * @param configFile file where config is stored + */ + public Config(Mod modData, String configFile) { + this.configFile = configFile; + init(modData); + } + + public void init(Mod mod) { + boolean migrate = false; + if (Profiles.getProfileFile(configFile).exists()) load(); + else if (!hasBeenInitialized && mod.migrator != null) migrate = true; + else save(); + mod.config = this; + generateOptionList(this, mod.defaultPage, mod, migrate); + if (migrate) save(); + ConfigCore.oneConfigMods.add(mod); + this.mod = mod; + hasBeenInitialized = true; + } + + /** + * Save current config to file + */ + public void save() { + try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(Profiles.getProfileFile(configFile).toPath()), StandardCharsets.UTF_8))) { + writer.write(gson.toJson(this)); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * Load file and overwrite current values + */ + public void load() { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(Profiles.getProfileFile(configFile).toPath()), StandardCharsets.UTF_8))) { + deserializePart(new JsonParser().parse(reader).getAsJsonObject(), this); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * Generate the option list, for internal use only + * + * @param instance instance of target class + * @param page page to add options too + * @param mod data about the mod + * @param migrate whether the migrator should be run + */ + protected void generateOptionList(Object instance, OptionPage page, Mod mod, boolean migrate) { + Class clazz = instance.getClass(); + for (Field field : clazz.getDeclaredFields()) { + String pagePrefix = page.equals(mod.defaultPage) ? "" : page.name + "."; + if (!field.isAnnotationPresent(Option.class) && !field.isAnnotationPresent(ConfigPage.class)) { + processCustomOption(field, page); + continue; + } else if (field.isAnnotationPresent(ConfigPage.class)) { + ConfigPage option = field.getAnnotation(ConfigPage.class); + if (!page.categories.containsKey(option.category())) + page.categories.put(option.category(), new OptionCategory()); + OptionCategory category = page.categories.get(option.category()); + if (category.subcategories.size() == 0 || !category.subcategories.get(category.subcategories.size() - 1).getName().equals(option.subcategory())) + category.subcategories.add(new OptionSubcategory(option.subcategory())); + OptionSubcategory subcategory = category.subcategories.get(category.subcategories.size() - 1); + OptionPage newPage = new OptionPage(option.name(), mod); + try { + field.setAccessible(true); + Object object = field.get(clazz); + generateOptionList(object, newPage, mod, migrate); + ConfigPageButton configPageButton = new ConfigPageButton(field, instance, option.name(), option.description(), newPage); + switch (option.location()) { + case TOP: + subcategory.topButtons.add(configPageButton); + break; + case BOTTOM: + subcategory.bottomButtons.add(configPageButton); + break; + } + optionNames.put(pagePrefix + field.getName(), configPageButton); + } catch (IllegalAccessException ignored) { + } + continue; + } + Option option = field.getAnnotation(Option.class); + if (!page.categories.containsKey(option.category())) + page.categories.put(option.category(), new OptionCategory()); + OptionCategory category = page.categories.get(option.category()); + if (category.subcategories.size() == 0 || !category.subcategories.get(category.subcategories.size() - 1).getName().equals(option.subcategory())) + category.subcategories.add(new OptionSubcategory(option.subcategory())); + if (migrate) { + try { + Object value = mod.migrator.getValue(field, option.name(), option.category(), option.subcategory()); + if (value != null) { + field.setAccessible(true); + field.set(instance, value); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + ArrayList options = category.subcategories.get(category.subcategories.size() - 1).options; + switch (option.type()) { + case SWITCH: + options.add(new ConfigSwitch(field, instance, option.name(), option.size())); + break; + case CHECKBOX: + options.add(new ConfigCheckbox(field, instance, option.name(), option.size())); + break; + case TEXT: + options.add(new ConfigTextBox(field, instance, option.name(), option.size(), option.placeholder(), option.secure(), option.multiLine())); + break; + case DUAL_OPTION: + options.add(new ConfigDualOption(field, instance, option.name(), option.size(), option.options())); + break; + case DROPDOWN: + options.add(new ConfigDropdown(field, instance, option.name(), option.size(), option.options())); + break; + case SLIDER: + options.add(new ConfigSlider(field, instance, option.name(), option.size(), option.min(), option.max(), option.step())); + break; + case INFO: + options.add(new ConfigInfo(field, instance, option.name(), option.size(), option.infoType())); + break; + case COLOR: + options.add(new ConfigColorElement(field, instance, option.name(), option.size())); + break; + case HEADER: + options.add(new ConfigHeader(field, instance, option.name(), option.size())); + break; + case BUTTON: + options.add(new ConfigButton(field, instance, option.name(), option.size(), option.buttonText())); + break; + case KEYBIND: + options.add(new ConfigKeyBind(field, instance, option.name(), option.size())); + break; + case HUD: + try { + field.setAccessible(true); + BasicHud hud = (BasicHud) field.get(instance); + HudCore.huds.add(hud); + options.add(new ConfigHeader(field, hud, option.name(), 1)); + options.add(new ConfigSwitch(hud.getClass().getField("enabled"), hud, "Enabled", 1)); + options.add(new ConfigCheckbox(hud.getClass().getField("rounded"), hud, "Rounded corners", 1)); + options.get(options.size() - 1).setDependency(() -> hud.enabled); + options.add(new ConfigCheckbox(hud.getClass().getField("border"), hud, "Outline/border", 1)); + options.get(options.size() - 1).setDependency(() -> hud.enabled); + options.add(new ConfigColorElement(hud.getClass().getField("bgColor"), hud, "Background color:", 1)); + options.get(options.size() - 1).setDependency(() -> hud.enabled); + options.add(new ConfigColorElement(hud.getClass().getField("borderColor"), hud, "Border color:", 1)); + options.get(options.size() - 1).setDependency(() -> hud.enabled && hud.border); + options.add(new ConfigSlider(hud.getClass().getField("cornerRadius"), hud, "Corner radius:", 2, 0, 10, 0)); + options.get(options.size() - 1).setDependency(() -> hud.enabled && hud.rounded); + options.add(new ConfigSlider(hud.getClass().getField("borderSize"), hud, "Border thickness:", 2, 0, 10, 0)); + options.get(options.size() - 1).setDependency(() -> hud.enabled && hud.border); + options.add(new ConfigSlider(hud.getClass().getField("paddingX"), hud, "X-Padding", 2, 0, 50, 0)); + options.get(options.size() - 1).setDependency(() -> hud.enabled); + options.add(new ConfigSlider(hud.getClass().getField("paddingY"), hud, "Y-Padding", 2, 0, 50, 0)); + options.get(options.size() - 1).setDependency(() -> hud.enabled); + } catch (IllegalAccessException | NoSuchFieldException e) { + e.printStackTrace(); + } + break; + } + if (!option.type().equals(OptionType.HUD)) + optionNames.put(pagePrefix + field.getName(), options.get(options.size() - 1)); + } + } + + /** + * Overwrite this method to add your own custom option types + * + * @param field target field + * @param page page to add options too + */ + protected void processCustomOption(Field field, OptionPage page) { + } + + /** + * Deserialize part of config and load values + * + * @param json json to deserialize + * @param instance instance of target class + */ + protected void deserializePart(JsonObject json, Object instance) { + Class clazz = instance.getClass(); + for (Map.Entry element : json.entrySet()) { + String name = element.getKey(); + JsonElement value = element.getValue(); + if (value.isJsonObject()) { + Optional> innerClass = Arrays.stream(clazz.getClasses()).filter(aClass -> aClass.getSimpleName().equals(name)).findFirst(); + if (innerClass.isPresent()) { + deserializePart(value.getAsJsonObject(), innerClass.get()); + continue; + } + } + try { + Field field = clazz.getField(name); + TypeAdapter adapter = gson.getAdapter(field.getType()); + Object object = adapter.fromJsonTree(value); + field.setAccessible(true); + field.set(instance, object); + } catch (Exception ignored) { + } + } + } + + /** + * Function to open the gui of this mod + */ + public void openGui() { + if (mod == null) return; + GuiUtils.displayScreen(new OneConfigGui(new ModConfigPage(mod.defaultPage))); + } + + /** + * Disable an option if a certain condition is not met + * + * @param option The name of the field, or if the field is in a page "pageName.fieldName" + * @param condition The condition that has to be met for the option to be enabled + */ + protected void addDependency(String option, Supplier condition) { + if (!optionNames.containsKey(option)) return; + optionNames.get(option).setDependency(condition); + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java b/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java deleted file mode 100644 index b867bc0..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java +++ /dev/null @@ -1,91 +0,0 @@ -package cc.polyfrost.oneconfig.config; - -import cc.polyfrost.oneconfig.config.core.OneColor; -import cc.polyfrost.oneconfig.config.data.Mod; -import cc.polyfrost.oneconfig.config.interfaces.Config; -import com.google.gson.JsonParser; - -import java.awt.*; -import java.io.*; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; - -public class OneConfigConfig extends Config { - - // the color library - public static final int TRANSPARENT = new Color(0, 0, 0, 0).getRGB(); // Transparent - public static final int BLACK = new Color(0, 0, 0, 255).getRGB(); // Black - public static final int GRAY_900 = new Color(13, 14, 15, 255).getRGB(); // Gray 900 - public static final int GRAY_900_80 = new Color(13, 14, 15, 204).getRGB(); // Gray 900 80% - public static final int GRAY_800 = new Color(21, 22, 23, 255).getRGB(); // Gray 800 - public static final int GRAY_800_95 = new Color(21, 22, 23, 242).getRGB(); - public static final int GRAY_700 = new Color(34, 35, 38, 255).getRGB(); // Gray 700 - public static final int GRAY_600 = new Color(42, 44, 48, 255).getRGB(); // Gray 600 - public static final int GRAY_500 = new Color(49, 51, 56, 255).getRGB(); // Gray 500 // button sidebar hover, button gray normal - public static final int GRAY_500_80 = new Color(49, 51, 56, 204).getRGB(); // Gray 500 80% // button sidebar pressed - public static final int GRAY_400 = new Color(55, 59, 69, 255).getRGB(); // Gray 400 - public static final int GRAY_300 = new Color(73, 79, 92, 255).getRGB(); // Gray 300 // button gray hover - public static final int GRAY_400_80 = new Color(55, 59, 69, 204).getRGB(); // Gray 400 80% // button gray pressed - public static final int PRIMARY_800 = new Color(13, 51, 128, 255).getRGB(); // Blue 800 - public static final int PRIMARY_700 = new Color(18, 71, 178, 255).getRGB(); // Blue 700 - public static final int PRIMARY_700_80 = new Color(18, 71, 178, 204).getRGB(); // Blue 700 80% - public static final int PRIMARY_600 = new Color(20, 82, 204, 255).getRGB(); // Blue 600 // button blue normal - public static final int PRIMARY_500 = new Color(25, 103, 255, 255).getRGB(); // Blue 500 // button blue hover - public static final int PRIMARY_400 = new Color(48, 129, 242, 255).getRGB(); - public static final int WHITE_50 = new Color(255, 255, 255, 127).getRGB(); // White 60% - public static final int WHITE_60 = new Color(255, 255, 255, 153).getRGB(); // White 60% - public static final int WHITE_80 = new Color(255, 255, 255, 204).getRGB(); // White 80% - public static final int WHITE_90 = new Color(255, 255, 255, 229).getRGB(); // White 90% - public static final int WHITE_95 = new Color(255, 255, 255, 242).getRGB(); // White 90% - public static final int WHITE = new Color(255, 255, 255, 255).getRGB(); // White 100% - public static final int SUCCESS_600 = new Color(3, 152, 85).getRGB(); - public static final int SUCCESS_700 = new Color(2, 121, 72).getRGB(); - public static final int WARNING_500 = new Color(247, 144, 9).getRGB(); - public static final int WARNING_600 = new Color(220, 104, 3).getRGB(); - public static final int ERROR_600_80 = new Color(217, 32, 32, 204).getRGB(); - public static final int ERROR_600 = new Color(217, 32, 32).getRGB(); - public static final int ERROR_700 = new Color(180, 24, 24).getRGB(); // Red 700 - public static final int ERROR_800 = new Color(145, 24, 24).getRGB(); // Red 800 - public static final int ERROR_800_80 = new Color(145, 24, 24, 204).getRGB(); // Red 800 - public static final int ERROR_300 = new Color(253, 155, 155).getRGB(); - public static final int ERROR_300_80 = new Color(253, 155, 155, 204).getRGB(); - public static String currentProfile = "Default Profile"; - public static ArrayList favoriteMods = new ArrayList<>(); - public static ArrayList favoriteColors = new ArrayList<>(); - public static ArrayList recentColors = new ArrayList<>(); - public static boolean ROUNDED_CORNERS = true; - public static float CORNER_RADIUS_WIN = 20f; - public static float CORNER_RADIUS = 12f; - - public static boolean allShowShortCut = 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(new JsonParser().parse(reader).getAsJsonObject(), this); - } catch (IOException e) { - e.printStackTrace(); - } - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilanceConfig.java b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilanceConfig.java deleted file mode 100644 index fa4f058..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilanceConfig.java +++ /dev/null @@ -1,202 +0,0 @@ -package cc.polyfrost.oneconfig.config.compatibility; - -import cc.polyfrost.oneconfig.config.core.ConfigCore; -import cc.polyfrost.oneconfig.config.core.OneColor; -import cc.polyfrost.oneconfig.config.data.Mod; -import cc.polyfrost.oneconfig.config.data.OptionCategory; -import cc.polyfrost.oneconfig.config.data.OptionPage; -import cc.polyfrost.oneconfig.config.data.OptionSubcategory; -import cc.polyfrost.oneconfig.config.interfaces.BasicOption; -import cc.polyfrost.oneconfig.config.interfaces.Config; -import cc.polyfrost.oneconfig.gui.elements.config.*; -import gg.essential.vigilance.Vigilant; -import gg.essential.vigilance.data.*; -import kotlin.reflect.KMutableProperty0; -import kotlin.reflect.jvm.ReflectJvmMapping; -import net.minecraft.client.resources.I18n; - -import java.awt.*; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Objects; - -/** - * This class is used to convert the Vigilance config to the new config system. - * It is not meant to be used outside the config system. - */ -public class VigilanceConfig extends Config { - public final Vigilant vigilant; - - public VigilanceConfig(Mod modData, String configFile, Vigilant vigilant) { - super(modData, configFile); - this.vigilant = vigilant; - init(modData); - } - - @Override - public void init(Mod mod) { - if (vigilant != null) { - mod.config = this; - generateOptionsList(mod.defaultPage); - ConfigCore.oneConfigMods.add(mod); - this.mod = mod; - } - } - - @Override - public void save() { - vigilant.markDirty(); - vigilant.writeData(); - } - - @Override - public void load() { - //no-op - } - - private void generateOptionsList(OptionPage page) { - for (PropertyData option : ((VigilantAccessor) vigilant).getPropertyCollector().getProperties()) { - PropertyAttributesExt attributes = option.getAttributesExt(); - if (attributes.getHidden()) continue; - if (!page.categories.containsKey(getCategory(attributes))) - page.categories.put(getCategory(attributes), new OptionCategory()); - OptionCategory category = page.categories.get(getCategory(attributes)); - if (category.subcategories.size() == 0 || !category.subcategories.get(category.subcategories.size() - 1).getName().equals(getSubcategory(attributes))) - category.subcategories.add(new OptionSubcategory(getSubcategory(attributes))); - ArrayList options = category.subcategories.get(category.subcategories.size() - 1).options; - switch (attributes.getType()) { - case SWITCH: - options.add(new ConfigSwitch(getFieldOfProperty(option), option.getInstance(), getName(attributes), 2)); - break; - case CHECKBOX: - options.add(new ConfigCheckbox(getFieldOfProperty(option), option.getInstance(), getName(attributes), 2)); - break; - case PARAGRAPH: - case TEXT: - options.add(new ConfigTextBox(getFieldOfProperty(option), option.getInstance(), getName(attributes), 2, attributes.getPlaceholder(), attributes.getProtected(), attributes.getType() == PropertyType.PARAGRAPH)); - break; - case SELECTOR: - options.add(new ConfigDropdown(getFieldOfProperty(option), option.getInstance(), getName(attributes), 2, attributes.getOptions().toArray(new String[0]))); - break; - case PERCENT_SLIDER: - options.add(new ConfigSlider(getFieldOfProperty(option), option.getInstance(), getName(attributes), 2, 0, 1, 0)); - break; - case DECIMAL_SLIDER: - options.add(new ConfigSlider(getFieldOfProperty(option), option.getInstance(), getName(attributes), 2, attributes.getMinF(), attributes.getMaxF(), 0)); - break; - case SLIDER: - options.add(new ConfigSlider(getFieldOfProperty(option), option.getInstance(), getName(attributes), 2, attributes.getMin(), attributes.getMax(), 0)); - break; - case COLOR: - options.add(new CompatConfigColorElement(getFieldOfProperty(option), option.getInstance(), getName(attributes), 2)); - break; - case BUTTON: - options.add(new ConfigButton(() -> ((CallablePropertyValue) option.getValue()).invoke(option.getInstance()), option.getInstance(), getName(attributes), 2, attributes.getPlaceholder().isEmpty() ? "Activate" : attributes.getPlaceholder())); - break; - } - if (attributes.getType() == PropertyType.SWITCH || attributes.getType() == PropertyType.CHECKBOX) { - optionNames.put(PropertyKt.fullPropertyPath(option.getAttributesExt()), options.get(options.size() - 1)); - } - } - } - - private Field getFieldOfProperty(PropertyData data) { - if (data.getValue() instanceof FieldBackedPropertyValue) { - FieldBackedPropertyValue fieldBackedPropertyValue = (FieldBackedPropertyValue) data.getValue(); - try { - Field field = fieldBackedPropertyValue.getClass().getDeclaredField("field"); - field.setAccessible(true); - return (Field) field.get(fieldBackedPropertyValue); - } catch (IllegalAccessException | NoSuchFieldException e) { - throw new RuntimeException(e); - } - } else if (data.getValue() instanceof ValueBackedPropertyValue) { - ValueBackedPropertyValue valueBackedPropertyValue = (ValueBackedPropertyValue) data.getValue(); - try { - Field field = valueBackedPropertyValue.getClass().getDeclaredField("obj"); - field.setAccessible(true); - return (Field) field.get(valueBackedPropertyValue); - } catch (IllegalAccessException | NoSuchFieldException e) { - throw new RuntimeException(e); - } - } else if (data.getValue() instanceof KPropertyBackedPropertyValue) { - KPropertyBackedPropertyValue kPropertyBackedPropertyValue = (KPropertyBackedPropertyValue) data.getValue(); - try { - Field field = kPropertyBackedPropertyValue.getClass().getDeclaredField("property"); - field.setAccessible(true); - KMutableProperty0 property = (KMutableProperty0) field.get(kPropertyBackedPropertyValue); - return ReflectJvmMapping.getJavaField(property); - } catch (IllegalAccessException | NoSuchFieldException e) { - throw new RuntimeException(e); - } - } else throw new RuntimeException("Unknown property value type: " + data.getValue().getClass()); - } - - private String getName(PropertyAttributesExt ext) { - try { - PropertyAttributesExt.class.getDeclaredField("i18nName").setAccessible(true); - return I18n.format((String) PropertyAttributesExt.class.getDeclaredField("i18nName").get(ext)); - } catch (IllegalAccessException | NoSuchFieldException e) { - return ext.getName(); - } - } - - private String getCategory(PropertyAttributesExt ext) { - try { - PropertyAttributesExt.class.getDeclaredField("i18nCategory").setAccessible(true); - return I18n.format((String) PropertyAttributesExt.class.getDeclaredField("i18nCategory").get(ext)); - } catch (IllegalAccessException | NoSuchFieldException e) { - return ext.getCategory(); - } - } - - private String getSubcategory(PropertyAttributesExt ext) { - try { - PropertyAttributesExt.class.getDeclaredField("i18nSubcategory").setAccessible(true); - return I18n.format((String) PropertyAttributesExt.class.getDeclaredField("i18nSubcategory").get(ext)); - } catch (IllegalAccessException | NoSuchFieldException e) { - return ext.getSubcategory(); - } - } - - @SuppressWarnings("unused") - public void addDependency(PropertyData property, PropertyData dependency) { - BasicOption option = optionNames.get(PropertyKt.fullPropertyPath(property.getAttributesExt())); - if (option != null) { - option.setDependency(() -> Objects.equals(dependency.getValue().getValue(vigilant), true)); - } - } - - private static class CompatConfigColorElement extends ConfigColorElement { - private final Field color; - private Color prevColor = null; - private OneColor cachedColor = null; - - public CompatConfigColorElement(Field color, Vigilant parent, String name, int size) { - super(null, parent, name, size); - this.color = color; - } - - @Override - protected Object get() throws IllegalAccessException { - Color currentColor = (Color) color.get(parent); - if (cachedColor == null || prevColor != color.get(parent)) { - cachedColor = new OneColor(currentColor); - } - prevColor = currentColor; - return cachedColor; - } - - @Override - protected void setColor(OneColor color) { - if (cachedColor != color) { - Color newColor = new Color(color.getRGB(), true); - try { - this.color.set(parent, newColor); - } catch (IllegalAccessException ignored) { - - } - } - } - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilantAccessor.java b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilantAccessor.java deleted file mode 100644 index ca2b1da..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilantAccessor.java +++ /dev/null @@ -1,11 +0,0 @@ -package cc.polyfrost.oneconfig.config.compatibility; - -import gg.essential.vigilance.data.PropertyCollector; - -/** - * Interface for accessing the {@link PropertyCollector} in a Vigilant config. - *

Not recommended for non-internal OneConfig usage, as Systemless will get really angry at us

- */ -public interface VigilantAccessor { - PropertyCollector getPropertyCollector(); -} diff --git a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig.java b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig.java new file mode 100644 index 0000000..cfa717f --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig.java @@ -0,0 +1,202 @@ +package cc.polyfrost.oneconfig.config.compatibility.vigilance; + +import cc.polyfrost.oneconfig.config.core.ConfigCore; +import cc.polyfrost.oneconfig.config.core.OneColor; +import cc.polyfrost.oneconfig.config.data.Mod; +import cc.polyfrost.oneconfig.config.elements.OptionCategory; +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.config.Config; +import cc.polyfrost.oneconfig.gui.elements.config.*; +import gg.essential.vigilance.Vigilant; +import gg.essential.vigilance.data.*; +import kotlin.reflect.KMutableProperty0; +import kotlin.reflect.jvm.ReflectJvmMapping; +import net.minecraft.client.resources.I18n; + +import java.awt.*; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Objects; + +/** + * This class is used to convert the Vigilance config to the new config system. + * It is not meant to be used outside the config system. + */ +public class VigilanceConfig extends Config { + public final Vigilant vigilant; + + public VigilanceConfig(Mod modData, String configFile, Vigilant vigilant) { + super(modData, configFile); + this.vigilant = vigilant; + init(modData); + } + + @Override + public void init(Mod mod) { + if (vigilant != null) { + mod.config = this; + generateOptionsList(mod.defaultPage); + ConfigCore.oneConfigMods.add(mod); + this.mod = mod; + } + } + + @Override + public void save() { + vigilant.markDirty(); + vigilant.writeData(); + } + + @Override + public void load() { + //no-op + } + + private void generateOptionsList(OptionPage page) { + for (PropertyData option : ((VigilantAccessor) vigilant).getPropertyCollector().getProperties()) { + PropertyAttributesExt attributes = option.getAttributesExt(); + if (attributes.getHidden()) continue; + if (!page.categories.containsKey(getCategory(attributes))) + page.categories.put(getCategory(attributes), new OptionCategory()); + OptionCategory category = page.categories.get(getCategory(attributes)); + if (category.subcategories.size() == 0 || !category.subcategories.get(category.subcategories.size() - 1).getName().equals(getSubcategory(attributes))) + category.subcategories.add(new OptionSubcategory(getSubcategory(attributes))); + ArrayList options = category.subcategories.get(category.subcategories.size() - 1).options; + switch (attributes.getType()) { + case SWITCH: + options.add(new ConfigSwitch(getFieldOfProperty(option), option.getInstance(), getName(attributes), 2)); + break; + case CHECKBOX: + options.add(new ConfigCheckbox(getFieldOfProperty(option), option.getInstance(), getName(attributes), 2)); + break; + case PARAGRAPH: + case TEXT: + options.add(new ConfigTextBox(getFieldOfProperty(option), option.getInstance(), getName(attributes), 2, attributes.getPlaceholder(), attributes.getProtected(), attributes.getType() == PropertyType.PARAGRAPH)); + break; + case SELECTOR: + options.add(new ConfigDropdown(getFieldOfProperty(option), option.getInstance(), getName(attributes), 2, attributes.getOptions().toArray(new String[0]))); + break; + case PERCENT_SLIDER: + options.add(new ConfigSlider(getFieldOfProperty(option), option.getInstance(), getName(attributes), 2, 0, 1, 0)); + break; + case DECIMAL_SLIDER: + options.add(new ConfigSlider(getFieldOfProperty(option), option.getInstance(), getName(attributes), 2, attributes.getMinF(), attributes.getMaxF(), 0)); + break; + case SLIDER: + options.add(new ConfigSlider(getFieldOfProperty(option), option.getInstance(), getName(attributes), 2, attributes.getMin(), attributes.getMax(), 0)); + break; + case COLOR: + options.add(new CompatConfigColorElement(getFieldOfProperty(option), option.getInstance(), getName(attributes), 2)); + break; + case BUTTON: + options.add(new ConfigButton(() -> ((CallablePropertyValue) option.getValue()).invoke(option.getInstance()), option.getInstance(), getName(attributes), 2, attributes.getPlaceholder().isEmpty() ? "Activate" : attributes.getPlaceholder())); + break; + } + if (attributes.getType() == PropertyType.SWITCH || attributes.getType() == PropertyType.CHECKBOX) { + optionNames.put(PropertyKt.fullPropertyPath(option.getAttributesExt()), options.get(options.size() - 1)); + } + } + } + + private Field getFieldOfProperty(PropertyData data) { + if (data.getValue() instanceof FieldBackedPropertyValue) { + FieldBackedPropertyValue fieldBackedPropertyValue = (FieldBackedPropertyValue) data.getValue(); + try { + Field field = fieldBackedPropertyValue.getClass().getDeclaredField("field"); + field.setAccessible(true); + return (Field) field.get(fieldBackedPropertyValue); + } catch (IllegalAccessException | NoSuchFieldException e) { + throw new RuntimeException(e); + } + } else if (data.getValue() instanceof ValueBackedPropertyValue) { + ValueBackedPropertyValue valueBackedPropertyValue = (ValueBackedPropertyValue) data.getValue(); + try { + Field field = valueBackedPropertyValue.getClass().getDeclaredField("obj"); + field.setAccessible(true); + return (Field) field.get(valueBackedPropertyValue); + } catch (IllegalAccessException | NoSuchFieldException e) { + throw new RuntimeException(e); + } + } else if (data.getValue() instanceof KPropertyBackedPropertyValue) { + KPropertyBackedPropertyValue kPropertyBackedPropertyValue = (KPropertyBackedPropertyValue) data.getValue(); + try { + Field field = kPropertyBackedPropertyValue.getClass().getDeclaredField("property"); + field.setAccessible(true); + KMutableProperty0 property = (KMutableProperty0) field.get(kPropertyBackedPropertyValue); + return ReflectJvmMapping.getJavaField(property); + } catch (IllegalAccessException | NoSuchFieldException e) { + throw new RuntimeException(e); + } + } else throw new RuntimeException("Unknown property value type: " + data.getValue().getClass()); + } + + private String getName(PropertyAttributesExt ext) { + try { + PropertyAttributesExt.class.getDeclaredField("i18nName").setAccessible(true); + return I18n.format((String) PropertyAttributesExt.class.getDeclaredField("i18nName").get(ext)); + } catch (IllegalAccessException | NoSuchFieldException e) { + return ext.getName(); + } + } + + private String getCategory(PropertyAttributesExt ext) { + try { + PropertyAttributesExt.class.getDeclaredField("i18nCategory").setAccessible(true); + return I18n.format((String) PropertyAttributesExt.class.getDeclaredField("i18nCategory").get(ext)); + } catch (IllegalAccessException | NoSuchFieldException e) { + return ext.getCategory(); + } + } + + private String getSubcategory(PropertyAttributesExt ext) { + try { + PropertyAttributesExt.class.getDeclaredField("i18nSubcategory").setAccessible(true); + return I18n.format((String) PropertyAttributesExt.class.getDeclaredField("i18nSubcategory").get(ext)); + } catch (IllegalAccessException | NoSuchFieldException e) { + return ext.getSubcategory(); + } + } + + @SuppressWarnings("unused") + public void addDependency(PropertyData property, PropertyData dependency) { + BasicOption option = optionNames.get(PropertyKt.fullPropertyPath(property.getAttributesExt())); + if (option != null) { + option.setDependency(() -> Objects.equals(dependency.getValue().getValue(vigilant), true)); + } + } + + private static class CompatConfigColorElement extends ConfigColorElement { + private final Field color; + private Color prevColor = null; + private OneColor cachedColor = null; + + public CompatConfigColorElement(Field color, Vigilant parent, String name, int size) { + super(null, parent, name, size); + this.color = color; + } + + @Override + protected Object get() throws IllegalAccessException { + Color currentColor = (Color) color.get(parent); + if (cachedColor == null || prevColor != color.get(parent)) { + cachedColor = new OneColor(currentColor); + } + prevColor = currentColor; + return cachedColor; + } + + @Override + protected void setColor(OneColor color) { + if (cachedColor != color) { + Color newColor = new Color(color.getRGB(), true); + try { + this.color.set(parent, newColor); + } catch (IllegalAccessException ignored) { + + } + } + } + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilantAccessor.java b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilantAccessor.java new file mode 100644 index 0000000..c449bd9 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilantAccessor.java @@ -0,0 +1,11 @@ +package cc.polyfrost.oneconfig.config.compatibility.vigilance; + +import gg.essential.vigilance.data.PropertyCollector; + +/** + * Interface for accessing the {@link PropertyCollector} in a Vigilant config. + *

Not recommended for non-internal OneConfig usage, as Systemless will get really angry at us

+ */ +public interface VigilantAccessor { + PropertyCollector getPropertyCollector(); +} diff --git a/src/main/java/cc/polyfrost/oneconfig/config/data/Mod.java b/src/main/java/cc/polyfrost/oneconfig/config/data/Mod.java index 241dca7..090d1f8 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/data/Mod.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/data/Mod.java @@ -1,7 +1,8 @@ package cc.polyfrost.oneconfig.config.data; -import cc.polyfrost.oneconfig.config.interfaces.Config; -import cc.polyfrost.oneconfig.config.migration.Migrator; +import cc.polyfrost.oneconfig.config.Config; +import cc.polyfrost.oneconfig.config.elements.OptionPage; +import cc.polyfrost.oneconfig.config.migration.vigilance.Migrator; import org.jetbrains.annotations.Nullable; public class Mod { diff --git a/src/main/java/cc/polyfrost/oneconfig/config/data/OptionCategory.java b/src/main/java/cc/polyfrost/oneconfig/config/data/OptionCategory.java deleted file mode 100644 index 76b2b34..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/config/data/OptionCategory.java +++ /dev/null @@ -1,7 +0,0 @@ -package cc.polyfrost.oneconfig.config.data; - -import java.util.ArrayList; - -public class OptionCategory { - public final ArrayList subcategories = new ArrayList<>(); -} diff --git a/src/main/java/cc/polyfrost/oneconfig/config/data/OptionPage.java b/src/main/java/cc/polyfrost/oneconfig/config/data/OptionPage.java deleted file mode 100644 index 32a07b9..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/config/data/OptionPage.java +++ /dev/null @@ -1,19 +0,0 @@ -package cc.polyfrost.oneconfig.config.data; - -import java.util.LinkedHashMap; - -public class OptionPage { - public final String name; - public final Mod mod; - /** - * Depth 1 = categories - * Depth 2 = subcategories - * Depth 3 = list of options - */ - public final LinkedHashMap categories = new LinkedHashMap<>(); - - public OptionPage(String name, Mod mod) { - this.name = name; - this.mod = mod; - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/config/data/OptionSubcategory.java b/src/main/java/cc/polyfrost/oneconfig/config/data/OptionSubcategory.java deleted file mode 100644 index e69e077..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/config/data/OptionSubcategory.java +++ /dev/null @@ -1,122 +0,0 @@ -package cc.polyfrost.oneconfig.config.data; - -import cc.polyfrost.oneconfig.config.OneConfigConfig; -import cc.polyfrost.oneconfig.config.interfaces.BasicOption; -import cc.polyfrost.oneconfig.gui.OneConfigGui; -import cc.polyfrost.oneconfig.gui.elements.config.ConfigPageButton; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; -import cc.polyfrost.oneconfig.lwjgl.font.Fonts; - -import java.util.ArrayList; - -public class OptionSubcategory { - private final String name; - public ArrayList options = new ArrayList<>(); - public ArrayList topButtons = new ArrayList<>(); - public ArrayList bottomButtons = new ArrayList<>(); - private ArrayList filteredOptions = new ArrayList<>(); - private int drawLastY; - - public OptionSubcategory(String name) { - this.name = name; - } - - public int draw(long vg, int x, int y) { - String filter = OneConfigGui.INSTANCE == null ? "" : OneConfigGui.INSTANCE.getSearchValue().toLowerCase().trim(); - filteredOptions = new ArrayList<>(options); - ArrayList filteredTop = new ArrayList<>(topButtons); - ArrayList filteredBottom = new ArrayList<>(bottomButtons); - if (!filter.equals("") && !name.toLowerCase().contains(filter)) { - filteredOptions.clear(); - filteredTop.clear(); - filteredBottom.clear(); - for (BasicOption option : options) { - if (option.getName().toLowerCase().contains(filter)) filteredOptions.add(option); - } - for (ConfigPageButton page : topButtons) { - if (page.getName().toLowerCase().contains(filter) || page.description.toLowerCase().contains(filter)) - filteredTop.add(page); - } - for (ConfigPageButton page : bottomButtons) { - if (page.getName().toLowerCase().contains(filter) || page.description.toLowerCase().contains(filter)) - filteredBottom.add(page); - } - } - if (filteredOptions.size() == 0 && filteredTop.size() == 0 && filteredBottom.size() == 0) return 0; - int optionY = y; - if (!name.equals("")) { - RenderManager.drawText(vg, name, x, y + 12, OneConfigConfig.WHITE_90, 24, Fonts.MEDIUM); - optionY += 36; - } - - for (ConfigPageButton page : filteredTop) { - page.draw(vg, x, optionY); - optionY += page.getHeight() + 16; - } - - if (filteredOptions.size() > 0) { - int backgroundSize = 16; - for (int i = 0; i < filteredOptions.size(); i++) { - BasicOption option = filteredOptions.get(i); - if (i + 1 < filteredOptions.size()) { - BasicOption nextOption = filteredOptions.get(i + 1); - if (option.size == 1 && option.hasHalfSize() && nextOption.size == 1 && nextOption.hasHalfSize()) { - backgroundSize += Math.max(option.getHeight(), nextOption.getHeight()) + 16; - i++; - continue; - } - } - backgroundSize += option.getHeight() + 16; - } - RenderManager.drawRoundedRect(vg, x - 16, optionY, 1024, backgroundSize, OneConfigConfig.GRAY_900, 20); - optionY += 16; - } - - drawLastY = optionY; - if (filteredOptions.size() > 0) { - for (int i = 0; i < filteredOptions.size(); i++) { - BasicOption option = filteredOptions.get(i); - option.draw(vg, x, optionY); - if (i + 1 < filteredOptions.size()) { - BasicOption nextOption = filteredOptions.get(i + 1); - if (option.size == 1 && option.hasHalfSize() && nextOption.size == 1 && nextOption.hasHalfSize()) { - nextOption.draw(vg, x + 512, optionY); - optionY += Math.max(option.getHeight(), nextOption.getHeight()) + 16; - i++; - continue; - } - } - optionY += option.getHeight() + 16; - } - optionY += 16; - } - - for (ConfigPageButton page : filteredBottom) { - page.draw(vg, x, optionY); - optionY += page.getHeight() + 16; - } - - return optionY - y; - } - - public void drawLast(long vg, int x) { - for (int i = 0; i < filteredOptions.size(); i++) { - BasicOption option = filteredOptions.get(i); - option.drawLast(vg, x, drawLastY); - if (i + 1 < filteredOptions.size()) { - BasicOption nextOption = filteredOptions.get(i + 1); - if (option.size == 1 && option.hasHalfSize() && nextOption.size == 1 && nextOption.hasHalfSize()) { - nextOption.drawLast(vg, x + 512, drawLastY); - drawLastY += Math.max(option.getHeight(), nextOption.getHeight()) + 16; - i++; - continue; - } - } - drawLastY += option.getHeight() + 16; - } - } - - public String getName() { - return name; - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java b/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java new file mode 100644 index 0000000..d4efeaa --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java @@ -0,0 +1,98 @@ +package cc.polyfrost.oneconfig.config.elements; + +import java.lang.reflect.Field; +import java.util.function.Supplier; + +@SuppressWarnings({"unused"}) +public abstract class BasicOption { + public final int size; + protected final Field field; + protected final String name; + protected final Object parent; + private Supplier dependency; + + /** + * Initialize option + * + * @param field variable attached to option (null for category) + * @param parent the parent object of the field, used for getting and setting the variable + * @param name name of option + * @param size size of option, 0 for single column, 1 for double. + */ + public BasicOption(Field field, Object parent, String name, int size) { + this.field = field; + this.parent = parent; + this.name = name; + this.size = size; + if (field != null) field.setAccessible(true); + } + + /** + * @param object Java object to set the variable to + */ + protected void set(Object object) throws IllegalAccessException { + if (field == null) return; + field.set(parent, object); + } + + /** + * @return value of variable as Java object + */ + protected Object get() throws IllegalAccessException { + if (field == null) return null; + return field.get(parent); + } + + /** + * @return height of option to align other options accordingly + */ + public abstract int getHeight(); + + /** + * Function that gets called when drawing option + * + * @param vg NanoVG context + * @param x x position + * @param y y position + */ + public abstract void draw(long vg, int x, int y); + + /** + * Function that gets called last drawing option, + * should be used for things that draw above other options + * + * @param vg NanoVG context + * @param x x position + * @param y y position + */ + public void drawLast(long vg, int x, int y) { + } + + /** + * Function that gets called when a key is typed + * + * @param key char that has been typed + * @param keyCode code of key + */ + public void keyTyped(char key, int keyCode) { + } + + /** + * @return If the component has an option to render at half size + */ + public boolean hasHalfSize() { + return true; + } + + public String getName() { + return name; + } + + public void setDependency(Supplier supplier) { + this.dependency = supplier; + } + + protected boolean isEnabled() { + return dependency == null || dependency.get(); + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionCategory.java b/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionCategory.java new file mode 100644 index 0000000..4a37bfc --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionCategory.java @@ -0,0 +1,7 @@ +package cc.polyfrost.oneconfig.config.elements; + +import java.util.ArrayList; + +public class OptionCategory { + public final ArrayList subcategories = new ArrayList<>(); +} diff --git a/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionPage.java b/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionPage.java new file mode 100644 index 0000000..5eaac8b --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionPage.java @@ -0,0 +1,16 @@ +package cc.polyfrost.oneconfig.config.elements; + +import cc.polyfrost.oneconfig.config.data.Mod; + +import java.util.LinkedHashMap; + +public class OptionPage { + public final String name; + public final Mod mod; + public final LinkedHashMap categories = new LinkedHashMap<>(); + + public OptionPage(String name, Mod mod) { + this.name = name; + this.mod = mod; + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java b/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java new file mode 100644 index 0000000..ff1d770 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java @@ -0,0 +1,122 @@ +package cc.polyfrost.oneconfig.config.elements; + +import cc.polyfrost.oneconfig.gui.Colors; +import cc.polyfrost.oneconfig.config.elements.BasicOption; +import cc.polyfrost.oneconfig.gui.OneConfigGui; +import cc.polyfrost.oneconfig.gui.elements.config.ConfigPageButton; +import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.renderer.font.Fonts; + +import java.util.ArrayList; + +public class OptionSubcategory { + private final String name; + public ArrayList options = new ArrayList<>(); + public ArrayList topButtons = new ArrayList<>(); + public ArrayList bottomButtons = new ArrayList<>(); + private ArrayList filteredOptions = new ArrayList<>(); + private int drawLastY; + + public OptionSubcategory(String name) { + this.name = name; + } + + public int draw(long vg, int x, int y) { + String filter = OneConfigGui.INSTANCE == null ? "" : OneConfigGui.INSTANCE.getSearchValue().toLowerCase().trim(); + filteredOptions = new ArrayList<>(options); + ArrayList filteredTop = new ArrayList<>(topButtons); + ArrayList filteredBottom = new ArrayList<>(bottomButtons); + if (!filter.equals("") && !name.toLowerCase().contains(filter)) { + filteredOptions.clear(); + filteredTop.clear(); + filteredBottom.clear(); + for (BasicOption option : options) { + if (option.getName().toLowerCase().contains(filter)) filteredOptions.add(option); + } + for (ConfigPageButton page : topButtons) { + if (page.getName().toLowerCase().contains(filter) || page.description.toLowerCase().contains(filter)) + filteredTop.add(page); + } + for (ConfigPageButton page : bottomButtons) { + if (page.getName().toLowerCase().contains(filter) || page.description.toLowerCase().contains(filter)) + filteredBottom.add(page); + } + } + if (filteredOptions.size() == 0 && filteredTop.size() == 0 && filteredBottom.size() == 0) return 0; + int optionY = y; + if (!name.equals("")) { + RenderManager.drawText(vg, name, x, y + 12, Colors.WHITE_90, 24, Fonts.MEDIUM); + optionY += 36; + } + + for (ConfigPageButton page : filteredTop) { + page.draw(vg, x, optionY); + optionY += page.getHeight() + 16; + } + + if (filteredOptions.size() > 0) { + int backgroundSize = 16; + for (int i = 0; i < filteredOptions.size(); i++) { + BasicOption option = filteredOptions.get(i); + if (i + 1 < filteredOptions.size()) { + BasicOption nextOption = filteredOptions.get(i + 1); + if (option.size == 1 && option.hasHalfSize() && nextOption.size == 1 && nextOption.hasHalfSize()) { + backgroundSize += Math.max(option.getHeight(), nextOption.getHeight()) + 16; + i++; + continue; + } + } + backgroundSize += option.getHeight() + 16; + } + RenderManager.drawRoundedRect(vg, x - 16, optionY, 1024, backgroundSize, Colors.GRAY_900, 20); + optionY += 16; + } + + drawLastY = optionY; + if (filteredOptions.size() > 0) { + for (int i = 0; i < filteredOptions.size(); i++) { + BasicOption option = filteredOptions.get(i); + option.draw(vg, x, optionY); + if (i + 1 < filteredOptions.size()) { + BasicOption nextOption = filteredOptions.get(i + 1); + if (option.size == 1 && option.hasHalfSize() && nextOption.size == 1 && nextOption.hasHalfSize()) { + nextOption.draw(vg, x + 512, optionY); + optionY += Math.max(option.getHeight(), nextOption.getHeight()) + 16; + i++; + continue; + } + } + optionY += option.getHeight() + 16; + } + optionY += 16; + } + + for (ConfigPageButton page : filteredBottom) { + page.draw(vg, x, optionY); + optionY += page.getHeight() + 16; + } + + return optionY - y; + } + + public void drawLast(long vg, int x) { + for (int i = 0; i < filteredOptions.size(); i++) { + BasicOption option = filteredOptions.get(i); + option.drawLast(vg, x, drawLastY); + if (i + 1 < filteredOptions.size()) { + BasicOption nextOption = filteredOptions.get(i + 1); + if (option.size == 1 && option.hasHalfSize() && nextOption.size == 1 && nextOption.hasHalfSize()) { + nextOption.drawLast(vg, x + 512, drawLastY); + drawLastY += Math.max(option.getHeight(), nextOption.getHeight()) + 16; + i++; + continue; + } + } + drawLastY += option.getHeight() + 16; + } + } + + public String getName() { + return name; + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/config/interfaces/BasicOption.java b/src/main/java/cc/polyfrost/oneconfig/config/interfaces/BasicOption.java deleted file mode 100644 index d4b4498..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/config/interfaces/BasicOption.java +++ /dev/null @@ -1,98 +0,0 @@ -package cc.polyfrost.oneconfig.config.interfaces; - -import java.lang.reflect.Field; -import java.util.function.Supplier; - -@SuppressWarnings({"unused"}) -public abstract class BasicOption { - public final int size; - protected final Field field; - protected final String name; - protected final Object parent; - private Supplier dependency; - - /** - * Initialize option - * - * @param field variable attached to option (null for category) - * @param parent the parent object of the field, used for getting and setting the variable - * @param name name of option - * @param size size of option, 0 for single column, 1 for double. - */ - public BasicOption(Field field, Object parent, String name, int size) { - this.field = field; - this.parent = parent; - this.name = name; - this.size = size; - if (field != null) field.setAccessible(true); - } - - /** - * @param object Java object to set the variable to - */ - protected void set(Object object) throws IllegalAccessException { - if (field == null) return; - field.set(parent, object); - } - - /** - * @return value of variable as Java object - */ - protected Object get() throws IllegalAccessException { - if (field == null) return null; - return field.get(parent); - } - - /** - * @return height of option to align other options accordingly - */ - public abstract int getHeight(); - - /** - * Function that gets called when drawing option - * - * @param vg NanoVG context - * @param x x position - * @param y y position - */ - public abstract void draw(long vg, int x, int y); - - /** - * Function that gets called last drawing option, - * should be used for things that draw above other options - * - * @param vg NanoVG context - * @param x x position - * @param y y position - */ - public void drawLast(long vg, int x, int y) { - } - - /** - * Function that gets called when a key is typed - * - * @param key char that has been typed - * @param keyCode code of key - */ - public void keyTyped(char key, int keyCode) { - } - - /** - * @return If the component has an option to render at half size - */ - public boolean hasHalfSize() { - return true; - } - - public String getName() { - return name; - } - - public void setDependency(Supplier supplier) { - this.dependency = supplier; - } - - protected boolean isEnabled() { - return dependency == null || dependency.get(); - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java b/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java deleted file mode 100644 index 8eb5eb1..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java +++ /dev/null @@ -1,259 +0,0 @@ -package cc.polyfrost.oneconfig.config.interfaces; - -import cc.polyfrost.oneconfig.config.annotations.ConfigPage; -import cc.polyfrost.oneconfig.config.annotations.Option; -import cc.polyfrost.oneconfig.config.core.ConfigCore; -import cc.polyfrost.oneconfig.config.data.*; -import cc.polyfrost.oneconfig.config.profiles.Profiles; -import cc.polyfrost.oneconfig.gui.OneConfigGui; -import cc.polyfrost.oneconfig.gui.elements.config.*; -import cc.polyfrost.oneconfig.gui.pages.ModConfigPage; -import cc.polyfrost.oneconfig.hud.BasicHud; -import cc.polyfrost.oneconfig.hud.HudCore; -import cc.polyfrost.oneconfig.utils.GuiUtils; -import com.google.gson.*; - -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.*; -import java.util.function.Supplier; - -public class Config { - public final transient HashMap optionNames = new HashMap<>(); - transient protected final String configFile; - transient protected final Gson gson = new GsonBuilder().excludeFieldsWithModifiers(Modifier.TRANSIENT).setPrettyPrinting().create(); - transient public Mod mod; - public transient boolean hasBeenInitialized = false; - public boolean enabled = true; - - /** - * @param modData information about the mod - * @param configFile file where config is stored - */ - public Config(Mod modData, String configFile) { - this.configFile = configFile; - init(modData); - } - - public void init(Mod mod) { - boolean migrate = false; - if (Profiles.getProfileFile(configFile).exists()) load(); - else if (!hasBeenInitialized && mod.migrator != null) migrate = true; - else save(); - mod.config = this; - generateOptionList(this, mod.defaultPage, mod, migrate); - if (migrate) save(); - ConfigCore.oneConfigMods.add(mod); - this.mod = mod; - hasBeenInitialized = true; - } - - /** - * Save current config to file - */ - public void save() { - try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(Profiles.getProfileFile(configFile).toPath()), StandardCharsets.UTF_8))) { - writer.write(gson.toJson(this)); - } catch (IOException e) { - e.printStackTrace(); - } - } - - /** - * Load file and overwrite current values - */ - public void load() { - try (BufferedReader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(Profiles.getProfileFile(configFile).toPath()), StandardCharsets.UTF_8))) { - deserializePart(new JsonParser().parse(reader).getAsJsonObject(), this); - } catch (IOException e) { - e.printStackTrace(); - } - } - - /** - * Generate the option list, for internal use only - * - * @param instance instance of target class - * @param page page to add options too - * @param mod data about the mod - * @param migrate whether the migrator should be run - */ - protected void generateOptionList(Object instance, OptionPage page, Mod mod, boolean migrate) { - Class clazz = instance.getClass(); - for (Field field : clazz.getDeclaredFields()) { - String pagePrefix = page.equals(mod.defaultPage) ? "" : page.name + "."; - if (!field.isAnnotationPresent(Option.class) && !field.isAnnotationPresent(ConfigPage.class)) { - processCustomOption(field, page); - continue; - } else if (field.isAnnotationPresent(ConfigPage.class)) { - ConfigPage option = field.getAnnotation(ConfigPage.class); - if (!page.categories.containsKey(option.category())) - page.categories.put(option.category(), new OptionCategory()); - OptionCategory category = page.categories.get(option.category()); - if (category.subcategories.size() == 0 || !category.subcategories.get(category.subcategories.size() - 1).getName().equals(option.subcategory())) - category.subcategories.add(new OptionSubcategory(option.subcategory())); - OptionSubcategory subcategory = category.subcategories.get(category.subcategories.size() - 1); - OptionPage newPage = new OptionPage(option.name(), mod); - try { - field.setAccessible(true); - Object object = field.get(clazz); - generateOptionList(object, newPage, mod, migrate); - ConfigPageButton configPageButton = new ConfigPageButton(field, instance, option.name(), option.description(), newPage); - switch (option.location()) { - case TOP: - subcategory.topButtons.add(configPageButton); - break; - case BOTTOM: - subcategory.bottomButtons.add(configPageButton); - break; - } - optionNames.put(pagePrefix + field.getName(), configPageButton); - } catch (IllegalAccessException ignored) { - } - continue; - } - Option option = field.getAnnotation(Option.class); - if (!page.categories.containsKey(option.category())) - page.categories.put(option.category(), new OptionCategory()); - OptionCategory category = page.categories.get(option.category()); - if (category.subcategories.size() == 0 || !category.subcategories.get(category.subcategories.size() - 1).getName().equals(option.subcategory())) - category.subcategories.add(new OptionSubcategory(option.subcategory())); - if (migrate) { - try { - Object value = mod.migrator.getValue(field, option.name(), option.category(), option.subcategory()); - if (value != null) { - field.setAccessible(true); - field.set(instance, value); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - ArrayList options = category.subcategories.get(category.subcategories.size() - 1).options; - switch (option.type()) { - case SWITCH: - options.add(new ConfigSwitch(field, instance, option.name(), option.size())); - break; - case CHECKBOX: - options.add(new ConfigCheckbox(field, instance, option.name(), option.size())); - break; - case TEXT: - options.add(new ConfigTextBox(field, instance, option.name(), option.size(), option.placeholder(), option.secure(), option.multiLine())); - break; - case DUAL_OPTION: - options.add(new ConfigDualOption(field, instance, option.name(), option.size(), option.options())); - break; - case DROPDOWN: - options.add(new ConfigDropdown(field, instance, option.name(), option.size(), option.options())); - break; - case SLIDER: - options.add(new ConfigSlider(field, instance, option.name(), option.size(), option.min(), option.max(), option.step())); - break; - case INFO: - options.add(new ConfigInfo(field, instance, option.name(), option.size(), option.infoType())); - break; - case COLOR: - options.add(new ConfigColorElement(field, instance, option.name(), option.size())); - break; - case HEADER: - options.add(new ConfigHeader(field, instance, option.name(), option.size())); - break; - case BUTTON: - options.add(new ConfigButton(field, instance, option.name(), option.size(), option.buttonText())); - break; - case KEYBIND: - options.add(new ConfigKeyBind(field, instance, option.name(), option.size())); - break; - case HUD: - try { - field.setAccessible(true); - BasicHud hud = (BasicHud) field.get(instance); - HudCore.huds.add(hud); - options.add(new ConfigHeader(field, hud, option.name(), 1)); - options.add(new ConfigSwitch(hud.getClass().getField("enabled"), hud, "Enabled", 1)); - options.add(new ConfigCheckbox(hud.getClass().getField("rounded"), hud, "Rounded corners", 1)); - options.get(options.size() - 1).setDependency(() -> hud.enabled); - options.add(new ConfigCheckbox(hud.getClass().getField("border"), hud, "Outline/border", 1)); - options.get(options.size() - 1).setDependency(() -> hud.enabled); - options.add(new ConfigColorElement(hud.getClass().getField("bgColor"), hud, "Background color:", 1)); - options.get(options.size() - 1).setDependency(() -> hud.enabled); - options.add(new ConfigColorElement(hud.getClass().getField("borderColor"), hud, "Border color:", 1)); - options.get(options.size() - 1).setDependency(() -> hud.enabled && hud.border); - options.add(new ConfigSlider(hud.getClass().getField("cornerRadius"), hud, "Corner radius:", 2, 0, 10, 0)); - options.get(options.size() - 1).setDependency(() -> hud.enabled && hud.rounded); - options.add(new ConfigSlider(hud.getClass().getField("borderSize"), hud, "Border thickness:", 2, 0, 10, 0)); - options.get(options.size() - 1).setDependency(() -> hud.enabled && hud.border); - options.add(new ConfigSlider(hud.getClass().getField("paddingX"), hud, "X-Padding", 2, 0, 50, 0)); - options.get(options.size() - 1).setDependency(() -> hud.enabled); - options.add(new ConfigSlider(hud.getClass().getField("paddingY"), hud, "Y-Padding", 2, 0, 50, 0)); - options.get(options.size() - 1).setDependency(() -> hud.enabled); - } catch (IllegalAccessException | NoSuchFieldException e) { - e.printStackTrace(); - } - break; - } - if (!option.type().equals(OptionType.HUD)) - optionNames.put(pagePrefix + field.getName(), options.get(options.size() - 1)); - } - } - - /** - * Overwrite this method to add your own custom option types - * - * @param field target field - * @param page page to add options too - */ - protected void processCustomOption(Field field, OptionPage page) { - } - - /** - * Deserialize part of config and load values - * - * @param json json to deserialize - * @param instance instance of target class - */ - protected void deserializePart(JsonObject json, Object instance) { - Class clazz = instance.getClass(); - for (Map.Entry element : json.entrySet()) { - String name = element.getKey(); - JsonElement value = element.getValue(); - if (value.isJsonObject()) { - Optional> innerClass = Arrays.stream(clazz.getClasses()).filter(aClass -> aClass.getSimpleName().equals(name)).findFirst(); - if (innerClass.isPresent()) { - deserializePart(value.getAsJsonObject(), innerClass.get()); - continue; - } - } - try { - Field field = clazz.getField(name); - TypeAdapter adapter = gson.getAdapter(field.getType()); - Object object = adapter.fromJsonTree(value); - field.setAccessible(true); - field.set(instance, object); - } catch (Exception ignored) { - } - } - } - - /** - * Function to open the gui of this mod - */ - public void openGui() { - if (mod == null) return; - GuiUtils.displayScreen(new OneConfigGui(new ModConfigPage(mod.defaultPage))); - } - - /** - * Disable an option if a certain condition is not met - * - * @param option The name of the field, or if the field is in a page "pageName.fieldName" - * @param condition The condition that has to be met for the option to be enabled - */ - protected void addDependency(String option, Supplier condition) { - if (!optionNames.containsKey(option)) return; - optionNames.get(option).setDependency(condition); - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/config/migration/Migrator.java b/src/main/java/cc/polyfrost/oneconfig/config/migration/Migrator.java deleted file mode 100644 index abfb2a0..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/config/migration/Migrator.java +++ /dev/null @@ -1,14 +0,0 @@ -package cc.polyfrost.oneconfig.config.migration; - -import java.lang.reflect.Field; - -public interface Migrator { - /** - * @param field The field of the option - * @param name The name of the option - * @param category The category of the option - * @param subcategory The subcategory of the option - * @return Value of the option, null if not found - */ - Object getValue(Field field, String name, String category, String subcategory); -} diff --git a/src/main/java/cc/polyfrost/oneconfig/config/migration/VigilanceMigrator.java b/src/main/java/cc/polyfrost/oneconfig/config/migration/VigilanceMigrator.java deleted file mode 100644 index b45aeba..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/config/migration/VigilanceMigrator.java +++ /dev/null @@ -1,84 +0,0 @@ -package cc.polyfrost.oneconfig.config.migration; - -import cc.polyfrost.oneconfig.config.annotations.VigilanceName; - -import java.io.BufferedReader; -import java.io.FileReader; -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class VigilanceMigrator implements Migrator { - private static final Pattern categoryPattern = Pattern.compile("\\[\"?(?[^.\\[\\]\"]+)\"?\\.\"?(?[^.\\[\\]\"]+)\"?]"); - private static final Pattern booleanPattern = Pattern.compile("\"?(?[^\\s\"]+)\"? = (?true|false)"); - private static final Pattern numberPattern = Pattern.compile("\"?(?[^\\s\"]+)\"? = (?[\\d.]+)"); - private static final Pattern stringPattern = Pattern.compile("\"?(?[^\\s\"]+)\"? = \"(?.+)\""); - protected final String filePath; - protected HashMap>> values = null; - - public VigilanceMigrator(String filePath) { - this.filePath = filePath; - } - - @Override - public Object getValue(Field field, String name, String category, String subcategory) { - if (values == null) getOptions(); - if (field.isAnnotationPresent(VigilanceName.class)) { - VigilanceName annotation = field.getAnnotation(VigilanceName.class); - name = annotation.name(); - category = annotation.category(); - subcategory = annotation.subcategory(); - } - name = parse(name); - category = parse(category); - subcategory = parse(subcategory); - if (values.containsKey(category) && values.get(category).containsKey(subcategory) && values.get(category).get(subcategory).containsKey(name)) - return values.get(category).get(subcategory).get(name); - return null; - } - - protected String parse(String value) { - return value.toLowerCase().replace(" ", "_"); - } - - protected void getOptions() { - if (values == null) values = new HashMap<>(); - try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) { - String currentCategory = null; - String currentSubcategory = null; - String line; - while ((line = reader.readLine()) != null) { - Matcher categoryMatcher = categoryPattern.matcher(line); - if (categoryMatcher.find()) { - currentCategory = categoryMatcher.group("category"); - currentSubcategory = categoryMatcher.group("subcategory"); - if (!values.containsKey(currentCategory)) values.put(currentCategory, new HashMap<>()); - if (!values.get(currentCategory).containsKey(currentSubcategory)) - values.get(currentCategory).put(currentSubcategory, new HashMap<>()); - continue; - } - if (currentCategory == null) continue; - HashMap options = values.get(currentCategory).get(currentSubcategory); - Matcher booleanMatcher = booleanPattern.matcher(line); - if (booleanMatcher.find()) { - options.put(booleanMatcher.group("name"), Boolean.parseBoolean(booleanMatcher.group("value"))); - continue; - } - Matcher numberMatcher = numberPattern.matcher(line); - if (numberMatcher.find()) { - String value = numberMatcher.group("value"); - if (value.contains(".")) options.put(numberMatcher.group("name"), Float.parseFloat(value)); - else options.put(numberMatcher.group("name"), Integer.parseInt(value)); - continue; - } - Matcher stringMatcher = stringPattern.matcher(line); - if (stringMatcher.find()) { - options.put(stringMatcher.group("name"), stringMatcher.group("value")); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/config/migration/vigilance/Migrator.java b/src/main/java/cc/polyfrost/oneconfig/config/migration/vigilance/Migrator.java new file mode 100644 index 0000000..f3f60b7 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/config/migration/vigilance/Migrator.java @@ -0,0 +1,14 @@ +package cc.polyfrost.oneconfig.config.migration.vigilance; + +import java.lang.reflect.Field; + +public interface Migrator { + /** + * @param field The field of the option + * @param name The name of the option + * @param category The category of the option + * @param subcategory The subcategory of the option + * @return Value of the option, null if not found + */ + Object getValue(Field field, String name, String category, String subcategory); +} diff --git a/src/main/java/cc/polyfrost/oneconfig/config/migration/vigilance/VigilanceMigrator.java b/src/main/java/cc/polyfrost/oneconfig/config/migration/vigilance/VigilanceMigrator.java new file mode 100644 index 0000000..2870e03 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/config/migration/vigilance/VigilanceMigrator.java @@ -0,0 +1,84 @@ +package cc.polyfrost.oneconfig.config.migration.vigilance; + +import cc.polyfrost.oneconfig.config.annotations.VigilanceName; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class VigilanceMigrator implements Migrator { + private static final Pattern categoryPattern = Pattern.compile("\\[\"?(?[^.\\[\\]\"]+)\"?\\.\"?(?[^.\\[\\]\"]+)\"?]"); + private static final Pattern booleanPattern = Pattern.compile("\"?(?[^\\s\"]+)\"? = (?true|false)"); + private static final Pattern numberPattern = Pattern.compile("\"?(?[^\\s\"]+)\"? = (?[\\d.]+)"); + private static final Pattern stringPattern = Pattern.compile("\"?(?[^\\s\"]+)\"? = \"(?.+)\""); + protected final String filePath; + protected HashMap>> values = null; + + public VigilanceMigrator(String filePath) { + this.filePath = filePath; + } + + @Override + public Object getValue(Field field, String name, String category, String subcategory) { + if (values == null) getOptions(); + if (field.isAnnotationPresent(VigilanceName.class)) { + VigilanceName annotation = field.getAnnotation(VigilanceName.class); + name = annotation.name(); + category = annotation.category(); + subcategory = annotation.subcategory(); + } + name = parse(name); + category = parse(category); + subcategory = parse(subcategory); + if (values.containsKey(category) && values.get(category).containsKey(subcategory) && values.get(category).get(subcategory).containsKey(name)) + return values.get(category).get(subcategory).get(name); + return null; + } + + protected String parse(String value) { + return value.toLowerCase().replace(" ", "_"); + } + + protected void getOptions() { + if (values == null) values = new HashMap<>(); + try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) { + String currentCategory = null; + String currentSubcategory = null; + String line; + while ((line = reader.readLine()) != null) { + Matcher categoryMatcher = categoryPattern.matcher(line); + if (categoryMatcher.find()) { + currentCategory = categoryMatcher.group("category"); + currentSubcategory = categoryMatcher.group("subcategory"); + if (!values.containsKey(currentCategory)) values.put(currentCategory, new HashMap<>()); + if (!values.get(currentCategory).containsKey(currentSubcategory)) + values.get(currentCategory).put(currentSubcategory, new HashMap<>()); + continue; + } + if (currentCategory == null) continue; + HashMap options = values.get(currentCategory).get(currentSubcategory); + Matcher booleanMatcher = booleanPattern.matcher(line); + if (booleanMatcher.find()) { + options.put(booleanMatcher.group("name"), Boolean.parseBoolean(booleanMatcher.group("value"))); + continue; + } + Matcher numberMatcher = numberPattern.matcher(line); + if (numberMatcher.find()) { + String value = numberMatcher.group("value"); + if (value.contains(".")) options.put(numberMatcher.group("name"), Float.parseFloat(value)); + else options.put(numberMatcher.group("name"), Integer.parseInt(value)); + continue; + } + Matcher stringMatcher = stringPattern.matcher(line); + if (stringMatcher.find()) { + options.put(stringMatcher.group("name"), stringMatcher.group("value")); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/config/profiles/Profiles.java b/src/main/java/cc/polyfrost/oneconfig/config/profiles/Profiles.java index dfc5e16..006fea9 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/profiles/Profiles.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/profiles/Profiles.java @@ -1,8 +1,8 @@ package cc.polyfrost.oneconfig.config.profiles; -import cc.polyfrost.oneconfig.OneConfig; -import cc.polyfrost.oneconfig.config.OneConfigConfig; +import cc.polyfrost.oneconfig.internal.OneConfig; import cc.polyfrost.oneconfig.config.core.ConfigCore; +import cc.polyfrost.oneconfig.internal.config.OneConfigConfig; import org.apache.commons.io.FileUtils; import java.io.File; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/Colors.java b/src/main/java/cc/polyfrost/oneconfig/gui/Colors.java new file mode 100644 index 0000000..6cb9567 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/gui/Colors.java @@ -0,0 +1,46 @@ +package cc.polyfrost.oneconfig.gui; + +import java.awt.*; + +public class Colors { + // the color library + public static final int TRANSPARENT = new Color(0, 0, 0, 0).getRGB(); // Transparent + public static final int BLACK = new Color(0, 0, 0, 255).getRGB(); // Black + public static final int GRAY_900 = new Color(13, 14, 15, 255).getRGB(); // Gray 900 + public static final int GRAY_900_80 = new Color(13, 14, 15, 204).getRGB(); // Gray 900 80% + public static final int GRAY_800 = new Color(21, 22, 23, 255).getRGB(); // Gray 800 + public static final int GRAY_800_95 = new Color(21, 22, 23, 242).getRGB(); + public static final int GRAY_700 = new Color(34, 35, 38, 255).getRGB(); // Gray 700 + public static final int GRAY_600 = new Color(42, 44, 48, 255).getRGB(); // Gray 600 + public static final int GRAY_500 = new Color(49, 51, 56, 255).getRGB(); // Gray 500 // button sidebar hover, button gray normal + public static final int GRAY_500_80 = new Color(49, 51, 56, 204).getRGB(); // Gray 500 80% // button sidebar pressed + public static final int GRAY_400 = new Color(55, 59, 69, 255).getRGB(); // Gray 400 + public static final int GRAY_300 = new Color(73, 79, 92, 255).getRGB(); // Gray 300 // button gray hover + public static final int GRAY_400_80 = new Color(55, 59, 69, 204).getRGB(); // Gray 400 80% // button gray pressed + public static final int PRIMARY_800 = new Color(13, 51, 128, 255).getRGB(); // Blue 800 + public static final int PRIMARY_700 = new Color(18, 71, 178, 255).getRGB(); // Blue 700 + public static final int PRIMARY_700_80 = new Color(18, 71, 178, 204).getRGB(); // Blue 700 80% + public static final int PRIMARY_600 = new Color(20, 82, 204, 255).getRGB(); // Blue 600 // button blue normal + public static final int PRIMARY_500 = new Color(25, 103, 255, 255).getRGB(); // Blue 500 // button blue hover + public static final int PRIMARY_400 = new Color(48, 129, 242, 255).getRGB(); + public static final int WHITE_50 = new Color(255, 255, 255, 127).getRGB(); // White 60% + public static final int WHITE_60 = new Color(255, 255, 255, 153).getRGB(); // White 60% + public static final int WHITE_80 = new Color(255, 255, 255, 204).getRGB(); // White 80% + public static final int WHITE_90 = new Color(255, 255, 255, 229).getRGB(); // White 90% + public static final int WHITE_95 = new Color(255, 255, 255, 242).getRGB(); // White 90% + public static final int WHITE = new Color(255, 255, 255, 255).getRGB(); // White 100% + public static final int SUCCESS_600 = new Color(3, 152, 85).getRGB(); + public static final int SUCCESS_700 = new Color(2, 121, 72).getRGB(); + public static final int WARNING_500 = new Color(247, 144, 9).getRGB(); + public static final int WARNING_600 = new Color(220, 104, 3).getRGB(); + public static final int ERROR_600_80 = new Color(217, 32, 32, 204).getRGB(); + public static final int ERROR_600 = new Color(217, 32, 32).getRGB(); + public static final int ERROR_700 = new Color(180, 24, 24).getRGB(); // Red 700 + public static final int ERROR_800 = new Color(145, 24, 24).getRGB(); // Red 800 + public static final int ERROR_800_80 = new Color(145, 24, 24, 204).getRGB(); // Red 800 + public static final int ERROR_300 = new Color(253, 155, 155).getRGB(); + public static final int ERROR_300_80 = new Color(253, 155, 155, 204).getRGB(); + public static boolean ROUNDED_CORNERS = true; + public static final float CORNER_RADIUS_WIN = 20f; + public static final float CORNER_RADIUS = 12f; +} diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java index 52030fc..1b172d0 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java @@ -3,7 +3,7 @@ package cc.polyfrost.oneconfig.gui; import cc.polyfrost.oneconfig.config.core.ConfigCore; import cc.polyfrost.oneconfig.hud.BasicHud; import cc.polyfrost.oneconfig.hud.HudCore; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; +import cc.polyfrost.oneconfig.renderer.RenderManager; import gg.essential.universal.UKeyboard; import gg.essential.universal.UMatrixStack; import gg.essential.universal.UScreen; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java index a9da8c2..81fe9c0 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java @@ -1,6 +1,5 @@ package cc.polyfrost.oneconfig.gui; -import cc.polyfrost.oneconfig.config.OneConfigConfig; import cc.polyfrost.oneconfig.config.core.OneColor; import cc.polyfrost.oneconfig.gui.animations.Animation; import cc.polyfrost.oneconfig.gui.animations.EaseInOutQuad; @@ -9,11 +8,11 @@ import cc.polyfrost.oneconfig.gui.elements.ColorSelector; import cc.polyfrost.oneconfig.gui.elements.text.TextInputField; import cc.polyfrost.oneconfig.gui.pages.ModsPage; import cc.polyfrost.oneconfig.gui.pages.Page; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; -import cc.polyfrost.oneconfig.lwjgl.font.Fonts; -import cc.polyfrost.oneconfig.lwjgl.image.SVGs; -import cc.polyfrost.oneconfig.lwjgl.scissor.ScissorManager; -import cc.polyfrost.oneconfig.utils.GuiUtils; +import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.renderer.font.Fonts; +import cc.polyfrost.oneconfig.renderer.image.SVGs; +import cc.polyfrost.oneconfig.renderer.scissor.ScissorManager; +import cc.polyfrost.oneconfig.utils.gui.GuiUtils; import cc.polyfrost.oneconfig.utils.InputUtils; import cc.polyfrost.oneconfig.utils.color.ColorPalette; import gg.essential.universal.UKeyboard; @@ -33,8 +32,8 @@ public class OneConfigGui extends UScreen { private final TextInputField textInputField = new TextInputField(248, 40, "Search...", false, false, SVGs.MAGNIFYING_GLASS_BOLD); private final ArrayList previousPages = new ArrayList<>(); private final ArrayList nextPages = new ArrayList<>(); - private final BasicElement backArrow = new BasicElement(40, 40, new ColorPalette(OneConfigConfig.GRAY_700, OneConfigConfig.GRAY_500, OneConfigConfig.GRAY_500_80), true); - private final BasicElement forwardArrow = new BasicElement(40, 40, new ColorPalette(OneConfigConfig.GRAY_700, OneConfigConfig.GRAY_500, OneConfigConfig.GRAY_500_80), true); + private final BasicElement backArrow = new BasicElement(40, 40, new ColorPalette(Colors.GRAY_700, Colors.GRAY_500, Colors.GRAY_500_80), true); + private final BasicElement forwardArrow = new BasicElement(40, 40, new ColorPalette(Colors.GRAY_700, Colors.GRAY_500, Colors.GRAY_500_80), true); private final ArrayList parents = new ArrayList<>(); public ColorSelector currentColorSelector; public boolean mouseDown; @@ -80,18 +79,18 @@ public class OneConfigGui extends UScreen { int x = (int) ((UResolution.getWindowWidth() - 1280 * scale) / 2f / scale); int y = (int) ((UResolution.getWindowHeight() - 800 * scale) / 2f / scale); RenderManager.scale(vg, scale, scale); - if (OneConfigConfig.ROUNDED_CORNERS) { + if (Colors.ROUNDED_CORNERS) { RenderManager.drawDropShadow(vg, x, y, 1280, 800, 32, 0, 20); - RenderManager.drawRoundedRect(vg, x + 224, y, 1056, 800, OneConfigConfig.GRAY_800, OneConfigConfig.CORNER_RADIUS_WIN); - RenderManager.drawRoundedRect(vg, x, y, 244, 800, OneConfigConfig.GRAY_800_95, OneConfigConfig.CORNER_RADIUS_WIN); - RenderManager.drawRect(vg, x + 224, y, 20, 800, OneConfigConfig.GRAY_800); + RenderManager.drawRoundedRect(vg, x + 224, y, 1056, 800, Colors.GRAY_800, Colors.CORNER_RADIUS_WIN); + RenderManager.drawRoundedRect(vg, x, y, 244, 800, Colors.GRAY_800_95, Colors.CORNER_RADIUS_WIN); + RenderManager.drawRect(vg, x + 224, y, 20, 800, Colors.GRAY_800); } - RenderManager.drawLine(vg, x + 224, y + 72, x + 1280, y + 72, 1, OneConfigConfig.GRAY_700); - RenderManager.drawLine(vg, x + 224, y, x + 222, y + 800, 1, OneConfigConfig.GRAY_700); + RenderManager.drawLine(vg, x + 224, y + 72, x + 1280, y + 72, 1, Colors.GRAY_700); + RenderManager.drawLine(vg, x + 224, y, x + 222, y + 800, 1, Colors.GRAY_700); RenderManager.drawSvg(vg, SVGs.ONECONFIG, x + 19, y + 19, 42, 42); - RenderManager.drawText(vg, "OneConfig", x + 69, y + 32, OneConfigConfig.WHITE, 18f, Fonts.BOLD); // added half line height to center text - RenderManager.drawText(vg, "By Polyfrost", x + 69, y + 51, OneConfigConfig.WHITE, 12f, Fonts.REGULAR); + RenderManager.drawText(vg, "OneConfig", x + 69, y + 32, Colors.WHITE, 18f, Fonts.BOLD); // added half line height to center text + RenderManager.drawText(vg, "By Polyfrost", x + 69, y + 51, Colors.WHITE, 12f, Fonts.REGULAR); textInputField.draw(vg, x + 1020, y + 16); sideBar.draw(vg, x, y); @@ -156,9 +155,9 @@ public class OneConfigGui extends UScreen { String title = parents.get(i).getTitle(); float width = RenderManager.getTextWidth(vg, title, 24f, Fonts.SEMIBOLD); boolean hovered = InputUtils.isAreaHovered((int) breadcrumbX, y + 24, (int) width, 36); - int color = OneConfigConfig.WHITE_60; - if (i == parents.size() - 1) color = OneConfigConfig.WHITE; - else if (hovered && !Mouse.isButtonDown(0)) color = OneConfigConfig.WHITE_80; + int color = Colors.WHITE_60; + if (i == parents.size() - 1) color = Colors.WHITE; + else if (hovered && !Mouse.isButtonDown(0)) color = Colors.WHITE_80; RenderManager.drawText(vg, title, breadcrumbX, y + 38, color, 24f, Fonts.SEMIBOLD); if (i != 0) RenderManager.drawSvg(vg, SVGs.CARET_RIGHT, breadcrumbX - 28, y + 25, 24, 24, color); @@ -168,7 +167,7 @@ public class OneConfigGui extends UScreen { long end = System.nanoTime() - start; String s = (" draw: " + end / 1000000f + "ms"); - RenderManager.drawText(vg, s, x + 1170, y + 792, OneConfigConfig.GRAY_300, 10f, Fonts.MEDIUM); + RenderManager.drawText(vg, s, x + 1170, y + 792, Colors.GRAY_300, 10f, Fonts.MEDIUM); if (currentColorSelector != null) { currentColorSelector.draw(vg); } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java index 236733a..b6f1160 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java @@ -1,17 +1,16 @@ package cc.polyfrost.oneconfig.gui; -import cc.polyfrost.oneconfig.config.OneConfigConfig; import cc.polyfrost.oneconfig.gui.animations.Animation; 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.ModsPage; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; -import cc.polyfrost.oneconfig.lwjgl.font.Fonts; -import cc.polyfrost.oneconfig.lwjgl.image.SVGs; +import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.renderer.font.Fonts; +import cc.polyfrost.oneconfig.renderer.image.SVGs; import cc.polyfrost.oneconfig.test.ButtonTestPage; -import cc.polyfrost.oneconfig.utils.GuiUtils; +import cc.polyfrost.oneconfig.utils.gui.GuiUtils; import cc.polyfrost.oneconfig.utils.color.ColorPalette; import java.util.ArrayList; @@ -60,7 +59,7 @@ public class SideBar { selected = buttons.indexOf(button); } if (moveAnimation != null) { - RenderManager.drawRoundedRect(vg, x + 16, moveAnimation.get() - (sizeAnimation.get() - 36) / 2f, 192, sizeAnimation.get(0), OneConfigConfig.PRIMARY_600, 12); + RenderManager.drawRoundedRect(vg, x + 16, moveAnimation.get() - (sizeAnimation.get() - 36) / 2f, 192, sizeAnimation.get(0), Colors.PRIMARY_600, 12); if (moveAnimation.isFinished() && sizeAnimation.isFinished()) { moveAnimation = null; sizeAnimation = null; @@ -70,12 +69,12 @@ public class SideBar { buttons.get(0).draw(vg, x + 16, y + 80); buttons.get(1).draw(vg, x + 16, y + 116); - RenderManager.drawText(vg, "MOD CONFIG", x + 16, y + 178, OneConfigConfig.WHITE, 12, Fonts.SEMIBOLD); + RenderManager.drawText(vg, "MOD CONFIG", x + 16, y + 178, Colors.WHITE, 12, Fonts.SEMIBOLD); buttons.get(2).draw(vg, x + 16, y + 192); buttons.get(3).draw(vg, x + 16, y + 228); buttons.get(4).draw(vg, x + 16, y + 264); buttons.get(5).draw(vg, x + 16, y + 300); - RenderManager.drawText(vg, "PERSONALIZATION", x + 16, y + 362, OneConfigConfig.WHITE, 12, Fonts.SEMIBOLD); + RenderManager.drawText(vg, "PERSONALIZATION", x + 16, y + 362, Colors.WHITE, 12, Fonts.SEMIBOLD); buttons.get(6).draw(vg, x + 16, y + 376); buttons.get(7).draw(vg, x + 16, y + 412); buttons.get(8).draw(vg, x + 16, y + 448); diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java b/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java index 3f2a552..a5cfae0 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java @@ -1,6 +1,6 @@ package cc.polyfrost.oneconfig.gui.animations; -import cc.polyfrost.oneconfig.utils.GuiUtils; +import cc.polyfrost.oneconfig.utils.gui.GuiUtils; public abstract class Animation { protected final boolean reverse; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java index 36acffa..f3168dd 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java @@ -1,11 +1,11 @@ package cc.polyfrost.oneconfig.gui.elements; -import cc.polyfrost.oneconfig.config.OneConfigConfig; +import cc.polyfrost.oneconfig.gui.Colors; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.gui.pages.Page; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; -import cc.polyfrost.oneconfig.lwjgl.font.Fonts; -import cc.polyfrost.oneconfig.lwjgl.image.SVGs; +import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.renderer.font.Fonts; +import cc.polyfrost.oneconfig.renderer.image.SVGs; import cc.polyfrost.oneconfig.utils.color.ColorPalette; import cc.polyfrost.oneconfig.utils.color.ColorUtils; import org.jetbrains.annotations.NotNull; @@ -68,7 +68,7 @@ public class BasicButton extends BasicElement { color = currentColor; } else { RenderManager.drawRoundedRect(vg, x, y, this.width, this.height, currentColor, this.cornerRadius); - color = ColorUtils.setAlpha(OneConfigConfig.WHITE, (int) (colorAnimation.getAlpha() * 255)); + color = ColorUtils.setAlpha(Colors.WHITE, (int) (colorAnimation.getAlpha() * 255)); } final float middle = x + width / 2f; final float middleYIcon = y + height / 2f - iconSize / 2f; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java index f0b930c..a4a3321 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java @@ -1,7 +1,7 @@ package cc.polyfrost.oneconfig.gui.elements; import cc.polyfrost.oneconfig.gui.animations.ColorAnimation; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; +import cc.polyfrost.oneconfig.renderer.RenderManager; import cc.polyfrost.oneconfig.utils.InputUtils; import cc.polyfrost.oneconfig.utils.color.ColorPalette; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java index 683be1e..d42d465 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java @@ -1,6 +1,6 @@ package cc.polyfrost.oneconfig.gui.elements; -import cc.polyfrost.oneconfig.config.OneConfigConfig; +import cc.polyfrost.oneconfig.gui.Colors; import cc.polyfrost.oneconfig.config.core.OneColor; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.gui.animations.Animation; @@ -9,12 +9,13 @@ import cc.polyfrost.oneconfig.gui.animations.EaseInOutCubic; import cc.polyfrost.oneconfig.gui.animations.EaseInOutQuad; import cc.polyfrost.oneconfig.gui.elements.text.NumberInputField; import cc.polyfrost.oneconfig.gui.elements.text.TextInputField; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; -import cc.polyfrost.oneconfig.lwjgl.font.Fonts; -import cc.polyfrost.oneconfig.lwjgl.image.Images; -import cc.polyfrost.oneconfig.lwjgl.image.SVGs; -import cc.polyfrost.oneconfig.lwjgl.scissor.Scissor; -import cc.polyfrost.oneconfig.lwjgl.scissor.ScissorManager; +import cc.polyfrost.oneconfig.internal.config.OneConfigConfig; +import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.renderer.font.Fonts; +import cc.polyfrost.oneconfig.renderer.image.Images; +import cc.polyfrost.oneconfig.renderer.image.SVGs; +import cc.polyfrost.oneconfig.renderer.scissor.Scissor; +import cc.polyfrost.oneconfig.renderer.scissor.ScissorManager; import cc.polyfrost.oneconfig.utils.InputUtils; import cc.polyfrost.oneconfig.utils.NetworkUtils; import cc.polyfrost.oneconfig.utils.color.ColorPalette; @@ -102,11 +103,11 @@ public class ColorSelector { int height = 768; Scissor scissor = ScissorManager.scissor(vg, x - 3, y - 3, width + 6, height + 6); RenderManager.drawHollowRoundRect(vg, x - 3, y - 3, width + 4, height + 4, new Color(204, 204, 204, 77).getRGB(), 20f, 2f); - RenderManager.drawRoundedRect(vg, x, y, width, height, OneConfigConfig.GRAY_800, 20f); - RenderManager.drawText(vg, "Color Selector", x + 16, y + 32, OneConfigConfig.WHITE_90, 18f, Fonts.SEMIBOLD); + RenderManager.drawRoundedRect(vg, x, y, width, height, Colors.GRAY_800, 20f); + RenderManager.drawText(vg, "Color Selector", x + 16, y + 32, Colors.WHITE_90, 18f, Fonts.SEMIBOLD); if (!closeBtn.isHovered()) RenderManager.setAlpha(vg, 0.8f); closeBtn.draw(vg, x + 368, y + 16); - RenderManager.drawSvg(vg, SVGs.X_CIRCLE_BOLD, x + 368, y + 16, 32, 32, closeBtn.isHovered() ? OneConfigConfig.ERROR_600 : -1); + RenderManager.drawSvg(vg, SVGs.X_CIRCLE_BOLD, x + 368, y + 16, 32, 32, closeBtn.isHovered() ? Colors.ERROR_600 : -1); RenderManager.setAlpha(vg, 1f); // hex parser @@ -124,9 +125,9 @@ public class ColorSelector { recentColors.get(i).draw(vg, x + 104 + i * 44, y + 720); } - RenderManager.drawRoundedRect(vg, x + 16, y + 64, 384, 32, OneConfigConfig.GRAY_500, 12f); + RenderManager.drawRoundedRect(vg, x + 16, y + 64, 384, 32, Colors.GRAY_500, 12f); if (!barMoveAnimation.isFinished()) - RenderManager.drawRoundedRect(vg, x + barMoveAnimation.get(), y + 66, 124, 28, OneConfigConfig.PRIMARY_600, 10f); + RenderManager.drawRoundedRect(vg, x + barMoveAnimation.get(), y + 66, 124, 28, Colors.PRIMARY_600, 10f); else buttons.get(mode).setColorPalette(ColorPalette.PRIMARY); int i = 18; @@ -144,22 +145,22 @@ public class ColorSelector { } float percentMoveMain = moveAnimation.get(); - RenderManager.drawText(vg, "Saturation", x + 224, y + 560, OneConfigConfig.WHITE_80, 12f, Fonts.MEDIUM); + RenderManager.drawText(vg, "Saturation", x + 224, y + 560, Colors.WHITE_80, 12f, Fonts.MEDIUM); saturationInput.draw(vg, x + 312, y + 544); - RenderManager.drawText(vg, "Brightness", x + 16, y + 599, OneConfigConfig.WHITE_80, 12f, Fonts.MEDIUM); + RenderManager.drawText(vg, "Brightness", x + 16, y + 599, Colors.WHITE_80, 12f, Fonts.MEDIUM); brightnessInput.draw(vg, x + 104, y + 584); - RenderManager.drawText(vg, "Alpha (%)", x + 224, y + 599, OneConfigConfig.WHITE_80, 12f, Fonts.MEDIUM); + RenderManager.drawText(vg, "Alpha (%)", x + 224, y + 599, Colors.WHITE_80, 12f, Fonts.MEDIUM); alphaInput.draw(vg, x + 312, y + 584); - RenderManager.drawText(vg, color.getDataBit() == -1 ? "Hex (RGB):" : "Color Code:", x + 16, y + 641, OneConfigConfig.WHITE_80, 12f, Fonts.MEDIUM); + RenderManager.drawText(vg, color.getDataBit() == -1 ? "Hex (RGB):" : "Color Code:", x + 16, y + 641, Colors.WHITE_80, 12f, Fonts.MEDIUM); hexInput.draw(vg, x + 104, y + 624); copyBtn.draw(vg, x + 204, y + 624); pasteBtn.draw(vg, x + 244, y + 624); if (mode != 2) { - RenderManager.drawText(vg, "Hue", x + 16, y + 560, OneConfigConfig.WHITE_80, 12f, Fonts.MEDIUM); + RenderManager.drawText(vg, "Hue", x + 16, y + 560, Colors.WHITE_80, 12f, Fonts.MEDIUM); hueInput.draw(vg, x + 104, y + 544); } else { - RenderManager.drawText(vg, "Speed (s)", x + 16, y + 560, OneConfigConfig.WHITE_80, 12f, Fonts.MEDIUM); + RenderManager.drawText(vg, "Speed (s)", x + 16, y + 560, Colors.WHITE_80, 12f, Fonts.MEDIUM); speedInput.draw(vg, x + 104, y + 544); } @@ -172,13 +173,13 @@ public class ColorSelector { if (dragging && InputUtils.isClicked(true)) { dragging = false; } - bottomSlider.setGradient(OneConfigConfig.TRANSPARENT, color.getRGBNoAlpha()); + bottomSlider.setGradient(Colors.TRANSPARENT, color.getRGBNoAlpha()); RenderManager.drawRoundImage(vg, Images.ALPHA_GRID, x + 16, y + 456, 384, 16, 8f); bottomSlider.draw(vg, x + 16, y + 456); if (percentMoveMain > 0.96f) { - RenderManager.drawRoundedRect(vg, mouseX - 7, mouseY - 7, 14, 14, OneConfigConfig.WHITE, 14f); - RenderManager.drawRoundedRect(vg, mouseX - 6, mouseY - 6, 12, 12, OneConfigConfig.BLACK, 12f); + RenderManager.drawRoundedRect(vg, mouseX - 7, mouseY - 7, 14, 14, Colors.WHITE, 14f); + RenderManager.drawRoundedRect(vg, mouseX - 6, mouseY - 6, 12, 12, Colors.BLACK, 12f); RenderManager.drawRoundedRect(vg, mouseX - 5, mouseY - 5, 10, 10, color.getRGBMax(true), 10f); } @@ -188,7 +189,7 @@ public class ColorSelector { // draw the color preview - RenderManager.drawHollowRoundRect(vg, x + 15, y + 487, 384, 40, OneConfigConfig.GRAY_300, 12f, 2f); + RenderManager.drawHollowRoundRect(vg, x + 15, y + 487, 384, 40, Colors.GRAY_300, 12f, 2f); RenderManager.drawRoundImage(vg, Images.ALPHA_GRID, x + 20, y + 492, 376, 32, 8f); RenderManager.drawRoundedRect(vg, x + 20, y + 492, 376, 32, color.getRGB(), 8f); InputUtils.blockClicks(true); @@ -213,8 +214,8 @@ public class ColorSelector { } if (mode == 2) { speedSlider.draw(vg, x + 60, y + 424); - RenderManager.drawText(vg, "SLOW", x + 16, y + 429, OneConfigConfig.WHITE_80, 12f, Fonts.REGULAR); - RenderManager.drawText(vg, "FAST", x + 370, y + 429, OneConfigConfig.WHITE_80, 12f, Fonts.REGULAR); + RenderManager.drawText(vg, "SLOW", x + 16, y + 429, Colors.WHITE_80, 12f, Fonts.REGULAR); + RenderManager.drawText(vg, "FAST", x + 370, y + 429, Colors.WHITE_80, 12f, Fonts.REGULAR); } break; case 1: @@ -222,7 +223,7 @@ public class ColorSelector { topSlider.setImage(null); RenderManager.drawRoundImage(vg, Images.COLOR_WHEEL, x + 64, y + 120, 288, 288, 144f); - topSlider.setGradient(OneConfigConfig.BLACK, color.getRGBMax(true)); + topSlider.setGradient(Colors.BLACK, color.getRGBMax(true)); topSlider.setImage(null); topSlider.draw(vg, x + 16, y + 424); break; @@ -427,8 +428,8 @@ public class ColorSelector { } RenderManager.drawHollowRoundRect(vg, x - 0.5f, y - 0.5f, width, height, new Color(204, 204, 204, 80).getRGB(), 8f, 1f); - RenderManager.drawHollowRoundRect(vg, currentDragPoint - 1, y - 1, 18, 18, OneConfigConfig.WHITE, 9f, 1f); - RenderManager.drawHollowRoundRect(vg, currentDragPoint, y, 16, 16, OneConfigConfig.BLACK, 8f, 1f); + RenderManager.drawHollowRoundRect(vg, currentDragPoint - 1, y - 1, 18, 18, Colors.WHITE, 9f, 1f); + RenderManager.drawHollowRoundRect(vg, currentDragPoint, y, 16, 16, Colors.BLACK, 8f, 1f); RenderManager.drawRoundedRect(vg, currentDragPoint + 1.5f, y + 1.5f, 14, 14, color, 7f); } @@ -456,8 +457,8 @@ public class ColorSelector { @Override public void draw(long vg, int x, int y) { - RenderManager.drawRoundedRect(vg, x, y, 32, 32, toggled ? OneConfigConfig.PRIMARY_600 : OneConfigConfig.GRAY_300, 12f); - RenderManager.drawRoundedRect(vg, x + 2, y + 2, 28, 28, OneConfigConfig.GRAY_800, 10f); + RenderManager.drawRoundedRect(vg, x, y, 32, 32, toggled ? Colors.PRIMARY_600 : Colors.GRAY_300, 12f); + RenderManager.drawRoundedRect(vg, x + 2, y + 2, 28, 28, Colors.GRAY_800, 10f); RenderManager.drawRoundedRect(vg, x + 4, y + 4, 24, 24, color.getRGB(), 8f); update(x, y); } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java index bac855e..f48e1af 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java @@ -1,16 +1,16 @@ package cc.polyfrost.oneconfig.gui.elements; -import cc.polyfrost.oneconfig.OneConfig; -import cc.polyfrost.oneconfig.config.OneConfigConfig; +import cc.polyfrost.oneconfig.internal.OneConfig; +import cc.polyfrost.oneconfig.gui.Colors; import cc.polyfrost.oneconfig.config.data.Mod; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.gui.animations.ColorAnimation; import cc.polyfrost.oneconfig.gui.pages.ModConfigPage; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; -import cc.polyfrost.oneconfig.lwjgl.font.Fonts; -import cc.polyfrost.oneconfig.lwjgl.image.SVGs; -import cc.polyfrost.oneconfig.lwjgl.scissor.Scissor; -import cc.polyfrost.oneconfig.lwjgl.scissor.ScissorManager; +import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.renderer.font.Fonts; +import cc.polyfrost.oneconfig.renderer.image.SVGs; +import cc.polyfrost.oneconfig.renderer.scissor.Scissor; +import cc.polyfrost.oneconfig.renderer.scissor.ScissorManager; import cc.polyfrost.oneconfig.utils.InputUtils; import cc.polyfrost.oneconfig.utils.color.ColorPalette; import cc.polyfrost.oneconfig.utils.color.ColorUtils; @@ -51,17 +51,17 @@ public class ModCard extends BasicElement { if (disabled) RenderManager.setAlpha(vg, 0.5f); RenderManager.drawRoundedRectVaried(vg, x, y, width, 87, colorFrame.getColor(isHoveredMain, isHoveredMain && Mouse.isButtonDown(0)), 12f, 12f, 0f, 0f); RenderManager.drawRoundedRectVaried(vg, x, y + 87, width, 32, colorToggle.getColor(isHoveredSecondary, isHoveredSecondary && Mouse.isButtonDown(0)), 0f, 0f, 12f, 12f); - RenderManager.drawLine(vg, x, y + 86, x + width, y + 86, 2, OneConfigConfig.GRAY_300); + RenderManager.drawLine(vg, x, y + 86, x + width, y + 86, 2, Colors.GRAY_300); if (modData.modIcon != null) { if (modData.modIcon.toLowerCase().endsWith(".svg")) RenderManager.drawSvg(vg, modData.modIcon, x + 98, y + 19, 48, 48); else RenderManager.drawImage(vg, modData.modIcon, x + 98, y + 19, 48, 48); } else { - RenderManager.drawText(vg, modData.name, x + 122 - RenderManager.getTextWidth(vg, modData.name, 16, Fonts.MINECRAFT_BOLD) / 2f, y + 44, ColorUtils.setAlpha(OneConfigConfig.WHITE, (int) (colorFrame.getAlpha() * 255)), 16, Fonts.MINECRAFT_BOLD); + RenderManager.drawText(vg, modData.name, x + 122 - RenderManager.getTextWidth(vg, modData.name, 16, Fonts.MINECRAFT_BOLD) / 2f, y + 44, ColorUtils.setAlpha(Colors.WHITE, (int) (colorFrame.getAlpha() * 255)), 16, Fonts.MINECRAFT_BOLD); } favoriteButton.draw(vg, x + 212, y + 87); favorite = favoriteButton.isToggled(); - RenderManager.drawText(vg, modData.name, x + 12, y + 103, ColorUtils.setAlpha(OneConfigConfig.WHITE, (int) (colorToggle.getAlpha() * 255)), 14f, Fonts.MEDIUM); + RenderManager.drawText(vg, modData.name, x + 12, y + 103, ColorUtils.setAlpha(Colors.WHITE, (int) (colorToggle.getAlpha() * 255)), 14f, Fonts.MEDIUM); if (favorite) favoriteButton.setLeftIcon(SVGs.HEART_FILL); else favoriteButton.setLeftIcon(SVGs.HEART_OUTLINE); diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModUpdateCard.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModUpdateCard.java deleted file mode 100644 index 55041b9..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModUpdateCard.java +++ /dev/null @@ -1,8 +0,0 @@ -package cc.polyfrost.oneconfig.gui.elements; - -public class ModUpdateCard extends BasicElement { - - public ModUpdateCard(int width, int height) { // TODO - super(width, height, true); - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/Slider.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/Slider.java index 3aab5ad..5705ba8 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/Slider.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/Slider.java @@ -1,7 +1,7 @@ package cc.polyfrost.oneconfig.gui.elements; -import cc.polyfrost.oneconfig.config.OneConfigConfig; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; +import cc.polyfrost.oneconfig.gui.Colors; +import cc.polyfrost.oneconfig.renderer.RenderManager; import cc.polyfrost.oneconfig.utils.InputUtils; import org.lwjgl.input.Mouse; @@ -23,9 +23,9 @@ public class Slider extends BasicElement { @Override public void draw(long vg, int x, int y) { update(x, y); - RenderManager.drawRoundedRect(vg, x, y + 2, width, height - 4, OneConfigConfig.GRAY_300, 3f); - RenderManager.drawRoundedRect(vg, x, y + 2, width * value, height - 4, OneConfigConfig.PRIMARY_500, 3f); - RenderManager.drawRoundedRect(vg, currentDragPoint - dragPointerSize / 2, y - 8, 24, 24, OneConfigConfig.WHITE, 12f); + RenderManager.drawRoundedRect(vg, x, y + 2, width, height - 4, Colors.GRAY_300, 3f); + RenderManager.drawRoundedRect(vg, x, y + 2, width * value, height - 4, Colors.PRIMARY_500, 3f); + RenderManager.drawRoundedRect(vg, currentDragPoint - dragPointerSize / 2, y - 8, 24, 24, Colors.WHITE, 12f); } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java index 19bf058..a488fea 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java @@ -1,10 +1,10 @@ package cc.polyfrost.oneconfig.gui.elements.config; -import cc.polyfrost.oneconfig.config.OneConfigConfig; -import cc.polyfrost.oneconfig.config.interfaces.BasicOption; +import cc.polyfrost.oneconfig.gui.Colors; +import cc.polyfrost.oneconfig.config.elements.BasicOption; import cc.polyfrost.oneconfig.gui.elements.BasicButton; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; -import cc.polyfrost.oneconfig.lwjgl.font.Fonts; +import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.renderer.font.Fonts; import cc.polyfrost.oneconfig.utils.color.ColorPalette; import java.lang.reflect.Field; @@ -39,7 +39,7 @@ public class ConfigButton extends BasicOption { public void draw(long vg, int x, int y) { button.disable(!isEnabled()); if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); - RenderManager.drawText(vg, name, x, y + 17, OneConfigConfig.WHITE, 14f, Fonts.MEDIUM); + RenderManager.drawText(vg, name, x, y + 17, Colors.WHITE, 14f, Fonts.MEDIUM); button.draw(vg, x + (size == 1 ? 352 : 736), y); RenderManager.setAlpha(vg, 1f); } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java index 4b38dd6..b21c7dc 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java @@ -1,14 +1,14 @@ package cc.polyfrost.oneconfig.gui.elements.config; -import cc.polyfrost.oneconfig.config.OneConfigConfig; -import cc.polyfrost.oneconfig.config.interfaces.BasicOption; +import cc.polyfrost.oneconfig.gui.Colors; +import cc.polyfrost.oneconfig.config.elements.BasicOption; import cc.polyfrost.oneconfig.gui.animations.Animation; import cc.polyfrost.oneconfig.gui.animations.ColorAnimation; import cc.polyfrost.oneconfig.gui.animations.DummyAnimation; import cc.polyfrost.oneconfig.gui.animations.EaseInOutQuad; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; -import cc.polyfrost.oneconfig.lwjgl.font.Fonts; -import cc.polyfrost.oneconfig.lwjgl.image.SVGs; +import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.renderer.font.Fonts; +import cc.polyfrost.oneconfig.renderer.image.SVGs; import cc.polyfrost.oneconfig.utils.InputUtils; import cc.polyfrost.oneconfig.utils.color.ColorPalette; import cc.polyfrost.oneconfig.utils.color.ColorUtils; @@ -49,16 +49,16 @@ public class ConfigCheckbox extends BasicOption { } float percentOn = animation.get(); - RenderManager.drawText(vg, name, x + 32, y + 17, OneConfigConfig.WHITE_90, 14f, Fonts.MEDIUM); + RenderManager.drawText(vg, name, x + 32, y + 17, Colors.WHITE_90, 14f, Fonts.MEDIUM); RenderManager.drawRoundedRect(vg, x, y + 4, 24, 24, color.getColor(hover, hover && Mouse.isButtonDown(0)), 6f); - RenderManager.drawHollowRoundRect(vg, x, y + 4, 23.5f, 23.5f, OneConfigConfig.GRAY_300, 6f, 1f); // the 0.5f is to make it look better ok + RenderManager.drawHollowRoundRect(vg, x, y + 4, 23.5f, 23.5f, Colors.GRAY_300, 6f, 1f); // the 0.5f is to make it look better ok - RenderManager.drawRoundedRect(vg, x, y + 4, 24, 24, ColorUtils.setAlpha(OneConfigConfig.PRIMARY_500, (int) (percentOn * 255)), 6f); + RenderManager.drawRoundedRect(vg, x, y + 4, 24, 24, ColorUtils.setAlpha(Colors.PRIMARY_500, (int) (percentOn * 255)), 6f); RenderManager.drawSvg(vg, SVGs.CHECKBOX_TICK, x, y + 4, 24, 24, new Color(1f, 1f, 1f, percentOn).getRGB()); if (toggled && hover) - RenderManager.drawHollowRoundRect(vg, x - 1, y + 3, 24, 24, OneConfigConfig.PRIMARY_600, 6f, 2f); + RenderManager.drawHollowRoundRect(vg, x - 1, y + 3, 24, 24, Colors.PRIMARY_600, 6f, 2f); RenderManager.setAlpha(vg, 1f); } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java index 121416d..0e13f07 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java @@ -1,15 +1,15 @@ package cc.polyfrost.oneconfig.gui.elements.config; -import cc.polyfrost.oneconfig.config.OneConfigConfig; +import cc.polyfrost.oneconfig.gui.Colors; import cc.polyfrost.oneconfig.config.core.OneColor; -import cc.polyfrost.oneconfig.config.interfaces.BasicOption; +import cc.polyfrost.oneconfig.config.elements.BasicOption; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.gui.elements.BasicElement; import cc.polyfrost.oneconfig.gui.elements.ColorSelector; import cc.polyfrost.oneconfig.gui.elements.text.TextInputField; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; -import cc.polyfrost.oneconfig.lwjgl.font.Fonts; -import cc.polyfrost.oneconfig.lwjgl.image.Images; +import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.renderer.font.Fonts; +import cc.polyfrost.oneconfig.renderer.image.Images; import cc.polyfrost.oneconfig.utils.InputUtils; import java.lang.reflect.Field; @@ -41,7 +41,7 @@ public class ConfigColorElement extends BasicOption { } catch (IllegalAccessException e) { return; } - RenderManager.drawText(vg, name, x, y + 16, OneConfigConfig.WHITE_90, 14f, Fonts.MEDIUM); + RenderManager.drawText(vg, name, x, y + 16, Colors.WHITE_90, 14f, Fonts.MEDIUM); if (!hexField.isToggled()) hexField.setInput("#" + color.getHex()); hexField.setErrored(false); if (hexField.isToggled()) { @@ -74,7 +74,7 @@ public class ConfigColorElement extends BasicOption { alphaField.draw(vg, x1 + 336, y); element.update(x1 + 416, y); - RenderManager.drawHollowRoundRect(vg, x1 + 415, y - 1, 64, 32, OneConfigConfig.GRAY_300, 12f, 2f); + RenderManager.drawHollowRoundRect(vg, x1 + 415, y - 1, 64, 32, Colors.GRAY_300, 12f, 2f); RenderManager.drawRoundImage(vg, Images.ALPHA_GRID, x1 + 420, y + 4, 56, 24, 8f); RenderManager.drawRoundedRect(vg, x1 + 420, y + 4, 56, 24, color.getRGB(), 8f); if (element.isClicked() && !element.isToggled()) { diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java index 472f80e..1d64420 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java @@ -1,11 +1,11 @@ package cc.polyfrost.oneconfig.gui.elements.config; -import cc.polyfrost.oneconfig.config.OneConfigConfig; -import cc.polyfrost.oneconfig.config.interfaces.BasicOption; +import cc.polyfrost.oneconfig.gui.Colors; +import cc.polyfrost.oneconfig.config.elements.BasicOption; import cc.polyfrost.oneconfig.gui.animations.ColorAnimation; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; -import cc.polyfrost.oneconfig.lwjgl.font.Fonts; -import cc.polyfrost.oneconfig.lwjgl.image.SVGs; +import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.renderer.font.Fonts; +import cc.polyfrost.oneconfig.renderer.image.SVGs; import cc.polyfrost.oneconfig.utils.InputUtils; import cc.polyfrost.oneconfig.utils.color.ColorPalette; import org.lwjgl.input.Mouse; @@ -17,7 +17,7 @@ import java.util.Arrays; public class ConfigDropdown extends BasicOption { private final String[] options; private final ColorAnimation backgroundColor = new ColorAnimation(ColorPalette.SECONDARY); - private final ColorAnimation atomColor = new ColorAnimation(new ColorPalette(OneConfigConfig.PRIMARY_600, OneConfigConfig.PRIMARY_500, OneConfigConfig.PRIMARY_500)); + private final ColorAnimation atomColor = new ColorAnimation(new ColorPalette(Colors.PRIMARY_600, Colors.PRIMARY_500, Colors.PRIMARY_500)); private boolean opened = false; public ConfigDropdown(Field field, Object parent, String name, int size, String[] options) { @@ -28,7 +28,7 @@ public class ConfigDropdown extends BasicOption { @Override public void draw(long vg, int x, int y) { if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); - RenderManager.drawText(vg, name, x, y + 16, OneConfigConfig.WHITE_90, 14f, Fonts.MEDIUM); + RenderManager.drawText(vg, name, x, y + 16, Colors.WHITE_90, 14f, Fonts.MEDIUM); boolean hovered; if (size == 1) hovered = InputUtils.isAreaHovered(x + 224, y, 256, 32) && isEnabled(); @@ -52,12 +52,12 @@ public class ConfigDropdown extends BasicOption { if (hovered && Mouse.isButtonDown(0)) RenderManager.setAlpha(vg, 0.8f); if (size == 1) { RenderManager.drawRoundedRect(vg, x + 224, y, 256, 32, backgroundColor.getColor(hovered, hovered && Mouse.isButtonDown(0)), 12); - RenderManager.drawText(vg, options[selected], x + 236, y + 16, OneConfigConfig.WHITE_80, 14f, Fonts.MEDIUM); + RenderManager.drawText(vg, options[selected], x + 236, y + 16, Colors.WHITE_80, 14f, Fonts.MEDIUM); RenderManager.drawRoundedRect(vg, x + 452, y + 4, 24, 24, atomColor.getColor(hovered, false), 8); RenderManager.drawSvg(vg, SVGs.DROPDOWN_LIST, x + 452, y + 4, 24, 24); } else { RenderManager.drawRoundedRect(vg, x + 352, y, 640, 32, backgroundColor.getColor(hovered, hovered && Mouse.isButtonDown(0)), 12); - RenderManager.drawText(vg, options[selected], x + 364, y + 16, OneConfigConfig.WHITE_80, 14f, Fonts.MEDIUM); + RenderManager.drawText(vg, options[selected], x + 364, y + 16, Colors.WHITE_80, 14f, Fonts.MEDIUM); RenderManager.drawRoundedRect(vg, x + 964, y + 4, 24, 24, atomColor.getColor(hovered, false), 8); RenderManager.drawSvg(vg, SVGs.DROPDOWN_LIST, x + 964, y + 4, 24, 24); } @@ -81,23 +81,23 @@ public class ConfigDropdown extends BasicOption { if (hovered && Mouse.isButtonDown(0)) RenderManager.setAlpha(vg, 0.8f); if (size == 1) { RenderManager.drawRoundedRect(vg, x + 224, y, 256, 32, backgroundColor.getColor(hovered, hovered && Mouse.isButtonDown(0)), 12); - RenderManager.drawText(vg, options[selected], x + 236, y + 16, OneConfigConfig.WHITE_80, 14f, Fonts.MEDIUM); + RenderManager.drawText(vg, options[selected], x + 236, y + 16, Colors.WHITE_80, 14f, Fonts.MEDIUM); if (hovered && Mouse.isButtonDown(0)) RenderManager.setAlpha(vg, 0.8f); RenderManager.drawRoundedRect(vg, x + 452, y + 4, 24, 24, atomColor.getColor(hovered, false), 8); RenderManager.drawSvg(vg, SVGs.DROPDOWN_LIST, x + 452, y + 4, 24, 24); RenderManager.setAlpha(vg, 1f); - RenderManager.drawRoundedRect(vg, x + 224, y + 40, 256, options.length * 32 + 8, OneConfigConfig.GRAY_700, 12); + RenderManager.drawRoundedRect(vg, x + 224, y + 40, 256, options.length * 32 + 8, Colors.GRAY_700, 12); RenderManager.drawHollowRoundRect(vg, x + 223, y + 39, 258, options.length * 32 + 10, new Color(204, 204, 204, 77).getRGB(), 12, 1); int optionY = y + 44; for (String option : options) { - int color = OneConfigConfig.WHITE_80; + int color = Colors.WHITE_80; boolean optionHovered = InputUtils.isAreaHovered(x + 224, optionY, 252, 32); if (optionHovered && Mouse.isButtonDown(0)) { - RenderManager.drawRoundedRect(vg, x + 228, optionY + 2, 248, 28, OneConfigConfig.PRIMARY_700_80, 8); + RenderManager.drawRoundedRect(vg, x + 228, optionY + 2, 248, 28, Colors.PRIMARY_700_80, 8); } else if (optionHovered) { - RenderManager.drawRoundedRect(vg, x + 228, optionY + 2, 248, 28, OneConfigConfig.PRIMARY_700, 8); - color = OneConfigConfig.WHITE; + RenderManager.drawRoundedRect(vg, x + 228, optionY + 2, 248, 28, Colors.PRIMARY_700, 8); + color = Colors.WHITE; } if (optionHovered && InputUtils.isClicked(true)) { try { @@ -114,23 +114,23 @@ public class ConfigDropdown extends BasicOption { } } else { RenderManager.drawRoundedRect(vg, x + 352, y, 640, 32, backgroundColor.getColor(hovered, hovered && Mouse.isButtonDown(0)), 12); - RenderManager.drawText(vg, options[selected], x + 364, y + 16, OneConfigConfig.WHITE_80, 14f, Fonts.MEDIUM); + RenderManager.drawText(vg, options[selected], x + 364, y + 16, Colors.WHITE_80, 14f, Fonts.MEDIUM); if (hovered && Mouse.isButtonDown(0)) RenderManager.setAlpha(vg, 0.8f); RenderManager.drawRoundedRect(vg, x + 964, y + 4, 24, 24, atomColor.getColor(hovered, false), 8); RenderManager.drawSvg(vg, SVGs.DROPDOWN_LIST, x + 964, y + 4, 24, 24); RenderManager.setAlpha(vg, 1f); - RenderManager.drawRoundedRect(vg, x + 352, y + 40, 640, options.length * 32 + 8, OneConfigConfig.GRAY_700, 12); + RenderManager.drawRoundedRect(vg, x + 352, y + 40, 640, options.length * 32 + 8, Colors.GRAY_700, 12); RenderManager.drawHollowRoundRect(vg, x + 351, y + 39, 642, options.length * 32 + 10, new Color(204, 204, 204, 77).getRGB(), 12, 1); int optionY = y + 44; for (String option : options) { - int color = OneConfigConfig.WHITE_80; + int color = Colors.WHITE_80; boolean optionHovered = InputUtils.isAreaHovered(x + 352, optionY, 640, 36); if (optionHovered && Mouse.isButtonDown(0)) { - RenderManager.drawRoundedRect(vg, x + 356, optionY + 2, 632, 28, OneConfigConfig.PRIMARY_700_80, 8); + RenderManager.drawRoundedRect(vg, x + 356, optionY + 2, 632, 28, Colors.PRIMARY_700_80, 8); } else if (optionHovered) { - RenderManager.drawRoundedRect(vg, x + 356, optionY + 2, 632, 28, OneConfigConfig.PRIMARY_700, 8); - color = OneConfigConfig.WHITE; + RenderManager.drawRoundedRect(vg, x + 356, optionY + 2, 632, 28, Colors.PRIMARY_700, 8); + color = Colors.WHITE; } RenderManager.drawText(vg, option, x + 368, optionY + 18, color, 14, Fonts.MEDIUM); diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java index e7b1083..5bf28c0 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java @@ -1,12 +1,12 @@ package cc.polyfrost.oneconfig.gui.elements.config; -import cc.polyfrost.oneconfig.config.OneConfigConfig; -import cc.polyfrost.oneconfig.config.interfaces.BasicOption; +import cc.polyfrost.oneconfig.gui.Colors; +import cc.polyfrost.oneconfig.config.elements.BasicOption; import cc.polyfrost.oneconfig.gui.animations.Animation; import cc.polyfrost.oneconfig.gui.animations.DummyAnimation; import cc.polyfrost.oneconfig.gui.animations.EaseInOutCubic; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; -import cc.polyfrost.oneconfig.lwjgl.font.Fonts; +import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.renderer.font.Fonts; import cc.polyfrost.oneconfig.utils.InputUtils; import java.lang.reflect.Field; @@ -38,14 +38,14 @@ public class ConfigDualOption extends BasicOption { if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); boolean hoveredLeft = InputUtils.isAreaHovered(x + 226, y, 128, 32) && isEnabled(); boolean hoveredRight = InputUtils.isAreaHovered(x + 354, y, 128, 32) && isEnabled(); - RenderManager.drawText(vg, name, x, y + 16, OneConfigConfig.WHITE_90, 14f, Fonts.MEDIUM); - RenderManager.drawRoundedRect(vg, x + 226, y, 256, 32, OneConfigConfig.GRAY_600, 12f); - RenderManager.drawRoundedRect(vg, x + posAnimation.get(), y + 2, 124, 28, OneConfigConfig.PRIMARY_600, 10f); + RenderManager.drawText(vg, name, x, y + 16, Colors.WHITE_90, 14f, Fonts.MEDIUM); + RenderManager.drawRoundedRect(vg, x + 226, y, 256, 32, Colors.GRAY_600, 12f); + RenderManager.drawRoundedRect(vg, x + posAnimation.get(), y + 2, 124, 28, Colors.PRIMARY_600, 10f); if (!hoveredLeft && isEnabled()) RenderManager.setAlpha(vg, 0.8f); - RenderManager.drawText(vg, left, x + 290 - RenderManager.getTextWidth(vg, left, 12f, Fonts.MEDIUM) / 2, y + 17, OneConfigConfig.WHITE, 12f, Fonts.MEDIUM); + RenderManager.drawText(vg, left, x + 290 - RenderManager.getTextWidth(vg, left, 12f, Fonts.MEDIUM) / 2, y + 17, Colors.WHITE, 12f, Fonts.MEDIUM); if (isEnabled()) RenderManager.setAlpha(vg, 1f); if (!hoveredRight && isEnabled()) RenderManager.setAlpha(vg, 0.8f); - RenderManager.drawText(vg, right, x + 418 - RenderManager.getTextWidth(vg, right, 12f, Fonts.MEDIUM) / 2, y + 17, OneConfigConfig.WHITE, 12f, Fonts.MEDIUM); + RenderManager.drawText(vg, right, x + 418 - RenderManager.getTextWidth(vg, right, 12f, Fonts.MEDIUM) / 2, y + 17, Colors.WHITE, 12f, Fonts.MEDIUM); RenderManager.setAlpha(vg, 1); if ((hoveredLeft && toggled || hoveredRight && !toggled) && InputUtils.isClicked()) { diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java index 445424e..bfdb8ca 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java @@ -1,11 +1,11 @@ package cc.polyfrost.oneconfig.gui.elements.config; -import cc.polyfrost.oneconfig.config.OneConfigConfig; -import cc.polyfrost.oneconfig.config.interfaces.BasicOption; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; -import cc.polyfrost.oneconfig.lwjgl.font.Fonts; -import cc.polyfrost.oneconfig.lwjgl.scissor.Scissor; -import cc.polyfrost.oneconfig.lwjgl.scissor.ScissorManager; +import cc.polyfrost.oneconfig.gui.Colors; +import cc.polyfrost.oneconfig.config.elements.BasicOption; +import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.renderer.font.Fonts; +import cc.polyfrost.oneconfig.renderer.scissor.Scissor; +import cc.polyfrost.oneconfig.renderer.scissor.ScissorManager; import java.lang.reflect.Field; @@ -18,7 +18,7 @@ public class ConfigHeader extends BasicOption { @Override public void draw(long vg, int x, int y) { Scissor scissor = ScissorManager.scissor(vg, x, y, size == 1 ? 480 : 992, 32); - RenderManager.drawText(vg, name, x, y + 17, OneConfigConfig.WHITE_90, 24, Fonts.MEDIUM); + RenderManager.drawText(vg, name, x, y + 17, Colors.WHITE_90, 24, Fonts.MEDIUM); ScissorManager.resetScissor(vg, scissor); } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigInfo.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigInfo.java index 6a6c4f2..c0e041f 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigInfo.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigInfo.java @@ -1,12 +1,12 @@ package cc.polyfrost.oneconfig.gui.elements.config; -import cc.polyfrost.oneconfig.config.OneConfigConfig; +import cc.polyfrost.oneconfig.gui.Colors; import cc.polyfrost.oneconfig.config.data.InfoType; -import cc.polyfrost.oneconfig.config.interfaces.BasicOption; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; -import cc.polyfrost.oneconfig.lwjgl.font.Fonts; -import cc.polyfrost.oneconfig.lwjgl.scissor.Scissor; -import cc.polyfrost.oneconfig.lwjgl.scissor.ScissorManager; +import cc.polyfrost.oneconfig.config.elements.BasicOption; +import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.renderer.font.Fonts; +import cc.polyfrost.oneconfig.renderer.scissor.Scissor; +import cc.polyfrost.oneconfig.renderer.scissor.ScissorManager; import java.lang.reflect.Field; @@ -22,7 +22,7 @@ public class ConfigInfo extends BasicOption { public void draw(long vg, int x, int y) { Scissor scissor = ScissorManager.scissor(vg, x, y, size == 1 ? 448 : 960, 32); RenderManager.drawInfo(vg, type, x, y + 4, 24); - RenderManager.drawText(vg, name, x + 32, y + 18, OneConfigConfig.WHITE_90, 14, Fonts.MEDIUM); + RenderManager.drawText(vg, name, x + 32, y + 18, Colors.WHITE_90, 14, Fonts.MEDIUM); ScissorManager.resetScissor(vg, scissor); } 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 a448b14..986bb98 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 @@ -1,13 +1,13 @@ package cc.polyfrost.oneconfig.gui.elements.config; -import cc.polyfrost.oneconfig.config.OneConfigConfig; +import cc.polyfrost.oneconfig.gui.Colors; import cc.polyfrost.oneconfig.config.core.OneKeyBind; -import cc.polyfrost.oneconfig.config.interfaces.BasicOption; +import cc.polyfrost.oneconfig.config.elements.BasicOption; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.gui.elements.BasicButton; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; -import cc.polyfrost.oneconfig.lwjgl.font.Fonts; -import cc.polyfrost.oneconfig.lwjgl.image.SVGs; +import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.renderer.font.Fonts; +import cc.polyfrost.oneconfig.renderer.image.SVGs; import cc.polyfrost.oneconfig.utils.color.ColorPalette; import gg.essential.universal.UKeyboard; @@ -26,7 +26,7 @@ public class ConfigKeyBind extends BasicOption { @Override public void draw(long vg, int x, int y) { if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); - RenderManager.drawText(vg, name, x, y + 17, OneConfigConfig.WHITE, 14f, Fonts.MEDIUM); + RenderManager.drawText(vg, name, x, y + 17, Colors.WHITE, 14f, Fonts.MEDIUM); OneKeyBind keyBind = getKeyBind(); String text = keyBind.getDisplay(); button.disable(!isEnabled()); diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java index 8b47045..e4fcc77 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java @@ -1,14 +1,14 @@ package cc.polyfrost.oneconfig.gui.elements.config; -import cc.polyfrost.oneconfig.config.OneConfigConfig; -import cc.polyfrost.oneconfig.config.data.OptionPage; -import cc.polyfrost.oneconfig.config.interfaces.BasicOption; +import cc.polyfrost.oneconfig.gui.Colors; +import cc.polyfrost.oneconfig.config.elements.OptionPage; +import cc.polyfrost.oneconfig.config.elements.BasicOption; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.gui.animations.ColorAnimation; import cc.polyfrost.oneconfig.gui.pages.ModConfigPage; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; -import cc.polyfrost.oneconfig.lwjgl.font.Fonts; -import cc.polyfrost.oneconfig.lwjgl.image.SVGs; +import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.renderer.font.Fonts; +import cc.polyfrost.oneconfig.renderer.image.SVGs; import cc.polyfrost.oneconfig.utils.InputUtils; import cc.polyfrost.oneconfig.utils.color.ColorPalette; import org.lwjgl.input.Mouse; @@ -35,9 +35,9 @@ public class ConfigPageButton extends BasicOption { if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); RenderManager.drawRoundedRect(vg, x - 16, y, 1024, height, backgroundColor.getColor(hovered, hovered && Mouse.isButtonDown(0)), 20); - RenderManager.drawText(vg, name, x + 10, y + 32, OneConfigConfig.WHITE_90, 24, Fonts.MEDIUM); + RenderManager.drawText(vg, name, x + 10, y + 32, Colors.WHITE_90, 24, Fonts.MEDIUM); if (!description.equals("")) - RenderManager.drawText(vg, name, x + 10, y + 70, OneConfigConfig.WHITE_90, 14, Fonts.MEDIUM); + RenderManager.drawText(vg, name, x + 10, y + 70, Colors.WHITE_90, 14, Fonts.MEDIUM); RenderManager.drawSvg(vg, SVGs.CARET_RIGHT, x + 981f, y + (description.equals("") ? 20f : 36f), 13, 22); if (clicked) OneConfigGui.INSTANCE.openPage(new ModConfigPage(page)); diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java index 45217c0..2bda274 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java @@ -1,10 +1,10 @@ package cc.polyfrost.oneconfig.gui.elements.config; -import cc.polyfrost.oneconfig.config.OneConfigConfig; -import cc.polyfrost.oneconfig.config.interfaces.BasicOption; +import cc.polyfrost.oneconfig.gui.Colors; +import cc.polyfrost.oneconfig.config.elements.BasicOption; import cc.polyfrost.oneconfig.gui.elements.text.NumberInputField; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; -import cc.polyfrost.oneconfig.lwjgl.font.Fonts; +import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.renderer.font.Fonts; import cc.polyfrost.oneconfig.utils.InputUtils; import cc.polyfrost.oneconfig.utils.MathUtils; import org.lwjgl.input.Mouse; @@ -67,17 +67,17 @@ public class ConfigSlider extends BasicOption { } if (!inputField.isToggled()) inputField.setCurrentValue(value); - RenderManager.drawText(vg, name, x, y + 17, OneConfigConfig.WHITE_90, 14f, Fonts.MEDIUM); - RenderManager.drawRoundedRect(vg, x + 352, y + 13, 512, 6, OneConfigConfig.GRAY_300, 4f); - RenderManager.drawRoundedRect(vg, x + 352, y + 13, xCoordinate - x - 352, 6, OneConfigConfig.PRIMARY_500, 4f); + RenderManager.drawText(vg, name, x, y + 17, Colors.WHITE_90, 14f, Fonts.MEDIUM); + RenderManager.drawRoundedRect(vg, x + 352, y + 13, 512, 6, Colors.GRAY_300, 4f); + RenderManager.drawRoundedRect(vg, x + 352, y + 13, xCoordinate - x - 352, 6, Colors.PRIMARY_500, 4f); if (step > 0) { for (float i = x + 352; i <= x + 864; i += 512 / ((max - min) / step)) { - int color = xCoordinate > i - 2 ? OneConfigConfig.PRIMARY_500 : OneConfigConfig.GRAY_300; + int color = xCoordinate > i - 2 ? Colors.PRIMARY_500 : Colors.GRAY_300; RenderManager.drawRoundedRect(vg, i - 2, y + 9, 4, 14, color, 2f); } } - if (step == 0) RenderManager.drawRoundedRect(vg, xCoordinate - 12, y + 4, 24, 24, OneConfigConfig.WHITE, 12f); - else RenderManager.drawRoundedRect(vg, xCoordinate - 4, y + 4, 8, 24, OneConfigConfig.WHITE, 4f); + if (step == 0) RenderManager.drawRoundedRect(vg, xCoordinate - 12, y + 4, 24, 24, Colors.WHITE, 12f); + else RenderManager.drawRoundedRect(vg, xCoordinate - 4, y + 4, 8, 24, Colors.WHITE, 4f); inputField.draw(vg, x + 892, y); RenderManager.setAlpha(vg, 1f); } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java index 090f5a6..2aedf4e 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java @@ -1,13 +1,13 @@ package cc.polyfrost.oneconfig.gui.elements.config; -import cc.polyfrost.oneconfig.config.OneConfigConfig; -import cc.polyfrost.oneconfig.config.interfaces.BasicOption; +import cc.polyfrost.oneconfig.gui.Colors; +import cc.polyfrost.oneconfig.config.elements.BasicOption; import cc.polyfrost.oneconfig.gui.animations.Animation; import cc.polyfrost.oneconfig.gui.animations.ColorAnimation; import cc.polyfrost.oneconfig.gui.animations.DummyAnimation; import cc.polyfrost.oneconfig.gui.animations.EaseInOutQuad; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; -import cc.polyfrost.oneconfig.lwjgl.font.Fonts; +import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.renderer.font.Fonts; import cc.polyfrost.oneconfig.utils.InputUtils; import cc.polyfrost.oneconfig.utils.color.ColorPalette; import org.lwjgl.input.Mouse; @@ -38,8 +38,8 @@ public class ConfigSwitch extends BasicOption { boolean hovered = InputUtils.isAreaHovered(x, y, 42, 32); if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); RenderManager.drawRoundedRect(vg, x, y + 4, 42, 24, color.getColor(hovered, hovered && Mouse.isButtonDown(0)), 12f); - RenderManager.drawRoundedRect(vg, x2, y + 7, 18, 18, OneConfigConfig.WHITE, 9f); - RenderManager.drawText(vg, name, x + 50, y + 17, OneConfigConfig.WHITE, 14f, Fonts.MEDIUM); + RenderManager.drawRoundedRect(vg, x2, y + 7, 18, 18, Colors.WHITE, 9f); + RenderManager.drawText(vg, name, x + 50, y + 17, Colors.WHITE, 14f, Fonts.MEDIUM); if (InputUtils.isAreaClicked(x, y, 42, 32) && isEnabled()) { toggled = !toggled; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java index 966a85e..225232b 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java @@ -1,11 +1,11 @@ package cc.polyfrost.oneconfig.gui.elements.config; -import cc.polyfrost.oneconfig.config.OneConfigConfig; -import cc.polyfrost.oneconfig.config.interfaces.BasicOption; +import cc.polyfrost.oneconfig.gui.Colors; +import cc.polyfrost.oneconfig.config.elements.BasicOption; import cc.polyfrost.oneconfig.gui.elements.text.TextInputField; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; -import cc.polyfrost.oneconfig.lwjgl.font.Fonts; -import cc.polyfrost.oneconfig.lwjgl.image.SVGs; +import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.renderer.font.Fonts; +import cc.polyfrost.oneconfig.renderer.image.SVGs; import cc.polyfrost.oneconfig.utils.InputUtils; import org.lwjgl.input.Mouse; @@ -27,7 +27,7 @@ public class ConfigTextBox extends BasicOption { public void draw(long vg, int x, int y) { if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); textField.disable(!isEnabled()); - RenderManager.drawText(vg, name, x, y + 16, OneConfigConfig.WHITE_90, 14, Fonts.MEDIUM); + RenderManager.drawText(vg, name, x, y + 16, Colors.WHITE_90, 14, Fonts.MEDIUM); try { String value = (String) get(); @@ -42,7 +42,7 @@ public class ConfigTextBox extends BasicOption { if (secure) { SVGs icon = textField.getPassword() ? SVGs.EYE_OFF : SVGs.EYE; boolean hovered = InputUtils.isAreaHovered(x + 967, y + 7, 18, 18) && isEnabled(); - int color = hovered ? OneConfigConfig.WHITE : OneConfigConfig.WHITE_80; + int color = hovered ? Colors.WHITE : Colors.WHITE_80; if (hovered && InputUtils.isClicked()) textField.setPassword(!textField.getPassword()); if (hovered && Mouse.isButtonDown(0)) RenderManager.setAlpha(vg, 0.5f); RenderManager.drawSvg(vg, icon, x + 967, y + 7, 18, 18, color); diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/NumberInputField.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/NumberInputField.java index ed05760..a76c242 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/NumberInputField.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/NumberInputField.java @@ -1,10 +1,10 @@ package cc.polyfrost.oneconfig.gui.elements.text; -import cc.polyfrost.oneconfig.config.OneConfigConfig; +import cc.polyfrost.oneconfig.gui.Colors; import cc.polyfrost.oneconfig.gui.animations.ColorAnimation; import cc.polyfrost.oneconfig.gui.elements.BasicElement; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; -import cc.polyfrost.oneconfig.lwjgl.image.SVGs; +import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.renderer.image.SVGs; import cc.polyfrost.oneconfig.utils.color.ColorPalette; public class NumberInputField extends TextInputField { @@ -29,7 +29,7 @@ public class NumberInputField extends TextInputField { @Override public void draw(long vg, int x, int y) { super.errored = false; - RenderManager.drawRoundedRect(vg, x + width + 4, y, 12, 28, OneConfigConfig.GRAY_500, 6f); + RenderManager.drawRoundedRect(vg, x + width + 4, y, 12, 28, Colors.GRAY_500, 6f); upArrow.disable(disabled); downArrow.disable(disabled); upArrow.update(x + width + 4, y); diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/SearchField.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/SearchField.java deleted file mode 100644 index af7b6e1..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/SearchField.java +++ /dev/null @@ -1,14 +0,0 @@ -package cc.polyfrost.oneconfig.gui.elements.text; - -public class SearchField extends TextInputField { - - public SearchField(int width, int height, String defaultText, boolean multiLine, boolean password) { - super(width, height, defaultText, multiLine, password); - } - - @Override - public void draw(long vg, int x, int y) { - super.draw(vg, x, y); - // TODO - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java index b16472d..3fde012 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java @@ -1,12 +1,12 @@ package cc.polyfrost.oneconfig.gui.elements.text; -import cc.polyfrost.oneconfig.config.OneConfigConfig; +import cc.polyfrost.oneconfig.gui.Colors; import cc.polyfrost.oneconfig.gui.elements.BasicElement; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; -import cc.polyfrost.oneconfig.lwjgl.font.Fonts; -import cc.polyfrost.oneconfig.lwjgl.image.SVGs; -import cc.polyfrost.oneconfig.lwjgl.scissor.Scissor; -import cc.polyfrost.oneconfig.lwjgl.scissor.ScissorManager; +import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.renderer.font.Fonts; +import cc.polyfrost.oneconfig.renderer.image.SVGs; +import cc.polyfrost.oneconfig.renderer.scissor.Scissor; +import cc.polyfrost.oneconfig.renderer.scissor.ScissorManager; import cc.polyfrost.oneconfig.utils.InputUtils; import cc.polyfrost.oneconfig.utils.MathUtils; import cc.polyfrost.oneconfig.utils.TextUtils; @@ -102,14 +102,14 @@ public class TextInputField extends BasicElement { this.y = y; this.vg = vg; try { - int colorOutline = errored ? OneConfigConfig.ERROR_700 : OneConfigConfig.GRAY_700; + int colorOutline = errored ? Colors.ERROR_700 : Colors.GRAY_700; if (!toggled) RenderManager.drawHollowRoundRect(vg, x, y, width - 0.5f, height - 0.5f, colorOutline, 12f, 2f); else { RenderManager.setAlpha(vg, 0.15f); - RenderManager.drawRoundedRect(vg, x - 4, y - 4, width + 8, height + 8, errored ? OneConfigConfig.ERROR_600 : OneConfigConfig.PRIMARY_600, 16); + RenderManager.drawRoundedRect(vg, x - 4, y - 4, width + 8, height + 8, errored ? Colors.ERROR_600 : Colors.PRIMARY_600, 16); RenderManager.setAlpha(vg, 1f); - RenderManager.drawHollowRoundRect(vg, x, y, width - 0.5f, height - 0.5f, errored ? OneConfigConfig.ERROR_600 : OneConfigConfig.PRIMARY_600, 12f, 2f); + RenderManager.drawHollowRoundRect(vg, x, y, width - 0.5f, height - 0.5f, errored ? Colors.ERROR_600 : Colors.PRIMARY_600, 12f, 2f); } Scissor scissor = ScissorManager.scissor(vg, x, y, width, height); super.update(x, y); @@ -117,7 +117,7 @@ public class TextInputField extends BasicElement { onClose(); toggled = false; } - int color = toggled ? OneConfigConfig.WHITE : OneConfigConfig.WHITE_60; + int color = toggled ? Colors.WHITE : Colors.WHITE_60; if (!toggled) caretPos = input.length(); if (caretPos > input.length()) caretPos = input.length(); if (prevCaret > input.length()) prevCaret = input.length(); @@ -177,15 +177,15 @@ public class TextInputField extends BasicElement { float halfTextWidth = this.getTextWidth(vg, input) / 2f; if (start != 0f && end != 0f && toggled) { if (!multiLine) { - RenderManager.drawRect(vg, start, y + height / 2f - 10, end, 20, OneConfigConfig.GRAY_300); + RenderManager.drawRect(vg, start, y + height / 2f - 10, end, 20, Colors.GRAY_300); } else if (startLine == endLine) { - RenderManager.drawRect(vg, start, y + 10 + 24 * startLine, end, 20, OneConfigConfig.GRAY_300); + RenderManager.drawRect(vg, start, y + 10 + 24 * startLine, end, 20, Colors.GRAY_300); } else { - RenderManager.drawRect(vg, start, y + 10 + 24 * startLine, this.width - 24, 20, OneConfigConfig.GRAY_300); + RenderManager.drawRect(vg, start, y + 10 + 24 * startLine, this.width - 24, 20, Colors.GRAY_300); for (int i = startLine + 1; i < endLine; i++) { - RenderManager.drawRect(vg, x + 12, y + 10 + 24 * i, this.width - 24, 20, OneConfigConfig.GRAY_300); + RenderManager.drawRect(vg, x + 12, y + 10 + 24 * i, this.width - 24, 20, Colors.GRAY_300); } - RenderManager.drawRect(vg, x + 12, y + 10 + 24 * endLine, end, 20, OneConfigConfig.GRAY_300); + RenderManager.drawRect(vg, x + 12, y + 10 + 24 * endLine, end, 20, Colors.GRAY_300); } } if (hovered) { @@ -215,11 +215,11 @@ public class TextInputField extends BasicElement { if (toggled) { if (multiLine) { int lineY = y + 20 + getCaretLine(caretPos) * 24; - RenderManager.drawLine(vg, x + width + 12, lineY - 10, x + width + 12, lineY + 10, 1, OneConfigConfig.WHITE); + RenderManager.drawLine(vg, x + width + 12, lineY - 10, x + width + 12, lineY + 10, 1, Colors.WHITE); } else if (!centered) { - RenderManager.drawLine(vg, x + width + 12, (float) y + height / 2f - 10, x + width + 12, (float) y + height / 2f + 10, 1, OneConfigConfig.WHITE); + RenderManager.drawLine(vg, x + width + 12, (float) y + height / 2f - 10, x + width + 12, (float) y + height / 2f + 10, 1, Colors.WHITE); } else { - RenderManager.drawLine(vg, x + this.width / 2f - halfTextWidth + width, (float) y + height / 2f - 10, x + this.width / 2f - halfTextWidth + width, (float) y + height / 2f + 10, 1, OneConfigConfig.WHITE); + RenderManager.drawLine(vg, x + this.width / 2f - halfTextWidth + width, (float) y + height / 2f - 10, x + this.width / 2f - halfTextWidth + width, (float) y + height / 2f + 10, 1, Colors.WHITE); } } 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 f67a028..ddc144c 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/CreditsPage.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/CreditsPage.java @@ -1,8 +1,8 @@ package cc.polyfrost.oneconfig.gui.pages; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; -import cc.polyfrost.oneconfig.lwjgl.font.Fonts; -import cc.polyfrost.oneconfig.lwjgl.image.SVGs; +import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.renderer.font.Fonts; +import cc.polyfrost.oneconfig.renderer.image.SVGs; public class CreditsPage extends Page { public CreditsPage() { diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/HomePage.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/HomePage.java index bd73c1e..4c24058 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/HomePage.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/HomePage.java @@ -1,9 +1,9 @@ package cc.polyfrost.oneconfig.gui.pages; -import cc.polyfrost.oneconfig.config.OneConfigConfig; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; -import cc.polyfrost.oneconfig.lwjgl.font.Fonts; -import cc.polyfrost.oneconfig.lwjgl.image.SVGs; +import cc.polyfrost.oneconfig.gui.Colors; +import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.renderer.font.Fonts; +import cc.polyfrost.oneconfig.renderer.image.SVGs; public class HomePage extends Page { /*private final BasicButton socialsBtn = new BasicButton(184, 36, "Socials", SVGs.SHARE, SVGs.POP_OUT, BasicButton.ALIGNMENT_CENTER, ColorUtils.PRIMARY); @@ -34,10 +34,10 @@ public class HomePage extends Page { public void draw(long vg, int x, int y) { RenderManager.drawRoundedRect(vg, x, y, 184, 36, -1, 12f); RenderManager.drawText(vg, "This is a cool string to test pages", x + 32, y + 72, -1, 36f, Fonts.BOLD); - RenderManager.drawRoundedRect(vg, x + 350, y + 310, 300, 200, OneConfigConfig.PRIMARY_600, 14f); + RenderManager.drawRoundedRect(vg, x + 350, y + 310, 300, 200, Colors.PRIMARY_600, 14f); RenderManager.drawSvg(vg, SVGs.INFO_CIRCLE, x + 20, y + 604, 24, 24); - RenderManager.drawText(vg, "Info", x + 52, y + 618, OneConfigConfig.WHITE_90, 24f, Fonts.MEDIUM); - RenderManager.drawRoundedRect(vg, x + 16, y + 644, 1024, 64, OneConfigConfig.GRAY_700, 20f); + RenderManager.drawText(vg, "Info", x + 52, y + 618, Colors.WHITE_90, 24f, Fonts.MEDIUM); + RenderManager.drawRoundedRect(vg, x + 16, y + 644, 1024, 64, Colors.GRAY_700, 20f); RenderManager.drawURL(vg, "https://www.youtube.com/watch?v=dQw4w9WgXcQ", x + 100, y + 205, 24, Fonts.MEDIUM); 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 b5f2256..3e8fbf8 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java @@ -1,11 +1,11 @@ package cc.polyfrost.oneconfig.gui.pages; -import cc.polyfrost.oneconfig.config.data.OptionPage; -import cc.polyfrost.oneconfig.config.data.OptionSubcategory; -import cc.polyfrost.oneconfig.config.interfaces.BasicOption; +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.elements.BasicButton; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; -import cc.polyfrost.oneconfig.lwjgl.font.Fonts; +import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.renderer.font.Fonts; import cc.polyfrost.oneconfig.utils.color.ColorPalette; import java.util.ArrayList; 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 3b8e172..c192255 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java @@ -1,14 +1,15 @@ package cc.polyfrost.oneconfig.gui.pages; -import cc.polyfrost.oneconfig.OneConfig; -import cc.polyfrost.oneconfig.config.OneConfigConfig; +import cc.polyfrost.oneconfig.internal.OneConfig; +import cc.polyfrost.oneconfig.gui.Colors; import cc.polyfrost.oneconfig.config.data.Mod; import cc.polyfrost.oneconfig.config.data.ModType; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.gui.elements.BasicButton; import cc.polyfrost.oneconfig.gui.elements.ModCard; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; -import cc.polyfrost.oneconfig.lwjgl.font.Fonts; +import cc.polyfrost.oneconfig.internal.config.OneConfigConfig; +import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.renderer.font.Fonts; import cc.polyfrost.oneconfig.utils.color.ColorPalette; import java.util.ArrayList; @@ -56,7 +57,7 @@ public class ModsPage extends Page { } size = iY + 119; if (iX == x + 16 && iY == y + 72) { - RenderManager.drawText(vg, "Looks like there is nothing here. Try another category?", x + 16, y + 72, OneConfigConfig.WHITE_60, 14f, Fonts.MEDIUM); + RenderManager.drawText(vg, "Looks like there is nothing here. Try another category?", x + 16, y + 72, Colors.WHITE_60, 14f, Fonts.MEDIUM); } } 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 fda6ea2..b1bc083 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java @@ -2,8 +2,8 @@ package cc.polyfrost.oneconfig.gui.pages; import cc.polyfrost.oneconfig.gui.animations.Animation; import cc.polyfrost.oneconfig.gui.animations.EaseOutQuad; -import cc.polyfrost.oneconfig.lwjgl.scissor.Scissor; -import cc.polyfrost.oneconfig.lwjgl.scissor.ScissorManager; +import cc.polyfrost.oneconfig.renderer.scissor.Scissor; +import cc.polyfrost.oneconfig.renderer.scissor.ScissorManager; import org.lwjgl.input.Mouse; /** diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java index d78fbaf..445b2ad 100644 --- a/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java +++ b/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java @@ -1,7 +1,7 @@ package cc.polyfrost.oneconfig.hud; import cc.polyfrost.oneconfig.config.core.OneColor; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; +import cc.polyfrost.oneconfig.renderer.RenderManager; public abstract class BasicHud { public boolean enabled; diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java index 9525ba4..f868660 100644 --- a/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java +++ b/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java @@ -1,6 +1,6 @@ package cc.polyfrost.oneconfig.hud; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; +import cc.polyfrost.oneconfig.renderer.RenderManager; import gg.essential.universal.UMinecraft; public abstract class TextHud extends BasicHud { diff --git a/src/main/java/cc/polyfrost/oneconfig/init/OneConfigInit.java b/src/main/java/cc/polyfrost/oneconfig/init/OneConfigInit.java deleted file mode 100644 index df424fd..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/init/OneConfigInit.java +++ /dev/null @@ -1,24 +0,0 @@ -package cc.polyfrost.oneconfig.init; - -import net.minecraft.launchwrapper.Launch; -import org.spongepowered.asm.launch.MixinBootstrap; -import org.spongepowered.asm.mixin.Mixins; - -/** - * Initializes the OneConfig mod. - *

MUST BE CALLED VIA AN ITWEAKER / FMLLOADINGPLUGIN FOR 1.12 AND BELOW, OR A PRELAUNCH TWEAKER FOR 1.14+ FABRIC.

- */ -@SuppressWarnings("unused") -public class OneConfigInit { - - /** - * Initializes the OneConfig mod. - * - * @param args The arguments passed to the mod. - */ - public static void initialize(String[] args) { - Launch.blackboard.put("oneconfig.initialized", true); - MixinBootstrap.init(); - Mixins.addConfiguration("mixins.oneconfig.json"); - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java b/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java new file mode 100644 index 0000000..3a00e06 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java @@ -0,0 +1,85 @@ +package cc.polyfrost.oneconfig.internal; + +import cc.polyfrost.oneconfig.config.core.ConfigCore; +import cc.polyfrost.oneconfig.config.data.Mod; +import cc.polyfrost.oneconfig.config.data.ModType; +import cc.polyfrost.oneconfig.events.EventManager; +import cc.polyfrost.oneconfig.hud.HudCore; +import cc.polyfrost.oneconfig.internal.config.OneConfigConfig; +import cc.polyfrost.oneconfig.internal.command.OneConfigCommand; +import cc.polyfrost.oneconfig.internal.gui.BlurHandler; +import cc.polyfrost.oneconfig.test.TestCommand; +import cc.polyfrost.oneconfig.test.TestConfig; +import cc.polyfrost.oneconfig.utils.gui.GuiUtils; +import cc.polyfrost.oneconfig.utils.commands.CommandManager; +import cc.polyfrost.oneconfig.utils.hypixel.HypixelUtils; +import net.minecraftforge.fml.common.DummyModContainer; +import net.minecraftforge.fml.common.Loader; +import net.minecraftforge.fml.common.ModContainer; +import net.minecraftforge.fml.common.ModMetadata; + +import java.io.File; +import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.List; + +/** + * The main class of OneConfig. + */ +@net.minecraftforge.fml.common.Mod(modid = "@ID@", name = "@NAME@", version = "@VER@") +public class OneConfig { + public static final File oneConfigDir = new File("./OneConfig"); + public static final List loadedMods = new ArrayList<>(); + public static final List loadedOtherMods = new ArrayList<>(); + public static OneConfigConfig config; + public static TestConfig testConfig; + private static boolean preLaunched = false; + private static boolean initialized = false; + + /** + * Called before mods are loaded. + *

SHOULD NOT BE CALLED!

+ */ + public static void preLaunch() { + if (preLaunched) return; + if (!net.minecraft.launchwrapper.Launch.blackboard.containsKey("oneconfig.initialized")) { + throw new RuntimeException("OneConfig has not been initialized! Please add the OneConfig tweaker or call OneConfigInit via an ITweaker or a FMLLoadingPlugin!"); + } + oneConfigDir.mkdirs(); + new File(oneConfigDir, "profiles").mkdirs(); + config = new OneConfigConfig(); + preLaunched = true; + } + + /** + * Called after mods are loaded. + *

SHOULD NOT BE CALLED!

+ */ + @SuppressWarnings("ResultOfMethodCallIgnored") + public static void init() { + if (initialized) return; + GuiUtils.getDeltaTime(); // called to make sure static initializer is called + BlurHandler.INSTANCE.load(); + testConfig = new TestConfig(); + CommandManager.INSTANCE.registerCommand(OneConfigCommand.class); + CommandManager.INSTANCE.registerCommand(TestCommand.class); + EventManager.INSTANCE.register(new HudCore()); + EventManager.INSTANCE.register(HypixelUtils.INSTANCE); + reloadModsList(); + initialized = true; + } + + public static void reloadModsList() { + loadedMods.addAll(ConfigCore.oneConfigMods); + LinkedHashSet modData = new LinkedHashSet<>(ConfigCore.oneConfigMods); + for (ModContainer mod : Loader.instance().getActiveModList()) { + ModMetadata metadata = mod.getMetadata(); + loadedOtherMods.add(metadata); + String imageName = Loader.instance().activeModContainer() == null || Loader.instance().activeModContainer().getMetadata().logoFile.trim().equals("") ? null : "/" + Loader.instance().activeModContainer().getMetadata().logoFile; + Mod newMod = new Mod(metadata.name, ModType.THIRD_PARTY, imageName); + newMod.isShortCut = true; + if (mod instanceof DummyModContainer || newMod.name.equals("OneConfig")) continue; + if (modData.add(newMod)) loadedMods.add(newMod); + } + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/command/OneConfigCommand.java b/src/main/java/cc/polyfrost/oneconfig/internal/command/OneConfigCommand.java new file mode 100644 index 0000000..82d040a --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/internal/command/OneConfigCommand.java @@ -0,0 +1,38 @@ +package cc.polyfrost.oneconfig.internal.command; + +import cc.polyfrost.oneconfig.gui.HudGui; +import cc.polyfrost.oneconfig.gui.OneConfigGui; +import cc.polyfrost.oneconfig.utils.gui.GuiUtils; +import cc.polyfrost.oneconfig.utils.InputUtils; +import cc.polyfrost.oneconfig.utils.commands.annotations.Command; +import cc.polyfrost.oneconfig.utils.commands.annotations.Main; +import cc.polyfrost.oneconfig.utils.commands.annotations.SubCommand; + +/** + * The main OneConfig command. + */ +@Command(value = "oneconfig", aliases = {"ocfg", "oneconfig"}, description = "Access the OneConfig GUI.") +public class OneConfigCommand { + + @Main + private static void main() { + GuiUtils.displayScreen(OneConfigGui.create()); + } + + @SubCommand(value = "hud", description = "Open the OneConfig HUD config.") + private static class HUDSubCommand { + @Main + private static void main() { + GuiUtils.displayScreen(new HudGui()); + } + } + + @SubCommand(value = "destroy", description = "Destroy the cached OneConfig GUI.") + private static class DestroySubCommand { + @Main + private static void main() { + OneConfigGui.instanceToRestore = null; + InputUtils.blockClicks(false); + } + } +} \ No newline at end of file diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/config/OneConfigConfig.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/OneConfigConfig.java new file mode 100644 index 0000000..8f67ee6 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/OneConfigConfig.java @@ -0,0 +1,48 @@ +package cc.polyfrost.oneconfig.internal.config; + +import cc.polyfrost.oneconfig.config.Config; +import cc.polyfrost.oneconfig.config.core.OneColor; +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; +import java.util.ArrayList; + +public class OneConfigConfig extends Config { + public static String currentProfile = "Default Profile"; + public static ArrayList favoriteMods = new ArrayList<>(); + public static ArrayList favoriteColors = new ArrayList<>(); + public static ArrayList recentColors = new ArrayList<>(); + public static boolean allShowShortCut = 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(); + } + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/gui/BlurHandler.java b/src/main/java/cc/polyfrost/oneconfig/internal/gui/BlurHandler.java new file mode 100644 index 0000000..f5c332f --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/internal/gui/BlurHandler.java @@ -0,0 +1,148 @@ +package cc.polyfrost.oneconfig.internal.gui; + +import cc.polyfrost.oneconfig.events.EventManager; +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.mixin.ShaderGroupAccessor; +import gg.essential.universal.UMinecraft; +import gg.essential.universal.UScreen; +import me.kbrewster.eventbus.Subscribe; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.shader.Shader; +import net.minecraft.client.shader.ShaderUniform; +import net.minecraft.util.ResourceLocation; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.List; + +/** + * An implementation of the BlurMC mod by tterrag1098. + *

+ * For the original source see https://github.com/tterrag1098/Blur/blob/1.8.9/src/main/java/com/tterrag/blur/Blur.java + * For the public license, see https://github.com/tterrag1098/Blur/blob/1.8.9/LICENSE + *

+ * License available under https://github.com/boomboompower/ToggleChat/blob/master/src/main/resources/licenses/BlurMC-License.txt + * + * @author tterrag1098, boomboompower + *

+ * Taken from ToggleChat + * https://github.com/boomboompower/ToggleChat/blob/master/LICENSE + */ +public class BlurHandler { + public static BlurHandler INSTANCE = new BlurHandler(); + private final ResourceLocation blurShader = new ResourceLocation("shaders/post/fade_in_blur.json"); + private final Logger logger = LogManager.getLogger("OneConfig - Blur"); + private long start; + private float lastProgress = 0; + + /** + * Simply initializes the blur mod so events are properly handled by forge. + */ + public void load() { + EventManager.INSTANCE.register(this); + } + + @Subscribe + private void onGuiChange(ScreenOpenEvent event) { + reloadBlur(event.screen); + } + + @Subscribe + private void onRenderTick(RenderEvent event) { + if (event.stage != Stage.END) { + return; + } + + // Only blur on our own menus + if (UScreen.getCurrentScreen() == null) { + return; + } + + // Only update the shader if one is active + if (!UMinecraft.getMinecraft().entityRenderer.isShaderActive()) { + return; + } + + float progress = getBlurStrengthProgress(); + + // If the new progress value matches the old one this + // will skip the frame update, which (hopefully) resolves the issue + // with the heavy computations after the "animation" is complete. + if (progress == this.lastProgress) { + return; + } + + // Store it for the next iteration! + this.lastProgress = progress; + + // This is hilariously bad, and could cause frame issues on low-end computers. + // Why is this being computed every tick? Surely there is a better way? + // This needs to be optimized. + try { + final List listShaders = ((ShaderGroupAccessor) Minecraft.getMinecraft().entityRenderer.getShaderGroup()).getListShaders(); + + // Should not happen. Something bad happened. + if (listShaders == null) { + return; + } + + // Iterate through the list of shaders. + for (Shader shader : listShaders) { + ShaderUniform su = shader.getShaderManager().getShaderUniform("Progress"); + + if (su == null) { + continue; + } + + // All this for this. + su.set(progress); + } + } catch (IllegalArgumentException ex) { + this.logger.error("An error.png occurred while updating OneConfig's blur. Please report this!", ex); + } + } + + /** + * Activates/deactivates the blur in the current world if + * one of many conditions are met, such as no current other shader + * is being used, we actually have the blur setting enabled + */ + private void reloadBlur(GuiScreen gui) { + // Don't do anything if no world is loaded + if (UMinecraft.getWorld() == null) { + return; + } + + // 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) { + UMinecraft.getMinecraft().entityRenderer.loadShader(this.blurShader); + + this.start = System.currentTimeMillis(); + + // If a shader is active and the incoming UI is null or we have blur disabled, stop using the shader. + } else if (UMinecraft.getMinecraft().entityRenderer.isShaderActive() && (gui == null)) { + String name = UMinecraft.getMinecraft().entityRenderer.getShaderGroup().getShaderGroupName(); + + // Only stop our specific blur ;) + if (!name.endsWith("fade_in_blur.json")) { + return; + } + + UMinecraft.getMinecraft().entityRenderer.stopUseShader(); + } + } + + /** + * Returns the strength of the blur as determined by the duration the effect of the blur. + *

+ * The strength of the blur does not go below 5.0F. + */ + private float getBlurStrengthProgress() { + return Math.min((System.currentTimeMillis() - this.start) / 50F, 5.0F); + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/init/OneConfigInit.java b/src/main/java/cc/polyfrost/oneconfig/internal/init/OneConfigInit.java new file mode 100644 index 0000000..438c60e --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/internal/init/OneConfigInit.java @@ -0,0 +1,24 @@ +package cc.polyfrost.oneconfig.internal.init; + +import net.minecraft.launchwrapper.Launch; +import org.spongepowered.asm.launch.MixinBootstrap; +import org.spongepowered.asm.mixin.Mixins; + +/** + * Initializes the OneConfig mod. + *

MUST BE CALLED VIA AN ITWEAKER / FMLLOADINGPLUGIN FOR 1.12 AND BELOW, OR A PRELAUNCH TWEAKER FOR 1.14+ FABRIC.

+ */ +@SuppressWarnings("unused") +public class OneConfigInit { + + /** + * Initializes the OneConfig mod. + * + * @param args The arguments passed to the mod. + */ + public static void initialize(String[] args) { + Launch.blackboard.put("oneconfig.initialized", true); + MixinBootstrap.init(); + Mixins.addConfiguration("mixins.oneconfig.json"); + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/FontRendererMixin.java b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/FontRendererMixin.java new file mode 100644 index 0000000..227b99e --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/FontRendererMixin.java @@ -0,0 +1,15 @@ +package cc.polyfrost.oneconfig.internal.mixin; + + +import net.minecraft.client.gui.FontRenderer; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(FontRenderer.class) +public class FontRendererMixin { + + //@Inject(method = "renderDefaultChar", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/FontRenderer;bindTexture(Lnet/minecraft/util/ResourceLocation;)V", shift = At.Shift.AFTER)) + //public void whoAsked(int ch, boolean italic, CallbackInfoReturnable cir) { + // GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); + // GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); + //} +} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/GuiIngameForgeMixin.java b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/GuiIngameForgeMixin.java new file mode 100644 index 0000000..f08d37e --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/GuiIngameForgeMixin.java @@ -0,0 +1,17 @@ +package cc.polyfrost.oneconfig.internal.mixin; + +import cc.polyfrost.oneconfig.events.EventManager; +import cc.polyfrost.oneconfig.events.event.HudRenderEvent; +import net.minecraftforge.client.GuiIngameForge; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(value = GuiIngameForge.class, remap = false) +public class GuiIngameForgeMixin { + @Inject(method = "renderGameOverlay", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/GuiIngameForge;post(Lnet/minecraftforge/client/event/RenderGameOverlayEvent$ElementType;)V", shift = At.Shift.AFTER, remap = false), remap = true) + private void onRenderGameOverlay(float partialTicks, CallbackInfo ci) { + EventManager.INSTANCE.post(new HudRenderEvent(partialTicks)); + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java new file mode 100644 index 0000000..f0d201c --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java @@ -0,0 +1,76 @@ +package cc.polyfrost.oneconfig.internal.mixin; + +import cc.polyfrost.oneconfig.internal.OneConfig; +import cc.polyfrost.oneconfig.events.EventManager; +import cc.polyfrost.oneconfig.events.event.*; +import net.minecraft.client.Minecraft; +import net.minecraft.util.Timer; +import net.minecraftforge.client.event.GuiOpenEvent; +import net.minecraftforge.fml.common.eventhandler.Event; +import org.objectweb.asm.Opcodes; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyArg; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(Minecraft.class) +public class MinecraftMixin { + @Shadow + private Timer timer; + + @Inject(method = "startGame", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/client/FMLClientHandler;beginMinecraftLoading(Lnet/minecraft/client/Minecraft;Ljava/util/List;Lnet/minecraft/client/resources/IReloadableResourceManager;)V", remap = false), remap = true) + private void onPreLaunch(CallbackInfo ci) { + OneConfig.preLaunch(); + } + + @Inject(method = "startGame", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/client/FMLClientHandler;onInitializationComplete()V", shift = At.Shift.AFTER, remap = false), remap = true) + private void onInit(CallbackInfo ci) { + OneConfig.init(); + } + + @Inject(method = "runGameLoop", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/FMLCommonHandler;onRenderTickStart(F)V", shift = At.Shift.AFTER, remap = false), remap = true) + private void onRenderTickStart(CallbackInfo ci) { + EventManager.INSTANCE.post(new RenderEvent(Stage.START, timer.renderPartialTicks)); + } + + @Inject(method = "runGameLoop", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/FMLCommonHandler;onRenderTickEnd(F)V", shift = At.Shift.AFTER, remap = false), remap = true) + private void onRenderTickEnd(CallbackInfo ci) { + EventManager.INSTANCE.post(new RenderEvent(Stage.END, timer.renderPartialTicks)); + } + + @Inject(method = "runTick", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/FMLCommonHandler;onPreClientTick()V", shift = At.Shift.AFTER, remap = false), remap = true) + private void onClientTickStart(CallbackInfo ci) { + EventManager.INSTANCE.post(new TickEvent(Stage.START)); + } + + @Inject(method = "runTick", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/FMLCommonHandler;onPostClientTick()V", shift = At.Shift.AFTER, remap = false), remap = true) + private void onClientTickEnd(CallbackInfo ci) { + EventManager.INSTANCE.post(new TickEvent(Stage.END)); + } + + @ModifyArg(method = "displayGuiScreen", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/eventhandler/EventBus;post(Lnet/minecraftforge/fml/common/eventhandler/Event;)Z", remap = false), remap = true) + private Event onGuiOpenEvent(Event a) { + if (a instanceof GuiOpenEvent) { + GuiOpenEvent forgeEvent = (GuiOpenEvent) a; + ScreenOpenEvent event = new ScreenOpenEvent(forgeEvent.gui); + EventManager.INSTANCE.post(event); + if (event.isCancelled) { + forgeEvent.setCanceled(true); + } + return forgeEvent; + } + return a; + } + + @Inject(method = "runGameLoop", at = @At(value = "FIELD", target = "Lnet/minecraft/util/Timer;renderPartialTicks:F", opcode = Opcodes.PUTFIELD, shift = At.Shift.AFTER)) + private void onNonDeltaTickTimerUpdate(CallbackInfo ci) { + EventManager.INSTANCE.post(new TimerUpdateEvent(timer, false)); + } + + @Inject(method = "runGameLoop", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Timer;updateTimer()V", shift = At.Shift.AFTER, ordinal = 1)) + private void onDeltaTickTimerUpdate(CallbackInfo ci) { + EventManager.INSTANCE.post(new TimerUpdateEvent(timer, true)); + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetHandlerPlayClientMixin.java b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetHandlerPlayClientMixin.java new file mode 100644 index 0000000..877d540 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetHandlerPlayClientMixin.java @@ -0,0 +1,36 @@ +package cc.polyfrost.oneconfig.internal.mixin; + +import cc.polyfrost.oneconfig.events.EventManager; +import cc.polyfrost.oneconfig.events.event.ChatReceiveEvent; +import cc.polyfrost.oneconfig.events.event.SendPacketEvent; +import net.minecraft.client.network.NetHandlerPlayClient; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S02PacketChat; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(value = NetHandlerPlayClient.class, priority = Integer.MAX_VALUE) +public class NetHandlerPlayClientMixin { + + @Inject(method = "addToSendQueue", at = @At("HEAD"), cancellable = true) + private void onSendPacket(Packet p_147297_1_, CallbackInfo ci) { + SendPacketEvent event = new SendPacketEvent(p_147297_1_); + EventManager.INSTANCE.post(event); + if (event.isCancelled) { + ci.cancel(); + } + } + + @Inject(method = "handleChat", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/event/ForgeEventFactory;onClientChat(BLnet/minecraft/util/IChatComponent;)Lnet/minecraft/util/IChatComponent;", remap = false), cancellable = true, remap = true) + private void onClientChat(S02PacketChat packetIn, CallbackInfo ci) { + if (packetIn.getType() == 0) { + ChatReceiveEvent event = new ChatReceiveEvent(packetIn.getChatComponent()); + EventManager.INSTANCE.post(event); + if (event.isCancelled) { + ci.cancel(); + } + } + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetworkManagerMixin.java b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetworkManagerMixin.java new file mode 100644 index 0000000..51988f2 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetworkManagerMixin.java @@ -0,0 +1,23 @@ +package cc.polyfrost.oneconfig.internal.mixin; + +import cc.polyfrost.oneconfig.events.EventManager; +import cc.polyfrost.oneconfig.events.event.ReceivePacketEvent; +import io.netty.channel.ChannelHandlerContext; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(value = NetworkManager.class, priority = Integer.MAX_VALUE) +public class NetworkManagerMixin { + @Inject(method = "channelRead0(Lio/netty/channel/ChannelHandlerContext;Lnet/minecraft/network/Packet;)V", at = @At("HEAD"), cancellable = true) + private void onReceivePacket(ChannelHandlerContext p_channelRead0_1_, Packet p_channelRead0_2_, CallbackInfo ci) { + ReceivePacketEvent event = new ReceivePacketEvent(p_channelRead0_2_); + EventManager.INSTANCE.post(event); + if (event.isCancelled) { + ci.cancel(); + } + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/ShaderGroupAccessor.java b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/ShaderGroupAccessor.java new file mode 100644 index 0000000..8014670 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/ShaderGroupAccessor.java @@ -0,0 +1,14 @@ +package cc.polyfrost.oneconfig.internal.mixin; + +import net.minecraft.client.shader.Shader; +import net.minecraft.client.shader.ShaderGroup; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.List; + +@Mixin(ShaderGroup.class) +public interface ShaderGroupAccessor { + @Accessor("listShaders") + List getListShaders(); +} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/WorldClientMixin.java b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/WorldClientMixin.java new file mode 100644 index 0000000..d1fce6a --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/WorldClientMixin.java @@ -0,0 +1,21 @@ +package cc.polyfrost.oneconfig.internal.mixin; + +import cc.polyfrost.oneconfig.events.EventManager; +import cc.polyfrost.oneconfig.events.event.WorldLoadEvent; +import net.minecraft.client.multiplayer.WorldClient; +import net.minecraft.client.network.NetHandlerPlayClient; +import net.minecraft.profiler.Profiler; +import net.minecraft.world.EnumDifficulty; +import net.minecraft.world.WorldSettings; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(WorldClient.class) +public class WorldClientMixin { + @Inject(method = "", at = @At("RETURN")) + private void onWorldLoad(NetHandlerPlayClient p_i45063_1_, WorldSettings p_i45063_2_, int p_i45063_3_, EnumDifficulty p_i45063_4_, Profiler p_i45063_5_, CallbackInfo ci) { + EventManager.INSTANCE.post(new WorldLoadEvent()); + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/LoadingPlugin.java b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/LoadingPlugin.java new file mode 100644 index 0000000..b819f24 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/LoadingPlugin.java @@ -0,0 +1,53 @@ +package cc.polyfrost.oneconfig.internal.plugin; + +import cc.polyfrost.oneconfig.internal.init.OneConfigInit; +import net.minecraft.launchwrapper.Launch; +import net.minecraft.launchwrapper.LaunchClassLoader; +import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin; + +import java.lang.reflect.Field; +import java.util.Map; +import java.util.Set; + +public class LoadingPlugin implements IFMLLoadingPlugin { + + /** + * Taken from LWJGLTwoPointFive under The Unlicense + * https://github.com/DJtheRedstoner/LWJGLTwoPointFive/blob/master/LICENSE/ + */ + public LoadingPlugin() { + try { + Field f_exceptions = LaunchClassLoader.class.getDeclaredField("classLoaderExceptions"); + f_exceptions.setAccessible(true); + Set exceptions = (Set) f_exceptions.get(Launch.classLoader); + exceptions.remove("org.lwjgl."); + OneConfigInit.initialize(new String[]{}); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public String[] getASMTransformerClass() { + return new String[]{"cc.polyfrost.oneconfig.internal.plugin.asm.ClassTransformer"}; + } + + @Override + public String getModContainerClass() { + return null; + } + + @Override + public String getSetupClass() { + return null; + } + + @Override + public void injectData(Map data) { + } + + @Override + public String getAccessTransformerClass() { + return null; + } +} \ No newline at end of file diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/Lwjgl2FunctionProvider.java b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/Lwjgl2FunctionProvider.java new file mode 100644 index 0000000..105afa2 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/Lwjgl2FunctionProvider.java @@ -0,0 +1,39 @@ +package cc.polyfrost.oneconfig.internal.plugin; + +import org.lwjgl.opengl.GLContext; +import org.lwjgl.system.FunctionProvider; + +import java.lang.reflect.Method; +import java.nio.ByteBuffer; + +/** + * Taken from LWJGLTwoPointFive under The Unlicense + * https://github.com/DJtheRedstoner/LWJGLTwoPointFive/blob/master/LICENSE/ + */ +public class Lwjgl2FunctionProvider implements FunctionProvider { + + private final Method m_getFunctionAddress; + + public Lwjgl2FunctionProvider() { + try { + m_getFunctionAddress = GLContext.class.getDeclaredMethod("getFunctionAddress", String.class); + m_getFunctionAddress.setAccessible(true); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public long getFunctionAddress(CharSequence functionName) { + try { + return (long) m_getFunctionAddress.invoke(null, functionName.toString()); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public long getFunctionAddress(ByteBuffer byteBuffer) { + throw new UnsupportedOperationException(); + } +} \ No newline at end of file diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java new file mode 100644 index 0000000..c55febc --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java @@ -0,0 +1,52 @@ +package cc.polyfrost.oneconfig.internal.plugin; + +import org.spongepowered.asm.lib.tree.ClassNode; +import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; +import org.spongepowered.asm.mixin.extensibility.IMixinInfo; + +import java.util.List; +import java.util.Set; + +public class OneConfigMixinPlugin implements IMixinConfigPlugin { + public static boolean isVigilance = false; + + @Override + public void onLoad(String mixinPackage) { + try { + Class.forName("gg.essential.vigilance.Vigilant"); + isVigilance = true; + } catch (Exception e) { + isVigilance = false; + } + } + + @Override + public String getRefMapperConfig() { + return null; + } + + @Override + public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { + return !targetClassName.contains("vigilance") || isVigilance; + } + + @Override + public void acceptTargets(Set myTargets, Set otherTargets) { + + } + + @Override + public List getMixins() { + return null; + } + + @Override + public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + + } + + @Override + public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/ClassTransformer.java b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/ClassTransformer.java new file mode 100644 index 0000000..1a2766f --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/ClassTransformer.java @@ -0,0 +1,64 @@ +package cc.polyfrost.oneconfig.internal.plugin.asm; + +import cc.polyfrost.oneconfig.internal.plugin.asm.tweakers.NanoVGGLConfigTransformer; +import cc.polyfrost.oneconfig.internal.plugin.asm.tweakers.VigilantTransformer; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; +import net.minecraft.launchwrapper.IClassTransformer; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.tree.ClassNode; + +import java.util.Collection; + +/** + * Taken from LWJGLTwoPointFive under The Unlicense + * https://github.com/DJtheRedstoner/LWJGLTwoPointFive/blob/master/LICENSE/ + *

also half taken from asmworkspace by asbyth ty

+ */ +@SuppressWarnings("unused") +public class ClassTransformer implements IClassTransformer { + private static final Logger logger = LogManager.getLogger("OneConfig ASM"); + private final Multimap transformerMap = ArrayListMultimap.create(); + + public ClassTransformer() { + registerTransformer(new NanoVGGLConfigTransformer()); + registerTransformer(new VigilantTransformer()); + } + + private void registerTransformer(ITransformer transformer) { + // loop through names of classes + for (String cls : transformer.getClassName()) { + // put the classes into the transformer map + transformerMap.put(cls, transformer); + } + } + + @Override + public byte[] transform(String name, String transformedName, byte[] basicClass) { + if (basicClass == null) return null; + + Collection transformers = transformerMap.get(transformedName); + if (transformers.isEmpty()) return basicClass; + + + ClassReader reader = new ClassReader(basicClass); + ClassNode node = new ClassNode(); + reader.accept(node, ClassReader.EXPAND_FRAMES); + + for (ITransformer transformer : transformers) { + transformer.transform(transformedName, node); + } + + ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); + try { + node.accept(cw); + } catch (Throwable t) { + logger.error("Exception when transforming " + transformedName + " : " + t.getClass().getSimpleName()); + t.printStackTrace(); + } + return cw.toByteArray(); + } +} \ No newline at end of file diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/ITransformer.java b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/ITransformer.java new file mode 100644 index 0000000..482a310 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/ITransformer.java @@ -0,0 +1,9 @@ +package cc.polyfrost.oneconfig.internal.plugin.asm; + +import org.objectweb.asm.tree.ClassNode; + +public interface ITransformer { + String[] getClassName(); + + void transform(String transformedName, ClassNode node); +} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/tweakers/NanoVGGLConfigTransformer.java b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/tweakers/NanoVGGLConfigTransformer.java new file mode 100644 index 0000000..4d7a5cc --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/tweakers/NanoVGGLConfigTransformer.java @@ -0,0 +1,43 @@ +package cc.polyfrost.oneconfig.internal.plugin.asm.tweakers; + +import cc.polyfrost.oneconfig.internal.plugin.asm.ITransformer; +import org.objectweb.asm.Opcodes; +import org.objectweb.asm.tree.*; + +public class NanoVGGLConfigTransformer implements ITransformer { + @Override + public String[] getClassName() { + return new String[]{"org.lwjgl.nanovg.NanoVGGLConfig"}; + } + + @Override + public void transform(String transformedName, ClassNode node) { + for (MethodNode method : node.methods) { + if (method.name.equals("configGL")) { + InsnList list = new InsnList(); + + list.add(new VarInsnNode(Opcodes.LLOAD, 0)); + list.add(new TypeInsnNode(Opcodes.NEW, "cc/polyfrost/oneconfig/internal/plugin/Lwjgl2FunctionProvider")); + list.add(new InsnNode(Opcodes.DUP)); + list.add(new MethodInsnNode( + Opcodes.INVOKESPECIAL, + "cc/polyfrost/oneconfig/internal/plugin/Lwjgl2FunctionProvider", + "", + "()V", + false + )); + list.add(new MethodInsnNode( + Opcodes.INVOKESTATIC, + "org/lwjgl/nanovg/NanoVGGLConfig", + "config", + "(JLorg/lwjgl/system/FunctionProvider;)V", + false + )); + list.add(new InsnNode(Opcodes.RETURN)); + + method.instructions.clear(); + method.instructions.insert(list); + } + } + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/tweakers/VigilantTransformer.java b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/tweakers/VigilantTransformer.java new file mode 100644 index 0000000..f241c74 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/tweakers/VigilantTransformer.java @@ -0,0 +1,105 @@ +package cc.polyfrost.oneconfig.internal.plugin.asm.tweakers; + +import cc.polyfrost.oneconfig.config.compatibility.vigilance.VigilanceConfig; +import cc.polyfrost.oneconfig.config.core.ConfigCore; +import cc.polyfrost.oneconfig.config.data.Mod; +import cc.polyfrost.oneconfig.config.data.ModType; +import cc.polyfrost.oneconfig.internal.plugin.asm.ITransformer; +import gg.essential.vigilance.Vigilant; +import gg.essential.vigilance.data.PropertyCollector; +import net.minecraft.client.Minecraft; +import net.minecraftforge.fml.common.Loader; +import org.objectweb.asm.Opcodes; +import org.objectweb.asm.Type; +import org.objectweb.asm.tree.*; + +import java.io.File; + +public class VigilantTransformer implements ITransformer { + @SuppressWarnings("unused") + public static VigilanceConfig returnNewConfig(Vigilant vigilant, File file) { + if (vigilant != null && Minecraft.getMinecraft().isCallingFromMinecraftThread()) { + String name = !vigilant.getGuiTitle().equals("Settings") ? vigilant.getGuiTitle() : Loader.instance().activeModContainer() == null ? "Unknown" : Loader.instance().activeModContainer().getName(); + if (name.equals("OneConfig")) name = "Essential"; + String finalName = name; + // duplicate fix + if (ConfigCore.oneConfigMods.stream().anyMatch(mod -> mod.name.equals(finalName))) return null; + return new VigilanceConfig(new Mod(name, ModType.THIRD_PARTY), file.getAbsolutePath(), vigilant); + } else { + return null; + } + } + + @Override + public String[] getClassName() { + return new String[]{"gg.essential.vigilance.Vigilant"}; + } + + @Override + public void transform(String transformedName, ClassNode node) { + node.fields.add(new FieldNode(Opcodes.ACC_PUBLIC, "oneconfig$config", Type.getDescriptor(VigilanceConfig.class), null, null)); + node.fields.add(new FieldNode(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "oneconfig$file", Type.getDescriptor(File.class), null, null)); + + node.interfaces.add("cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilantAccessor"); + MethodNode methodNode = new MethodNode(Opcodes.ACC_PUBLIC, "getPropertyCollector", "()Lgg/essential/vigilance/data/PropertyCollector;", null, null); + LabelNode labelNode = new LabelNode(); + methodNode.instructions.add(labelNode); + methodNode.instructions.add(new LineNumberNode(421421, labelNode)); + methodNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); + methodNode.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, "gg/essential/vigilance/Vigilant", "propertyCollector", Type.getDescriptor(PropertyCollector.class))); + methodNode.instructions.add(new InsnNode(Opcodes.ARETURN)); + node.methods.add(methodNode); + + MethodNode methodNode2 = new MethodNode(Opcodes.ACC_PUBLIC, "handleOneConfigDependency", "(Lgg/essential/vigilance/data/PropertyData;Lgg/essential/vigilance/data/PropertyData;)V", null, null); + LabelNode labelNode2 = new LabelNode(); + LabelNode labelNode3 = new LabelNode(); + LabelNode labelNode4 = new LabelNode(); + methodNode2.instructions.add(labelNode2); + methodNode2.instructions.add(new LineNumberNode(15636436, labelNode2)); + methodNode2.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); + methodNode2.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$config", Type.getDescriptor(VigilanceConfig.class))); + + methodNode2.instructions.add(new JumpInsnNode(Opcodes.IFNULL, labelNode4)); + + methodNode2.instructions.add(labelNode3); + methodNode2.instructions.add(new LineNumberNode(15636437, labelNode3)); + methodNode2.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); + methodNode2.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$config", Type.getDescriptor(VigilanceConfig.class))); + methodNode2.instructions.add(new VarInsnNode(Opcodes.ALOAD, 1)); + methodNode2.instructions.add(new VarInsnNode(Opcodes.ALOAD, 2)); + methodNode2.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, Type.getInternalName(VigilanceConfig.class), "addDependency", "(Lgg/essential/vigilance/data/PropertyData;Lgg/essential/vigilance/data/PropertyData;)V", false)); + + methodNode2.instructions.add(labelNode4); + methodNode2.instructions.add(new LineNumberNode(15636438, labelNode4)); + methodNode2.instructions.add(new InsnNode(Opcodes.RETURN)); + node.methods.add(methodNode2); + + for (MethodNode method : node.methods) { + if (method.name.equals("initialize")) { + InsnList list = new InsnList(); + list.add(new VarInsnNode(Opcodes.ALOAD, 0)); + list.add(new VarInsnNode(Opcodes.ALOAD, 0)); + list.add(new VarInsnNode(Opcodes.ALOAD, 0)); + list.add(new FieldInsnNode(Opcodes.GETFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$file", Type.getDescriptor(File.class))); + list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(getClass()), "returnNewConfig", "(Lgg/essential/vigilance/Vigilant;Ljava/io/File;)Lcc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig;", false)); + list.add(new FieldInsnNode(Opcodes.PUTFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$config", Type.getDescriptor(VigilanceConfig.class))); + method.instructions.insertBefore(method.instructions.getLast().getPrevious(), list); + } else if (method.name.equals("addDependency") && method.desc.equals("(Lgg/essential/vigilance/data/PropertyData;Lgg/essential/vigilance/data/PropertyData;)V")) { + InsnList list = new InsnList(); + + list.add(new VarInsnNode(Opcodes.ALOAD, 0)); + list.add(new VarInsnNode(Opcodes.ALOAD, 1)); + list.add(new VarInsnNode(Opcodes.ALOAD, 2)); + list.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "gg/essential/vigilance/Vigilant", "handleOneConfigDependency", "(Lgg/essential/vigilance/data/PropertyData;Lgg/essential/vigilance/data/PropertyData;)V", false)); + + method.instructions.insertBefore(method.instructions.getLast().getPrevious(), list); + } else if (method.name.equals("") && method.desc.equals("(Ljava/io/File;Ljava/lang/String;Lgg/essential/vigilance/data/PropertyCollector;Lgg/essential/vigilance/data/SortingBehavior;)V")) { + InsnList list = new InsnList(); + list.add(new VarInsnNode(Opcodes.ALOAD, 0)); + list.add(new VarInsnNode(Opcodes.ALOAD, 1)); + list.add(new FieldInsnNode(Opcodes.PUTFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$file", Type.getDescriptor(File.class))); + method.instructions.insertBefore(method.instructions.getLast().getPrevious(), list); + } + } + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/BlurHandler.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/BlurHandler.java deleted file mode 100644 index 1219782..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/BlurHandler.java +++ /dev/null @@ -1,148 +0,0 @@ -package cc.polyfrost.oneconfig.lwjgl; - -import cc.polyfrost.oneconfig.events.EventManager; -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.mixin.ShaderGroupAccessor; -import gg.essential.universal.UMinecraft; -import gg.essential.universal.UScreen; -import me.kbrewster.eventbus.Subscribe; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.shader.Shader; -import net.minecraft.client.shader.ShaderUniform; -import net.minecraft.util.ResourceLocation; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.util.List; - -/** - * An implementation of the BlurMC mod by tterrag1098. - *

- * For the original source see https://github.com/tterrag1098/Blur/blob/1.8.9/src/main/java/com/tterrag/blur/Blur.java - * For the public license, see https://github.com/tterrag1098/Blur/blob/1.8.9/LICENSE - *

- * License available under https://github.com/boomboompower/ToggleChat/blob/master/src/main/resources/licenses/BlurMC-License.txt - * - * @author tterrag1098, boomboompower - *

- * Taken from ToggleChat - * https://github.com/boomboompower/ToggleChat/blob/master/LICENSE - */ -public class BlurHandler { - public static BlurHandler INSTANCE = new BlurHandler(); - private final ResourceLocation blurShader = new ResourceLocation("shaders/post/fade_in_blur.json"); - private final Logger logger = LogManager.getLogger("OneConfig - Blur"); - private long start; - private float lastProgress = 0; - - /** - * Simply initializes the blur mod so events are properly handled by forge. - */ - public void load() { - EventManager.INSTANCE.register(this); - } - - @Subscribe - private void onGuiChange(ScreenOpenEvent event) { - reloadBlur(event.screen); - } - - @Subscribe - private void onRenderTick(RenderEvent event) { - if (event.stage != Stage.END) { - return; - } - - // Only blur on our own menus - if (UScreen.getCurrentScreen() == null) { - return; - } - - // Only update the shader if one is active - if (!UMinecraft.getMinecraft().entityRenderer.isShaderActive()) { - return; - } - - float progress = getBlurStrengthProgress(); - - // If the new progress value matches the old one this - // will skip the frame update, which (hopefully) resolves the issue - // with the heavy computations after the "animation" is complete. - if (progress == this.lastProgress) { - return; - } - - // Store it for the next iteration! - this.lastProgress = progress; - - // This is hilariously bad, and could cause frame issues on low-end computers. - // Why is this being computed every tick? Surely there is a better way? - // This needs to be optimized. - try { - final List listShaders = ((ShaderGroupAccessor) Minecraft.getMinecraft().entityRenderer.getShaderGroup()).getListShaders(); - - // Should not happen. Something bad happened. - if (listShaders == null) { - return; - } - - // Iterate through the list of shaders. - for (Shader shader : listShaders) { - ShaderUniform su = shader.getShaderManager().getShaderUniform("Progress"); - - if (su == null) { - continue; - } - - // All this for this. - su.set(progress); - } - } catch (IllegalArgumentException ex) { - this.logger.error("An error.png occurred while updating OneConfig's blur. Please report this!", ex); - } - } - - /** - * Activates/deactivates the blur in the current world if - * one of many conditions are met, such as no current other shader - * is being used, we actually have the blur setting enabled - */ - private void reloadBlur(GuiScreen gui) { - // Don't do anything if no world is loaded - if (UMinecraft.getWorld() == null) { - return; - } - - // 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) { - UMinecraft.getMinecraft().entityRenderer.loadShader(this.blurShader); - - this.start = System.currentTimeMillis(); - - // If a shader is active and the incoming UI is null or we have blur disabled, stop using the shader. - } else if (UMinecraft.getMinecraft().entityRenderer.isShaderActive() && (gui == null)) { - String name = UMinecraft.getMinecraft().entityRenderer.getShaderGroup().getShaderGroupName(); - - // Only stop our specific blur ;) - if (!name.endsWith("fade_in_blur.json")) { - return; - } - - UMinecraft.getMinecraft().entityRenderer.stopUseShader(); - } - } - - /** - * Returns the strength of the blur as determined by the duration the effect of the blur. - *

- * The strength of the blur does not go below 5.0F. - */ - private float getBlurStrengthProgress() { - return Math.min((System.currentTimeMillis() - this.start) / 50F, 5.0F); - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java deleted file mode 100644 index ef65ecf..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java +++ /dev/null @@ -1,755 +0,0 @@ -package cc.polyfrost.oneconfig.lwjgl; - -import cc.polyfrost.oneconfig.config.OneConfigConfig; -import cc.polyfrost.oneconfig.config.data.InfoType; -import cc.polyfrost.oneconfig.gui.OneConfigGui; -import cc.polyfrost.oneconfig.lwjgl.font.Font; -import cc.polyfrost.oneconfig.lwjgl.font.FontManager; -import cc.polyfrost.oneconfig.lwjgl.font.Fonts; -import cc.polyfrost.oneconfig.lwjgl.image.ImageLoader; -import cc.polyfrost.oneconfig.lwjgl.image.Images; -import cc.polyfrost.oneconfig.lwjgl.image.SVGs; -import cc.polyfrost.oneconfig.utils.InputUtils; -import cc.polyfrost.oneconfig.utils.NetworkUtils; -import gg.essential.universal.UGraphics; -import gg.essential.universal.UMinecraft; -import gg.essential.universal.UResolution; -import net.minecraft.client.gui.Gui; -import net.minecraft.client.shader.Framebuffer; -import org.lwjgl.nanovg.NVGColor; -import org.lwjgl.nanovg.NVGPaint; -import org.lwjgl.opengl.GL11; - -import java.util.function.LongConsumer; - -import static org.lwjgl.nanovg.NanoVG.*; -import static org.lwjgl.nanovg.NanoVGGL2.NVG_ANTIALIAS; -import static org.lwjgl.nanovg.NanoVGGL2.nvgCreate; - -/** - * Handles NanoVG rendering and wraps it in a more convenient interface. - */ -public final class RenderManager { - private static long vg = -1; - - //nanovg - - private RenderManager() { - - } - - /** - * Sets up rendering, calls the consumer with the NanoVG context, and then cleans up. - * - * @param consumer The consumer to call. - * @see RenderManager#setupAndDraw(boolean, LongConsumer) - */ - public static void setupAndDraw(LongConsumer consumer) { - setupAndDraw(false, consumer); - } - - /** - * Sets up rendering, calls the consumer with the NanoVG context, and then cleans up. - * - * @param mcScaling Whether to render with Minecraft's scaling. - * @param consumer The consumer to call. - */ - public static void setupAndDraw(boolean mcScaling, LongConsumer consumer) { - if (vg == -1) { - vg = nvgCreate(NVG_ANTIALIAS); - if (vg == -1) { - throw new RuntimeException("Failed to create nvg context"); - } - FontManager.INSTANCE.initialize(vg); - } - - Framebuffer fb = UMinecraft.getMinecraft().getFramebuffer(); - if (!fb.isStencilEnabled()) { - fb.enableStencil(); - } - GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); - GL11.glDisable(GL11.GL_ALPHA_TEST); - - if (mcScaling) { - nvgBeginFrame(vg, (float) UResolution.getScaledWidth(), (float) UResolution.getScaledHeight(), (float) UResolution.getScaleFactor()); - } else { - // If we get blurry problems with high DPI monitors, 1 might need to be replaced with Display.getPixelScaleFactor() - nvgBeginFrame(vg, UResolution.getWindowWidth(), UResolution.getWindowHeight(), 1); - } - - consumer.accept(vg); - - nvgEndFrame(vg); - - GL11.glPopAttrib(); - } - - /** - * Draws a rectangle with the given parameters. - * - * @param vg The NanoVG context. - * @param x The x position. - * @param y The y position. - * @param width The width. - * @param height The height. - * @param color The color. - */ - public static void drawRectangle(long vg, float x, float y, float width, float height, int color) { // TODO make everything use this one day - if (OneConfigConfig.ROUNDED_CORNERS) { - drawRoundedRect(vg, x, y, width, height, color, OneConfigConfig.CORNER_RADIUS); - } else { - drawRect(vg, x, y, width, height, color); - } - } - - /** - * Draws a rectangle with the given parameters. - * - * @param vg The NanoVG context. - * @param x The x position. - * @param y The y position. - * @param width The width. - * @param height The height. - * @param color The color. - */ - public static void drawRect(long vg, float x, float y, float width, float height, int color) { - nvgBeginPath(vg); - nvgRect(vg, x, y, width, height); - NVGColor nvgColor = color(vg, color); - nvgFill(vg); - nvgColor.free(); - } - - /** - * Draws a rounded rectangle with the given parameters. - * - * @param vg The NanoVG context. - * @param x The x position. - * @param y The y position. - * @param width The width. - * @param height The height. - * @param color The color. - * @param radius The radius. - */ - public static void drawRoundedRect(long vg, float x, float y, float width, float height, int color, float radius) { - nvgBeginPath(vg); - nvgRoundedRect(vg, x, y, width, height, radius); - color(vg, color); - NVGColor nvgColor = color(vg, color); - nvgFill(vg); - nvgColor.free(); - } - - /** - * Draw a rounded rectangle where every corner has a different radius - * - * @param vg The NanoVG context - * @param x The x position. - * @param y The y position. - * @param width The width. - * @param height The height. - * @param color The color. - * @param radiusTL Top left corner radius. - * @param radiusTR Top right corner radius. - * @param radiusBR Bottom right corner radius. - * @param radiusBL Bottom left corner radius - */ - public static void drawRoundedRectVaried(long vg, float x, float y, float width, float height, int color, float radiusTL, float radiusTR, float radiusBR, float radiusBL) { - nvgBeginPath(vg); - nvgRoundedRectVarying(vg, x, y, width, height, radiusTL, radiusTR, radiusBR, radiusBL); - color(vg, color); - NVGColor nvgColor = color(vg, color); - nvgFill(vg); - nvgColor.free(); - } - - /** - * Draws a hollow rounded rectangle with the given parameters. - * - * @param vg The NanoVG context. - * @param x The x position. - * @param y The y position. - * @param width The width. - * @param height The height. - * @param color The color. - * @param radius The radius. - * @param thickness The thickness. - */ - public static void drawHollowRoundRect(long vg, float x, float y, float width, float height, int color, float radius, float thickness) { - nvgBeginPath(vg); - nvgRoundedRect(vg, x + thickness, y + thickness, width - thickness, height - thickness, radius); - nvgStrokeWidth(vg, thickness + 0.5f); - nvgPathWinding(vg, NVG_HOLE); - color(vg, color); - NVGColor nvgColor = color(vg, color); - nvgStrokeColor(vg, nvgColor); - nvgStroke(vg); - nvgColor.free(); - } - - /** - * Draws a gradient rectangle with the given parameters. - * - * @param vg The NanoVG context. - * @param x The x position. - * @param y The y position. - * @param width The width. - * @param height The height. - * @param color The first color of the gradient. - * @param color2 The second color of the gradient. - */ - public static void drawGradientRect(long vg, float x, float y, float width, float height, int color, int color2) { - NVGPaint bg = NVGPaint.create(); - nvgBeginPath(vg); - nvgRect(vg, x, y, width, height); - NVGColor nvgColor = color(vg, color); - NVGColor nvgColor2 = color(vg, color2); - nvgFillPaint(vg, nvgLinearGradient(vg, x, y, x, y + width, nvgColor, nvgColor2, bg)); - nvgFillPaint(vg, bg); - nvgFill(vg); - nvgColor.free(); - nvgColor2.free(); - } - - /** - * Draws a rounded gradient rectangle with the given parameters. - * - * @param vg The NanoVG context. - * @param x The x position. - * @param y The y position. - * @param width The width. - * @param height The height. - * @param color The first color of the gradient. - * @param color2 The second color of the gradient. - * @param radius The corner radius. - */ - public static void drawGradientRoundedRect(long vg, float x, float y, float width, float height, int color, int color2, float radius) { - NVGPaint bg = NVGPaint.create(); - nvgBeginPath(vg); - nvgRoundedRect(vg, x, y, width, height, radius); - NVGColor nvgColor = color(vg, color); - NVGColor nvgColor2 = color(vg, color2); - nvgFillPaint(vg, nvgLinearGradient(vg, x, y, x + width, y, nvgColor, nvgColor2, bg)); - nvgFill(vg); - nvgColor.free(); - nvgColor2.free(); - } - - /** - * Draw a HSB box - * - * @param vg The NanoVG context. - * @param x The x coordinate. - * @param y The y coordinate - * @param width The width. - * @param height The height. - * @param colorTarget Hue color - */ - public static void drawHSBBox(long vg, float x, float y, float width, float height, int colorTarget) { - drawRoundedRect(vg, x, y, width, height, colorTarget, 8f); - - NVGPaint bg = NVGPaint.create(); - nvgBeginPath(vg); - nvgRoundedRect(vg, x, y, width, height, 8f); - NVGColor nvgColor = color(vg, -1); - NVGColor nvgColor2 = color(vg, OneConfigConfig.TRANSPARENT); - nvgFillPaint(vg, nvgLinearGradient(vg, x, y, x + width, y, nvgColor, nvgColor2, bg)); - nvgFill(vg); - nvgColor.free(); - nvgColor2.free(); - - NVGPaint bg2 = NVGPaint.create(); - nvgBeginPath(vg); - nvgRoundedRect(vg, x, y, width, height, 8f); - NVGColor nvgColor3 = color(vg, OneConfigConfig.TRANSPARENT); - NVGColor nvgColor4 = color(vg, OneConfigConfig.BLACK); - nvgFillPaint(vg, nvgLinearGradient(vg, x, y, x, y + height, nvgColor3, nvgColor4, bg2)); - nvgFill(vg); - nvgColor3.free(); - nvgColor4.free(); - } - - /** - * Draws a circle with the given parameters. - * - * @param vg The NanoVG context. - * @param x The x position. - * @param y The y position. - * @param radius The radius. - * @param color The color. - */ - public static void drawCircle(long vg, float x, float y, float radius, int color) { - nvgBeginPath(vg); - nvgCircle(vg, x, y, radius); - NVGColor nvgColor = color(vg, color); - nvgFill(vg); - nvgColor.free(); - } - - /** - * Draws a String with the given parameters. - * - * @param vg The NanoVG context. - * @param text The text. - * @param x The x position. - * @param y The y position. - * @param color The color. - * @param size The size. - * @param font The font. - * @see cc.polyfrost.oneconfig.lwjgl.font.Font - */ - public static void drawText(long vg, String text, float x, float y, int color, float size, Fonts font) { - drawText(vg, text, x, y, color, size, font.font); - } - - /** - * Draws a String with the given parameters. - * - * @param vg The NanoVG context. - * @param text The text. - * @param x The x position. - * @param y The y position. - * @param color The color. - * @param size The size. - * @param font The font. - * @see cc.polyfrost.oneconfig.lwjgl.font.Font - */ - public static void drawText(long vg, String text, float x, float y, int color, float size, Font font) { - nvgBeginPath(vg); - nvgFontSize(vg, size); - nvgFontFace(vg, font.getName()); - nvgTextAlign(vg, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE); - NVGColor nvgColor = color(vg, color); - nvgText(vg, x, y, text); - nvgFill(vg); - nvgColor.free(); - } - - /** - * Draws a String wrapped at the given width, with the given parameters. - * - * @param vg The NanoVG context. - * @param text The text. - * @param x The x position. - * @param y The y position. - * @param width The width. - * @param color The color. - * @param size The size. - * @param font The font. - */ - public static void drawWrappedString(long vg, String text, float x, float y, float width, int color, float size, Fonts font) { - drawWrappedString(vg, text, x, y, width, color, size, font.font); - } - - /** - * Draws a String wrapped at the given width, with the given parameters. - * - * @param vg The NanoVG context. - * @param text The text. - * @param x The x position. - * @param y The y position. - * @param width The width. - * @param color The color. - * @param size The size. - * @param font The font. - */ - public static void drawWrappedString(long vg, String text, float x, float y, float width, int color, float size, Font font) { - nvgBeginPath(vg); - nvgFontSize(vg, size); - nvgFontFace(vg, font.getName()); - nvgTextAlign(vg, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE); - NVGColor nvgColor = color(vg, color); - nvgTextBox(vg, x, y, width, text); - nvgFill(vg); - nvgColor.free(); - } - - /** - * Draw a formatted URL (a string in blue with an underline) that when clicked, opens the given text. - * - *

This does NOT scale to Minecraft's GUI scale!

- * - * @see RenderManager#drawText(long, String, float, float, int, float, Font) - * @see InputUtils#isAreaClicked(int, int, int, int) - */ - public static void drawURL(long vg, String url, float x, float y, float size, Fonts font) { - drawURL(vg, url, x, y, size, font.font); - } - - /** - * Draw a formatted URL (a string in blue with an underline) that when clicked, opens the given text. - * - *

This does NOT scale to Minecraft's GUI scale!

- * - * @see RenderManager#drawText(long, String, float, float, int, float, Font) - * @see InputUtils#isAreaClicked(int, int, int, int) - */ - public static void drawURL(long vg, String url, float x, float y, float size, Font font) { - drawText(vg, url, x, y, OneConfigConfig.PRIMARY_500, size, font); - float length = getTextWidth(vg, url, size, font); - drawRectangle(vg, x, y + size / 2, length, 1, OneConfigConfig.PRIMARY_500); - if (InputUtils.isAreaClicked((int) (x - 2), (int) (y - 1), (int) (length + 4), (int) (size / 2 + 3))) { - NetworkUtils.browseLink(url); - } - } - - /** - * Draws an image with the provided file path. - * - * @param vg The NanoVG context. - * @param filePath The file path. - * @param x The x position. - * @param y The y position. - * @param width The width. - * @param height The height. - * @see RenderManager#drawImage(long, String, float, float, float, float, int) - */ - public static void drawImage(long vg, String filePath, float x, float y, float width, float height) { - if (ImageLoader.INSTANCE.loadImage(vg, filePath)) { - NVGPaint imagePaint = NVGPaint.calloc(); - int image = ImageLoader.INSTANCE.getImage(filePath); - nvgBeginPath(vg); - nvgImagePattern(vg, x, y, width, height, 0, image, 1, imagePaint); - nvgRect(vg, x, y, width, height); - nvgFillPaint(vg, imagePaint); - nvgFill(vg); - imagePaint.free(); - } - } - - /** - * Draws an image with the provided file path. - * - * @param vg The NanoVG context. - * @param filePath The file path. - * @param x The x position. - * @param y The y position. - * @param width The width. - * @param height The height. - * @param color The color. - */ - public static void drawImage(long vg, String filePath, float x, float y, float width, float height, int color) { - if (ImageLoader.INSTANCE.loadImage(vg, filePath)) { - NVGPaint imagePaint = NVGPaint.calloc(); - int image = ImageLoader.INSTANCE.getImage(filePath); - nvgBeginPath(vg); - nvgImagePattern(vg, x, y, width, height, 0, image, 1, imagePaint); - nvgRGBA((byte) (color >> 16 & 0xFF), (byte) (color >> 8 & 0xFF), (byte) (color & 0xFF), (byte) (color >> 24 & 0xFF), imagePaint.innerColor()); - nvgRect(vg, x, y, width, height); - nvgFillPaint(vg, imagePaint); - nvgFill(vg); - imagePaint.free(); - } - } - - /** - * Draws an image with the provided file path and parameters. - * - * @see RenderManager#drawImage(long, String, float, float, float, float) - */ - public static void drawImage(long vg, Images filePath, float x, float y, float width, float height) { - drawImage(vg, filePath.filePath, x, y, width, height); - } - - /** - * Draws an image with the provided file path and parameters. - * - * @see RenderManager#drawImage(long, String, float, float, float, float, int) - */ - public static void drawImage(long vg, Images filePath, float x, float y, float width, float height, int color) { - drawImage(vg, filePath.filePath, x, y, width, height, color); - } - - /** - * Draws a rounded image with the provided file path and parameters. - * - * @param vg The NanoVG context. - * @param filePath The file path. - * @param x The x position. - * @param y The y position. - * @param width The width. - * @param height The height. - * @param radius The radius. - */ - public static void drawRoundImage(long vg, String filePath, float x, float y, float width, float height, float radius) { - if (ImageLoader.INSTANCE.loadImage(vg, filePath)) { - NVGPaint imagePaint = NVGPaint.calloc(); - int image = ImageLoader.INSTANCE.getImage(filePath); - nvgBeginPath(vg); - nvgImagePattern(vg, x, y, width, height, 0, image, 1, imagePaint); - nvgRoundedRect(vg, x, y, width, height, radius); - nvgFillPaint(vg, imagePaint); - nvgFill(vg); - imagePaint.free(); - } - } - - /** - * Draws a rounded image with the provided file path and parameters. - * - * @see RenderManager#drawRoundImage(long, String, float, float, float, float, float) - */ - public static void drawRoundImage(long vg, Images filePath, float x, float y, float width, float height, float radius) { - drawRoundImage(vg, filePath.filePath, x, y, width, height, radius); - } - - public static float getTextWidth(long vg, String text, float fontSize, Fonts font) { - return getTextWidth(vg, text, fontSize, font.font); - } - - /** - * Get the width of the provided String. - * - * @param vg The NanoVG context. - * @param text The text. - * @param fontSize The font size. - * @param font The font. - * @return The width of the text. - */ - public static float getTextWidth(long vg, String text, float fontSize, Font font) { - float[] bounds = new float[4]; - nvgFontSize(vg, fontSize); - nvgFontFace(vg, font.getName()); - return nvgTextBounds(vg, 0, 0, text, bounds); - } - - /** - * Draws a line with the provided parameters. - * - * @param vg The NanoVG context. - * @param x The x position. - * @param y The y position. - * @param endX The end x position. - * @param endY The end y position. - * @param width The width. - * @param color The color. - */ - public static void drawLine(long vg, float x, float y, float endX, float endY, float width, int color) { - nvgBeginPath(vg); - nvgMoveTo(vg, x, y); - nvgLineTo(vg, endX, endY); - NVGColor nvgColor = color(vg, color); - nvgStrokeColor(vg, nvgColor); - nvgStrokeWidth(vg, width); - nvgStroke(vg); - nvgColor.free(); - } - - /** - * Draw a drop shadow. - * - * Adapted from legui under MIT license - * - * @param vg The NanoVG context. - * @param x The x coordinate. - * @param y The y coordinate. - * @param w The width. - * @param h The height. - * @param blur The blur (feather). - * @param spread The spread. - * @param cornerRadius The radius of the corner - */ - public static void drawDropShadow(long vg, float x, float y, float w, float h, float blur, float spread, float cornerRadius) { - try (NVGPaint shadowPaint = NVGPaint.calloc(); // allocating memory to pass color to nanovg wrapper - NVGColor firstColor = NVGColor.calloc(); // allocating memory to pass color to nanovg wrapper - NVGColor secondColor = NVGColor.calloc() // allocating memory to pass color to nanovg wrapper - ) { - fillNVGColorWithRGBA(0, 0, 0, 0.5f, firstColor); // filling allocated memory - fillNVGColorWithRGBA(0, 0, 0, 0, secondColor); // filling allocated memory - - // creating gradient and put it to shadowPaint - nvgBoxGradient(vg, x - spread, y - spread, w + 2 * spread, h + 2 * spread, cornerRadius + spread, blur, firstColor, secondColor, shadowPaint); - nvgBeginPath(vg); - nvgRoundedRect(vg, x - spread - blur, y - spread - blur, w + 2 * spread + 2 * blur, h + 2 * spread + 2 * blur, cornerRadius + spread); - nvgRoundedRect(vg, x, y, w, h, cornerRadius); - nvgPathWinding(vg, NVG_HOLE); - nvgFillPaint(vg, shadowPaint); - nvgFill(vg); - } - } - - /** - * Fills the provided {@link NVGColor} with the provided RGBA values. - * - * @param r The red value. - * @param g The green value. - * @param b The blue value. - * @param a The alpha value. - * @param color The {@link NVGColor} to fill. - */ - public static void fillNVGColorWithRGBA(float r, float g, float b, float a, NVGColor color) { - color.r(r); - color.g(g); - color.b(b); - color.a(a); - } - - /** - * Create a {@link NVGColor} from the provided RGBA values. - * - * @param vg The NanoVG context. - * @param color The color. - * @return The {@link NVGColor} created. - */ - public static NVGColor color(long vg, int color) { - NVGColor nvgColor = NVGColor.calloc(); - nvgRGBA((byte) (color >> 16 & 0xFF), (byte) (color >> 8 & 0xFF), (byte) (color & 0xFF), (byte) (color >> 24 & 0xFF), nvgColor); - nvgFillColor(vg, nvgColor); - return nvgColor; - } - - /** - * Scales all rendering by the provided scale. - * - * @param vg The NanoVG context. - * @param x The x scale. - * @param y The y scale. - */ - public static void scale(long vg, float x, float y) { - nvgScale(vg, x, y); - } - - /** - * Sets the global alpha value to render with. - * - * @param vg The NanoVG context. - * @param alpha The alpha value. - */ - public static void setAlpha(long vg, float alpha) { - nvgGlobalAlpha(vg, alpha); - } - - /** - * Draws a SVG with the provided file path and parameters. - * - * @param vg The NanoVG context. - * @param filePath The file path. - * @param x The x position. - * @param y The y position. - * @param width The width. - * @param height The height. - */ - public static void drawSvg(long vg, String filePath, float x, float y, float width, float height) { - float w = width; - float h = height; - if (OneConfigGui.INSTANCE != null) { - w *= OneConfigGui.INSTANCE.getScaleFactor(); - h *= OneConfigGui.INSTANCE.getScaleFactor(); - } - if (ImageLoader.INSTANCE.loadSVG(vg, filePath, w, h)) { - NVGPaint imagePaint = NVGPaint.calloc(); - int image = ImageLoader.INSTANCE.getSVG(filePath, w, h); - nvgBeginPath(vg); - nvgImagePattern(vg, x, y, width, height, 0, image, 1, imagePaint); - nvgRect(vg, x, y, width, height); - nvgFillPaint(vg, imagePaint); - nvgFill(vg); - imagePaint.free(); - } - } - - /** - * Draws a SVG with the provided file path and parameters. - * - * @param vg The NanoVG context. - * @param filePath The file path. - * @param x The x position. - * @param y The y position. - * @param width The width. - * @param height The height. - * @param color The color. - */ - public static void drawSvg(long vg, String filePath, float x, float y, float width, float height, int color) { - float w = width; - float h = height; - if (OneConfigGui.INSTANCE != null) { - w *= OneConfigGui.INSTANCE.getScaleFactor(); - h *= OneConfigGui.INSTANCE.getScaleFactor(); - } - if (ImageLoader.INSTANCE.loadSVG(vg, filePath, w, h)) { - NVGPaint imagePaint = NVGPaint.calloc(); - int image = ImageLoader.INSTANCE.getSVG(filePath, w, h); - nvgBeginPath(vg); - nvgImagePattern(vg, x, y, width, height, 0, image, 1, imagePaint); - nvgRGBA((byte) (color >> 16 & 0xFF), (byte) (color >> 8 & 0xFF), (byte) (color & 0xFF), (byte) (color >> 24 & 0xFF), imagePaint.innerColor()); - nvgRect(vg, x, y, width, height); - nvgFillPaint(vg, imagePaint); - nvgFill(vg); - imagePaint.free(); - } - } - - /** - * Draws an SVG with the provided file path and parameters. - * - * @see RenderManager#drawSvg(long, String, float, float, float, float) - */ - public static void drawSvg(long vg, SVGs svg, float x, float y, float width, float height) { - drawSvg(vg, svg.filePath, x, y, width, height); - } - - /** - * Draws an SVG with the provided file path and parameters. - * - * @see RenderManager#drawSvg(long, String, float, float, float, float, int) - */ - public static void drawSvg(long vg, SVGs svg, float x, float y, float width, float height, int color) { - drawSvg(vg, svg.filePath, x, y, width, height, color); - } - - /** - * Draw a circle with an info icon inside of it - * - * @param vg The NanoVG context. - * @param type The icon type. - * @param x The x position. - * @param y The y position. - * @param size The diameter. - */ - public static void drawInfo(long vg, InfoType type, float x, float y, float size) { - SVGs icon = null; - int colorOuter = 0; - int colorInner = 0; - switch (type) { - case INFO: - icon = SVGs.INFO_CIRCLE; - colorOuter = OneConfigConfig.GRAY_400; - colorInner = OneConfigConfig.GRAY_300; - break; - case SUCCESS: - icon = SVGs.CHECK_CIRCLE; - colorOuter = OneConfigConfig.SUCCESS_700; - colorInner = OneConfigConfig.SUCCESS_600; - break; - case WARNING: - icon = SVGs.WARNING; - colorOuter = OneConfigConfig.WARNING_600; - colorInner = OneConfigConfig.WARNING_500; - break; - case ERROR: - icon = SVGs.ERROR; - colorOuter = OneConfigConfig.ERROR_700; - colorInner = OneConfigConfig.ERROR_600; - break; - } - float centerX = x + size / 2f; - float centerY = y + size / 2f; - drawCircle(vg, centerX, centerY, size / 2, colorOuter); - drawCircle(vg, centerX, centerY, size / 2 - size / 12, colorInner); - float iconSize = size / 1.75f; - drawSvg(vg, icon, centerX - iconSize / 2f, centerY - iconSize / 2f, iconSize, iconSize); - } - - // gl - - public static void drawScaledString(String text, float x, float y, int color, boolean shadow, float scale) { - UGraphics.GL.pushMatrix(); - UGraphics.GL.scale(scale, scale, 1); - UMinecraft.getFontRenderer().drawString(text, x * (1 / scale), y * (1 / scale), color, shadow); - UGraphics.GL.popMatrix(); - } - - public static void drawGlRect(int x, int y, int width, int height, int color) { - Gui.drawRect(x, y, x + width, y + height, color); - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/font/Font.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/font/Font.java deleted file mode 100644 index 8267ba7..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/font/Font.java +++ /dev/null @@ -1,41 +0,0 @@ -package cc.polyfrost.oneconfig.lwjgl.font; - -import java.nio.ByteBuffer; - -public class Font { - private final String fileName; - private final String name; - private boolean loaded = false; - private ByteBuffer buffer = null; - - public Font(String name, String fileName) { - this.name = name; - this.fileName = fileName; - } - - public String getName() { - return name; - } - - public String getFileName() { - return fileName; - } - - public boolean isLoaded() { - return loaded; - } - - void setLoaded(boolean loaded) { - this.loaded = loaded; - } - - public ByteBuffer getBuffer() { - return buffer; - } - - void setBuffer(ByteBuffer buffer) { - this.buffer = buffer; - } - -} - diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/font/FontManager.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/font/FontManager.java deleted file mode 100644 index 534795b..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/font/FontManager.java +++ /dev/null @@ -1,31 +0,0 @@ -package cc.polyfrost.oneconfig.lwjgl.font; - -import cc.polyfrost.oneconfig.utils.IOUtils; - -import java.io.IOException; -import java.nio.ByteBuffer; - -import static org.lwjgl.nanovg.NanoVG.nvgCreateFontMem; - -public class FontManager { - public static FontManager INSTANCE = new FontManager(); - - public void initialize(long vg) { - for (Fonts fonts : Fonts.values()) { - Font font = fonts.font; - int loaded = -1; - try { - ByteBuffer buffer = IOUtils.resourceToByteBuffer(font.getFileName()); - loaded = nvgCreateFontMem(vg, font.getName(), buffer, 0); - font.setBuffer(buffer); - } catch (IOException e) { - e.printStackTrace(); - } - if (loaded == -1) { - throw new RuntimeException("Failed to initialize font " + font.getName()); - } else { - font.setLoaded(true); - } - } - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/font/Fonts.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/font/Fonts.java deleted file mode 100644 index 74d7828..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/font/Fonts.java +++ /dev/null @@ -1,15 +0,0 @@ -package cc.polyfrost.oneconfig.lwjgl.font; - -public enum Fonts { - BOLD(new Font("inter-bold", "/assets/oneconfig/font/Bold.otf")), - SEMIBOLD(new Font("inter-semibold", "/assets/oneconfig/font/SemiBold.otf")), - MEDIUM(new Font("inter-medium", "/assets/oneconfig/font/Medium.otf")), - REGULAR(new Font("inter-regular", "/assets/oneconfig/font/Regular.otf")), - MINECRAFT_REGULAR(new Font("mc-regular", "/assets/oneconfig/font/Minecraft-Regular.otf")), - MINECRAFT_BOLD(new Font("mc-bold", "/assets/oneconfig/font/Minecraft-Bold.otf")); - public final Font font; - - Fonts(Font font) { - this.font = font; - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/ImageLoader.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/ImageLoader.java deleted file mode 100644 index faf3e13..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/ImageLoader.java +++ /dev/null @@ -1,190 +0,0 @@ -package cc.polyfrost.oneconfig.lwjgl.image; - -import cc.polyfrost.oneconfig.utils.IOUtils; -import org.lwjgl.nanovg.NSVGImage; -import org.lwjgl.nanovg.NanoSVG; -import org.lwjgl.nanovg.NanoVG; -import org.lwjgl.stb.STBImage; -import org.lwjgl.system.MemoryUtil; - -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.ByteBuffer; -import java.util.HashMap; - -/** - * Loads images and SVGs from resources into NanoVG. - * - * @see cc.polyfrost.oneconfig.lwjgl.RenderManager - * @see Images - * @see SVGs - */ -public final class ImageLoader { - private ImageLoader() { - - } - - private final HashMap imageHashMap = new HashMap<>(); - private final HashMap svgHashMap = new HashMap<>(); - public static ImageLoader INSTANCE = new ImageLoader(); - - /** - * Loads an image from resources. - * - * @param vg The NanoVG context. - * @param fileName The name of the file to load. - * @return Whether the image was loaded successfully. - */ - public boolean loadImage(long vg, String fileName) { - if (!imageHashMap.containsKey(fileName)) { - int[] width = {0}; - int[] height = {0}; - int[] channels = {0}; - - ByteBuffer image = IOUtils.resourceToByteBufferNullable(fileName); - if (image == null) { - return false; - } - - ByteBuffer buffer = STBImage.stbi_load_from_memory(image, width, height, channels, 4); - if (buffer == null) { - return false; - } - - imageHashMap.put(fileName, NanoVG.nvgCreateImageRGBA(vg, width[0], height[0], NanoVG.NVG_IMAGE_REPEATX | NanoVG.NVG_IMAGE_REPEATY | NanoVG.NVG_IMAGE_GENERATE_MIPMAPS, buffer)); - return true; - } - return true; - } - - /** - * Loads an SVG from resources. - * - * @param vg The NanoVG context. - * @param fileName The name of the file to load. - * @param width The width of the SVG. - * @param height The height of the SVG. - * @return Whether the SVG was loaded successfully. - */ - public boolean loadSVG(long vg, String fileName, float width, float height) { - String name = fileName + "-" + width + "-" + height; - if (!svgHashMap.containsKey(name)) { - try { - InputStream inputStream = this.getClass().getResourceAsStream(fileName); - if (inputStream == null) return false; - StringBuilder resultStringBuilder = new StringBuilder(); - try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) { - String line; - while ((line = br.readLine()) != null) { - resultStringBuilder.append(line); - } - } - CharSequence s = resultStringBuilder.toString(); - NSVGImage svg = NanoSVG.nsvgParse(s, "px", 96f); - if (svg == null) return false; - long rasterizer = NanoSVG.nsvgCreateRasterizer(); - - int w = (int) svg.width(); - int h = (int) svg.height(); - float scale = Math.max(width / w, height / h); - w = (int) (w * scale); - h = (int) (h * scale); - - ByteBuffer image = MemoryUtil.memAlloc(w * h * 4); - NanoSVG.nsvgRasterize(rasterizer, svg, 0, 0, scale, image, w, h, w * 4); - - NanoSVG.nsvgDeleteRasterizer(rasterizer); - NanoSVG.nsvgDelete(svg); - - svgHashMap.put(name, NanoVG.nvgCreateImageRGBA(vg, w, h, NanoVG.NVG_IMAGE_REPEATX | NanoVG.NVG_IMAGE_REPEATY | NanoVG.NVG_IMAGE_GENERATE_MIPMAPS, image)); - return true; - } catch (Exception e) { - System.err.println("Failed to parse SVG file"); - e.printStackTrace(); - return false; - } - } - return true; - } - - /** - * Get a loaded image from the cache. - *

Requires the image to have been loaded first.

- * - * @param fileName The name of the file to load. - * @return The image - * @see ImageLoader#loadImage(long, String) - */ - public int getImage(String fileName) { - return imageHashMap.get(fileName); - } - - /** - * Remove an image from the cache, allowing the image to be garbage collected. - * Should be used when the GUI rendering the image is closed. - * - * @param vg The NanoVG context. - * @param fileName The name of the file to remove. - * @see ImageLoader#loadImage(long, String) - */ - public void removeImage(long vg, String fileName) { - NanoVG.nvgDeleteImage(vg, imageHashMap.get(fileName)); - imageHashMap.remove(fileName); - } - - /** - * Clears all images from the cache, allowing the images cleared to be garbage collected. - * Should be used when the GUI rendering loaded images are closed. - * - * @param vg The NanoVG context. - */ - public void clearImages(long vg) { - HashMap temp = new HashMap<>(imageHashMap); - for (String image : temp.keySet()) { - NanoVG.nvgDeleteImage(vg, imageHashMap.get(image)); - imageHashMap.remove(image); - } - } - - /** - * Get a loaded SVG from the cache. - *

Requires the SVG to have been loaded first.

- * - * @param fileName The name of the file to load. - * @return The SVG - * @see ImageLoader#loadSVG(long, String, float, float) - */ - public int getSVG(String fileName, float width, float height) { - String name = fileName + "-" + width + "-" + height; - return svgHashMap.get(name); - } - - /** - * Remove a SVG from the cache, allowing the SVG to be garbage collected. - * Should be used when the GUI rendering the SVG is closed. - * - * @param vg The NanoVG context. - * @param fileName The name of the file to remove. - * @see ImageLoader#loadSVG(long, String, float, float) - */ - public void removeSVG(long vg, String fileName, float width, float height) { - String name = fileName + "-" + width + "-" + height; - NanoVG.nvgDeleteImage(vg, imageHashMap.get(name)); - svgHashMap.remove(name); - } - - /** - * Clears all SVGs from the cache, allowing the SVGs cleared to be garbage collected. - * Should be used when the GUI rendering loaded SVGs are closed. - * - * @param vg The NanoVG context. - */ - public void clearSVGs(long vg) { - HashMap temp = new HashMap<>(svgHashMap); - for (String image : temp.keySet()) { - NanoVG.nvgDeleteImage(vg, svgHashMap.get(image)); - svgHashMap.remove(image); - } - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/Images.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/Images.java deleted file mode 100644 index 0379b2e..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/Images.java +++ /dev/null @@ -1,19 +0,0 @@ -package cc.polyfrost.oneconfig.lwjgl.image; - -/** - * An enum of images used in OneConfig. - * - * @see cc.polyfrost.oneconfig.lwjgl.RenderManager#drawImage(long, String, float, float, float, float, int) - * @see ImageLoader - */ -public enum Images { - HUE_GRADIENT("/assets/oneconfig/options/HueGradient.png"), - COLOR_WHEEL("/assets/oneconfig/options/ColorWheel.png"), - ALPHA_GRID("/assets/oneconfig/options/AlphaGrid.png"); - - public final String filePath; - - Images(String filePath) { - this.filePath = filePath; - } -} \ No newline at end of file diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/SVGs.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/SVGs.java deleted file mode 100644 index 28e9f4a..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/SVGs.java +++ /dev/null @@ -1,52 +0,0 @@ -package cc.polyfrost.oneconfig.lwjgl.image; - -/** - * An enum of SVGs used in OneConfig. - * - * @see cc.polyfrost.oneconfig.lwjgl.RenderManager#drawSvg(long, String, float, float, float, float, int) - * @see ImageLoader - */ -public enum SVGs { - ONECONFIG("/assets/oneconfig/icons/OneConfig.svg"), - ONECONFIG_OFF("/assets/oneconfig/icons/OneConfigOff.svg"), - COPYRIGHT_FILL("/assets/oneconfig/icons/CopyrightFill.svg"), - APERTURE_FILL("/assets/oneconfig/icons/ApertureFill.svg"), - ARROWS_CLOCKWISE_BOLD("/assets/oneconfig/icons/ArrowsClockwiseBold.svg"), - FADERS_HORIZONTAL_BOLD("/assets/oneconfig/icons/FadersHorizontalBold.svg"), - GAUGE_FILL("/assets/oneconfig/icons/GaugeFill.svg"), - GEAR_SIX_FILL("/assets/oneconfig/icons/GearSixFill.svg"), - MAGNIFYING_GLASS_BOLD("/assets/oneconfig/icons/MagnifyingGlassBold.svg"), - NOTE_PENCIL_BOLD("/assets/oneconfig/icons/NotePencilBold.svg"), - PAINT_BRUSH_BROAD_FILL("/assets/oneconfig/icons/PaintBrushBroadFill.svg"), - USER_SWITCH_FILL("/assets/oneconfig/icons/UserSwitchFill.svg"), - X_CIRCLE_BOLD("/assets/oneconfig/icons/XCircleBold.svg"), - CARET_LEFT("/assets/oneconfig/icons/CaretLeftBold.svg"), - CARET_RIGHT("/assets/oneconfig/icons/CaretRightBold.svg"), - - // OLD ICONS - BOX("/assets/oneconfig/old-icons/Box.svg"), - CHECKBOX_TICK("/assets/oneconfig/old-icons/CheckboxTick.svg"), - CHECK_CIRCLE("/assets/oneconfig/old-icons/CheckCircle.svg"), - CHEVRON_DOWN("/assets/oneconfig/old-icons/ChevronDown.svg"), - CHEVRON_UP("/assets/oneconfig/old-icons/ChevronUp.svg"), - COPY("/assets/oneconfig/old-icons/Copy.svg"), - DROPDOWN_LIST("/assets/oneconfig/old-icons/DropdownList.svg"), - ERROR("/assets/oneconfig/old-icons/Error.svg"), - EYE("/assets/oneconfig/old-icons/Eye.svg"), - EYE_OFF("/assets/oneconfig/old-icons/EyeOff.svg"), - HEART_FILL("/assets/oneconfig/old-icons/HeartFill.svg"), - HEART_OUTLINE("/assets/oneconfig/old-icons/HeartOutline.svg"), - HELP_CIRCLE("/assets/oneconfig/old-icons/HelpCircle.svg"), - HISTORY("/assets/oneconfig/old-icons/History.svg"), - INFO_CIRCLE("/assets/oneconfig/old-icons/InfoCircle.svg"), - KEYSTROKE("/assets/oneconfig/old-icons/Keystroke.svg"), - PASTE("/assets/oneconfig/old-icons/Paste.svg"), - POP_OUT("/assets/oneconfig/old-icons/PopOut.svg"), - WARNING("/assets/oneconfig/old-icons/Warning.svg"); - - public final String filePath; - - SVGs(String filePath) { - this.filePath = filePath; - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/plugin/Lwjgl2FunctionProvider.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/plugin/Lwjgl2FunctionProvider.java deleted file mode 100644 index 4cef17c..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/plugin/Lwjgl2FunctionProvider.java +++ /dev/null @@ -1,39 +0,0 @@ -package cc.polyfrost.oneconfig.lwjgl.plugin; - -import org.lwjgl.opengl.GLContext; -import org.lwjgl.system.FunctionProvider; - -import java.lang.reflect.Method; -import java.nio.ByteBuffer; - -/** - * Taken from LWJGLTwoPointFive under The Unlicense - * https://github.com/DJtheRedstoner/LWJGLTwoPointFive/blob/master/LICENSE/ - */ -public class Lwjgl2FunctionProvider implements FunctionProvider { - - private final Method m_getFunctionAddress; - - public Lwjgl2FunctionProvider() { - try { - m_getFunctionAddress = GLContext.class.getDeclaredMethod("getFunctionAddress", String.class); - m_getFunctionAddress.setAccessible(true); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - @Override - public long getFunctionAddress(CharSequence functionName) { - try { - return (long) m_getFunctionAddress.invoke(null, functionName.toString()); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - @Override - public long getFunctionAddress(ByteBuffer byteBuffer) { - throw new UnsupportedOperationException(); - } -} \ No newline at end of file diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/scissor/Scissor.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/scissor/Scissor.java deleted file mode 100644 index 089268f..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/scissor/Scissor.java +++ /dev/null @@ -1,27 +0,0 @@ -package cc.polyfrost.oneconfig.lwjgl.scissor; - -/** - * A class that represents a scissor rectangle. - * - * @see ScissorManager - */ -public class Scissor { - public float x; - public float y; - public float width; - public float height; - - public Scissor(float x, float y, float width, float height) { - this.x = x; - this.y = y; - this.width = width; - this.height = height; - } - - public Scissor(Scissor scissor) { - this.x = scissor.x; - this.y = scissor.y; - this.width = scissor.width; - this.height = scissor.height; - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/scissor/ScissorManager.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/scissor/ScissorManager.java deleted file mode 100644 index 159de96..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/scissor/ScissorManager.java +++ /dev/null @@ -1,69 +0,0 @@ -package cc.polyfrost.oneconfig.lwjgl.scissor; - -import org.lwjgl.nanovg.NanoVG; - -import java.util.ArrayList; - -/** - * Provides an easy way to manage and group scissor rectangles. - */ -public class ScissorManager { - private static final ArrayList scissors = new ArrayList<>(); - - /** - * Adds and applies a scissor rectangle to the list of scissor rectangles. - * - * @param vg The NanoVG context. - * @param x The x coordinate of the scissor rectangle. - * @param y The y coordinate of the scissor rectangle. - * @param width The width of the scissor rectangle. - * @param height The height of the scissor rectangle. - * @return The scissor rectangle. - */ - public static Scissor scissor(long vg, float x, float y, float width, float height) { - Scissor scissor = new Scissor(x, y, width, height); - if (scissors.contains(scissor)) return scissor; - scissors.add(scissor); - applyScissors(vg); - return scissor; - } - - /** - * Resets the scissor rectangle provided. - * - * @param vg The NanoVG context. - * @param scissor The scissor rectangle to reset. - */ - public static void resetScissor(long vg, Scissor scissor) { - if (scissors.contains(scissor)) { - scissors.remove(scissor); - applyScissors(vg); - } - } - - /** - * Clear all scissor rectangles. - * - * @param vg The NanoVG context. - */ - public static void clearScissors(long vg) { - scissors.clear(); - NanoVG.nvgResetScissor(vg); - } - - private static void applyScissors(long vg) { - NanoVG.nvgResetScissor(vg); - if (scissors.size() <= 0) return; - Scissor finalScissor = new Scissor(scissors.get(0)); - for (int i = 1; i < scissors.size(); i++) { - Scissor scissor = scissors.get(i); - float rightX = Math.min(scissor.x + scissor.width, finalScissor.x + finalScissor.width); - float rightY = Math.min(scissor.y + scissor.height, finalScissor.y + finalScissor.height); - finalScissor.x = Math.max(finalScissor.x, scissor.x); - finalScissor.y = Math.max(finalScissor.y, scissor.y); - finalScissor.width = rightX - finalScissor.x; - finalScissor.height = rightY - finalScissor.y; - } - NanoVG.nvgScissor(vg, finalScissor.x, finalScissor.y, finalScissor.width, finalScissor.height); - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/mixin/FontRendererMixin.java b/src/main/java/cc/polyfrost/oneconfig/mixin/FontRendererMixin.java deleted file mode 100644 index 7eac19d..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/mixin/FontRendererMixin.java +++ /dev/null @@ -1,15 +0,0 @@ -package cc.polyfrost.oneconfig.mixin; - - -import net.minecraft.client.gui.FontRenderer; -import org.spongepowered.asm.mixin.Mixin; - -@Mixin(FontRenderer.class) -public class FontRendererMixin { - - //@Inject(method = "renderDefaultChar", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/FontRenderer;bindTexture(Lnet/minecraft/util/ResourceLocation;)V", shift = At.Shift.AFTER)) - //public void whoAsked(int ch, boolean italic, CallbackInfoReturnable cir) { - // GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); - // GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); - //} -} diff --git a/src/main/java/cc/polyfrost/oneconfig/mixin/GuiIngameForgeMixin.java b/src/main/java/cc/polyfrost/oneconfig/mixin/GuiIngameForgeMixin.java deleted file mode 100644 index 36ec90b..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/mixin/GuiIngameForgeMixin.java +++ /dev/null @@ -1,17 +0,0 @@ -package cc.polyfrost.oneconfig.mixin; - -import cc.polyfrost.oneconfig.events.EventManager; -import cc.polyfrost.oneconfig.events.event.HudRenderEvent; -import net.minecraftforge.client.GuiIngameForge; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(value = GuiIngameForge.class, remap = false) -public class GuiIngameForgeMixin { - @Inject(method = "renderGameOverlay", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/GuiIngameForge;post(Lnet/minecraftforge/client/event/RenderGameOverlayEvent$ElementType;)V", shift = At.Shift.AFTER, remap = false), remap = true) - private void onRenderGameOverlay(float partialTicks, CallbackInfo ci) { - EventManager.INSTANCE.post(new HudRenderEvent(partialTicks)); - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/mixin/MinecraftMixin.java b/src/main/java/cc/polyfrost/oneconfig/mixin/MinecraftMixin.java deleted file mode 100644 index 6618094..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/mixin/MinecraftMixin.java +++ /dev/null @@ -1,76 +0,0 @@ -package cc.polyfrost.oneconfig.mixin; - -import cc.polyfrost.oneconfig.OneConfig; -import cc.polyfrost.oneconfig.events.EventManager; -import cc.polyfrost.oneconfig.events.event.*; -import net.minecraft.client.Minecraft; -import net.minecraft.util.Timer; -import net.minecraftforge.client.event.GuiOpenEvent; -import net.minecraftforge.fml.common.eventhandler.Event; -import org.objectweb.asm.Opcodes; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyArg; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(Minecraft.class) -public class MinecraftMixin { - @Shadow - private Timer timer; - - @Inject(method = "startGame", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/client/FMLClientHandler;beginMinecraftLoading(Lnet/minecraft/client/Minecraft;Ljava/util/List;Lnet/minecraft/client/resources/IReloadableResourceManager;)V", remap = false), remap = true) - private void onPreLaunch(CallbackInfo ci) { - OneConfig.preLaunch(); - } - - @Inject(method = "startGame", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/client/FMLClientHandler;onInitializationComplete()V", shift = At.Shift.AFTER, remap = false), remap = true) - private void onInit(CallbackInfo ci) { - OneConfig.init(); - } - - @Inject(method = "runGameLoop", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/FMLCommonHandler;onRenderTickStart(F)V", shift = At.Shift.AFTER, remap = false), remap = true) - private void onRenderTickStart(CallbackInfo ci) { - EventManager.INSTANCE.post(new RenderEvent(Stage.START, timer.renderPartialTicks)); - } - - @Inject(method = "runGameLoop", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/FMLCommonHandler;onRenderTickEnd(F)V", shift = At.Shift.AFTER, remap = false), remap = true) - private void onRenderTickEnd(CallbackInfo ci) { - EventManager.INSTANCE.post(new RenderEvent(Stage.END, timer.renderPartialTicks)); - } - - @Inject(method = "runTick", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/FMLCommonHandler;onPreClientTick()V", shift = At.Shift.AFTER, remap = false), remap = true) - private void onClientTickStart(CallbackInfo ci) { - EventManager.INSTANCE.post(new TickEvent(Stage.START)); - } - - @Inject(method = "runTick", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/FMLCommonHandler;onPostClientTick()V", shift = At.Shift.AFTER, remap = false), remap = true) - private void onClientTickEnd(CallbackInfo ci) { - EventManager.INSTANCE.post(new TickEvent(Stage.END)); - } - - @ModifyArg(method = "displayGuiScreen", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/eventhandler/EventBus;post(Lnet/minecraftforge/fml/common/eventhandler/Event;)Z", remap = false), remap = true) - private Event onGuiOpenEvent(Event a) { - if (a instanceof GuiOpenEvent) { - GuiOpenEvent forgeEvent = (GuiOpenEvent) a; - ScreenOpenEvent event = new ScreenOpenEvent(forgeEvent.gui); - EventManager.INSTANCE.post(event); - if (event.isCancelled) { - forgeEvent.setCanceled(true); - } - return forgeEvent; - } - return a; - } - - @Inject(method = "runGameLoop", at = @At(value = "FIELD", target = "Lnet/minecraft/util/Timer;renderPartialTicks:F", opcode = Opcodes.PUTFIELD, shift = At.Shift.AFTER)) - private void onNonDeltaTickTimerUpdate(CallbackInfo ci) { - EventManager.INSTANCE.post(new TimerUpdateEvent(timer, false)); - } - - @Inject(method = "runGameLoop", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Timer;updateTimer()V", shift = At.Shift.AFTER, ordinal = 1)) - private void onDeltaTickTimerUpdate(CallbackInfo ci) { - EventManager.INSTANCE.post(new TimerUpdateEvent(timer, true)); - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/mixin/NetHandlerPlayClientMixin.java b/src/main/java/cc/polyfrost/oneconfig/mixin/NetHandlerPlayClientMixin.java deleted file mode 100644 index 5d78531..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/mixin/NetHandlerPlayClientMixin.java +++ /dev/null @@ -1,36 +0,0 @@ -package cc.polyfrost.oneconfig.mixin; - -import cc.polyfrost.oneconfig.events.EventManager; -import cc.polyfrost.oneconfig.events.event.ChatReceiveEvent; -import cc.polyfrost.oneconfig.events.event.SendPacketEvent; -import net.minecraft.client.network.NetHandlerPlayClient; -import net.minecraft.network.Packet; -import net.minecraft.network.play.server.S02PacketChat; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(value = NetHandlerPlayClient.class, priority = Integer.MAX_VALUE) -public class NetHandlerPlayClientMixin { - - @Inject(method = "addToSendQueue", at = @At("HEAD"), cancellable = true) - private void onSendPacket(Packet p_147297_1_, CallbackInfo ci) { - SendPacketEvent event = new SendPacketEvent(p_147297_1_); - EventManager.INSTANCE.post(event); - if (event.isCancelled) { - ci.cancel(); - } - } - - @Inject(method = "handleChat", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/event/ForgeEventFactory;onClientChat(BLnet/minecraft/util/IChatComponent;)Lnet/minecraft/util/IChatComponent;", remap = false), cancellable = true, remap = true) - private void onClientChat(S02PacketChat packetIn, CallbackInfo ci) { - if (packetIn.getType() == 0) { - ChatReceiveEvent event = new ChatReceiveEvent(packetIn.getChatComponent()); - EventManager.INSTANCE.post(event); - if (event.isCancelled) { - ci.cancel(); - } - } - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/mixin/NetworkManagerMixin.java b/src/main/java/cc/polyfrost/oneconfig/mixin/NetworkManagerMixin.java deleted file mode 100644 index e7a9396..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/mixin/NetworkManagerMixin.java +++ /dev/null @@ -1,23 +0,0 @@ -package cc.polyfrost.oneconfig.mixin; - -import cc.polyfrost.oneconfig.events.EventManager; -import cc.polyfrost.oneconfig.events.event.ReceivePacketEvent; -import io.netty.channel.ChannelHandlerContext; -import net.minecraft.network.NetworkManager; -import net.minecraft.network.Packet; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(value = NetworkManager.class, priority = Integer.MAX_VALUE) -public class NetworkManagerMixin { - @Inject(method = "channelRead0(Lio/netty/channel/ChannelHandlerContext;Lnet/minecraft/network/Packet;)V", at = @At("HEAD"), cancellable = true) - private void onReceivePacket(ChannelHandlerContext p_channelRead0_1_, Packet p_channelRead0_2_, CallbackInfo ci) { - ReceivePacketEvent event = new ReceivePacketEvent(p_channelRead0_2_); - EventManager.INSTANCE.post(event); - if (event.isCancelled) { - ci.cancel(); - } - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/mixin/ShaderGroupAccessor.java b/src/main/java/cc/polyfrost/oneconfig/mixin/ShaderGroupAccessor.java deleted file mode 100644 index cf8754e..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/mixin/ShaderGroupAccessor.java +++ /dev/null @@ -1,14 +0,0 @@ -package cc.polyfrost.oneconfig.mixin; - -import net.minecraft.client.shader.Shader; -import net.minecraft.client.shader.ShaderGroup; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import java.util.List; - -@Mixin(ShaderGroup.class) -public interface ShaderGroupAccessor { - @Accessor("listShaders") - List getListShaders(); -} diff --git a/src/main/java/cc/polyfrost/oneconfig/mixin/WorldClientMixin.java b/src/main/java/cc/polyfrost/oneconfig/mixin/WorldClientMixin.java deleted file mode 100644 index 13a3821..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/mixin/WorldClientMixin.java +++ /dev/null @@ -1,21 +0,0 @@ -package cc.polyfrost.oneconfig.mixin; - -import cc.polyfrost.oneconfig.events.EventManager; -import cc.polyfrost.oneconfig.events.event.WorldLoadEvent; -import net.minecraft.client.multiplayer.WorldClient; -import net.minecraft.client.network.NetHandlerPlayClient; -import net.minecraft.profiler.Profiler; -import net.minecraft.world.EnumDifficulty; -import net.minecraft.world.WorldSettings; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(WorldClient.class) -public class WorldClientMixin { - @Inject(method = "", at = @At("RETURN")) - private void onWorldLoad(NetHandlerPlayClient p_i45063_1_, WorldSettings p_i45063_2_, int p_i45063_3_, EnumDifficulty p_i45063_4_, Profiler p_i45063_5_, CallbackInfo ci) { - EventManager.INSTANCE.post(new WorldLoadEvent()); - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/plugin/LoadingPlugin.java b/src/main/java/cc/polyfrost/oneconfig/plugin/LoadingPlugin.java deleted file mode 100644 index be2b399..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/plugin/LoadingPlugin.java +++ /dev/null @@ -1,54 +0,0 @@ -package cc.polyfrost.oneconfig.plugin; - -import cc.polyfrost.oneconfig.init.OneConfigInit; -import net.minecraft.launchwrapper.Launch; -import net.minecraft.launchwrapper.LaunchClassLoader; -import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin; - -import java.lang.reflect.Field; -import java.util.Map; -import java.util.Set; - -public class LoadingPlugin implements IFMLLoadingPlugin { - - /** - * Taken from LWJGLTwoPointFive under The Unlicense - * https://github.com/DJtheRedstoner/LWJGLTwoPointFive/blob/master/LICENSE/ - */ - public LoadingPlugin() { - try { - Field f_exceptions = LaunchClassLoader.class.getDeclaredField("classLoaderExceptions"); - f_exceptions.setAccessible(true); - Set exceptions = (Set) f_exceptions.get(Launch.classLoader); - exceptions.remove("org.lwjgl."); - OneConfigInit.initialize(new String[]{}); - } catch (Exception e) { - throw new RuntimeException("e"); - } - } - - @Override - public String[] getASMTransformerClass() { - return new String[]{"cc.polyfrost.oneconfig.plugin.asm.ClassTransformer"}; - } - - @Override - public String getModContainerClass() { - return null; - } - - @Override - public String getSetupClass() { - return null; - } - - @Override - public void injectData(Map data) { - - } - - @Override - public String getAccessTransformerClass() { - return null; - } -} \ No newline at end of file diff --git a/src/main/java/cc/polyfrost/oneconfig/plugin/OneConfigMixinPlugin.java b/src/main/java/cc/polyfrost/oneconfig/plugin/OneConfigMixinPlugin.java deleted file mode 100644 index 951e942..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/plugin/OneConfigMixinPlugin.java +++ /dev/null @@ -1,52 +0,0 @@ -package cc.polyfrost.oneconfig.plugin; - -import org.spongepowered.asm.lib.tree.ClassNode; -import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; -import org.spongepowered.asm.mixin.extensibility.IMixinInfo; - -import java.util.List; -import java.util.Set; - -public class OneConfigMixinPlugin implements IMixinConfigPlugin { - public static boolean isVigilance = false; - - @Override - public void onLoad(String mixinPackage) { - try { - Class.forName("gg.essential.vigilance.Vigilant"); - isVigilance = true; - } catch (Exception e) { - isVigilance = false; - } - } - - @Override - public String getRefMapperConfig() { - return null; - } - - @Override - public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { - return !targetClassName.contains("vigilance") || isVigilance; - } - - @Override - public void acceptTargets(Set myTargets, Set otherTargets) { - - } - - @Override - public List getMixins() { - return null; - } - - @Override - public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { - - } - - @Override - public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { - - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/plugin/asm/ClassTransformer.java b/src/main/java/cc/polyfrost/oneconfig/plugin/asm/ClassTransformer.java deleted file mode 100644 index 989b5da..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/plugin/asm/ClassTransformer.java +++ /dev/null @@ -1,64 +0,0 @@ -package cc.polyfrost.oneconfig.plugin.asm; - -import cc.polyfrost.oneconfig.plugin.asm.tweakers.NanoVGGLConfigTransformer; -import cc.polyfrost.oneconfig.plugin.asm.tweakers.VigilantTransformer; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Multimap; -import net.minecraft.launchwrapper.IClassTransformer; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.tree.ClassNode; - -import java.util.Collection; - -/** - * Taken from LWJGLTwoPointFive under The Unlicense - * https://github.com/DJtheRedstoner/LWJGLTwoPointFive/blob/master/LICENSE/ - *

also half taken from asmworkspace by asbyth ty

- */ -@SuppressWarnings("unused") -public class ClassTransformer implements IClassTransformer { - private static final Logger logger = LogManager.getLogger("OneConfig ASM"); - private final Multimap transformerMap = ArrayListMultimap.create(); - - public ClassTransformer() { - registerTransformer(new NanoVGGLConfigTransformer()); - registerTransformer(new VigilantTransformer()); - } - - private void registerTransformer(ITransformer transformer) { - // loop through names of classes - for (String cls : transformer.getClassName()) { - // put the classes into the transformer map - transformerMap.put(cls, transformer); - } - } - - @Override - public byte[] transform(String name, String transformedName, byte[] basicClass) { - if (basicClass == null) return null; - - Collection transformers = transformerMap.get(transformedName); - if (transformers.isEmpty()) return basicClass; - - - ClassReader reader = new ClassReader(basicClass); - ClassNode node = new ClassNode(); - reader.accept(node, ClassReader.EXPAND_FRAMES); - - for (ITransformer transformer : transformers) { - transformer.transform(transformedName, node); - } - - ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); - try { - node.accept(cw); - } catch (Throwable t) { - logger.error("Exception when transforming " + transformedName + " : " + t.getClass().getSimpleName()); - t.printStackTrace(); - } - return cw.toByteArray(); - } -} \ No newline at end of file diff --git a/src/main/java/cc/polyfrost/oneconfig/plugin/asm/ITransformer.java b/src/main/java/cc/polyfrost/oneconfig/plugin/asm/ITransformer.java deleted file mode 100644 index f14877f..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/plugin/asm/ITransformer.java +++ /dev/null @@ -1,9 +0,0 @@ -package cc.polyfrost.oneconfig.plugin.asm; - -import org.objectweb.asm.tree.ClassNode; - -public interface ITransformer { - String[] getClassName(); - - void transform(String transformedName, ClassNode node); -} diff --git a/src/main/java/cc/polyfrost/oneconfig/plugin/asm/tweakers/NanoVGGLConfigTransformer.java b/src/main/java/cc/polyfrost/oneconfig/plugin/asm/tweakers/NanoVGGLConfigTransformer.java deleted file mode 100644 index 38da8dd..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/plugin/asm/tweakers/NanoVGGLConfigTransformer.java +++ /dev/null @@ -1,43 +0,0 @@ -package cc.polyfrost.oneconfig.plugin.asm.tweakers; - -import cc.polyfrost.oneconfig.plugin.asm.ITransformer; -import org.objectweb.asm.Opcodes; -import org.objectweb.asm.tree.*; - -public class NanoVGGLConfigTransformer implements ITransformer { - @Override - public String[] getClassName() { - return new String[]{"org.lwjgl.nanovg.NanoVGGLConfig"}; - } - - @Override - public void transform(String transformedName, ClassNode node) { - for (MethodNode method : node.methods) { - if (method.name.equals("configGL")) { - InsnList list = new InsnList(); - - list.add(new VarInsnNode(Opcodes.LLOAD, 0)); - list.add(new TypeInsnNode(Opcodes.NEW, "cc/polyfrost/oneconfig/lwjgl/plugin/Lwjgl2FunctionProvider")); - list.add(new InsnNode(Opcodes.DUP)); - list.add(new MethodInsnNode( - Opcodes.INVOKESPECIAL, - "cc/polyfrost/oneconfig/lwjgl/plugin/Lwjgl2FunctionProvider", - "", - "()V", - false - )); - list.add(new MethodInsnNode( - Opcodes.INVOKESTATIC, - "org/lwjgl/nanovg/NanoVGGLConfig", - "config", - "(JLorg/lwjgl/system/FunctionProvider;)V", - false - )); - list.add(new InsnNode(Opcodes.RETURN)); - - method.instructions.clear(); - method.instructions.insert(list); - } - } - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/plugin/asm/tweakers/VigilantTransformer.java b/src/main/java/cc/polyfrost/oneconfig/plugin/asm/tweakers/VigilantTransformer.java deleted file mode 100644 index 29cf2fd..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/plugin/asm/tweakers/VigilantTransformer.java +++ /dev/null @@ -1,105 +0,0 @@ -package cc.polyfrost.oneconfig.plugin.asm.tweakers; - -import cc.polyfrost.oneconfig.config.compatibility.VigilanceConfig; -import cc.polyfrost.oneconfig.config.core.ConfigCore; -import cc.polyfrost.oneconfig.config.data.Mod; -import cc.polyfrost.oneconfig.config.data.ModType; -import cc.polyfrost.oneconfig.plugin.asm.ITransformer; -import gg.essential.vigilance.Vigilant; -import gg.essential.vigilance.data.PropertyCollector; -import net.minecraft.client.Minecraft; -import net.minecraftforge.fml.common.Loader; -import org.objectweb.asm.Opcodes; -import org.objectweb.asm.Type; -import org.objectweb.asm.tree.*; - -import java.io.File; - -public class VigilantTransformer implements ITransformer { - @SuppressWarnings("unused") - public static VigilanceConfig returnNewConfig(Vigilant vigilant, File file) { - if (vigilant != null && Minecraft.getMinecraft().isCallingFromMinecraftThread()) { - String name = !vigilant.getGuiTitle().equals("Settings") ? vigilant.getGuiTitle() : Loader.instance().activeModContainer() == null ? "Unknown" : Loader.instance().activeModContainer().getName(); - if (name.equals("OneConfig")) name = "Essential"; - String finalName = name; - // duplicate fix - if (ConfigCore.oneConfigMods.stream().anyMatch(mod -> mod.name.equals(finalName))) return null; - return new VigilanceConfig(new Mod(name, ModType.THIRD_PARTY), file.getAbsolutePath(), vigilant); - } else { - return null; - } - } - - @Override - public String[] getClassName() { - return new String[]{"gg.essential.vigilance.Vigilant"}; - } - - @Override - public void transform(String transformedName, ClassNode node) { - node.fields.add(new FieldNode(Opcodes.ACC_PUBLIC, "oneconfig$config", Type.getDescriptor(VigilanceConfig.class), null, null)); - node.fields.add(new FieldNode(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "oneconfig$file", Type.getDescriptor(File.class), null, null)); - - node.interfaces.add("cc/polyfrost/oneconfig/config/compatibility/VigilantAccessor"); - MethodNode methodNode = new MethodNode(Opcodes.ACC_PUBLIC, "getPropertyCollector", "()Lgg/essential/vigilance/data/PropertyCollector;", null, null); - LabelNode labelNode = new LabelNode(); - methodNode.instructions.add(labelNode); - methodNode.instructions.add(new LineNumberNode(421421, labelNode)); - methodNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); - methodNode.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, "gg/essential/vigilance/Vigilant", "propertyCollector", Type.getDescriptor(PropertyCollector.class))); - methodNode.instructions.add(new InsnNode(Opcodes.ARETURN)); - node.methods.add(methodNode); - - MethodNode methodNode2 = new MethodNode(Opcodes.ACC_PUBLIC, "handleOneConfigDependency", "(Lgg/essential/vigilance/data/PropertyData;Lgg/essential/vigilance/data/PropertyData;)V", null, null); - LabelNode labelNode2 = new LabelNode(); - LabelNode labelNode3 = new LabelNode(); - LabelNode labelNode4 = new LabelNode(); - methodNode2.instructions.add(labelNode2); - methodNode2.instructions.add(new LineNumberNode(15636436, labelNode2)); - methodNode2.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); - methodNode2.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$config", Type.getDescriptor(VigilanceConfig.class))); - - methodNode2.instructions.add(new JumpInsnNode(Opcodes.IFNULL, labelNode4)); - - methodNode2.instructions.add(labelNode3); - methodNode2.instructions.add(new LineNumberNode(15636437, labelNode3)); - methodNode2.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); - methodNode2.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$config", Type.getDescriptor(VigilanceConfig.class))); - methodNode2.instructions.add(new VarInsnNode(Opcodes.ALOAD, 1)); - methodNode2.instructions.add(new VarInsnNode(Opcodes.ALOAD, 2)); - methodNode2.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, Type.getInternalName(VigilanceConfig.class), "addDependency", "(Lgg/essential/vigilance/data/PropertyData;Lgg/essential/vigilance/data/PropertyData;)V", false)); - - methodNode2.instructions.add(labelNode4); - methodNode2.instructions.add(new LineNumberNode(15636438, labelNode4)); - methodNode2.instructions.add(new InsnNode(Opcodes.RETURN)); - node.methods.add(methodNode2); - - for (MethodNode method : node.methods) { - if (method.name.equals("initialize")) { - InsnList list = new InsnList(); - list.add(new VarInsnNode(Opcodes.ALOAD, 0)); - list.add(new VarInsnNode(Opcodes.ALOAD, 0)); - list.add(new VarInsnNode(Opcodes.ALOAD, 0)); - list.add(new FieldInsnNode(Opcodes.GETFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$file", Type.getDescriptor(File.class))); - list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(getClass()), "returnNewConfig", "(Lgg/essential/vigilance/Vigilant;Ljava/io/File;)Lcc/polyfrost/oneconfig/config/compatibility/VigilanceConfig;", false)); - list.add(new FieldInsnNode(Opcodes.PUTFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$config", Type.getDescriptor(VigilanceConfig.class))); - method.instructions.insertBefore(method.instructions.getLast().getPrevious(), list); - } else if (method.name.equals("addDependency") && method.desc.equals("(Lgg/essential/vigilance/data/PropertyData;Lgg/essential/vigilance/data/PropertyData;)V")) { - InsnList list = new InsnList(); - - list.add(new VarInsnNode(Opcodes.ALOAD, 0)); - list.add(new VarInsnNode(Opcodes.ALOAD, 1)); - list.add(new VarInsnNode(Opcodes.ALOAD, 2)); - list.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "gg/essential/vigilance/Vigilant", "handleOneConfigDependency", "(Lgg/essential/vigilance/data/PropertyData;Lgg/essential/vigilance/data/PropertyData;)V", false)); - - method.instructions.insertBefore(method.instructions.getLast().getPrevious(), list); - } else if (method.name.equals("") && method.desc.equals("(Ljava/io/File;Ljava/lang/String;Lgg/essential/vigilance/data/PropertyCollector;Lgg/essential/vigilance/data/SortingBehavior;)V")) { - InsnList list = new InsnList(); - list.add(new VarInsnNode(Opcodes.ALOAD, 0)); - list.add(new VarInsnNode(Opcodes.ALOAD, 1)); - list.add(new FieldInsnNode(Opcodes.PUTFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$file", Type.getDescriptor(File.class))); - method.instructions.insertBefore(method.instructions.getLast().getPrevious(), list); - } - } - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java b/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java new file mode 100644 index 0000000..20fc8f6 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java @@ -0,0 +1,755 @@ +package cc.polyfrost.oneconfig.renderer; + +import cc.polyfrost.oneconfig.gui.Colors; +import cc.polyfrost.oneconfig.config.data.InfoType; +import cc.polyfrost.oneconfig.gui.OneConfigGui; +import cc.polyfrost.oneconfig.renderer.font.Font; +import cc.polyfrost.oneconfig.renderer.font.FontManager; +import cc.polyfrost.oneconfig.renderer.font.Fonts; +import cc.polyfrost.oneconfig.renderer.image.ImageLoader; +import cc.polyfrost.oneconfig.renderer.image.Images; +import cc.polyfrost.oneconfig.renderer.image.SVGs; +import cc.polyfrost.oneconfig.utils.InputUtils; +import cc.polyfrost.oneconfig.utils.NetworkUtils; +import gg.essential.universal.UGraphics; +import gg.essential.universal.UMinecraft; +import gg.essential.universal.UResolution; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.shader.Framebuffer; +import org.lwjgl.nanovg.NVGColor; +import org.lwjgl.nanovg.NVGPaint; +import org.lwjgl.opengl.GL11; + +import java.util.function.LongConsumer; + +import static org.lwjgl.nanovg.NanoVG.*; +import static org.lwjgl.nanovg.NanoVGGL2.NVG_ANTIALIAS; +import static org.lwjgl.nanovg.NanoVGGL2.nvgCreate; + +/** + * Handles NanoVG rendering and wraps it in a more convenient interface. + */ +public final class RenderManager { + private static long vg = -1; + + //nanovg + + private RenderManager() { + + } + + /** + * Sets up rendering, calls the consumer with the NanoVG context, and then cleans up. + * + * @param consumer The consumer to call. + * @see RenderManager#setupAndDraw(boolean, LongConsumer) + */ + public static void setupAndDraw(LongConsumer consumer) { + setupAndDraw(false, consumer); + } + + /** + * Sets up rendering, calls the consumer with the NanoVG context, and then cleans up. + * + * @param mcScaling Whether to render with Minecraft's scaling. + * @param consumer The consumer to call. + */ + public static void setupAndDraw(boolean mcScaling, LongConsumer consumer) { + if (vg == -1) { + vg = nvgCreate(NVG_ANTIALIAS); + if (vg == -1) { + throw new RuntimeException("Failed to create nvg context"); + } + FontManager.INSTANCE.initialize(vg); + } + + Framebuffer fb = UMinecraft.getMinecraft().getFramebuffer(); + if (!fb.isStencilEnabled()) { + fb.enableStencil(); + } + GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); + GL11.glDisable(GL11.GL_ALPHA_TEST); + + if (mcScaling) { + nvgBeginFrame(vg, (float) UResolution.getScaledWidth(), (float) UResolution.getScaledHeight(), (float) UResolution.getScaleFactor()); + } else { + // If we get blurry problems with high DPI monitors, 1 might need to be replaced with Display.getPixelScaleFactor() + nvgBeginFrame(vg, UResolution.getWindowWidth(), UResolution.getWindowHeight(), 1); + } + + consumer.accept(vg); + + nvgEndFrame(vg); + + GL11.glPopAttrib(); + } + + /** + * Draws a rectangle with the given parameters. + * + * @param vg The NanoVG context. + * @param x The x position. + * @param y The y position. + * @param width The width. + * @param height The height. + * @param color The color. + */ + public static void drawRectangle(long vg, float x, float y, float width, float height, int color) { // TODO make everything use this one day + if (Colors.ROUNDED_CORNERS) { + drawRoundedRect(vg, x, y, width, height, color, Colors.CORNER_RADIUS); + } else { + drawRect(vg, x, y, width, height, color); + } + } + + /** + * Draws a rectangle with the given parameters. + * + * @param vg The NanoVG context. + * @param x The x position. + * @param y The y position. + * @param width The width. + * @param height The height. + * @param color The color. + */ + public static void drawRect(long vg, float x, float y, float width, float height, int color) { + nvgBeginPath(vg); + nvgRect(vg, x, y, width, height); + NVGColor nvgColor = color(vg, color); + nvgFill(vg); + nvgColor.free(); + } + + /** + * Draws a rounded rectangle with the given parameters. + * + * @param vg The NanoVG context. + * @param x The x position. + * @param y The y position. + * @param width The width. + * @param height The height. + * @param color The color. + * @param radius The radius. + */ + public static void drawRoundedRect(long vg, float x, float y, float width, float height, int color, float radius) { + nvgBeginPath(vg); + nvgRoundedRect(vg, x, y, width, height, radius); + color(vg, color); + NVGColor nvgColor = color(vg, color); + nvgFill(vg); + nvgColor.free(); + } + + /** + * Draw a rounded rectangle where every corner has a different radius + * + * @param vg The NanoVG context + * @param x The x position. + * @param y The y position. + * @param width The width. + * @param height The height. + * @param color The color. + * @param radiusTL Top left corner radius. + * @param radiusTR Top right corner radius. + * @param radiusBR Bottom right corner radius. + * @param radiusBL Bottom left corner radius + */ + public static void drawRoundedRectVaried(long vg, float x, float y, float width, float height, int color, float radiusTL, float radiusTR, float radiusBR, float radiusBL) { + nvgBeginPath(vg); + nvgRoundedRectVarying(vg, x, y, width, height, radiusTL, radiusTR, radiusBR, radiusBL); + color(vg, color); + NVGColor nvgColor = color(vg, color); + nvgFill(vg); + nvgColor.free(); + } + + /** + * Draws a hollow rounded rectangle with the given parameters. + * + * @param vg The NanoVG context. + * @param x The x position. + * @param y The y position. + * @param width The width. + * @param height The height. + * @param color The color. + * @param radius The radius. + * @param thickness The thickness. + */ + public static void drawHollowRoundRect(long vg, float x, float y, float width, float height, int color, float radius, float thickness) { + nvgBeginPath(vg); + nvgRoundedRect(vg, x + thickness, y + thickness, width - thickness, height - thickness, radius); + nvgStrokeWidth(vg, thickness + 0.5f); + nvgPathWinding(vg, NVG_HOLE); + color(vg, color); + NVGColor nvgColor = color(vg, color); + nvgStrokeColor(vg, nvgColor); + nvgStroke(vg); + nvgColor.free(); + } + + /** + * Draws a gradient rectangle with the given parameters. + * + * @param vg The NanoVG context. + * @param x The x position. + * @param y The y position. + * @param width The width. + * @param height The height. + * @param color The first color of the gradient. + * @param color2 The second color of the gradient. + */ + public static void drawGradientRect(long vg, float x, float y, float width, float height, int color, int color2) { + NVGPaint bg = NVGPaint.create(); + nvgBeginPath(vg); + nvgRect(vg, x, y, width, height); + NVGColor nvgColor = color(vg, color); + NVGColor nvgColor2 = color(vg, color2); + nvgFillPaint(vg, nvgLinearGradient(vg, x, y, x, y + width, nvgColor, nvgColor2, bg)); + nvgFillPaint(vg, bg); + nvgFill(vg); + nvgColor.free(); + nvgColor2.free(); + } + + /** + * Draws a rounded gradient rectangle with the given parameters. + * + * @param vg The NanoVG context. + * @param x The x position. + * @param y The y position. + * @param width The width. + * @param height The height. + * @param color The first color of the gradient. + * @param color2 The second color of the gradient. + * @param radius The corner radius. + */ + public static void drawGradientRoundedRect(long vg, float x, float y, float width, float height, int color, int color2, float radius) { + NVGPaint bg = NVGPaint.create(); + nvgBeginPath(vg); + nvgRoundedRect(vg, x, y, width, height, radius); + NVGColor nvgColor = color(vg, color); + NVGColor nvgColor2 = color(vg, color2); + nvgFillPaint(vg, nvgLinearGradient(vg, x, y, x + width, y, nvgColor, nvgColor2, bg)); + nvgFill(vg); + nvgColor.free(); + nvgColor2.free(); + } + + /** + * Draw a HSB box + * + * @param vg The NanoVG context. + * @param x The x coordinate. + * @param y The y coordinate + * @param width The width. + * @param height The height. + * @param colorTarget Hue color + */ + public static void drawHSBBox(long vg, float x, float y, float width, float height, int colorTarget) { + drawRoundedRect(vg, x, y, width, height, colorTarget, 8f); + + NVGPaint bg = NVGPaint.create(); + nvgBeginPath(vg); + nvgRoundedRect(vg, x, y, width, height, 8f); + NVGColor nvgColor = color(vg, -1); + NVGColor nvgColor2 = color(vg, Colors.TRANSPARENT); + nvgFillPaint(vg, nvgLinearGradient(vg, x, y, x + width, y, nvgColor, nvgColor2, bg)); + nvgFill(vg); + nvgColor.free(); + nvgColor2.free(); + + NVGPaint bg2 = NVGPaint.create(); + nvgBeginPath(vg); + nvgRoundedRect(vg, x, y, width, height, 8f); + NVGColor nvgColor3 = color(vg, Colors.TRANSPARENT); + NVGColor nvgColor4 = color(vg, Colors.BLACK); + nvgFillPaint(vg, nvgLinearGradient(vg, x, y, x, y + height, nvgColor3, nvgColor4, bg2)); + nvgFill(vg); + nvgColor3.free(); + nvgColor4.free(); + } + + /** + * Draws a circle with the given parameters. + * + * @param vg The NanoVG context. + * @param x The x position. + * @param y The y position. + * @param radius The radius. + * @param color The color. + */ + public static void drawCircle(long vg, float x, float y, float radius, int color) { + nvgBeginPath(vg); + nvgCircle(vg, x, y, radius); + NVGColor nvgColor = color(vg, color); + nvgFill(vg); + nvgColor.free(); + } + + /** + * Draws a String with the given parameters. + * + * @param vg The NanoVG context. + * @param text The text. + * @param x The x position. + * @param y The y position. + * @param color The color. + * @param size The size. + * @param font The font. + * @see cc.polyfrost.oneconfig.renderer.font.Font + */ + public static void drawText(long vg, String text, float x, float y, int color, float size, Fonts font) { + drawText(vg, text, x, y, color, size, font.font); + } + + /** + * Draws a String with the given parameters. + * + * @param vg The NanoVG context. + * @param text The text. + * @param x The x position. + * @param y The y position. + * @param color The color. + * @param size The size. + * @param font The font. + * @see cc.polyfrost.oneconfig.renderer.font.Font + */ + public static void drawText(long vg, String text, float x, float y, int color, float size, Font font) { + nvgBeginPath(vg); + nvgFontSize(vg, size); + nvgFontFace(vg, font.getName()); + nvgTextAlign(vg, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE); + NVGColor nvgColor = color(vg, color); + nvgText(vg, x, y, text); + nvgFill(vg); + nvgColor.free(); + } + + /** + * Draws a String wrapped at the given width, with the given parameters. + * + * @param vg The NanoVG context. + * @param text The text. + * @param x The x position. + * @param y The y position. + * @param width The width. + * @param color The color. + * @param size The size. + * @param font The font. + */ + public static void drawWrappedString(long vg, String text, float x, float y, float width, int color, float size, Fonts font) { + drawWrappedString(vg, text, x, y, width, color, size, font.font); + } + + /** + * Draws a String wrapped at the given width, with the given parameters. + * + * @param vg The NanoVG context. + * @param text The text. + * @param x The x position. + * @param y The y position. + * @param width The width. + * @param color The color. + * @param size The size. + * @param font The font. + */ + public static void drawWrappedString(long vg, String text, float x, float y, float width, int color, float size, Font font) { + nvgBeginPath(vg); + nvgFontSize(vg, size); + nvgFontFace(vg, font.getName()); + nvgTextAlign(vg, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE); + NVGColor nvgColor = color(vg, color); + nvgTextBox(vg, x, y, width, text); + nvgFill(vg); + nvgColor.free(); + } + + /** + * Draw a formatted URL (a string in blue with an underline) that when clicked, opens the given text. + * + *

This does NOT scale to Minecraft's GUI scale!

+ * + * @see RenderManager#drawText(long, String, float, float, int, float, Font) + * @see InputUtils#isAreaClicked(int, int, int, int) + */ + public static void drawURL(long vg, String url, float x, float y, float size, Fonts font) { + drawURL(vg, url, x, y, size, font.font); + } + + /** + * Draw a formatted URL (a string in blue with an underline) that when clicked, opens the given text. + * + *

This does NOT scale to Minecraft's GUI scale!

+ * + * @see RenderManager#drawText(long, String, float, float, int, float, Font) + * @see InputUtils#isAreaClicked(int, int, int, int) + */ + public static void drawURL(long vg, String url, float x, float y, float size, Font font) { + drawText(vg, url, x, y, Colors.PRIMARY_500, size, font); + float length = getTextWidth(vg, url, size, font); + drawRectangle(vg, x, y + size / 2, length, 1, Colors.PRIMARY_500); + if (InputUtils.isAreaClicked((int) (x - 2), (int) (y - 1), (int) (length + 4), (int) (size / 2 + 3))) { + NetworkUtils.browseLink(url); + } + } + + /** + * Draws an image with the provided file path. + * + * @param vg The NanoVG context. + * @param filePath The file path. + * @param x The x position. + * @param y The y position. + * @param width The width. + * @param height The height. + * @see RenderManager#drawImage(long, String, float, float, float, float, int) + */ + public static void drawImage(long vg, String filePath, float x, float y, float width, float height) { + if (ImageLoader.INSTANCE.loadImage(vg, filePath)) { + NVGPaint imagePaint = NVGPaint.calloc(); + int image = ImageLoader.INSTANCE.getImage(filePath); + nvgBeginPath(vg); + nvgImagePattern(vg, x, y, width, height, 0, image, 1, imagePaint); + nvgRect(vg, x, y, width, height); + nvgFillPaint(vg, imagePaint); + nvgFill(vg); + imagePaint.free(); + } + } + + /** + * Draws an image with the provided file path. + * + * @param vg The NanoVG context. + * @param filePath The file path. + * @param x The x position. + * @param y The y position. + * @param width The width. + * @param height The height. + * @param color The color. + */ + public static void drawImage(long vg, String filePath, float x, float y, float width, float height, int color) { + if (ImageLoader.INSTANCE.loadImage(vg, filePath)) { + NVGPaint imagePaint = NVGPaint.calloc(); + int image = ImageLoader.INSTANCE.getImage(filePath); + nvgBeginPath(vg); + nvgImagePattern(vg, x, y, width, height, 0, image, 1, imagePaint); + nvgRGBA((byte) (color >> 16 & 0xFF), (byte) (color >> 8 & 0xFF), (byte) (color & 0xFF), (byte) (color >> 24 & 0xFF), imagePaint.innerColor()); + nvgRect(vg, x, y, width, height); + nvgFillPaint(vg, imagePaint); + nvgFill(vg); + imagePaint.free(); + } + } + + /** + * Draws an image with the provided file path and parameters. + * + * @see RenderManager#drawImage(long, String, float, float, float, float) + */ + public static void drawImage(long vg, Images filePath, float x, float y, float width, float height) { + drawImage(vg, filePath.filePath, x, y, width, height); + } + + /** + * Draws an image with the provided file path and parameters. + * + * @see RenderManager#drawImage(long, String, float, float, float, float, int) + */ + public static void drawImage(long vg, Images filePath, float x, float y, float width, float height, int color) { + drawImage(vg, filePath.filePath, x, y, width, height, color); + } + + /** + * Draws a rounded image with the provided file path and parameters. + * + * @param vg The NanoVG context. + * @param filePath The file path. + * @param x The x position. + * @param y The y position. + * @param width The width. + * @param height The height. + * @param radius The radius. + */ + public static void drawRoundImage(long vg, String filePath, float x, float y, float width, float height, float radius) { + if (ImageLoader.INSTANCE.loadImage(vg, filePath)) { + NVGPaint imagePaint = NVGPaint.calloc(); + int image = ImageLoader.INSTANCE.getImage(filePath); + nvgBeginPath(vg); + nvgImagePattern(vg, x, y, width, height, 0, image, 1, imagePaint); + nvgRoundedRect(vg, x, y, width, height, radius); + nvgFillPaint(vg, imagePaint); + nvgFill(vg); + imagePaint.free(); + } + } + + /** + * Draws a rounded image with the provided file path and parameters. + * + * @see RenderManager#drawRoundImage(long, String, float, float, float, float, float) + */ + public static void drawRoundImage(long vg, Images filePath, float x, float y, float width, float height, float radius) { + drawRoundImage(vg, filePath.filePath, x, y, width, height, radius); + } + + public static float getTextWidth(long vg, String text, float fontSize, Fonts font) { + return getTextWidth(vg, text, fontSize, font.font); + } + + /** + * Get the width of the provided String. + * + * @param vg The NanoVG context. + * @param text The text. + * @param fontSize The font size. + * @param font The font. + * @return The width of the text. + */ + public static float getTextWidth(long vg, String text, float fontSize, Font font) { + float[] bounds = new float[4]; + nvgFontSize(vg, fontSize); + nvgFontFace(vg, font.getName()); + return nvgTextBounds(vg, 0, 0, text, bounds); + } + + /** + * Draws a line with the provided parameters. + * + * @param vg The NanoVG context. + * @param x The x position. + * @param y The y position. + * @param endX The end x position. + * @param endY The end y position. + * @param width The width. + * @param color The color. + */ + public static void drawLine(long vg, float x, float y, float endX, float endY, float width, int color) { + nvgBeginPath(vg); + nvgMoveTo(vg, x, y); + nvgLineTo(vg, endX, endY); + NVGColor nvgColor = color(vg, color); + nvgStrokeColor(vg, nvgColor); + nvgStrokeWidth(vg, width); + nvgStroke(vg); + nvgColor.free(); + } + + /** + * Draw a drop shadow. + * + * Adapted from legui under MIT license + * + * @param vg The NanoVG context. + * @param x The x coordinate. + * @param y The y coordinate. + * @param w The width. + * @param h The height. + * @param blur The blur (feather). + * @param spread The spread. + * @param cornerRadius The radius of the corner + */ + public static void drawDropShadow(long vg, float x, float y, float w, float h, float blur, float spread, float cornerRadius) { + try (NVGPaint shadowPaint = NVGPaint.calloc(); // allocating memory to pass color to nanovg wrapper + NVGColor firstColor = NVGColor.calloc(); // allocating memory to pass color to nanovg wrapper + NVGColor secondColor = NVGColor.calloc() // allocating memory to pass color to nanovg wrapper + ) { + fillNVGColorWithRGBA(0, 0, 0, 0.5f, firstColor); // filling allocated memory + fillNVGColorWithRGBA(0, 0, 0, 0, secondColor); // filling allocated memory + + // creating gradient and put it to shadowPaint + nvgBoxGradient(vg, x - spread, y - spread, w + 2 * spread, h + 2 * spread, cornerRadius + spread, blur, firstColor, secondColor, shadowPaint); + nvgBeginPath(vg); + nvgRoundedRect(vg, x - spread - blur, y - spread - blur, w + 2 * spread + 2 * blur, h + 2 * spread + 2 * blur, cornerRadius + spread); + nvgRoundedRect(vg, x, y, w, h, cornerRadius); + nvgPathWinding(vg, NVG_HOLE); + nvgFillPaint(vg, shadowPaint); + nvgFill(vg); + } + } + + /** + * Fills the provided {@link NVGColor} with the provided RGBA values. + * + * @param r The red value. + * @param g The green value. + * @param b The blue value. + * @param a The alpha value. + * @param color The {@link NVGColor} to fill. + */ + public static void fillNVGColorWithRGBA(float r, float g, float b, float a, NVGColor color) { + color.r(r); + color.g(g); + color.b(b); + color.a(a); + } + + /** + * Create a {@link NVGColor} from the provided RGBA values. + * + * @param vg The NanoVG context. + * @param color The color. + * @return The {@link NVGColor} created. + */ + public static NVGColor color(long vg, int color) { + NVGColor nvgColor = NVGColor.calloc(); + nvgRGBA((byte) (color >> 16 & 0xFF), (byte) (color >> 8 & 0xFF), (byte) (color & 0xFF), (byte) (color >> 24 & 0xFF), nvgColor); + nvgFillColor(vg, nvgColor); + return nvgColor; + } + + /** + * Scales all rendering by the provided scale. + * + * @param vg The NanoVG context. + * @param x The x scale. + * @param y The y scale. + */ + public static void scale(long vg, float x, float y) { + nvgScale(vg, x, y); + } + + /** + * Sets the global alpha value to render with. + * + * @param vg The NanoVG context. + * @param alpha The alpha value. + */ + public static void setAlpha(long vg, float alpha) { + nvgGlobalAlpha(vg, alpha); + } + + /** + * Draws a SVG with the provided file path and parameters. + * + * @param vg The NanoVG context. + * @param filePath The file path. + * @param x The x position. + * @param y The y position. + * @param width The width. + * @param height The height. + */ + public static void drawSvg(long vg, String filePath, float x, float y, float width, float height) { + float w = width; + float h = height; + if (OneConfigGui.INSTANCE != null) { + w *= OneConfigGui.INSTANCE.getScaleFactor(); + h *= OneConfigGui.INSTANCE.getScaleFactor(); + } + if (ImageLoader.INSTANCE.loadSVG(vg, filePath, w, h)) { + NVGPaint imagePaint = NVGPaint.calloc(); + int image = ImageLoader.INSTANCE.getSVG(filePath, w, h); + nvgBeginPath(vg); + nvgImagePattern(vg, x, y, width, height, 0, image, 1, imagePaint); + nvgRect(vg, x, y, width, height); + nvgFillPaint(vg, imagePaint); + nvgFill(vg); + imagePaint.free(); + } + } + + /** + * Draws a SVG with the provided file path and parameters. + * + * @param vg The NanoVG context. + * @param filePath The file path. + * @param x The x position. + * @param y The y position. + * @param width The width. + * @param height The height. + * @param color The color. + */ + public static void drawSvg(long vg, String filePath, float x, float y, float width, float height, int color) { + float w = width; + float h = height; + if (OneConfigGui.INSTANCE != null) { + w *= OneConfigGui.INSTANCE.getScaleFactor(); + h *= OneConfigGui.INSTANCE.getScaleFactor(); + } + if (ImageLoader.INSTANCE.loadSVG(vg, filePath, w, h)) { + NVGPaint imagePaint = NVGPaint.calloc(); + int image = ImageLoader.INSTANCE.getSVG(filePath, w, h); + nvgBeginPath(vg); + nvgImagePattern(vg, x, y, width, height, 0, image, 1, imagePaint); + nvgRGBA((byte) (color >> 16 & 0xFF), (byte) (color >> 8 & 0xFF), (byte) (color & 0xFF), (byte) (color >> 24 & 0xFF), imagePaint.innerColor()); + nvgRect(vg, x, y, width, height); + nvgFillPaint(vg, imagePaint); + nvgFill(vg); + imagePaint.free(); + } + } + + /** + * Draws an SVG with the provided file path and parameters. + * + * @see RenderManager#drawSvg(long, String, float, float, float, float) + */ + public static void drawSvg(long vg, SVGs svg, float x, float y, float width, float height) { + drawSvg(vg, svg.filePath, x, y, width, height); + } + + /** + * Draws an SVG with the provided file path and parameters. + * + * @see RenderManager#drawSvg(long, String, float, float, float, float, int) + */ + public static void drawSvg(long vg, SVGs svg, float x, float y, float width, float height, int color) { + drawSvg(vg, svg.filePath, x, y, width, height, color); + } + + /** + * Draw a circle with an info icon inside of it + * + * @param vg The NanoVG context. + * @param type The icon type. + * @param x The x position. + * @param y The y position. + * @param size The diameter. + */ + public static void drawInfo(long vg, InfoType type, float x, float y, float size) { + SVGs icon = null; + int colorOuter = 0; + int colorInner = 0; + switch (type) { + case INFO: + icon = SVGs.INFO_CIRCLE; + colorOuter = Colors.GRAY_400; + colorInner = Colors.GRAY_300; + break; + case SUCCESS: + icon = SVGs.CHECK_CIRCLE; + colorOuter = Colors.SUCCESS_700; + colorInner = Colors.SUCCESS_600; + break; + case WARNING: + icon = SVGs.WARNING; + colorOuter = Colors.WARNING_600; + colorInner = Colors.WARNING_500; + break; + case ERROR: + icon = SVGs.ERROR; + colorOuter = Colors.ERROR_700; + colorInner = Colors.ERROR_600; + break; + } + float centerX = x + size / 2f; + float centerY = y + size / 2f; + drawCircle(vg, centerX, centerY, size / 2, colorOuter); + drawCircle(vg, centerX, centerY, size / 2 - size / 12, colorInner); + float iconSize = size / 1.75f; + drawSvg(vg, icon, centerX - iconSize / 2f, centerY - iconSize / 2f, iconSize, iconSize); + } + + // gl + + public static void drawScaledString(String text, float x, float y, int color, boolean shadow, float scale) { + UGraphics.GL.pushMatrix(); + UGraphics.GL.scale(scale, scale, 1); + UMinecraft.getFontRenderer().drawString(text, x * (1 / scale), y * (1 / scale), color, shadow); + UGraphics.GL.popMatrix(); + } + + public static void drawGlRect(int x, int y, int width, int height, int color) { + Gui.drawRect(x, y, x + width, y + height, color); + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/font/Font.java b/src/main/java/cc/polyfrost/oneconfig/renderer/font/Font.java new file mode 100644 index 0000000..b35708b --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/renderer/font/Font.java @@ -0,0 +1,41 @@ +package cc.polyfrost.oneconfig.renderer.font; + +import java.nio.ByteBuffer; + +public class Font { + private final String fileName; + private final String name; + private boolean loaded = false; + private ByteBuffer buffer = null; + + public Font(String name, String fileName) { + this.name = name; + this.fileName = fileName; + } + + public String getName() { + return name; + } + + public String getFileName() { + return fileName; + } + + public boolean isLoaded() { + return loaded; + } + + void setLoaded(boolean loaded) { + this.loaded = loaded; + } + + public ByteBuffer getBuffer() { + return buffer; + } + + void setBuffer(ByteBuffer buffer) { + this.buffer = buffer; + } + +} + diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/font/FontManager.java b/src/main/java/cc/polyfrost/oneconfig/renderer/font/FontManager.java new file mode 100644 index 0000000..388911d --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/renderer/font/FontManager.java @@ -0,0 +1,47 @@ +package cc.polyfrost.oneconfig.renderer.font; + +import cc.polyfrost.oneconfig.utils.IOUtils; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import static org.lwjgl.nanovg.NanoVG.nvgCreateFontMem; + +public class FontManager { + public static FontManager INSTANCE = new FontManager(); + + /** + * Load all fonts in the Fonts class + * + * @param vg NanoVG context + */ + + public void initialize(long vg) { + for (Fonts fonts : Fonts.values()) { + loadFont(vg, fonts.font); + } + } + + /** + * Load a font into NanoVG + * + * @param vg NanoVG context + * @param font The font to be loaded + */ + public void loadFont(long vg, Font font) { + if (font.isLoaded()) return; + int loaded = -1; + try { + ByteBuffer buffer = IOUtils.resourceToByteBuffer(font.getFileName()); + loaded = nvgCreateFontMem(vg, font.getName(), buffer, 0); + font.setBuffer(buffer); + } catch (IOException e) { + e.printStackTrace(); + } + if (loaded == -1) { + throw new RuntimeException("Failed to initialize font " + font.getName()); + } else { + font.setLoaded(true); + } + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/font/Fonts.java b/src/main/java/cc/polyfrost/oneconfig/renderer/font/Fonts.java new file mode 100644 index 0000000..9b6193f --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/renderer/font/Fonts.java @@ -0,0 +1,15 @@ +package cc.polyfrost.oneconfig.renderer.font; + +public enum Fonts { + BOLD(new Font("inter-bold", "/assets/oneconfig/font/Bold.otf")), + SEMIBOLD(new Font("inter-semibold", "/assets/oneconfig/font/SemiBold.otf")), + MEDIUM(new Font("inter-medium", "/assets/oneconfig/font/Medium.otf")), + REGULAR(new Font("inter-regular", "/assets/oneconfig/font/Regular.otf")), + MINECRAFT_REGULAR(new Font("mc-regular", "/assets/oneconfig/font/Minecraft-Regular.otf")), + MINECRAFT_BOLD(new Font("mc-bold", "/assets/oneconfig/font/Minecraft-Bold.otf")); + public final Font font; + + Fonts(Font font) { + this.font = font; + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/image/ImageLoader.java b/src/main/java/cc/polyfrost/oneconfig/renderer/image/ImageLoader.java new file mode 100644 index 0000000..e8861eb --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/renderer/image/ImageLoader.java @@ -0,0 +1,190 @@ +package cc.polyfrost.oneconfig.renderer.image; + +import cc.polyfrost.oneconfig.utils.IOUtils; +import org.lwjgl.nanovg.NSVGImage; +import org.lwjgl.nanovg.NanoSVG; +import org.lwjgl.nanovg.NanoVG; +import org.lwjgl.stb.STBImage; +import org.lwjgl.system.MemoryUtil; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.ByteBuffer; +import java.util.HashMap; + +/** + * Loads images and SVGs from resources into NanoVG. + * + * @see cc.polyfrost.oneconfig.renderer.RenderManager + * @see Images + * @see SVGs + */ +public final class ImageLoader { + private ImageLoader() { + + } + + private final HashMap imageHashMap = new HashMap<>(); + private final HashMap svgHashMap = new HashMap<>(); + public static ImageLoader INSTANCE = new ImageLoader(); + + /** + * Loads an image from resources. + * + * @param vg The NanoVG context. + * @param fileName The name of the file to load. + * @return Whether the image was loaded successfully. + */ + public boolean loadImage(long vg, String fileName) { + if (!imageHashMap.containsKey(fileName)) { + int[] width = {0}; + int[] height = {0}; + int[] channels = {0}; + + ByteBuffer image = IOUtils.resourceToByteBufferNullable(fileName); + if (image == null) { + return false; + } + + ByteBuffer buffer = STBImage.stbi_load_from_memory(image, width, height, channels, 4); + if (buffer == null) { + return false; + } + + imageHashMap.put(fileName, NanoVG.nvgCreateImageRGBA(vg, width[0], height[0], NanoVG.NVG_IMAGE_REPEATX | NanoVG.NVG_IMAGE_REPEATY | NanoVG.NVG_IMAGE_GENERATE_MIPMAPS, buffer)); + return true; + } + return true; + } + + /** + * Loads an SVG from resources. + * + * @param vg The NanoVG context. + * @param fileName The name of the file to load. + * @param width The width of the SVG. + * @param height The height of the SVG. + * @return Whether the SVG was loaded successfully. + */ + public boolean loadSVG(long vg, String fileName, float width, float height) { + String name = fileName + "-" + width + "-" + height; + if (!svgHashMap.containsKey(name)) { + try { + InputStream inputStream = this.getClass().getResourceAsStream(fileName); + if (inputStream == null) return false; + StringBuilder resultStringBuilder = new StringBuilder(); + try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) { + String line; + while ((line = br.readLine()) != null) { + resultStringBuilder.append(line); + } + } + CharSequence s = resultStringBuilder.toString(); + NSVGImage svg = NanoSVG.nsvgParse(s, "px", 96f); + if (svg == null) return false; + long rasterizer = NanoSVG.nsvgCreateRasterizer(); + + int w = (int) svg.width(); + int h = (int) svg.height(); + float scale = Math.max(width / w, height / h); + w = (int) (w * scale); + h = (int) (h * scale); + + ByteBuffer image = MemoryUtil.memAlloc(w * h * 4); + NanoSVG.nsvgRasterize(rasterizer, svg, 0, 0, scale, image, w, h, w * 4); + + NanoSVG.nsvgDeleteRasterizer(rasterizer); + NanoSVG.nsvgDelete(svg); + + svgHashMap.put(name, NanoVG.nvgCreateImageRGBA(vg, w, h, NanoVG.NVG_IMAGE_REPEATX | NanoVG.NVG_IMAGE_REPEATY | NanoVG.NVG_IMAGE_GENERATE_MIPMAPS, image)); + return true; + } catch (Exception e) { + System.err.println("Failed to parse SVG file"); + e.printStackTrace(); + return false; + } + } + return true; + } + + /** + * Get a loaded image from the cache. + *

Requires the image to have been loaded first.

+ * + * @param fileName The name of the file to load. + * @return The image + * @see ImageLoader#loadImage(long, String) + */ + public int getImage(String fileName) { + return imageHashMap.get(fileName); + } + + /** + * Remove an image from the cache, allowing the image to be garbage collected. + * Should be used when the GUI rendering the image is closed. + * + * @param vg The NanoVG context. + * @param fileName The name of the file to remove. + * @see ImageLoader#loadImage(long, String) + */ + public void removeImage(long vg, String fileName) { + NanoVG.nvgDeleteImage(vg, imageHashMap.get(fileName)); + imageHashMap.remove(fileName); + } + + /** + * Clears all images from the cache, allowing the images cleared to be garbage collected. + * Should be used when the GUI rendering loaded images are closed. + * + * @param vg The NanoVG context. + */ + public void clearImages(long vg) { + HashMap temp = new HashMap<>(imageHashMap); + for (String image : temp.keySet()) { + NanoVG.nvgDeleteImage(vg, imageHashMap.get(image)); + imageHashMap.remove(image); + } + } + + /** + * Get a loaded SVG from the cache. + *

Requires the SVG to have been loaded first.

+ * + * @param fileName The name of the file to load. + * @return The SVG + * @see ImageLoader#loadSVG(long, String, float, float) + */ + public int getSVG(String fileName, float width, float height) { + String name = fileName + "-" + width + "-" + height; + return svgHashMap.get(name); + } + + /** + * Remove a SVG from the cache, allowing the SVG to be garbage collected. + * Should be used when the GUI rendering the SVG is closed. + * + * @param vg The NanoVG context. + * @param fileName The name of the file to remove. + * @see ImageLoader#loadSVG(long, String, float, float) + */ + public void removeSVG(long vg, String fileName, float width, float height) { + String name = fileName + "-" + width + "-" + height; + NanoVG.nvgDeleteImage(vg, imageHashMap.get(name)); + svgHashMap.remove(name); + } + + /** + * Clears all SVGs from the cache, allowing the SVGs cleared to be garbage collected. + * Should be used when the GUI rendering loaded SVGs are closed. + * + * @param vg The NanoVG context. + */ + public void clearSVGs(long vg) { + HashMap temp = new HashMap<>(svgHashMap); + for (String image : temp.keySet()) { + NanoVG.nvgDeleteImage(vg, svgHashMap.get(image)); + svgHashMap.remove(image); + } + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/image/Images.java b/src/main/java/cc/polyfrost/oneconfig/renderer/image/Images.java new file mode 100644 index 0000000..ad1941e --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/renderer/image/Images.java @@ -0,0 +1,19 @@ +package cc.polyfrost.oneconfig.renderer.image; + +/** + * An enum of images used in OneConfig. + * + * @see cc.polyfrost.oneconfig.renderer.RenderManager#drawImage(long, String, float, float, float, float, int) + * @see ImageLoader + */ +public enum Images { + HUE_GRADIENT("/assets/oneconfig/options/HueGradient.png"), + COLOR_WHEEL("/assets/oneconfig/options/ColorWheel.png"), + ALPHA_GRID("/assets/oneconfig/options/AlphaGrid.png"); + + public final String filePath; + + Images(String filePath) { + this.filePath = filePath; + } +} \ No newline at end of file diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/image/SVGs.java b/src/main/java/cc/polyfrost/oneconfig/renderer/image/SVGs.java new file mode 100644 index 0000000..5ba3fcd --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/renderer/image/SVGs.java @@ -0,0 +1,52 @@ +package cc.polyfrost.oneconfig.renderer.image; + +/** + * An enum of SVGs used in OneConfig. + * + * @see cc.polyfrost.oneconfig.renderer.RenderManager#drawSvg(long, String, float, float, float, float, int) + * @see ImageLoader + */ +public enum SVGs { + ONECONFIG("/assets/oneconfig/icons/OneConfig.svg"), + ONECONFIG_OFF("/assets/oneconfig/icons/OneConfigOff.svg"), + COPYRIGHT_FILL("/assets/oneconfig/icons/CopyrightFill.svg"), + APERTURE_FILL("/assets/oneconfig/icons/ApertureFill.svg"), + ARROWS_CLOCKWISE_BOLD("/assets/oneconfig/icons/ArrowsClockwiseBold.svg"), + FADERS_HORIZONTAL_BOLD("/assets/oneconfig/icons/FadersHorizontalBold.svg"), + GAUGE_FILL("/assets/oneconfig/icons/GaugeFill.svg"), + GEAR_SIX_FILL("/assets/oneconfig/icons/GearSixFill.svg"), + MAGNIFYING_GLASS_BOLD("/assets/oneconfig/icons/MagnifyingGlassBold.svg"), + NOTE_PENCIL_BOLD("/assets/oneconfig/icons/NotePencilBold.svg"), + PAINT_BRUSH_BROAD_FILL("/assets/oneconfig/icons/PaintBrushBroadFill.svg"), + USER_SWITCH_FILL("/assets/oneconfig/icons/UserSwitchFill.svg"), + X_CIRCLE_BOLD("/assets/oneconfig/icons/XCircleBold.svg"), + CARET_LEFT("/assets/oneconfig/icons/CaretLeftBold.svg"), + CARET_RIGHT("/assets/oneconfig/icons/CaretRightBold.svg"), + + // OLD ICONS + BOX("/assets/oneconfig/old-icons/Box.svg"), + CHECKBOX_TICK("/assets/oneconfig/old-icons/CheckboxTick.svg"), + CHECK_CIRCLE("/assets/oneconfig/old-icons/CheckCircle.svg"), + CHEVRON_DOWN("/assets/oneconfig/old-icons/ChevronDown.svg"), + CHEVRON_UP("/assets/oneconfig/old-icons/ChevronUp.svg"), + COPY("/assets/oneconfig/old-icons/Copy.svg"), + DROPDOWN_LIST("/assets/oneconfig/old-icons/DropdownList.svg"), + ERROR("/assets/oneconfig/old-icons/Error.svg"), + EYE("/assets/oneconfig/old-icons/Eye.svg"), + EYE_OFF("/assets/oneconfig/old-icons/EyeOff.svg"), + HEART_FILL("/assets/oneconfig/old-icons/HeartFill.svg"), + HEART_OUTLINE("/assets/oneconfig/old-icons/HeartOutline.svg"), + HELP_CIRCLE("/assets/oneconfig/old-icons/HelpCircle.svg"), + HISTORY("/assets/oneconfig/old-icons/History.svg"), + INFO_CIRCLE("/assets/oneconfig/old-icons/InfoCircle.svg"), + KEYSTROKE("/assets/oneconfig/old-icons/Keystroke.svg"), + PASTE("/assets/oneconfig/old-icons/Paste.svg"), + POP_OUT("/assets/oneconfig/old-icons/PopOut.svg"), + WARNING("/assets/oneconfig/old-icons/Warning.svg"); + + public final String filePath; + + SVGs(String filePath) { + this.filePath = filePath; + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/scissor/Scissor.java b/src/main/java/cc/polyfrost/oneconfig/renderer/scissor/Scissor.java new file mode 100644 index 0000000..179a260 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/renderer/scissor/Scissor.java @@ -0,0 +1,27 @@ +package cc.polyfrost.oneconfig.renderer.scissor; + +/** + * A class that represents a scissor rectangle. + * + * @see ScissorManager + */ +public class Scissor { + public float x; + public float y; + public float width; + public float height; + + public Scissor(float x, float y, float width, float height) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } + + public Scissor(Scissor scissor) { + this.x = scissor.x; + this.y = scissor.y; + this.width = scissor.width; + this.height = scissor.height; + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/scissor/ScissorManager.java b/src/main/java/cc/polyfrost/oneconfig/renderer/scissor/ScissorManager.java new file mode 100644 index 0000000..1f7801b --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/renderer/scissor/ScissorManager.java @@ -0,0 +1,69 @@ +package cc.polyfrost.oneconfig.renderer.scissor; + +import org.lwjgl.nanovg.NanoVG; + +import java.util.ArrayList; + +/** + * Provides an easy way to manage and group scissor rectangles. + */ +public class ScissorManager { + private static final ArrayList scissors = new ArrayList<>(); + + /** + * Adds and applies a scissor rectangle to the list of scissor rectangles. + * + * @param vg The NanoVG context. + * @param x The x coordinate of the scissor rectangle. + * @param y The y coordinate of the scissor rectangle. + * @param width The width of the scissor rectangle. + * @param height The height of the scissor rectangle. + * @return The scissor rectangle. + */ + public static Scissor scissor(long vg, float x, float y, float width, float height) { + Scissor scissor = new Scissor(x, y, width, height); + if (scissors.contains(scissor)) return scissor; + scissors.add(scissor); + applyScissors(vg); + return scissor; + } + + /** + * Resets the scissor rectangle provided. + * + * @param vg The NanoVG context. + * @param scissor The scissor rectangle to reset. + */ + public static void resetScissor(long vg, Scissor scissor) { + if (scissors.contains(scissor)) { + scissors.remove(scissor); + applyScissors(vg); + } + } + + /** + * Clear all scissor rectangles. + * + * @param vg The NanoVG context. + */ + public static void clearScissors(long vg) { + scissors.clear(); + NanoVG.nvgResetScissor(vg); + } + + private static void applyScissors(long vg) { + NanoVG.nvgResetScissor(vg); + if (scissors.size() <= 0) return; + Scissor finalScissor = new Scissor(scissors.get(0)); + for (int i = 1; i < scissors.size(); i++) { + Scissor scissor = scissors.get(i); + float rightX = Math.min(scissor.x + scissor.width, finalScissor.x + finalScissor.width); + float rightY = Math.min(scissor.y + scissor.height, finalScissor.y + finalScissor.height); + finalScissor.x = Math.max(finalScissor.x, scissor.x); + finalScissor.y = Math.max(finalScissor.y, scissor.y); + finalScissor.width = rightX - finalScissor.x; + finalScissor.height = rightY - finalScissor.y; + } + NanoVG.nvgScissor(vg, finalScissor.x, finalScissor.y, finalScissor.width, finalScissor.height); + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/test/ButtonTestPage.java b/src/main/java/cc/polyfrost/oneconfig/test/ButtonTestPage.java index fb137db..3dd74dc 100644 --- a/src/main/java/cc/polyfrost/oneconfig/test/ButtonTestPage.java +++ b/src/main/java/cc/polyfrost/oneconfig/test/ButtonTestPage.java @@ -2,7 +2,7 @@ package cc.polyfrost.oneconfig.test; import cc.polyfrost.oneconfig.gui.elements.BasicButton; import cc.polyfrost.oneconfig.gui.pages.Page; -import cc.polyfrost.oneconfig.lwjgl.image.SVGs; +import cc.polyfrost.oneconfig.renderer.image.SVGs; import cc.polyfrost.oneconfig.utils.color.ColorPalette; import java.util.ArrayList; diff --git a/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java b/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java index f632784..2d76a0e 100644 --- a/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java +++ b/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java @@ -5,8 +5,9 @@ import cc.polyfrost.oneconfig.config.annotations.Option; import cc.polyfrost.oneconfig.config.core.OneColor; import cc.polyfrost.oneconfig.config.core.OneKeyBind; import cc.polyfrost.oneconfig.config.data.*; -import cc.polyfrost.oneconfig.config.interfaces.Config; -import cc.polyfrost.oneconfig.config.migration.VigilanceMigrator; +import cc.polyfrost.oneconfig.config.Config; +import cc.polyfrost.oneconfig.config.data.ModType; +import cc.polyfrost.oneconfig.config.migration.vigilance.VigilanceMigrator; import net.minecraftforge.fml.common.FMLCommonHandler; public class TestConfig extends Config { diff --git a/src/main/java/cc/polyfrost/oneconfig/test/TestNanoVGGui_Test.java b/src/main/java/cc/polyfrost/oneconfig/test/TestNanoVGGui_Test.java index 504c12f..5ad95c7 100644 --- a/src/main/java/cc/polyfrost/oneconfig/test/TestNanoVGGui_Test.java +++ b/src/main/java/cc/polyfrost/oneconfig/test/TestNanoVGGui_Test.java @@ -1,7 +1,7 @@ package cc.polyfrost.oneconfig.test; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; -import cc.polyfrost.oneconfig.lwjgl.font.Fonts; +import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.renderer.font.Fonts; import gg.essential.universal.UMatrixStack; import gg.essential.universal.UScreen; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/GuiUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/GuiUtils.java deleted file mode 100644 index 29c26fb..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/utils/GuiUtils.java +++ /dev/null @@ -1,62 +0,0 @@ -package cc.polyfrost.oneconfig.utils; - -import cc.polyfrost.oneconfig.events.EventManager; -import cc.polyfrost.oneconfig.events.event.RenderEvent; -import cc.polyfrost.oneconfig.events.event.Stage; -import gg.essential.universal.UMinecraft; -import gg.essential.universal.UScreen; -import me.kbrewster.eventbus.Subscribe; -import net.minecraft.client.gui.GuiScreen; - -/** - * A class containing utility methods for working with GuiScreens. - */ -public final class GuiUtils { - private static long time = -1L; - private static long deltaTime = 17L; - - static { - EventManager.INSTANCE.register(new GuiUtils()); - } - - /** - * Displays a screen after a tick, preventing mouse sync issues. - * - * @param screen the screen to display. - */ - public static void displayScreen(GuiScreen screen) { - new TickDelay(() -> UScreen.displayScreen(screen), 1); - } - - /** - * Close the current open GUI screen. - */ - public static void closeScreen() { - UScreen.displayScreen(null); - } - - /** - * Gets the delta time (in milliseconds) between frames. - *

- * Not to be confused with Minecraft deltaTicks / renderPartialTicks, which can be gotten via - * {@link cc.polyfrost.oneconfig.events.event.TimerUpdateEvent} - *

- * - * @return the delta time. - */ - public static float getDeltaTime() { - return deltaTime; - } - - @Subscribe - private void onRenderEvent(RenderEvent event) { - if (event.stage == Stage.START) { - if (time == -1) time = UMinecraft.getTime(); - else { - long currentTime = UMinecraft.getTime(); - deltaTime = currentTime - time; - time = currentTime; - } - } - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/OneUIScreen.java b/src/main/java/cc/polyfrost/oneconfig/utils/OneUIScreen.java deleted file mode 100644 index dac995d..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/utils/OneUIScreen.java +++ /dev/null @@ -1,146 +0,0 @@ -package cc.polyfrost.oneconfig.utils; - -import cc.polyfrost.oneconfig.lwjgl.RenderManager; -import gg.essential.universal.UMatrixStack; -import gg.essential.universal.UScreen; -import net.minecraft.client.gui.GuiScreen; -import org.jetbrains.annotations.NotNull; -import org.lwjgl.input.Mouse; - -/** - *

OneUIScreen

- * OneUIScreen is a GUI that can be used to render things on the client's screen. - * It contains many handy methods for rendering, including {@link #draw(long, float)} for drawing using OneConfig's {@link RenderManager}. - *

It also contains methods for mouse input. (see {@link InputUtils} for more utils). - *

- * Use {@link GuiUtils#displayScreen(GuiScreen)} to display a screen; and {@link GuiUtils#closeScreen()} to close it. - */ -public abstract class OneUIScreen extends UScreen { - private boolean mouseDown; - private boolean blockClicks; - - /** - * Create a new OneUIScreen. - * - * @param restoreGuiOnClose use this to declare weather or not to open the Gui that was open before it when this screen is closed. - */ - public OneUIScreen(boolean restoreGuiOnClose) { - super(restoreGuiOnClose); - } - - /** - * Create a new OneUIScreen. - */ - public OneUIScreen() { - super(false); - } - - @Override - public void onDrawScreen(@NotNull UMatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { - super.onDrawScreen(matrixStack, mouseX, mouseY, partialTicks); - RenderManager.setupAndDraw(ignoreMinecraftScale(), vg -> draw(vg, partialTicks)); - mouseDown = Mouse.isButtonDown(0); - } - - /** - * This method is called when the screen is first opened. You can use it to set variables, initialize things, etc. - */ - public abstract void onScreenOpen(); - - /** - * Use this method to draw things on the screen. It is called every render tick, and has a handy vg (NanoVG context) that can be used with the {@link RenderManager} to draw things. - *

- * For example: {@link RenderManager#drawRoundedRect(long, float, float, float, float, int, float)} - * - * @param vg the NanoVG context you can use to render things with - * @param partialTicks the time between ticks (You can use this as a deltaTime equivalent) - */ - public abstract void draw(long vg, float partialTicks); - - /** - * This method is called when the screen is closed. You can use it to clean up things, etc. - */ - @Override - public abstract void onScreenClose(); - - @Override - public void initScreen(int width, int height) { - onScreenOpen(); - } - - /** - * Use this method to set weather or not to use the Minecraft scale on the GUI. Its default is true, and that is recommended for the NanoVG rendering. - */ - public boolean ignoreMinecraftScale() { - return true; - } - - /** - * Use this method to declare weather or not this Screen pauses the game when it is open. (Single-player only) Its default is false. - */ - public boolean doesScreenPauseGame() { - return false; - } - - @Override - public boolean doesGuiPauseGame() { - return doesScreenPauseGame(); - } - - - /** - * Get the current x position of the mouse. - */ - public int getMouseX() { - return InputUtils.mouseX(); - } - - /** - * Get the current y position of the mouse. - */ - public int getMouseY() { - return InputUtils.mouseY(); - } - - @Override - public void onMouseClicked(double mouseX, double mouseY, int mouseButton) { - super.onMouseClicked(mouseX, mouseY, mouseButton); - } - - /** - * Retrieve the click status of the mouse. This method uses a boolean to store the status of the mouse, so it will only return true once per click. (very useful) - * - * @param ignoreBlockClicks whether to ignore the current click blocker. - */ - public boolean isClicked(boolean ignoreBlockClicks) { - return mouseDown && !Mouse.isButtonDown(0) && (!blockClicks || ignoreBlockClicks); - } - - /** - * Retrieve the click status of the mouse. This method uses a boolean to store the status of the mouse, so it will only return true once per click. (very useful) - */ - public boolean isClicked() { - return isClicked(false); - } - - /** - * Retrieve weather or not the mouse is currently down. Will constantly return true if its clicked. See {@link #isClicked()} for a method that only executes once per tick. - */ - public boolean isMouseDown() { - return Mouse.isButtonDown(0); - } - - /** - * Click blocking can be useful when you are drawing buttons for example over the top of other elements, so a click blocker can be used to ensure that the mouse doesn't click through things. - */ - public void shouldBlockClicks(boolean state) { - blockClicks = state; - } - - /** - * Click blocking can be useful when you are drawing buttons for example over the top of other elements, so a click blocker can be used to ensure that the mouse doesn't click through things. - */ - public boolean isBlockingClicks() { - return blockClicks; - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/TextUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/TextUtils.java index df37aae..51b42d8 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/TextUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/TextUtils.java @@ -1,8 +1,8 @@ package cc.polyfrost.oneconfig.utils; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; -import cc.polyfrost.oneconfig.lwjgl.font.Font; -import cc.polyfrost.oneconfig.lwjgl.font.Fonts; +import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.renderer.font.Font; +import cc.polyfrost.oneconfig.renderer.font.Fonts; import java.util.ArrayList; diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/color/ColorPalette.java b/src/main/java/cc/polyfrost/oneconfig/utils/color/ColorPalette.java index a73e9ff..dc15e92 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/color/ColorPalette.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/color/ColorPalette.java @@ -1,18 +1,18 @@ package cc.polyfrost.oneconfig.utils.color; -import cc.polyfrost.oneconfig.config.OneConfigConfig; +import cc.polyfrost.oneconfig.gui.Colors; import cc.polyfrost.oneconfig.config.core.OneColor; import java.awt.*; -import static cc.polyfrost.oneconfig.config.OneConfigConfig.*; +import static cc.polyfrost.oneconfig.gui.Colors.*; public class ColorPalette { /** * Always returns transparent. */ - public static final ColorPalette TRANSPARENT = new ColorPalette(OneConfigConfig.TRANSPARENT, OneConfigConfig.TRANSPARENT, OneConfigConfig.TRANSPARENT); + public static final ColorPalette TRANSPARENT = new ColorPalette(Colors.TRANSPARENT, Colors.TRANSPARENT, Colors.TRANSPARENT); /** *

Primary Color Scheme

Normal: Primary 600,
Hover: Primary 700,
Clicked: Primary 700 (80%) */ @@ -20,7 +20,7 @@ public class ColorPalette { /** *

Secondary Color Scheme

Normal: Gray 500,
Hover: Gray 400,
Clicked: Gray 400 (80%) */ - public static final ColorPalette SECONDARY = new ColorPalette(OneConfigConfig.GRAY_500, OneConfigConfig.GRAY_400, OneConfigConfig.GRAY_400_80); + public static final ColorPalette SECONDARY = new ColorPalette(Colors.GRAY_500, Colors.GRAY_400, Colors.GRAY_400_80); /** *

Tertiary Color Scheme

Normal: Transparent (Text=White 90%),
Hover: Transparent (Text=White 100%),
Clicked: Transparent (Text=White 80%) *

NOTICE this returns the text colors as it is always transparent.

@@ -33,7 +33,7 @@ public class ColorPalette { /** *

Secondary Destructive Color Scheme

Normal: Gray 500,
Hover: Error 800,
Clicked: Error 800 (80%) */ - public static final ColorPalette SECONDARY_DESTRUCTIVE = new ColorPalette(OneConfigConfig.GRAY_500, ERROR_800, ERROR_800_80); + public static final ColorPalette SECONDARY_DESTRUCTIVE = new ColorPalette(Colors.GRAY_500, ERROR_800, ERROR_800_80); /** *

Tertiary Destructive Color Scheme

Normal: Transparent (Text=White 90%),
Hover: Transparent (Text=Error 300),
Clicked: Transparent (Text=Error 300 80%) *

NOTICE this returns the text colors as it is always transparent.

diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/Command.java b/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/Command.java index deec7f1..41909c0 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/Command.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/Command.java @@ -1,5 +1,6 @@ package cc.polyfrost.oneconfig.utils.commands.annotations; +import cc.polyfrost.oneconfig.internal.command.OneConfigCommand; import cc.polyfrost.oneconfig.utils.commands.CommandManager; import cc.polyfrost.oneconfig.utils.commands.arguments.ArgumentParser; @@ -78,7 +79,7 @@ import java.lang.annotation.Target; * Note: if you're viewing this in IntelliJ or just see the @literal tag everywhere, please ignore that. *

* - * @see cc.polyfrost.oneconfig.command.OneConfigCommand + * @see OneConfigCommand * @see Main * @see CommandManager */ diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/gui/GuiUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/gui/GuiUtils.java new file mode 100644 index 0000000..973e003 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/utils/gui/GuiUtils.java @@ -0,0 +1,63 @@ +package cc.polyfrost.oneconfig.utils.gui; + +import cc.polyfrost.oneconfig.events.EventManager; +import cc.polyfrost.oneconfig.events.event.RenderEvent; +import cc.polyfrost.oneconfig.events.event.Stage; +import cc.polyfrost.oneconfig.utils.TickDelay; +import gg.essential.universal.UMinecraft; +import gg.essential.universal.UScreen; +import me.kbrewster.eventbus.Subscribe; +import net.minecraft.client.gui.GuiScreen; + +/** + * A class containing utility methods for working with GuiScreens. + */ +public final class GuiUtils { + private static long time = -1L; + private static long deltaTime = 17L; + + static { + EventManager.INSTANCE.register(new GuiUtils()); + } + + /** + * Displays a screen after a tick, preventing mouse sync issues. + * + * @param screen the screen to display. + */ + public static void displayScreen(GuiScreen screen) { + new TickDelay(() -> UScreen.displayScreen(screen), 1); + } + + /** + * Close the current open GUI screen. + */ + public static void closeScreen() { + UScreen.displayScreen(null); + } + + /** + * Gets the delta time (in milliseconds) between frames. + *

+ * Not to be confused with Minecraft deltaTicks / renderPartialTicks, which can be gotten via + * {@link cc.polyfrost.oneconfig.events.event.TimerUpdateEvent} + *

+ * + * @return the delta time. + */ + public static float getDeltaTime() { + return deltaTime; + } + + @Subscribe + private void onRenderEvent(RenderEvent event) { + if (event.stage == Stage.START) { + if (time == -1) time = UMinecraft.getTime(); + else { + long currentTime = UMinecraft.getTime(); + deltaTime = currentTime - time; + time = currentTime; + } + } + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/gui/OneUIScreen.java b/src/main/java/cc/polyfrost/oneconfig/utils/gui/OneUIScreen.java new file mode 100644 index 0000000..c06f6f3 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/utils/gui/OneUIScreen.java @@ -0,0 +1,147 @@ +package cc.polyfrost.oneconfig.utils.gui; + +import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.utils.InputUtils; +import gg.essential.universal.UMatrixStack; +import gg.essential.universal.UScreen; +import net.minecraft.client.gui.GuiScreen; +import org.jetbrains.annotations.NotNull; +import org.lwjgl.input.Mouse; + +/** + *

OneUIScreen

+ * OneUIScreen is a GUI that can be used to render things on the client's screen. + * It contains many handy methods for rendering, including {@link #draw(long, float)} for drawing using OneConfig's {@link RenderManager}. + *

It also contains methods for mouse input. (see {@link InputUtils} for more utils). + *

+ * Use {@link GuiUtils#displayScreen(GuiScreen)} to display a screen; and {@link GuiUtils#closeScreen()} to close it. + */ +public abstract class OneUIScreen extends UScreen { + private boolean mouseDown; + private boolean blockClicks; + + /** + * Create a new OneUIScreen. + * + * @param restoreGuiOnClose use this to declare weather or not to open the Gui that was open before it when this screen is closed. + */ + public OneUIScreen(boolean restoreGuiOnClose) { + super(restoreGuiOnClose); + } + + /** + * Create a new OneUIScreen. + */ + public OneUIScreen() { + super(false); + } + + @Override + public void onDrawScreen(@NotNull UMatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { + super.onDrawScreen(matrixStack, mouseX, mouseY, partialTicks); + RenderManager.setupAndDraw(ignoreMinecraftScale(), vg -> draw(vg, partialTicks)); + mouseDown = Mouse.isButtonDown(0); + } + + /** + * This method is called when the screen is first opened. You can use it to set variables, initialize things, etc. + */ + public abstract void onScreenOpen(); + + /** + * Use this method to draw things on the screen. It is called every render tick, and has a handy vg (NanoVG context) that can be used with the {@link RenderManager} to draw things. + *

+ * For example: {@link RenderManager#drawRoundedRect(long, float, float, float, float, int, float)} + * + * @param vg the NanoVG context you can use to render things with + * @param partialTicks the time between ticks (You can use this as a deltaTime equivalent) + */ + public abstract void draw(long vg, float partialTicks); + + /** + * This method is called when the screen is closed. You can use it to clean up things, etc. + */ + @Override + public abstract void onScreenClose(); + + @Override + public void initScreen(int width, int height) { + onScreenOpen(); + } + + /** + * Use this method to set weather or not to use the Minecraft scale on the GUI. Its default is true, and that is recommended for the NanoVG rendering. + */ + public boolean ignoreMinecraftScale() { + return true; + } + + /** + * Use this method to declare weather or not this Screen pauses the game when it is open. (Single-player only) Its default is false. + */ + public boolean doesScreenPauseGame() { + return false; + } + + @Override + public boolean doesGuiPauseGame() { + return doesScreenPauseGame(); + } + + + /** + * Get the current x position of the mouse. + */ + public int getMouseX() { + return InputUtils.mouseX(); + } + + /** + * Get the current y position of the mouse. + */ + public int getMouseY() { + return InputUtils.mouseY(); + } + + @Override + public void onMouseClicked(double mouseX, double mouseY, int mouseButton) { + super.onMouseClicked(mouseX, mouseY, mouseButton); + } + + /** + * Retrieve the click status of the mouse. This method uses a boolean to store the status of the mouse, so it will only return true once per click. (very useful) + * + * @param ignoreBlockClicks whether to ignore the current click blocker. + */ + public boolean isClicked(boolean ignoreBlockClicks) { + return mouseDown && !Mouse.isButtonDown(0) && (!blockClicks || ignoreBlockClicks); + } + + /** + * Retrieve the click status of the mouse. This method uses a boolean to store the status of the mouse, so it will only return true once per click. (very useful) + */ + public boolean isClicked() { + return isClicked(false); + } + + /** + * Retrieve weather or not the mouse is currently down. Will constantly return true if its clicked. See {@link #isClicked()} for a method that only executes once per tick. + */ + public boolean isMouseDown() { + return Mouse.isButtonDown(0); + } + + /** + * Click blocking can be useful when you are drawing buttons for example over the top of other elements, so a click blocker can be used to ensure that the mouse doesn't click through things. + */ + public void shouldBlockClicks(boolean state) { + blockClicks = state; + } + + /** + * Click blocking can be useful when you are drawing buttons for example over the top of other elements, so a click blocker can be used to ensure that the mouse doesn't click through things. + */ + public boolean isBlockingClicks() { + return blockClicks; + } +} -- cgit