From 1e3380cbd112f9e7f7e494a6540715eb3bb7a6a7 Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Sun, 6 Nov 2022 11:32:02 +0100 Subject: [PATCH] implement job icon feature --- .../Configuration/PluginConfiguration.cs | 4 +- .../Configuration/PluginConfigurationUI.cs | 5 ++ PlayerTags/Data/DefaultPluginData.cs | 4 +- PlayerTags/Data/Tag.cs | 9 ++- PlayerTags/Features/ChatTagTargetFeature.cs | 4 +- .../Features/NameplateTagTargetFeature.cs | 37 +++++++-- PlayerTags/Resources/Strings.Designer.cs | 75 +++++++++++++++---- PlayerTags/Resources/Strings.resx | 27 +++++-- 8 files changed, 130 insertions(+), 35 deletions(-) diff --git a/PlayerTags/Configuration/PluginConfiguration.cs b/PlayerTags/Configuration/PluginConfiguration.cs index 3c5761b..bc340e4 100644 --- a/PlayerTags/Configuration/PluginConfiguration.cs +++ b/PlayerTags/Configuration/PluginConfiguration.cs @@ -1,6 +1,7 @@ using Dalamud.Configuration; using Newtonsoft.Json; using Pilz.Dalamud.ActivityContexts; +using Pilz.Dalamud.Nameplates.Tools; using PlayerTags.Data; using PlayerTags.Inheritables; using System; @@ -35,12 +36,13 @@ namespace PlayerTags.Configuration { ActivityType.PvpDuty, new GeneralOptionsClass() } }; + public StatusIconPriorizerSettings StatusIconPriorizerSettings = new(); public bool IsPlayerNameRandomlyGenerated = false; public bool IsCustomTagsContextMenuEnabled = true; public bool IsShowInheritedPropertiesEnabled = true; public bool IsPlayersTabOrderedByProximity = false; public bool IsPlayersTabSelfVisible = true; - public bool IsPlayersTabFriendsVisible = true; + public bool IsPlayersTabFriendsVisible = true; public bool IsPlayersTabPartyVisible = true; public bool IsPlayersTabAllianceVisible = true; public bool IsPlayersTabEnemiesVisible = true; diff --git a/PlayerTags/Configuration/PluginConfigurationUI.cs b/PlayerTags/Configuration/PluginConfigurationUI.cs index 9f2f923..d012e00 100644 --- a/PlayerTags/Configuration/PluginConfigurationUI.cs +++ b/PlayerTags/Configuration/PluginConfigurationUI.cs @@ -6,6 +6,7 @@ using Dalamud.Logging; using ImGuiNET; using Lumina.Excel.GeneratedSheets; using Pilz.Dalamud.ActivityContexts; +using Pilz.Dalamud.Icons; using PlayerTags.Data; using PlayerTags.Inheritables; using PlayerTags.PluginStrings; @@ -692,6 +693,10 @@ namespace PlayerTags.Configuration { DrawInheritable(selectedInheritable.Inheritable.Key, true, false, inheritableNameplateTitlePosition); } + else if (selectedInheritable.Inheritable.Value is InheritableValue inheritableJobIconSetName) + { + DrawInheritable(selectedInheritable.Inheritable.Key, false, false, inheritableJobIconSetName); + } else if (selectedInheritable.Inheritable.Value is InheritableReference inheritableString) { DrawInheritable(selectedInheritable.Inheritable.Key, inheritableString); diff --git a/PlayerTags/Data/DefaultPluginData.cs b/PlayerTags/Data/DefaultPluginData.cs index 143fc64..48263ae 100644 --- a/PlayerTags/Data/DefaultPluginData.cs +++ b/PlayerTags/Data/DefaultPluginData.cs @@ -50,9 +50,9 @@ namespace PlayerTags.Data { IsSelected = false, IsExpanded = true, - IsIconVisibleInChat = true, + IsRoleIconVisibleInChat = true, IsTextVisibleInChat = true, - IsIconVisibleInNameplates = true, + IsRoleIconVisibleInNameplates = true, IsTextVisibleInNameplates = true, IsTextColorAppliedToChatName = true, }; diff --git a/PlayerTags/Data/Tag.cs b/PlayerTags/Data/Tag.cs index 51e9d0a..e32fe59 100644 --- a/PlayerTags/Data/Tag.cs +++ b/PlayerTags/Data/Tag.cs @@ -1,4 +1,5 @@ using Dalamud.Game.Text.SeStringHandling; +using Pilz.Dalamud.Icons; using PlayerTags.Inheritables; using PlayerTags.PluginStrings; using System; @@ -99,9 +100,13 @@ namespace PlayerTags.Data [InheritableCategory("IconCategory")] public InheritableValue Icon = new InheritableValue(BitmapFontIcon.Aethernet); [InheritableCategory("IconCategory")] - public InheritableValue IsIconVisibleInChat = new InheritableValue(false); + public InheritableValue IsRoleIconVisibleInChat = new InheritableValue(false); [InheritableCategory("IconCategory")] - public InheritableValue IsIconVisibleInNameplates = new InheritableValue(false); + public InheritableValue IsRoleIconVisibleInNameplates = new InheritableValue(false); + [InheritableCategory("IconCategory")] + public InheritableValue IsJobIconVisibleInNameplates = new InheritableValue(false); + [InheritableCategory("IconCategory")] + public InheritableValue JobIconSet = new InheritableValue(JobIconSetName.Framed); [InheritableCategory("TextCategory")] public InheritableReference Text = new InheritableReference(""); diff --git a/PlayerTags/Features/ChatTagTargetFeature.cs b/PlayerTags/Features/ChatTagTargetFeature.cs index 9e25e90..4239425 100644 --- a/PlayerTags/Features/ChatTagTargetFeature.cs +++ b/PlayerTags/Features/ChatTagTargetFeature.cs @@ -130,9 +130,9 @@ namespace PlayerTags.Features protected override bool IsIconVisible(Tag tag) { - if (tag.IsIconVisibleInChat.InheritedValue != null) + if (tag.IsRoleIconVisibleInChat.InheritedValue != null) { - return tag.IsIconVisibleInChat.InheritedValue.Value; + return tag.IsRoleIconVisibleInChat.InheritedValue.Value; } return false; diff --git a/PlayerTags/Features/NameplateTagTargetFeature.cs b/PlayerTags/Features/NameplateTagTargetFeature.cs index 869e968..c73205f 100644 --- a/PlayerTags/Features/NameplateTagTargetFeature.cs +++ b/PlayerTags/Features/NameplateTagTargetFeature.cs @@ -3,6 +3,7 @@ using Dalamud.Game.ClientState.Objects.Types; using Dalamud.Game.Text.SeStringHandling; using Dalamud.Game.Text.SeStringHandling.Payloads; using Lumina.Excel.GeneratedSheets; +using Pilz.Dalamud.Icons; using Pilz.Dalamud.Nameplates.Tools; using Pilz.Dalamud.Tools.Strings; using PlayerTags.Configuration; @@ -20,25 +21,31 @@ namespace PlayerTags.Features /// public class NameplateTagTargetFeature : TagTargetFeature { - private PluginConfiguration m_PluginConfiguration; - private PluginData m_PluginData; + private readonly PluginConfiguration m_PluginConfiguration; + private readonly PluginData m_PluginData; + private readonly StatusIconPriorizer statusiconPriorizer; + private readonly JobIconSets jobIconSets = new(); private Nameplate? m_Nameplate; public NameplateTagTargetFeature(PluginConfiguration pluginConfiguration, PluginData pluginData) { m_PluginConfiguration = pluginConfiguration; m_PluginData = pluginData; + statusiconPriorizer = new(pluginConfiguration.StatusIconPriorizerSettings); PluginServices.ClientState.Login += ClientState_Login; PluginServices.ClientState.Logout += ClientState_Logout; + Hook(); } public override void Dispose() { Unhook(); + PluginServices.ClientState.Logout -= ClientState_Logout; PluginServices.ClientState.Login -= ClientState_Login; + base.Dispose(); } @@ -81,9 +88,9 @@ namespace PlayerTags.Features protected override bool IsIconVisible(Tag tag) { - if (tag.IsIconVisibleInNameplates.InheritedValue != null) + if (tag.IsRoleIconVisibleInNameplates.InheritedValue != null) { - return tag.IsIconVisibleInNameplates.InheritedValue.Value; + return tag.IsRoleIconVisibleInNameplates.InheritedValue.Value; } return false; @@ -102,9 +109,12 @@ namespace PlayerTags.Features private void Nameplate_PlayerNameplateUpdated(PlayerNameplateUpdatedArgs args) { var beforeTitleBytes = args.Title.Encode(); - AddTagsToNameplate(args.PlayerCharacter, args.Name, args.Title, args.FreeCompany); + var iconID = args.IconId; var generalOptions = m_PluginConfiguration.GeneralOptions[ActivityContextManager.CurrentActivityContext.ActivityType]; + AddTagsToNameplate(args.PlayerCharacter, args.Name, args.Title, args.FreeCompany, ref iconID); + args.IconId = iconID; + if (generalOptions.NameplateTitlePosition == NameplateTitlePosition.AlwaysAboveName) args.IsTitleAboveName = true; else if (generalOptions.NameplateTitlePosition == NameplateTitlePosition.AlwaysBelowName) @@ -147,8 +157,9 @@ namespace PlayerTags.Features /// The name text to change. /// The title text to change. /// The free company text to change. - private void AddTagsToNameplate(GameObject gameObject, SeString name, SeString title, SeString freeCompany) + private void AddTagsToNameplate(GameObject gameObject, SeString name, SeString title, SeString freeCompany, ref int statusIcon) { + int? newStatusIcon = null; NameplateChanges nameplateChanges = new(); nameplateChanges.GetProps(NameplateElements.Name).Destination = name; nameplateChanges.GetProps(NameplateElements.Title).Destination = title; @@ -156,8 +167,11 @@ namespace PlayerTags.Features if (gameObject is PlayerCharacter playerCharacter) { + var classJob = playerCharacter.ClassJob; + var classJobGameData = classJob?.GameData; + // Add the job tags - if (playerCharacter.ClassJob.GameData != null && m_PluginData.JobTags.TryGetValue(playerCharacter.ClassJob.GameData.Abbreviation, out var jobTag)) + if (classJobGameData != null && m_PluginData.JobTags.TryGetValue(classJobGameData.Abbreviation, out var jobTag)) { if (jobTag.TagTargetInNameplates.InheritedValue != null && jobTag.TagPositionInNameplates.InheritedValue != null) checkTag(jobTag); @@ -192,9 +206,18 @@ namespace PlayerTags.Features if (payloads.Any()) AddPayloadChanges(tag.TagTargetInNameplates.InheritedValue.Value, tag.TagPositionInNameplates.InheritedValue.Value, payloads, nameplateChanges, false); } + if (newStatusIcon == null && classJob != null && (tag.IsJobIconVisibleInNameplates?.InheritedValue ?? false)) + newStatusIcon = jobIconSets.GetJobIcon(JobIconSetName.Framed, classJob.Id); } } + // Apply new status icon + if (newStatusIcon != null) + { + var change = nameplateChanges.GetChange(NameplateElements.Name, StringPosition.Before); + NameplateUpdateFactory.ApplyStatusIconWithPrio(ref statusIcon, (int)newStatusIcon, change, ActivityContextManager.CurrentActivityContext, statusiconPriorizer); + } + // Build the final strings out of the payloads ApplyNameplateChanges(nameplateChanges); diff --git a/PlayerTags/Resources/Strings.Designer.cs b/PlayerTags/Resources/Strings.Designer.cs index ceb3809..a7e101f 100644 --- a/PlayerTags/Resources/Strings.Designer.cs +++ b/PlayerTags/Resources/Strings.Designer.cs @@ -358,29 +358,20 @@ namespace PlayerTags.Resources { } /// - /// Sucht eine lokalisierte Zeichenfolge, die Whether the icon will be shown in chat. ähnelt. + /// Sucht eine lokalisierte Zeichenfolge, die Show job icon in nameplates ähnelt. /// - public static string Loc_IsIconVisibleInChat_Description { + public static string Loc_IsJobIconVisibleInNameplates { get { - return ResourceManager.GetString("Loc_IsIconVisibleInChat_Description", resourceCulture); + return ResourceManager.GetString("Loc_IsJobIconVisibleInNameplates", resourceCulture); } } /// - /// Sucht eine lokalisierte Zeichenfolge, die Show in nameplates ähnelt. + /// Sucht eine lokalisierte Zeichenfolge, die Whether the job icon will be shown in nameplates. ähnelt. /// - public static string Loc_IsIconVisibleInNameplates { + public static string Loc_IsJobIconVisibleInNameplates_Description { get { - return ResourceManager.GetString("Loc_IsIconVisibleInNameplates", resourceCulture); - } - } - - /// - /// Sucht eine lokalisierte Zeichenfolge, die Whether the icon will be shown in nameplates. ähnelt. - /// - public static string Loc_IsIconVisibleInNameplates_Description { - get { - return ResourceManager.GetString("Loc_IsIconVisibleInNameplates_Description", resourceCulture); + return ResourceManager.GetString("Loc_IsJobIconVisibleInNameplates_Description", resourceCulture); } } @@ -546,6 +537,42 @@ namespace PlayerTags.Resources { } } + /// + /// Sucht eine lokalisierte Zeichenfolge, die Whether the role icon will be shown in chat. ähnelt. + /// + public static string Loc_IsRoleIconVisibleInChat_Description { + get { + return ResourceManager.GetString("Loc_IsRoleIconVisibleInChat_Description", resourceCulture); + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die Show role icon in nameplates ähnelt. + /// + public static string Loc_IsRoleIconVisibleInNameplates { + get { + return ResourceManager.GetString("Loc_IsRoleIconVisibleInNameplates", resourceCulture); + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die Whether the role icon will be shown in nameplates. ähnelt. + /// + public static string Loc_IsRoleIconVisibleInNameplates_Description { + get { + return ResourceManager.GetString("Loc_IsRoleIconVisibleInNameplates_Description", resourceCulture); + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die Show role icon in nameplate ähnelt. + /// + public static string Loc_IsRoleJobIconVisibleInNameplates { + get { + return ResourceManager.GetString("Loc_IsRoleJobIconVisibleInNameplates", resourceCulture); + } + } + /// /// Sucht eine lokalisierte Zeichenfolge, die Selected ähnelt. /// @@ -861,6 +888,24 @@ namespace PlayerTags.Resources { } } + /// + /// Sucht eine lokalisierte Zeichenfolge, die Job icon set ähnelt. + /// + public static string Loc_JobIconSet { + get { + return ResourceManager.GetString("Loc_JobIconSet", resourceCulture); + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die The icon set to use for displaying the job icon. You can also choose the role icon set to display the role icon instead. ähnelt. + /// + public static string Loc_JobIconSet_Description { + get { + return ResourceManager.GetString("Loc_JobIconSet_Description", resourceCulture); + } + } + /// /// Sucht eine lokalisierte Zeichenfolge, die Hand ähnelt. /// diff --git a/PlayerTags/Resources/Strings.resx b/PlayerTags/Resources/Strings.resx index c272ddc..c5639a9 100644 --- a/PlayerTags/Resources/Strings.resx +++ b/PlayerTags/Resources/Strings.resx @@ -354,14 +354,14 @@ Show in chat - - Whether the icon will be shown in chat. + + Whether the role icon will be shown in chat. - - Show in nameplates + + Show role icon in nameplates - - Whether the icon will be shown in nameplates. + + Whether the role icon will be shown in nameplates. Text @@ -642,4 +642,19 @@ Chat + + Show role icon in nameplate + + + Show job icon in nameplates + + + Whether the job icon will be shown in nameplates. + + + Job icon set + + + The icon set to use for displaying the job icon. You can also choose the role icon set to display the role icon instead. + \ No newline at end of file