Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library Feature: Spawn as new actor #140

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
);
}
}
}