From a42906edbe213e7fc6ba04ecbb1744b0643056ca Mon Sep 17 00:00:00 2001 From: Max Weber Date: Sat, 16 Jun 2018 19:01:28 -0600 Subject: [PATCH] screenshot plugin: Allow hotkey to be changed from insert --- .../net/runelite/client/config/Keybind.java | 12 ++-- .../plugins/screenshot/ScreenshotConfig.java | 13 ++-- .../plugins/screenshot/ScreenshotInput.java | 67 ------------------- .../plugins/screenshot/ScreenshotPlugin.java | 17 +++-- 4 files changed, 25 insertions(+), 84 deletions(-) delete mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotInput.java diff --git a/runelite-client/src/main/java/net/runelite/client/config/Keybind.java b/runelite-client/src/main/java/net/runelite/client/config/Keybind.java index 3132da815b..9148ce40d9 100644 --- a/runelite-client/src/main/java/net/runelite/client/config/Keybind.java +++ b/runelite-client/src/main/java/net/runelite/client/config/Keybind.java @@ -37,12 +37,6 @@ import lombok.Getter; @Getter public class Keybind { - public static final Keybind NOT_SET = new Keybind(KeyEvent.VK_UNDEFINED, 0); - - public static final Keybind CTRL = new Keybind(KeyEvent.VK_UNDEFINED, InputEvent.CTRL_DOWN_MASK); - public static final Keybind ALT = new Keybind(KeyEvent.VK_UNDEFINED, InputEvent.ALT_DOWN_MASK); - public static final Keybind SHIFT = new Keybind(KeyEvent.VK_UNDEFINED, InputEvent.SHIFT_DOWN_MASK); - private static final BiMap modifierToKeyCode = new ImmutableBiMap.Builder() .put(InputEvent.CTRL_DOWN_MASK, KeyEvent.VK_CONTROL) .put(InputEvent.ALT_DOWN_MASK, KeyEvent.VK_ALT) @@ -54,6 +48,12 @@ public class Keybind private static final int KEYBOARD_MODIFIER_MASK = modifierToKeyCode.keySet().stream() .reduce((a, b) -> a | b).get(); + public static final Keybind NOT_SET = new Keybind(KeyEvent.VK_UNDEFINED, 0); + + public static final Keybind CTRL = new Keybind(KeyEvent.VK_UNDEFINED, InputEvent.CTRL_DOWN_MASK); + public static final Keybind ALT = new Keybind(KeyEvent.VK_UNDEFINED, InputEvent.ALT_DOWN_MASK); + public static final Keybind SHIFT = new Keybind(KeyEvent.VK_UNDEFINED, InputEvent.SHIFT_DOWN_MASK); + private final int keyCode; private final int modifiers; diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotConfig.java index 42a588c778..ea1b5a842f 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotConfig.java @@ -27,6 +27,7 @@ package net.runelite.client.plugins.screenshot; import net.runelite.client.config.Config; import net.runelite.client.config.ConfigGroup; import net.runelite.client.config.ConfigItem; +import net.runelite.client.config.Keybind; @ConfigGroup( keyName = "screenshot", @@ -124,14 +125,14 @@ public interface ScreenshotConfig extends Config } @ConfigItem( - keyName = "enableShortcut", - name = "Screenshot with [Insert]", - description = "Configures whether or not screenshots can be taken with the Insert key", - position = 8 + keyName = "hotkey", + name = "Screenshot hotkey", + description = "When you press this key a screenshot will be taken", + position = 10 ) - default boolean isScreenshotEnabled() + default Keybind hotkey() { - return false; + return Keybind.NOT_SET; } @ConfigItem( diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotInput.java b/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotInput.java deleted file mode 100644 index 0501332eef..0000000000 --- a/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotInput.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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.screenshot; - -import java.awt.event.KeyEvent; -import java.util.Date; -import javax.inject.Inject; -import net.runelite.client.input.KeyListener; -import static net.runelite.client.plugins.screenshot.ScreenshotPlugin.format; - -public class ScreenshotInput implements KeyListener -{ - private final ScreenshotConfig config; - private final ScreenshotPlugin plugin; - - @Inject - ScreenshotInput(ScreenshotConfig config, ScreenshotPlugin plugin) - { - this.config = config; - this.plugin = plugin; - } - - @Override - public void keyPressed(KeyEvent event) - { - } - - @Override - public void keyTyped(KeyEvent event) - { - } - - @Override - public void keyReleased(KeyEvent event) - { - if (!config.isScreenshotEnabled()) - return; - - if (event.getKeyCode() == KeyEvent.VK_INSERT) - { - plugin.takeScreenshot(format(new Date())); - } - } - -} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotPlugin.java index fbf2922a18..36e994d0cc 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotPlugin.java @@ -82,6 +82,7 @@ import net.runelite.client.ui.DrawManager; import net.runelite.client.ui.NavigationButton; import net.runelite.client.ui.TitleToolbar; import net.runelite.client.ui.overlay.OverlayManager; +import net.runelite.client.util.HotkeyListener; import net.runelite.client.util.Text; import net.runelite.http.api.RuneLiteAPI; import okhttp3.Call; @@ -155,9 +156,6 @@ public class ScreenshotPlugin extends Plugin @Inject private DrawManager drawManager; - @Inject - private ScreenshotInput inputListener; - @Inject private ScheduledExecutorService executor; @@ -166,6 +164,15 @@ public class ScreenshotPlugin extends Plugin private NavigationButton titleBarButton; + private final HotkeyListener hotkeyListener = new HotkeyListener(() -> config.hotkey()) + { + @Override + public void hotkeyReleased() + { + takeScreenshot(format(new Date())); + } + }; + @Provides ScreenshotConfig getConfig(ConfigManager configManager) { @@ -177,7 +184,7 @@ public class ScreenshotPlugin extends Plugin { overlayManager.add(screenshotOverlay); SCREENSHOT_DIR.mkdirs(); - keyManager.registerKeyListener(inputListener); + keyManager.registerKeyListener(hotkeyListener); try { @@ -221,7 +228,7 @@ public class ScreenshotPlugin extends Plugin { overlayManager.remove(screenshotOverlay); titleToolbar.removeNavigation(titleBarButton); - keyManager.unregisterKeyListener(inputListener); + keyManager.unregisterKeyListener(hotkeyListener); } @Subscribe