Handle/fix DTR bar when not on homeworld

master v0.2
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

@ -55,11 +55,18 @@ internal sealed class CharacterSwitch : IDisposable
{ {
unsafe unsafe
{ {
UIInputData* uiInputData = UIInputData.Instance(); uint? homeWorldId = _clientState.LocalPlayer?.HomeWorld.Id;
MouseButtonFlags mouseButtonFlags = uint? currentWorldId = _clientState.LocalPlayer?.CurrentWorld.Id;
uiInputData != null ? uiInputData->MouseButtonReleasedFlags : MouseButtonFlags.LBUTTON; if (homeWorldId == currentWorldId)
var target = FindCharacter(mouseButtonFlags.HasFlag(MouseButtonFlags.RBUTTON) ? -1 : 1); {
SwitchCharacter(target); UIInputData* uiInputData = UIInputData.Instance();
MouseButtonFlags mouseButtonFlags =
uiInputData != null ? uiInputData->MouseButtonReleasedFlags : MouseButtonFlags.LBUTTON;
var target = FindCharacter(mouseButtonFlags.HasFlag(MouseButtonFlags.RBUTTON) ? -1 : 1);
SwitchCharacter(target);
}
else
_commandManager.ProcessCommand("/li");
} }
}; };
@ -167,23 +174,32 @@ 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);
_dtrBarEntry.Text = seIconChar.ToIconString(); if (currentWorld == homeWorld)
{
_dtrBarEntry.Text = seIconChar.ToIconString();
var previous = FindCharacter(-1); var previous = FindCharacter(-1);
var next = FindCharacter(1); var next = FindCharacter(1);
if (previous != null && next != null) if (previous != null && next != null)
_dtrBarEntry.Tooltip = $"Prev: {previous.Name}\nNext: {next.Name}"; _dtrBarEntry.Tooltip = $"Prev: {previous.Name}\nNext: {next.Name}";
else if (previous != null) else if (previous != null)
_dtrBarEntry.Tooltip = $"Prev: {previous.Name}"; _dtrBarEntry.Tooltip = $"Prev: {previous.Name}";
else if (next != null) else if (next != null)
_dtrBarEntry.Tooltip = $"Next: {next.Name}"; _dtrBarEntry.Tooltip = $"Next: {next.Name}";
else
_dtrBarEntry.Tooltip = null;
}
else else
_dtrBarEntry.Tooltip = null; {
_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"
} }