From 18438626c415673175cbd2464fb35be66f61108b Mon Sep 17 00:00:00 2001 From: LoneVV <55526650+LoneVV@users.noreply.github.com> Date: Sat, 28 Sep 2019 18:46:50 +0300 Subject: [PATCH] Anti Drag: Hold on Key (#1629) Added an option for key hold instead of toggle. Fixed cursor not changing to normal and instead using RS3 Gold as default when toggling off. --- .../plugins/antidrag/AntiDragConfig.java | 49 ++++++++++------- .../plugins/antidrag/AntiDragPlugin.java | 54 +++++++++++++++++-- .../client/plugins/antidrag/CustomCursor.java | 4 +- 3 files changed, 83 insertions(+), 24 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/antidrag/AntiDragConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/antidrag/AntiDragConfig.java index 833a07e2a3..e34cd35e8a 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/antidrag/AntiDragConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/antidrag/AntiDragConfig.java @@ -42,8 +42,8 @@ public interface AntiDragConfig extends Config keyName = "alwaysOn", name = "Always On", description = "Makes the anti-drag always active and disables the hotkey toggle", - disabledBy = "keybind", - hide = "keybind" + disabledBy = "keybind || holdkeybind", + hide = "keybind || holdkeybind" ) default boolean alwaysOn() { @@ -55,21 +55,34 @@ public interface AntiDragConfig extends Config keyName = "keybind", name = "Toggle with Keybind", description = "Toggle anti drag on and off, rather than always on.", - disabledBy = "alwaysOn", - hide = "alwaysOn" + disabledBy = "alwaysOn || holdkeybind", + hide = "alwaysOn || holdkeybind" ) default boolean keybind() { return false; } + @ConfigItem( + position = 2, + keyName = "holdkeybind", + name = "Hold with Keybind", + description = "Hold anti drag key to turn it on, rather than toggle it on or off.", + disabledBy = "alwaysOn || keybind", + hide = "alwaysOn || keybind" + ) + default boolean holdkeybind() + { + return false; + } + @ConfigItem( keyName = "key", name = "Keybind", description = "The keybind you want to use for antidrag", - position = 2, + position = 3, hidden = true, - unhide = "keybind" + unhide = "keybind || holdkeybind" ) default Keybind key() { @@ -80,7 +93,7 @@ public interface AntiDragConfig extends Config keyName = "dragDelay", name = "Drag Delay", description = "Configures the inventory drag delay in client ticks (20ms)", - position = 3 + position = 4 ) default int dragDelay() { @@ -91,9 +104,9 @@ public interface AntiDragConfig extends Config keyName = "reqfocus", name = "Reset on focus loss", description = "Disable antidrag when losing focus (like alt tabbing)", - position = 4, + position = 5, hidden = true, - unhide = "keybind" + unhide = "keybind || holdkeybind" ) default boolean reqfocus() { @@ -104,9 +117,9 @@ public interface AntiDragConfig extends Config keyName = "overlay", name = "Enable overlay", description = "Do you really need a description?", - position = 5, + position = 6, hidden = true, - unhide = "keybind" + unhide = "keybind || holdkeybind" ) default boolean overlay() { @@ -119,8 +132,8 @@ public interface AntiDragConfig extends Config name = "Overlay color", description = "Change the overlay color, duh", hidden = true, - unhide = "keybind", - position = 6 + unhide = "keybind || holdkeybind", + position = 7 ) default Color color() { @@ -131,9 +144,9 @@ public interface AntiDragConfig extends Config keyName = "changeCursor", name = "Change Cursor", description = "Change cursor when you have anti-drag enabled.", - position = 7, + position = 8, hidden = true, - unhide = "keybind" + unhide = "keybind || holdkeybind" ) default boolean changeCursor() { @@ -145,11 +158,11 @@ public interface AntiDragConfig extends Config name = "Cursor", description = "Select which cursor you wish to use", hidden = true, - unhide = "keybind", - position = 8 + unhide = "changeCursor", + position = 9 ) default CustomCursor selectedCursor() { - return CustomCursor.DRAGON_SCIMITAR; + return CustomCursor.RS3_GOLD; } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/antidrag/AntiDragPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/antidrag/AntiDragPlugin.java index 7eeefe22ed..aab7bd37d1 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/antidrag/AntiDragPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/antidrag/AntiDragPlugin.java @@ -42,7 +42,6 @@ import net.runelite.client.input.KeyManager; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.plugins.PluginType; -import net.runelite.client.plugins.customcursor.CustomCursorConfig; import net.runelite.client.ui.ClientUI; import net.runelite.client.ui.overlay.OverlayManager; import net.runelite.client.util.HotkeyListener; @@ -93,6 +92,7 @@ public class AntiDragPlugin extends Plugin private boolean alwaysOn; private boolean keybind; + private boolean holdkeybind; private Keybind key; private int dragDelay; private boolean reqfocus; @@ -109,7 +109,7 @@ public class AntiDragPlugin extends Plugin addSubscriptions(); updateConfig(); - if (this.keybind) + if (this.keybind || this.holdkeybind) { keyManager.registerKeyListener(hotkeyListener); } @@ -125,6 +125,7 @@ public class AntiDragPlugin extends Plugin keyManager.unregisterKeyListener(hotkeyListener); toggleDrag = false; overlayManager.remove(overlay); + clientUI.resetCursor(); } private void addSubscriptions() @@ -151,6 +152,18 @@ public class AntiDragPlugin extends Plugin keyManager.unregisterKeyListener(hotkeyListener); } } + if + (event.getKey().equals(("holdkeybind"))) + { + if (this.holdkeybind) + { + keyManager.registerKeyListener(hotkeyListener); + } + else + { + keyManager.unregisterKeyListener(hotkeyListener); + } + } if (event.getKey().equals("alwaysOn")) { client.setInventoryDragDelay(this.alwaysOn ? this.dragDelay : DEFAULT_DELAY); @@ -159,6 +172,10 @@ public class AntiDragPlugin extends Plugin { client.setInventoryDragDelay(this.dragDelay); } + if (event.getKey().equals(("changeCursor"))) + { + clientUI.resetCursor(); + } } } @@ -167,7 +184,7 @@ public class AntiDragPlugin extends Plugin switch (event.getGameState()) { case LOGGED_IN: - if (keybind) + if (keybind || holdkeybind) { keyManager.registerKeyListener(hotkeyListener); } @@ -181,6 +198,7 @@ public class AntiDragPlugin extends Plugin { this.alwaysOn = config.alwaysOn(); this.keybind = config.keybind(); + this.holdkeybind = config.holdkeybind(); this.key = config.key(); this.dragDelay = config.dragDelay(); this.reqfocus = config.reqfocus(); @@ -227,12 +245,38 @@ public class AntiDragPlugin extends Plugin { overlayManager.remove(overlay); client.setInventoryDragDelay(DEFAULT_DELAY); + clientUI.resetCursor(); + } + } + + @Override + public void hotkeyReleased() + { + if (alwaysOn) + { + return; + } + + toggleDrag = !toggleDrag; + if (toggleDrag) + { + if (configOverlay) + { + overlayManager.add(overlay); + } if (changeCursor) { - net.runelite.client.plugins.customcursor.CustomCursor selectedCursor = configManager.getConfig(CustomCursorConfig.class).selectedCursor(); clientUI.setCursor(selectedCursor.getCursorImage(), selectedCursor.toString()); } + + client.setInventoryDragDelay(dragDelay); + } + else + { + overlayManager.remove(overlay); + client.setInventoryDragDelay(DEFAULT_DELAY); + clientUI.resetCursor(); } } }; -} \ No newline at end of file +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/antidrag/CustomCursor.java b/runelite-client/src/main/java/net/runelite/client/plugins/antidrag/CustomCursor.java index e6e3b5da8e..16b965f979 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/antidrag/CustomCursor.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/antidrag/CustomCursor.java @@ -35,13 +35,15 @@ public enum CustomCursor RS3_GOLD("RS3 Gold", "cursor-rs3-gold.png"), RS3_SILVER("RS3 Silver", "cursor-rs3-silver.png"), DRAGON_DAGGER("Dragon Dagger", "cursor-dragon-dagger.png"), + DRAGON_DAGGER_POISON("Dragon Dagger (p)", "cursor-dragon-dagger-p.png"), TROUT("Trout", "cursor-trout.png"), DRAGON_SCIMITAR("Dragon Scimitar", "cursor-dragon-scimitar.png"), ARMADYL_GODSWORD("Armadyl Godsword", "cursor-armadyl-godsword.png"), BANDOS_GODSWORD("Bandos Godsword", "cursor-bandos-godsword.png"), MOUSE("Mouse", "cursor-mouse.png"), SARADOMIN_GODSWORD("Saradomin Godsword", "cursor-saradomin-godsword.png"), - ZAMORAK_GODSWORD("Zamorak Godsword", "cursor-zamorak-godsword.png"); + ZAMORAK_GODSWORD("Zamorak Godsword", "cursor-zamorak-godsword.png"), + SKILL_SPECS("Skill Specs", "cursor-skill-specs.png"); private final String name;