diff options
author | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-07-05 22:37:47 +0900 |
---|---|---|
committer | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-07-05 22:37:47 +0900 |
commit | 206063acf3a6e0edc0d16b07d206aa36207b42d4 (patch) | |
tree | 8d0f31d65cfa4b3f85a3d4f7f0844f6df65b2b7e /src | |
parent | fecb67e07ded0d20b12d3bdb48fea3e2e50b7f88 (diff) | |
download | OneConfig-206063acf3a6e0edc0d16b07d206aa36207b42d4.tar.gz OneConfig-206063acf3a6e0edc0d16b07d206aa36207b42d4.tar.bz2 OneConfig-206063acf3a6e0edc0d16b07d206aa36207b42d4.zip |
a
Diffstat (limited to 'src')
7 files changed, 91 insertions, 167 deletions
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 40463df..552051f 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 @@ -143,32 +143,26 @@ public class TextInputField extends BasicElement { width = RenderManager.getTextWidth(vg, s.substring(0, caretPos), 14f, Fonts.REGULAR.font); } if (hovered) { - while (Platform.getMousePlatform().next()) { - if (Platform.getMousePlatform().getEventButtonState()) { - if (Platform.getMousePlatform().getEventButton() == 0) { - if (multiLine) { - int caretLine = Math.max(0, Math.min(wrappedText.size() - 1, (int) Math.floor((InputUtils.mouseY() - y - 10) / 24f))); - caretPos = calculatePos(InputUtils.mouseX(), wrappedText.get(caretLine)); - } else prevCaret = calculatePos(InputUtils.mouseX(), input); - if (System.currentTimeMillis() - clickTimeD1 < 300) { - onDoubleClick(); - isDoubleClick = true; - } - clickTimeD1 = System.currentTimeMillis(); - } - } else { - if (Platform.getMousePlatform().getEventButton() == 0) { - long clickTimeU = System.currentTimeMillis(); - if (clickTimeU - clickTimeD1 < 200) { - if (!isDoubleClick) { - start = 0; - end = 0; - } - prevCaret = caretPos; - isDoubleClick = false; - } - + int state = Platform.getMousePlatform().getButtonState(0); //todo does this work + if (state == 1) { + if (multiLine) { + int caretLine = Math.max(0, Math.min(wrappedText.size() - 1, (int) Math.floor((InputUtils.mouseY() - y - 10) / 24f))); + caretPos = calculatePos(InputUtils.mouseX(), wrappedText.get(caretLine)); + } else prevCaret = calculatePos(InputUtils.mouseX(), input); + if (System.currentTimeMillis() - clickTimeD1 < 300) { + onDoubleClick(); + isDoubleClick = true; + } + clickTimeD1 = System.currentTimeMillis(); + } else { + long clickTimeU = System.currentTimeMillis(); + if (clickTimeU - clickTimeD1 < 200) { + if (!isDoubleClick) { + start = 0; + end = 0; } + prevCaret = caretPos; + isDoubleClick = false; } } } 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 ddf6a3f..028f098 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java @@ -52,7 +52,7 @@ public abstract class Page { 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); - int dWheel = Platform.getMousePlatform().getDWheel(); + int dWheel = (int) Platform.getMousePlatform().getDWheel(); if (dWheel != 0) { scrollTarget += dWheel; diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java deleted file mode 100644 index 0ef2c58..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java +++ /dev/null @@ -1,129 +0,0 @@ -package cc.polyfrost.oneconfig.internal.plugin; - -import org.objectweb.asm.Opcodes; -import org.objectweb.asm.Type; -import org.spongepowered.asm.lib.tree.*; -import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; -import org.spongepowered.asm.mixin.extensibility.IMixinInfo; - -import java.io.File; -import java.util.List; -import java.util.Set; - -public class OneConfigMixinPlugin implements IMixinConfigPlugin { - private static boolean isVigilance = false; - - @Override - public void onLoad(String mixinPackage) { - try { - Class.forName("gg.essential.vigilance.Vigilant"); - isVigilance = true; - } catch (Exception e) { - isVigilance = false; - } - } - - @Override - public String getRefMapperConfig() { - return null; - } - - @Override - public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { - return !targetClassName.contains("vigilance") || isVigilance; - } - - @Override - public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) { - - } - - @Override - public List<String> getMixins() { - return null; - } - - @Override - public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { - - } - - @Override - public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { - if (mixinClassName.equals("cc.polyfrost.oneconfig.internal.mixin.VigilantMixin")) { - transform(targetClass); - } - } - - /** - * If anything here is changed, edit the corresponding method in OneConfigMixinPlugin! - */ - private void transform(ClassNode node) { - if (!node.interfaces.contains("cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilantAccessor")) { - node.fields.add(new FieldNode(Opcodes.ACC_PUBLIC, "oneconfig$config", "Lcc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig;", null, null)); - node.fields.add(new FieldNode(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "oneconfig$file", Type.getDescriptor(File.class), null, null)); - - node.interfaces.add("cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilantAccessor"); - MethodNode methodNode = new MethodNode(Opcodes.ACC_PUBLIC, "getPropertyCollector", "()Lgg/essential/vigilance/data/PropertyCollector;", null, null); - LabelNode labelNode = new LabelNode(); - methodNode.instructions.add(labelNode); - methodNode.instructions.add(new LineNumberNode(421421, labelNode)); - methodNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); - methodNode.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, "gg/essential/vigilance/Vigilant", "propertyCollector", "Lgg/essential/vigilance/data/PropertyCollector;")); - methodNode.instructions.add(new InsnNode(Opcodes.ARETURN)); - node.methods.add(methodNode); - - MethodNode methodNode2 = new MethodNode(Opcodes.ACC_PUBLIC, "handleOneConfigDependency", "(Lgg/essential/vigilance/data/PropertyData;Lgg/essential/vigilance/data/PropertyData;)V", null, null); - LabelNode labelNode2 = new LabelNode(); - LabelNode labelNode3 = new LabelNode(); - LabelNode labelNode4 = new LabelNode(); - methodNode2.instructions.add(labelNode2); - methodNode2.instructions.add(new LineNumberNode(15636436, labelNode2)); - methodNode2.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); - methodNode2.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$config", "Lcc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig;")); - - methodNode2.instructions.add(new JumpInsnNode(Opcodes.IFNULL, labelNode4)); - - methodNode2.instructions.add(labelNode3); - methodNode2.instructions.add(new LineNumberNode(15636437, labelNode3)); - methodNode2.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); - methodNode2.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$config", "Lcc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig;")); - methodNode2.instructions.add(new VarInsnNode(Opcodes.ALOAD, 1)); - methodNode2.instructions.add(new VarInsnNode(Opcodes.ALOAD, 2)); - methodNode2.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig", "addDependency", "(Lgg/essential/vigilance/data/PropertyData;Lgg/essential/vigilance/data/PropertyData;)V", false)); - - methodNode2.instructions.add(labelNode4); - methodNode2.instructions.add(new LineNumberNode(15636438, labelNode4)); - methodNode2.instructions.add(new InsnNode(Opcodes.RETURN)); - node.methods.add(methodNode2); - - for (MethodNode method : node.methods) { - if (method.name.equals("initialize")) { - InsnList list = new InsnList(); - list.add(new VarInsnNode(Opcodes.ALOAD, 0)); - list.add(new VarInsnNode(Opcodes.ALOAD, 0)); - list.add(new VarInsnNode(Opcodes.ALOAD, 0)); - list.add(new FieldInsnNode(Opcodes.GETFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$file", Type.getDescriptor(File.class))); - list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "cc/polyfrost/oneconfig/internal/plugin/hooks/VigilantHook", "returnNewConfig", "(Lgg/essential/vigilance/Vigilant;Ljava/io/File;)Lcc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig;", false)); - list.add(new FieldInsnNode(Opcodes.PUTFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$config", "Lcc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig;")); - method.instructions.insertBefore(method.instructions.getLast().getPrevious(), list); - } else if (method.name.equals("addDependency") && method.desc.equals("(Lgg/essential/vigilance/data/PropertyData;Lgg/essential/vigilance/data/PropertyData;)V")) { - InsnList list = new InsnList(); - - list.add(new VarInsnNode(Opcodes.ALOAD, 0)); - list.add(new VarInsnNode(Opcodes.ALOAD, 1)); - list.add(new VarInsnNode(Opcodes.ALOAD, 2)); - list.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "gg/essential/vigilance/Vigilant", "handleOneConfigDependency", "(Lgg/essential/vigilance/data/PropertyData;Lgg/essential/vigilance/data/PropertyData;)V", false)); - - method.instructions.insertBefore(method.instructions.getLast().getPrevious(), list); - } else if (method.name.equals("<init>") && method.desc.equals("(Ljava/io/File;Ljava/lang/String;Lgg/essential/vigilance/data/PropertyCollector;Lgg/essential/vigilance/data/SortingBehavior;)V")) { - InsnList list = new InsnList(); - list.add(new VarInsnNode(Opcodes.ALOAD, 0)); - list.add(new VarInsnNode(Opcodes.ALOAD, 1)); - list.add(new FieldInsnNode(Opcodes.PUTFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$file", Type.getDescriptor(File.class))); - method.instructions.insertBefore(method.instructions.getLast().getPrevious(), list); - } - } - } - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/platform/MousePlatform.java b/src/main/java/cc/polyfrost/oneconfig/platform/MousePlatform.java index add5f4f..3d7d735 100644 --- a/src/main/java/cc/polyfrost/oneconfig/platform/MousePlatform.java +++ b/src/main/java/cc/polyfrost/oneconfig/platform/MousePlatform.java @@ -1,15 +1,13 @@ package cc.polyfrost.oneconfig.platform; public interface MousePlatform { - int getMouseX(); - int getMouseY(); - int getDWheel(); - int getMouseDX(); - int getMouseDY(); + double getMouseX(); + double getMouseY(); + double getDWheel(); + double getMouseDX(); + double getMouseDY(); - boolean next(); - boolean getEventButtonState(); - int getEventButton(); + int getButtonState(int button); boolean isButtonDown(int button); } diff --git a/src/main/java/cc/polyfrost/oneconfig/platform/Platform.java b/src/main/java/cc/polyfrost/oneconfig/platform/Platform.java index 3eea049..62e9e2a 100644 --- a/src/main/java/cc/polyfrost/oneconfig/platform/Platform.java +++ b/src/main/java/cc/polyfrost/oneconfig/platform/Platform.java @@ -39,6 +39,8 @@ public interface Platform { boolean isCallingFromMinecraftThread(); + int getMinecraftVersion(); + class PlatformHolder { private PlatformHolder() { diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java index a48d369..6582eaa 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java @@ -96,7 +96,7 @@ public final class InputUtils { * @return the current mouse X position */ public static int mouseX() { - if (OneConfigGui.INSTANCE == null) return Platform.getMousePlatform().getMouseX(); + if (OneConfigGui.INSTANCE == null) return (int) Platform.getMousePlatform().getMouseX(); //todo stop casting and actually use doubles return (int) (Platform.getMousePlatform().getMouseX() / OneConfigGui.INSTANCE.getScaleFactor()); } @@ -110,7 +110,7 @@ public final class InputUtils { * @return the current mouse Y position */ public static int mouseY() { - if (OneConfigGui.INSTANCE == null) return UResolution.getWindowHeight() - Math.abs(Platform.getMousePlatform().getMouseY()); + if (OneConfigGui.INSTANCE == null) return (int) (UResolution.getWindowHeight() - Math.abs(Platform.getMousePlatform().getMouseY())); return (int) ((UResolution.getWindowHeight() - Math.abs(Platform.getMousePlatform().getMouseY())) / OneConfigGui.INSTANCE.getScaleFactor()); } diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManager.java b/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManager.java index a02f4ff..1ab356c 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManager.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManager.java @@ -1,7 +1,66 @@ package cc.polyfrost.oneconfig.utils.commands; +import cc.polyfrost.oneconfig.libs.universal.ChatColor; import cc.polyfrost.oneconfig.utils.commands.annotations.Command; +import cc.polyfrost.oneconfig.utils.commands.annotations.Name; +import cc.polyfrost.oneconfig.utils.commands.annotations.SubCommand; +import cc.polyfrost.oneconfig.utils.commands.arguments.ArgumentParser; -public interface PlatformCommandManager { - void createCommand(CommandManager.InternalCommand root, Command annotation); +import java.lang.reflect.Parameter; + +public abstract class PlatformCommandManager { + + //TODO: someone make the help command actually look nice lmao + protected String sendHelpCommand(CommandManager.InternalCommand root) { + StringBuilder builder = new StringBuilder(); + builder.append(ChatColor.GOLD).append("Help for ").append(ChatColor.BOLD).append(root.name).append(ChatColor.RESET).append(ChatColor.GOLD).append(":\n"); + if (!root.description.isEmpty()) { + builder.append("\n").append(ChatColor.GOLD).append("Description: ").append(ChatColor.BOLD).append(root.description); + } + for (CommandManager.InternalCommand command : root.children) { + runThroughCommandsHelp(root.name, command, builder); + } + builder.append("\n").append(ChatColor.GOLD).append("Aliases: ").append(ChatColor.BOLD); + int index = 0; + for (String alias : root.aliases) { + ++index; + builder.append(alias).append(index < root.aliases.length ? ", " : ""); + } + builder.append("\n"); + return builder.toString(); + } + + protected void runThroughCommandsHelp(String append, CommandManager.InternalCommand command, StringBuilder builder) { + if (!command.invokers.isEmpty()) { + Class<?> declaringClass = command.invokers.get(0).method.getDeclaringClass(); + if (declaringClass.isAnnotationPresent(SubCommand.class)) { + String description = declaringClass.getAnnotation(SubCommand.class).description(); + if (!description.isEmpty()) { + builder.append("\n").append(ChatColor.GOLD).append("Description: ").append(ChatColor.BOLD).append(description); + } + } + } + for (CommandManager.InternalCommand.InternalCommandInvoker invoker : command.invokers) { + builder.append("\n").append(ChatColor.GOLD).append("/").append(append).append(" ").append(command.name); + for (Parameter parameter : invoker.method.getParameters()) { + String name = parameter.getName(); + if (parameter.isAnnotationPresent(Name.class)) { + name = parameter.getAnnotation(Name.class).value(); + } + builder.append(" <").append(name).append(">"); + } + if (!command.description.trim().isEmpty()) { + builder.append(": ").append(ChatColor.BOLD).append(command.description); + } + } + for (CommandManager.InternalCommand subCommand : command.children) { + runThroughCommandsHelp(append + " " + command.name, subCommand, builder); + } + } + + abstract void createCommand(CommandManager.InternalCommand root, Command annotation); + + public void handleNewParser(ArgumentParser<?> parser, Class<?> clazz) { + + } } |