Add some options to which special actors use which character collection and fix Inspect Actor recognition.

This commit is contained in:
Ottermandias 2022-06-04 00:54:01 +02:00
parent 4b58213597
commit c0102368c3
3 changed files with 72 additions and 7 deletions

View file

@ -21,6 +21,13 @@ public partial class Configuration : IPluginConfiguration
public bool HideUiInCutscenes { get; set; } = true; public bool HideUiInCutscenes { get; set; } = true;
public bool HideUiWhenUiHidden { get; set; } = false; public bool HideUiWhenUiHidden { get; set; } = false;
public bool UseCharacterCollectionInMainWindow { get; set; } = true;
public bool UseCharacterCollectionsInCards { get; set; } = true;
public bool UseCharacterCollectionInInspect { get; set; } = true;
public bool UseCharacterCollectionInTryOn { get; set; } = true;
public bool UseOwnerNameForCharacterCollection { get; set; } = true;
public bool PreferNamedCollectionsOverOwners { get; set; } = false;
#if DEBUG #if DEBUG
public bool DebugMode { get; set; } = true; public bool DebugMode { get; set; } = true;
#else #else

View file

@ -125,6 +125,11 @@ public unsafe partial class PathResolver
// Obtain the name of the inspect target from its window, if it exists. // Obtain the name of the inspect target from its window, if it exists.
private static string? GetInspectName() private static string? GetInspectName()
{ {
if( !Penumbra.Config.UseCharacterCollectionInInspect )
{
return null;
}
var addon = Dalamud.GameGui.GetAddonByName( "CharacterInspect", 1 ); var addon = Dalamud.GameGui.GetAddonByName( "CharacterInspect", 1 );
if( addon == IntPtr.Zero ) if( addon == IntPtr.Zero )
{ {
@ -137,13 +142,23 @@ public unsafe partial class PathResolver
return null; return null;
} }
var text = ( AtkTextNode* )ui->UldManager.NodeList[ 60 ]; var text = ( AtkTextNode* )ui->UldManager.NodeList[ 59 ];
if( text == null || !text->AtkResNode.IsVisible )
{
text = ( AtkTextNode* )ui->UldManager.NodeList[ 60 ];
}
return text != null ? text->NodeText.ToString() : null; return text != null ? text->NodeText.ToString() : null;
} }
// Obtain the name displayed in the Character Card from the agent. // Obtain the name displayed in the Character Card from the agent.
private static string? GetCardName() private static string? GetCardName()
{ {
if( !Penumbra.Config.UseCharacterCollectionsInCards )
{
return null;
}
var uiModule = ( UIModule* )Dalamud.GameGui.GetUIModule(); var uiModule = ( UIModule* )Dalamud.GameGui.GetUIModule();
var agentModule = uiModule->GetAgentModule(); var agentModule = uiModule->GetAgentModule();
var agent = ( byte* )agentModule->GetAgentByInternalID( 393 ); var agent = ( byte* )agentModule->GetAgentByInternalID( 393 );
@ -165,6 +180,11 @@ public unsafe partial class PathResolver
// Obtain the name of the player character if the glamour plate edit window is open. // Obtain the name of the player character if the glamour plate edit window is open.
private static string? GetGlamourName() private static string? GetGlamourName()
{ {
if( !Penumbra.Config.UseCharacterCollectionInTryOn )
{
return null;
}
var addon = Dalamud.GameGui.GetAddonByName( "MiragePrismMiragePlate", 1 ); var addon = Dalamud.GameGui.GetAddonByName( "MiragePrismMiragePlate", 1 );
return addon == IntPtr.Zero ? null : GetPlayerName(); return addon == IntPtr.Zero ? null : GetPlayerName();
} }
@ -193,6 +213,11 @@ public unsafe partial class PathResolver
// Monsters with a owner use that owner if it exists. // Monsters with a owner use that owner if it exists.
private static string? GetOwnerName( GameObject* gameObject ) private static string? GetOwnerName( GameObject* gameObject )
{ {
if( !Penumbra.Config.UseOwnerNameForCharacterCollection )
{
return null;
}
GameObject* owner = null; GameObject* owner = null;
if( ( ObjectKind )gameObject->GetObjectKind() is ObjectKind.Companion or ObjectKind.MountType && gameObject->ObjectIndex > 0 ) if( ( ObjectKind )gameObject->GetObjectKind() is ObjectKind.Companion or ObjectKind.MountType && gameObject->ObjectIndex > 0 )
{ {
@ -219,17 +244,30 @@ public unsafe partial class PathResolver
return Penumbra.CollectionManager.Default; return Penumbra.CollectionManager.Default;
} }
var name = gameObject->ObjectIndex switch string? actorName = null;
if( Penumbra.Config.PreferNamedCollectionsOverOwners )
{ {
240 => GetPlayerName(), // character window // Early return if we prefer the actors own name over its owner.
actorName = new Utf8String( gameObject->Name ).ToString();
if( actorName.Length > 0 && Penumbra.CollectionManager.Characters.TryGetValue( actorName, out var actorCollection ) )
{
return actorCollection;
}
}
// All these special cases are relevant for an empty name, so never collide with the above setting.
// Only OwnerName can be applied to something with a non-empty name, and that is the specific case we want to handle.
var actualName = gameObject->ObjectIndex switch
{
240 => Penumbra.Config.UseCharacterCollectionInMainWindow ? GetPlayerName() : null, // character window
241 => GetInspectName() ?? GetCardName() ?? GetGlamourName(), // inspect, character card, glamour plate editor. 241 => GetInspectName() ?? GetCardName() ?? GetGlamourName(), // inspect, character card, glamour plate editor.
242 => GetPlayerName(), // try-on 242 => Penumbra.Config.UseCharacterCollectionInTryOn ? GetPlayerName() : null, // try-on
>= 200 => GetCutsceneName( gameObject ), >= 200 => GetCutsceneName( gameObject ),
_ => null, _ => null,
} }
?? GetOwnerName( gameObject ) ?? new Utf8String( gameObject->Name ).ToString(); ?? GetOwnerName( gameObject ) ?? actorName ?? new Utf8String( gameObject->Name ).ToString();
return Penumbra.CollectionManager.Character( name ); return Penumbra.CollectionManager.Character( actualName );
} }
// Update collections linked to Game/DrawObjects due to a change in collection configuration. // Update collections linked to Game/DrawObjects due to a change in collection configuration.

View file

@ -56,6 +56,26 @@ public partial class ConfigWindow
Dalamud.PluginInterface.UiBuilder.DisableGposeUiHide = !v; Dalamud.PluginInterface.UiBuilder.DisableGposeUiHide = !v;
} ); } );
ImGui.Dummy( _window._defaultSpace ); ImGui.Dummy( _window._defaultSpace );
Checkbox( "Use Character Collections in Character Window",
"Use the character collection for your character's name in your main character window, if it is set.",
Penumbra.Config.UseCharacterCollectionInMainWindow, v => Penumbra.Config.UseCharacterCollectionInMainWindow = v );
Checkbox( "Use Character Collections in Adventurer Cards",
"Use the appropriate character collection for the adventurer card you are currently looking at, based on the adventurer's name.",
Penumbra.Config.UseCharacterCollectionsInCards, v => Penumbra.Config.UseCharacterCollectionsInCards = v );
Checkbox( "Use Character Collections in Try-On Window",
"Use the character collection for your character's name in your try-on window, if it is set.",
Penumbra.Config.UseCharacterCollectionInTryOn, v => Penumbra.Config.UseCharacterCollectionInTryOn = v );
Checkbox( "Use Character Collections in Inspect Windows",
"Use the appropriate character collection for the character you are currently inspecting, based on their name.",
Penumbra.Config.UseCharacterCollectionInInspect, v => Penumbra.Config.UseCharacterCollectionInInspect = v );
Checkbox( "Use Character Collections based on Ownership",
"Use the owner's name to determine the appropriate character collection for mounts, companions and combat pets.",
Penumbra.Config.UseOwnerNameForCharacterCollection, v => Penumbra.Config.UseOwnerNameForCharacterCollection = v );
Checkbox( "Prefer Named Collections over Ownership",
"If you have a character collection set to a specific name for a companion or combat pet, prefer this collection over the owner's collection.\n"
+ "That is, if you have a 'Topaz Carbuncle' collection, it will use this one instead of the one for its owner.",
Penumbra.Config.PreferNamedCollectionsOverOwners, v => Penumbra.Config.PreferNamedCollectionsOverOwners = v );
ImGui.Dummy( _window._defaultSpace );
DrawFolderSortType(); DrawFolderSortType();
DrawAbsoluteSizeSelector(); DrawAbsoluteSizeSelector();
DrawRelativeSizeSelector(); DrawRelativeSizeSelector();