Add an option to track territories to revert manual changes or outdated automations when changing zone.

This commit is contained in:
Ottermandias 2023-09-29 15:46:28 +02:00
parent 66596f8868
commit cfe306fc19
5 changed files with 47 additions and 15 deletions

View file

@ -1,5 +1,6 @@
using System; using System;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using Dalamud.Plugin.Services;
using Glamourer.Customization; using Glamourer.Customization;
using Glamourer.Designs; using Glamourer.Designs;
using Glamourer.Events; using Glamourer.Events;
@ -31,6 +32,7 @@ public class AutoDesignApplier : IDisposable
private readonly ObjectManager _objects; private readonly ObjectManager _objects;
private readonly WeaponLoading _weapons; private readonly WeaponLoading _weapons;
private readonly HumanModelList _humans; private readonly HumanModelList _humans;
private readonly IClientState _clientState;
private ActorState? _jobChangeState; private ActorState? _jobChangeState;
private EquipItem _jobChangeMainhand; private EquipItem _jobChangeMainhand;
@ -38,7 +40,7 @@ public class AutoDesignApplier : IDisposable
public AutoDesignApplier(Configuration config, AutoDesignManager manager, StateManager state, JobService jobs, public AutoDesignApplier(Configuration config, AutoDesignManager manager, StateManager state, JobService jobs,
CustomizationService customizations, ActorService actors, ItemUnlockManager itemUnlocks, CustomizeUnlockManager customizeUnlocks, CustomizationService customizations, ActorService actors, ItemUnlockManager itemUnlocks, CustomizeUnlockManager customizeUnlocks,
AutomationChanged @event, ObjectManager objects, WeaponLoading weapons, HumanModelList humans) AutomationChanged @event, ObjectManager objects, WeaponLoading weapons, HumanModelList humans, IClientState clientState)
{ {
_config = config; _config = config;
_manager = manager; _manager = manager;
@ -52,6 +54,7 @@ public class AutoDesignApplier : IDisposable
_objects = objects; _objects = objects;
_weapons = weapons; _weapons = weapons;
_humans = humans; _humans = humans;
_clientState = clientState;
_jobs.JobChanged += OnJobChange; _jobs.JobChanged += OnJobChange;
_event.Subscribe(OnAutomationChange, AutomationChanged.Priority.AutoDesignApplier); _event.Subscribe(OnAutomationChange, AutomationChanged.Priority.AutoDesignApplier);
_weapons.Subscribe(OnWeaponLoading, WeaponLoading.Priority.AutoDesignApplier); _weapons.Subscribe(OnWeaponLoading, WeaponLoading.Priority.AutoDesignApplier);
@ -227,10 +230,15 @@ public class AutoDesignApplier : IDisposable
} }
else if (!GetPlayerSet(identifier, out set!)) else if (!GetPlayerSet(identifier, out set!))
{ {
if (state.UpdateTerritory(_clientState.TerritoryType) && _config.RevertManualChangesOnZoneChange)
_state.ResetState(state, StateChanged.Source.Game);
return true; return true;
} }
Reduce(actor, state, set, true, false); var respectManual = !state.UpdateTerritory(_clientState.TerritoryType) || !_config.RevertManualChangesOnZoneChange;
if (!respectManual)
_state.ResetState(state, StateChanged.Source.Game);
Reduce(actor, state, set, respectManual, false);
return true; return true;
} }

View file

@ -34,6 +34,7 @@ public class Configuration : IPluginConfiguration, ISavable
public bool ShowAutomationSetEditing { get; set; } = true; public bool ShowAutomationSetEditing { get; set; } = true;
public bool ShowAllAutomatedApplicationRules { get; set; } = true; public bool ShowAllAutomatedApplicationRules { get; set; } = true;
public bool ShowUnlockedItemWarnings { get; set; } = true; public bool ShowUnlockedItemWarnings { get; set; } = true;
public bool RevertManualChangesOnZoneChange { get; set; } = false;
public MainWindow.TabType SelectedTab { get; set; } = MainWindow.TabType.Settings; public MainWindow.TabType SelectedTab { get; set; } = MainWindow.TabType.Settings;
public DoubleModifier DeleteDesignModifier { get; set; } = new(ModifierHotkey.Control, ModifierHotkey.Shift); public DoubleModifier DeleteDesignModifier { get; set; } = new(ModifierHotkey.Control, ModifierHotkey.Shift);

View file

@ -82,6 +82,9 @@ public class SettingsTab : ITab
Checkbox("Auto-Reload Gear", Checkbox("Auto-Reload Gear",
"Automatically reload equipment pieces on your own character when changing any mod options in Penumbra in their associated collection.", "Automatically reload equipment pieces on your own character when changing any mod options in Penumbra in their associated collection.",
_config.AutoRedrawEquipOnChanges, _autoRedraw.SetState); _config.AutoRedrawEquipOnChanges, _autoRedraw.SetState);
Checkbox("Revert Manual Changes on Zone Change",
"Restores the old behaviour of reverting your character to its game or automation base whenever you change the zone.",
_config.RevertManualChangesOnZoneChange, v => _config.RevertManualChangesOnZoneChange = v);
ImGui.NewLine(); ImGui.NewLine();
} }

View file

@ -38,6 +38,9 @@ public class ActorState
/// <summary> The Lock-Key locking this state. </summary> /// <summary> The Lock-Key locking this state. </summary>
public uint Combination; public uint Combination;
/// <summary> The territory the draw object was created last. </summary>
public ushort LastTerritory;
/// <summary> Whether the State is locked at all. </summary> /// <summary> Whether the State is locked at all. </summary>
public bool IsLocked public bool IsLocked
=> Combination != 0; => Combination != 0;
@ -98,4 +101,13 @@ public class ActorState
_sources[i] = StateChanged.Source.Manual; _sources[i] = StateChanged.Source.Manual;
} }
} }
public bool UpdateTerritory(ushort territory)
{
if (territory == LastTerritory)
return false;
LastTerritory = territory;
return true;
}
} }

