diff options
| author | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-05-21 17:50:43 +0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-21 12:50:43 +0200 |
| commit | ba87b8b1fa4e2397a3e0ed5a18f7ea6137d42f77 (patch) | |
| tree | a052e7ac963be0f64980fc3faa664ebf20a52b34 /src | |
| parent | 1abe65dc3875df5a490d8c900399e61a378ae901 (diff) | |
| download | OneConfig-ba87b8b1fa4e2397a3e0ed5a18f7ea6137d42f77.tar.gz OneConfig-ba87b8b1fa4e2397a3e0ed5a18f7ea6137d42f77.tar.bz2 OneConfig-ba87b8b1fa4e2397a3e0ed5a18f7ea6137d42f77.zip | |
vigilance compat (#15)
* vigilance compat
reorganize ASM
* remove non-RenderManager nanovg usage wherever possible
fix build
generalize utils
* setupGradle task
* migrate to kotlin gradle
use essential gradle toolkit
shade new gson
* Small changes
* Update .gitignore
* fix natives
* Fix all problems
* null
Co-authored-by: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>
Diffstat (limited to 'src')
50 files changed, 581 insertions, 209 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/OneConfig.java b/src/main/java/cc/polyfrost/oneconfig/OneConfig.java index 3661c42..8812894 100644 --- a/src/main/java/cc/polyfrost/oneconfig/OneConfig.java +++ b/src/main/java/cc/polyfrost/oneconfig/OneConfig.java @@ -28,8 +28,8 @@ import java.util.List; @net.minecraftforge.fml.common.Mod(modid = "@ID@", name = "@NAME@", version = "@VER@") public class OneConfig { public static File jarFile; - public static File oneConfigDir = new File("./OneConfig/"); - public static File themesDir = new File(oneConfigDir, "themes/"); + public static File oneConfigDir = new File("./OneConfig"); + public static File themesDir = new File(oneConfigDir, "themes"); public static OneConfigConfig config; public static TestConfig testConfig; public static List<Mod> loadedMods = new ArrayList<>(); diff --git a/src/main/java/cc/polyfrost/oneconfig/command/OneConfigCommand.java b/src/main/java/cc/polyfrost/oneconfig/command/OneConfigCommand.java index f21e569..fac2112 100644 --- a/src/main/java/cc/polyfrost/oneconfig/command/OneConfigCommand.java +++ b/src/main/java/cc/polyfrost/oneconfig/command/OneConfigCommand.java @@ -4,7 +4,7 @@ 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 gg.essential.universal.UScreen; +import cc.polyfrost.oneconfig.libs.universal.UScreen; import net.minecraft.command.CommandBase; import net.minecraft.command.ICommandSender; diff --git a/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java b/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java index a590536..407afdf 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java @@ -89,7 +89,7 @@ public class OneConfigConfig extends Config { @Override public void load() { try (BufferedReader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(Paths.get("OneConfig/" + configFile)), StandardCharsets.UTF_8))) { - deserializePart(new JsonParser().parse(reader).getAsJsonObject(), this.getClass()); + deserializePart(new JsonParser().parse(reader).getAsJsonObject(), this); } catch (IOException e) { e.printStackTrace(); } diff --git a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilanceConfig.java b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilanceConfig.java new file mode 100644 index 0000000..14d1e72 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilanceConfig.java @@ -0,0 +1,135 @@ +package cc.polyfrost.oneconfig.config.compatibility; + +import cc.polyfrost.oneconfig.config.core.ConfigCore; +import cc.polyfrost.oneconfig.config.data.Mod; +import cc.polyfrost.oneconfig.config.data.OptionCategory; +import cc.polyfrost.oneconfig.config.data.OptionPage; +import cc.polyfrost.oneconfig.config.data.OptionSubcategory; +import cc.polyfrost.oneconfig.config.interfaces.BasicOption; +import cc.polyfrost.oneconfig.config.interfaces.Config; +import cc.polyfrost.oneconfig.gui.elements.config.*; +import gg.essential.vigilance.Vigilant; +import gg.essential.vigilance.data.*; +import kotlin.reflect.KMutableProperty0; +import kotlin.reflect.jvm.ReflectJvmMapping; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Objects; + +public class VigilanceConfig extends Config { + public final Vigilant vigilant; + + public VigilanceConfig(Mod modData, String configFile, Vigilant vigilant) { + super(modData, configFile); + this.vigilant = vigilant; + init(modData); + } + + @Override + public void init(Mod mod) { + if (vigilant != null) { + mod.config = this; + generateOptionsList(mod.defaultPage); + ConfigCore.oneConfigMods.add(mod); + this.mod = mod; + } + } + + @Override + public void save() { + vigilant.markDirty(); + vigilant.writeData(); + } + + @Override + public void load() { + //no-op + } + + private void generateOptionsList(OptionPage page) { + for (PropertyData option : ((VigilantAccessor) vigilant).getPropertyCollector().getProperties()) { + PropertyAttributesExt attributes = option.getAttributesExt(); + if (attributes.getHidden()) continue; + if (!page.categories.containsKey(attributes.getCategory())) + page.categories.put(attributes.getCategory(), new OptionCategory()); + OptionCategory category = page.categories.get(attributes.getCategory()); + if (category.subcategories.size() == 0 || !category.subcategories.get(category.subcategories.size() - 1).getName().equals(attributes.getSubcategory())) + category.subcategories.add(new OptionSubcategory(attributes.getSubcategory())); + ArrayList<BasicOption> options = category.subcategories.get(category.subcategories.size() - 1).options; + switch (attributes.getType()) { + case SWITCH: + options.add(new ConfigSwitch(getFieldOfProperty(option), option.getInstance(), attributes.getName(), 2)); + break; + case CHECKBOX: + options.add(new ConfigCheckbox(getFieldOfProperty(option), option.getInstance(), attributes.getName(), 2)); + break; + case PARAGRAPH: + case TEXT: + options.add(new ConfigTextBox(getFieldOfProperty(option), option.getInstance(), attributes.getName(), 2, attributes.getPlaceholder(), attributes.getProtected(), attributes.getType() == PropertyType.PARAGRAPH)); + break; + case SELECTOR: + options.add(new ConfigDropdown(getFieldOfProperty(option), option.getInstance(), attributes.getName(), 2, attributes.getOptions().toArray(new String[0]))); + break; + case PERCENT_SLIDER: + options.add(new ConfigSlider(getFieldOfProperty(option), option.getInstance(), attributes.getName(), 2, 0, 1, 0)); + break; + case DECIMAL_SLIDER: + options.add(new ConfigSlider(getFieldOfProperty(option), option.getInstance(), attributes.getName(), 2, attributes.getMinF(), attributes.getMaxF(), 0)); + break; + case SLIDER: + options.add(new ConfigSlider(getFieldOfProperty(option), option.getInstance(), attributes.getName(), 2, attributes.getMin(), attributes.getMax(), 0)); + break; + /*case COLOR: TODO: find a way to go from Color to OneColor + options.add(new ConfigColorElement(getFieldOfProperty(option), option.getInstance(), attributes.getName(), 2)); + break;*/ + case BUTTON: + options.add(new ConfigButton(() -> ((CallablePropertyValue) option.getValue()).invoke(option.getInstance()), option.getInstance(), attributes.getName(), 2, attributes.getPlaceholder())); + break; + } + if (attributes.getType() == PropertyType.SWITCH || attributes.getType() == PropertyType.CHECKBOX) { + optionNames.put(PropertyKt.fullPropertyPath(option.getAttributesExt()), options.get(options.size() - 1)); + } + } + } + + private Field getFieldOfProperty(PropertyData data) { + if (data.getValue() instanceof FieldBackedPropertyValue) { + FieldBackedPropertyValue fieldBackedPropertyValue = (FieldBackedPropertyValue) data.getValue(); + try { + Field field = fieldBackedPropertyValue.getClass().getDeclaredField("field"); + field.setAccessible(true); + return (Field) field.get(fieldBackedPropertyValue); + } catch (IllegalAccessException | NoSuchFieldException e) { + throw new RuntimeException(e); + } + } else if (data.getValue() instanceof ValueBackedPropertyValue) { + ValueBackedPropertyValue valueBackedPropertyValue = (ValueBackedPropertyValue) data.getValue(); + try { + Field field = valueBackedPropertyValue.getClass().getDeclaredField("obj"); + field.setAccessible(true); + return (Field) field.get(valueBackedPropertyValue); + } catch (IllegalAccessException | NoSuchFieldException e) { + throw new RuntimeException(e); + } + } else if (data.getValue() instanceof KPropertyBackedPropertyValue) { + KPropertyBackedPropertyValue kPropertyBackedPropertyValue = (KPropertyBackedPropertyValue) data.getValue(); + try { + Field field = kPropertyBackedPropertyValue.getClass().getDeclaredField("property"); + field.setAccessible(true); + KMutableProperty0 property = (KMutableProperty0) field.get(kPropertyBackedPropertyValue); + return ReflectJvmMapping.getJavaField(property); + } catch (IllegalAccessException | NoSuchFieldException e) { + throw new RuntimeException(e); + } + } else throw new RuntimeException("Unknown property value type: " + data.getValue().getClass()); + } + + @SuppressWarnings("unused") + public void addDependency(PropertyData property, PropertyData dependency) { + BasicOption option = optionNames.get(PropertyKt.fullPropertyPath(property.getAttributesExt())); + if (option != null) { + option.setDependency(() -> Objects.equals(dependency.getValue().getValue(vigilant), true)); + } + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilantAccessor.java b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilantAccessor.java new file mode 100644 index 0000000..4c79a21 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilantAccessor.java @@ -0,0 +1,7 @@ +package cc.polyfrost.oneconfig.config.compatibility; + +import gg.essential.vigilance.data.PropertyCollector; + +public interface VigilantAccessor { + PropertyCollector getPropertyCollector(); +} diff --git a/src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java b/src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java index d455411..d62247c 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java @@ -1,6 +1,6 @@ package cc.polyfrost.oneconfig.config.core; -import gg.essential.universal.UKeyboard; +import cc.polyfrost.oneconfig.libs.universal.UKeyboard; import java.util.ArrayList; diff --git a/src/main/java/cc/polyfrost/oneconfig/config/data/Mod.java b/src/main/java/cc/polyfrost/oneconfig/config/data/Mod.java index e38c062..c7e86cd 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/data/Mod.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/data/Mod.java @@ -2,6 +2,8 @@ package cc.polyfrost.oneconfig.config.data; import cc.polyfrost.oneconfig.config.interfaces.Config; +import java.util.ArrayList; + public class Mod { public final String name; public final ModType modType; @@ -10,6 +12,7 @@ public class Mod { public Config config; public final OptionPage defaultPage; public boolean isShortCut = false; + private static final ArrayList<Mod> mods = new ArrayList<>(); /** * @param name Friendly name of the mod @@ -18,10 +21,18 @@ public class Mod { * @param version Version of the mod */ public Mod(String name, ModType modType, String creator, String version) { + int i = 1; + for (Mod mod : mods) { + if (mod.name.startsWith(name)) { + ++i; + name = name + " " + i; + } + } this.name = name; this.modType = modType; this.creator = creator; this.version = version; this.defaultPage = new OptionPage(name, this); + mods.add(this); } } 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 694404a..49d2049 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java @@ -10,9 +10,8 @@ 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.lwjgl.RenderManager; import com.google.gson.*; -import gg.essential.universal.UScreen; +import cc.polyfrost.oneconfig.libs.universal.UScreen; import java.io.*; import java.lang.reflect.Field; @@ -20,14 +19,13 @@ import java.lang.reflect.Modifier; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.*; -import java.util.function.Consumer; import java.util.function.Supplier; public class Config { transient protected final String configFile; transient protected final Gson gson = new GsonBuilder().excludeFieldsWithModifiers(Modifier.TRANSIENT).setPrettyPrinting().create(); - transient private Mod mod; - final transient private HashMap<String, BasicOption> optionNames = new HashMap<>(); + transient public Mod mod; + public final transient HashMap<String, BasicOption> optionNames = new HashMap<>(); public boolean enabled = true; /** @@ -35,8 +33,17 @@ public class Config { * @param configFile file where config is stored */ public Config(Mod modData, String configFile) { + this(modData, configFile, true); + } + + /** + * @param modData information about the mod + * @param configFile file where config is stored + * @param initialize whether to load the config immediately or not + */ + public Config(Mod modData, String configFile, boolean initialize) { this.configFile = configFile; - init(modData); + if (initialize) init(modData); } public void init(Mod mod) { diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java index e81fb86..4595725 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java @@ -4,9 +4,9 @@ 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 gg.essential.universal.UKeyboard; -import gg.essential.universal.UMatrixStack; -import gg.essential.universal.UScreen; +import cc.polyfrost.oneconfig.libs.universal.UKeyboard; +import cc.polyfrost.oneconfig.libs.universal.UMatrixStack; +import cc.polyfrost.oneconfig.libs.universal.UScreen; 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 66bc2cd..d0e0625 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java @@ -14,11 +14,10 @@ import cc.polyfrost.oneconfig.lwjgl.scissor.Scissor; import cc.polyfrost.oneconfig.lwjgl.scissor.ScissorManager; import cc.polyfrost.oneconfig.utils.InputUtils; import cc.polyfrost.oneconfig.utils.MathUtils; -import gg.essential.universal.*; +import cc.polyfrost.oneconfig.libs.universal.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.lwjgl.input.Mouse; -import org.lwjgl.nanovg.NanoVG; import java.util.ArrayList; @@ -82,7 +81,7 @@ public class OneConfigGui extends UScreen { scale = Math.min(Math.min(1f, UResolution.getWindowWidth() / 1280f), Math.min(1f, UResolution.getWindowHeight() / 800f)); int x = (int) ((UResolution.getWindowWidth() - 1280 * scale) / 2f / scale); int y = (int) ((UResolution.getWindowHeight() - 800 * scale) / 2f / scale); - NanoVG.nvgScale(vg, scale, scale); + RenderManager.scale(vg, scale, scale); if (OneConfigConfig.ROUNDED_CORNERS) { RenderManager.drawRoundedRect(vg, x + 224, y, 1056, 800, OneConfigConfig.GRAY_800, OneConfigConfig.CORNER_RADIUS_WIN); RenderManager.drawRoundedRect(vg, x, y, 244, 800, OneConfigConfig.GRAY_900_80, OneConfigConfig.CORNER_RADIUS_WIN); @@ -103,22 +102,22 @@ public class OneConfigGui extends UScreen { if (previousPages.size() == 0) { backArrow.disable(true); - NanoVG.nvgGlobalAlpha(vg, 0.5f); + RenderManager.withAlpha(vg, 0.5f); } else { backArrow.disable(false); - if (!backArrow.isHovered() || Mouse.isButtonDown(0)) NanoVG.nvgGlobalAlpha(vg, 0.8f); + if (!backArrow.isHovered() || Mouse.isButtonDown(0)) RenderManager.withAlpha(vg, 0.8f); } RenderManager.drawSvg(vg, SVGs.ARROW_CIRCLE_LEFT, x + 249, y + 25, 22, 22); - NanoVG.nvgGlobalAlpha(vg, 1f); + RenderManager.withAlpha(vg, 1f); if (nextPages.size() == 0) { forwardArrow.disable(true); - NanoVG.nvgGlobalAlpha(vg, 0.5f); + RenderManager.withAlpha(vg, 0.5f); } else { forwardArrow.disable(false); - if (!forwardArrow.isHovered() || Mouse.isButtonDown(0)) NanoVG.nvgGlobalAlpha(vg, 0.8f); + if (!forwardArrow.isHovered() || Mouse.isButtonDown(0)) RenderManager.withAlpha(vg, 0.8f); } RenderManager.drawSvg(vg, SVGs.ARROW_CIRCLE_RIGHT, x + 289, y + 25, 22, 22); - NanoVG.nvgGlobalAlpha(vg, 1f); + RenderManager.withAlpha(vg, 1f); if (backArrow.isClicked() && previousPages.size() > 0) { try { @@ -138,7 +137,7 @@ public class OneConfigGui extends UScreen { Scissor scissor = ScissorManager.scissor(vg, x + 224, y + 88, 1056, 698); if (prevPage != null) { - pageProgress = MathUtils.easeInOutCirc(50, pageProgress, 832 - pageProgress, 600); + pageProgress = MathUtils.easeInOutCirc(50, pageProgress, 832 - pageProgress, 600, deltaTime); prevPage.scrollWithDraw(vg, (int) (x - pageProgress), y + 72); RenderManager.drawLine(vg, (int) (x - pageProgress + 1055), y + 72, (int) (x - pageProgress + 1057), y + 800, 2, OneConfigConfig.GRAY_700); // TODO might remove this currentPage.scrollWithDraw(vg, (int) (x - pageProgress + 1056), y + 72); @@ -225,7 +224,7 @@ public class OneConfigGui extends UScreen { /** * initialize a new ColorSelector and add it to the draw script. This method is used to make sure it is always rendered on top. * - * @implNote Correct usage: <code>OneConfigGui.INSTANCE.initColorSelector(new ColorSelector(color, InputUtils.mouseX(), InputUtils.mouseY()));</code> + * Correct usage: <code>OneConfigGui.INSTANCE.initColorSelector(new ColorSelector(color, InputUtils.mouseX(), InputUtils.mouseY()));</code> */ public void initColorSelector(ColorSelector colorSelector) { currentColorSelector = colorSelector; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java index 059e69d..11e9c6e 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java @@ -6,10 +6,9 @@ import cc.polyfrost.oneconfig.gui.pages.HomePage; import cc.polyfrost.oneconfig.gui.pages.ModsPage; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; -import cc.pol |
