merge self linking feature into ChatTagTargetFeature
This commit is contained in:
@@ -108,16 +108,6 @@ namespace PlayerTags.Configuration
|
||||
}
|
||||
}
|
||||
|
||||
[JsonProperty("IsLinkSelfInChatEnabled"), Obsolete]
|
||||
private bool IsLinkSelfInChatEnabledV1
|
||||
{
|
||||
set
|
||||
{
|
||||
foreach (var key in GeneralOptions.Keys)
|
||||
GeneralOptions[key].IsLinkSelfInChatEnabled = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public event System.Action? Saved;
|
||||
@@ -229,6 +219,5 @@ namespace PlayerTags.Configuration
|
||||
public NameplateTitlePosition NameplateTitlePosition = NameplateTitlePosition.AlwaysAboveName;
|
||||
|
||||
public bool IsApplyTagsToAllChatMessagesEnabled = true;
|
||||
public bool IsLinkSelfInChatEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,8 +80,8 @@ namespace PlayerTags.Configuration
|
||||
|
||||
ImGui.Spacing();
|
||||
ImGui.Spacing();
|
||||
DrawHeading(Strings.Loc_Static_ChatExperimental);
|
||||
DrawCheckbox(nameof(propertyProxy.IsLinkSelfInChatEnabled), true, ref propertyProxy.IsLinkSelfInChatEnabled, () => SaveSettings(true));
|
||||
DrawHeading(Strings.Loc_Static_Chat);
|
||||
//DrawCheckbox(nameof(propertyProxy.IsLinkSelfInChatEnabled), true, ref propertyProxy.IsLinkSelfInChatEnabled, () => SaveSettings(true));
|
||||
DrawCheckbox(nameof(propertyProxy.IsApplyTagsToAllChatMessagesEnabled), true, ref propertyProxy.IsApplyTagsToAllChatMessagesEnabled, () => SaveSettings(true));
|
||||
|
||||
|
||||
@@ -1203,7 +1203,6 @@ namespace PlayerTags.Configuration
|
||||
public NameplateTitleVisibility NameplateTitleVisibility;
|
||||
public NameplateTitlePosition NameplateTitlePosition;
|
||||
public bool IsApplyTagsToAllChatMessagesEnabled;
|
||||
public bool IsLinkSelfInChatEnabled;
|
||||
|
||||
public PropertyProxy(PluginConfiguration config)
|
||||
{
|
||||
@@ -1218,7 +1217,6 @@ namespace PlayerTags.Configuration
|
||||
NameplateTitleVisibility = pluginConfig.GeneralOptions[currentActivityContext].NameplateTitleVisibility;
|
||||
NameplateTitlePosition = pluginConfig.GeneralOptions[currentActivityContext].NameplateTitlePosition;
|
||||
IsApplyTagsToAllChatMessagesEnabled = pluginConfig.GeneralOptions[currentActivityContext].IsApplyTagsToAllChatMessagesEnabled;
|
||||
IsLinkSelfInChatEnabled = pluginConfig.GeneralOptions[currentActivityContext].IsLinkSelfInChatEnabled;
|
||||
}
|
||||
|
||||
public void SaveData()
|
||||
@@ -1241,7 +1239,6 @@ namespace PlayerTags.Configuration
|
||||
pluginConfig.GeneralOptions[key].NameplateTitleVisibility = NameplateTitleVisibility;
|
||||
pluginConfig.GeneralOptions[key].NameplateTitlePosition = NameplateTitlePosition;
|
||||
pluginConfig.GeneralOptions[key].IsApplyTagsToAllChatMessagesEnabled = IsApplyTagsToAllChatMessagesEnabled;
|
||||
pluginConfig.GeneralOptions[key].IsLinkSelfInChatEnabled = IsLinkSelfInChatEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -208,12 +208,102 @@ namespace PlayerTags.Features
|
||||
}
|
||||
}
|
||||
|
||||
private void ParsePayloadsForOwnPlayer(SeString seString, XivChatType chatType, bool isSender)
|
||||
{
|
||||
if (PluginServices.ClientState.LocalPlayer != null)
|
||||
{
|
||||
foreach (var payload in seString.Payloads.ToArray())
|
||||
{
|
||||
if (payload is TextPayload textPayload)
|
||||
{
|
||||
List<TextPayload> playerTextPayloads = new List<TextPayload>();
|
||||
|
||||
var playerName = PluginServices.ClientState.LocalPlayer.Name.TextValue;
|
||||
|
||||
if (textPayload.Text == playerName)
|
||||
{
|
||||
playerTextPayloads.Add(textPayload);
|
||||
textPayload.Text = textPayload.Text;
|
||||
}
|
||||
else
|
||||
{
|
||||
var textMatchIndex = textPayload.Text.IndexOf(playerName);
|
||||
|
||||
while (textMatchIndex >= 0)
|
||||
{
|
||||
var textPayloadIndex = seString.Payloads.IndexOf(payload);
|
||||
|
||||
// Chop text to the left and insert it as a new payload
|
||||
if (textMatchIndex > 0)
|
||||
{
|
||||
// Add the content before the player
|
||||
seString.Payloads.Insert(textPayloadIndex, new TextPayload(textPayload.Text.Substring(0, textMatchIndex)));
|
||||
|
||||
// Remove from the chopped text from the original payload
|
||||
textPayload.Text = textPayload.Text.Substring(textMatchIndex, textPayload.Text.Length - textMatchIndex);
|
||||
}
|
||||
|
||||
// This is the last reference to the local player in this payload
|
||||
if (textPayload.Text.Length == playerName.Length)
|
||||
{
|
||||
playerTextPayloads.Add(textPayload);
|
||||
break;
|
||||
}
|
||||
|
||||
// Create the new name payload and add it
|
||||
var playerTextPayload = new TextPayload(playerName);
|
||||
playerTextPayloads.Add(playerTextPayload);
|
||||
seString.Payloads.Insert(textPayloadIndex, playerTextPayload);
|
||||
|
||||
// Remove from the chopped text from the original payload
|
||||
textPayload.Text = textPayload.Text.Substring(playerName.Length);
|
||||
|
||||
textMatchIndex = textPayload.Text.IndexOf(playerName);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var playerTextPayload in playerTextPayloads)
|
||||
{
|
||||
// This does some dodgy shit for an unknown reason.
|
||||
// Typically when you receive a player payload followed by a text payload, it displays the text
|
||||
// and links it with the player payload. When trying to make one of these manually, it displays the player payload separately,
|
||||
// effectively doubling up the player name.
|
||||
// For now, don't follow up with a text payload. Only use a player payload.
|
||||
|
||||
var playerPayload = new PlayerPayload(playerName, PluginServices.ClientState.LocalPlayer.HomeWorld.Id);
|
||||
int playerPayloadIndex = seString.Payloads.IndexOf(playerTextPayload);
|
||||
|
||||
if (isSender && (chatType == XivChatType.Party || chatType == XivChatType.Alliance))
|
||||
playerPayloadIndex--;
|
||||
|
||||
// Add the Player Link Payload
|
||||
seString.Payloads.Insert(playerPayloadIndex++, playerPayload);
|
||||
|
||||
// Add the Link Terminator to end the Player Link. This should be done behind the Text Payload (display text).
|
||||
// Normally used to end PlayerPayload linking. But for the own player it has no affect. Anyway, use it, just because. Maybe it's needed in the future somewhere else.
|
||||
//seString.Payloads.Insert(++playerPayloadIndex, RawPayload.LinkTerminator);
|
||||
|
||||
// Remove TextPayload
|
||||
//seString.Payloads.Remove(playerTextPayload);
|
||||
|
||||
// I M P O R T A N T N O T I C E:
|
||||
// The PlayerPayload is now just temporary. We keep the TextPayload don't add the LinkTerminator.
|
||||
// The PayerPayload gets removed at the ChatTagTargetFeature at the end and the TextPayload will be keeped there.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds all configured tags to a chat message.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to change.</param>
|
||||
private void AddTagsToChat(SeString message, XivChatType chatType, bool isSender)
|
||||
{
|
||||
// Parse Payloads for local player to be able to work with in the following code
|
||||
ParsePayloadsForOwnPlayer(message, chatType, isSender);
|
||||
|
||||
// Split out the party/alliance number from the PlayerPayload
|
||||
if (isSender)
|
||||
SplitOffPartyNumberPrefix(message, chatType);
|
||||
|
||||
@@ -1,128 +0,0 @@
|
||||
using Dalamud.Game.Text;
|
||||
using Dalamud.Game.Text.SeStringHandling;
|
||||
using Dalamud.Game.Text.SeStringHandling.Payloads;
|
||||
using PlayerTags.Configuration;
|
||||
using PlayerTags.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PlayerTags.Features
|
||||
{
|
||||
public class LinkSelfInChatFeature : IDisposable
|
||||
{
|
||||
private PluginConfiguration m_PluginConfiguration;
|
||||
private PluginData m_PluginData;
|
||||
private ActivityContextManager activityContextManager;
|
||||
|
||||
public LinkSelfInChatFeature(PluginConfiguration pluginConfiguration, PluginData pluginData)
|
||||
{
|
||||
m_PluginConfiguration = pluginConfiguration;
|
||||
m_PluginData = pluginData;
|
||||
activityContextManager = new();
|
||||
|
||||
PluginServices.ChatGui.ChatMessage += Chat_ChatMessage;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
PluginServices.ChatGui.ChatMessage -= Chat_ChatMessage;
|
||||
activityContextManager.Dispose();
|
||||
}
|
||||
|
||||
private void Chat_ChatMessage(XivChatType type, uint senderId, ref SeString sender, ref SeString message, ref bool isHandled)
|
||||
{
|
||||
if (m_PluginConfiguration.GeneralOptions[activityContextManager.CurrentActivityContext].IsLinkSelfInChatEnabled)
|
||||
{
|
||||
ParsePayloads(sender, type, true);
|
||||
ParsePayloads(message, type, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void ParsePayloads(SeString seString, XivChatType chatType, bool isSender)
|
||||
{
|
||||
if (PluginServices.ClientState.LocalPlayer != null)
|
||||
{
|
||||
foreach (var payload in seString.Payloads.ToArray())
|
||||
{
|
||||
if (payload is TextPayload textPayload)
|
||||
{
|
||||
List<TextPayload> playerTextPayloads = new List<TextPayload>();
|
||||
|
||||
var playerName = PluginServices.ClientState.LocalPlayer.Name.TextValue;
|
||||
|
||||
if (textPayload.Text == playerName)
|
||||
{
|
||||
playerTextPayloads.Add(textPayload);
|
||||
textPayload.Text = textPayload.Text;
|
||||
}
|
||||
else
|
||||
{
|
||||
var textMatchIndex = textPayload.Text.IndexOf(playerName);
|
||||
|
||||
while (textMatchIndex >= 0)
|
||||
{
|
||||
var textPayloadIndex = seString.Payloads.IndexOf(payload);
|
||||
|
||||
// Chop text to the left and insert it as a new payload
|
||||
if (textMatchIndex > 0)
|
||||
{
|
||||
// Add the content before the player
|
||||
seString.Payloads.Insert(textPayloadIndex, new TextPayload(textPayload.Text.Substring(0, textMatchIndex)));
|
||||
|
||||
// Remove from the chopped text from the original payload
|
||||
textPayload.Text = textPayload.Text.Substring(textMatchIndex, textPayload.Text.Length - textMatchIndex);
|
||||
}
|
||||
|
||||
// This is the last reference to the local player in this payload
|
||||
if (textPayload.Text.Length == playerName.Length)
|
||||
{
|
||||
playerTextPayloads.Add(textPayload);
|
||||
break;
|
||||
}
|
||||
|
||||
// Create the new name payload and add it
|
||||
var playerTextPayload = new TextPayload(playerName);
|
||||
playerTextPayloads.Add(playerTextPayload);
|
||||
seString.Payloads.Insert(textPayloadIndex, playerTextPayload);
|
||||
|
||||
// Remove from the chopped text from the original payload
|
||||
textPayload.Text = textPayload.Text.Substring(playerName.Length);
|
||||
|
||||
textMatchIndex = textPayload.Text.IndexOf(playerName);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var playerTextPayload in playerTextPayloads)
|
||||
{
|
||||
// This does some dodgy shit for an unknown reason.
|
||||
// Typically when you receive a player payload followed by a text payload, it displays the text
|
||||
// and links it with the player payload. When trying to make one of these manually, it displays the player payload separately,
|
||||
// effectively doubling up the player name.
|
||||
// For now, don't follow up with a text payload. Only use a player payload.
|
||||
|
||||
var playerPayload = new PlayerPayload(playerName, PluginServices.ClientState.LocalPlayer.HomeWorld.Id);
|
||||
int playerPayloadIndex = seString.Payloads.IndexOf(playerTextPayload);
|
||||
|
||||
if (isSender && (chatType == XivChatType.Party || chatType == XivChatType.Alliance))
|
||||
playerPayloadIndex--;
|
||||
|
||||
// Add the Player Link Payload
|
||||
seString.Payloads.Insert(playerPayloadIndex++, playerPayload);
|
||||
|
||||
// Add the Link Terminator to end the Player Link. This should be done behind the Text Payload (display text).
|
||||
// Normally used to end PlayerPayload linking. But for the own player it has no affect. Anyway, use it, just because. Maybe it's needed in the future somewhere else.
|
||||
//seString.Payloads.Insert(++playerPayloadIndex, RawPayload.LinkTerminator);
|
||||
|
||||
// Remove TextPayload
|
||||
//seString.Payloads.Remove(playerTextPayload);
|
||||
|
||||
// I M P O R T A N T N O T I C E:
|
||||
// The PlayerPayload is now just temporary. We keep the TextPayload don't add the LinkTerminator.
|
||||
// The PayerPayload gets removed at the ChatTagTargetFeature at the end and the TextPayload will be keeped there.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,6 @@ namespace PlayerTags
|
||||
private PluginData m_PluginData;
|
||||
private PluginConfigurationUI m_PluginConfigurationUI;
|
||||
|
||||
private LinkSelfInChatFeature m_LinkSelfInChatFeature;
|
||||
private CustomTagsContextMenuFeature m_CustomTagsContextMenuFeature;
|
||||
private NameplateTagTargetFeature m_NameplatesTagTargetFeature;
|
||||
private ChatTagTargetFeature m_ChatTagTargetFeature;
|
||||
@@ -43,7 +42,6 @@ namespace PlayerTags
|
||||
{
|
||||
UiBuilder_OpenConfigUi();
|
||||
}) { HelpMessage = "Shows the config" });
|
||||
m_LinkSelfInChatFeature = new LinkSelfInChatFeature(m_PluginConfiguration, m_PluginData);
|
||||
m_CustomTagsContextMenuFeature = new CustomTagsContextMenuFeature(m_PluginConfiguration, m_PluginData);
|
||||
m_NameplatesTagTargetFeature = new NameplateTagTargetFeature(m_PluginConfiguration, m_PluginData);
|
||||
m_ChatTagTargetFeature = new ChatTagTargetFeature(m_PluginConfiguration, m_PluginData);
|
||||
@@ -54,7 +52,6 @@ namespace PlayerTags
|
||||
m_ChatTagTargetFeature.Dispose();
|
||||
m_NameplatesTagTargetFeature.Dispose();
|
||||
m_CustomTagsContextMenuFeature.Dispose();
|
||||
m_LinkSelfInChatFeature.Dispose();
|
||||
PluginServices.DalamudPluginInterface.LanguageChanged -= DalamudPluginInterface_LanguageChanged;
|
||||
PluginServices.CommandManager.RemoveHandler(c_CommandName);
|
||||
PluginServices.DalamudPluginInterface.UiBuilder.OpenConfigUi -= UiBuilder_OpenConfigUi;
|
||||
|
||||
Reference in New Issue
Block a user