Antidrag: Add overlay, customizable keybinds (#99)
This commit is contained in:
@@ -24,16 +24,16 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.antidrag;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.event.KeyEvent;
|
||||
import net.runelite.client.config.Alpha;
|
||||
import net.runelite.client.config.Config;
|
||||
import net.runelite.client.config.ConfigGroup;
|
||||
import net.runelite.client.config.ConfigItem;
|
||||
import net.runelite.client.config.Keybind;
|
||||
import net.runelite.client.config.ModifierlessKeybind;
|
||||
|
||||
/*@ConfigGroup(
|
||||
keyName = "antiDrag",
|
||||
name = "Anti Drag",
|
||||
description = "Configuration for the anti drag plugin"
|
||||
)*/
|
||||
@ConfigGroup("antidrag")
|
||||
@ConfigGroup("antiDrag")
|
||||
public interface AntiDragConfig extends Config
|
||||
{
|
||||
@ConfigItem(
|
||||
@@ -46,4 +46,49 @@ public interface AntiDragConfig extends Config
|
||||
{
|
||||
return 600 / 20; // one game tick
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "keybind",
|
||||
name = "keybind",
|
||||
description = "The keybind you want to use for antidrag",
|
||||
position = 2
|
||||
)
|
||||
default Keybind key()
|
||||
{
|
||||
return new ModifierlessKeybind(KeyEvent.VK_SHIFT, 0);
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "reqfocus",
|
||||
name = "Reset on focus loss",
|
||||
description = "Disable antidrag when losing focus (like alt tabbing)",
|
||||
position = 3
|
||||
)
|
||||
default boolean reqfocus()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "overlay",
|
||||
name = "Enable overlay",
|
||||
description = "Do you really need a description?",
|
||||
position = 4
|
||||
)
|
||||
default boolean overlay()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Alpha
|
||||
@ConfigItem(
|
||||
keyName = "color",
|
||||
name = "Overlay color",
|
||||
description = "Change the overlay color, duh",
|
||||
position = 5
|
||||
)
|
||||
default Color color()
|
||||
{
|
||||
return new Color(255, 0, 0, 30);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package net.runelite.client.plugins.antidrag;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
import net.runelite.client.ui.overlay.OverlayLayer;
|
||||
import net.runelite.client.ui.overlay.OverlayPosition;
|
||||
import net.runelite.client.ui.overlay.OverlayPriority;
|
||||
|
||||
@Singleton
|
||||
public class AntiDragOverlay extends Overlay
|
||||
{
|
||||
private static final int RADIUS = 20;
|
||||
|
||||
private Client client;
|
||||
private AntiDragConfig config;
|
||||
|
||||
@Inject
|
||||
private AntiDragOverlay(Client client, AntiDragConfig config)
|
||||
{
|
||||
this.config = config;
|
||||
this.client = client;
|
||||
setPosition(OverlayPosition.TOOLTIP);
|
||||
setPriority(OverlayPriority.HIGHEST);
|
||||
setLayer(OverlayLayer.ALWAYS_ON_TOP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension render(Graphics2D g)
|
||||
{
|
||||
final Color color = config.color();
|
||||
g.setColor(color);
|
||||
|
||||
final net.runelite.api.Point mouseCanvasPosition = client.getMouseCanvasPosition();
|
||||
final Point mousePosition = new Point(mouseCanvasPosition.getX() - RADIUS, mouseCanvasPosition.getY() - RADIUS);
|
||||
final Rectangle bounds = new Rectangle(mousePosition.x, mousePosition.y, 2 * RADIUS, 2 * RADIUS);
|
||||
g.fillOval(bounds.x, bounds.y, bounds.height, bounds.width);
|
||||
|
||||
return bounds.getSize();
|
||||
}
|
||||
}
|
||||
@@ -24,26 +24,30 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.antidrag;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import com.google.inject.Provides;
|
||||
import java.awt.event.KeyEvent;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.events.FocusChanged;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.input.KeyListener;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
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.ui.overlay.OverlayManager;
|
||||
import net.runelite.client.util.HotkeyListener;
|
||||
|
||||
@PluginDescriptor(
|
||||
name = "Anti Drag",
|
||||
type = PluginType.UTILITY,
|
||||
enabledByDefault = false)
|
||||
public class AntiDragPlugin extends Plugin implements KeyListener
|
||||
name = "Shift Anti Drag",
|
||||
description = "Prevent dragging an item for a specified delay",
|
||||
tags = {"antidrag", "delay", "inventory", "items"},
|
||||
type = PluginType.UTILITY,
|
||||
enabledByDefault = false
|
||||
)
|
||||
public class AntiDragPlugin extends Plugin
|
||||
{
|
||||
private static final int DEFAULT_DELAY = 5;
|
||||
private boolean toggleDrag;
|
||||
|
||||
@Inject
|
||||
private Client client;
|
||||
@@ -51,6 +55,12 @@ public class AntiDragPlugin extends Plugin implements KeyListener
|
||||
@Inject
|
||||
private AntiDragConfig config;
|
||||
|
||||
@Inject
|
||||
private AntiDragOverlay overlay;
|
||||
|
||||
@Inject
|
||||
private OverlayManager overlayManager;
|
||||
|
||||
@Inject
|
||||
private KeyManager keyManager;
|
||||
|
||||
@@ -63,57 +73,50 @@ public class AntiDragPlugin extends Plugin implements KeyListener
|
||||
@Override
|
||||
protected void startUp() throws Exception
|
||||
{
|
||||
client.setInventoryDragDelay(config.dragDelay());
|
||||
keyManager.registerKeyListener(this);
|
||||
keyManager.registerKeyListener(hotkeyListener);
|
||||
toggleDrag = false;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void shutDown() throws Exception
|
||||
{
|
||||
client.setInventoryDragDelay(DEFAULT_DELAY);
|
||||
keyManager.unregisterKeyListener(this);
|
||||
keyManager.unregisterKeyListener(hotkeyListener);
|
||||
toggleDrag = false;
|
||||
overlayManager.remove(overlay);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e)
|
||||
private final HotkeyListener hotkeyListener = new HotkeyListener(() -> config.key())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public boolean toggleDrag = true;
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e)
|
||||
{
|
||||
/*if (e.getKeyCode() == KeyEvent.VK_SHIFT)
|
||||
@Override
|
||||
public void hotkeyPressed()
|
||||
{
|
||||
client.setInventoryDragDelay(config.dragDelay());
|
||||
toggleDrag = !toggleDrag;
|
||||
if (toggleDrag)
|
||||
{
|
||||
if (config.overlay())
|
||||
{
|
||||
overlayManager.add(overlay);
|
||||
}
|
||||
|
||||
client.setInventoryDragDelay(config.dragDelay());
|
||||
}
|
||||
else
|
||||
{
|
||||
overlayManager.remove(overlay);
|
||||
client.setInventoryDragDelay(DEFAULT_DELAY);
|
||||
}
|
||||
}
|
||||
client.setInventoryDragDelay(config.dragDelay());*/
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e)
|
||||
{
|
||||
if (e.getKeyCode() == KeyEvent.VK_CONTROL && toggleDrag) {
|
||||
|
||||
toggleDrag = false;
|
||||
client.setInventoryDragDelay(DEFAULT_DELAY);
|
||||
|
||||
} else if (e.getKeyCode() == KeyEvent.VK_CONTROL && !toggleDrag) {
|
||||
|
||||
toggleDrag = true;
|
||||
client.setInventoryDragDelay(config.dragDelay());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*@Subscribe
|
||||
@Subscribe
|
||||
public void onFocusChanged(FocusChanged focusChanged)
|
||||
{
|
||||
if (!focusChanged.isFocused())
|
||||
if (!focusChanged.isFocused() && config.reqfocus())
|
||||
{
|
||||
client.setInventoryDragDelay(DEFAULT_DELAY);
|
||||
overlayManager.remove(overlay);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user