diff options
author | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-05-27 21:31:59 +0700 |
---|---|---|
committer | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-05-27 21:31:59 +0700 |
commit | ab2dd02145d5f89455a74605dd953888761d0ddb (patch) | |
tree | d8a9e909798a9bf84e876319c1fdea758d9c5963 /src | |
parent | 2de9cec78992b9589c13ca24b911a1d8ce381c75 (diff) | |
download | OneConfig-ab2dd02145d5f89455a74605dd953888761d0ddb.tar.gz OneConfig-ab2dd02145d5f89455a74605dd953888761d0ddb.tar.bz2 OneConfig-ab2dd02145d5f89455a74605dd953888761d0ddb.zip |
javadoc a lot of stuff + reorganize
Diffstat (limited to 'src')
47 files changed, 555 insertions, 161 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/command/OneConfigCommand.java b/src/main/java/cc/polyfrost/oneconfig/command/OneConfigCommand.java index 4ea67d9..0743b54 100644 --- a/src/main/java/cc/polyfrost/oneconfig/command/OneConfigCommand.java +++ b/src/main/java/cc/polyfrost/oneconfig/command/OneConfigCommand.java @@ -3,8 +3,7 @@ package cc.polyfrost.oneconfig.command; import cc.polyfrost.oneconfig.gui.HudGui; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.test.TestNanoVGGui; -import cc.polyfrost.oneconfig.utils.TickDelay; -import cc.polyfrost.oneconfig.libs.universal.UScreen; +import cc.polyfrost.oneconfig.utils.GuiUtils; import net.minecraft.command.CommandBase; import net.minecraft.command.ICommandSender; @@ -33,14 +32,14 @@ public class OneConfigCommand extends CommandBase { @Override public void processCommand(ICommandSender sender, String[] args) { - if (args.length == 0) new TickDelay(() -> UScreen.displayScreen(OneConfigGui.create()), 1); + if (args.length == 0) GuiUtils.displayScreen(OneConfigGui.create()); else { switch (args[0]) { case "hud": - new TickDelay(() -> UScreen.displayScreen(new HudGui()), 1); + GuiUtils.displayScreen(new HudGui()); break; case "lwjgl": - new TickDelay(() -> UScreen.displayScreen(new TestNanoVGGui()), 1); + GuiUtils.displayScreen(new TestNanoVGGui()); break; case "destroy": OneConfigGui.instanceToRestore = null; diff --git a/src/main/java/cc/polyfrost/oneconfig/config/annotations/VigilanceName.java b/src/main/java/cc/polyfrost/oneconfig/config/annotations/VigilanceName.java index 03e94af..e4b042a 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/annotations/VigilanceName.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/annotations/VigilanceName.java @@ -9,6 +9,8 @@ import java.lang.annotation.Target; @Target(ElementType.FIELD) public @interface VigilanceName { String name(); + String category(); + String subcategory(); } diff --git a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilanceConfig.java b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilanceConfig.java index f31b609..0fbfa62 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilanceConfig.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilanceConfig.java @@ -20,6 +20,10 @@ 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; @@ -133,7 +137,7 @@ public class VigilanceConfig extends Config { PropertyAttributesExt.class.getDeclaredField("i18nName").setAccessible(true); return I18n.format((String) PropertyAttributesExt.class.getDeclaredField("i18nName").get(ext)); } catch (IllegalAccessException | NoSuchFieldException e) { - return ext.getName(); + return ext.getName(); } } @@ -151,7 +155,7 @@ public class VigilanceConfig extends Config { PropertyAttributesExt.class.getDeclaredField("i18nSubcategory").setAccessible(true); return I18n.format((String) PropertyAttributesExt.class.getDeclaredField("i18nSubcategory").get(ext)); } catch (IllegalAccessException | NoSuchFieldException e) { - return ext.getSubcategory(); + return ext.getSubcategory(); } } diff --git a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilantAccessor.java b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilantAccessor.java index 4c79a21..ca2b1da 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilantAccessor.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilantAccessor.java @@ -2,6 +2,10 @@ package cc.polyfrost.oneconfig.config.compatibility; import gg.essential.vigilance.data.PropertyCollector; +/** + * Interface for accessing the {@link PropertyCollector} in a Vigilant config. + * <p>Not recommended for non-internal OneConfig usage, as Systemless will get really angry at us</p> + */ public interface VigilantAccessor { PropertyCollector getPropertyCollector(); } diff --git a/src/main/java/cc/polyfrost/oneconfig/config/core/OneColor.java b/src/main/java/cc/polyfrost/oneconfig/config/core/OneColor.java index 3f6289e..8135ac0 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/core/OneColor.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/core/OneColor.java @@ -5,7 +5,7 @@ import org.jetbrains.annotations.NotNull; import java.awt.*; /** - * OneColor is a class for storing Colors in HSBA format. This format is used to allow the color selectors to work correctly. + * OneColor is a class for storing colors in HSBA format. This format is used to allow the color selectors to work correctly. * <p> * <code> * short[0] = hue (0-360) @@ -71,11 +71,14 @@ public final class OneColor { } // chroma constructors - /** Create a new Chroma OneColor. The speed should be a max of 30s and a min of 1s. */ + + /** + * Create a new Chroma OneColor. The speed should be a max of 30s and a min of 1s. + */ public OneColor(int saturation, int brightness, int alpha, float chromaSpeed) { this(System.currentTimeMillis() % (int) chromaSpeed / chromaSpeed, saturation, brightness, alpha); - if(chromaSpeed < 1) chromaSpeed = 1; - if(chromaSpeed > 30) chromaSpeed = 30; + if (chromaSpeed < 1) chromaSpeed = 1; + if (chromaSpeed > 30) chromaSpeed = 30; this.dataBit = (int) chromaSpeed; } @@ -92,58 +95,79 @@ public final class OneColor { // accessors - /** Get the red value of the color (0-255). */ + + /** + * Get the red value of the color (0-255). + */ public int getRed() { return rgba >> 16 & 255; } - /** Get the green value of the color (0-255). */ + /** + * Get the green value of the color (0-255). + */ public int getGreen() { return rgba >> 8 & 255; } - /** Get the blue value of the color (0-255). */ + /** + * Get the blue value of the color (0-255). + */ public int getBlue() { return rgba & 255; } - /** Get the hue value of the color (0-360). */ + /** + * Get the hue value of the color (0-360). + */ public int getHue() { return hsba[0]; } - /** Get the saturation value of the color (0-100). */ + /** + * Get the saturation value of the color (0-100). + */ public int getSaturation() { return hsba[1]; } - /** Get the brightness value of the color (0-100). */ + /** + * Get the brightness value of the color (0-100). + */ public int getBrightness() { return hsba[2]; } - /** Get the alpha value of the color (0-255). */ + /** + * Get the alpha value of the color (0-255). + */ public int getAlpha() { return hsba[3]; } - /** Get the chroma speed of the color (1s-30s). */ + /** + * Get the chroma speed of the color (1s-30s). + */ public int getDataBit() { return dataBit == -1 ? -1 : dataBit / 1000; } - /** Set the current chroma speed of the color. -1 to disable. */ + /** + * Set the current chroma speed of the color. -1 to disable. + */ public void setChromaSpeed(int speed) { - if(speed == -1) { + if (speed == -1) { this.dataBit = -1; return; } - if(speed < 1) speed = 1; - if(speed > 30) speed = 30; + if (speed < 1) speed = 1; + if (speed > 30) speed = 30; this.dataBit = speed * 1000; } - /** Set the HSBA values of the color. */ + /** + * Set the HSBA values of the color. + */ public void setHSBA(int hue, int saturation, int brightness, int alpha) { this.hsba[0] = (short) hue; this.hsba[1] = (short) saturation; @@ -217,16 +241,16 @@ public final class OneColor { public void setColorFromHex(String hex) { hex = hex.replace("#", ""); - if(hex.length() > 6) { + if (hex.length() > 6) { hex = hex.substring(0, 6); } - if(hex.length() == 3) { + if (hex.length() == 3) { hex = charsToString(hex.charAt(0), hex.charAt(0), hex.charAt(1), hex.charAt(1), hex.charAt(2), hex.charAt(2)); } - if(hex.length() == 1) { + if (hex.length() == 1) { hex = charsToString(hex.charAt(0), hex.charAt(0), hex.charAt(0), hex.charAt(0), hex.charAt(0), hex.charAt(0)); } - if(hex.length() == 2 && hex.charAt(1) == hex.charAt(0)) { + if (hex.length() == 2 && hex.charAt(1) == hex.charAt(0)) { hex = charsToString(hex.charAt(0), hex.charAt(0), hex.charAt(0), hex.charAt(0), hex.charAt(0), hex.charAt(0)); } StringBuilder hexBuilder = new StringBuilder(hex); @@ -235,9 +259,9 @@ public final class OneColor { } hex = hexBuilder.toString(); //System.out.println(hex); - int r = Integer.valueOf(hex.substring( 0, 2 ), 16); - int g = Integer.valueOf( hex.substring( 2, 4 ), 16); - int b = Integer.valueOf( hex.substring( 4, 6 ), 16); + int r = Integer.valueOf(hex.substring(0, 2), 16); + int g = Integer.valueOf(hex.substring(2, 4), 16); + int b = Integer.valueOf(hex.substring(4, 6), 16); this.rgba = ((getAlpha() & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | ((b & 0xFF)); hsba = RGBAtoHSBA(rgba); } @@ -249,7 +273,7 @@ public final class OneColor { private String charsToString(char... chars) { StringBuilder sb = new StringBuilder(); - for(char c : chars) { + for (char c : chars) { sb.append(c); } return sb.toString(); diff --git a/src/main/java/cc/polyfrost/oneconfig/config/data/OptionCategory.java b/src/main/java/cc/polyfrost/oneconfig/config/data/OptionCategory.java index 363cfda..76b2b34 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/data/OptionCategory.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/data/OptionCategory.java @@ -1,10 +1,6 @@ package cc.polyfrost.oneconfig.config.data; -import cc.polyfrost.oneconfig.config.interfaces.BasicOption; -import cc.polyfrost.oneconfig.gui.elements.config.ConfigPageButton; - import java.util.ArrayList; -import java.util.LinkedHashMap; public class OptionCategory { public final ArrayList<OptionSubcategory> subcategories = new ArrayList<>(); diff --git a/src/main/java/cc/polyfrost/oneconfig/config/data/OptionType.java b/src/main/java/cc/polyfrost/oneconfig/config/data/OptionType.java index 519e890..10c9a6b 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/data/OptionType.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/data/OptionType.java @@ -48,7 +48,7 @@ public enum OptionType { BUTTON, /** * Type: OneKeyBind - */ + */ KEYBIND, /** * Type: ? extends BasicHud diff --git a/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java b/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java index a9d1d1e..f495ecd 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java @@ -4,15 +4,14 @@ 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.migration.Migrator; 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 cc.polyfrost.oneconfig.libs.universal.UScreen; import java.io.*; import java.lang.reflect.Field; @@ -247,7 +246,7 @@ public class Config { */ public void openGui() { if (mod == null) return; - UScreen.displayScreen(new OneConfigGui(new ModConfigPage(mod.defaultPage))); + GuiUtils.displayScreen(new OneConfigGui(new ModConfigPage(mod.defaultPage))); } /** 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 4eafd6d..dfc5e16 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/profiles/Profiles.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/profiles/Profiles.java @@ -1,7 +1,7 @@ package cc.polyfrost.oneconfig.config.profiles; -import cc.polyfrost.oneconfig.config.OneConfigConfig; import cc.polyfrost.oneconfig.OneConfig; +import cc.polyfrost.oneconfig.config.OneConfigConfig; import cc.polyfrost.oneconfig.config.core.ConfigCore; import org.apache.commons.io.FileUtils; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java index 4595725..e94ef44 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java @@ -3,10 +3,10 @@ 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.libs.universal.UKeyboard; import cc.polyfrost.oneconfig.libs.universal.UMatrixStack; import cc.polyfrost.oneconfig.libs.universal.UScreen; +import cc.polyfrost.oneconfig.lwjgl.RenderManager; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java index df35ee0..5194f83 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java @@ -1,19 +1,19 @@ package cc.polyfrost.oneconfig.gui; import cc.polyfrost.oneconfig.config.OneConfigConfig; +import cc.polyfrost.oneconfig.config.core.OneColor; 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.gui.pages.HomePage; import cc.polyfrost.oneconfig.gui.pages.Page; -import cc.polyfrost.oneconfig.config.core.OneColor; +import cc.polyfrost.oneconfig.libs.universal.*; 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.InputUtils; import cc.polyfrost.oneconfig.utils.MathUtils; -import cc.polyfrost.oneconfig.libs.universal.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.lwjgl.input.Mouse; @@ -243,7 +243,7 @@ public class OneConfigGui extends UScreen { } public OneColor getColor() { - if(currentColorSelector == null) return null; + if (currentColorSelector == null) return null; return currentColorSelector.getColor(); } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java index 5729de3..51e5a66 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java @@ -8,13 +8,14 @@ import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.SVGs; import cc.polyfrost.oneconfig.utils.ColorUtils; +import cc.polyfrost.oneconfig.utils.GuiUtils; import cc.polyfrost.oneconfig.utils.MathUtils; -import cc.polyfrost.oneconfig.libs.universal.UScreen; import java.util.ArrayList; import java.util.List; -import static cc.polyfrost.oneconfig.gui.elements.BasicButton.*; +import static cc.polyfrost.oneconfig.gui.elements.BasicButton.ALIGNMENT_LEFT; +import static cc.polyfrost.oneconfig.gui.elements.BasicButton.SIZE_36; public class SideBar { private final List<BasicButton> btnList = new ArrayList<>(); @@ -37,11 +38,11 @@ public class SideBar { btnList.add(new BasicButton(192, SIZE_36, "Packs Library", SVGs.BOX, null, ALIGNMENT_LEFT, ColorUtils.TERTIARY)); btnList.add(new BasicButton(192, SIZE_36, "Packs Browser", SVGs.SEARCH, null, ALIGNMENT_LEFT, ColorUtils.TERTIARY)); btnList.add(new BasicButton(192, SIZE_36, "Close", SVGs.X_CIRCLE, null, ALIGNMENT_LEFT, ColorUtils.SECONDARY_TRANSPARENT)); - btnList.get(12).setClickAction(() -> UScreen.displayScreen(null)); + btnList.get(12).setClickAction(() -> GuiUtils.displayScreen(null)); btnList.add(new BasicButton(192, SIZE_36, "Minimize", SVGs.MINIMISE, null, ALIGNMENT_LEFT, ColorUtils.SECONDARY_TRANSPARENT)); - btnList.get(13).setClickAction(() -> UScreen.displayScreen(null)); + btnList.get(13).setClickAction(() -> GuiUtils.displayScreen(null)); btnList.add(new BasicButton(192, SIZE_36, "Edit HUD", SVGs.HUD, null, ALIGNMENT_LEFT, ColorUtils.SECONDARY_TRANSPARENT)); - btnList.get(14).setClickAction(() -> UScreen.displayScreen(new HudGui())); + btnList.get(14).setClickAction(() -> GuiUtils.displayScreen(new HudGui())); } public void draw(long vg, int x, int y) { 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 579841e..a84c290 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java @@ -89,7 +89,7 @@ public class BasicButton extends BasicElement { contentWidth += RenderManager.getTextWidth(vg, text, fontSize, Fonts.MEDIUM); } if (alignment == ALIGNMENT_CENTER) { - if(icon1 != null && icon2 == null && text == null) { + if (icon1 != null && icon2 == null && text == null) { RenderManager.drawSvg(vg, icon1, middle - iconSize / 2f, middleYIcon, iconSize, iconSize); this.update(x, y); return; 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 f6c9e35..8b86827 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java @@ -1,6 +1,5 @@ package cc.polyfrost.oneconfig.gui.elements; -import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.utils.ColorUtils; import cc.polyfrost.oneconfig.utils.InputUtils; 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 4e04f5c..c734ccb 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java @@ -11,8 +11,8 @@ import cc.polyfrost.oneconfig.lwjgl.image.Images; import cc.polyfrost.oneconfig.lwjgl.image.SVGs; import cc.polyfrost.oneconfig.utils.ColorUtils; import cc.polyfrost.oneconfig.utils.InputUtils; -import cc.polyfrost.oneconfig.utils.NetworkUtils; import cc.polyfrost.oneconfig.utils.MathUtils; +import cc.polyfrost.oneconfig.utils.NetworkUtils; import org.lwjgl.input.Mouse; import java.awt.*; @@ -23,7 +23,7 @@ import java.util.ArrayList; public class ColorSelector { private int x; private int y; - private OneColor color; + private final OneColor color; private float percentMove = 0f; private int mouseX, mouseY; private final ArrayList<BasicElement> buttons = new ArrayList<>(); @@ -66,7 +66,7 @@ public class ColorSelector { hexInput.setInput(color.getHex()); this.x = mouseX - 208; this.y = Math.max(0, mouseY - 776); - if(color.getDataBit() != -1) mode = 2; + if (color.getDataBit() != -1) mode = 2; if (mode == 0 || mode == 2) { this.mouseX = (int) (color.getSaturation() / 100f * 384 + x + 16); this.mouseY = (int) (Math.abs(color.getBrightness() / 100f - 1f) * 288 + y + 120); @@ -106,7 +106,7 @@ public class ColorSelector { 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.drawString(vg, "Color Selector", x + 16, y + 32, OneConfigConfig.WHITE_90, 18f, Fonts.SEMIBOLD); - if(!closeBtn.isHovered()) RenderManager.setAlpha(vg, 0.8f); + if (!closeBtn.isHovered()) RenderManager.setAlpha(vg, 0.8f); closeBtn.draw(vg, x + 368, y + 16); RenderManager.drawSvg(vg, SVGs.X_CIRCLE, x + 368, y + 16, 32, 32, closeBtn.isHovered() ? OneConfigConfig.ERROR_600 : -1); RenderManager.setAlpha(vg, 1f); @@ -140,10 +140,10 @@ public class ColorSelector { // TODO favorite stuff faveBtn.draw(vg, x + 16, y + 672); recentBtn.draw(vg, x + 16, y + 720); - for(int i = 0; i < 7; i++) { + for (int i = 0; i < 7; i++) { favoriteColors.get(i).draw(vg, x + 104 + i * 44, y + 672); } - for(int i = 0; i < 7; i++) { + for (int i = 0; i < 7; i++) { recentColors.get(i).draw(vg, x + 104 + i * 44, y + 720); } @@ -318,7 +318,7 @@ public class ColorSelector { hueInput.setInput(String.format("%.01f", (float) color.getHue())); hexInput.setInput("#" + color.getHex()); } - if(guideBtn.isClicked()) NetworkUtils.browseLink("https://www.youtube.com/watch?v=dQw4w9WgXcQ"); + if (guideBtn.isClicked()) NetworkUtils.browseLink("https://www.youtube.com/watch?v=dQw4w9WgXcQ"); // draw the color preview @@ -388,7 +388,7 @@ 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, y, 16, 16, OneConfigConfig.BLACK, 8f, 1f); if (color != null) { RenderManager.drawRoundedRect(vg, currentDragPoint + 1.5f, y + 1.5f, 14, 14, color.getRGBMax(true), 7f); } 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 c60286d..cc8c54d 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java @@ -5,16 +5,15 @@ import cc.polyfrost.oneconfig.config.OneConfigConfig; import cc.polyfrost.oneconfig.config.data.Mod; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.gui.pages.ModConfigPage; +import cc.polyfrost.oneconfig.libs.universal.wrappers.UPlayer; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.SVGs; import cc.polyfrost.oneconfig.utils.ColorUtils; import cc.polyfrost.oneconfig.utils.InputUtils; -import cc.polyfrost.oneconfig.libs.universal.wrappers.UPlayer; import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.fml.common.ModMetadata; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.ArrayList; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModUpdateCard.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModUpdateCard.java index 3baf001..55041b9 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModUpdateCard.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModUpdateCard.java @@ -1,6 +1,6 @@ package cc.polyfrost.oneconfig.gui.elements; -public class ModUpdateCard extends BasicElement{ +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/config/ConfigButton.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java index a0ba444..3ad7f51 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 @@ -27,7 +27,7 @@ public class ConfigButton extends BasicOption { @Override public void draw(long vg, int x, int y) { button.disable(!isEnabled()); - if(!isEnabled()) RenderManager.setAlpha(vg, 0.5f); + if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); RenderManager.drawString(vg, name, x, y + 17, OneConfigConfig.WHITE, 14f, Fonts.MEDIUM); button.draw(vg, x + (size == 1 ? 352 : 736), y); RenderManager.setAlpha(vg, 1f); @@ -39,7 +39,8 @@ public class ConfigButton extends BasicOption { } private static Runnable getRunnableFromField(Field field, Object parent) { - Runnable runnable = () -> {}; + Runnable runnable = () -> { + }; try { runnable = (Runnable) field.get(parent); } catch (IllegalAccessException e) { 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 91c3cff..f8c34e1 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 @@ -54,7 +54,8 @@ public class ConfigCheckbox extends BasicOption { RenderManager.drawRoundedRect(vg, x, y + 4, 24, 24, OneConfigConfig.PRIMARY_500, 6f); RenderManager.drawSvg(vg, SVGs.CHECKBOX_TICK, x, y + 4, 24, 24); } - if(percentOn != 0 && hover) RenderManager.drawHollowRoundRect(vg, x - 1, y + 3, 24, 24, OneConfigConfig.PRIMARY_600, 6f, 2f); + if (percentOn != 0 && hover) + RenderManager.drawHollowRoundRect(vg, x - 1, y + 3, 24, 24, OneConfigConfig.PRIMARY_600, 6f, 2f); RenderManager.setAlpha(vg, 1f); } 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 08343a9..f8aa0d6 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 @@ -4,7 +4,6 @@ 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.utils.ColorUtils; import cc.polyfrost.oneconfig.utils.InputUtils; import cc.polyfrost.oneconfig.utils.MathUtils; 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 7810d57..6564e9e 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 @@ -5,15 +5,13 @@ 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.image.Images; -import cc.polyfrost.oneconfig.lwjgl.image.SVGs; import cc.polyfrost.oneconfig.lwjgl.scissor.Scissor; import cc.polyfrost.oneconfig.lwjgl.scissor.ScissorManager; import java.lang.reflect.Field; public class ConfigInfo extends BasicOption { - private InfoType type; + private final InfoType type; public ConfigInfo(Field field, Object parent, String name, int size, InfoType type) { super(field, parent, name, size); 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 905aabf..cb90165 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 @@ -5,10 +5,10 @@ import cc.polyfrost.oneconfig.config.core.OneKeyBind; import cc.polyfrost.oneconfig.config.interfaces.BasicOption; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.gui.elements.BasicButton; +import cc.polyfrost.oneconfig.libs.universal.UKeyboard; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.SVGs; -import cc.polyfrost.oneconfig.libs.universal.UKeyboard; import cc.polyfrost.oneconfig.utils.ColorUtils; import java.lang.reflect.Field; 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 6d93be7..a7dbf62 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 @@ -2,6 +2,7 @@ package cc.polyfrost.oneconfig.gui.elements.text; import cc.polyfrost.oneconfig.config.OneConfigConfig; import cc.polyfrost.oneconfig.gui.elements.BasicElement; +import cc.polyfrost.oneconfig.libs.universal.UKeyboard; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.SVGs; @@ -10,7 +11,6 @@ import cc.polyfrost.oneconfig.lwjgl.scissor.ScissorManager; import cc.polyfrost.oneconfig.utils.InputUtils; import cc.polyfrost.oneconfig.utils.MathUtils; import cc.polyfrost.oneconfig.utils.TextUtils; -import cc.polyfrost.oneconfig.libs.universal.UKeyboard; import org.jetbrains.annotations.NotNull; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; 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 db19226..5892273 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/HomePage.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/HomePage.java @@ -1,10 +1,10 @@ package cc.polyfrost.oneconfig.gui.pages; import cc.polyfrost.oneconfig.config.OneConfigConfig; +import cc.polyfrost.oneconfig.config.core.OneColor; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.gui.elements.BasicButton; import cc.polyfrost.oneconfig.gui.elements.ColorSelector; -import cc.polyfrost.oneconfig.config.core.OneColor; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.SVGs; @@ -55,7 +55,7 @@ public class HomePage extends Page { socialsBtn.draw(vg, x + 432, y + 658); creditsBtn.draw(vg, x + 632, y + 658); guideBtn.draw(vg, x + 832, y + 658); - if(socialsBtn.isClicked()) { + if (socialsBtn.isClicked()) { OneConfigGui.INSTANCE.initColorSelector(new ColorSelector(new OneColor(new Color(255, 0, 255, 127)), InputUtils.mouseX(), InputUtils.mouseY())); } 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 91b8d88..1f17c7d 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java @@ -34,7 +34,7 @@ public class ModsPage extends Page { modCategories.add(new BasicButton(88, 32, "3rd Party", BasicButton.ALIGNMENT_CENTER, ColorUtils.SECONDARY)); modCategories.get(0).setToggled(true); int i = 0; - for(BasicButton button : modCategories) { + for (BasicButton button : modCategories) { button.setToggleable(true); int finalI = i; button.setClickAction(() -> unselect(finalI)); @@ -84,7 +84,7 @@ public class ModsPage extends Page { OneConfigConfig.favoriteMods.clear(); for (ModCard modCard : modCards) { if (modCard.isFavorite()) OneConfigConfig.favoriteMods.add(modCard.getModData().name); - if (modCard.getModData().config != null && modCard.getModData().config.enabled != modCard.isActive()){ + if (modCard.getModData().config != null && modCard.getModData().config.enabled != modCard.isActive()) { modCard.getModData().config.enabled = modCard.isActive(); modCard.getModData().config.save(); } @@ -93,7 +93,7 @@ public class ModsPage extends Page { } private boolean inSelection(ModCard modCard) { - return modCategories.get(0).isToggled() && (OneConfigConfig.allShowShortCut || !modCard.getModData().isShortCut) || (modCategories.get(1).isToggled() && modCard.getModData().modType == ModType.PVP) || (modCategories.get(2).isToggled() && modCard.getModData().modType == ModType.HUD) || (modCategories.get(3).isToggled() && modCard.getModData().modType == ModType.UTIL_QOL) || (modCategories.get(4).isToggled() && modCard.getModData().modType == ModType.HYPIXEL) || (modCategories.get(5).isToggled() && modCard.getModData().modType == ModType.SKYBLOCK) || (modCategories.get(6).isToggled() && modCard.getModData().modType == ModType.THIRD_PARTY); + return modCategories.get(0).isToggled() && (OneConfigConfig.allShowShortCut || !modCard.getModData().isShortCut) || (modCategories.get(1).isToggled() && modCard.getModData().modType == ModType.PVP) || (modCategories.get(2).isToggled() && modCard.getModData().modType == ModType.HUD) || (modCategories.get(3).isToggled() && modCard.getModData().modType == ModType.UTIL_QOL) || (modCategories.get(4).isToggled() && modCard.getModData().modType == ModType.HYPIXEL) || (modCategories.get(5).isToggled() && modCard.getModData().modType == ModType.SKYBLOCK) || (modCategories.get(6).isToggled() && modCard.getModData().modType == ModType.THIRD_PARTY); } @Override diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java index 1fbea21..fdb5292 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java @@ -1,6 +1,5 @@ package cc.polyfrost.oneconfig.gui.pages; -import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.lwjgl.scissor.Scissor; import cc.polyfrost.oneconfig.lwjgl.scissor.ScissorManager; import cc.polyfrost.oneconfig.utils.MathUtils; diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java index c6d58a9..d78fbaf 100644 --- a/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java +++ b/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java @@ -79,6 +79,7 @@ public abstract class BasicHud { /** * Function called when drawing the hud + * * @param x Top left x-coordinate of the hud * @param y Top left y-coordinate of the hud * @param scale Scale of the hud @@ -88,6 +89,7 @@ public abstract class BasicHud { /** * Function called when drawing the example version of the hud. * This is used in for example, the hud editor gui. + * * @param x Top left x-coordinate of the hud * @param y Top left y-coordinate of the hud * @param scale Scale of the hud @@ -126,6 +128,7 @@ public abstract class BasicHud { /** * Draw the background, the hud and all childed huds, used by HudCore + * * @param x X-coordinate * @param y Y-coordinate * @param scale Scale of the hud @@ -142,6 +145,7 @@ public abstract class BasicHud { /** * Draw example version of the background, the hud and all childed huds, used by HudGui + * * @param x X-coordinate * @param y Y-coordinate * @param scale Scale of the hud @@ -158,6 +162,7 @@ public abstract class BasicHud { /** * Draw example version of the background, the hud and all childed huds, used by HudGui + * * @param x X-coordinate * @param y Y-coordinate * @param width Width of the hud @@ -168,10 +173,12 @@ public abstract class BasicHud { RenderManager.setupAndDraw(true, (vg) -> { if (rounded) { RenderManager.drawRoundedRect(vg, x, y, (width + paddingX * scale), (height + paddingY * scale), bgColor.getRGB(), cornerRadius * scale); - if (border) RenderManager.drawHollowRoundRect(vg, x - borderSize * scale, y - borderSize * scale, (width + paddingX * scale) + borderSize * scale, (height + paddingY * scale) + borderSize * scale, borderColor.getRGB(), cornerRadius * scale, borderSize * scale); + if (border) + RenderManager.drawHollowRoundRect(vg, x - borderSize * scale, y - borderSize * scale, (width + paddingX * scale) + borderSize * scale, (height + paddingY * scale) + borderSize * scale, borderColor.getRGB(), cornerRadius * scale, borderSize * scale); } else { RenderManager.drawRect(vg, x, y, (width + paddingX * scale), (height + paddingY * scale), bgColor.getRGB()); - if (border) RenderManager.drawHollowRoundRect(vg, x - borderSize * scale, y - borderSize * scale, (width + paddingX * scale) + borderSize * scale, (height + paddingY * scale) + borderSize * scale, borderColor.getRGB(), 0, borderSize * scale); + if (border) + RenderManager.drawHollowRoundRect(vg, x - borderSize * scale, y - borderSize * scale, (width + paddingX * scale) + borderSize * scale, (height + paddingY * scale) + borderSize * scale, borderColor.getRGB(), 0, borderSize * scale); } }); } diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/HudCore.java b/src/main/java/cc/polyfrost/oneconfig/hud/HudCore.java index 8bf650f..87336e9 100644 --- a/src/main/java/cc/polyfrost/oneconfig/hud/HudCore.java +++ b/src/main/java/cc/polyfrost/oneconfig/hud/HudCore.java @@ -14,7 +14,8 @@ public class HudCore { public void onRender(RenderGameOverlayEvent.Post event) { if (event.type != RenderGameOverlayEvent.ElementType.ALL || editing) return; for (BasicHud hud : huds) { - if(hud.enabled) hud.drawAll(hud.getXScaled(UResolution.getScaledWidth()), hud.getYScaled(UResolution.getScaledHeight()), hud.scale, true); + if (hud.enabled) + hud.drawAll(hud.getXScaled(UResolution.getScaledWidth()), hud.getYScaled(UResolution.getScaledHeight()), hud.scale, true); } } } diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java index 8d68715..f14390e 100644 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java +++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java @@ -3,14 +3,14 @@ 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.libs.universal.UGraphics; +import cc.polyfrost.oneconfig.libs.universal.UMinecraft; +import cc.polyfrost.oneconfig.libs.universal.UResolution; 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.libs.universal.UGraphics; -import cc.polyfrost.oneconfig.libs.universal.UMinecraft; -import cc.polyfrost.oneconfig.libs.universal.UResolution; import cc.polyfrost.oneconfig.utils.InputUtils; import cc.polyfrost.oneconfig.utils.NetworkUtils; import net.minecraft.client.gui.Gui; @@ -24,6 +24,9 @@ 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 RenderManager() { @@ -33,10 +36,22 @@ public final class RenderManager { private static long vg = -1; + /** + * Sets up rendering, calls the consumer with the NanoVG context, and then cleans up. + * + * @see RenderManager#setupAndDraw(boolean, LongConsumer) + * @param consumer The consumer to call. + */ 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); @@ -67,6 +82,16 @@ public final class RenderManager { 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); @@ -75,6 +100,18 @@ public final class RenderManager { } } + /** + * 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); @@ -87,6 +124,7 @@ public final class RenderManager { nvgColor2.free(); } + //todo wtf does this do - wyvest, 2022 public static void drawHSBBox(long vg, float x, float y, float width, float height, int colorTarget) { drawRoundedRect(vg, x, y, width, height, colorTarget, 8f); @@ -111,6 +149,17 @@ public final class RenderManager { nvgColor4.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); @@ -124,6 +173,16 @@ public final class RenderManager { nvgColor2.free(); } + /** + * 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); @@ -132,6 +191,17 @@ public final class RenderManager { 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); @@ -141,6 +211,7 @@ public final class RenderManager { nvgColor.free(); } + //todo wtf does this do - wyvest, 2022 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); @@ -150,6 +221,18 @@ public final class RenderManager { 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); @@ -162,6 +245,14 @@ public final class RenderManager { nvgColor.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); @@ -170,6 +261,18 @@ public final class RenderManager { 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 drawString(long vg, String text, float x, float y, int color, float size, Fonts font) { nvgBeginPath(vg); nvgFontSize(vg, size); @@ -181,6 +284,7 @@ public final class RenderManager { nvgColor.free(); } + //todo wtf does this do - wyvest, 2022 public static void drawString(long vg, String text, float x, float y, int color, float size, int lineHeight, Fonts font) { nvgBeginPath(vg); nvgFontSize(vg, size); @@ -193,16 +297,34 @@ public final class RenderManager { nvgColor.free(); } - /** Draw a formatted URL (a string in blue with an underline) that when clicked, opens the given text. */ + /** + * Draw a formatted URL (a string in blue with an underline) that when clicked, opens the given text. + * + * <p><b>This does NOT scale to Minecraft's GUI scale!</b></p> + * + * @see RenderManager#drawString(long, String, float, float, int, float, Fonts) + * @see InputUtils#isAreaClicked(int, int, int, int) + */ public static void drawURL(long vg, String url, float x, float y, float size, Fonts font) { drawString(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))) { + if (InputUtils.isAreaClicked((int) (x - 2), (int) (y - 1), (int) (length + 4), (int) (size / 2 + 3))) { NetworkUtils.browseLink(url); } } + /** + * 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) { nvgBeginPath(vg); nvgFontSize(vg, size); @@ -214,6 +336,17 @@ public final class RenderManager { nvgColor.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. + * + * @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(); @@ -227,6 +360,16 @@ public final class RenderManager { } } + /** + * 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(); @@ -241,6 +384,16 @@ public final class RenderManager { } } + /** + * 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(); @@ -254,19 +407,41 @@ public final class RenderManager { } } + /** + * 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); } + /** + * 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); } - + /** + * 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, Fonts font) { float[] bounds = new float[4]; nvgFontSize(vg, fontSize); @@ -274,6 +449,16 @@ public final class RenderManager { 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); @@ -285,6 +470,7 @@ public final class RenderManager { nvgColor.free(); } + //todo i know what this does but diamond knows what it does in detail so diamond needs to javadoc this 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 @@ -320,6 +506,14 @@ public final class RenderManager { } } + /** + * 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); @@ -327,7 +521,13 @@ public final class RenderManager { 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); @@ -335,14 +535,36 @@ public final class RenderManager { 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; @@ -362,6 +584,17 @@ public final class RenderManager { } } + /** + * 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; @@ -382,14 +615,25 @@ public final class RenderManager { } } + /** + * 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); } + //todo diamond come here and write javadocs please public static void drawInfo(long vg, InfoType type, float x, float y, float size) { SVGs icon = null; int colorOuter = 0; diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/ImageLoader.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/ImageLoader.java index fb436dd..289ab03 100644 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/ImageLoader.java +++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/ImageLoader.java @@ -13,11 +13,27 @@ import java.io.InputStreamReader; import java.nio.ByteBuffer; import java.util.HashMap; -public class ImageLoader { +/** + * 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<String, Integer> imageHashMap = new HashMap<>(); private final HashMap<String, Integer> 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}; @@ -40,8 +56,16 @@ public class ImageLoader { return true; } - public boolean loadSVG(long vg, String fileName, float SVGWidth, float SVGHeight) { - String name = fileName + "-" + SVGWidth + "-" + SVGHeight; + /** + * 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); @@ -60,7 +84,7 @@ public class ImageLoader { int w = (int) svg.width(); int h = (int) svg.height(); - float scale = Math.max(SVGWidth / w, SVGHeight / h); + float scale = Math.max(width / w, height / h); w = (int) (w * scale); h = (int) (h * scale); @@ -81,34 +105,80 @@ public class ImageLoader { return true; } + /** + * Get a loaded image from the cache. + * <p><b>Requires the image to have been loaded first.</b></p> + * + * @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<String, Integer> temp = new HashMap<>(imageHashMap); for (String image : temp.keySet()) { NanoVG.nvgDeleteImage(vg, imageHashMap.get(image)); imageHashMap.remove(image); } - } + } - public int getSVG( String fileName, float width, float height) { + /** + * Get a loaded SVG from the cache. + * <p><b>Requires the SVG to have been loaded first.</b></p> + * + * @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<String, Integer> temp = new HashMap<>(svgHashMap); for (String image : temp.keySet()) { diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/Images.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/Images.java index c42e581..af62b00 100644 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/Images.java +++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/Images.java @@ -1,5 +1,11 @@ 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/colorui/huegradient.png"), COLOR_WHEEL("/assets/oneconfig/colorui/colorwheel.png"), diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/SVGs.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/SVGs.java index 1b8744f..76c93a4 100644 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/SVGs.java +++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/SVGs.java @@ -1,5 +1,11 @@ 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 { ALIGN_H_CENTER("/assets/oneconfig/icons/AlignHCenter.svg"), ALIGN_H_LEFT("/assets/oneconfig/icons/AlignHLeft.svg"), diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/scissor/Scissor.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/scissor/Scissor.java index 9523865..089268f 100644 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/scissor/Scissor.java +++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/scissor/Scissor.java @@ -1,5 +1,10 @@ package cc.polyfrost.oneconfig.lwjgl.scissor; +/** + * A class that represents a scissor rectangle. + * + * @see ScissorManager + */ public class Scissor { public float x; public float y; diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/scissor/ScissorManager.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/scissor/ScissorManager.java index 1697b7e..05747df 100644 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/scissor/ScissorManager.java +++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/scissor/ScissorManager.java @@ -4,9 +4,21 @@ 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<Scissor> 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; @@ -15,6 +27,11 @@ public class ScissorManager { 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); @@ -22,6 +39,10 @@ public class ScissorManager { } } + /** + * Clear all scissor rectangles. + * @param vg The NanoVG context. + */ public static void clearScissors(long vg) { scissors.clear(); NanoVG.nvgResetScissor(vg); diff --git a/src/main/java/cc/polyfrost/oneconfig/plugin/OneConfigMixinPlugin.java b/src/main/java/cc/polyfrost/oneconfig/plugin/OneConfigMixinPlugin.java index 9ceacde..951e942 100644 --- a/src/main/java/cc/polyfrost/oneconfig/plugin/OneConfigMixinPlugin.java +++ b/src/main/java/cc/polyfrost/oneconfig/plugin/OneConfigMixinPlugin.java @@ -9,6 +9,7 @@ import java.util.Set; public class OneConfigMixinPlugin implements IMixinConfigPlugin { public static boolean isVigilance = false; + @Override public void onLoad(String mixinPackage) { try { diff --git a/src/main/java/cc/polyfrost/oneconfig/plugin/asm/ITransformer.java b/src/main/java/cc/polyfrost/oneconfig/plugin/asm/ITransformer.java index f1e12bf..f14877f 100644 --- a/src/main/java/cc/polyfrost/oneconfig/plugin/asm/ITransformer.java +++ b/src/main/java/cc/polyfrost/oneconfig/plugin/asm/ITransformer.java @@ -4,5 +4,6 @@ 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/test/TestConfig.java b/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java index cecbef8..3e40cdc 100644 --- a/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java +++ b/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java @@ -2,10 +2,10 @@ package cc.polyfrost.oneconfig.test; import cc.polyfrost.oneconfig.config.annotations.ConfigPage; 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.core.OneColor; import cc.polyfrost.oneconfig.config.migration.VigilanceMigrator; import cc.polyfrost.oneconfig.lwjgl.image.SVGs; import net.minecraftforge.fml.common.FMLCommonHandler; diff --git a/src/main/java/cc/polyfrost/oneconfig/test/TestNanoVGGui.java b/src/main/java/cc/polyfrost/oneconfig/test/TestNanoVGGui.java index f29fea4..b309429 100644 --- a/src/main/java/cc/polyfrost/oneconfig/test/TestNanoVGGui.java +++ b/src/main/java/cc/polyfrost/oneconfig/test/TestNanoVGGui.java @@ -1,9 +1,9 @@ package cc.polyfrost.oneconfig.test; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; -import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.libs.universal.UMatrixStack; import cc.polyfrost.oneconfig.libs.universal.UScreen; +import cc.polyfrost.oneconfig.lwjgl.RenderManager; +import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import org.jetbrains.annotations.NotNull; import java.awt.*; diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/ColorUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/ColorUtils.java index ee9fe3e..73fd629 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/ColorUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/ColorUtils.java @@ -7,30 +7,46 @@ import java.awt.*; /** * A class to help with color manipulation. */ -public class ColorUtils { - /** Always returns transparent. */ +public final class ColorUtils { + /** + * Always returns transparent. + */ public static final int TRANSPARENT = -10; - /** <h1>Primary Color Scheme</h1> Normal: Primary 600,<br> Hover: Primary 700,<br> Clicked: Primary 700 (80%) */ + /** + * <h1>Primary Color Scheme</h1> Normal: Primary 600,<br> Hover: Primary 700,<br> Clicked: Primary 700 (80%) + */ public static final int PRIMARY = 1; - /** <h1>Secondary Color Scheme</h1> Normal: Gray 500,<br> Hover: Gray 400,<br> Clicked: Gray 400 (80%) */ + /** + * <h1>Secondary Color Scheme</h1> Normal: Gray 500,<br> Hover: Gray 400,<br> Clicked: Gray 400 (80%) + */ public static final int SECONDARY = 2; - /** <h1>Secondary (Transparent) Color Scheme</h1> Normal: Transparent,<br> Hover: Gray rgba(229, 229, 229, 77),<br> Clicked: Gray rgba(229, 229, 229, 51) */ + /** + * <h1>Secondary (Transparent) Color Scheme</h1> Normal: Transparent,<br> Hover: Gray rgba(229, 229, 229, 77),<br> Clicked: Gray rgba(229, 229, 229, 51) + */ public static final int SECONDARY_TRANSPARENT = 0; - /** <h1>Tertiary Color Scheme</h1> Normal: Transparent (Text=White 90%),<br> Hover: Transparent (Text=White 100%),<br> Clicked: Transparent (Text=White 80%) - * <h2>NOTICE this returns the text colors as it is always transparent.</h2>*/ + /** + * <h1>Tertiary Color Scheme</h1> Normal: Transparent (Text=White 90%),<br> Hover: Transparent (Text=White 100%),<br> Clicked: Transparent (Text=White 80%) + * <h2>NOTICE this returns the text colors as it is always transparent.</h2> + */ public static final int TERTIARY = 3; - /** <h1>Primary Destructive Color Scheme</h1> Normal: Error 700,<br> Hover: Error 600,<br> Clicked: Error 600 (80%) */ + /** + * <h1>Primary Destructive Color Scheme</h1> Normal: Error 700,<br> Hover: Error 600,<br> Clicked: Error 600 (80%) + */ public static final int PRIMARY_DESTRUCTIVE = -1; - /** <h1>Secondary Destructive Color Scheme</h1> Normal: Gray 500,<br> Hover: Error 800,<br> Clicked: Error 800 (80%) */ + /** + * <h1>Secondary Destructive Color Scheme</h1> Normal: Gray 500,<br> Hover: Error 800,<br> Clicked: Error 800 (80%) + */ public static final int SECONDARY_DESTRUCTIVE = -2; - /** <h1>Tertiary Destructive Color Scheme</h1> Normal: Transparent (Text=White 90%),<br> Hover: Transparent (Text=Error 300),<br> Clicked: Transparent (Text=Error 300 80%) - * <h2>NOTICE this returns the text colors as it is always transparent.</h2>*/ + /** + * <h1>Tertiary Destructive Color Scheme</h1> Normal: Transparent (Text=White 90%),<br> Hover: Transparent (Text=Error 300),<br> Clicked: Transparent (Text=Error 300 80%) + * <h2>NOTICE this returns the text colors as it is always transparent.</h2> + */ public static final int TERTIARY_DESTRUCTIVE = -3; public static int getColor(int currentColor, int colorPalette, boolean hover, boolean click) { float[] color = splitColor(currentColor); - if(colorPalette == TRANSPARENT) { + if (colorPalette == TRANSPARENT) { return OneConfigConfig.TRANSPARENT; } if (click) { @@ -55,10 +71,10 @@ public class ColorUtils { switch (colorPalette) { case SECONDARY_TRANSPARENT: // Formally -2 - return getColorComponents(color, new float[]{0f,0f,0f,0f}, new float[]{0.9f, 0.9f, 0.9f, 0.3f}, hover, 50f); + return getColorComponents(color, new float[]{0f, 0f, 0f, 0f}, new float[]{0.9f, 0.9f, 0.9f, 0.3f}, hover, 50f); case PRIMARY: // Formally 1 return hover ? OneConfigConfig.PRIMARY_700 : OneConfigConfig.PRIMARY_600; - //return getColorComponents(color, splitColor(OneConfigConfig.PRIMARY_600), splitColor(OneConfigConfig.PRIMARY_700), hover, 100f); + //return getColorComponents(color, splitColor(OneConfigConfig.PRIMARY_600), splitColor(OneConfigConfig.PRIMARY_700), hover, 100f); default: case SECONDARY: // Formally 0 return getColorComponents(color, splitColor(OneConfigConfig.GRAY_500), splitColor(OneConfigConfig.GRAY_400), hover, 100f); @@ -100,7 +116,7 @@ public class ColorUtils { return ((int) (currentColor[3] * 255) << 24) | ((int) (currentColor[0] * 255) << 16) | - ((int) (currentColor[1] * 255) << 8) | + ((int) (currentColor[1] * 255) << 8) | ((int) (currentColor[2] * 255)); } @@ -119,6 +135,7 @@ public class ColorUtils { /** * Get the red component of an RGB color. + * * @param color the color. * @return the red component. */ @@ -128,6 +145,7 @@ public class ColorUtils { /** * Get the green component of an RGB color. + * * @param color the color. * @return the green component. */ @@ -137,6 +155,7 @@ public class ColorUtils { /** * Get the blue component of an RGB color. + * * @param color the color. * @return the blue component. */ @@ -146,6 +165,7 @@ public class ColorUtils { /** * Get the alpha component of an ARGB color. + * * @param color the color. * @return the alpha component. */ @@ -155,9 +175,10 @@ public class ColorUtils { /** * Get the RGB color from the given color components. - * @param red the red component. + * + * @param red the red component. * @param green the green component. - * @param blue the blue component. + * @param blue the blue component. * @param alpha the alpha component. * @return the RGB color. */ @@ -167,9 +188,10 @@ public class ColorUtils { /** * Get the RGB color from the given color components. - * @param red the red component. + * + * @param red the red component. * @param green the green component. - * @param blue the blue component. + * @param blue the blue component. * @return the RGB color. */ public static int getColor(int red, int green, int blue) { @@ -178,9 +200,10 @@ public class ColorUtils { /** * Get the RGB color from the given color components. - * @param red the red component. + * + * @param red the red component. * @param green the green component. - * @param blue the blue component. + * @param blue the blue component. * @param alpha the alpha component. * @return the RGB color. */ @@ -190,8 +213,9 @@ public class ColorUtils { /** * Return the color with the given red component. + * * @param color the color. - * @param red the red component. + * @param red the red component. * @return the color with the given red component. */ public static int setRed(int color, int red) { @@ -200,6 +224,7 @@ public class ColorUtils { /** * Return the color with the given green component. + * * @param color the color. * @param green the green component. * @return the color with the given green component. @@ -210,8 +235,9 @@ public class ColorUtils { /** * Return the color with the given blue component. + * * @param color the color. - * @param blue the blue component. + * @param blue the blue component. * @return the color with the given blue component. */ public static int setBlue(int color, int blue) { @@ -220,6 +246,7 @@ public class ColorUtils { /** * Return the color with the given alpha component. + * * @param color the color. * @param alpha the alpha component. * @return the color with the given alpha component. diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/GuiUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/GuiUtils.java index 53f8d54..3c710c3 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/GuiUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/GuiUtils.java @@ -6,10 +6,11 @@ import net.minecraft.client.gui.GuiScreen; /** * A class containing utility methods for working with GuiScreens. */ -public class GuiUtils { +public final class GuiUtils { /** * Displays a screen after a tick, preventing mouse sync issues. + * * @param screen the screen to display. */ public static void displayScreen(GuiScreen screen) { diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/IOUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/IOUtils.java index 7263a19..64cabfd 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/IOUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/IOUtils.java @@ -12,9 +12,6 @@ import java.nio.file.Files; public final class IOUtils { - private IOUtils() { - } - /** * Taken from legui under MIT License * <a href="https://github.com/SpinyOwl/legui/blob/develop/LICENSE">https://github.com/SpinyOwl/legui/blob/develop/LICENSE</a> diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java index 922010d..86e6c86 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java @@ -4,7 +4,14 @@ import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.libs.universal.UResolution; import org.lwjgl.input.Mouse; -public class InputUtils { +/** + * Various utility methods for input. + * <p> + * All values returned from this class are not scaled to Minecraft's GUI scale. + * For scaled values, see {@link cc.polyfrost.oneconfig.libs.universal.UMouse}. + * </p> + */ +public final class InputUtils { private static boolean blockClicks = false; /** diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/JsonUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/JsonUtils.java index f450d3b..4ea9ce2 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/JsonUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/JsonUtils.java @@ -3,12 +3,8 @@ package cc.polyfrost.oneconfig.utils; import com.google.gson.JsonElement; import com.google.gson.JsonParser; -public class JsonUtils { - private static final JsonParser PARSER = new JsonParser(); - - public static JsonParser getParser() { - return PARSER; - } +public final class JsonUtils { + public static final JsonParser PARSER = new JsonParser(); public static JsonElement parseString(String string, boolean catchExceptions) { try { diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java index fcfca02..19d399f 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java @@ -2,7 +2,7 @@ package cc.polyfrost.oneconfig.utils; import cc.polyfrost.oneconfig.gui.OneConfigGui; -public class MathUtils { +public final class MathUtils { public static float clamp(float number) { return number < 0f ? 0f : Math.min(number, 1f); } @@ -36,10 +36,10 @@ public class MathUtils { /** * taken from <a href="https://github.com/jesusgollonet/processing-penner-easing">https://github.com/jesusgollonet/processing-penner-easing</a> */ - public static float easeInOutQuad(float t,float b , float c, float d) { + public static float easeInOutQuad(float t, float b, float c, float d) { c *= OneConfigGui.INSTANCE == null ? 16 : OneConfigGui.INSTANCE.getDeltaTime(); - if ((t/=d/2) < 1) return c/2*t*t + b; - return -c/2 * ((--t)*(t-2) - 1) + b; + if ((t /= d / 2) < 1) return c / 2 * t * t + b; + return -c / 2 * ((--t) * (t - 2) - 1) + b; } public static float map(float value, float start1, float stop1, float start2, float stop2) { diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/NetworkUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/NetworkUtils.java index 3192a2e..34d4382 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/NetworkUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/NetworkUtils.java @@ -1,9 +1,9 @@ package cc.polyfrost.oneconfig.utils; +import cc.polyfrost.oneconfig.libs.universal.UDesktop; import com.google.gson.JsonElement; import org.apache.commons.io.IOUtils; -import java.awt.*; import java.io.*; import java.net.HttpURLConnection; import java.net.URI; @@ -11,7 +11,7 @@ import java.net.URL; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; -public class NetworkUtils { +public final class NetworkUtils { private static InputStream setupConnection(String url, String userAgent, int timeout, boolean useCaches) throws IOException { HttpURLConnection connection = ((HttpURLConnection) new URL(url).openConnection()); connection.setRequestMethod("GET"); @@ -87,22 +87,6 @@ public class NetworkUtils { } public static void browseLink(String uri) { - try { - browseLink(new URI(uri)); - } catch (Exception e) { - e.printStackTrace(); - System.err.println("Invalid URI: " + uri); - } - } - - public static void browseLink(URI uri) { - if(Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { - try { - Desktop.getDesktop().browse(uri); - } catch (IOException e) { - e.printStackTrace(); - System.err.println("Failed to open URL in browser: " + uri); - } - } + UDesktop.browse(URI.create(uri)); } } diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/TextUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/TextUtils.java index 22baee0..252a588 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/TextUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/TextUtils.java @@ -5,8 +5,7 @@ import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import java.util.ArrayList; -public class TextUtils { - +public final class TextUtils { public static ArrayList<String> wrapText(long vg, String text, float maxWidth, float fontSize, Fonts font) { ArrayList<String> wrappedText = new ArrayList<>(); text += " "; diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/TickDelay.java b/src/main/java/cc/polyfrost/oneconfig/utils/TickDelay.java index f467976..08f5fce 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/TickDelay.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/TickDelay.java @@ -19,7 +19,7 @@ public class TickDelay { if (event.phase == TickEvent.Phase.START) { // Delay expired if (delay < 1) { - run(); + function.run(); destroy(); } delay--; @@ -33,8 +33,4 @@ public class TickDelay { private void register() { MinecraftForge.EVENT_BUS.register(this); } - - private void run() { - function.run(); - } } |