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.
This commit is contained in:
LoneVV
2019-09-28 18:46:50 +03:00
committed by Kyle
parent 9258c8eff8
commit 18438626c4
3 changed files with 83 additions and 24 deletions

View File

@@ -42,8 +42,8 @@ public interface AntiDragConfig extends Config
keyName = "alwaysOn", keyName = "alwaysOn",
name = "Always On", name = "Always On",
description = "Makes the anti-drag always active and disables the hotkey toggle", description = "Makes the anti-drag always active and disables the hotkey toggle",
disabledBy = "keybind", disabledBy = "keybind || holdkeybind",
hide = "keybind" hide = "keybind || holdkeybind"
) )
default boolean alwaysOn() default boolean alwaysOn()
{ {
@@ -55,21 +55,34 @@ public interface AntiDragConfig extends Config
keyName = "keybind", keyName = "keybind",
name = "Toggle with Keybind", name = "Toggle with Keybind",
description = "Toggle anti drag on and off, rather than always on.", description = "Toggle anti drag on and off, rather than always on.",
disabledBy = "alwaysOn", disabledBy = "alwaysOn || holdkeybind",
hide = "alwaysOn" hide = "alwaysOn || holdkeybind"
) )
default boolean keybind() default boolean keybind()
{ {
return false; 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( @ConfigItem(
keyName = "key", keyName = "key",
name = "Keybind", name = "Keybind",
description = "The keybind you want to use for antidrag", description = "The keybind you want to use for antidrag",
position = 2, position = 3,
hidden = true, hidden = true,
unhide = "keybind" unhide = "keybind || holdkeybind"
) )
default Keybind key() default Keybind key()
{ {
@@ -80,7 +93,7 @@ public interface AntiDragConfig extends Config
keyName = "dragDelay", keyName = "dragDelay",
name = "Drag Delay", name = "Drag Delay",
description = "Configures the inventory drag delay in client ticks (20ms)", description = "Configures the inventory drag delay in client ticks (20ms)",
position = 3 position = 4
) )
default int dragDelay() default int dragDelay()
{ {
@@ -91,9 +104,9 @@ public interface AntiDragConfig extends Config
keyName = "reqfocus", keyName = "reqfocus",
name = "Reset on focus loss", name = "Reset on focus loss",
description = "Disable antidrag when losing focus (like alt tabbing)", description = "Disable antidrag when losing focus (like alt tabbing)",
position = 4, position = 5,
hidden = true, hidden = true,
unhide = "keybind" unhide = "keybind || holdkeybind"
) )
default boolean reqfocus() default boolean reqfocus()
{ {
@@ -104,9 +117,9 @@ public interface AntiDragConfig extends Config
keyName = "overlay", keyName = "overlay",
name = "Enable overlay", name = "Enable overlay",
description = "Do you really need a description?", description = "Do you really need a description?",
position = 5, position = 6,
hidden = true, hidden = true,
unhide = "keybind" unhide = "keybind || holdkeybind"
) )
default boolean overlay() default boolean overlay()
{ {
@@ -119,8 +132,8 @@ public interface AntiDragConfig extends Config
name = "Overlay color", name = "Overlay color",
description = "Change the overlay color, duh", description = "Change the overlay color, duh",
hidden = true, hidden = true,
unhide = "keybind", unhide = "keybind || holdkeybind",
position = 6 position = 7
) )
default Color color() default Color color()
{ {
@@ -131,9 +144,9 @@ public interface AntiDragConfig extends Config
keyName = "changeCursor", keyName = "changeCursor",
name = "Change Cursor", name = "Change Cursor",
description = "Change cursor when you have anti-drag enabled.", description = "Change cursor when you have anti-drag enabled.",
position = 7, position = 8,
hidden = true, hidden = true,
unhide = "keybind" unhide = "keybind || holdkeybind"
) )
default boolean changeCursor() default boolean changeCursor()
{ {
@@ -145,11 +158,11 @@ public interface AntiDragConfig extends Config
name = "Cursor", name = "Cursor",
description = "Select which cursor you wish to use", description = "Select which cursor you wish to use",
hidden = true, hidden = true,
unhide = "keybind", unhide = "changeCursor",
position = 8 position = 9
) )
default CustomCursor selectedCursor() default CustomCursor selectedCursor()
{ {
return CustomCursor.DRAGON_SCIMITAR; return CustomCursor.RS3_GOLD;
} }
} }

View File

