use seperated ActivityContextManager class & pre-pair testing stuff for fixing group member number and name location
This commit is contained in:
50
PlayerTags/Data/ActivityContextManager.cs
Normal file
50
PlayerTags/Data/ActivityContextManager.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using Dalamud.Plugin;
|
||||
using Lumina.Excel.GeneratedSheets;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PlayerTags.Data
|
||||
{
|
||||
public class ActivityContextManager : IDisposable
|
||||
{
|
||||
private ActivityContext m_CurrentActivityContext;
|
||||
|
||||
public ActivityContext CurrentActivityContext => m_CurrentActivityContext;
|
||||
|
||||
public ActivityContextManager()
|
||||
{
|
||||
m_CurrentActivityContext = ActivityContext.None;
|
||||
PluginServices.ClientState.TerritoryChanged += ClientState_TerritoryChanged;
|
||||
}
|
||||
|
||||
private void ClientState_TerritoryChanged(object? sender, ushort e)
|
||||
{
|
||||
m_CurrentActivityContext = ActivityContext.None;
|
||||
|
||||
var contentFinderConditionsSheet = PluginServices.DataManager.GameData.GetExcelSheet<ContentFinderCondition>();
|
||||
if (contentFinderConditionsSheet != null)
|
||||
{
|
||||
var foundContentFinderCondition = contentFinderConditionsSheet.FirstOrDefault(contentFinderCondition => contentFinderCondition.TerritoryType.Row == PluginServices.ClientState.TerritoryType);
|
||||
if (foundContentFinderCondition != null)
|
||||
{
|
||||
if (foundContentFinderCondition.PvP)
|
||||
{
|
||||
m_CurrentActivityContext = ActivityContext.PvpDuty;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_CurrentActivityContext = ActivityContext.PveDuty;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
PluginServices.ClientState.TerritoryChanged -= ClientState_TerritoryChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,11 +12,13 @@ namespace PlayerTags.Features
|
||||
{
|
||||
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;
|
||||
}
|
||||
@@ -24,6 +26,7 @@ namespace PlayerTags.Features
|
||||
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)
|
||||
@@ -58,21 +61,31 @@ namespace PlayerTags.Features
|
||||
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)
|
||||
if (textMatchIndex > 0) // textMatchIndex > 1 TODO: Find out, why this does the correct thing but doesn't let process the name correctly.
|
||||
{
|
||||
seString.Payloads.Insert(textPayloadIndex, new TextPayload(textPayload.Text.Substring(0, textMatchIndex)));
|
||||
var indexToUser = textMatchIndex;
|
||||
|
||||
// TODO: Find out, why this does the correct thing but doesn't let process the name correctly.
|
||||
//if (indexToUser == 1 && activityContextManager.CurrentActivityContext != ActivityContext.None)
|
||||
// indexToUser--;
|
||||
|
||||
seString.Payloads.Insert(textPayloadIndex, new TextPayload(textPayload.Text.Substring(0, indexToUser)));
|
||||
|
||||
// Remove from the chopped text from the original payload
|
||||
textPayload.Text = textPayload.Text.Substring(textMatchIndex, textPayload.Text.Length - textMatchIndex);
|
||||
textPayload.Text = textPayload.Text.Substring(indexToUser, textPayload.Text.Length - textMatchIndex);
|
||||
}
|
||||
|
||||
// TODO: Find out, why this does the correct thing but doesn't let process the name correctly.
|
||||
var textPayloadTextLenghOffset = /*textMatchIndex == 1 ? 1 :*/ 0;
|
||||
|
||||
// This is the last reference to the local player in this payload
|
||||
if (textPayload.Text.Length == playerName.Length)
|
||||
if (textPayload.Text.Length == playerName.Length + textPayloadTextLenghOffset)
|
||||
{
|
||||
playerTextPayloads.Add(textPayload);
|
||||
break;
|
||||
@@ -84,7 +97,7 @@ namespace PlayerTags.Features
|
||||
seString.Payloads.Insert(textPayloadIndex, playerTextPayload);
|
||||
|
||||
// Remove from the chopped text from the original payload
|
||||
textPayload.Text = textPayload.Text.Substring(0, playerName.Length);
|
||||
textPayload.Text = textPayload.Text.Substring(0, playerName.Length + textPayloadTextLenghOffset);
|
||||
|
||||
textMatchIndex = textPayload.Text.IndexOf(playerName);
|
||||
}
|
||||
@@ -100,7 +113,7 @@ namespace PlayerTags.Features
|
||||
//seString.Payloads.Insert(seString.Payloads.IndexOf(playerTextPayload), playerPayload);
|
||||
|
||||
// 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 playerPayload = new PlayerPayload(playerTextPayload.Text, PluginServices.ClientState.LocalPlayer.HomeWorld.Id);
|
||||
seString.Payloads.Insert(seString.Payloads.IndexOf(playerTextPayload), playerPayload);
|
||||
seString.Payloads.Remove(playerTextPayload);
|
||||
}
|
||||
|
||||
@@ -15,50 +15,25 @@ namespace PlayerTags.Features
|
||||
/// </summary>
|
||||
public abstract class TagTargetFeature : IDisposable
|
||||
{
|
||||
private ActivityContext m_CurrentActivityContext;
|
||||
public ActivityContextManager ActivityContextManager { get; init; }
|
||||
|
||||
public TagTargetFeature()
|
||||
{
|
||||
|
||||
m_CurrentActivityContext = ActivityContext.None;
|
||||
|
||||
PluginServices.ClientState.TerritoryChanged += ClientState_TerritoryChanged;
|
||||
ActivityContextManager = new();
|
||||
}
|
||||
|
||||
public virtual void Dispose()
|
||||
{
|
||||
PluginServices.ClientState.TerritoryChanged -= ClientState_TerritoryChanged;
|
||||
ActivityContextManager.Dispose();
|
||||
}
|
||||
|
||||
protected abstract bool IsIconVisible(Tag tag);
|
||||
|
||||
protected abstract bool IsTextVisible(Tag tag);
|
||||
|
||||
private void ClientState_TerritoryChanged(object? sender, ushort e)
|
||||
{
|
||||
m_CurrentActivityContext = ActivityContext.None;
|
||||
|
||||
var contentFinderConditionsSheet = PluginServices.DataManager.GameData.GetExcelSheet<ContentFinderCondition>();
|
||||
if (contentFinderConditionsSheet != null)
|
||||
{
|
||||
var foundContentFinderCondition = contentFinderConditionsSheet.FirstOrDefault(contentFinderCondition => contentFinderCondition.TerritoryType.Row == PluginServices.ClientState.TerritoryType);
|
||||
if (foundContentFinderCondition != null)
|
||||
{
|
||||
if (foundContentFinderCondition.PvP)
|
||||
{
|
||||
m_CurrentActivityContext = ActivityContext.PvpDuty;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_CurrentActivityContext = ActivityContext.PveDuty;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected bool IsTagVisible(Tag tag, GameObject? gameObject)
|
||||
{
|
||||
bool isVisibleForActivity = ActivityContextHelper.GetIsVisible(m_CurrentActivityContext,
|
||||
bool isVisibleForActivity = ActivityContextHelper.GetIsVisible(ActivityContextManager.CurrentActivityContext,
|
||||
tag.IsVisibleInPveDuties.InheritedValue ?? false,
|
||||
tag.IsVisibleInPvpDuties.InheritedValue ?? false,
|
||||
tag.IsVisibleInOverworld.InheritedValue ?? false);
|
||||
|
||||
Reference in New Issue
Block a user