Make this option work when applying automation.

This commit is contained in:
Ottermandias 2024-05-05 15:40:04 +02:00
parent 2713e6f1f6
commit 6efd89e0ab
7 changed files with 35 additions and 32 deletions

View file

@ -293,8 +293,8 @@ public sealed class StateApi : IGlamourerApiState, IApiService, IDisposable
private void RevertToAutomation(Actor actor, ActorState state, uint key, ApplyFlag flags) private void RevertToAutomation(Actor actor, ActorState state, uint key, ApplyFlag flags)
{ {
var source = (flags & ApplyFlag.Once) != 0 ? StateSource.IpcManual : StateSource.IpcFixed; var source = (flags & ApplyFlag.Once) != 0 ? StateSource.IpcManual : StateSource.IpcFixed;
_autoDesigns.ReapplyAutomation(actor, state.Identifier, state, true); _autoDesigns.ReapplyAutomation(actor, state.Identifier, state, true, out var forcedRedraw);
_stateManager.ReapplyState(actor, state, source); _stateManager.ReapplyState(actor, state, forcedRedraw, source);
ApiHelpers.Lock(state, key, flags); ApiHelpers.Lock(state, key, flags);
} }

View file

@ -152,9 +152,9 @@ public sealed class AutoDesignApplier : IDisposable
{ {
if (_state.GetOrCreate(id, data.Objects[0], out var state)) 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) 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)) 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); var specificId = actor.GetIdentifier(_actors);
if (_state.GetOrCreate(specificId, actor, out var state)) if (_state.GetOrCreate(specificId, actor, out var state))
{ {
Reduce(actor, state, newSet, _config.RespectManualOnAutomationUpdate, false); Reduce(actor, state, newSet, _config.RespectManualOnAutomationUpdate, false, out var forcedRedraw);
_state.ReapplyState(actor, StateSource.Fixed); _state.ReapplyState(actor, forcedRedraw, StateSource.Fixed);
} }
} }
} }
@ -212,12 +212,13 @@ public sealed class AutoDesignApplier : IDisposable
var respectManual = state.LastJob == newJob.Id; var respectManual = state.LastJob == newJob.Id;
state.LastJob = actor.Job; state.LastJob = actor.Job;
Reduce(actor, state, set, respectManual, true); Reduce(actor, state, set, respectManual, true, out var forcedRedraw);
_state.ReapplyState(actor, StateSource.Fixed); _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) if (!_config.EnableAutoDesigns)
return; return;
@ -226,7 +227,7 @@ public sealed class AutoDesignApplier : IDisposable
if (reset) if (reset)
_state.ResetState(state, StateSource.Game); _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) 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; var respectManual = !state.UpdateTerritory(_clientState.TerritoryType) || !_config.RevertManualChangesOnZoneChange;
if (!respectManual) if (!respectManual)
_state.ResetState(state, StateSource.Game); _state.ResetState(state, StateSource.Game);
Reduce(actor, state, set, respectManual, false); Reduce(actor, state, set, respectManual, false, out _);
return true; 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) 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)) if (!_humans.IsHuman((uint)actor.AsCharacter->CharacterData.ModelCharaId))
return; 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))), 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.ModelData.Customize, state.BaseData, true, _config.AlwaysApplyAssociatedMods);
_state.ApplyDesign(state, mergedDesign, new ApplySettings(0, StateSource.Fixed, respectManual, fromJobChange, false, false, false)); _state.ApplyDesign(state, mergedDesign, new ApplySettings(0, StateSource.Fixed, respectManual, fromJobChange, false, false, false));
forcedRedraw = mergedDesign.ForcedRedraw;
} }
/// <summary> Get world-specific first and all-world afterward. </summary> /// <summary> Get world-specific first and all-world afterward. </summary>
@ -323,10 +326,10 @@ public sealed class AutoDesignApplier : IDisposable
var respectManual = prior == id; var respectManual = prior == id;
NewGearsetId = 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; NewGearsetId = -1;
foreach (var actor in data.Objects) foreach (var actor in data.Objects)
_state.ReapplyState(actor, StateSource.Fixed); _state.ReapplyState(actor, forcedRedraw, StateSource.Fixed);
} }
public static unsafe bool CheckGearset(short check) public static unsafe bool CheckGearset(short check)

View file

@ -251,8 +251,8 @@ public sealed class DesignQuickBar : Window, IDisposable
foreach (var actor in data.Objects) foreach (var actor in data.Objects)
{ {
_autoDesignApplier.ReapplyAutomation(actor, id, state!, true); _autoDesignApplier.ReapplyAutomation(actor, id, state!, true, out var forcedRedraw);
_stateManager.ReapplyState(actor, StateSource.Manual); _stateManager.ReapplyState(actor, forcedRedraw, StateSource.Manual);
} }
} }
@ -291,8 +291,8 @@ public sealed class DesignQuickBar : Window, IDisposable
foreach (var actor in data.Objects) foreach (var actor in data.Objects)
{ {
_autoDesignApplier.ReapplyAutomation(actor, id, state!, false); _autoDesignApplier.ReapplyAutomation(actor, id, state!, false, out var forcedRedraw);
_stateManager.ReapplyState(actor, StateSource.Manual); _stateManager.ReapplyState(actor, forcedRedraw, StateSource.Manual);
} }
} }

