diff options
Diffstat (limited to 'src/main')
14 files changed, 49 insertions, 61 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/Config.java b/src/main/java/cc/polyfrost/oneconfig/config/Config.java index 7ecd4d0..c2661fa 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/Config.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/Config.java @@ -21,8 +21,6 @@ import cc.polyfrost.oneconfig.internal.config.annotations.Option; import cc.polyfrost.oneconfig.internal.config.core.ConfigCore; import cc.polyfrost.oneconfig.internal.config.core.KeyBindHandler; import cc.polyfrost.oneconfig.utils.JsonUtils; -import cc.polyfrost.oneconfig.utils.Multithreading; -import cc.polyfrost.oneconfig.utils.TickDelay; import cc.polyfrost.oneconfig.utils.gui.GuiUtils; import com.google.gson.*; @@ -49,22 +47,13 @@ public class Config { /** * @param modData information about the mod * @param configFile file where config is stored - * @param initialize whether to initialize the config. - */ - public Config(Mod modData, String configFile, boolean initialize) { - this.configFile = configFile; - Multithreading.runAsync(() -> init(modData)); // wait a bit to give everything time to initialize - } - - /** - * @param modData information about the mod - * @param configFile file where config is stored */ public Config(Mod modData, String configFile) { - this(modData, configFile, true); + this.configFile = configFile; + this.mod = modData; } - public void init(Mod mod) { + public void initialize() { boolean migrate = false; if (Profiles.getProfileFile(configFile).exists()) load(); else if (!hasBeenInitialized && mod.migrator != null) migrate = true; @@ -72,8 +61,7 @@ public class Config { mod.config = this; generateOptionList(this, mod.defaultPage, mod, migrate); if (migrate) save(); - ConfigCore.oneConfigMods.add(mod); - this.mod = mod; + ConfigCore.mods.add(mod); hasBeenInitialized = true; } diff --git a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig.java b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig.java index ad148df..1948e0a 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig.java @@ -4,9 +4,7 @@ import cc.polyfrost.oneconfig.config.core.ConfigUtils; import cc.polyfrost.oneconfig.internal.config.core.ConfigCore; import cc.polyfrost.oneconfig.config.core.OneColor; import cc.polyfrost.oneconfig.config.data.Mod; -import cc.polyfrost.oneconfig.config.elements.OptionCategory; import cc.polyfrost.oneconfig.config.elements.OptionPage; -import cc.polyfrost.oneconfig.config.elements.OptionSubcategory; import cc.polyfrost.oneconfig.config.elements.BasicOption; import cc.polyfrost.oneconfig.config.Config; import cc.polyfrost.oneconfig.gui.elements.config.*; @@ -31,16 +29,15 @@ public class VigilanceConfig extends Config { public VigilanceConfig(Mod modData, String configFile, Vigilant vigilant) { super(modData, configFile); this.vigilant = vigilant; - init(modData); + initialize(); } @Override - public void init(Mod mod) { + public void initialize() { if (vigilant != null) { mod.config = this; generateOptionsList(mod.defaultPage); - ConfigCore.oneConfigMods.add(mod); - this.mod = mod; + ConfigCore.mods.add(mod); } } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java index c138e4a..fd3c86b 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java @@ -19,6 +19,7 @@ import cc.polyfrost.oneconfig.libs.universal.UResolution; import cc.polyfrost.oneconfig.libs.universal.UScreen; import cc.polyfrost.oneconfig.renderer.RenderManager; import cc.polyfrost.oneconfig.renderer.font.Fonts; +import cc.polyfrost.oneconfig.renderer.scissor.Scissor; import cc.polyfrost.oneconfig.renderer.scissor.ScissorManager; import cc.polyfrost.oneconfig.utils.InputUtils; import cc.polyfrost.oneconfig.utils.color.ColorPalette; @@ -140,6 +141,7 @@ public class OneConfigGui extends UScreen { } ScissorManager.scissor(vg, x + 224, y + 72, 1056, 728); + Scissor blockedClicks = InputUtils.blockInputArea(x + 224, y, 1056,72); if (prevPage != null && animation != null) { float pageProgress = animation.get(GuiUtils.getDeltaTime()); if (!animation.isReversed()) { @@ -156,6 +158,7 @@ public class OneConfigGui extends UScreen { currentPage.scrollWithDraw(vg, x + 224, y + 72); } ScissorManager.clearScissors(vg); + InputUtils.stopBlock(blockedClicks); float breadcrumbX = x + 352; for (int i = 0; i < currentPage.parents.size(); i++) { 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 75a9f8e..5f454f2 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java @@ -13,7 +13,6 @@ import cc.polyfrost.oneconfig.renderer.font.Fonts; import cc.polyfrost.oneconfig.utils.color.ColorPalette; import java.util.ArrayList; -import java.util.Iterator; public class ModsPage extends Page { @@ -46,7 +45,7 @@ public class ModsPage extends Page { ArrayList<ModCard> finalModCards = new ArrayList<>(modCards); for (ModCard modCard : finalModCards) { if (inSelection(modCard) && (filter.equals("") || modCard.getModData().name.toLowerCase().contains(filter))) { - modCard.draw(vg, iX, iY); + if (iY + 135 >= y - scroll && iY <= y + 728 - scroll) modCard.draw(vg, iX, iY); iX += 260; if (iX > x + 796) { iX = x + 16; @@ -86,7 +85,7 @@ public class ModsPage extends Page { public void reloadMods() { modCards.clear(); - for (Mod modData : ConfigCore.oneConfigMods) { + for (Mod modData : ConfigCore.mods) { modCards.add(new ModCard(modData, modData.config == null || modData.config.enabled, false, OneConfigConfig.favoriteMods.contains(modData.name), this)); } } 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 9a4b1eb..b55f851 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java @@ -24,6 +24,7 @@ public abstract class Page { private long scrollTime; private boolean mouseWasDown, dragging; private float yStart; + protected float scroll; public final ArrayList<Page> parents = new ArrayList<>(); public Page(String title) { @@ -47,7 +48,7 @@ public abstract class Page { public void scrollWithDraw(long vg, int x, int y) { int maxScroll = getMaxScrollHeight(); int scissorOffset = drawStatic(vg, x, y); - float scroll = scrollAnimation == null ? scrollTarget : scrollAnimation.get(); + scroll = scrollAnimation == null ? scrollTarget : scrollAnimation.get(); final float scrollBarLength = (728f / maxScroll) * 728f; Scissor scissor = ScissorManager.scissor(vg, x, y + scissorOffset, x + 1056, y + 728 - scissorOffset); Scissor inputScissor = InputUtils.blockInputArea(x, y,1056, scissorOffset); diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/config/InternalConfig.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/InternalConfig.java index f0b065e..df90c19 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/config/InternalConfig.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/InternalConfig.java @@ -19,12 +19,11 @@ public abstract class InternalConfig extends Config { } @Override - public void init(Mod mod) { + public void initialize() { if (new File("OneConfig/" + configFile).exists()) load(); else save(); generateOptionList(this, mod.defaultPage, mod, false); mod.config = this; - this.mod = mod; } @Override diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/config/OneConfigConfig.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/OneConfigConfig.java index 96fde65..0ed5dc2 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/config/OneConfigConfig.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/OneConfigConfig.java @@ -26,5 +26,6 @@ public class OneConfigConfig extends InternalConfig { public OneConfigConfig() { super("", "OneConfig.json"); + initialize(); } } diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/config/Preferences.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/Preferences.java index c8a5163..fff8fed 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/config/Preferences.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/Preferences.java @@ -5,7 +5,9 @@ import cc.polyfrost.oneconfig.config.annotations.Slider; import cc.polyfrost.oneconfig.config.annotations.Switch; import cc.polyfrost.oneconfig.config.core.OneKeyBind; import cc.polyfrost.oneconfig.gui.OneConfigGui; +import cc.polyfrost.oneconfig.internal.gui.BlurHandler; import cc.polyfrost.oneconfig.libs.universal.UKeyboard; +import cc.polyfrost.oneconfig.libs.universal.UMinecraft; import cc.polyfrost.oneconfig.utils.gui.GuiUtils; public class Preferences extends InternalConfig { @@ -37,6 +39,8 @@ public class Preferences extends InternalConfig { public Preferences() { super("Preferences", "Preferences.json"); + initialize(); + addListener("enableBlur", () -> BlurHandler.INSTANCE.reloadBlur(UMinecraft.getMinecraft().currentScreen)); registerKeyBind(oneConfigKeyBind, () -> GuiUtils.displayScreen(OneConfigGui.create())); } } diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java index 90c1062..4edff74 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java @@ -20,31 +20,31 @@ public class ConfigCore { } }, 30000, 30000); } - public static List<Mod> oneConfigMods = new ArrayList<>(); + public static List<Mod> mods = new ArrayList<>(); public static void saveAll() { - for (Mod modData : oneConfigMods) { + for (Mod modData : mods) { modData.config.save(); } } public static void reInitAll() { - ArrayList<Mod> data = new ArrayList<>(oneConfigMods); - oneConfigMods.clear(); + ArrayList<Mod> data = new ArrayList<>(mods); + mods.clear(); HudCore.huds.clear(); KeyBindHandler.INSTANCE.clearKeyBinds(); for (Mod modData : data) { - modData.config.init(modData); + modData.config.initialize(); } sortMods(); } public static void sortMods() { - ArrayList<Mod> mods = new ArrayList<>(oneConfigMods); - oneConfigMods = mods.stream().filter((mod -> OneConfigConfig.favoriteMods.contains(mod.name))).sorted().collect(Collectors.toList()); - mods.removeAll(oneConfigMods); - oneConfigMods.addAll(mods.stream().filter(mod -> mod.modType != ModType.THIRD_PARTY).sorted().collect(Collectors.toList())); - mods.removeAll(oneConfigMods); - oneConfigMods.addAll(mods.stream().sorted().collect(Collectors.toList())); + ArrayList<Mod> mods = new ArrayList<>(ConfigCore.mods); + ConfigCore.mods = mods.stream().filter((mod -> OneConfigConfig.favoriteMods.contains(mod.name))).sorted().collect(Collectors.toList()); + mods.removeAll(ConfigCore.mods); + ConfigCore.mods.addAll(mods.stream().filter(mod -> mod.modType != ModType.THIRD_PARTY).sorted().collect(Collectors.toList())); + mods.removeAll(ConfigCore.mods); + ConfigCore.mods.addAll(mods.stream().sorted().collect(Collectors.toList())); } } diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/gui/BlurHandler.java b/src/main/java/cc/polyfrost/oneconfig/internal/gui/BlurHandler.java index 697f2d4..dac0202 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/gui/BlurHandler.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/gui/BlurHandler.java @@ -38,7 +38,7 @@ public class BlurHandler { private final ResourceLocation blurShader = new ResourceLocation("shaders/post/fade_in_blur.json"); private final Logger logger = LogManager.getLogger("OneConfig - Blur"); private long start; - private float lastProgress = 0; + private float progress = 0; /** * Simply initializes the blur mod so events are properly handled by forge. @@ -67,18 +67,8 @@ public class BlurHandler { if (!UMinecraft.getMinecraft().entityRenderer.isShaderActive()) { return; } - - float progress = getBlurStrengthProgress(); - - // If the new progress value matches the old one this - // will skip the frame update, which (hopefully) resolves the issue - // with the heavy computations after the "animation" is complete. - if (progress == this.lastProgress) { - return; - } - - // Store it for the next iteration! - this.lastProgress = progress; + if (progress >= 5) return; + progress = getBlurStrengthProgress(); // This is hilariously bad, and could cause frame issues on low-end computers. // Why is this being computed every tick? Surely there is a better way? @@ -112,7 +102,7 @@ public class BlurHandler { * one of many conditions are met, such as no current other shader * is being used, we actually have the blur setting enabled */ - private void reloadBlur(GuiScreen gui) { + public void reloadBlur(GuiScreen gui) { // Don't do anything if no world is loaded if (UMinecraft.getWorld() == null) { return; @@ -124,9 +114,10 @@ public class BlurHandler { UMinecraft.getMinecraft().entityRenderer.loadShader(this.blurShader); this.start = System.currentTimeMillis(); + this.progress = 0; // If a shader is active and the incoming UI is null or we have blur disabled, stop using the shader. - } else if (UMinecraft.getMinecraft().entityRenderer.isShaderActive() && (gui == null)) { + } else if (UMinecraft.getMinecraft().entityRenderer.isShaderActive() && (gui == null || !Preferences.enableBlur)) { String name = UMinecraft.getMinecraft().entityRenderer.getShaderGroup().getShaderGroupName(); // Only stop our specific blur ;) diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/hooks/VigilantHook.java b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/hooks/VigilantHook.java index 59aebca..7b66435 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/hooks/VigilantHook.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/hooks/VigilantHook.java @@ -18,7 +18,7 @@ public class VigilantHook { if (name.equals("OneConfig")) name = "Essential"; String finalName = name; // duplicate fix - if (ConfigCore.oneConfigMods.stream().anyMatch(mod -> mod.name.equals(finalName))) return null; + if (ConfigCore.mods.stream().anyMatch(mod -> mod.name.equals(finalName))) return null; return new VigilanceConfig(new Mod(name, ModType.THIRD_PARTY), file.getAbsolutePath(), vigilant); } else { return null; diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/scissor/ScissorManager.java b/src/main/java/cc/polyfrost/oneconfig/renderer/scissor/ScissorManager.java index bfafedf..59a2da8 100644 --- a/src/main/java/cc/polyfrost/oneconfig/renderer/scissor/ScissorManager.java +++ b/src/main/java/cc/polyfrost/oneconfig/renderer/scissor/ScissorManager.java @@ -58,7 +58,7 @@ public class ScissorManager { NanoVG.nvgScissor(vg, finalScissor.x, finalScissor.y, finalScissor.width, finalScissor.height); } - public static Scissor getFinalScissor(ArrayList<Scissor> scissors) { + private static Scissor getFinalScissor(ArrayList<Scissor> scissors) { Scissor finalScissor = new Scissor(scissors.get(0)); for (int i = 1; i < scissors.size(); i++) { Scissor scissor = scissors.get(i); diff --git a/src/main/java/cc/polyfrost/oneconfig/test/TestConfig_Test.java b/src/main/java/cc/polyfrost/oneconfig/test/TestConfig_Test.java index 1ae0af8..a7ad2ac 100644 --- a/src/main/java/cc/polyfrost/oneconfig/test/TestConfig_Test.java +++ b/src/main/java/cc/polyfrost/oneconfig/test/TestConfig_Test.java @@ -128,6 +128,7 @@ public class TestConfig_Test extends Config { public TestConfig_Test() { super(new Mod("Test Mod", ModType.UTIL_QOL, new VigilanceMigrator("./config/testConfig.toml")), "hacksConfig.json"); + initialize(); addDependency("testCheckBox", "testSwitch"); } } diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java index 0e342a2..b7e620b 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java @@ -17,7 +17,6 @@ import java.util.ArrayList; */ public final class InputUtils { private static final ArrayList<Scissor> blockScissors = new ArrayList<>(); - private static Scissor finalScissor = new Scissor(0, 0, 0, 0); /** * function to determine weather the mouse is currently over a specific region. Uses the current nvgScale to fix to any scale. @@ -27,7 +26,7 @@ public final class InputUtils { public static boolean isAreaHovered(int x, int y, int width, int height, boolean ignoreBlock) { int mouseX = mouseX(); int mouseY = mouseY(); - return (ignoreBlock || blockScissors.size() == 0 || !finalScissor.isInScissor(mouseX, mouseY)) && mouseX > x && mouseY > y && mouseX < x + width && mouseY < y + height; + return (ignoreBlock || blockScissors.size() == 0 || !shouldBlock(mouseX, mouseY)) && mouseX > x && mouseY > y && mouseX < x + width && mouseY < y + height; } /** @@ -75,7 +74,7 @@ public final class InputUtils { * @return true if the mouse is clicked, false if not */ public static boolean isClicked(boolean ignoreBlock) { - return OneConfigGui.INSTANCE != null && OneConfigGui.INSTANCE.mouseDown && !Mouse.isButtonDown(0) && (ignoreBlock || blockScissors.size() == 0 || !finalScissor.isInScissor(mouseX(), mouseY())); + return OneConfigGui.INSTANCE != null && OneConfigGui.INSTANCE.mouseDown && !Mouse.isButtonDown(0) && (ignoreBlock || blockScissors.size() == 0 || !shouldBlock(mouseX(), mouseY())); } /** @@ -127,7 +126,6 @@ public final class InputUtils { public static Scissor blockInputArea(int x, int y, int width, int height) { Scissor scissor = new Scissor(new Scissor(x, y, width, height)); blockScissors.add(scissor); - finalScissor = ScissorManager.getFinalScissor(blockScissors); return scissor; } @@ -145,7 +143,6 @@ public final class InputUtils { */ public static void stopBlock(Scissor scissor) { blockScissors.remove(scissor); - if (blockScissors.size() > 0) finalScissor = ScissorManager.getFinalScissor(blockScissors); } /** @@ -163,4 +160,11 @@ public final class InputUtils { public static boolean isBlockingInput() { return blockScissors.size() > 0; } + + private static boolean shouldBlock(int x, int y) { + for (Scissor block : blockScissors) { + if (block.isInScissor(x, y)) return true; + } + return false; + } } |