ground items: make hotkey configurable
Co-authored-by: David Goldstein <goldstein.g.david@gmail.com>
This commit is contained in:
@@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, Seth <https://github.com/sethtroll>
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,69 +25,16 @@
|
|||||||
package net.runelite.client.plugins.grounditems;
|
package net.runelite.client.plugins.grounditems;
|
||||||
|
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
import java.awt.event.KeyEvent;
|
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.time.Duration;
|
|
||||||
import java.time.Instant;
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import net.runelite.client.input.KeyListener;
|
|
||||||
import net.runelite.client.input.MouseAdapter;
|
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
|
@Inject
|
||||||
private GroundItemsPlugin plugin;
|
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
|
@Override
|
||||||
public MouseEvent mousePressed(MouseEvent e)
|
public MouseEvent mousePressed(MouseEvent e)
|
||||||
{
|
{
|
||||||
@@ -134,4 +81,3 @@ public class GroundItemInputListener extends MouseAdapter implements KeyListener
|
|||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,8 +30,9 @@ import net.runelite.client.config.Alpha;
|
|||||||
import net.runelite.client.config.Config;
|
import net.runelite.client.config.Config;
|
||||||
import net.runelite.client.config.ConfigGroup;
|
import net.runelite.client.config.ConfigGroup;
|
||||||
import net.runelite.client.config.ConfigItem;
|
import net.runelite.client.config.ConfigItem;
|
||||||
import net.runelite.client.config.Units;
|
|
||||||
import net.runelite.client.config.ConfigSection;
|
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.DespawnTimerMode;
|
||||||
import net.runelite.client.plugins.grounditems.config.HighlightTier;
|
import net.runelite.client.plugins.grounditems.config.HighlightTier;
|
||||||
import net.runelite.client.plugins.grounditems.config.ItemHighlightMode;
|
import net.runelite.client.plugins.grounditems.config.ItemHighlightMode;
|
||||||
@@ -447,4 +448,15 @@ public interface GroundItemsConfig extends Config
|
|||||||
{
|
{
|
||||||
return Lootbeam.Style.MODERN;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,7 +140,10 @@ public class GroundItemsPlugin extends Plugin
|
|||||||
private List<String> highlightedItemsList = new CopyOnWriteArrayList<>();
|
private List<String> highlightedItemsList = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private GroundItemInputListener inputListener;
|
private GroundItemHotkeyListener hotkeyListener;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private GroundItemMouseAdapter mouseAdapter;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private MouseManager mouseManager;
|
private MouseManager mouseManager;
|
||||||
@@ -191,8 +194,8 @@ public class GroundItemsPlugin extends Plugin
|
|||||||
protected void startUp()
|
protected void startUp()
|
||||||
{
|
{
|
||||||
overlayManager.add(overlay);
|
overlayManager.add(overlay);
|
||||||
mouseManager.registerMouseListener(inputListener);
|
mouseManager.registerMouseListener(mouseAdapter);
|
||||||
keyManager.registerKeyListener(inputListener);
|
keyManager.registerKeyListener(hotkeyListener);
|
||||||
executor.execute(this::reset);
|
executor.execute(this::reset);
|
||||||
lastUsedItem = -1;
|
lastUsedItem = -1;
|
||||||
}
|
}
|
||||||
@@ -201,8 +204,8 @@ public class GroundItemsPlugin extends Plugin
|
|||||||
protected void shutDown()
|
protected void shutDown()
|
||||||
{
|
{
|
||||||
overlayManager.remove(overlay);
|
overlayManager.remove(overlay);
|
||||||
mouseManager.unregisterMouseListener(inputListener);
|
mouseManager.unregisterMouseListener(mouseAdapter);
|
||||||
keyManager.unregisterKeyListener(inputListener);
|
keyManager.unregisterKeyListener(hotkeyListener);
|
||||||
highlightedItems.invalidateAll();
|
highlightedItems.invalidateAll();
|
||||||
highlightedItems = null;
|
highlightedItems = null;
|
||||||
hiddenItems.invalidateAll();
|
hiddenItems.invalidateAll();
|
||||||
|
|||||||
@@ -85,10 +85,15 @@ public abstract class HotkeyListener implements KeyListener
|
|||||||
{
|
{
|
||||||
isPressed = false;
|
isPressed = false;
|
||||||
isConsumingTyped = false;
|
isConsumingTyped = false;
|
||||||
|
hotkeyReleased();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hotkeyPressed()
|
public void hotkeyPressed()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void hotkeyReleased()
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user