This commit is contained in:
Ottermandias 2023-07-11 16:05:38 +02:00
parent 20cc67275a
commit f8f90124ee
8 changed files with 68 additions and 19 deletions

View file

@ -106,7 +106,7 @@ public class AutoDesignApplier : IDisposable
return; return;
} }
if (!_state.GetOrCreate(id, actor, out var state)) if (!_state.TryGetValue(id, out var state))
return; return;
if (oldJob.Id == newJob.Id && state.LastJob == newJob.Id) if (oldJob.Id == newJob.Id && state.LastJob == newJob.Id)
@ -128,6 +128,27 @@ public class AutoDesignApplier : IDisposable
Reduce(actor, state, set, false); Reduce(actor, state, set, false);
} }
public bool Reduce(Actor actor, ActorIdentifier identifier, [NotNullWhen(true)] out ActorState? state)
{
AutoDesignSet set;
if (!_state.TryGetValue(identifier, out state))
{
if (!_config.EnableAutoDesigns)
return false;
if (!GetPlayerSet(identifier, out set!))
return false;
if (!_state.GetOrCreate(identifier, actor, out state))
return false;
}
else if (!GetPlayerSet(identifier, out set!))
return true;
Reduce(actor, state, set, true);
return true;
}
public void Reduce(Actor actor, ActorIdentifier identifier, ActorState state) public void Reduce(Actor actor, ActorIdentifier identifier, ActorState state)
{ {
if (!_config.EnableAutoDesigns) if (!_config.EnableAutoDesigns)

View file

@ -39,6 +39,9 @@ public class DesignConverter
return ShareJObject(design); return ShareJObject(design);
} }
public string ShareBase64(Design design)
=> ShareBase64(ShareJObject(design));
public string ShareBase64(DesignBase design) public string ShareBase64(DesignBase design)
=> ShareBase64(ShareJObject(design)); => ShareBase64(ShareJObject(design));

View file

@ -17,7 +17,6 @@ using ImGuiNET;
using OtterGui; using OtterGui;
using OtterGui.Raii; using OtterGui.Raii;
using Penumbra.GameData.Actors; using Penumbra.GameData.Actors;
using Penumbra.GameData.Data;
using Penumbra.GameData.Enums; using Penumbra.GameData.Enums;
namespace Glamourer.Gui.Tabs.ActorTab; namespace Glamourer.Gui.Tabs.ActorTab;
@ -33,6 +32,7 @@ public class ActorPanel
private readonly Configuration _config; private readonly Configuration _config;
private readonly DesignConverter _converter; private readonly DesignConverter _converter;
private readonly ObjectManager _objects; private readonly ObjectManager _objects;
private readonly DesignManager _designManager;
private ActorIdentifier _identifier; private ActorIdentifier _identifier;
private string _actorName = string.Empty; private string _actorName = string.Empty;
@ -42,7 +42,7 @@ public class ActorPanel
public ActorPanel(ActorSelector selector, StateManager stateManager, CustomizationDrawer customizationDrawer, public ActorPanel(ActorSelector selector, StateManager stateManager, CustomizationDrawer customizationDrawer,
EquipmentDrawer equipmentDrawer, IdentifierService identification, AutoDesignApplier autoDesignApplier, EquipmentDrawer equipmentDrawer, IdentifierService identification, AutoDesignApplier autoDesignApplier,
Configuration config, DesignConverter converter, ObjectManager objects) Configuration config, DesignConverter converter, ObjectManager objects, DesignManager designManager)
{ {
_selector = selector; _selector = selector;
_stateManager = stateManager; _stateManager = stateManager;
@ -53,6 +53,7 @@ public class ActorPanel
_config = config; _config = config;
_converter = converter; _converter = converter;
_objects = objects; _objects = objects;
_designManager = designManager;
} }
public void Draw() public void Draw()
@ -106,9 +107,11 @@ public class ActorPanel
if (!child || !_selector.HasSelection || !_stateManager.GetOrCreate(_identifier, _actor, out _state)) if (!child || !_selector.HasSelection || !_stateManager.GetOrCreate(_identifier, _actor, out _state))
return; return;
ApplyClipboardButton(); SetFromClipboard();
ImGui.SameLine(); ImGui.SameLine();
CopyToClipboardButton(); ExportToClipboardButton();
ImGui.SameLine();
SaveDesignButton();
ImGui.SameLine(); ImGui.SameLine();
DrawApplyToSelf(); DrawApplyToSelf();
ImGui.SameLine(); ImGui.SameLine();
@ -222,7 +225,7 @@ public class ActorPanel
_stateManager.TurnHuman(_state, StateChanged.Source.Manual); _stateManager.TurnHuman(_state, StateChanged.Source.Manual);
} }
private void ApplyClipboardButton() private void SetFromClipboard()
{ {
if (!ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Clipboard.ToIconString(), new Vector2(ImGui.GetFrameHeight()), if (!ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Clipboard.ToIconString(), new Vector2(ImGui.GetFrameHeight()),
"Try to apply a design from your clipboard.", false, true)) "Try to apply a design from your clipboard.", false, true))
@ -241,7 +244,7 @@ public class ActorPanel
} }
} }
private void CopyToClipboardButton() private void ExportToClipboardButton()
{ {
if (!ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Copy.ToIconString(), new Vector2(ImGui.GetFrameHeight()), if (!ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Copy.ToIconString(), new Vector2(ImGui.GetFrameHeight()),
"Copy the current design to your clipboard.", false, true)) "Copy the current design to your clipboard.", false, true))
@ -303,4 +306,26 @@ public class ActorPanel
_stateManager.ApplyDesign(_converter.Convert(_state!, EquipFlagExtensions.All, CustomizeFlagExtensions.AllRelevant), state, _stateManager.ApplyDesign(_converter.Convert(_state!, EquipFlagExtensions.All, CustomizeFlagExtensions.AllRelevant), state,
StateChanged.Source.Manual); StateChanged.Source.Manual);
} }
private string _newName = string.Empty;
private DesignBase? _newDesign = null;
private void SaveDesignButton()
{
if (ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Save.ToIconString(), new Vector2(ImGui.GetFrameHeight()),
"Save the current state as a design.", !_state!.ModelData.IsHuman, true))
{
ImGui.OpenPopup("Save as Design");
_newName = _state.Identifier.ToName();
_newDesign = _converter.Convert(_state, EquipFlagExtensions.All, CustomizeFlagExtensions.All);
}
if (ImGuiUtil.OpenNameField("Save as Design", ref _newName))
{
if (_newDesign != null && _newName.Length > 0)
_designManager.CreateClone(_newDesign, _newName);
_newDesign = null;
_newName = string.Empty;
}
}
} }

