antidrag: Add option to use CTRL to disable delay

This allows users who enable the plugin to temporarily allow item
dragging to reorganize their inventory without fully toggling the plugin
off and on again.

Co-authored-by: Jordan <nightfirecat@protonmail.com>
This commit is contained in:
Jacob Lindelof
2020-06-02 21:45:01 -07:00
committed by Jordan Atwood
parent bda66e8da4
commit cc2ed2311b
2 changed files with 36 additions and 8 deletions

View File

@@ -53,4 +53,15 @@ public interface AntiDragConfig extends Config
{
return true;
}
@ConfigItem(
keyName = "disableOnCtrl",
name = "Disable On Control Pressed",
description = "Configures whether to ignore the delay while holding control.",
position = 3
)
default boolean disableOnCtrl()
{
return false;
}
}

View File

@@ -70,7 +70,8 @@ public class AntiDragPlugin extends Plugin implements KeyListener
private KeyManager keyManager;
private boolean inPvp;
private boolean held;
private boolean shiftHeld;
private boolean ctrlHeld;
@Provides
AntiDragConfig getConfig(ConfigManager configManager)
@@ -112,20 +113,30 @@ public class AntiDragPlugin extends Plugin implements KeyListener
@Override
public void keyPressed(KeyEvent e)
{
if (e.getKeyCode() == KeyEvent.VK_SHIFT && (inPvp || config.onShiftOnly()))
if (e.getKeyCode() == KeyEvent.VK_CONTROL && config.disableOnCtrl() && !(inPvp || config.onShiftOnly()))
{
resetDragDelay();
ctrlHeld = true;
}
else if (e.getKeyCode() == KeyEvent.VK_SHIFT && (inPvp || config.onShiftOnly()))
{
setDragDelay();
held = true;
shiftHeld = true;
}
}
@Override
public void keyReleased(KeyEvent e)
{
if (e.getKeyCode() == KeyEvent.VK_SHIFT && (inPvp || config.onShiftOnly()))
if (e.getKeyCode() == KeyEvent.VK_CONTROL && config.disableOnCtrl() && !(inPvp || config.onShiftOnly()))
{
setDragDelay();
ctrlHeld = false;
}
else if (e.getKeyCode() == KeyEvent.VK_SHIFT && (inPvp || config.onShiftOnly()))
{
resetDragDelay();
held = false;
shiftHeld = false;
}
}
@@ -134,9 +145,14 @@ public class AntiDragPlugin extends Plugin implements KeyListener
{
if (event.getGroup().equals(CONFIG_GROUP))
{
if (!config.disableOnCtrl())
{
ctrlHeld = false;
}
if (config.onShiftOnly() || inPvp)
{
held = false;
shiftHeld = false;
clientThread.invoke(this::resetDragDelay);
}
else
@@ -172,7 +188,8 @@ public class AntiDragPlugin extends Plugin implements KeyListener
{
if (!focusChanged.isFocused())
{
held = false;
shiftHeld = false;
ctrlHeld = false;
clientThread.invoke(this::resetDragDelay);
}
else if (!inPvp && !config.onShiftOnly())
@@ -184,7 +201,7 @@ public class AntiDragPlugin extends Plugin implements KeyListener
@Subscribe
public void onWidgetLoaded(WidgetLoaded widgetLoaded)
{
if (widgetLoaded.getGroupId() == WidgetID.BANK_GROUP_ID && (!config.onShiftOnly() || held))
if (widgetLoaded.getGroupId() == WidgetID.BANK_GROUP_ID && (!config.onShiftOnly() || shiftHeld) && !ctrlHeld)
{
setBankDragDelay(config.dragDelay());
}