keep TextPayload in LinkSelfInChatFeature if ChatTwo is installed

-> Fix own player name not visible in Chat 2 when enabled the Link Self In Chat Feature
This commit is contained in:
2022-09-15 20:20:31 +02:00
parent 8d15040fe0
commit 248ef429d4
2 changed files with 32 additions and 2 deletions

View File

@@ -14,6 +14,9 @@ namespace PlayerTags.Features
private PluginData m_PluginData;
private ActivityContextManager activityContextManager;
public delegate bool ShouldRemovePlayerNameTextPayloadEventHandler(object sender);
public event ShouldRemovePlayerNameTextPayloadEventHandler ShouldRemovePlayerNameTextPayload;
public LinkSelfInChatFeature(PluginConfiguration pluginConfiguration, PluginData pluginData)
{
m_PluginConfiguration = pluginConfiguration;
@@ -102,12 +105,20 @@ namespace PlayerTags.Features
// 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);
var playerPayloadIndex = seString.Payloads.IndexOf(playerTextPayload);
// 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);
seString.Payloads.Remove(playerTextPayload);
seString.Payloads.Insert(++playerPayloadIndex, RawPayload.LinkTerminator);
// Remove the text payload (display text)
if (ShouldRemovePlayerNameTextPayload?.Invoke(this) ?? true)
seString.Payloads.Remove(playerTextPayload);
}
}
}

View File

@@ -1,8 +1,13 @@
using Dalamud.Game.Command;
using Dalamud.Plugin;
using Dalamud.Plugin.Internal;
using PlayerTags.Configuration;
using PlayerTags.Data;
using PlayerTags.Features;
using System;
using System.IO;
using System.Linq;
using System.Reflection;
namespace PlayerTags
{
@@ -10,6 +15,7 @@ namespace PlayerTags
{
public string Name => "PlayerTags";
private const string c_CommandName = "/playertags";
private const string c_ChatTwo_InternalPluginName = "ChatTwo";
private PluginConfiguration m_PluginConfiguration;
private PluginData m_PluginData;
@@ -38,6 +44,7 @@ namespace PlayerTags
UiBuilder_OpenConfigUi();
}) { HelpMessage = "Shows the config" });
m_LinkSelfInChatFeature = new LinkSelfInChatFeature(m_PluginConfiguration, m_PluginData);
m_LinkSelfInChatFeature.ShouldRemovePlayerNameTextPayload += LinkSelfInChatFeature_ShouldRemovePlayerNameTextPayload;
m_CustomTagsContextMenuFeature = new CustomTagsContextMenuFeature(m_PluginConfiguration, m_PluginData);
m_NameplatesTagTargetFeature = new NameplateTagTargetFeature(m_PluginConfiguration, m_PluginData);
m_ChatTagTargetFeature = new ChatTagTargetFeature(m_PluginConfiguration, m_PluginData);
@@ -55,6 +62,18 @@ namespace PlayerTags
PluginServices.DalamudPluginInterface.UiBuilder.Draw -= UiBuilder_Draw;
}
private bool LinkSelfInChatFeature_ShouldRemovePlayerNameTextPayload(object sender)
{
return !IsChatTwoActive();
}
private bool IsChatTwoActive()
{
var file = Path.Combine(Path.GetDirectoryName(PluginServices.DalamudPluginInterface.ConfigDirectory.FullName), @"ChatTwo\chat-log.db");
var exists = File.Exists(file);
return exists;
}
private void DalamudPluginInterface_LanguageChanged(string langCode)
{
Localizer.SetLanguage(langCode);