@@ -42,7 +42,6 @@ import net.runelite.client.input.KeyManager;
import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.plugins.PluginType; import net.runelite.client.plugins.PluginType;
import net.runelite.client.plugins.customcursor.CustomCursorConfig;
import net.runelite.client.ui.ClientUI; import net.runelite.client.ui.ClientUI;
import net.runelite.client.ui.overlay.OverlayManager; import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.util.HotkeyListener; import net.runelite.client.util.HotkeyListener;
@@ -93,6 +92,7 @@ public class AntiDragPlugin extends Plugin
private boolean alwaysOn; private boolean alwaysOn;
private boolean keybind; private boolean keybind;
private boolean holdkeybind;
private Keybind key; private Keybind key;
private int dragDelay; private int dragDelay;
private boolean reqfocus; private boolean reqfocus;
@@ -109,7 +109,7 @@ public class AntiDragPlugin extends Plugin
addSubscriptions(); addSubscriptions();
updateConfig(); updateConfig();
if (this.keybind) if (this.keybind || this.holdkeybind)
{ {
keyManager.registerKeyListener(hotkeyListener); keyManager.registerKeyListener(hotkeyListener);
} }
@@ -125,6 +125,7 @@ public class AntiDragPlugin extends Plugin
keyManager.unregisterKeyListener(hotkeyListener); keyManager.unregisterKeyListener(hotkeyListener);
toggleDrag = false; toggleDrag = false;
overlayManager.remove(overlay); overlayManager.remove(overlay);
clientUI.resetCursor();
} }
private void addSubscriptions() private void addSubscriptions()
@@ -151,6 +152,18 @@ public class AntiDragPlugin extends Plugin
keyManager.unregisterKeyListener(hotkeyListener); keyManager.unregisterKeyListener(hotkeyListener);
} }
} }
if
(event.getKey().equals(("holdkeybind")))
{
if (this.holdkeybind)
{
keyManager.registerKeyListener(hotkeyListener);
}
else
{
keyManager.unregisterKeyListener(hotkeyListener);
}
}
if (event.getKey().equals("alwaysOn")) if (event.getKey().equals("alwaysOn"))
{ {
client.setInventoryDragDelay(this.alwaysOn ? this.dragDelay : DEFAULT_DELAY); client.setInventoryDragDelay(this.alwaysOn ? this.dragDelay : DEFAULT_DELAY);
@@ -159,6 +172,10 @@ public class AntiDragPlugin extends Plugin
{ {
client.setInventoryDragDelay(this.dragDelay); client.setInventoryDragDelay(this.dragDelay);
} }
if (event.getKey().equals(("changeCursor")))
{
clientUI.resetCursor();
}
} }
} }
@@ -167,7 +184,7 @@ public class AntiDragPlugin extends Plugin
switch (event.getGameState()) switch (event.getGameState())
{ {
case LOGGED_IN: case LOGGED_IN:
if (keybind) if (keybind || holdkeybind)
{ {
keyManager.registerKeyListener(hotkeyListener); keyManager.registerKeyListener(hotkeyListener);
} }
@@ -181,6 +198,7 @@ public class AntiDragPlugin extends Plugin
{ {
this.alwaysOn = config.alwaysOn(); this.alwaysOn = config.alwaysOn();
this.keybind = config.keybind(); this.keybind = config.keybind();
this.holdkeybind = config.holdkeybind();
this.key = config.key(); this.key = config.key();
this.dragDelay = config.dragDelay(); this.dragDelay = config.dragDelay();
this.reqfocus = config.reqfocus(); this.reqfocus = config.reqfocus();
@@ -227,12 +245,38 @@ public class AntiDragPlugin extends Plugin
{ {
overlayManager.remove(overlay); overlayManager.remove(overlay);
client.setInventoryDragDelay(DEFAULT_DELAY); client.setInventoryDragDelay(DEFAULT_DELAY);
clientUI.resetCursor();
}
}
@Override
public void hotkeyReleased()
{
if (alwaysOn)
{
return;
}
toggleDrag = !toggleDrag;
if (toggleDrag)
{
if (configOverlay)
{
overlayManager.add(overlay);
}
if (changeCursor) if (changeCursor)
{ {
net.runelite.client.plugins.customcursor.CustomCursor selectedCursor = configManager.getConfig(CustomCursorConfig.class).selectedCursor();
clientUI.setCursor(selectedCursor.getCursorImage(), selectedCursor.toString()); clientUI.setCursor(selectedCursor.getCursorImage(), selectedCursor.toString());
} }
client.setInventoryDragDelay(dragDelay);
}
else
{
overlayManager.remove(overlay);
client.setInventoryDragDelay(DEFAULT_DELAY);
clientUI.resetCursor();
} }
} }
}; };
} }

View File

@@ -35,13 +35,15 @@ public enum CustomCursor
RS3_GOLD("RS3 Gold", "cursor-rs3-gold.png"), RS3_GOLD("RS3 Gold", "cursor-rs3-gold.png"),
RS3_SILVER("RS3 Silver", "cursor-rs3-silver.png"), RS3_SILVER("RS3 Silver", "cursor-rs3-silver.png"),
DRAGON_DAGGER("Dragon Dagger", "cursor-dragon-dagger.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"), TROUT("Trout", "cursor-trout.png"),
DRAGON_SCIMITAR("Dragon Scimitar", "cursor-dragon-scimitar.png"), DRAGON_SCIMITAR("Dragon Scimitar", "cursor-dragon-scimitar.png"),
ARMADYL_GODSWORD("Armadyl Godsword", "cursor-armadyl-godsword.png"), ARMADYL_GODSWORD("Armadyl Godsword", "cursor-armadyl-godsword.png"),
BANDOS_GODSWORD("Bandos Godsword", "cursor-bandos-godsword.png"), BANDOS_GODSWORD("Bandos Godsword", "cursor-bandos-godsword.png"),
MOUSE("Mouse", "cursor-mouse.png"), MOUSE("Mouse", "cursor-mouse.png"),
SARADOMIN_GODSWORD("Saradomin Godsword", "cursor-saradomin-godsword.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; private final String name;