Skip to content

Commit

Permalink
Library Feature: Spawn as new actor (#140)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
Cazzar authored Feb 27, 2025
1 parent f6e20fb commit 1f860e0
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
1 change: 1 addition & 0 deletions Brio/Library/Sources/GameDataAppearanceEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Brio.UI.Controls.Stateless;
using Dalamud.Interface.Textures.TextureWraps;
using System;
using ImGuiNET;

namespace Brio.Library.Sources;

Expand Down
62 changes: 59 additions & 3 deletions Brio/UI/Controls/Stateless/ImBrio.ApplyToActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -11,16 +19,64 @@ public static void DrawApplyToActor(EntityManager entityManager, Action<ActorEnt
{
if(entityManager.SelectedEntity is null || entityManager.SelectedEntity is not ActorEntity selectedActor)
{
ImGui.BeginDisabled();
ImGui.Button($"Select an Actor");
ImGui.EndDisabled();
DrawSpawnActor(entityManager, callback);

return;
}

if(ImGui.IsKeyDown(ImGuiKey.LeftCtrl) || ImGui.IsKeyDown(ImGuiKey.RightCtrl))
{
DrawSpawnActor(entityManager, callback);
}
else
{
if(ImGui.Button($"Apply To {selectedActor.FriendlyName}"))
{
callback?.Invoke(selectedActor);
}


if(ImGui.IsItemHovered())
ImGui.SetTooltip("Hold Ctrl to spawn as a new actor");
}

}

private static void DrawSpawnActor(EntityManager entityManager, Action<ActorEntity> 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
);
}
}
}

0 comments on commit 1f860e0

Please sign in to comment.