View file

@ -268,6 +268,8 @@ public class SetPanel
_manager.ChangeApplicationType(set, autoDesignIndex, newType); _manager.ChangeApplicationType(set, autoDesignIndex, newType);
} }
private static readonly IReadOnlyList<(AutoDesign.Type, string)> Types = new[] private static readonly IReadOnlyList<(AutoDesign.Type, string)> Types = new[]
{ {
(AutoDesign.Type.Customizations, (AutoDesign.Type.Customizations,

View file

@ -289,16 +289,16 @@ public class DesignPanel
private void DrawButtonRow() private void DrawButtonRow()
{ {
DrawSetFromClipboard(); SetFromClipboardButton();
ImGui.SameLine(); ImGui.SameLine();
DrawExportToClipboard(); ExportToClipboardButton();
ImGui.SameLine(); ImGui.SameLine();
DrawApplyToSelf(); DrawApplyToSelf();
ImGui.SameLine(); ImGui.SameLine();
DrawApplyToTarget(); DrawApplyToTarget();
} }
private void DrawSetFromClipboard() private void SetFromClipboardButton()
{ {
if (!ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Clipboard.ToIconString(), new Vector2(ImGui.GetFrameHeight()), if (!ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Clipboard.ToIconString(), new Vector2(ImGui.GetFrameHeight()),
"Try to apply a design from your clipboard.", _selector.Selected!.WriteProtected(), true)) "Try to apply a design from your clipboard.", _selector.Selected!.WriteProtected(), true))
@ -317,7 +317,7 @@ public class DesignPanel
} }
} }
private void DrawExportToClipboard() private void ExportToClipboardButton()
{ {
if (!ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Copy.ToIconString(), new Vector2(ImGui.GetFrameHeight()), if (!ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Copy.ToIconString(), new Vector2(ImGui.GetFrameHeight()),
"Copy the current design to your clipboard.", false, true)) "Copy the current design to your clipboard.", false, true))

View file

@ -2,7 +2,6 @@
using System; using System;
using FFXIVClientStructs.FFXIV.Client.Game.Character; using FFXIVClientStructs.FFXIV.Client.Game.Character;
using FFXIVClientStructs.FFXIV.Client.Game.Object; using FFXIVClientStructs.FFXIV.Client.Game.Object;
using FFXIVClientStructs.FFXIV.Client.System.String;
using Glamourer.Customization; using Glamourer.Customization;
using Penumbra.GameData.Enums; using Penumbra.GameData.Enums;
using Penumbra.GameData.Structs; using Penumbra.GameData.Structs;

View file

