Add owned NPC button for automation identifiers.

This commit is contained in:
Ottermandias 2024-10-07 18:34:52 +02:00
parent 65e33d91ac
commit d104b794ae
4 changed files with 31 additions and 9 deletions

View file

@ -299,12 +299,19 @@ public sealed class AutoDesignApplier : IDisposable
if (_manager.EnabledSets.TryGetValue(identifier, out set)) if (_manager.EnabledSets.TryGetValue(identifier, out set))
return true; return true;
identifier = _actors.CreatePlayer(identifier.PlayerName, ushort.MaxValue); identifier = _actors.CreatePlayer(identifier.PlayerName, WorldId.AnyWorld);
return _manager.EnabledSets.TryGetValue(identifier, out set); return _manager.EnabledSets.TryGetValue(identifier, out set);
case IdentifierType.Retainer: case IdentifierType.Retainer:
case IdentifierType.Npc: case IdentifierType.Npc:
return _manager.EnabledSets.TryGetValue(identifier, out set); return _manager.EnabledSets.TryGetValue(identifier, out set);
case IdentifierType.Owned: case IdentifierType.Owned:
if (_manager.EnabledSets.TryGetValue(identifier, out set))
return true;
identifier = _actors.CreateOwned(identifier.PlayerName, WorldId.AnyWorld, identifier.Kind, identifier.DataId);
if (_manager.EnabledSets.TryGetValue(identifier, out set))
return true;
identifier = _actors.CreateNpc(identifier.Kind, identifier.DataId); identifier = _actors.CreateNpc(identifier.Kind, identifier.DataId);
return _manager.EnabledSets.TryGetValue(identifier, out set); return _manager.EnabledSets.TryGetValue(identifier, out set);
default: default:

View file

@ -570,12 +570,13 @@ public class AutoDesignManager : ISavable, IReadOnlyList<AutoDesignSet>, IDispos
IdentifierType.Player => true, IdentifierType.Player => true,
IdentifierType.Retainer => true, IdentifierType.Retainer => true,
IdentifierType.Npc => true, IdentifierType.Npc => true,
IdentifierType.Owned => true,
_ => false, _ => false,
}; };
if (!validType) if (!validType)
{ {
group = Array.Empty<ActorIdentifier>(); group = [];
return false; return false;
} }
@ -602,6 +603,7 @@ public class AutoDesignManager : ISavable, IReadOnlyList<AutoDesignSet>, IDispos
: ActorIdentifier.RetainerType.Bell).CreatePermanent(), : ActorIdentifier.RetainerType.Bell).CreatePermanent(),
], ],
IdentifierType.Npc => CreateNpcs(_actors, identifier), IdentifierType.Npc => CreateNpcs(_actors, identifier),
IdentifierType.Owned => CreateNpcs(_actors, identifier),
_ => [], _ => [],
}; };
@ -616,8 +618,7 @@ public class AutoDesignManager : ISavable, IReadOnlyList<AutoDesignSet>, IDispos
}; };
return table.Where(kvp => kvp.Value == name) return table.Where(kvp => kvp.Value == name)
.Select(kvp => manager.CreateIndividualUnchecked(identifier.Type, identifier.PlayerName, identifier.HomeWorld.Id, .Select(kvp => manager.CreateIndividualUnchecked(identifier.Type, identifier.PlayerName, identifier.HomeWorld.Id,
identifier.Kind, identifier.Kind, kvp.Key)).ToArray();
kvp.Key)).ToArray();
} }
} }

View file

@ -20,6 +20,7 @@ public class IdentifierDrawer
public ActorIdentifier PlayerIdentifier { get; private set; } = ActorIdentifier.Invalid; public ActorIdentifier PlayerIdentifier { get; private set; } = ActorIdentifier.Invalid;
public ActorIdentifier RetainerIdentifier { get; private set; } = ActorIdentifier.Invalid; public ActorIdentifier RetainerIdentifier { get; private set; } = ActorIdentifier.Invalid;
public ActorIdentifier MannequinIdentifier { get; private set; } = ActorIdentifier.Invalid; public ActorIdentifier MannequinIdentifier { get; private set; } = ActorIdentifier.Invalid;
public ActorIdentifier OwnedIdentifier { get; private set; } = ActorIdentifier.Invalid;
public IdentifierDrawer(ActorManager actors, DictWorld dictWorld, DictModelChara dictModelChara, DictBNpcNames bNpcNames, DictBNpc bNpc, public IdentifierDrawer(ActorManager actors, DictWorld dictWorld, DictModelChara dictModelChara, DictBNpcNames bNpcNames, DictBNpc bNpc,
HumanModelList humans) HumanModelList humans)
@ -60,6 +61,9 @@ public class IdentifierDrawer
public bool CanSetNpc public bool CanSetNpc
=> NpcIdentifier.IsValid; => NpcIdentifier.IsValid;
public bool CanSetOwned
=> OwnedIdentifier.IsValid;
private void UpdateIdentifiers() private void UpdateIdentifiers()
{ {
if (ByteString.FromString(_characterName, out var byteName)) if (ByteString.FromString(_characterName, out var byteName))
@ -67,6 +71,11 @@ public class IdentifierDrawer
PlayerIdentifier = _actors.CreatePlayer(byteName, _worldCombo.CurrentSelection.Key); PlayerIdentifier = _actors.CreatePlayer(byteName, _worldCombo.CurrentSelection.Key);
RetainerIdentifier = _actors.CreateRetainer(byteName, ActorIdentifier.RetainerType.Bell); RetainerIdentifier = _actors.CreateRetainer(byteName, ActorIdentifier.RetainerType.Bell);
MannequinIdentifier = _actors.CreateRetainer(byteName, ActorIdentifier.RetainerType.Mannequin); MannequinIdentifier = _actors.CreateRetainer(byteName, ActorIdentifier.RetainerType.Mannequin);
if (_humanNpcCombo.CurrentSelection.Kind is ObjectKind.EventNpc or ObjectKind.BattleNpc)
OwnedIdentifier = _actors.CreateOwned(byteName, _worldCombo.CurrentSelection.Key, _humanNpcCombo.CurrentSelection.Kind, _humanNpcCombo.CurrentSelection.Ids[0]);
else
OwnedIdentifier = ActorIdentifier.Invalid;
} }
NpcIdentifier = _humanNpcCombo.CurrentSelection.Kind is ObjectKind.EventNpc or ObjectKind.BattleNpc NpcIdentifier = _humanNpcCombo.CurrentSelection.Kind is ObjectKind.EventNpc or ObjectKind.BattleNpc

