Clean up Anti-Drag Plugin (#798)

* Clean up Anti-Drag Plugin

* Cleanup Anti-Drag Config
This commit is contained in:
Ganom
2019-06-28 15:26:15 -04:00
committed by Kyleeld
parent 8b3a70d115
commit 23f6463024
2 changed files with 74 additions and 48 deletions

View File

@@ -37,33 +37,66 @@ import net.runelite.client.config.ModifierlessKeybind;
@ConfigGroup("antiDrag") @ConfigGroup("antiDrag")
public interface AntiDragConfig extends Config public interface AntiDragConfig extends Config
{ {
@ConfigItem( @ConfigItem(
keyName = "dragDelay", position = 0,
name = "Drag Delay", keyName = "alwaysOn",
description = "Configures the inventory drag delay in client ticks (20ms)", name = "Always On",
position = 1 description = "Makes the anti-drag always active and disables the hotkey toggle",
disabledBy = "keybind",
hide = "keybind"
) )
default int dragDelay() default boolean alwaysOn()
{ {
return Constants.GAME_TICK_LENGTH / Constants.CLIENT_TICK_LENGTH; // one game tick return false;
} }
@ConfigItem( @ConfigItem(
position = 1,
keyName = "keybind", keyName = "keybind",
name = "keybind", name = "Toggle with Keybind",
description = "Toggle anti drag on and off, rather than always on.",
disabledBy = "alwaysOn",
hide = "alwaysOn"
)
default boolean keybind()
{
return false;
}
@ConfigItem(
keyName = "key",
name = "Keybind",
description = "The keybind you want to use for antidrag", description = "The keybind you want to use for antidrag",
position = 2 position = 2,
hidden = true,
unhide = "keybind"
) )
default Keybind key() default Keybind key()
{ {
return new ModifierlessKeybind(KeyEvent.VK_SHIFT, 0); return new ModifierlessKeybind(KeyEvent.VK_SHIFT, 0);
} }
@ConfigItem(
keyName = "dragDelay",
name = "Drag Delay",
description = "Configures the inventory drag delay in client ticks (20ms)",
position = 3,
hidden = true,
unhide = "keybind"
)
default int dragDelay()
{
return Constants.GAME_TICK_LENGTH / Constants.CLIENT_TICK_LENGTH; // one game tick
}
@ConfigItem( @ConfigItem(
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 = 3 position = 4,
hidden = true,
unhide = "keybind"
) )
default boolean reqfocus() default boolean reqfocus()
{ {
@@ -74,7 +107,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 = 4 position = 5,
hidden = true,
unhide = "keybind"
) )
default boolean overlay() default boolean overlay()
{ {
@@ -87,8 +122,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 = "overlay", unhide = "keybind",
position = 5 position = 6
) )
default Color color() default Color color()
{ {
@@ -99,7 +134,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 = 6 position = 7,
hidden = true,
unhide = "keybind"
) )
default boolean changeCursor() default boolean changeCursor()
{ {
@@ -111,22 +148,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 = "changeCursor", unhide = "keybind",
position = 7 position = 8
) )
default CustomCursor selectedCursor() default CustomCursor selectedCursor()
{ {
return CustomCursor.DRAGON_SCIMITAR; return CustomCursor.DRAGON_SCIMITAR;
} }
@ConfigItem(
keyName = "alwaysOn",
name = "Always On",
description = "Makes the anti-drag always active and disables the hotkey toggle",
position = 8
)
default boolean alwaysOn()
{
return false;
}
} }

View File

@@ -52,7 +52,7 @@ import net.runelite.client.util.HotkeyListener;
public class AntiDragPlugin extends Plugin public class AntiDragPlugin extends Plugin
{ {
private static final int DEFAULT_DELAY = 5; private static final int DEFAULT_DELAY = 5;
private static final String CONFIG_GROUP_NAME = "antiDrag";
private boolean toggleDrag; private boolean toggleDrag;
@Inject @Inject
@@ -85,10 +85,11 @@ public class AntiDragPlugin extends Plugin
@Override @Override
protected void startUp() throws Exception protected void startUp() throws Exception
{ {
keyManager.registerKeyListener(hotkeyListener); if (config.keybind())
toggleDrag = config.alwaysOn(); {
enableAntiDrag(); keyManager.registerKeyListener(hotkeyListener);
}
client.setInventoryDragDelay(config.alwaysOn() ? config.dragDelay() : DEFAULT_DELAY);
} }
@Override @Override
@@ -103,10 +104,23 @@ public class AntiDragPlugin extends Plugin
@Subscribe @Subscribe
public void onConfigChanged(ConfigChanged event) public void onConfigChanged(ConfigChanged event)
{ {
if (event.getGroup().equals(CONFIG_GROUP_NAME)) if (event.getGroup().equals("antiDrag"))
{ {
toggleDrag = config.alwaysOn(); if (event.getKey().equals("keybind"))
enableAntiDrag(); {
if (config.keybind())
{
keyManager.registerKeyListener(hotkeyListener);
}
else
{
keyManager.unregisterKeyListener(hotkeyListener);
}
}
if (event.getKey().equals("alwaysOn"))
{
client.setInventoryDragDelay(config.alwaysOn() ? config.dragDelay() : DEFAULT_DELAY);
}
} }
} }
@@ -123,18 +137,6 @@ public class AntiDragPlugin extends Plugin
} }
} }
private void enableAntiDrag()
{
if (toggleDrag)
{
client.setInventoryDragDelay(config.dragDelay());
}
else
{
client.setInventoryDragDelay(DEFAULT_DELAY);
}
}
private final HotkeyListener hotkeyListener = new HotkeyListener(() -> config.key()) private final HotkeyListener hotkeyListener = new HotkeyListener(() -> config.key())
{ {
@Override @Override
@@ -170,6 +172,4 @@ public class AntiDragPlugin extends Plugin
} }
} }
}; };
} }