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

@ -55,11 +55,18 @@ internal sealed class CharacterSwitch : IDisposable
{
unsafe
{
UIInputData* uiInputData = UIInputData.Instance();
MouseButtonFlags mouseButtonFlags =
uiInputData != null ? uiInputData->MouseButtonReleasedFlags : MouseButtonFlags.LBUTTON;
var target = FindCharacter(mouseButtonFlags.HasFlag(MouseButtonFlags.RBUTTON) ? -1 : 1);
SwitchCharacter(target);
uint? homeWorldId = _clientState.LocalPlayer?.HomeWorld.Id;
uint? currentWorldId = _clientState.LocalPlayer?.CurrentWorld.Id;
if (homeWorldId == currentWorldId)
{
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()
{
string? currentWorld = _clientState.LocalPlayer?.CurrentWorld.GameData?.Name?.ToString();
string? homeWorld = _clientState.LocalPlayer?.HomeWorld.GameData?.Name?.ToString();
var characterIds = _autoRetainerApi.GetRegisteredCharacters() ?? new();
var characterIdsOnCurrentWorld = characterIds
.Where(x => _autoRetainerApi.GetOfflineCharacterData(x)?.World == currentWorld).ToList();
var characterIdsOnHomeWorld = characterIds
.Where(x => _autoRetainerApi.GetOfflineCharacterData(x)?.World == homeWorld).ToList();
SeIconChar seIconChar = SeIconChar.Instance1 + characterIdsOnCurrentWorld.IndexOf(_clientState.LocalContentId);
_dtrBarEntry.Text = seIconChar.ToIconString();
SeIconChar seIconChar = SeIconChar.Instance1 + characterIdsOnHomeWorld.IndexOf(_clientState.LocalContentId);
if (currentWorld == homeWorld)
{
_dtrBarEntry.Text = seIconChar.ToIconString();
var previous = FindCharacter(-1);
var next = FindCharacter(1);
if (previous != null && next != null)
_dtrBarEntry.Tooltip = $"Prev: {previous.Name}\nNext: {next.Name}";
else if (previous != null)
_dtrBarEntry.Tooltip = $"Prev: {previous.Name}";
else if (next != null)
_dtrBarEntry.Tooltip = $"Next: {next.Name}";
var previous = FindCharacter(-1);
var next = FindCharacter(1);
if (previous != null && next != null)
_dtrBarEntry.Tooltip = $"Prev: {previous.Name}\nNext: {next.Name}";
else if (previous != null)
_dtrBarEntry.Tooltip = $"Prev: {previous.Name}";
else if (next != null)
_dtrBarEntry.Tooltip = $"Next: {next.Name}";
else
_dtrBarEntry.Tooltip = null;
}
else
_dtrBarEntry.Tooltip = null;
{
_dtrBarEntry.Text = $"{homeWorld} {seIconChar.ToIconString()}";
_dtrBarEntry.Tooltip = $"Return to {homeWorld}";
}
}
public void Dispose()

View File

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

View File

@ -4,5 +4,6 @@
"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.",
"Tags": ["character switch"],
"RepoUrl": "https://git.carvel.li/liza/KitchenSink",
"IconUrl": "https://plugins.carvel.li/icons/KitchenSink.png"
}