From 1f860e044f8f8cce6910532668b1a551cede1712 Mon Sep 17 00:00:00 2001 From: Cazzar Date: Thu, 27 Feb 2025 11:23:17 +1100 Subject: [PATCH] Library Feature: Spawn as new actor (#140) * Add option to spawn as new actor - WIP * refactor controls to icon button, add tooltip, remove commented code * Change functionality to holding ctrl instead of a new button due to layout issues. --- .../Sources/GameDataAppearanceEntry.cs | 1 + .../Controls/Stateless/ImBrio.ApplyToActor.cs | 62 ++++++++++++++++++- 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/Brio/Library/Sources/GameDataAppearanceEntry.cs b/Brio/Library/Sources/GameDataAppearanceEntry.cs index f43c4c8c..9d1a765d 100644 --- a/Brio/Library/Sources/GameDataAppearanceEntry.cs +++ b/Brio/Library/Sources/GameDataAppearanceEntry.cs @@ -8,6 +8,7 @@ using Brio.UI.Controls.Stateless; using Dalamud.Interface.Textures.TextureWraps; using System; +using ImGuiNET; namespace Brio.Library.Sources; diff --git a/Brio/UI/Controls/Stateless/ImBrio.ApplyToActor.cs b/Brio/UI/Controls/Stateless/ImBrio.ApplyToActor.cs index bc4b59fa..8bc806dd 100644 --- a/Brio/UI/Controls/Stateless/ImBrio.ApplyToActor.cs +++ b/Brio/UI/Controls/Stateless/ImBrio.ApplyToActor.cs @@ -2,6 +2,14 @@ using Brio.Entities.Actor; using ImGuiNET; using System; +using System.Numerics; +using Brio.Entities.Core; +using Brio.Game.Actor; +using Brio.Game.Actor.Extensions; +using Brio.Game.Core; +using Dalamud.Game.ClientState.Objects.Types; +using Dalamud.Interface; +using Dalamud.Interface.Utility.Raii; namespace Brio.UI.Controls.Stateless; @@ -11,9 +19,14 @@ public static void DrawApplyToActor(EntityManager entityManager, Action callback) + { + if(!Brio.TryGetService(out ActorSpawnService spawnService)) + { + using var _ = ImRaii.Disabled(true); + ImGui.Button("Unable to Spawn"); + } + + + if(ImGui.Button("Spawn As New Actor")) + { + if(!spawnService.CreateCharacter(out var character, disableSpawnCompanion: true)) + { + Brio.Log.Error("Unable to spawn character"); + return; + } + + unsafe bool IsReadyToDraw() => character.Native()->IsReadyToDraw(); + + Brio.Framework.RunUntilSatisfied( + IsReadyToDraw, + (_) => + { + var entity = entityManager.GetEntity(new EntityId(character)); + if(entity is not ActorEntity actorEntity) + { + Brio.Log.Error($"Unable to get actor entity is: {entity?.GetType()} {entity}"); + return; + } + + callback?.Invoke(actorEntity); + }, + 100, + dontStartFor: 2 + ); } } }