Rewrite ApplyToCurrentlyActiveCharacter so it behaves like DefaultProfile
This commit is contained in:
@@ -413,10 +413,10 @@ public unsafe sealed class ArmatureManager : IDisposable
|
|||||||
type is not ProfileChanged.Type.TemporaryProfileDeleted &&
|
type is not ProfileChanged.Type.TemporaryProfileDeleted &&
|
||||||
type is not ProfileChanged.Type.ChangedCharacter &&
|
type is not ProfileChanged.Type.ChangedCharacter &&
|
||||||
type is not ProfileChanged.Type.ChangedDefaultProfile &&
|
type is not ProfileChanged.Type.ChangedDefaultProfile &&
|
||||||
type is not ProfileChanged.Type.ApplyToCurrentlyActiveCharacterChanged)
|
type is not ProfileChanged.Type.ChangedDefaultLocalPlayerProfile)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (type == ProfileChanged.Type.ChangedDefaultProfile)
|
if (type == ProfileChanged.Type.ChangedDefaultProfile || type == ProfileChanged.Type.ChangedDefaultLocalPlayerProfile)
|
||||||
{
|
{
|
||||||
var oldProfile = (Profile?)arg3;
|
var oldProfile = (Profile?)arg3;
|
||||||
|
|
||||||
@@ -426,7 +426,7 @@ public unsafe sealed class ArmatureManager : IDisposable
|
|||||||
foreach (var armature in oldProfile.Armatures)
|
foreach (var armature in oldProfile.Armatures)
|
||||||
armature.IsPendingProfileRebind = true;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
@@ -505,8 +505,7 @@ public unsafe sealed class ArmatureManager : IDisposable
|
|||||||
|
|
||||||
if (type == ProfileChanged.Type.ChangedCharacter ||
|
if (type == ProfileChanged.Type.ChangedCharacter ||
|
||||||
type == ProfileChanged.Type.Deleted ||
|
type == ProfileChanged.Type.Deleted ||
|
||||||
type == ProfileChanged.Type.TemporaryProfileDeleted ||
|
type == ProfileChanged.Type.TemporaryProfileDeleted)
|
||||||
type == ProfileChanged.Type.ApplyToCurrentlyActiveCharacterChanged)
|
|
||||||
{
|
{
|
||||||
if (profile.Armatures.Count == 0)
|
if (profile.Armatures.Count == 0)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ public sealed class Profile : ISavable
|
|||||||
public LowerString CharacterName { get; set; } = LowerString.Empty;
|
public LowerString CharacterName { get; set; } = LowerString.Empty;
|
||||||
|
|
||||||
public ActorIdentifier Character { get; set; } = ActorIdentifier.Invalid;
|
public ActorIdentifier Character { get; set; } = ActorIdentifier.Invalid;
|
||||||
public bool ApplyToCurrentlyActiveCharacter { get; set; }
|
|
||||||
|
|
||||||
public LowerString Name { get; set; } = LowerString.Empty;
|
public LowerString Name { get; set; } = LowerString.Empty;
|
||||||
|
|
||||||
@@ -80,7 +79,6 @@ public sealed class Profile : ISavable
|
|||||||
public Profile(Profile original) : this()
|
public Profile(Profile original) : this()
|
||||||
{
|
{
|
||||||
Character = original.Character;
|
Character = original.Character;
|
||||||
ApplyToCurrentlyActiveCharacter = original.ApplyToCurrentlyActiveCharacter;
|
|
||||||
|
|
||||||
foreach (var template in original.Templates)
|
foreach (var template in original.Templates)
|
||||||
{
|
{
|
||||||
@@ -105,7 +103,6 @@ public sealed class Profile : ISavable
|
|||||||
["ModifiedDate"] = ModifiedDate,
|
["ModifiedDate"] = ModifiedDate,
|
||||||
["CharacterName"] = CharacterName.Text,
|
["CharacterName"] = CharacterName.Text,
|
||||||
["Character"] = Character.ToJson(),
|
["Character"] = Character.ToJson(),
|
||||||
["ApplyToCurrentlyActiveCharacter"] = ApplyToCurrentlyActiveCharacter,
|
|
||||||
["Name"] = Name.Text,
|
["Name"] = Name.Text,
|
||||||
["Enabled"] = Enabled,
|
["Enabled"] = Enabled,
|
||||||
["IsWriteProtected"] = IsWriteProtected,
|
["IsWriteProtected"] = IsWriteProtected,
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ public sealed class ProfileChanged() : EventWrapper<ProfileChanged.Type, Profile
|
|||||||
ChangedTemplate,
|
ChangedTemplate,
|
||||||
ReloadedAll,
|
ReloadedAll,
|
||||||
WriteProtection,
|
WriteProtection,
|
||||||
ApplyToCurrentlyActiveCharacterChanged,
|
|
||||||
ChangedDefaultProfile,
|
ChangedDefaultProfile,
|
||||||
|
ChangedDefaultLocalPlayerProfile,
|
||||||
TemporaryProfileAdded,
|
TemporaryProfileAdded,
|
||||||
TemporaryProfileDeleted,
|
TemporaryProfileDeleted,
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -103,7 +103,6 @@ public partial class ProfileManager : IDisposable
|
|||||||
var character = _actorManager.FromJson(obj["Character"] as JObject);
|
var character = _actorManager.FromJson(obj["Character"] as JObject);
|
||||||
|
|
||||||
profile.Character = character;
|
profile.Character = character;
|
||||||
profile.ApplyToCurrentlyActiveCharacter = obj["ApplyToCurrentlyActiveCharacter"]?.ToObject<bool>() ?? false;
|
|
||||||
profile.CharacterName = new LowerString(obj["CharacterName"]?.ToObject<string>()?.Trim() ?? throw new ArgumentNullException("CharacterName")); //temp
|
profile.CharacterName = new LowerString(obj["CharacterName"]?.ToObject<string>()?.Trim() ?? throw new ArgumentNullException("CharacterName")); //temp
|
||||||
|
|
||||||
return profile;
|
return profile;
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ public partial class ProfileManager : IDisposable
|
|||||||
public readonly List<Profile> Profiles = new();
|
public readonly List<Profile> Profiles = new();
|
||||||
|
|
||||||
public Profile? DefaultProfile { get; private set; }
|
public Profile? DefaultProfile { get; private set; }
|
||||||
|
public Profile? DefaultLocalPlayerProfile { get; private set; }
|
||||||
|
|
||||||
public ProfileManager(
|
public ProfileManager(
|
||||||
TemplateManager templateManager,
|
TemplateManager templateManager,
|
||||||
@@ -255,19 +256,6 @@ public partial class ProfileManager : IDisposable
|
|||||||
throw new ProfileNotFoundException();
|
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)
|
public void DeleteTemplate(Profile profile, int templateIndex)
|
||||||
{
|
{
|
||||||
_logger.Debug($"Deleting template #{templateIndex} from {profile}...");
|
_logger.Debug($"Deleting template #{templateIndex} from {profile}...");
|
||||||
@@ -342,6 +330,26 @@ public partial class ProfileManager : IDisposable
|
|||||||
_event.Invoke(ProfileChanged.Type.ChangedDefaultProfile, profile, previousProfile);
|
_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
|
//warn: temporary profile system does not support any world identifiers
|
||||||
public void AddTemporaryProfile(Profile profile, Actor actor)
|
public void AddTemporaryProfile(Profile profile, Actor actor)
|
||||||
{
|
{
|
||||||
@@ -453,14 +461,8 @@ public partial class ProfileManager : IDisposable
|
|||||||
if (profile == DefaultProfile)
|
if (profile == DefaultProfile)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (profile.ApplyToCurrentlyActiveCharacter)
|
if (profile == DefaultLocalPlayerProfile)
|
||||||
{
|
return false;
|
||||||
if (_objectManager.IsInLobby)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
var currentPlayer = _actorManager.GetCurrentPlayer();
|
|
||||||
return currentPlayer.IsValid && currentPlayer.MatchesIgnoringOwnership(actorIdentifier);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (actorIdentifier.Type == IdentifierType.Owned && !actorIdentifier.IsOwnedByLocalPlayer())
|
if (actorIdentifier.Type == IdentifierType.Owned && !actorIdentifier.IsOwnedByLocalPlayer())
|
||||||
return false;
|
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 &&
|
if (DefaultProfile != null &&
|
||||||
DefaultProfile.Enabled &&
|
DefaultProfile.Enabled &&
|
||||||
(actorIdentifier.Type == IdentifierType.Player || actorIdentifier.Type == IdentifierType.Retainer))
|
(actorIdentifier.Type == IdentifierType.Player || actorIdentifier.Type == IdentifierType.Retainer))
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ public class ProfilePanel
|
|||||||
if (!_selector.IncognitoMode)
|
if (!_selector.IncognitoMode)
|
||||||
{
|
{
|
||||||
bool showMultipleMessage = false;
|
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 ?
|
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");
|
_selector.Selected?.Character.ToNameWithoutOwnerName() : _selector.Selected?.Character.ToString())}" : "No valid character selected for the profile");
|
||||||
@@ -264,11 +264,23 @@ public class ProfilePanel
|
|||||||
|
|
||||||
ImGui.Separator();
|
ImGui.Separator();
|
||||||
|
|
||||||
var anyActiveCharaBool = _selector.Selected?.ApplyToCurrentlyActiveCharacter ?? false;
|
var isDefaultLP = _manager.DefaultLocalPlayerProfile == _selector.Selected;
|
||||||
if (ImGui.Checkbox("##ApplyToCurrentlyActiveCharacter", ref anyActiveCharaBool))
|
var isDefaultLPOrCurrentProfilesEnabled = (_manager.DefaultLocalPlayerProfile?.Enabled ?? false) || (_selector.Selected?.Enabled ?? false);
|
||||||
_manager.SetApplyToCurrentlyActiveCharacter(_selector.Selected!, anyActiveCharaBool);
|
using (ImRaii.Disabled(isDefaultLPOrCurrentProfilesEnabled))
|
||||||
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.");
|
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 isDefault = _manager.DefaultProfile == _selector.Selected;
|
||||||
var isDefaultOrCurrentProfilesEnabled = (_manager.DefaultProfile?.Enabled ?? false) || (_selector.Selected?.Enabled ?? false);
|
var isDefaultOrCurrentProfilesEnabled = (_manager.DefaultProfile?.Enabled ?? false) || (_selector.Selected?.Enabled ?? false);
|
||||||
@@ -277,7 +289,7 @@ public class ProfilePanel
|
|||||||
if (ImGui.Checkbox("##DefaultProfile", ref isDefault))
|
if (ImGui.Checkbox("##DefaultProfile", ref isDefault))
|
||||||
_manager.SetDefaultProfile(isDefault ? _selector.Selected! : null);
|
_manager.SetDefaultProfile(isDefault ? _selector.Selected! : null);
|
||||||
ImGuiUtil.LabeledHelpMarker("Apply to all players and retainers",
|
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)
|
if (isDefaultOrCurrentProfilesEnabled)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user