From 07f89334c17e1776ac398ee7ca1337fbc17a53c5 Mon Sep 17 00:00:00 2001 From: RisaDev <151885272+RisaDev@users.noreply.github.com> Date: Sat, 13 Apr 2024 01:55:27 +0300 Subject: [PATCH] Added ability to automatically set editor preview character to current character on login Also refactored some things --- .../Configuration/Data/PluginConfiguration.cs | 14 +-- .../Game/Services/GameObjectService.cs | 3 + .../Templates/TemplateEditorManager.cs | 86 +++++++++++++++---- .../UI/Windows/MainWindow/Tabs/SettingsTab.cs | 13 +++ .../Tabs/Templates/BoneEditorPanel.cs | 29 ++----- 5 files changed, 95 insertions(+), 50 deletions(-) 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