From 486a5ddbe69e602d2feedfe7da304f92c2bd56e5 Mon Sep 17 00:00:00 2001 From: RisaDev <151885272+RisaDev@users.noreply.github.com> Date: Fri, 18 Oct 2024 21:48:19 +0300 Subject: [PATCH] Rewrite ApplyToCurrentlyActiveCharacter so it behaves like DefaultProfile --- .../Armatures/Services/ArmatureManager.cs | 9 ++-- CustomizePlus/Profiles/Data/Profile.cs | 3 -- .../Profiles/Events/ProfileChanged.cs | 2 +- .../Profiles/ProfileManager.ProfileLoading.cs | 1 - CustomizePlus/Profiles/ProfileManager.cs | 51 +++++++++++-------- .../MainWindow/Tabs/Profiles/ProfilePanel.cs | 26 +++++++--- 6 files changed, 54 insertions(+), 38 deletions(-) diff --git a/CustomizePlus/Armatures/Services/ArmatureManager.cs b/CustomizePlus/Armatures/Services/ArmatureManager.cs index dd0f707..1242e00 100644 --- a/CustomizePlus/Armatures/Services/ArmatureManager.cs +++ b/CustomizePlus/Armatures/Services/ArmatureManager.cs @@ -413,10 +413,10 @@ public unsafe sealed class ArmatureManager : IDisposable type is not ProfileChanged.Type.TemporaryProfileDeleted && type is not ProfileChanged.Type.ChangedCharacter && type is not ProfileChanged.Type.ChangedDefaultProfile && - type is not ProfileChanged.Type.ApplyToCurrentlyActiveCharacterChanged) + type is not ProfileChanged.Type.ChangedDefaultLocalPlayerProfile) return; - if (type == ProfileChanged.Type.ChangedDefaultProfile) + if (type == ProfileChanged.Type.ChangedDefaultProfile || type == ProfileChanged.Type.ChangedDefaultLocalPlayerProfile) { var oldProfile = (Profile?)arg3; @@ -426,7 +426,7 @@ public unsafe sealed class ArmatureManager : IDisposable foreach (var armature in oldProfile.Armatures) armature.IsPendingProfileRebind = true; - _logger.Debug($"ArmatureManager.OnProfileChange Profile no longer default, armatures rebind scheduled: {type}, old profile: {oldProfile.Name.Text.Incognify()}->{oldProfile.Enabled}"); + _logger.Debug($"ArmatureManager.OnProfileChange Profile no longer default/default for local player, armatures rebind scheduled: {type}, old profile: {oldProfile.Name.Text.Incognify()}->{oldProfile.Enabled}"); return; } @@ -505,8 +505,7 @@ public unsafe sealed class ArmatureManager : IDisposable if (type == ProfileChanged.Type.ChangedCharacter || type == ProfileChanged.Type.Deleted || - type == ProfileChanged.Type.TemporaryProfileDeleted || - type == ProfileChanged.Type.ApplyToCurrentlyActiveCharacterChanged) + type == ProfileChanged.Type.TemporaryProfileDeleted) { if (profile.Armatures.Count == 0) return; diff --git a/CustomizePlus/Profiles/Data/Profile.cs b/CustomizePlus/Profiles/Data/Profile.cs index 35603aa..841e4a9 100644 --- a/CustomizePlus/Profiles/Data/Profile.cs +++ b/CustomizePlus/Profiles/Data/Profile.cs @@ -33,7 +33,6 @@ public sealed class Profile : ISavable public LowerString CharacterName { get; set; } = LowerString.Empty; public ActorIdentifier Character { get; set; } = ActorIdentifier.Invalid; - public bool ApplyToCurrentlyActiveCharacter { get; set; } public LowerString Name { get; set; } = LowerString.Empty; @@ -80,7 +79,6 @@ public sealed class Profile : ISavable public Profile(Profile original) : this() { Character = original.Character; - ApplyToCurrentlyActiveCharacter = original.ApplyToCurrentlyActiveCharacter; foreach (var template in original.Templates) { @@ -105,7 +103,6 @@ public sealed class Profile : ISavable ["ModifiedDate"] = ModifiedDate, ["CharacterName"] = CharacterName.Text, ["Character"] = Character.ToJson(), - ["ApplyToCurrentlyActiveCharacter"] = ApplyToCurrentlyActiveCharacter, ["Name"] = Name.Text, ["Enabled"] = Enabled, ["IsWriteProtected"] = IsWriteProtected, diff --git a/CustomizePlus/Profiles/Events/ProfileChanged.cs b/CustomizePlus/Profiles/Events/ProfileChanged.cs index a0f63d1..1df3200 100644 --- a/CustomizePlus/Profiles/Events/ProfileChanged.cs +++ b/CustomizePlus/Profiles/Events/ProfileChanged.cs @@ -22,8 +22,8 @@ public sealed class ProfileChanged() : EventWrapper() ?? false; profile.CharacterName = new LowerString(obj["CharacterName"]?.ToObject()?.Trim() ?? throw new ArgumentNullException("CharacterName")); //temp return profile; diff --git a/CustomizePlus/Profiles/ProfileManager.cs b/CustomizePlus/Profiles/ProfileManager.cs index f08056a..77421aa 100644 --- a/CustomizePlus/Profiles/ProfileManager.cs +++ b/CustomizePlus/Profiles/ProfileManager.cs @@ -52,6 +52,7 @@ public partial class ProfileManager : IDisposable public readonly List Profiles = new(); public Profile? DefaultProfile { get; private set; } + public Profile? DefaultLocalPlayerProfile { get; private set; } public ProfileManager( TemplateManager templateManager, @@ -255,19 +256,6 @@ public partial class ProfileManager : IDisposable throw new ProfileNotFoundException(); } - public void SetApplyToCurrentlyActiveCharacter(Profile profile, bool value) - { - //todo: only one profile is allowed to be active for that setting - if (profile.ApplyToCurrentlyActiveCharacter != value) - { - profile.ApplyToCurrentlyActiveCharacter = value; - - SaveProfile(profile); - - _event.Invoke(ProfileChanged.Type.ApplyToCurrentlyActiveCharacterChanged, profile, value); - } - } - public void DeleteTemplate(Profile profile, int templateIndex) { _logger.Debug($"Deleting template #{templateIndex} from {profile}..."); @@ -342,6 +330,26 @@ public partial class ProfileManager : IDisposable _event.Invoke(ProfileChanged.Type.ChangedDefaultProfile, profile, previousProfile); } + public void SetDefaultLocalPlayerProfile(Profile? profile) + { + if (profile == null) + { + if (DefaultLocalPlayerProfile == null) + return; + } + else if (!Profiles.Contains(profile)) + return; + + var previousProfile = DefaultLocalPlayerProfile; + + DefaultLocalPlayerProfile = profile; + _configuration.DefaultLocalPlayerProfile = profile?.UniqueId ?? Guid.Empty; + _configuration.Save(); + + _logger.Debug($"Set profile {profile?.Incognito ?? "no profile"} as default local player profile"); + _event.Invoke(ProfileChanged.Type.ChangedDefaultLocalPlayerProfile, profile, previousProfile); + } + //warn: temporary profile system does not support any world identifiers public void AddTemporaryProfile(Profile profile, Actor actor) { @@ -453,14 +461,8 @@ public partial class ProfileManager : IDisposable if (profile == DefaultProfile) return false; - if (profile.ApplyToCurrentlyActiveCharacter) - { - if (_objectManager.IsInLobby) - return true; - - var currentPlayer = _actorManager.GetCurrentPlayer(); - return currentPlayer.IsValid && currentPlayer.MatchesIgnoringOwnership(actorIdentifier); - } + if (profile == DefaultLocalPlayerProfile) + return false; if (actorIdentifier.Type == IdentifierType.Owned && !actorIdentifier.IsOwnedByLocalPlayer()) return false; @@ -489,6 +491,13 @@ public partial class ProfileManager : IDisposable } } + if (DefaultLocalPlayerProfile != null && DefaultLocalPlayerProfile.Enabled) + { + var currentPlayer = _actorManager.GetCurrentPlayer(); + if(_objectManager.IsInLobby || (currentPlayer.IsValid && currentPlayer.Matches(actorIdentifier))) + yield return DefaultLocalPlayerProfile; + } + if (DefaultProfile != null && DefaultProfile.Enabled && (actorIdentifier.Type == IdentifierType.Player || actorIdentifier.Type == IdentifierType.Retainer)) diff --git a/CustomizePlus/UI/Windows/MainWindow/Tabs/Profiles/ProfilePanel.cs b/CustomizePlus/UI/Windows/MainWindow/Tabs/Profiles/ProfilePanel.cs index bb507c8..c566ae5 100644 --- a/CustomizePlus/UI/Windows/MainWindow/Tabs/Profiles/ProfilePanel.cs +++ b/CustomizePlus/UI/Windows/MainWindow/Tabs/Profiles/ProfilePanel.cs @@ -216,7 +216,7 @@ public class ProfilePanel if (!_selector.IncognitoMode) { bool showMultipleMessage = false; - if (_manager.DefaultProfile != _selector.Selected && !_selector.Selected!.ApplyToCurrentlyActiveCharacter) + if (_manager.DefaultProfile != _selector.Selected && _manager.DefaultLocalPlayerProfile != _selector.Selected) { ImGui.Text(_selector.Selected!.Character.IsValid ? $"Applies to {(_selector.Selected?.Character.Type == Penumbra.GameData.Enums.IdentifierType.Owned ? _selector.Selected?.Character.ToNameWithoutOwnerName() : _selector.Selected?.Character.ToString())}" : "No valid character selected for the profile"); @@ -264,11 +264,23 @@ public class ProfilePanel ImGui.Separator(); - var anyActiveCharaBool = _selector.Selected?.ApplyToCurrentlyActiveCharacter ?? false; - if (ImGui.Checkbox("##ApplyToCurrentlyActiveCharacter", ref anyActiveCharaBool)) - _manager.SetApplyToCurrentlyActiveCharacter(_selector.Selected!, anyActiveCharaBool); - ImGuiUtil.LabeledHelpMarker("Apply to any character you are logged in with", - "Whether the templates in this profile should be applied to any character you are currently logged in with."); + var isDefaultLP = _manager.DefaultLocalPlayerProfile == _selector.Selected; + var isDefaultLPOrCurrentProfilesEnabled = (_manager.DefaultLocalPlayerProfile?.Enabled ?? false) || (_selector.Selected?.Enabled ?? false); + using (ImRaii.Disabled(isDefaultLPOrCurrentProfilesEnabled)) + { + if (ImGui.Checkbox("##DefaultLocalPlayerProfile", ref isDefaultLP)) + _manager.SetDefaultLocalPlayerProfile(isDefaultLP ? _selector.Selected! : null); + ImGuiUtil.LabeledHelpMarker("Apply to any character you are logged in with", + "Whether the templates in this profile should be applied to any character you are currently logged in with.\r\nTakes priority over the next option for said character.\r\nThis setting cannot be applied to multiple profiles."); + } + if (isDefaultLPOrCurrentProfilesEnabled) + { + ImGui.SameLine(); + ImGui.PushStyleColor(ImGuiCol.Text, Constants.Colors.Warning); + ImGuiUtil.PrintIcon(FontAwesomeIcon.ExclamationTriangle); + ImGui.PopStyleColor(); + ImGuiUtil.HoverTooltip("Can only be changed when both currently selected and profile where this checkbox is checked are disabled."); + } var isDefault = _manager.DefaultProfile == _selector.Selected; var isDefaultOrCurrentProfilesEnabled = (_manager.DefaultProfile?.Enabled ?? false) || (_selector.Selected?.Enabled ?? false); @@ -277,7 +289,7 @@ public class ProfilePanel if (ImGui.Checkbox("##DefaultProfile", ref isDefault)) _manager.SetDefaultProfile(isDefault ? _selector.Selected! : null); ImGuiUtil.LabeledHelpMarker("Apply to all players and retainers", - "Whether the templates in this profile are applied to all players and retainers without a specific profile. This setting cannot be applied to multiple profiles."); + "Whether the templates in this profile are applied to all players and retainers without a specific profile.\r\nThis setting cannot be applied to multiple profiles."); } if (isDefaultOrCurrentProfilesEnabled) {