diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemHotkeyListener.java b/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemHotkeyListener.java new file mode 100644 index 0000000000..a83210b0a7 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemHotkeyListener.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2018, Seth + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.plugins.grounditems; + +import java.time.Duration; +import java.time.Instant; +import javax.inject.Inject; +import net.runelite.client.util.HotkeyListener; + +class GroundItemHotkeyListener extends HotkeyListener +{ + private final GroundItemsPlugin plugin; + private final GroundItemsConfig config; + + private Instant lastPress; + + @Inject + private GroundItemHotkeyListener(GroundItemsPlugin plugin, GroundItemsConfig config) + { + super(config::hotkey); + + this.plugin = plugin; + this.config = config; + } + + @Override + public void hotkeyPressed() + { + if (plugin.isHideAll()) + { + plugin.setHideAll(false); + plugin.setHotKeyPressed(true); + lastPress = null; + } + else if (lastPress != null && !plugin.isHotKeyPressed() && config.doubleTapDelay() > 0 && Duration.between(lastPress, Instant.now()).compareTo(Duration.ofMillis(config.doubleTapDelay())) < 0) + { + plugin.setHideAll(true); + lastPress = null; + } + else + { + plugin.setHotKeyPressed(true); + lastPress = Instant.now(); + } + } + + @Override + public void hotkeyReleased() + { + plugin.setHotKeyPressed(false); + plugin.setTextBoxBounds(null); + plugin.setHiddenBoxBounds(null); + plugin.setHighlightBoxBounds(null); + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemInputListener.java b/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemMouseAdapter.java similarity index 71% rename from runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemInputListener.java rename to runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemMouseAdapter.java index da6c3a80c5..a61be015db 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemInputListener.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemMouseAdapter.java @@ -25,69 +25,16 @@ package net.runelite.client.plugins.grounditems; import java.awt.Point; -import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; -import java.time.Duration; -import java.time.Instant; import javax.inject.Inject; import javax.swing.SwingUtilities; -import net.runelite.client.input.KeyListener; import net.runelite.client.input.MouseAdapter; -public class GroundItemInputListener extends MouseAdapter implements KeyListener +class GroundItemMouseAdapter extends MouseAdapter { - private static final int HOTKEY = KeyEvent.VK_ALT; - - private Instant lastPress; - @Inject private GroundItemsPlugin plugin; - @Inject - private GroundItemsConfig config; - - @Override - public void keyTyped(KeyEvent e) - { - - } - - @Override - public void keyPressed(KeyEvent e) - { - if (e.getKeyCode() == HOTKEY) - { - if (plugin.isHideAll()) - { - plugin.setHideAll(false); - plugin.setHotKeyPressed(true); - lastPress = null; - } - else if (lastPress != null && !plugin.isHotKeyPressed() && config.doubleTapDelay() > 0 && Duration.between(lastPress, Instant.now()).compareTo(Duration.ofMillis(config.doubleTapDelay())) < 0) - { - plugin.setHideAll(true); - lastPress = null; - } - else - { - plugin.setHotKeyPressed(true); - lastPress = Instant.now(); - } - } - } - - @Override - public void keyReleased(KeyEvent e) - { - if (e.getKeyCode() == HOTKEY) - { - plugin.setHotKeyPressed(false); - plugin.setTextBoxBounds(null); - plugin.setHiddenBoxBounds(null); - plugin.setHighlightBoxBounds(null); - } - } - @Override public MouseEvent mousePressed(MouseEvent e) { @@ -134,4 +81,3 @@ public class GroundItemInputListener extends MouseAdapter implements KeyListener return e; } } - diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsConfig.java index 5869c07208..1031765645 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsConfig.java @@ -30,8 +30,9 @@ 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.Units; import net.runelite.client.config.ConfigSection; +import net.runelite.client.config.Keybind; +import net.runelite.client.config.Units; import net.runelite.client.plugins.grounditems.config.DespawnTimerMode; import net.runelite.client.plugins.grounditems.config.HighlightTier; import net.runelite.client.plugins.grounditems.config.ItemHighlightMode; @@ -447,4 +448,15 @@ public interface GroundItemsConfig extends Config { return Lootbeam.Style.MODERN; } + + @ConfigItem( + keyName = "hotkey", + name = "Hotkey", + description = "Configures the hotkey used by the Ground Items plugin", + position = 33 + ) + default Keybind hotkey() + { + return Keybind.ALT; + } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsPlugin.java index af5282db14..c4524bf353 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsPlugin.java @@ -140,7 +140,10 @@ public class GroundItemsPlugin extends Plugin private List highlightedItemsList = new CopyOnWriteArrayList<>(); @Inject - private GroundItemInputListener inputListener; + private GroundItemHotkeyListener hotkeyListener; + + @Inject + private GroundItemMouseAdapter mouseAdapter; @Inject private MouseManager mouseManager; @@ -191,8 +194,8 @@ public class GroundItemsPlugin extends Plugin protected void startUp() { overlayManager.add(overlay); - mouseManager.registerMouseListener(inputListener); - keyManager.registerKeyListener(inputListener); + mouseManager.registerMouseListener(mouseAdapter); + keyManager.registerKeyListener(hotkeyListener); executor.execute(this::reset); lastUsedItem = -1; } @@ -201,8 +204,8 @@ public class GroundItemsPlugin extends Plugin protected void shutDown() { overlayManager.remove(overlay); - mouseManager.unregisterMouseListener(inputListener); - keyManager.unregisterKeyListener(inputListener); + mouseManager.unregisterMouseListener(mouseAdapter); + keyManager.unregisterKeyListener(hotkeyListener); highlightedItems.invalidateAll(); highlightedItems = null; hiddenItems.invalidateAll(); diff --git a/runelite-client/src/main/java/net/runelite/client/util/HotkeyListener.java b/runelite-client/src/main/java/net/runelite/client/util/HotkeyListener.java index 2099564846..8451ca134b 100644 --- a/runelite-client/src/main/java/net/runelite/client/util/HotkeyListener.java +++ b/runelite-client/src/main/java/net/runelite/client/util/HotkeyListener.java @@ -85,10 +85,15 @@ public abstract class HotkeyListener implements KeyListener { isPressed = false; isConsumingTyped = false; + hotkeyReleased(); } } public void hotkeyPressed() { } + + public void hotkeyReleased() + { + } }