From 1ae01335b42fc6881348bcface414c32d4033627 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 27 May 2021 21:59:16 -0400 Subject: [PATCH] chat channel: add typing modes This allows changing the target of typed messages via /f, /c, /g, and /p. All further messages go to the given target until a new target is specified. --- .../chatchannel/ChatChannelPlugin.java | 83 +++++++++++++++++++ .../src/main/scripts/CommandScript.rs2asm | 10 +++ 2 files changed, 93 insertions(+) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/chatchannel/ChatChannelPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/chatchannel/ChatChannelPlugin.java index 4d80810db8..ed9613da66 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/chatchannel/ChatChannelPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/chatchannel/ChatChannelPlugin.java @@ -41,6 +41,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import javax.inject.Inject; +import lombok.AllArgsConstructor; import net.runelite.api.ChatLineBuffer; import net.runelite.api.ChatMessageType; import net.runelite.api.ChatPlayer; @@ -80,6 +81,8 @@ import net.runelite.api.widgets.WidgetInfo; import net.runelite.api.widgets.WidgetType; import net.runelite.client.callback.ClientThread; import net.runelite.client.chat.ChatMessageBuilder; +import net.runelite.client.chat.ChatMessageManager; +import net.runelite.client.chat.QueuedMessage; import net.runelite.client.config.ChatColorConfig; import net.runelite.client.config.ConfigManager; import net.runelite.client.eventbus.Subscribe; @@ -131,6 +134,9 @@ public class ChatChannelPlugin extends Plugin @Inject private ChatColorConfig chatColorConfig; + @Inject + private ChatMessageManager chatMessageManager; + private List chats; private final List members = new ArrayList<>(); private MembersIndicator membersIndicator; @@ -143,6 +149,21 @@ public class ChatChannelPlugin extends Plugin private boolean kickConfirmed = false; + private boolean inputWarning; + + @AllArgsConstructor + private enum InputMode + { + FRIEND("Friends Chat", ChatMessageType.FRIENDSCHAT), + CLAN("Clan Chat", ChatMessageType.CLAN_CHAT), + GUEST("Guest Clan Chat", ChatMessageType.CLAN_GUEST_CHAT); + + private final String prompt; + private final ChatMessageType chatMessageType; + } + + private InputMode inputMode; + @Provides ChatChannelConfig getConfig(ConfigManager configManager) { @@ -168,6 +189,7 @@ public class ChatChannelPlugin extends Plugin members.clear(); resetCounter(); rebuildFriendsChat(); + inputMode = null; } @Subscribe @@ -674,6 +696,67 @@ public class ChatChannelPlugin extends Plugin clientThread.invokeLater(() -> confirmKickPlayer(kickPlayerName)); break; } + case "preChatSendpublic": + { + final String chatboxInput = client.getVar(VarClientStr.CHATBOX_TYPED_TEXT); + switch (chatboxInput) + { + case "/p": + switchTypingMode(null); + break; + case "/f": + switchTypingMode(InputMode.FRIEND); + break; + case "/c": + switchTypingMode(InputMode.CLAN); + break; + case "/g": + switchTypingMode(InputMode.GUEST); + break; + default: + if (inputMode != null) + { + final int[] intStack = client.getIntStack(); + final int intStackSize = client.getIntStackSize(); + intStack[intStackSize - 1] = inputMode.chatMessageType.getType(); // chat message type + intStack[intStackSize - 2] = 0; // prefix length + } + break; + } + break; + } + case "setChatboxInput": + { + Widget chatboxInput = client.getWidget(WidgetInfo.CHATBOX_INPUT); + if (chatboxInput != null && inputMode != null) + { + String text = chatboxInput.getText(); + int idx = text.indexOf(": "); + if (idx != -1) + { + String newText = inputMode.prompt + ": " + text.substring(idx + 2); + chatboxInput.setText(newText); + } + } + break; + } + } + } + + private void switchTypingMode(InputMode mode) + { + inputMode = mode; + client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, ""); + + if (mode != null && !inputWarning) + { + inputWarning = true; + + chatMessageManager.queue(QueuedMessage.builder() + .type(ChatMessageType.CONSOLE) + .runeLiteFormattedMessage("You've entered " + inputMode.prompt + " typing mode. All typed messages will be sent to your " + + inputMode.prompt.toLowerCase() + ". Use /p to reset to public chat.") + .build()); } } diff --git a/runelite-client/src/main/scripts/CommandScript.rs2asm b/runelite-client/src/main/scripts/CommandScript.rs2asm index 53f510b945..cb21384884 100644 --- a/runelite-client/src/main/scripts/CommandScript.rs2asm +++ b/runelite-client/src/main/scripts/CommandScript.rs2asm @@ -270,6 +270,16 @@ LABEL222: istore 5 istore 6 LABEL226: + iload 6 ; prefix length + iload 5 ; chat type + sconst "preChatSendpublic" + runelite_callback + istore 5 ; chat type + istore 6 ; prefix length + get_varc_string 335 ; load input string + string_length ; get length + iconst 0 ; load 0 + if_icmpeq LABEL420 ; if (%varcstring355 == 0) jump to script223 call iload 5 iconst 44 if_icmpeq LABEL230