From 70a097b1ad4da1c44c085f9f0006b818add0f90a Mon Sep 17 00:00:00 2001 From: Kyleeld <48519776+Kyleeld@users.noreply.github.com> Date: Sat, 18 May 2019 22:09:32 +0100 Subject: [PATCH] press enter to chat - no wasd shit press enter to chat - no wasd shit --- .../entertochat/EnterToChatListener.java | 135 ++++++++++++ .../entertochat/EnterToChatPlugin.java | 206 ++++++++++++++++++ .../plugins/wasdcamera/WASDCameraPlugin.java | 4 + 3 files changed, 345 insertions(+) create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/entertochat/EnterToChatListener.java create 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 new file mode 100644 index 0000000000..3dabc56600 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/entertochat/EnterToChatListener.java @@ -0,0 +1,135 @@ +/* + * 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 new file mode 100644 index 0000000000..6436b6802a --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/entertochat/EnterToChatPlugin.java @@ -0,0 +1,206 @@ +/*' + * 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"}, + enabledByDefault = false, + type = PluginType.UTILITY +) +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/wasdcamera/WASDCameraPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/wasdcamera/WASDCameraPlugin.java index a60a389674..ac59c414d6 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/wasdcamera/WASDCameraPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/wasdcamera/WASDCameraPlugin.java @@ -67,6 +67,9 @@ public class WASDCameraPlugin extends Plugin @Inject private ClientThread clientThread; + @Inject + private ConfigManager configManager; + @Inject private KeyManager keyManager; @@ -80,6 +83,7 @@ public class WASDCameraPlugin extends Plugin @Override protected void startUp() throws Exception { + configManager.setConfiguration("runelite", "entertochatplugin", false); typing = false; keyManager.registerKeyListener(inputListener);