From 56e58585285f0f6253295930dfe0fb850bf365d1 Mon Sep 17 00:00:00 2001 From: se7enAte9 <50936458+se7enAte9@users.noreply.github.com> Date: Thu, 27 Jun 2019 17:06:38 -0400 Subject: [PATCH] keyremapping: merge entertochat plugin (#774) * keyremapping: merge with entertochat plugin * travis rebuild --- .../entertochat/EnterToChatListener.java | 135 ------------ .../entertochat/EnterToChatPlugin.java | 207 ------------------ .../keyremapping/KeyRemappingConfig.java | 11 + .../keyremapping/KeyRemappingPlugin.java | 39 +++- 4 files changed, 46 insertions(+), 346 deletions(-) delete mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/entertochat/EnterToChatListener.java delete mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/entertochat/EnterToChatPlugin.java diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/entertochat/EnterToChatListener.java b/runelite-client/src/main/java/net/runelite/client/plugins/entertochat/EnterToChatListener.java deleted file mode 100644 index 3dabc56600..0000000000 --- a/runelite-client/src/main/java/net/runelite/client/plugins/entertochat/EnterToChatListener.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (c) 2018, Adam - * Copyright (c) 2018, Abexlry - * 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.entertochat; - -import com.google.common.base.Strings; -import java.awt.event.KeyEvent; -import java.util.HashMap; -import java.util.Map; -import javax.inject.Inject; -import net.runelite.api.Client; -import net.runelite.api.GameState; -import net.runelite.api.VarClientStr; -import net.runelite.client.callback.ClientThread; -import net.runelite.client.input.KeyListener; -import net.runelite.client.input.MouseAdapter; - -class EnterToChatListener extends MouseAdapter implements KeyListener -{ - @Inject - private EnterToChatPlugin plugin; - - @Inject - private Client client; - - @Inject - private ClientThread clientThread; - - private final Map modified = new HashMap<>(); - - @Override - public void keyTyped(KeyEvent e) - { - } - - @Override - public void keyPressed(KeyEvent e) - { - if (client.getGameState() != GameState.LOGGED_IN || !plugin.chatboxFocused()) - { - return; - } - - if (!plugin.isTyping()) - { - switch (e.getKeyCode()) - { - case KeyEvent.VK_ENTER: - case KeyEvent.VK_SLASH: - case KeyEvent.VK_COLON: - // refocus chatbox - plugin.setTyping(true); - clientThread.invoke(() -> - { - plugin.unlockChat(); - }); - break; - } - } - else - { - switch (e.getKeyCode()) - { - case KeyEvent.VK_ENTER: - plugin.setTyping(false); - clientThread.invoke(() -> - { - plugin.lockChat(); - }); - break; - case KeyEvent.VK_ESCAPE: - plugin.setTyping(false); - clientThread.invoke(() -> - { - client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, ""); - plugin.lockChat(); - }); - break; - case KeyEvent.VK_BACK_SPACE: - if (Strings.isNullOrEmpty(client.getVar(VarClientStr.CHATBOX_TYPED_TEXT))) - { - plugin.setTyping(false); - clientThread.invoke(() -> plugin.lockChat()); - } - } - } - } - - @Override - public void keyReleased(KeyEvent e) - { - if (client.getGameState() != GameState.LOGGED_IN) - { - return; - } - - if (plugin.chatboxFocused() && !plugin.isTyping()) - { - modified.remove(e.getKeyCode()); - - } - else - { - // press d + enter + release d - causes the right arrow to never be released - Integer m = modified.get(e.getKeyCode()); - if (m != null) - { - modified.remove(e.getKeyCode()); - e.setKeyCode(m); - } - } - } -} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/entertochat/EnterToChatPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/entertochat/EnterToChatPlugin.java deleted file mode 100644 index c8e5edfbb1..0000000000 --- a/runelite-client/src/main/java/net/runelite/client/plugins/entertochat/EnterToChatPlugin.java +++ /dev/null @@ -1,207 +0,0 @@ -/*' - * Copyright (c) 2018, Adam - * Copyright (c) 2018, Abexlry - * 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.entertochat; - -import java.awt.Color; -import javax.inject.Inject; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.Setter; -import net.runelite.api.Client; -import net.runelite.api.GameState; -import net.runelite.api.IconID; -import net.runelite.api.VarClientInt; -import net.runelite.api.VarClientStr; -import net.runelite.api.Varbits; -import net.runelite.api.events.ScriptCallbackEvent; -import net.runelite.api.widgets.Widget; -import net.runelite.api.widgets.WidgetInfo; -import net.runelite.client.callback.ClientThread; -import net.runelite.client.config.ConfigManager; -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.JagexColors; -import net.runelite.client.util.ColorUtil; - -@PluginDescriptor( - name = "Press Enter to Chat", - description = "'Press Enter to Chat'", - tags = {"enter", "chat"}, - type = PluginType.UTILITY, - enabledByDefault = false -) - -public class EnterToChatPlugin extends Plugin -{ - private static final String PRESS_ENTER_TO_CHAT = "Press Enter to Chat..."; - private static final String SCRIPT_EVENT_SET_CHATBOX_INPUT = "setChatboxInput"; - private static final String SCRIPT_EVENT_BLOCK_CHAT_INPUT = "blockChatInput"; - - @Inject - private Client client; - - @Inject - private ClientThread clientThread; - - @Inject - private ConfigManager configManager; - - @Inject - private KeyManager keyManager; - - @Inject - private EnterToChatListener inputListener; - - @Getter(AccessLevel.PACKAGE) - @Setter(AccessLevel.PACKAGE) - private boolean typing; - - @Override - protected void startUp() throws Exception - { - configManager.setConfiguration("runelite", "wasdcameraplugin", false); - typing = false; - keyManager.registerKeyListener(inputListener); - - clientThread.invoke(() -> - { - if (client.getGameState() == GameState.LOGGED_IN) - { - lockChat(); - } - }); - } - - @Override - protected void shutDown() throws Exception - { - clientThread.invoke(() -> - { - if (client.getGameState() == GameState.LOGGED_IN) - { - unlockChat(); - } - }); - - keyManager.unregisterKeyListener(inputListener); - } - - - boolean chatboxFocused() - { - Widget chatboxParent = client.getWidget(WidgetInfo.CHATBOX_PARENT); - if (chatboxParent == null || chatboxParent.getOnKeyListener() == null) - { - return false; - } - - // the search box on the world map can be focused, and chat input goes there, even - // though the chatbox still has its key listener. - Widget worldMapSearch = client.getWidget(WidgetInfo.WORLD_MAP_SEARCH); - return worldMapSearch == null || client.getVar(VarClientInt.WORLD_MAP_SEARCH_FOCUSED) != 1; - - } - - @Subscribe - public void onScriptCallbackEvent(ScriptCallbackEvent scriptCallbackEvent) - { - switch (scriptCallbackEvent.getEventName()) - { - case SCRIPT_EVENT_SET_CHATBOX_INPUT: - Widget chatboxInput = client.getWidget(WidgetInfo.CHATBOX_INPUT); - if (chatboxInput != null) - { - if (chatboxFocused() && !typing) - { - chatboxInput.setText(PRESS_ENTER_TO_CHAT); - } - } - break; - case SCRIPT_EVENT_BLOCK_CHAT_INPUT: - if (!typing) - { - int[] intStack = client.getIntStack(); - int intStackSize = client.getIntStackSize(); - intStack[intStackSize - 1] = 1; - } - break; - } - } - - void lockChat() - { - Widget chatboxParent = client.getWidget(WidgetInfo.CHATBOX_PARENT); - if (chatboxParent != null && chatboxParent.getOnKeyListener() != null) - { - Widget chatboxInput = client.getWidget(WidgetInfo.CHATBOX_INPUT); - if (chatboxInput != null) - { - chatboxInput.setText(PRESS_ENTER_TO_CHAT); - } - } - } - - void unlockChat() - { - Widget chatboxParent = client.getWidget(WidgetInfo.CHATBOX_PARENT); - if (chatboxParent != null) - { - Widget chatboxInput = client.getWidget(WidgetInfo.CHATBOX_INPUT); - if (chatboxInput != null) - { - if (client.getGameState() == GameState.LOGGED_IN) - { - final boolean isChatboxTransparent = client.isResized() && client.getVar(Varbits.TRANSPARENT_CHATBOX) == 1; - final Color textColor = isChatboxTransparent ? JagexColors.CHAT_TYPED_TEXT_TRANSPARENT_BACKGROUND : JagexColors.CHAT_TYPED_TEXT_OPAQUE_BACKGROUND; - chatboxInput.setText(getPlayerNameWithIcon() + ": " + ColorUtil.wrapWithColorTag(client.getVar(VarClientStr.CHATBOX_TYPED_TEXT) + "*", textColor)); - } - } - } - } - - private String getPlayerNameWithIcon() - { - IconID icon; - switch (client.getAccountType()) - { - case IRONMAN: - icon = IconID.IRONMAN; - break; - case ULTIMATE_IRONMAN: - icon = IconID.ULTIMATE_IRONMAN; - break; - case HARDCORE_IRONMAN: - icon = IconID.HARDCORE_IRONMAN; - break; - default: - return client.getLocalPlayer().getName(); - } - return icon + client.getLocalPlayer().getName(); - } -} \ No newline at end of file diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/keyremapping/KeyRemappingConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/keyremapping/KeyRemappingConfig.java index 4774bc67e7..cc14b5ff67 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/keyremapping/KeyRemappingConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/keyremapping/KeyRemappingConfig.java @@ -33,6 +33,17 @@ import net.runelite.client.config.ModifierlessKeybind; @ConfigGroup("keyremapping") public interface KeyRemappingConfig extends Config { + @ConfigItem( + position = 0, + keyName = "hideDisplayName", + name = "Hide display name", + description = "Hides the display name from showing before \"Press Enter to Chat...\"" + ) + default boolean hideDisplayName() + { + return false; + } + @ConfigItem( position = 1, keyName = "cameraRemap", diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/keyremapping/KeyRemappingPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/keyremapping/KeyRemappingPlugin.java index 12f25828f7..5b38cbdc25 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/keyremapping/KeyRemappingPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/keyremapping/KeyRemappingPlugin.java @@ -37,6 +37,7 @@ import net.runelite.api.IconID; import net.runelite.api.VarClientInt; import net.runelite.api.VarClientStr; import net.runelite.api.Varbits; +import net.runelite.api.events.ConfigChanged; import net.runelite.api.events.ScriptCallbackEvent; import net.runelite.api.widgets.Widget; import net.runelite.api.widgets.WidgetInfo; @@ -68,7 +69,7 @@ public class KeyRemappingPlugin extends Plugin private ClientThread clientThread; @Inject - private ConfigManager configManager; + private KeyRemappingConfig config; @Inject private KeyManager keyManager; @@ -83,7 +84,6 @@ public class KeyRemappingPlugin extends Plugin @Override protected void startUp() throws Exception { - configManager.setConfiguration("runelite", "entertochatplugin", false); typing = false; keyManager.registerKeyListener(inputListener); @@ -150,6 +150,25 @@ public class KeyRemappingPlugin extends Plugin return w == null || w.isSelfHidden(); } + @Subscribe + public void onConfigChanged(ConfigChanged configChanged) + { + if (!configChanged.getGroup().equals("keyremapping") || !configChanged.getKey().equals("hideDisplayName")) + { + return; + } + + clientThread.invoke(() -> + { + Widget chatboxInput = client.getWidget(WidgetInfo.CHATBOX_INPUT); + if (chatboxInput != null && chatboxInput.getText().endsWith(PRESS_ENTER_TO_CHAT)) + { + chatboxInput.setText(getWaitingText()); + } + } + ); + } + @Subscribe public void onScriptCallbackEvent(ScriptCallbackEvent scriptCallbackEvent) { @@ -161,7 +180,7 @@ public class KeyRemappingPlugin extends Plugin { if (chatboxFocused() && !typing) { - chatboxInput.setText(getPlayerNameWithIcon() + ": " + PRESS_ENTER_TO_CHAT); + chatboxInput.setText(getWaitingText()); } } break; @@ -181,7 +200,7 @@ public class KeyRemappingPlugin extends Plugin Widget chatboxInput = client.getWidget(WidgetInfo.CHATBOX_INPUT); if (chatboxInput != null) { - chatboxInput.setText(getPlayerNameWithIcon() + ": " + PRESS_ENTER_TO_CHAT); + chatboxInput.setText(getWaitingText()); // Typed text can be non-empty on plugin start, so clear it now client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, ""); } @@ -220,4 +239,16 @@ public class KeyRemappingPlugin extends Plugin } return icon + client.getLocalPlayer().getName(); } + + private String getWaitingText() + { + if (config.hideDisplayName()) + { + return PRESS_ENTER_TO_CHAT; + } + else + { + return getPlayerNameWithIcon() + ": " + PRESS_ENTER_TO_CHAT; + } + } }