View file

@ -341,8 +341,8 @@ public class ActorPanel
"Reapply the current automation state for the character on top of its current state..", "Reapply the current automation state for the character on top of its current state..",
!_config.EnableAutoDesigns || _state!.IsLocked)) !_config.EnableAutoDesigns || _state!.IsLocked))
{ {
_autoDesignApplier.ReapplyAutomation(_actor, _identifier, _state!, false); _autoDesignApplier.ReapplyAutomation(_actor, _identifier, _state!, false, out var forcedRedraw);
_stateManager.ReapplyState(_actor, StateSource.Manual); _stateManager.ReapplyState(_actor, forcedRedraw, StateSource.Manual);
} }
ImGui.SameLine(); ImGui.SameLine();
@ -350,15 +350,15 @@ public class ActorPanel
"Try to revert the character to the state it would have using automated designs.", "Try to revert the character to the state it would have using automated designs.",
!_config.EnableAutoDesigns || _state!.IsLocked)) !_config.EnableAutoDesigns || _state!.IsLocked))
{ {
_autoDesignApplier.ReapplyAutomation(_actor, _identifier, _state!, true); _autoDesignApplier.ReapplyAutomation(_actor, _identifier, _state!, true, out var forcedRedraw);
_stateManager.ReapplyState(_actor, StateSource.Manual); _stateManager.ReapplyState(_actor, forcedRedraw, StateSource.Manual);
} }
ImGui.SameLine(); ImGui.SameLine();
if (ImGuiUtil.DrawDisabledButton("Reapply", Vector2.Zero, if (ImGuiUtil.DrawDisabledButton("Reapply", Vector2.Zero,
"Try to reapply the configured state if something went wrong. Should generally not be necessary.", "Try to reapply the configured state if something went wrong. Should generally not be necessary.",
_state!.IsLocked)) _state!.IsLocked))
_stateManager.ReapplyState(_actor, StateSource.Manual); _stateManager.ReapplyState(_actor, false, StateSource.Manual);
} }
private void DrawApplyToSelf() private void DrawApplyToSelf()

View file

@ -86,7 +86,7 @@ public class PenumbraAutoRedraw : IDisposable, IRequiredService
_actions.Enqueue((state, () => _actions.Enqueue((state, () =>
{ {
foreach (var actor in actors.Objects) 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)}."); Glamourer.Log.Debug($"Automatically applied mod settings of type {type} to {id.Incognito(null)}.");
}, WaitFrames)); }, WaitFrames));
} }
@ -106,7 +106,7 @@ public class PenumbraAutoRedraw : IDisposable, IRequiredService
_frame = currentFrame; _frame = currentFrame;
_framework.RunOnFrameworkThread(() => _framework.RunOnFrameworkThread(() =>
{ {
_state.ReapplyState(_objects.Player, StateSource.IpcManual); _state.ReapplyState(_objects.Player, false, StateSource.IpcManual);
Glamourer.Log.Debug( Glamourer.Log.Debug(
$"Automatically applied mod settings of type {type} to {_objects.PlayerData.Identifier.Incognito(null)} (Local Player)."); $"Automatically applied mod settings of type {type} to {_objects.PlayerData.Identifier.Incognito(null)} (Local Player).");
}); });

View file

@ -329,8 +329,8 @@ public class CommandService : IDisposable, IApiService
{ {
if (_stateManager.GetOrCreate(identifier, actor, out var state)) if (_stateManager.GetOrCreate(identifier, actor, out var state))
{ {
_autoDesignApplier.ReapplyAutomation(actor, identifier, state, revert); _autoDesignApplier.ReapplyAutomation(actor, identifier, state, revert, out var forcedRedraw);
_stateManager.ReapplyState(actor, StateSource.Manual); _stateManager.ReapplyState(actor, forcedRedraw, StateSource.Manual);
} }
} }
} }
@ -379,7 +379,7 @@ public class CommandService : IDisposable, IApiService
return true; return true;
foreach (var actor in data.Objects) foreach (var actor in data.Objects)
_stateManager.ReapplyState(actor, StateSource.Manual); _stateManager.ReapplyState(actor, false, StateSource.Manual);
} }

View file

@ -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)) if (!GetOrCreate(actor, out var state))
return; 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, 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); StateChanged.Invoke(StateChanged.Type.Reapply, source, state, data, null);
} }