chat message manager: format rl-messages at chat build time
This allows different final messages being built for split chat vs normal chat, fixing <colNORMAL> incorrectly applying the default chatbox color to split chat.
This commit is contained in:
@@ -31,9 +31,7 @@ import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Multimap;
|
||||
import java.awt.Color;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
@@ -45,9 +43,7 @@ import net.runelite.api.MessageNode;
|
||||
import net.runelite.api.Player;
|
||||
import net.runelite.api.VarPlayer;
|
||||
import net.runelite.api.Varbits;
|
||||
import net.runelite.api.events.ResizeableChanged;
|
||||
import net.runelite.api.events.ScriptCallbackEvent;
|
||||
import net.runelite.api.events.VarbitChanged;
|
||||
import net.runelite.client.callback.ClientThread;
|
||||
import net.runelite.client.config.ChatColorConfig;
|
||||
import net.runelite.client.eventbus.EventBus;
|
||||
@@ -66,7 +62,6 @@ public class ChatMessageManager
|
||||
private final Client client;
|
||||
private final ChatColorConfig chatColorConfig;
|
||||
private final ClientThread clientThread;
|
||||
private int transparencyVarbit = -1;
|
||||
private final Queue<QueuedMessage> queuedMessages = new ConcurrentLinkedQueue<>();
|
||||
|
||||
@Inject
|
||||
@@ -83,40 +78,25 @@ public class ChatMessageManager
|
||||
loadColors();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onVarbitChanged(VarbitChanged event)
|
||||
{
|
||||
int setting = client.getVar(Varbits.TRANSPARENT_CHATBOX);
|
||||
|
||||
if (transparencyVarbit != setting)
|
||||
{
|
||||
transparencyVarbit = setting;
|
||||
refreshAll();
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onResizeableChanged(ResizeableChanged event)
|
||||
{
|
||||
refreshAll();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onConfigChanged(ConfigChanged event)
|
||||
{
|
||||
if (event.getGroup().equals("textrecolor"))
|
||||
{
|
||||
loadColors();
|
||||
clientThread.invokeLater(this::refreshAll);
|
||||
clientThread.invokeLater(client::refreshChat);
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void colorChatMessage()
|
||||
{
|
||||
final int[] intStack = client.getIntStack();
|
||||
final String[] stringStack = client.getStringStack();
|
||||
final int size = client.getStringStackSize();
|
||||
final int uid = client.getIntStack()[client.getIntStackSize() - 1];
|
||||
final int isize = client.getIntStackSize();
|
||||
final int uid = intStack[isize - 1];
|
||||
final boolean splitpmbox = intStack[isize - 2] == 1;
|
||||
|
||||
final MessageNode messageNode = client.getMessages().get(uid);
|
||||
assert messageNode != null : "chat message build for unknown message";
|
||||
@@ -184,6 +164,12 @@ public class ChatMessageManager
|
||||
stringStack[size - 4] = ColorUtil.wrapWithColorTag(channel, channelColor);
|
||||
}
|
||||
|
||||
if (messageNode.getRuneLiteFormatMessage() != null)
|
||||
{
|
||||
stringStack[size - 2] = message = formatRuneLiteMessage(messageNode.getRuneLiteFormatMessage(),
|
||||
chatMessageType, splitpmbox);
|
||||
}
|
||||
|
||||
final Collection<ChatColor> chatColors = colorCache.get(chatMessageType);
|
||||
for (ChatColor chatColor : chatColors)
|
||||
{
|
||||
@@ -824,13 +810,11 @@ public class ChatMessageManager
|
||||
return;
|
||||
}
|
||||
|
||||
final String formattedMessage = formatRuneLiteMessage(message.getRuneLiteFormattedMessage(), message.getType());
|
||||
|
||||
// this updates chat cycle
|
||||
final MessageNode line = client.addChatMessage(
|
||||
message.getType(),
|
||||
MoreObjects.firstNonNull(message.getName(), ""),
|
||||
MoreObjects.firstNonNull(formattedMessage, message.getValue()),
|
||||
MoreObjects.firstNonNull(message.getRuneLiteFormattedMessage(), message.getValue()),
|
||||
message.getSender());
|
||||
|
||||
// Update the message with RuneLite additions
|
||||
@@ -843,64 +827,64 @@ public class ChatMessageManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuild the message node message from the RuneLite format message
|
||||
* Rebuild the message node message from the RuneLite format message.
|
||||
* DEPRECATED: no longer needs to be called.
|
||||
*
|
||||
* @param messageNode message node
|
||||
*/
|
||||
@Deprecated
|
||||
public void update(final MessageNode messageNode)
|
||||
{
|
||||
String message = formatRuneLiteMessage(messageNode.getRuneLiteFormatMessage(), messageNode.getType());
|
||||
if (message != null)
|
||||
{
|
||||
messageNode.setValue(message);
|
||||
}
|
||||
}
|
||||
|
||||
private String formatRuneLiteMessage(String runeLiteFormatMessage, ChatMessageType type)
|
||||
@VisibleForTesting
|
||||
String formatRuneLiteMessage(String runeLiteFormatMessage, ChatMessageType type, boolean pmbox)
|
||||
{
|
||||
if (Strings.isNullOrEmpty(runeLiteFormatMessage))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
final boolean transparent = client.isResized() && transparencyVarbit != 0;
|
||||
final boolean transparentChatbox = client.getVar(Varbits.TRANSPARENT_CHATBOX) != 0;
|
||||
final boolean transparent = client.isResized() && transparentChatbox;
|
||||
final Collection<ChatColor> chatColors = colorCache.get(type);
|
||||
for (ChatColor chatColor : chatColors)
|
||||
{
|
||||
if (chatColor.isTransparent() == transparent)
|
||||
{
|
||||
Color color = chatColor.getColor();
|
||||
String colstr;
|
||||
|
||||
VarPlayer varp = chatColor.getSetting();
|
||||
if (varp != null)
|
||||
if (pmbox && chatColor.getType() == ChatColorType.NORMAL)
|
||||
{
|
||||
// Apply configured color from game settings, if set
|
||||
assert chatColor.isDefault();
|
||||
int v = client.getVar(varp);
|
||||
if (v != 0)
|
||||
// The default ChatColors for private have the chatbox text color, not the split chat color,
|
||||
// and the split chat color is set by widget color, so just use </col>. The in-game
|
||||
// private chat color doesn't apply to split chat either so using that here also is incorrect.
|
||||
//
|
||||
// If we recolor the final message later we replace </col> with the desired color in
|
||||
// colorChatMessage()
|
||||
colstr = ColorUtil.CLOSING_COLOR_TAG;
|
||||
}
|
||||
else
|
||||
{
|
||||
Color color = chatColor.getColor();
|
||||
|
||||
VarPlayer varp = chatColor.getSetting();
|
||||
if (varp != null)
|
||||
{
|
||||
color = new Color(v - 1);
|
||||
// Apply configured color from game settings, if set
|
||||
assert chatColor.isDefault();
|
||||
int v = client.getVar(varp);
|
||||
if (v != 0)
|
||||
{
|
||||
color = new Color(v - 1);
|
||||
}
|
||||
}
|
||||
|
||||
colstr = ColorUtil.colorTag(color);
|
||||
}
|
||||
|
||||
// Replace custom formatting with actual colors
|
||||
runeLiteFormatMessage = runeLiteFormatMessage.replaceAll(
|
||||
"<col" + chatColor.getType().name() + ">",
|
||||
ColorUtil.colorTag(color));
|
||||
colstr);
|
||||
}
|
||||
}
|
||||
|
||||
return runeLiteFormatMessage;
|
||||
}
|
||||
|
||||
private void refreshAll()
|
||||
{
|
||||
client.getChatLineMap().values().stream()
|
||||
.filter(Objects::nonNull)
|
||||
.flatMap(clb -> Arrays.stream(clb.getLines()))
|
||||
.filter(Objects::nonNull)
|
||||
.forEach(this::update);
|
||||
|
||||
client.refreshChat();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,6 @@ import net.runelite.client.chat.ChatClient;
|
||||
import net.runelite.client.chat.ChatColorType;
|
||||
import net.runelite.client.chat.ChatCommandManager;
|
||||
import net.runelite.client.chat.ChatMessageBuilder;
|
||||
import net.runelite.client.chat.ChatMessageManager;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.config.RuneLiteConfig;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
@@ -175,9 +174,6 @@ public class ChatCommandsPlugin extends Plugin
|
||||
@Inject
|
||||
private ItemManager itemManager;
|
||||
|
||||
@Inject
|
||||
private ChatMessageManager chatMessageManager;
|
||||
|
||||
@Inject
|
||||
private ChatCommandManager chatCommandManager;
|
||||
|
||||
@@ -840,7 +836,6 @@ public class ChatCommandsPlugin extends Plugin
|
||||
log.debug("Setting response {}", response);
|
||||
final MessageNode messageNode = chatMessage.getMessageNode();
|
||||
messageNode.setRuneLiteFormatMessage(response);
|
||||
chatMessageManager.update(messageNode);
|
||||
client.refreshChat();
|
||||
}
|
||||
|
||||
@@ -930,7 +925,6 @@ public class ChatCommandsPlugin extends Plugin
|
||||
log.debug("Setting response {}", response);
|
||||
final MessageNode messageNode = chatMessage.getMessageNode();
|
||||
messageNode.setRuneLiteFormatMessage(response);
|
||||
chatMessageManager.update(messageNode);
|
||||
client.refreshChat();
|
||||
}
|
||||
|
||||
@@ -974,7 +968,6 @@ public class ChatCommandsPlugin extends Plugin
|
||||
log.debug("Setting response {}", response);
|
||||
final MessageNode messageNode = chatMessage.getMessageNode();
|
||||
messageNode.setRuneLiteFormatMessage(response);
|
||||
chatMessageManager.update(messageNode);
|
||||
client.refreshChat();
|
||||
}
|
||||
|
||||
@@ -1061,7 +1054,6 @@ public class ChatCommandsPlugin extends Plugin
|
||||
log.debug("Setting response {}", response);
|
||||
final MessageNode messageNode = chatMessage.getMessageNode();
|
||||
messageNode.setRuneLiteFormatMessage(response);
|
||||
chatMessageManager.update(messageNode);
|
||||
client.refreshChat();
|
||||
}
|
||||
|
||||
@@ -1137,7 +1129,6 @@ public class ChatCommandsPlugin extends Plugin
|
||||
log.debug("Setting response {}", response);
|
||||
final MessageNode messageNode = chatMessage.getMessageNode();
|
||||
messageNode.setRuneLiteFormatMessage(response);
|
||||
chatMessageManager.update(messageNode);
|
||||
client.refreshChat();
|
||||
}
|
||||
|
||||
@@ -1231,7 +1222,6 @@ public class ChatCommandsPlugin extends Plugin
|
||||
log.debug("Setting response {}", response);
|
||||
final MessageNode messageNode = chatMessage.getMessageNode();
|
||||
messageNode.setRuneLiteFormatMessage(response);
|
||||
chatMessageManager.update(messageNode);
|
||||
client.refreshChat();
|
||||
}
|
||||
|
||||
@@ -1321,7 +1311,6 @@ public class ChatCommandsPlugin extends Plugin
|
||||
|
||||
log.debug("Setting response {}", response);
|
||||
messageNode.setRuneLiteFormatMessage(response);
|
||||
chatMessageManager.update(messageNode);
|
||||
client.refreshChat();
|
||||
}
|
||||
}
|
||||
@@ -1403,7 +1392,6 @@ public class ChatCommandsPlugin extends Plugin
|
||||
log.debug("Setting response {}", response);
|
||||
final MessageNode messageNode = chatMessage.getMessageNode();
|
||||
messageNode.setRuneLiteFormatMessage(response);
|
||||
chatMessageManager.update(messageNode);
|
||||
client.refreshChat();
|
||||
}
|
||||
catch (IOException ex)
|
||||
@@ -1488,7 +1476,6 @@ public class ChatCommandsPlugin extends Plugin
|
||||
log.debug("Setting response {}", response);
|
||||
final MessageNode messageNode = chatMessage.getMessageNode();
|
||||
messageNode.setRuneLiteFormatMessage(response);
|
||||
chatMessageManager.update(messageNode);
|
||||
client.refreshChat();
|
||||
}
|
||||
catch (IOException ex)
|
||||
@@ -1616,7 +1603,6 @@ public class ChatCommandsPlugin extends Plugin
|
||||
log.debug("Setting response {}", response);
|
||||
final MessageNode messageNode = chatMessage.getMessageNode();
|
||||
messageNode.setRuneLiteFormatMessage(response);
|
||||
chatMessageManager.update(messageNode);
|
||||
client.refreshChat();
|
||||
}
|
||||
catch (IOException ex)
|
||||
@@ -1710,7 +1696,6 @@ public class ChatCommandsPlugin extends Plugin
|
||||
log.debug("Setting response {}", response);
|
||||
final MessageNode messageNode = chatMessage.getMessageNode();
|
||||
messageNode.setRuneLiteFormatMessage(response);
|
||||
chatMessageManager.update(messageNode);
|
||||
client.refreshChat();
|
||||
}
|
||||
catch (IOException ex)
|
||||
|
||||
@@ -47,7 +47,6 @@ import net.runelite.api.events.ChatMessage;
|
||||
import net.runelite.api.events.GameStateChanged;
|
||||
import net.runelite.client.Notifier;
|
||||
import net.runelite.client.chat.ChatColorType;
|
||||
import net.runelite.client.chat.ChatMessageManager;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
import net.runelite.client.events.ConfigChanged;
|
||||
@@ -69,9 +68,6 @@ public class ChatNotificationsPlugin extends Plugin
|
||||
@Inject
|
||||
private ChatNotificationsConfig config;
|
||||
|
||||
@Inject
|
||||
private ChatMessageManager chatMessageManager;
|
||||
|
||||
@Inject
|
||||
private Notifier notifier;
|
||||
|
||||
@@ -324,7 +320,6 @@ public class ChatNotificationsPlugin extends Plugin
|
||||
if (update)
|
||||
{
|
||||
messageNode.setRuneLiteFormatMessage(messageNode.getValue());
|
||||
chatMessageManager.update(messageNode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -830,7 +830,6 @@ public class RaidsPlugin extends Plugin
|
||||
log.debug("Setting response {}", response);
|
||||
final MessageNode messageNode = chatMessage.getMessageNode();
|
||||
messageNode.setRuneLiteFormatMessage(response);
|
||||
chatMessageManager.update(messageNode);
|
||||
client.refreshChat();
|
||||
}
|
||||
|
||||
|
||||
@@ -79,7 +79,6 @@ import net.runelite.client.chat.ChatClient;
|
||||
import net.runelite.client.chat.ChatColorType;
|
||||
import net.runelite.client.chat.ChatCommandManager;
|
||||
import net.runelite.client.chat.ChatMessageBuilder;
|
||||
import net.runelite.client.chat.ChatMessageManager;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
import net.runelite.client.events.ChatInput;
|
||||
@@ -161,9 +160,6 @@ public class SlayerPlugin extends Plugin
|
||||
@Inject
|
||||
private TargetWeaknessOverlay targetWeaknessOverlay;
|
||||
|
||||
@Inject
|
||||
private ChatMessageManager chatMessageManager;
|
||||
|
||||
@Inject
|
||||
private ChatCommandManager chatCommandManager;
|
||||
|
||||
@@ -875,7 +871,6 @@ public class SlayerPlugin extends Plugin
|
||||
|
||||
final MessageNode messageNode = chatMessage.getMessageNode();
|
||||
messageNode.setRuneLiteFormatMessage(response);
|
||||
chatMessageManager.update(messageNode);
|
||||
client.refreshChat();
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,6 @@ import net.runelite.api.events.GameTick;
|
||||
import net.runelite.api.events.ItemContainerChanged;
|
||||
import net.runelite.api.events.VarbitChanged;
|
||||
import net.runelite.client.Notifier;
|
||||
import net.runelite.client.chat.ChatMessageManager;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
@@ -105,9 +104,6 @@ public class WintertodtPlugin extends Plugin
|
||||
@Inject
|
||||
private WintertodtConfig config;
|
||||
|
||||
@Inject
|
||||
private ChatMessageManager chatMessageManager;
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private WintertodtActivity currentActivity = WintertodtActivity.IDLE;
|
||||
|
||||
@@ -314,7 +310,6 @@ public class WintertodtPlugin extends Plugin
|
||||
|
||||
// Recolor message for damage notification
|
||||
messageNode.setRuneLiteFormatMessage(ColorUtil.wrapWithColorTag(messageNode.getValue(), config.damageNotificationColor()));
|
||||
chatMessageManager.update(messageNode);
|
||||
client.refreshChat();
|
||||
|
||||
// all actions except woodcutting and idle are interrupted from damage
|
||||
|
||||
@@ -35,7 +35,7 @@ public class JagexColors
|
||||
* Colors of chat text when displayed on an opaque background.
|
||||
*/
|
||||
public static final Color CHAT_PUBLIC_TEXT_OPAQUE_BACKGROUND = Color.BLUE;
|
||||
public static final Color CHAT_PRIVATE_MESSAGE_TEXT_OPAQUE_BACKGROUND = Color.CYAN;
|
||||
public static final Color CHAT_PRIVATE_MESSAGE_TEXT_OPAQUE_BACKGROUND = new Color(0x7F0000); // in chatbox, not split chat
|
||||
public static final Color CHAT_FC_TEXT_OPAQUE_BACKGROUND = new Color(127, 0, 0);
|
||||
public static final Color CHAT_FC_NAME_OPAQUE_BACKGROUND = Color.BLUE;
|
||||
public static final Color CHAT_GAME_EXAMINE_TEXT_OPAQUE_BACKGROUND = Color.BLACK;
|
||||
@@ -45,7 +45,7 @@ public class JagexColors
|
||||
* Colors of chat text when displayed on a transparent background.
|
||||
*/
|
||||
public static final Color CHAT_PUBLIC_TEXT_TRANSPARENT_BACKGROUND = new Color(144, 144, 255);
|
||||
public static final Color CHAT_PRIVATE_MESSAGE_TEXT_TRANSPARENT_BACKGROUND = Color.CYAN;
|
||||
public static final Color CHAT_PRIVATE_MESSAGE_TEXT_TRANSPARENT_BACKGROUND = new Color(0xBF2020); // in chatbox, not split chat
|
||||
public static final Color CHAT_FC_TEXT_TRANSPARENT_BACKGROUND = new Color(239, 80, 80);
|
||||
public static final Color CHAT_FC_NAME_TRANSPARENT_BACKGROUND = new Color(144, 112, 255);
|
||||
public static final Color CHAT_GAME_EXAMINE_TEXT_TRANSPARENT_BACKGROUND = Color.WHITE;
|
||||
|
||||
Reference in New Issue
Block a user