@ -98,7 +98,7 @@ public class StateListener : IDisposable
/// Invoked when a new draw object is created from a game object. /// Invoked when a new draw object is created from a game object.
/// We need to update all state: Model ID, Customize and Equipment. /// We need to update all state: Model ID, Customize and Equipment.
/// Weapons and meta flags are updated independently. /// Weapons and meta flags are updated independently.
/// We also need to apply fixed designs here (TODO). /// We also need to apply fixed designs here.
/// </summary> /// </summary>
private unsafe void OnCreatingCharacterBase(nint actorPtr, string _, nint modelPtr, nint customizePtr, nint equipDataPtr) private unsafe void OnCreatingCharacterBase(nint actorPtr, string _, nint modelPtr, nint customizePtr, nint equipDataPtr)
{ {
@ -107,9 +107,8 @@ public class StateListener : IDisposable
ref var modelId = ref *(uint*)modelPtr; ref var modelId = ref *(uint*)modelPtr;
ref var customize = ref *(Customize*)customizePtr; ref var customize = ref *(Customize*)customizePtr;
if (_manager.TryGetValue(identifier, out var state)) if (_autoDesignApplier.Reduce(actor, identifier, out var state))
{ {
_autoDesignApplier.Reduce(actor, identifier, state);
switch (UpdateBaseData(actor, state, modelId, customizePtr, equipDataPtr)) switch (UpdateBaseData(actor, state, modelId, customizePtr, equipDataPtr))
{ {
// TODO handle right // TODO handle right

View file

@ -286,7 +286,7 @@ public class StateManager : IReadOnlyDictionary<ActorIdentifier, ActorState>
var actors = _applier.ChangeHatState(state, source is StateChanged.Source.Manual or StateChanged.Source.Ipc); var actors = _applier.ChangeHatState(state, source is StateChanged.Source.Manual or StateChanged.Source.Ipc);
Glamourer.Log.Verbose( Glamourer.Log.Verbose(
$"Set Head Gear Visibility in state {state.Identifier} from {old} to {value}. [Affecting {actors.ToLazyString("nothing")}.]"); $"Set Head Gear Visibility in state {state.Identifier.Incognito(null)} from {old} to {value}. [Affecting {actors.ToLazyString("nothing")}.]");
_event.Invoke(StateChanged.Type.Other, source, state, actors, (old, value, ActorState.MetaIndex.HatState)); _event.Invoke(StateChanged.Type.Other, source, state, actors, (old, value, ActorState.MetaIndex.HatState));
} }
@ -298,7 +298,7 @@ public class StateManager : IReadOnlyDictionary<ActorIdentifier, ActorState>
var actors = _applier.ChangeWeaponState(state, source is StateChanged.Source.Manual or StateChanged.Source.Ipc); var actors = _applier.ChangeWeaponState(state, source is StateChanged.Source.Manual or StateChanged.Source.Ipc);
Glamourer.Log.Verbose( Glamourer.Log.Verbose(
$"Set Weapon Visibility in state {state.Identifier} from {old} to {value}. [Affecting {actors.ToLazyString("nothing")}.]"); $"Set Weapon Visibility in state {state.Identifier.Incognito(null)} from {old} to {value}. [Affecting {actors.ToLazyString("nothing")}.]");
_event.Invoke(StateChanged.Type.Other, source, state, actors, (old, value, ActorState.MetaIndex.WeaponState)); _event.Invoke(StateChanged.Type.Other, source, state, actors, (old, value, ActorState.MetaIndex.WeaponState));
} }
@ -310,7 +310,7 @@ public class StateManager : IReadOnlyDictionary<ActorIdentifier, ActorState>
var actors = _applier.ChangeVisor(state, source is StateChanged.Source.Manual or StateChanged.Source.Ipc); var actors = _applier.ChangeVisor(state, source is StateChanged.Source.Manual or StateChanged.Source.Ipc);
Glamourer.Log.Verbose( Glamourer.Log.Verbose(
$"Set Visor State in state {state.Identifier} from {old} to {value}. [Affecting {actors.ToLazyString("nothing")}.]"); $"Set Visor State in state {state.Identifier.Incognito(null)} from {old} to {value}. [Affecting {actors.ToLazyString("nothing")}.]");
_event.Invoke(StateChanged.Type.Other, source, state, actors, (old, value, ActorState.MetaIndex.VisorState)); _event.Invoke(StateChanged.Type.Other, source, state, actors, (old, value, ActorState.MetaIndex.VisorState));
} }
@ -322,7 +322,7 @@ public class StateManager : IReadOnlyDictionary<ActorIdentifier, ActorState>
var actors = _applier.ChangeVisor(state, true); var actors = _applier.ChangeVisor(state, true);
Glamourer.Log.Verbose( Glamourer.Log.Verbose(
$"Set Wetness in state {state.Identifier} from {old} to {value}. [Affecting {actors.ToLazyString("nothing")}.]"); $"Set Wetness in state {state.Identifier.Incognito(null)} from {old} to {value}. [Affecting {actors.ToLazyString("nothing")}.]");
_event.Invoke(StateChanged.Type.Other, state[ActorState.MetaIndex.Wetness], state, actors, (old, value, ActorState.MetaIndex.Wetness)); _event.Invoke(StateChanged.Type.Other, state[ActorState.MetaIndex.Wetness], state, actors, (old, value, ActorState.MetaIndex.Wetness));
} }