From 22a8ba3f35b16d67244b26bdd7ab6cca941b3a92 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Sun, 18 Feb 2024 13:05:04 +0100 Subject: [PATCH] Make a reapply event. --- Glamourer/Api/GlamourerIpc.Revert.cs | 2 +- Glamourer/Automation/AutoDesignApplier.cs | 8 ++++---- Glamourer/Events/StateChanged.cs | 3 +++ Glamourer/Gui/DesignQuickBar.cs | 2 +- Glamourer/Gui/Tabs/ActorTab/ActorPanel.cs | 4 ++-- Glamourer/Interop/CharaFile/CmaFile.cs | 5 +++-- Glamourer/Services/CommandService.cs | 4 ++-- Glamourer/State/StateApplier.cs | 2 ++ Glamourer/State/StateManager.cs | 8 ++++---- 9 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Glamourer/Api/GlamourerIpc.Revert.cs b/Glamourer/Api/GlamourerIpc.Revert.cs index c5ca3b3..c5e1005 100644 --- a/Glamourer/Api/GlamourerIpc.Revert.cs +++ b/Glamourer/Api/GlamourerIpc.Revert.cs @@ -110,7 +110,7 @@ public partial class GlamourerIpc foreach (var obj in data.Objects) { _autoDesignApplier.ReapplyAutomation(obj, state.Identifier, state); - _stateManager.ReapplyState(obj); + _stateManager.ReapplyState(obj, StateSource.IpcManual); } } } diff --git a/Glamourer/Automation/AutoDesignApplier.cs b/Glamourer/Automation/AutoDesignApplier.cs index adbd355..380de33 100644 --- a/Glamourer/Automation/AutoDesignApplier.cs +++ b/Glamourer/Automation/AutoDesignApplier.cs @@ -151,7 +151,7 @@ public sealed class AutoDesignApplier : IDisposable { Reduce(data.Objects[0], state, newSet, false, false); foreach (var actor in data.Objects) - _state.ReapplyState(actor); + _state.ReapplyState(actor, StateSource.Fixed); } } else if (_objects.TryGetValueAllWorld(id, out data) || _objects.TryGetValueNonOwned(id, out data)) @@ -162,7 +162,7 @@ public sealed class AutoDesignApplier : IDisposable if (_state.GetOrCreate(specificId, actor, out var state)) { Reduce(actor, state, newSet, false, false); - _state.ReapplyState(actor); + _state.ReapplyState(actor, StateSource.Fixed); } } } @@ -210,7 +210,7 @@ public sealed class AutoDesignApplier : IDisposable var respectManual = state.LastJob == newJob.Id; state.LastJob = actor.Job; Reduce(actor, state, set, respectManual, true); - _state.ReapplyState(actor); + _state.ReapplyState(actor, StateSource.Fixed); } public void ReapplyAutomation(Actor actor, ActorIdentifier identifier, ActorState state) @@ -310,7 +310,7 @@ public sealed class AutoDesignApplier : IDisposable Reduce(data.Objects[0], state, set, respectManual, job != state.LastJob); NewGearsetId = -1; foreach (var actor in data.Objects) - _state.ReapplyState(actor); + _state.ReapplyState(actor, StateSource.Fixed); } public static unsafe bool CheckGearset(short check) diff --git a/Glamourer/Events/StateChanged.cs b/Glamourer/Events/StateChanged.cs index ad2ab7b..0cffc35 100644 --- a/Glamourer/Events/StateChanged.cs +++ b/Glamourer/Events/StateChanged.cs @@ -53,6 +53,9 @@ namespace Glamourer.Events /// A characters saved state had a meta toggle changed. Data is the old stain id, the new stain id and the slot [(StainId, StainId, EquipSlot)]. Other, + + /// A characters state was reapplied. Data is null. + Reapply, } public enum Priority diff --git a/Glamourer/Gui/DesignQuickBar.cs b/Glamourer/Gui/DesignQuickBar.cs index 2521765..58bdb24 100644 --- a/Glamourer/Gui/DesignQuickBar.cs +++ b/Glamourer/Gui/DesignQuickBar.cs @@ -225,7 +225,7 @@ public sealed class DesignQuickBar : Window, IDisposable foreach (var actor in data.Objects) { _autoDesignApplier.ReapplyAutomation(actor, id, state!); - _stateManager.ReapplyState(actor); + _stateManager.ReapplyState(actor, StateSource.Manual); } } diff --git a/Glamourer/Gui/Tabs/ActorTab/ActorPanel.cs b/Glamourer/Gui/Tabs/ActorTab/ActorPanel.cs index dc97acb..b205127 100644 --- a/Glamourer/Gui/Tabs/ActorTab/ActorPanel.cs +++ b/Glamourer/Gui/Tabs/ActorTab/ActorPanel.cs @@ -373,7 +373,7 @@ public class ActorPanel( ImGui.SameLine(); if (ImGuiUtil.DrawDisabledButton("Reapply State", Vector2.Zero, "Try to reapply the configured state if something went wrong.", _state!.IsLocked)) - _stateManager.ReapplyState(_actor); + _stateManager.ReapplyState(_actor, StateSource.Manual); ImGui.SameLine(); if (ImGuiUtil.DrawDisabledButton("Reapply Automation", Vector2.Zero, @@ -381,7 +381,7 @@ public class ActorPanel( !_config.EnableAutoDesigns || _state!.IsLocked)) { _autoDesignApplier.ReapplyAutomation(_actor, _identifier, _state!); - _stateManager.ReapplyState(_actor); + _stateManager.ReapplyState(_actor, StateSource.Manual); } } diff --git a/Glamourer/Interop/CharaFile/CmaFile.cs b/Glamourer/Interop/CharaFile/CmaFile.cs index bf67a59..dab91ac 100644 --- a/Glamourer/Interop/CharaFile/CmaFile.cs +++ b/Glamourer/Interop/CharaFile/CmaFile.cs @@ -1,4 +1,4 @@ -using Glamourer.Designs; +using Glamourer.Designs; using Glamourer.Services; using Newtonsoft.Json.Linq; using Penumbra.GameData.Enums; @@ -54,9 +54,10 @@ public sealed class CmaFile { foreach (var slot in EquipSlotExtensions.EqdpSlots) { - var idx = slot.ToIndex(); + var idx = slot.ToIndex(); if (idx * 4 + 3 >= byteData.Length) continue; + var armor = ((CharacterArmor*)ptr)[idx]; var item = items.Identify(slot, armor.Set, armor.Variant); data.SetItem(slot, item); diff --git a/Glamourer/Services/CommandService.cs b/Glamourer/Services/CommandService.cs index 74364e2..3ca1e76 100644 --- a/Glamourer/Services/CommandService.cs +++ b/Glamourer/Services/CommandService.cs @@ -308,7 +308,7 @@ public class CommandService : IDisposable if (_stateManager.GetOrCreate(identifier, actor, out var state)) { _autoDesignApplier.ReapplyAutomation(actor, identifier, state); - _stateManager.ReapplyState(actor); + _stateManager.ReapplyState(actor, StateSource.Manual); } } } @@ -357,7 +357,7 @@ public class CommandService : IDisposable return true; foreach (var actor in data.Objects) - _stateManager.ReapplyState(actor); + _stateManager.ReapplyState(actor, StateSource.Manual); } diff --git a/Glamourer/State/StateApplier.cs b/Glamourer/State/StateApplier.cs index 1b9c69a..a025cb5 100644 --- a/Glamourer/State/StateApplier.cs +++ b/Glamourer/State/StateApplier.cs @@ -341,6 +341,8 @@ public class StateApplier( ChangeMetaState(actors, MetaIndex.VisorState, state.ModelData.IsVisorToggled()); ChangeCrests(actors, state.ModelData.CrestVisibility); ChangeParameters(actors, state.OnlyChangedParameters(), state.ModelData.Parameters, state.IsLocked); + foreach (var material in state.Materials.Values) + ChangeMaterialValue(actors, MaterialValueIndex.FromKey(material.Key), material.Value.Model, state.IsLocked); } return actors; diff --git a/Glamourer/State/StateManager.cs b/Glamourer/State/StateManager.cs index d731a66..b58bab9 100644 --- a/Glamourer/State/StateManager.cs +++ b/Glamourer/State/StateManager.cs @@ -334,14 +334,14 @@ public sealed class StateManager( } } - public void ReapplyState(Actor actor) + public void ReapplyState(Actor actor, StateSource source) { if (!GetOrCreate(actor, out var state)) return; - Applier.ApplyAll(state, - !actor.Model.IsHuman || CustomizeArray.Compare(actor.Model.GetCustomize(), state.ModelData.Customize).RequiresRedraw(), - false); + var data = Applier.ApplyAll(state, + !actor.Model.IsHuman || CustomizeArray.Compare(actor.Model.GetCustomize(), state.ModelData.Customize).RequiresRedraw(), false); + StateChanged.Invoke(StateChanged.Type.Reapply, source, state, data, null); } public void DeleteState(ActorIdentifier identifier)