Handle/fix DTR bar when not on homeworld

This commit is contained in:
Liza 2024-05-01 21:51:20 +02:00
parent 5bbc75f527
commit ccfb53df2e
Signed by: liza
GPG Key ID: 7199F8D727D55F67
3 changed files with 36 additions and 19 deletions

View File

@ -54,6 +54,10 @@ internal sealed class CharacterSwitch : IDisposable
_dtrBarEntry.OnClick = () => _dtrBarEntry.OnClick = () =>
{ {
unsafe unsafe
{
uint? homeWorldId = _clientState.LocalPlayer?.HomeWorld.Id;
uint? currentWorldId = _clientState.LocalPlayer?.CurrentWorld.Id;
if (homeWorldId == currentWorldId)
{ {
UIInputData* uiInputData = UIInputData.Instance(); UIInputData* uiInputData = UIInputData.Instance();
MouseButtonFlags mouseButtonFlags = MouseButtonFlags mouseButtonFlags =
@ -61,6 +65,9 @@ internal sealed class CharacterSwitch : IDisposable
var target = FindCharacter(mouseButtonFlags.HasFlag(MouseButtonFlags.RBUTTON) ? -1 : 1); var target = FindCharacter(mouseButtonFlags.HasFlag(MouseButtonFlags.RBUTTON) ? -1 : 1);
SwitchCharacter(target); SwitchCharacter(target);
} }
else
_commandManager.ProcessCommand("/li");
}
}; };
_clientState.Login += UpdateDtrBar; _clientState.Login += UpdateDtrBar;
@ -167,11 +174,14 @@ internal sealed class CharacterSwitch : IDisposable
private void UpdateDtrBar() private void UpdateDtrBar()
{ {
string? currentWorld = _clientState.LocalPlayer?.CurrentWorld.GameData?.Name?.ToString(); string? currentWorld = _clientState.LocalPlayer?.CurrentWorld.GameData?.Name?.ToString();
string? homeWorld = _clientState.LocalPlayer?.HomeWorld.GameData?.Name?.ToString();
var characterIds = _autoRetainerApi.GetRegisteredCharacters() ?? new(); var characterIds = _autoRetainerApi.GetRegisteredCharacters() ?? new();
var characterIdsOnCurrentWorld = characterIds var characterIdsOnHomeWorld = characterIds
.Where(x => _autoRetainerApi.GetOfflineCharacterData(x)?.World == currentWorld).ToList(); .Where(x => _autoRetainerApi.GetOfflineCharacterData(x)?.World == homeWorld).ToList();
SeIconChar seIconChar = SeIconChar.Instance1 + characterIdsOnCurrentWorld.IndexOf(_clientState.LocalContentId); SeIconChar seIconChar = SeIconChar.Instance1 + characterIdsOnHomeWorld.IndexOf(_clientState.LocalContentId);
if (currentWorld == homeWorld)
{
_dtrBarEntry.Text = seIconChar.ToIconString(); _dtrBarEntry.Text = seIconChar.ToIconString();
var previous = FindCharacter(-1); var previous = FindCharacter(-1);
@ -185,6 +195,12 @@ internal sealed class CharacterSwitch : IDisposable
else else
_dtrBarEntry.Tooltip = null; _dtrBarEntry.Tooltip = null;
} }
else
{
_dtrBarEntry.Text = $"{homeWorld} {seIconChar.ToIconString()}";
_dtrBarEntry.Tooltip = $"Return to {homeWorld}";
}
}
public void Dispose() public void Dispose()
{ {

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework> <TargetFramework>net8.0-windows</TargetFramework>
<Version>0.1</Version> <Version>0.2</Version>
<LangVersion>12</LangVersion> <LangVersion>12</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

View File

@ -4,5 +4,6 @@
"Punchline": "A plugin for things that aren't worth their own plugins.", "Punchline": "A plugin for things that aren't worth their own plugins.",
"Description": "A plugin for things that aren't worth their own plugins; see commands for details.", "Description": "A plugin for things that aren't worth their own plugins; see commands for details.",
"Tags": ["character switch"], "Tags": ["character switch"],
"RepoUrl": "https://git.carvel.li/liza/KitchenSink",
"IconUrl": "https://plugins.carvel.li/icons/KitchenSink.png" "IconUrl": "https://plugins.carvel.li/icons/KitchenSink.png"
} }