diff --git a/CustomizePlus/Configuration/Data/PluginConfiguration.cs b/CustomizePlus/Configuration/Data/PluginConfiguration.cs
index 961dcf1..a7b40b6 100644
--- a/CustomizePlus/Configuration/Data/PluginConfiguration.cs
+++ b/CustomizePlus/Configuration/Data/PluginConfiguration.cs
@@ -13,6 +13,7 @@
using CustomizePlus.Configuration.Services;
using CustomizePlus.Game.Services;
using CustomizePlus.UI.Windows;
+using Dalamud.Plugin.Services;
namespace CustomizePlus.Configuration.Data;
@@ -73,7 +74,10 @@ public class EditorConfigurationEntries
public string? PreviewCharacterName { get; set; } = null;
public int EditorValuesPrecision { get; set; } = 3;
+
public BoneAttribute EditorMode { get; set; } = BoneAttribute.Position;
+
+ public bool SetPreviewToCurrentCharacterOnLogin { get; set; } = false;
}
public EditorConfigurationEntries EditorConfiguration { get; set; } = new();
@@ -100,25 +104,15 @@ public class ProfileApplicationSettingsEntries
[JsonIgnore]
private readonly SaveService _saveService;
- [JsonIgnore]
- private readonly Logger _logger;
-
- [JsonIgnore]
- private readonly ChatService _chatService;
-
[JsonIgnore]
private readonly MessageService _messageService;
public PluginConfiguration(
SaveService saveService,
- Logger logger,
- ChatService chatService,
MessageService messageService,
ConfigurationMigrator migrator)
{
_saveService = saveService;
- _logger = logger;
- _chatService = chatService;
_messageService = messageService;
Load(migrator);
diff --git a/CustomizePlus/Game/Services/GameObjectService.cs b/CustomizePlus/Game/Services/GameObjectService.cs
index d3177ce..523eb7f 100644
--- a/CustomizePlus/Game/Services/GameObjectService.cs
+++ b/CustomizePlus/Game/Services/GameObjectService.cs
@@ -59,6 +59,8 @@ public bool IsActorHasScalableRoot(Actor actor)
///
public IEnumerable<(ActorIdentifier, Actor)> FindActorsByName(string name)
{
+ _objectManager.Update();
+
foreach (var kvPair in _objectManager.Identifiers)
{
var identifier = kvPair.Key;
@@ -81,6 +83,7 @@ public bool IsActorHasScalableRoot(Actor actor)
public Actor GetLocalPlayerActor()
{
+ _objectManager.Update();
return _objectManager.Player;
}
diff --git a/CustomizePlus/Templates/TemplateEditorManager.cs b/CustomizePlus/Templates/TemplateEditorManager.cs
index 07f4a17..5e2e684 100644
--- a/CustomizePlus/Templates/TemplateEditorManager.cs
+++ b/CustomizePlus/Templates/TemplateEditorManager.cs
@@ -1,4 +1,5 @@
-using CustomizePlus.Core.Data;
+using CustomizePlus.Configuration.Data;
+using CustomizePlus.Core.Data;
using CustomizePlus.Game.Events;
using CustomizePlus.Game.Services;
using CustomizePlus.Profiles;
@@ -6,20 +7,24 @@
using CustomizePlus.Profiles.Enums;
using CustomizePlus.Templates.Data;
using CustomizePlus.Templates.Events;
+using Dalamud.Plugin.Services;
using FFXIVClientStructs.FFXIV.Client.Graphics.Scene;
using OtterGui.Log;
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Numerics;
namespace CustomizePlus.Templates;
-public class TemplateEditorManager
+public class TemplateEditorManager : IDisposable
{
private readonly TemplateChanged _event;
private readonly Logger _logger;
private readonly GameObjectService _gameObjectService;
private readonly TemplateManager _templateManager;
+ private readonly IClientState _clientState;
+ private readonly PluginConfiguration _configuration;
///
/// Reference to the original template which is currently being edited, should not be edited!
@@ -54,31 +59,59 @@ public class TemplateEditorManager
///
public bool HasChanges { get; private set; }
+ ///
+ /// Name of the preview character for the editor
+ ///
+ public string CharacterName => EditorProfile.CharacterName;
+
+ ///
+ /// Checks if preview character exists at the time of call
+ ///
+ public bool IsCharacterFound => _gameObjectService.FindActorsByName(CharacterName).Count() > 0;
+
public bool IsKeepOnlyEditorProfileActive { get; set; } //todo
public TemplateEditorManager(
TemplateChanged @event,
Logger logger,
TemplateManager templateManager,
- GameObjectService gameObjectService)
+ GameObjectService gameObjectService,
+ IClientState clientState,
+ PluginConfiguration configuration)
{
_event = @event;
_logger = logger;
_templateManager = templateManager;
_gameObjectService = gameObjectService;
+ _clientState = clientState;
+ _configuration = configuration;
+
+ _clientState.Login += OnLogin;
+
+ EditorProfile = new Profile()
+ {
+ Templates = new List(),
+ Enabled = false,
+ Name = "Template editor profile",
+ ProfileType = ProfileType.Editor,
+ CharacterName = configuration.EditorConfiguration.PreviewCharacterName!
+ };
+ }
- EditorProfile = new Profile() { Templates = new List(), Enabled = false, Name = "Template editor profile", ProfileType = ProfileType.Editor };
+ public void Dispose()
+ {
+ _clientState.Login -= OnLogin;
}
///
/// Turn on editing of a specific template. If character name not set will default to local player.
///
- internal bool EnableEditor(Template template, string? characterName = null)
+ internal bool EnableEditor(Template template)
{
if (IsEditorActive || IsEditorPaused)
return false;
- _logger.Debug($"Enabling editor profile for {template.Name} via character {characterName}");
+ _logger.Debug($"Enabling editor profile for {template.Name} via character {CharacterName}");
CurrentlyEditedTemplateId = template.UniqueId;
_currentlyEditedTemplateOriginal = template;
@@ -90,10 +123,10 @@ internal bool EnableEditor(Template template, string? characterName = null)
Name = "Template editor temporary template"
};
- if (characterName != null)
- EditorProfile.CharacterName = characterName;
- else //safeguard
- EditorProfile.CharacterName = _gameObjectService.GetCurrentPlayerName();
+ if (CharacterName == null) //safeguard
+ ChangeEditorCharacterInternal(_gameObjectService.GetCurrentPlayerName()); //will also set EditorProfile.CharacterName
+ else
+ EditorProfile.CharacterName = CharacterName;
EditorProfile.Templates.Clear(); //safeguard
EditorProfile.Templates.Add(CurrentlyEditedTemplate);
@@ -101,7 +134,7 @@ internal bool EnableEditor(Template template, string? characterName = null)
HasChanges = false;
IsEditorActive = true;
- _event.Invoke(TemplateChanged.Type.EditorEnabled, template, characterName);
+ _event.Invoke(TemplateChanged.Type.EditorEnabled, template, CharacterName);
return true;
}
@@ -116,17 +149,14 @@ internal bool DisableEditor()
_logger.Debug($"Disabling editor profile");
- string characterName = EditorProfile.CharacterName;
-
CurrentlyEditedTemplateId = Guid.Empty;
CurrentlyEditedTemplate = null;
EditorProfile.Enabled = false;
- EditorProfile.CharacterName = "";
EditorProfile.Templates.Clear();
IsEditorActive = false;
HasChanges = false;
- _event.Invoke(TemplateChanged.Type.EditorDisabled, null, characterName);
+ _event.Invoke(TemplateChanged.Type.EditorDisabled, null, CharacterName);
return true;
}
@@ -145,12 +175,21 @@ public void SaveChanges(bool asCopy = false)
public bool ChangeEditorCharacter(string characterName)
{
- if (!IsEditorActive || EditorProfile.CharacterName == characterName || IsEditorPaused)
+ if (!IsEditorActive || CharacterName == characterName || IsEditorPaused)
return false;
+ return ChangeEditorCharacterInternal(characterName);
+ }
+
+ private bool ChangeEditorCharacterInternal(string characterName)
+ {
_logger.Debug($"Changing character name for editor profile from {EditorProfile.CharacterName} to {characterName}");
EditorProfile.CharacterName = characterName;
+
+ _configuration.EditorConfiguration.PreviewCharacterName = CharacterName;
+ _configuration.Save();
+
_event.Invoke(TemplateChanged.Type.EditorCharacterChanged, CurrentlyEditedTemplate, (characterName, EditorProfile));
return true;
@@ -265,6 +304,21 @@ public bool ModifyBoneTransform(string boneName, BoneTransform transform)
return true;
}
+ private void OnLogin()
+ {
+ if (_configuration.EditorConfiguration.SetPreviewToCurrentCharacterOnLogin ||
+ string.IsNullOrWhiteSpace(_configuration.EditorConfiguration.PreviewCharacterName))
+ {
+ var localPlayerName = _gameObjectService.GetCurrentPlayerName();
+
+ if (_configuration.EditorConfiguration.PreviewCharacterName != localPlayerName)
+ {
+ _logger.Debug("Resetting editor character because automatic condition triggered in OnLogin");
+ ChangeEditorCharacterInternal(localPlayerName);
+ }
+ }
+ }
+
private Vector3 GetResetValueForAttribute(BoneAttribute attribute)
{
switch (attribute)
diff --git a/CustomizePlus/UI/Windows/MainWindow/Tabs/SettingsTab.cs b/CustomizePlus/UI/Windows/MainWindow/Tabs/SettingsTab.cs
index c6160c9..545c1ae 100644
--- a/CustomizePlus/UI/Windows/MainWindow/Tabs/SettingsTab.cs
+++ b/CustomizePlus/UI/Windows/MainWindow/Tabs/SettingsTab.cs
@@ -194,6 +194,7 @@ private void DrawInterface()
DrawHideWindowInCutscene();
DrawFoldersDefaultOpen();
+ DrawSetPreviewToCurrentCharacterOnLogin();
if (Widget.DoubleModifierSelector("Template Deletion Modifier",
"A modifier you need to hold while clicking the Delete Template button for it to take effect.", 100 * ImGuiHelpers.GlobalScale,
@@ -225,6 +226,18 @@ private void DrawFoldersDefaultOpen()
}
}
+ private void DrawSetPreviewToCurrentCharacterOnLogin()
+ {
+ var isChecked = _configuration.EditorConfiguration.SetPreviewToCurrentCharacterOnLogin;
+
+ if (CtrlHelper.CheckboxWithTextAndHelp("##setpreviewcharaonlogin", "Automatically Set Current Character as Editor Preview Character",
+ "Controls whether editor character will be automatically set to the current character during login.", ref isChecked))
+ {
+ _configuration.EditorConfiguration.SetPreviewToCurrentCharacterOnLogin = isChecked;
+ _configuration.Save();
+ }
+ }
+
#endregion
#region Advanced Settings
diff --git a/CustomizePlus/UI/Windows/MainWindow/Tabs/Templates/BoneEditorPanel.cs b/CustomizePlus/UI/Windows/MainWindow/Tabs/Templates/BoneEditorPanel.cs
index 3468778..7079197 100644
--- a/CustomizePlus/UI/Windows/MainWindow/Tabs/Templates/BoneEditorPanel.cs
+++ b/CustomizePlus/UI/Windows/MainWindow/Tabs/Templates/BoneEditorPanel.cs
@@ -42,12 +42,7 @@ public class BoneEditorPanel
public bool HasChanges => _editorManager.HasChanges;
public bool IsEditorActive => _editorManager.IsEditorActive;
public bool IsEditorPaused => _editorManager.IsEditorPaused;
-
- ///
- /// Was character with name from CharacterName found in the object table or not
- ///
- public bool IsCharacterFound { get; private set; }
- public string CharacterName { get; private set; }
+ public bool IsCharacterFound => _editorManager.IsCharacterFound;
public BoneEditorPanel(
TemplateFileSystemSelector templateFileSystemSelector,
@@ -64,12 +59,11 @@ public BoneEditorPanel(
_isMirrorModeEnabled = configuration.EditorConfiguration.BoneMirroringEnabled;
_precision = configuration.EditorConfiguration.EditorValuesPrecision;
_editingAttribute = configuration.EditorConfiguration.EditorMode;
- CharacterName = configuration.EditorConfiguration.PreviewCharacterName!;
}
public bool EnableEditor(Template template)
{
- if (_editorManager.EnableEditor(template, CharacterName))
+ if (_editorManager.EnableEditor(template))
{
_editorManager.SetLimitLookupToOwned(_configuration.EditorConfiguration.LimitLookupToOwnedObjects);
@@ -94,18 +88,8 @@ public bool DisableEditor()
public void Draw()
{
- IsCharacterFound = _gameObjectService.FindActorsByName(CharacterName).Count() > 0;
_isUnlocked = IsCharacterFound && IsEditorActive && !IsEditorPaused;
- if (string.IsNullOrWhiteSpace(CharacterName))
- {
- CharacterName = _gameObjectService.GetCurrentPlayerName();
- _editorManager.ChangeEditorCharacter(CharacterName);
-
- _configuration.EditorConfiguration.PreviewCharacterName = CharacterName;
- _configuration.Save();
- }
-
DrawEditorConfirmationPopup();
ImGui.Separator();
@@ -121,7 +105,7 @@ public void Draw()
ImGuiUtil.DrawFrameColumn("Show editor preview on");
ImGui.TableNextColumn();
var width = new Vector2(ImGui.GetContentRegionAvail().X - ImGui.CalcTextSize("Limit to my creatures").X - 68, 0);
- var name = _newCharacterName ?? CharacterName;
+ var name = _newCharacterName ?? _editorManager.CharacterName;
ImGui.SetNextItemWidth(width.X);
using (var disabled = ImRaii.Disabled(!IsEditorActive || IsEditorPaused))
@@ -135,13 +119,10 @@ public void Draw()
if (ImGui.IsItemDeactivatedAfterEdit())
{
- if (_newCharacterName == "")
+ if (string.IsNullOrWhiteSpace(_newCharacterName))
_newCharacterName = _gameObjectService.GetCurrentPlayerName();
- CharacterName = _newCharacterName!;
- _editorManager.ChangeEditorCharacter(CharacterName);
- _configuration.EditorConfiguration.PreviewCharacterName = CharacterName;
- _configuration.Save();
+ _editorManager.ChangeEditorCharacter(_newCharacterName);
_newCharacterName = null;
}