add settings for chat target types (broken state yet)

This commit is contained in:
2022-11-09 12:57:23 +01:00
parent c2b2fa86a4
commit 5501d1ecc4
16 changed files with 282 additions and 48 deletions

View File

@@ -5,8 +5,6 @@ VisualStudioVersion = 17.3.32929.385
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlayerTags", "PlayerTags\PlayerTags.csproj", "{13C812E9-0D42-4B95-8646-40EEBF30636F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pilz.Dalamud", "..\Pilz.Dalamud\Pilz.Dalamud\Pilz.Dalamud.csproj", "{A92D2FFC-FDB8-4F28-B5DD-4A1B3EB0B1BB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
@@ -17,10 +15,6 @@ Global
{13C812E9-0D42-4B95-8646-40EEBF30636F}.Debug|x64.Build.0 = Debug|x64
{13C812E9-0D42-4B95-8646-40EEBF30636F}.Release|x64.ActiveCfg = Release|x64
{13C812E9-0D42-4B95-8646-40EEBF30636F}.Release|x64.Build.0 = Release|x64
{A92D2FFC-FDB8-4F28-B5DD-4A1B3EB0B1BB}.Debug|x64.ActiveCfg = Debug|x64
{A92D2FFC-FDB8-4F28-B5DD-4A1B3EB0B1BB}.Debug|x64.Build.0 = Debug|x64
{A92D2FFC-FDB8-4F28-B5DD-4A1B3EB0B1BB}.Release|x64.ActiveCfg = Release|x64
{A92D2FFC-FDB8-4F28-B5DD-4A1B3EB0B1BB}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@@ -1,19 +1,27 @@
using Dalamud.Configuration;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Pilz.Dalamud.ActivityContexts;
using Pilz.Dalamud.Nameplates.Tools;
using PlayerTags.Data;
using PlayerTags.Inheritables;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection.Metadata.Ecma335;
using System.Runtime.CompilerServices;
namespace PlayerTags.Configuration
{
[Serializable]
public class PluginConfiguration : IPluginConfiguration
{
public int Version { get; set; } = 1;
private const int DEFAULT_CONFIG_VERSION = 1;
[JsonProperty]
public int RootVersion { get; private set; } = DEFAULT_CONFIG_VERSION;
public int Version { get; set; } = DEFAULT_CONFIG_VERSION;
public bool IsVisible = false;
[JsonProperty("GeneralOptionsV2")]
@@ -24,7 +32,7 @@ namespace PlayerTags.Configuration
{ ActivityType.PvpDuty, new GeneralOptionsClass() }
};
public StatusIconPriorizerSettings StatusIconPriorizerSettings = new();
public StatusIconPriorizerSettings StatusIconPriorizerSettings = new(true);
public bool IsPlayerNameRandomlyGenerated = false;
public bool IsCustomTagsContextMenuEnabled = true;
public bool IsShowInheritedPropertiesEnabled = true;
@@ -218,9 +226,56 @@ namespace PlayerTags.Configuration
Identities = pluginData.Identities;
PluginServices.DalamudPluginInterface.SavePluginConfig(this);
SavePluginConfig();
Saved?.Invoke();
}
private void SavePluginConfig()
{
Version = DEFAULT_CONFIG_VERSION;
var configFilePath = GetConfigFilePath();
var configFileContent = JsonConvert.SerializeObject(this, Formatting.Indented, GetJsonSettings());
File.WriteAllText(configFilePath, configFileContent);
}
public static PluginConfiguration LoadPluginConfig()
{
var configFilePath = GetConfigFilePath();
object config = null;
if (File.Exists(configFilePath))
{
var configFileContent = File.ReadAllText(configFilePath);
config = JsonConvert.DeserializeObject<PluginConfiguration>(configFileContent, GetJsonSettings());
}
else
{
// Try loading the old settings, if possible
configFilePath = PluginServices.DalamudPluginInterface.ConfigFile.FullName;
config = PluginServices.DalamudPluginInterface.GetPluginConfig();
}
return config as PluginConfiguration;
}
private static string GetConfigFilePath()
{
return Path.Combine(PluginServices.DalamudPluginInterface.ConfigDirectory.FullName, "Config.json");
}
private static JsonSerializerSettings GetJsonSettings()
{
var jsonSettings = new JsonSerializerSettings
{
TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple,
TypeNameHandling = TypeNameHandling.Auto,
};
jsonSettings.Converters.Add(new StringEnumConverter());
return jsonSettings;
}
}
public class GeneralOptionsClass

View File

@@ -1,8 +1,11 @@
using Dalamud.Configuration;
using Dalamud.Game.ClientState.Objects.SubKinds;
using Dalamud.Game.Text;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Interface;
using Dalamud.Logging;
using FFXIVClientStructs.FFXIV.Client.Game.UI;
using FFXIVClientStructs.Havok;
using ImGuiNET;
using Lumina.Excel.GeneratedSheets;
using Pilz.Dalamud.ActivityContexts;
@@ -15,6 +18,8 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Threading.Tasks;
using System.Transactions;
namespace PlayerTags.Configuration
{
@@ -31,6 +36,7 @@ namespace PlayerTags.Configuration
private PropertyProxy propertyProxy;
private InheritableValue<ushort>? m_ColorPickerPopupDataContext;
private Dictionary<object, object> inheritableTEnumProxies = new();
public PluginConfigurationUI(PluginConfiguration config, PluginData pluginData)
{
@@ -697,6 +703,10 @@ namespace PlayerTags.Configuration
{
DrawInheritable(selectedInheritable.Inheritable.Key, false, false, inheritableJobIconSetName);
}
else if (selectedInheritable.Inheritable.Value is InheritableReference<EnumList<XivChatType>> inheritableXivChatType)
{
DrawMultiselect(selectedInheritable.Inheritable.Key, inheritableXivChatType);
}
else if (selectedInheritable.Inheritable.Value is InheritableReference<string> inheritableString)
{
DrawInheritable(selectedInheritable.Inheritable.Key, inheritableString);
@@ -1058,6 +1068,66 @@ namespace PlayerTags.Configuration
ImGui.TextColored(new Vector4(0.7f, 0.6f, 1f, 1f), label);
}
private void DrawMultiselect<TEnum>(string localizedStringName, InheritableReference<EnumList<TEnum>> inheritable) where TEnum : Enum
{
bool isDisabled = inheritable.Behavior == InheritableBehavior.Inherit;
EnumList<TEnum> proxyKey = isDisabled ? inheritable.InheritedValue : inheritable.Value;
if (isDisabled)
proxyKey = inheritable.InheritedValue;
if (proxyKey == null)
proxyKey = inheritable.Value;
if (isDisabled)
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, 0.25f);
var isExpanded = ImGui.CollapsingHeader(Localizer.GetString(localizedStringName, false));
if (ImGui.IsItemHovered())
ImGui.SetTooltip(Localizer.GetString(localizedStringName, true));
if (isDisabled)
{
ImGui.SameLine();
ImGui.Text(Strings.Loc_Static_Inherited);
}
else
DrawRemovePropertyOverrideButton(inheritable);
if (isExpanded)
{
bool isClicked = false;
var typeofEnum = typeof(TEnum);
EnumMultiselectProxy<TEnum> proxy;
if (inheritableTEnumProxies.ContainsKey(proxyKey))
proxy = inheritableTEnumProxies[proxyKey] as EnumMultiselectProxy<TEnum>;
else
{
proxy = new EnumMultiselectProxy<TEnum>(proxyKey);
inheritableTEnumProxies.Add(proxyKey, proxy);
}
foreach (var entry in proxy.Entries)
{
var entryName = Enum.GetName(typeofEnum, entry.Value);
var tempval = entry.Enabled;
isClicked = ImGui.Checkbox(Localizer.GetString(entryName), ref isDisabled ? ref tempval : ref entry.Enabled);
if (ImGui.IsItemHovered())
ImGui.SetTooltip(Localizer.GetString(entryName, true));
}
if (!isDisabled && isClicked)
{
proxy.ApplyTo(proxyKey);
SaveSettings();
}
}
if (isDisabled)
ImGui.PopStyleVar();
}
private void DrawComboBox<TEnum>(bool isLabelVisible, bool shouldLocalizeNames, bool shouldOrderNames, ref TEnum currentValue, System.Action changed)
where TEnum : Enum
{
@@ -1278,5 +1348,42 @@ namespace PlayerTags.Configuration
PveDuty,
PvpDuty
}
private class EnumMultiselectProxy<TEnum> where TEnum : Enum
{
public List<Entry> Entries { get; } = new();
public EnumMultiselectProxy(EnumList<TEnum> target)
{
foreach (TEnum value in Enum.GetValues(typeof(TEnum)))
Entries.Add(new(value, target.Contains(value)));
}
public void ApplyTo(EnumList<TEnum> target)
{
foreach (var entry in Entries)
{
if (entry.Enabled)
{
if (!target.Contains(entry.Value))
target.Add(entry.Value);
}
else if (target.Contains(entry.Value))
target.Remove(entry.Value);
}
}
public class Entry
{
public TEnum Value { get; set; }
public bool Enabled;
public Entry(TEnum value, bool enabled)
{
Value = value;
Enabled = enabled;
}
}
}
}
}