View file

@ -3,7 +3,9 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using Dalamud.Game.ClientState;
using Dalamud.Game.ClientState.Conditions; using Dalamud.Game.ClientState.Conditions;
using Dalamud.Plugin.Services;
using Glamourer.Customization; using Glamourer.Customization;
using Glamourer.Designs; using Glamourer.Designs;
using Glamourer.Events; using Glamourer.Events;
@ -26,19 +28,21 @@ public class StateManager : IReadOnlyDictionary<ActorIdentifier, ActorState>
private readonly StateApplier _applier; private readonly StateApplier _applier;
private readonly StateEditor _editor; private readonly StateEditor _editor;
private readonly Condition _condition; private readonly Condition _condition;
private readonly IClientState _clientState;
private readonly Dictionary<ActorIdentifier, ActorState> _states = new(); private readonly Dictionary<ActorIdentifier, ActorState> _states = new();
public StateManager(ActorService actors, ItemManager items, StateChanged @event, StateApplier applier, StateEditor editor, public StateManager(ActorService actors, ItemManager items, StateChanged @event, StateApplier applier, StateEditor editor,
HumanModelList humans, Condition condition) HumanModelList humans, Condition condition, IClientState clientState)
{ {
_actors = actors; _actors = actors;
_items = items; _items = items;
_event = @event; _event = @event;
_applier = applier; _applier = applier;
_editor = editor; _editor = editor;
_humans = humans; _humans = humans;
_condition = condition; _condition = condition;
_clientState = clientState;
} }
public IEnumerator<KeyValuePair<ActorIdentifier, ActorState>> GetEnumerator() public IEnumerator<KeyValuePair<ActorIdentifier, ActorState>> GetEnumerator()
@ -81,9 +85,10 @@ public class StateManager : IReadOnlyDictionary<ActorIdentifier, ActorState>
// and the draw objects data for the model data (where possible). // and the draw objects data for the model data (where possible).
state = new ActorState(identifier) state = new ActorState(identifier)
{ {
ModelData = FromActor(actor, true), ModelData = FromActor(actor, true),
BaseData = FromActor(actor, false), BaseData = FromActor(actor, false),
LastJob = (byte)(actor.IsCharacter ? actor.AsCharacter->CharacterData.ClassJob : 0), LastJob = (byte)(actor.IsCharacter ? actor.AsCharacter->CharacterData.ClassJob : 0),
LastTerritory = _clientState.TerritoryType,
}; };
// state.Identifier is owned. // state.Identifier is owned.
_states.Add(state.Identifier, state); _states.Add(state.Identifier, state);
@ -381,7 +386,9 @@ public class StateManager : IReadOnlyDictionary<ActorIdentifier, ActorState>
if (design.DoApplyVisorToggle()) if (design.DoApplyVisorToggle())
_editor.ChangeMetaState(state, ActorState.MetaIndex.VisorState, design.DesignData.IsVisorToggled(), source, out _, key); _editor.ChangeMetaState(state, ActorState.MetaIndex.VisorState, design.DesignData.IsVisorToggled(), source, out _, key);
var flags = state.AllowsRedraw(_condition) ? design.ApplyCustomize : design.ApplyCustomize & ~CustomizeFlagExtensions.RedrawRequired; var flags = state.AllowsRedraw(_condition)
? design.ApplyCustomize
: design.ApplyCustomize & ~CustomizeFlagExtensions.RedrawRequired;
_editor.ChangeHumanCustomize(state, design.DesignData.Customize, flags, source, out _, out var applied, key); _editor.ChangeHumanCustomize(state, design.DesignData.Customize, flags, source, out _, out var applied, key);
redraw |= applied.RequiresRedraw(); redraw |= applied.RequiresRedraw();
@ -408,7 +415,8 @@ public class StateManager : IReadOnlyDictionary<ActorIdentifier, ActorState>
{ {
_applier.ChangeCustomize(actors, state.ModelData.Customize); _applier.ChangeCustomize(actors, state.ModelData.Customize);
foreach (var slot in EquipSlotExtensions.EqdpSlots) foreach (var slot in EquipSlotExtensions.EqdpSlots)
_applier.ChangeArmor(actors, slot, state.ModelData.Armor(slot), state[slot, false] is not StateChanged.Source.Ipc, state.ModelData.IsHatVisible()); _applier.ChangeArmor(actors, slot, state.ModelData.Armor(slot), state[slot, false] is not StateChanged.Source.Ipc,
state.ModelData.IsHatVisible());
var mainhandActors = state.ModelData.MainhandType != state.BaseData.MainhandType ? actors.OnlyGPose() : actors; var mainhandActors = state.ModelData.MainhandType != state.BaseData.MainhandType ? actors.OnlyGPose() : actors;
_applier.ChangeMainhand(mainhandActors, state.ModelData.Item(EquipSlot.MainHand), state.ModelData.Stain(EquipSlot.MainHand)); _applier.ChangeMainhand(mainhandActors, state.ModelData.Item(EquipSlot.MainHand), state.ModelData.Stain(EquipSlot.MainHand));
var offhandActors = state.ModelData.OffhandType != state.BaseData.OffhandType ? actors.OnlyGPose() : actors; var offhandActors = state.ModelData.OffhandType != state.BaseData.OffhandType ? actors.OnlyGPose() : actors;