diff options
| author | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-05-03 18:25:32 +0200 |
|---|---|---|
| committer | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-05-03 18:25:32 +0200 |
| commit | a0ff501947a84b268e099524a06b56a6b900dad2 (patch) | |
| tree | db27ca1b28dbc7e57b8c99f54c80732d3042e856 /src/main/java/cc/polyfrost/oneconfig | |
| parent | b798930b21b89b81be05a31281f768667a6dd7f3 (diff) | |
| download | OneConfig-a0ff501947a84b268e099524a06b56a6b900dad2.tar.gz OneConfig-a0ff501947a84b268e099524a06b56a6b900dad2.tar.bz2 OneConfig-a0ff501947a84b268e099524a06b56a6b900dad2.zip | |
move to cc.polyfrost
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig')
66 files changed, 5309 insertions, 0 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/OneConfig.java b/src/main/java/cc/polyfrost/oneconfig/OneConfig.java new file mode 100644 index 0000000..2dcb8fe --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/OneConfig.java @@ -0,0 +1,81 @@ +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.lwjgl.BlurHandler; +import cc.polyfrost.oneconfig.lwjgl.font.Fonts; +import cc.polyfrost.oneconfig.hud.HudCore; +import cc.polyfrost.oneconfig.lwjgl.RenderManager; +import cc.polyfrost.oneconfig.lwjgl.image.Images; +import cc.polyfrost.oneconfig.test.TestConfig; +import net.minecraft.client.Minecraft; +import net.minecraftforge.client.ClientCommandHandler; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.common.Loader; +import net.minecraftforge.fml.common.ModContainer; +import net.minecraftforge.fml.common.ModMetadata; +import net.minecraftforge.fml.common.event.FMLInitializationEvent; +import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; + +import java.io.File; +import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.List; + +@net.minecraftforge.fml.common.Mod(modid = "@ID@", name = "@NAME@", version = "@VER@") +public class OneConfig { + private static final Minecraft mc = Minecraft.getMinecraft(); + public static File jarFile; + public static File oneConfigDir = new File(mc.mcDataDir, "OneConfig/"); + public static File themesDir = new File(oneConfigDir, "themes/"); + public static OneConfigConfig config; + public static TestConfig testConfig; + public static List<Mod> loadedMods = new ArrayList<>(); + public static List<ModMetadata> loadedOtherMods = new ArrayList<>(); + + @net.minecraftforge.fml.common.Mod.EventHandler + public void onPreFMLInit(FMLPreInitializationEvent event) { + jarFile = event.getSourceFile(); + oneConfigDir.mkdirs(); + themesDir.mkdirs(); + config = new OneConfigConfig(); + } + + @net.minecraftforge.fml.common.Mod.EventHandler + public void onFMLInitialization(FMLInitializationEvent event) { + BlurHandler.INSTANCE.load(); + testConfig = new TestConfig(); + ClientCommandHandler.instance.registerCommand(new OneConfigCommand()); + MinecraftForge.EVENT_BUS.register(this); + MinecraftForge.EVENT_BUS.register(new HudCore()); + RenderManager.setupAndDraw((vg) -> { + RenderManager.drawRoundedRect(vg, -100, -100, 50, 50, -1, 12f); + RenderManager.drawString(vg, "OneConfig loading...", -100, -100, -1, 12f, Fonts.INTER_MEDIUM); + RenderManager.drawImage(vg, Images.LOGO, -100, -100, 50, 50); + }); + } + + @net.minecraftforge.fml.common.Mod.EventHandler + public void onPostFMLInit(FMLPostInitializationEvent event) { + reloadModsList(); + } + + public static void reloadModsList() { + loadedMods.addAll(ConfigCore.oneConfigMods); + LinkedHashSet<Mod> modData = new LinkedHashSet<>(ConfigCore.oneConfigMods); + for (ModContainer mod : Loader.instance().getActiveModList()) { + ModMetadata metadata = mod.getMetadata(); + loadedOtherMods.add(metadata); + String author = metadata.authorList.size() > 0 ? metadata.authorList.get(0) : ""; + Mod newMod = new Mod(metadata.name, ModType.OTHER, author, metadata.version); + if (newMod.name.equals("Minecraft Coder Pack") || newMod.name.equals("Forge Mod Loader") || newMod.name.equals("Minecraft Forge")) { // TODO add oneconfig + continue; + } + if (modData.add(newMod)) loadedMods.add(newMod); // anti duplicate fix + } + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/command/OneConfigCommand.java b/src/main/java/cc/polyfrost/oneconfig/command/OneConfigCommand.java new file mode 100644 index 0000000..35d099c --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/command/OneConfigCommand.java @@ -0,0 +1,55 @@ +package cc.polyfrost.oneconfig.command; + +import cc.polyfrost.oneconfig.gui.OneConfigGui; +import cc.polyfrost.oneconfig.gui.HudGui; +import cc.polyfrost.oneconfig.test.TestNanoVGGui; +import cc.polyfrost.oneconfig.utils.TickDelay; +import net.minecraft.client.Minecraft; +import net.minecraft.command.CommandBase; +import net.minecraft.command.ICommandSender; + +import java.util.ArrayList; +import java.util.List; + +public class OneConfigCommand extends CommandBase { + + private static final Minecraft mc = Minecraft.getMinecraft(); + + @Override + public String getCommandName() { + return "oneconfig"; + } + + @Override + public String getCommandUsage(ICommandSender sender) { + return "oneconfig <>"; + } + + @Override + public List<String> getCommandAliases() { + return new ArrayList<String>() {{ + add("oneconfig"); + add("ocfg"); + }}; + } + + @Override + public void processCommand(ICommandSender sender, String[] args) { + if (args.length == 0) new TickDelay(() -> mc.displayGuiScreen(new OneConfigGui()), 1); + else { + switch (args[0]) { + case "hud": + new TickDelay(() -> mc.displayGuiScreen(new HudGui()), 1); + break; + case "lwjgl": + new TickDelay(() -> mc.displayGuiScreen(new TestNanoVGGui()), 1); + break; + } + } + } + + @Override + public int getRequiredPermissionLevel() { + return -1; + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java b/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java new file mode 100644 index 0000000..73f5821 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java @@ -0,0 +1,81 @@ +package cc.polyfrost.oneconfig.config; + +import cc.polyfrost.oneconfig.config.interfaces.Config; +import com.google.gson.JsonParser; +import cc.polyfrost.oneconfig.config.data.Mod; + +import java.awt.*; +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; + +public class OneConfigConfig extends Config { + + public static String currentProfile = "Default Profile"; + + // TODO i dont know how this works so this is just gonna be here for now + public static final int TRANSPARENT = new Color(0, 0, 0, 0).getRGB(); // Transparent // button sidebar normal + + 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_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_200 = new Color(100, 107, 125, 255).getRGB(); // Gray 200 + public static final int GRAY_400_80 = new Color(55, 59, 69, 204).getRGB(); // Gray 400 80% // button gray pressed + public static final int BLUE_800 = new Color(13, 51, 128, 255).getRGB(); // Blue 800 + public static final int BLUE_700 = new Color(18, 71, 178, 255).getRGB(); // Blue 700 + public static final int BLUE_700_80 = new Color(18, 71, 178, 204).getRGB(); // Blue 700 80% + public static final int BLUE_600 = new Color(20, 82, 204, 255).getRGB(); // Blue 600 // button blue normal + public static final int BLUE_600_80 = new Color(20, 82, 204, 204).getRGB(); // Blue 600 80% // button blue click + public static final int BLUE_500 = new Color(25, 103, 255, 255).getRGB(); // Blue 500 // button blue hover + public static final int BLUE_400 = new Color(48, 129, 242, 255).getRGB(); + public static final int BLUE_400_80 = new Color(48, 129, 242, 204).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 ERROR_700 = new Color(180, 24, 24, 255).getRGB(); // Red 700 + + public static boolean ROUNDED_CORNERS = true; + public static float CORNER_RADIUS_WIN = 20f; + public static float CORNER_RADIUS = 12f; + + + 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.getClass())); + } 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.getClass()); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/config/annotations/ConfigPage.java b/src/main/java/cc/polyfrost/oneconfig/config/annotations/ConfigPage.java new file mode 100644 index 0000000..f9d7c19 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/config/annotations/ConfigPage.java @@ -0,0 +1,32 @@ +package cc.polyfrost.oneconfig.config.annotations; + +import cc.polyfrost.oneconfig.config.data.PageLocation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface ConfigPage { + /** + * The name of the page that will be displayed to the user + */ + String name(); + + /** + * If the page button is at the top or bottem of the page + */ + PageLocation location(); + + /** + * The description of the page that will be displayed to the user + */ + String description() default ""; + + /** + * The category of the page + */ + String category() default "General"; +} diff --git a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Option.java b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Option.java new file mode 100644 index 0000000..d5e9fc7 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Option.java @@ -0,0 +1,85 @@ +package cc.polyfrost.oneconfig.config.annotations; + +import cc.polyfrost.oneconfig.config.data.InfoType; +import cc.polyfrost.oneconfig.config.data.OptionType; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface Option { + /** + * The name of the option that will be displayed to the user + */ + String name(); + + /** + * The type of the option + */ + OptionType type(); + + /** + * The category of the component + */ + String category() default "General"; + + /** + * The subcategory of the component (displayed as header) + */ + String subcategory(); + + /** + * The width of the option (1 = half width, 2 = full width) + */ + int size() default 1; + + /** + * A String array of all the possible values for the UniSelector, dropdownList, and ComboBox. + * Also used in the DualOption slider, index 0 is the left, index 1 is the right; for example: + * {"Option 1", "Option 2"} + */ + String[] options() default {}; + + /** + * The places you want dividers to be in a dropdown + */ + int[] dividers() default {}; + + /** + * The placeholder in the text field + */ + String placeholder() default ""; + + /** + * If the text field is secure or not + */ + boolean secure() default false; + + /** + * If the text field is multi line or not + */ + boolean multiLine() default false; + + /** + * Minimum value of slider + */ + float min() default 0; + + /** + * The maximum value of the slider + */ + float max() default 0; + + /** + * Steps of slider (0 for no steps) + */ + int step() default 0; + + /** + * Option for info option type + */ + InfoType infoType() default InfoType.INFO; +} diff --git a/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigCore.java b/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigCore.java new file mode 100644 index 0000000..a000f7c --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigCore.java @@ -0,0 +1,25 @@ +package cc.polyfrost.oneconfig.config.core; + +import cc.polyfrost.oneconfig.config.data.Mod; +import cc.polyfrost.oneconfig.hud.HudCore; + +import java.util.ArrayList; + +public class ConfigCore { + public static ArrayList<Mod> oneConfigMods = new ArrayList<>(); + + public static void saveAll() { + for (Mod modData : oneConfigMods) { + modData.config.save(); + } + } + + public static void reInitAll() { + ArrayList<Mod> data = new ArrayList<>(oneConfigMods); + oneConfigMods.clear(); + HudCore.huds.clear(); + for (Mod modData : data) { + modData.config.init(modData); + } + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/config/data/InfoType.java b/src/main/java/cc/polyfrost/oneconfig/config/data/InfoType.java new file mode 100644 index 0000000..1c436d6 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/config/data/InfoType.java @@ -0,0 +1,8 @@ |