View file

@ -10,6 +10,7 @@ using ImGuiNET;
using OtterGui; using OtterGui;
using OtterGui.Log; using OtterGui.Log;
using OtterGui.Raii; using OtterGui.Raii;
using OtterGui.Text;
using OtterGui.Widgets; using OtterGui.Widgets;
using Penumbra.GameData.Enums; using Penumbra.GameData.Enums;
using Penumbra.GameData.Structs; using Penumbra.GameData.Structs;
@ -424,22 +425,26 @@ public class SetPanel(
private void DrawIdentifierSelection(int setIndex) private void DrawIdentifierSelection(int setIndex)
{ {
using var id = ImRaii.PushId("Identifiers"); using var id = ImUtf8.PushId("Identifiers"u8);
_identifierDrawer.DrawWorld(130); _identifierDrawer.DrawWorld(130);
ImGui.SameLine(); ImGui.SameLine();
_identifierDrawer.DrawName(200 - ImGui.GetStyle().ItemSpacing.X); _identifierDrawer.DrawName(200 - ImGui.GetStyle().ItemSpacing.X);
_identifierDrawer.DrawNpcs(330); _identifierDrawer.DrawNpcs(330);
var buttonWidth = new Vector2(165 * ImGuiHelpers.GlobalScale - ImGui.GetStyle().ItemSpacing.X / 2, 0); var buttonWidth = new Vector2(165 * ImGuiHelpers.GlobalScale - ImGui.GetStyle().ItemSpacing.X / 2, 0);
if (ImGuiUtil.DrawDisabledButton("Set to Character", buttonWidth, string.Empty, !_identifierDrawer.CanSetPlayer)) if (ImUtf8.ButtonEx("Set to Character"u8, string.Empty, buttonWidth, !_identifierDrawer.CanSetPlayer))
_manager.ChangeIdentifier(setIndex, _identifierDrawer.PlayerIdentifier); _manager.ChangeIdentifier(setIndex, _identifierDrawer.PlayerIdentifier);
ImGui.SameLine(); ImGui.SameLine();
if (ImGuiUtil.DrawDisabledButton("Set to NPC", buttonWidth, string.Empty, !_identifierDrawer.CanSetNpc)) if (ImUtf8.ButtonEx("Set to NPC"u8, string.Empty, buttonWidth, !_identifierDrawer.CanSetNpc))
_manager.ChangeIdentifier(setIndex, _identifierDrawer.NpcIdentifier); _manager.ChangeIdentifier(setIndex, _identifierDrawer.NpcIdentifier);
if (ImGuiUtil.DrawDisabledButton("Set to Retainer", buttonWidth, string.Empty, !_identifierDrawer.CanSetRetainer))
if (ImUtf8.ButtonEx("Set to Retainer"u8, string.Empty, buttonWidth, !_identifierDrawer.CanSetRetainer))
_manager.ChangeIdentifier(setIndex, _identifierDrawer.RetainerIdentifier); _manager.ChangeIdentifier(setIndex, _identifierDrawer.RetainerIdentifier);
ImGui.SameLine(); ImGui.SameLine();
if (ImGuiUtil.DrawDisabledButton("Set to Mannequin", buttonWidth, string.Empty, !_identifierDrawer.CanSetRetainer)) if (ImUtf8.ButtonEx("Set to Mannequin"u8, string.Empty, buttonWidth, !_identifierDrawer.CanSetRetainer))
_manager.ChangeIdentifier(setIndex, _identifierDrawer.MannequinIdentifier); _manager.ChangeIdentifier(setIndex, _identifierDrawer.MannequinIdentifier);
if (ImUtf8.ButtonEx("Set to Owned NPC"u8, string.Empty, buttonWidth, !_identifierDrawer.CanSetOwned))
_manager.ChangeIdentifier(setIndex, _identifierDrawer.OwnedIdentifier);
} }
private sealed class JobGroupCombo(AutoDesignManager manager, JobService jobs, Logger log) private sealed class JobGroupCombo(AutoDesignManager manager, JobService jobs, Logger log)