From 6efd89e0abab2205d8bb1039bbb5adaa92a95af4 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Sun, 5 May 2024 15:40:04 +0200 Subject: [PATCH] Make this option work when applying automation. --- Glamourer/Api/StateApi.cs | 4 +-- Glamourer/Automation/AutoDesignApplier.cs | 27 ++++++++++--------- Glamourer/Gui/DesignQuickBar.cs | 8 +++--- Glamourer/Gui/Tabs/ActorTab/ActorPanel.cs | 10 +++---- .../Interop/Penumbra/PenumbraAutoRedraw.cs | 4 +-- Glamourer/Services/CommandService.cs | 6 ++--- Glamourer/State/StateManager.cs | 8 +++--- 7 files changed, 35 insertions(+), 32 deletions(-) diff --git a/Glamourer/Api/StateApi.cs b/Glamourer/Api/StateApi.cs index 3e2fde4..344fc5c 100644 --- a/Glamourer/Api/StateApi.cs +++ b/Glamourer/Api/StateApi.cs @@ -293,8 +293,8 @@ public sealed class StateApi : IGlamourerApiState, IApiService, IDisposable private void RevertToAutomation(Actor actor, ActorState state, uint key, ApplyFlag flags) { var source = (flags & ApplyFlag.Once) != 0 ? StateSource.IpcManual : StateSource.IpcFixed; - _autoDesigns.ReapplyAutomation(actor, state.Identifier, state, true); - _stateManager.ReapplyState(actor, state, source); + _autoDesigns.ReapplyAutomation(actor, state.Identifier, state, true, out var forcedRedraw); + _stateManager.ReapplyState(actor, state, forcedRedraw, source); ApiHelpers.Lock(state, key, flags); } diff --git a/Glamourer/Automation/AutoDesignApplier.cs b/Glamourer/Automation/AutoDesignApplier.cs index c739a75..f2ac1b3 100644 --- a/Glamourer/Automation/AutoDesignApplier.cs +++ b/Glamourer/Automation/AutoDesignApplier.cs @@ -152,9 +152,9 @@ public sealed class AutoDesignApplier : IDisposable { if (_state.GetOrCreate(id, data.Objects[0], out var state)) { - Reduce(data.Objects[0], state, newSet, _config.RespectManualOnAutomationUpdate, false); + Reduce(data.Objects[0], state, newSet, _config.RespectManualOnAutomationUpdate, false, out var forcedRedraw); foreach (var actor in data.Objects) - _state.ReapplyState(actor, StateSource.Fixed); + _state.ReapplyState(actor, forcedRedraw,StateSource.Fixed); } } else if (_objects.TryGetValueAllWorld(id, out data) || _objects.TryGetValueNonOwned(id, out data)) @@ -164,8 +164,8 @@ public sealed class AutoDesignApplier : IDisposable var specificId = actor.GetIdentifier(_actors); if (_state.GetOrCreate(specificId, actor, out var state)) { - Reduce(actor, state, newSet, _config.RespectManualOnAutomationUpdate, false); - _state.ReapplyState(actor, StateSource.Fixed); + Reduce(actor, state, newSet, _config.RespectManualOnAutomationUpdate, false, out var forcedRedraw); + _state.ReapplyState(actor, forcedRedraw, StateSource.Fixed); } } } @@ -212,12 +212,13 @@ public sealed class AutoDesignApplier : IDisposable var respectManual = state.LastJob == newJob.Id; state.LastJob = actor.Job; - Reduce(actor, state, set, respectManual, true); - _state.ReapplyState(actor, StateSource.Fixed); + Reduce(actor, state, set, respectManual, true, out var forcedRedraw); + _state.ReapplyState(actor, forcedRedraw, StateSource.Fixed); } - public void ReapplyAutomation(Actor actor, ActorIdentifier identifier, ActorState state, bool reset) + public void ReapplyAutomation(Actor actor, ActorIdentifier identifier, ActorState state, bool reset, out bool forcedRedraw) { + forcedRedraw = false; if (!_config.EnableAutoDesigns) return; @@ -226,7 +227,7 @@ public sealed class AutoDesignApplier : IDisposable if (reset) _state.ResetState(state, StateSource.Game); - Reduce(actor, state, set, false, false); + Reduce(actor, state, set, false, false, out forcedRedraw); } public bool Reduce(Actor actor, ActorIdentifier identifier, [NotNullWhen(true)] out ActorState? state) @@ -253,11 +254,11 @@ public sealed class AutoDesignApplier : IDisposable var respectManual = !state.UpdateTerritory(_clientState.TerritoryType) || !_config.RevertManualChangesOnZoneChange; if (!respectManual) _state.ResetState(state, StateSource.Game); - Reduce(actor, state, set, respectManual, false); + Reduce(actor, state, set, respectManual, false, out _); return true; } - private unsafe void Reduce(Actor actor, ActorState state, AutoDesignSet set, bool respectManual, bool fromJobChange) + private unsafe void Reduce(Actor actor, ActorState state, AutoDesignSet set, bool respectManual, bool fromJobChange, out bool forcedRedraw) { if (set.BaseState is AutoDesignSet.Base.Game) { @@ -275,6 +276,7 @@ public sealed class AutoDesignApplier : IDisposable } } + forcedRedraw = false; if (!_humans.IsHuman((uint)actor.AsCharacter->CharacterData.ModelCharaId)) return; @@ -282,6 +284,7 @@ public sealed class AutoDesignApplier : IDisposable set.Designs.Where(d => d.IsActive(actor)).SelectMany(d => d.Design.AllLinks.Select(l => (l.Design, l.Flags & d.Type, d.Jobs.Flags))), state.ModelData.Customize, state.BaseData, true, _config.AlwaysApplyAssociatedMods); _state.ApplyDesign(state, mergedDesign, new ApplySettings(0, StateSource.Fixed, respectManual, fromJobChange, false, false, false)); + forcedRedraw = mergedDesign.ForcedRedraw; } /// Get world-specific first and all-world afterward. @@ -323,10 +326,10 @@ public sealed class AutoDesignApplier : IDisposable var respectManual = prior == id; NewGearsetId = id; - Reduce(data.Objects[0], state, set, respectManual, job != state.LastJob); + Reduce(data.Objects[0], state, set, respectManual, job != state.LastJob, out var forcedRedraw); NewGearsetId = -1; foreach (var actor in data.Objects) - _state.ReapplyState(actor, StateSource.Fixed); + _state.ReapplyState(actor, forcedRedraw, StateSource.Fixed); } public static unsafe bool CheckGearset(short check) diff --git a/Glamourer/Gui/DesignQuickBar.cs b/Glamourer/Gui/DesignQuickBar.cs index 50e976f..d81b1ae 100644 --- a/Glamourer/Gui/DesignQuickBar.cs +++ b/Glamourer/Gui/DesignQuickBar.cs @@ -251,8 +251,8 @@ public sealed class DesignQuickBar : Window, IDisposable foreach (var actor in data.Objects) { - _autoDesignApplier.ReapplyAutomation(actor, id, state!, true); - _stateManager.ReapplyState(actor, StateSource.Manual); + _autoDesignApplier.ReapplyAutomation(actor, id, state!, true, out var forcedRedraw); + _stateManager.ReapplyState(actor, forcedRedraw, StateSource.Manual); } } @@ -291,8 +291,8 @@ public sealed class DesignQuickBar : Window, IDisposable foreach (var actor in data.Objects) { - _autoDesignApplier.ReapplyAutomation(actor, id, state!, false); - _stateManager.ReapplyState(actor, StateSource.Manual); + _autoDesignApplier.ReapplyAutomation(actor, id, state!, false, out var forcedRedraw); + _stateManager.ReapplyState(actor, forcedRedraw, StateSource.Manual); } } diff --git a/Glamourer/Gui/Tabs/ActorTab/ActorPanel.cs b/Glamourer/Gui/Tabs/ActorTab/ActorPanel.cs index b8ecd53..5a05058 100644 --- a/Glamourer/Gui/Tabs/ActorTab/ActorPanel.cs +++ b/Glamourer/Gui/Tabs/ActorTab/ActorPanel.cs @@ -341,8 +341,8 @@ public class ActorPanel "Reapply the current automation state for the character on top of its current state..", !_config.EnableAutoDesigns || _state!.IsLocked)) { - _autoDesignApplier.ReapplyAutomation(_actor, _identifier, _state!, false); - _stateManager.ReapplyState(_actor, StateSource.Manual); + _autoDesignApplier.ReapplyAutomation(_actor, _identifier, _state!, false, out var forcedRedraw); + _stateManager.ReapplyState(_actor, forcedRedraw, StateSource.Manual); } ImGui.SameLine(); @@ -350,15 +350,15 @@ public class ActorPanel "Try to revert the character to the state it would have using automated designs.", !_config.EnableAutoDesigns || _state!.IsLocked)) { - _autoDesignApplier.ReapplyAutomation(_actor, _identifier, _state!, true); - _stateManager.ReapplyState(_actor, StateSource.Manual); + _autoDesignApplier.ReapplyAutomation(_actor, _identifier, _state!, true, out var forcedRedraw); + _stateManager.ReapplyState(_actor, forcedRedraw, StateSource.Manual); } ImGui.SameLine(); if (ImGuiUtil.DrawDisabledButton("Reapply", Vector2.Zero, "Try to reapply the configured state if something went wrong. Should generally not be necessary.", _state!.IsLocked)) - _stateManager.ReapplyState(_actor, StateSource.Manual); + _stateManager.ReapplyState(_actor, false, StateSource.Manual); } private void DrawApplyToSelf() diff --git a/Glamourer/Interop/Penumbra/PenumbraAutoRedraw.cs b/Glamourer/Interop/Penumbra/PenumbraAutoRedraw.cs index 11f7fd9..9359bea 100644 --- a/Glamourer/Interop/Penumbra/PenumbraAutoRedraw.cs +++ b/Glamourer/Interop/Penumbra/PenumbraAutoRedraw.cs @@ -86,7 +86,7 @@ public class PenumbraAutoRedraw : IDisposable, IRequiredService _actions.Enqueue((state, () => { foreach (var actor in actors.Objects) - _state.ReapplyState(actor, state, StateSource.IpcManual); + _state.ReapplyState(actor, state, false, StateSource.IpcManual); Glamourer.Log.Debug($"Automatically applied mod settings of type {type} to {id.Incognito(null)}."); }, WaitFrames)); } @@ -106,7 +106,7 @@ public class PenumbraAutoRedraw : IDisposable, IRequiredService _frame = currentFrame; _framework.RunOnFrameworkThread(() => { - _state.ReapplyState(_objects.Player, StateSource.IpcManual); + _state.ReapplyState(_objects.Player, false, StateSource.IpcManual); Glamourer.Log.Debug( $"Automatically applied mod settings of type {type} to {_objects.PlayerData.Identifier.Incognito(null)} (Local Player)."); }); diff --git a/Glamourer/Services/CommandService.cs b/Glamourer/Services/CommandService.cs index 47ffa00..b18c817 100644 --- a/Glamourer/Services/CommandService.cs +++ b/Glamourer/Services/CommandService.cs @@ -329,8 +329,8 @@ public class CommandService : IDisposable, IApiService { if (_stateManager.GetOrCreate(identifier, actor, out var state)) { - _autoDesignApplier.ReapplyAutomation(actor, identifier, state, revert); - _stateManager.ReapplyState(actor, StateSource.Manual); + _autoDesignApplier.ReapplyAutomation(actor, identifier, state, revert, out var forcedRedraw); + _stateManager.ReapplyState(actor, forcedRedraw, StateSource.Manual); } } } @@ -379,7 +379,7 @@ public class CommandService : IDisposable, IApiService return true; foreach (var actor in data.Objects) - _stateManager.ReapplyState(actor, StateSource.Manual); + _stateManager.ReapplyState(actor, false, StateSource.Manual); } diff --git a/Glamourer/State/StateManager.cs b/Glamourer/State/StateManager.cs index 7fe2264..77e8797 100644 --- a/Glamourer/State/StateManager.cs +++ b/Glamourer/State/StateManager.cs @@ -402,18 +402,18 @@ public sealed class StateManager( } } - public void ReapplyState(Actor actor, StateSource source) + public void ReapplyState(Actor actor, bool forceRedraw, StateSource source) { if (!GetOrCreate(actor, out var state)) return; - ReapplyState(actor, state, source); + ReapplyState(actor, state, forceRedraw, source); } - public void ReapplyState(Actor actor, ActorState state, StateSource source) + public void ReapplyState(Actor actor, ActorState state, bool forceRedraw, StateSource source) { var data = Applier.ApplyAll(state, - !actor.Model.IsHuman || CustomizeArray.Compare(actor.Model.GetCustomize(), state.ModelData.Customize).RequiresRedraw(), false); + forceRedraw || !actor.Model.IsHuman || CustomizeArray.Compare(actor.Model.GetCustomize(), state.ModelData.Customize).RequiresRedraw(), false); StateChanged.Invoke(StateChanged.Type.Reapply, source, state, data, null); }