View File

@@ -1,5 +1,7 @@
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Game.Text;
using Dalamud.Game.Text.SeStringHandling;
using Lumina.Excel.GeneratedSheets;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -44,6 +46,8 @@ namespace PlayerTags.Data
IsVisibleForAlliancePlayers = true,
IsVisibleForEnemyPlayers = true,
IsVisibleForOtherPlayers = true,
TargetChatTypes = new EnumList<XivChatType>(Enum.GetValues<XivChatType>()),
};
AllRoleTags = new Tag()

View File

@@ -1,5 +1,7 @@
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Game.Text;
using Dalamud.Game.Text.SeStringHandling;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Pilz.Dalamud.Icons;
using PlayerTags.Inheritables;
using PlayerTags.PluginStrings;
@@ -172,6 +174,9 @@ namespace PlayerTags.Data
[InheritableCategory("PlayerCategory")]
public InheritableValue<bool> IsVisibleForOtherPlayers = new InheritableValue<bool>(false);
[InheritableCategory("ChatFeatureCategory")]
public InheritableReference<EnumList<XivChatType>> TargetChatTypes = new(new EnumList<XivChatType>(Enum.GetValues<XivChatType>()));
[JsonIgnore]
public string[] IdentitiesToAddTo
{

View File

@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PlayerTags.Data
{
public class EnumList<TEnum> : List<TEnum> where TEnum : Enum
{
public EnumList() : base()
{
}
public EnumList(IEnumerable<TEnum> collection) : base(collection)
{
}
//// this is first one '=='
//public static bool operator ==(EnumList<TEnum> obj1, EnumList<TEnum> obj2)
//{
//}
//// this is second one '!='
//public static bool operator !=(EnumList<TEnum> obj1, EnumList<TEnum> obj2)
//{
// return !(obj1 == obj2);
//}
public override bool Equals(object? obj)
{
var obj1 = this;
var obj2 = obj as EnumList<TEnum>;
if (obj1 is not null && obj2 is not null)
{
if (obj1.Count != obj2.Count)
return false;
for (int i = 0; i < obj1.Count; i++)
{
if (!obj1[i]?.Equals(obj2[i]) ?? true)
return false;
}
}
return true;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}

View File

@@ -345,7 +345,7 @@ namespace PlayerTags.Features
// Add the job tag
if (playerCharacter.ClassJob.GameData != null && m_PluginData.JobTags.TryGetValue(playerCharacter.ClassJob.GameData.Abbreviation, out var jobTag))
{
if (jobTag.TagPositionInChat.InheritedValue != null)
if (jobTag.TagPositionInChat.InheritedValue != null && jobTag.TargetChatTypes.InheritedValue != null && jobTag.TargetChatTypes.Value.Contains(chatType))
{
var payloads = GetPayloads(jobTag, stringMatch.GameObject);
if (payloads.Any())

View File

@@ -1,30 +0,0 @@
using Newtonsoft.Json;
using System;
namespace PlayerTags
{
public class GeneralConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
{
if (value != null && value.GetType().IsEnum)
{
writer.WriteValue(Enum.GetName(value.GetType(), value));
}
else
{
writer.WriteValue(value);
}
}
public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
{
return reader.Value;
}
public override bool CanConvert(Type objectType)
{
return true;
}
}
}

View File

@@ -1,4 +1,7 @@
namespace PlayerTags.Inheritables
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace PlayerTags.Inheritables
{
public enum InheritableBehavior
{

View File

@@ -12,7 +12,6 @@ namespace PlayerTags.Inheritables
public InheritableBehavior Behavior;
[JsonProperty("Value")]
[JsonConverter(typeof(GeneralConverter))]
public object Value;
}
}

View File

@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace PlayerTags.Inheritables
{

View File

@@ -26,7 +26,7 @@
<ItemGroup>
<PackageReference Include="Dalamud.ContextMenu" Version="1.2.1" />
<PackageReference Include="DalamudPackager" Version="2.1.8" />
<ProjectReference Include="..\..\Pilz.Dalamud\Pilz.Dalamud\Pilz.Dalamud.csproj" />
<PackageReference Include="Pilz.Dalamud" Version="0.1.0" />
<Reference Include="FFXIVClientStructs">
<HintPath>$(DalamudLibPath)FFXIVClientStructs.dll</HintPath>
<Private>false</Private>

View File

@@ -1,4 +1,5 @@
using Dalamud.Game.Command;
using Dalamud.Logging;
using Dalamud.Plugin;
using Dalamud.Plugin.Internal;
using FFXIVClientStructs.FFXIV.Client.UI.Misc;
@@ -30,7 +31,7 @@ namespace PlayerTags
PluginServices.Initialize(pluginInterface);
Pilz.Dalamud.PluginServices.Initialize(pluginInterface);
m_PluginConfiguration = PluginServices.DalamudPluginInterface.GetPluginConfig() as PluginConfiguration ?? new PluginConfiguration();
m_PluginConfiguration = PluginConfiguration.LoadPluginConfig() ?? new PluginConfiguration();
m_PluginData = new PluginData(m_PluginConfiguration);
m_PluginConfigurationUI = new PluginConfigurationUI(m_PluginConfiguration, m_PluginData);

View File

@@ -177,6 +177,15 @@ namespace PlayerTags.Resources {
}
}
/// <summary>
/// Sucht eine lokalisierte Zeichenfolge, die Advanced Chat Options ähnelt.
/// </summary>
public static string Loc_ChatFeatureCategory {
get {
return ResourceManager.GetString("Loc_ChatFeatureCategory", resourceCulture);
}
}
/// <summary>
/// Sucht eine lokalisierte Zeichenfolge, die Custom id ähnelt.
/// </summary>
@@ -1617,6 +1626,24 @@ namespace PlayerTags.Resources {
}
}
/// <summary>
/// Sucht eine lokalisierte Zeichenfolge, die Target Chat Types ähnelt.
/// </summary>
public static string Loc_TargetChatTypes {
get {
return ResourceManager.GetString("Loc_TargetChatTypes", resourceCulture);
}
}
/// <summary>
/// Sucht eine lokalisierte Zeichenfolge, die Defines for which chat type the chat features of this tag should be enabled for. ähnelt.
/// </summary>
public static string Loc_TargetChatTypes_Description {
get {
return ResourceManager.GetString("Loc_TargetChatTypes_Description", resourceCulture);
}
}
/// <summary>
/// Sucht eine lokalisierte Zeichenfolge, die Text ähnelt.
/// </summary>

View File

@@ -657,4 +657,13 @@
<data name="Loc_JobIconSet_Description" xml:space="preserve">
<value>The icon set to use for displaying the job icon. You can also choose the role icon set to display the role icon instead.</value>
</data>
<data name="Loc_ChatFeatureCategory" xml:space="preserve">
<value>Advanced Chat Options</value>
</data>
<data name="Loc_TargetChatTypes" xml:space="preserve">
<value>Target Chat Types</value>
</data>
<data name="Loc_TargetChatTypes_Description" xml:space="preserve">
<value>Defines for which chat type the chat features of this tag should be enabled for.</value>
</data>
</root>

View File

@@ -14,8 +14,11 @@
"resolved": "2.1.8",
"contentHash": "YqagNXs9InxmqkXzq7kLveImxnodkBEicAhydMXVp7dFjC7xb76U6zGgAax4/BWIWfZeWzr5DJyQSev31kj81A=="
},
"pilz.dalamud": {
"type": "Project"
"Pilz.Dalamud": {
"type": "Direct",
"requested": "[0.1.0, )",
"resolved": "0.1.0",
"contentHash": "n22WXrCzA+EAQHi4ve4PgTZYDzr0f0qsQ/1ApBBQjoCKJcwFox2rO692/2davRWiUQiNv9B56ikcnHocLp75tQ=="
}
}
}