Added ability to automatically set editor preview character to current character on login
Also refactored some things
This commit is contained in:
@@ -13,6 +13,7 @@ using CustomizePlus.Core.Data;
|
||||
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 PluginConfiguration : IPluginConfiguration, ISavable
|
||||
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 PluginConfiguration : IPluginConfiguration, ISavable
|
||||
[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);
|
||||
|
||||
@@ -59,6 +59,8 @@ public class GameObjectService
|
||||
/// <returns></returns>
|
||||
public IEnumerable<(ActorIdentifier, Actor)> FindActorsByName(string name)
|
||||
{
|
||||
_objectManager.Update();
|
||||
|
||||
foreach (var kvPair in _objectManager.Identifiers)
|
||||
{
|
||||
var identifier = kvPair.Key;
|
||||
@@ -81,6 +83,7 @@ public class GameObjectService
|
||||
|
||||
public Actor GetLocalPlayerActor()
|
||||
{
|
||||
_objectManager.Update();
|
||||
return _objectManager.Player;
|
||||
}
|
||||
|
||||
|
||||
@@ -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.Data;
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the original template which is currently being edited, should not be edited!
|
||||
@@ -54,31 +59,59 @@ public class TemplateEditorManager
|
||||
/// </summary>
|
||||
public bool HasChanges { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Name of the preview character for the editor
|
||||
/// </summary>
|
||||
public string CharacterName => EditorProfile.CharacterName;
|
||||
|
||||
/// <summary>
|
||||
/// Checks if preview character exists at the time of call
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
EditorProfile = new Profile() { Templates = new List<Template>(), Enabled = false, Name = "Template editor profile", ProfileType = ProfileType.Editor };
|
||||
_clientState.Login += OnLogin;
|
||||
|
||||
EditorProfile = new Profile()
|
||||
{
|
||||
Templates = new List<Template>(),
|
||||
Enabled = false,
|
||||
Name = "Template editor profile",
|
||||
ProfileType = ProfileType.Editor,
|
||||
CharacterName = configuration.EditorConfiguration.PreviewCharacterName!
|
||||
};
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_clientState.Login -= OnLogin;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turn on editing of a specific template. If character name not set will default to local player.
|
||||
/// </summary>
|
||||
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 @@ public class TemplateEditorManager
|
||||
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 @@ public class TemplateEditorManager
|
||||
HasChanges = false;
|
||||
IsEditorActive = true;
|
||||
|
||||
_event.Invoke(TemplateChanged.Type.EditorEnabled, template, characterName);
|
||||
_event.Invoke(TemplateChanged.Type.EditorEnabled, template, CharacterName);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -116,17 +149,14 @@ public class TemplateEditorManager
|
||||
|
||||
_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 class TemplateEditorManager
|
||||
|
||||
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 class TemplateEditorManager
|
||||
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)
|
||||
|
||||
@@ -194,6 +194,7 @@ public class SettingsTab
|
||||
|
||||
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 @@ public class SettingsTab
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -42,12 +42,7 @@ public class BoneEditorPanel
|
||||
public bool HasChanges => _editorManager.HasChanges;
|
||||
public bool IsEditorActive => _editorManager.IsEditorActive;
|
||||
public bool IsEditorPaused => _editorManager.IsEditorPaused;
|
||||
|
||||
/// <summary>
|
||||
/// Was character with name from CharacterName found in the object table or not
|
||||
/// </summary>
|
||||
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 class 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 class BoneEditorPanel
|
||||
|
||||
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 class BoneEditorPanel
|
||||
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 class BoneEditorPanel
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user