Just some formatting

This commit is contained in:
Infi
2024-04-25 20:26:39 +02:00
parent 60bfefd359
commit 8e006f8ab5
3 changed files with 129 additions and 129 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<Version>1.22.2</Version> <Version>1.23.0</Version>
<TargetFramework>net8.0-windows</TargetFramework> <TargetFramework>net8.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
+5 -5
View File
@@ -154,10 +154,10 @@ internal sealed unsafe class Chat : IDisposable
private Plugin Plugin { get; } private Plugin Plugin { get; }
/// <summary> /// <summary>
/// Holds the current game channel details. `tellplayerName` and /// Holds the current game channel details.
/// `tellWorldId` are only set when the channel is `InputChannel.Tell`. /// `TellPlayerName` and `TellWorldId` are only set when the channel is `InputChannel.Tell`.
/// </summary> /// </summary>
internal (InputChannel channel, List<Chunk> name, string? tellPlayerName, ushort tellWorldId) Channel { get; private set; } internal (InputChannel Channel, List<Chunk> Name, string? TellPlayerName, ushort TellWorldId) Channel { get; private set; }
internal bool UsesTellTempChannel { get; set; } internal bool UsesTellTempChannel { get; set; }
internal InputChannel? PreviousChannel { get; private set; } internal InputChannel? PreviousChannel { get; private set; }
@@ -613,7 +613,7 @@ internal sealed unsafe class Chat : IDisposable
if (!UsesTellTempChannel) if (!UsesTellTempChannel)
{ {
UsesTellTempChannel = true; UsesTellTempChannel = true;
PreviousChannel = Channel.channel; PreviousChannel = Channel.Channel;
} }
if (SetChannelTargetTell != null) if (SetChannelTargetTell != null)
@@ -660,7 +660,7 @@ internal sealed unsafe class Chat : IDisposable
if (!UsesTellTempChannel) if (!UsesTellTempChannel)
{ {
UsesTellTempChannel = true; UsesTellTempChannel = true;
PreviousChannel = Channel.channel; PreviousChannel = Channel.Channel;
} }
var utfName = Utf8String.FromString(name); var utfName = Utf8String.FromString(name);
+123 -123
View File
@@ -50,40 +50,40 @@ public sealed class ChatLogWindow : Window
} }
internal bool Activate; internal bool Activate;
private int _activatePos = -1; private int ActivatePos = -1;
internal string Chat = string.Empty; internal string Chat = string.Empty;
private readonly IDalamudTextureWrap? _fontIcon; private readonly IDalamudTextureWrap? FontIcon;
private readonly List<string> _inputBacklog = []; private readonly List<string> InputBacklog = [];
private int _inputBacklogIdx = -1; private int InputBacklogIdx = -1;
private int LastTab { get; set; } private int LastTab { get; set; }
private InputChannel? _tempChannel; private InputChannel? TempChannel;
private TellTarget? _tellTarget; private TellTarget? TellTarget;
private readonly Stopwatch _lastResize = new(); private readonly Stopwatch LastResize = new();
private AutoCompleteInfo? _autoCompleteInfo; private AutoCompleteInfo? AutoCompleteInfo;
private bool _autoCompleteOpen; private bool AutoCompleteOpen;
private List<AutoTranslateEntry>? _autoCompleteList; private List<AutoTranslateEntry>? AutoCompleteList;
private bool _fixCursor; private bool FixCursor;
private int _autoCompleteSelection; private int AutoCompleteSelection;
private bool _autoCompleteShouldScroll; private bool AutoCompleteShouldScroll;
public Vector2 LastWindowPos { get; private set; } = Vector2.Zero; public Vector2 LastWindowPos { get; private set; } = Vector2.Zero;
public Vector2 LastWindowSize { get; private set; } = Vector2.Zero; public Vector2 LastWindowSize { get; private set; } = Vector2.Zero;
public unsafe ImGuiViewport* LastViewport; public unsafe ImGuiViewport* LastViewport;
private bool _wasDocked; private bool WasDocked;
private PayloadHandler PayloadHandler { get; } private PayloadHandler PayloadHandler { get; }
internal Lender<PayloadHandler> HandlerLender { get; } internal Lender<PayloadHandler> HandlerLender { get; }
private Dictionary<string, ChatType> TextCommandChannels { get; } = new(); private Dictionary<string, ChatType> TextCommandChannels { get; } = new();
private HashSet<string> AllCommands { get; } = []; private HashSet<string> AllCommands { get; } = [];
private uint ChatOpenSfx = 35u; private const uint ChatOpenSfx = 35u;
private uint ChatCloseSfx = 3u; private const uint ChatCloseSfx = 3u;
private bool PlayedClosingSound = true; private bool PlayedClosingSound = true;
private ExcelSheet<World> WorldSheet; private readonly ExcelSheet<World> WorldSheet;
private ExcelSheet<LogFilter> LogFilterSheet; private readonly ExcelSheet<LogFilter> LogFilterSheet;
private ExcelSheet<TextCommand> TextCommandSheet; private readonly ExcelSheet<TextCommand> TextCommandSheet;
internal ChatLogWindow(Plugin plugin) : base($"{Plugin.PluginName}###chat2") internal ChatLogWindow(Plugin plugin) : base($"{Plugin.PluginName}###chat2")
{ {
@@ -109,7 +109,7 @@ public sealed class ChatLogWindow : Window
WorldSheet = Plugin.DataManager.GetExcelSheet<World>()!; WorldSheet = Plugin.DataManager.GetExcelSheet<World>()!;
LogFilterSheet = Plugin.DataManager.GetExcelSheet<LogFilter>()!; LogFilterSheet = Plugin.DataManager.GetExcelSheet<LogFilter>()!;
TextCommandSheet = Plugin.DataManager.GetExcelSheet<TextCommand>()!; TextCommandSheet = Plugin.DataManager.GetExcelSheet<TextCommand>()!;
_fontIcon = Plugin.TextureProvider.GetTextureFromGame("common/font/fonticon_ps5.tex"); FontIcon = Plugin.TextureProvider.GetTextureFromGame("common/font/fonticon_ps5.tex");
Plugin.Functions.Chat.Activated += Activated; Plugin.Functions.Chat.Activated += Activated;
Plugin.ClientState.Login += Login; Plugin.ClientState.Login += Login;
@@ -136,7 +136,7 @@ public sealed class ChatLogWindow : Window
Plugin.ClientState.Logout -= Logout; Plugin.ClientState.Logout -= Logout;
Plugin.ClientState.Login -= Login; Plugin.ClientState.Login -= Login;
Plugin.Functions.Chat.Activated -= Activated; Plugin.Functions.Chat.Activated -= Activated;
_fontIcon?.Dispose(); FontIcon?.Dispose();
Plugin.Commands.Register("/chat2").Execute -= ToggleChat; Plugin.Commands.Register("/chat2").Execute -= ToggleChat;
Plugin.Commands.Register("/clearlog2").Execute -= ClearLog; Plugin.Commands.Register("/clearlog2").Execute -= ClearLog;
} }
@@ -165,11 +165,11 @@ public sealed class ChatLogWindow : Window
if (info.Channel != null) if (info.Channel != null)
{ {
var prevTemp = _tempChannel; var prevTemp = TempChannel;
if (info.Permanent) if (info.Permanent)
SetChannel(info.Channel.Value); SetChannel(info.Channel.Value);
else else
_tempChannel = info.Channel.Value; TempChannel = info.Channel.Value;
if (info.Channel is InputChannel.Tell) if (info.Channel is InputChannel.Tell)
{ {
@@ -181,18 +181,18 @@ public sealed class ChatLogWindow : Window
var tellInfo = Plugin.Functions.Chat.GetTellHistoryInfo(idx); var tellInfo = Plugin.Functions.Chat.GetTellHistoryInfo(idx);
if (tellInfo != null && reason != null) if (tellInfo != null && reason != null)
_tellTarget = new TellTarget(tellInfo.Name, (ushort) tellInfo.World, tellInfo.ContentId, reason.Value); TellTarget = new TellTarget(tellInfo.Name, (ushort) tellInfo.World, tellInfo.ContentId, reason.Value);
} }
else else
{ {
_tellTarget = null; TellTarget = null;
if (target != null) if (target != null)
_tellTarget = target; TellTarget = target;
} }
} }
else else
{ {
_tellTarget = null; TellTarget = null;
} }
var mode = prevTemp == null ? RotateMode.None : info.Rotate; var mode = prevTemp == null ? RotateMode.None : info.Rotate;
@@ -200,12 +200,12 @@ public sealed class ChatLogWindow : Window
if (info.Channel is InputChannel.Linkshell1 && info.Rotate != RotateMode.None) if (info.Channel is InputChannel.Linkshell1 && info.Rotate != RotateMode.None)
{ {
var idx = Plugin.Functions.Chat.RotateLinkshellHistory(mode); var idx = Plugin.Functions.Chat.RotateLinkshellHistory(mode);
_tempChannel = info.Channel.Value + (uint) idx; TempChannel = info.Channel.Value + (uint) idx;
} }
else if (info.Channel is InputChannel.CrossLinkshell1 && info.Rotate != RotateMode.None) else if (info.Channel is InputChannel.CrossLinkshell1 && info.Rotate != RotateMode.None)
{ {
var idx = Plugin.Functions.Chat.RotateCrossLinkshellHistory(mode); var idx = Plugin.Functions.Chat.RotateCrossLinkshellHistory(mode);
_tempChannel = info.Channel.Value + (uint) idx; TempChannel = info.Channel.Value + (uint) idx;
} }
} }
@@ -315,16 +315,16 @@ public sealed class ChatLogWindow : Window
private void AddBacklog(string message) private void AddBacklog(string message)
{ {
for (var i = 0; i < _inputBacklog.Count; i++) for (var i = 0; i < InputBacklog.Count; i++)
{ {
if (_inputBacklog[i] != message) if (InputBacklog[i] != message)
continue; continue;
_inputBacklog.RemoveAt(i); InputBacklog.RemoveAt(i);
break; break;
} }
_inputBacklog.Add(message); InputBacklog.Add(message);
} }
private static float GetRemainingHeightForMessageLog() private static float GetRemainingHeightForMessageLog()
@@ -397,12 +397,12 @@ public sealed class ChatLogWindow : Window
// Save the previous channel to restore it later // Save the previous channel to restore it later
var current = CurrentTab; var current = CurrentTab;
if (current is { Channel: null }) if (current is { Channel: null })
current.PreviousChannel = Plugin.Functions.Chat.Channel.channel; current.PreviousChannel = Plugin.Functions.Chat.Channel.Channel;
// Channel will be null if PreviousChannel is used // Channel will be null if PreviousChannel is used
var channel = tab.Channel ?? tab.PreviousChannel; var channel = tab.Channel ?? tab.PreviousChannel;
// Channel being null it doesn't have a default, and we never selected this channel before // If channel is null it doesn't have a default, and we never selected this channel before
if (channel != null) if (channel != null)
SetChannel(tab.Channel ?? tab.PreviousChannel); SetChannel(tab.Channel ?? tab.PreviousChannel);
} }
@@ -460,11 +460,11 @@ public sealed class ChatLogWindow : Window
if (!Plugin.Config.ShowTitleBar) if (!Plugin.Config.ShowTitleBar)
Flags |= ImGuiWindowFlags.NoTitleBar; Flags |= ImGuiWindowFlags.NoTitleBar;
if (LastViewport == ImGuiHelpers.MainViewport.NativePtr && !_wasDocked) if (LastViewport == ImGuiHelpers.MainViewport.NativePtr && !WasDocked)
BgAlpha = Plugin.Config.WindowAlpha / 100f; BgAlpha = Plugin.Config.WindowAlpha / 100f;
LastViewport = ImGui.GetWindowViewport().NativePtr; LastViewport = ImGui.GetWindowViewport().NativePtr;
_wasDocked = ImGui.IsWindowDocked(); WasDocked = ImGui.IsWindowDocked();
} }
public override bool DrawConditions() public override bool DrawConditions()
@@ -487,10 +487,10 @@ public sealed class ChatLogWindow : Window
LastWindowPos = ImGui.GetWindowPos(); LastWindowPos = ImGui.GetWindowPos();
if (resized) if (resized)
_lastResize.Restart(); LastResize.Restart();
LastViewport = ImGui.GetWindowViewport().NativePtr; LastViewport = ImGui.GetWindowViewport().NativePtr;
_wasDocked = ImGui.IsWindowDocked(); WasDocked = ImGui.IsWindowDocked();
var currentTab = Plugin.Config.SidebarTabView ? DrawTabSidebar() : DrawTabBar(); var currentTab = Plugin.Config.SidebarTabView ? DrawTabSidebar() : DrawTabBar();
@@ -500,12 +500,12 @@ public sealed class ChatLogWindow : Window
using (ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, Vector2.Zero)) using (ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, Vector2.Zero))
{ {
if (_tellTarget != null) if (TellTarget != null)
{ {
var playerName = _tellTarget.Name; var playerName = TellTarget.Name;
if (ScreenshotMode) if (ScreenshotMode)
playerName = HashPlayer(_tellTarget.Name, _tellTarget.World); playerName = HashPlayer(TellTarget.Name, TellTarget.World);
var world = WorldSheet.GetRow(_tellTarget.World)?.Name?.RawString ?? "???"; var world = WorldSheet.GetRow(TellTarget.World)?.Name?.RawString ?? "???";
DrawChunks(new Chunk[] DrawChunks(new Chunk[]
{ {
@@ -515,23 +515,23 @@ public sealed class ChatLogWindow : Window
new TextChunk(ChunkSource.None, null, world), new TextChunk(ChunkSource.None, null, world),
}); });
} }
else if (_tempChannel != null) else if (TempChannel != null)
{ {
if (_tempChannel.Value.IsLinkshell()) if (TempChannel.Value.IsLinkshell())
{ {
var idx = (uint) _tempChannel.Value - (uint) InputChannel.Linkshell1; var idx = (uint) TempChannel.Value - (uint) InputChannel.Linkshell1;
var lsName = Plugin.Functions.Chat.GetLinkshellName(idx); var lsName = Plugin.Functions.Chat.GetLinkshellName(idx);
ImGui.TextUnformatted($"LS #{idx + 1}: {lsName}"); ImGui.TextUnformatted($"LS #{idx + 1}: {lsName}");
} }
else if (_tempChannel.Value.IsCrossLinkshell()) else if (TempChannel.Value.IsCrossLinkshell())
{ {
var idx = (uint) _tempChannel.Value - (uint) InputChannel.CrossLinkshell1; var idx = (uint) TempChannel.Value - (uint) InputChannel.CrossLinkshell1;
var cwlsName = Plugin.Functions.Chat.GetCrossLinkshellName(idx); var cwlsName = Plugin.Functions.Chat.GetCrossLinkshellName(idx);
ImGui.TextUnformatted($"CWLS [{idx + 1}]: {cwlsName}"); ImGui.TextUnformatted($"CWLS [{idx + 1}]: {cwlsName}");
} }
else else
{ {
ImGui.TextUnformatted(_tempChannel.Value.ToChatType().Name()); ImGui.TextUnformatted(TempChannel.Value.ToChatType().Name());
} }
} }
else if (activeTab is { Channel: { } channel }) else if (activeTab is { Channel: { } channel })
@@ -572,7 +572,7 @@ public sealed class ChatLogWindow : Window
} }
else else
{ {
DrawChunks(Plugin.Functions.Chat.Channel.name); DrawChunks(Plugin.Functions.Chat.Channel.Name);
} }
} }
@@ -630,7 +630,7 @@ public sealed class ChatLogWindow : Window
var showNovice = Plugin.Config.ShowNoviceNetwork && Plugin.Functions.IsMentor(); var showNovice = Plugin.Config.ShowNoviceNetwork && Plugin.Functions.IsMentor();
var inputWidth = ImGui.GetContentRegionAvail().X - buttonWidth * (showNovice ? 2 : 1); var inputWidth = ImGui.GetContentRegionAvail().X - buttonWidth * (showNovice ? 2 : 1);
var inputType = _tempChannel?.ToChatType() ?? activeTab?.Channel?.ToChatType() ?? Plugin.Functions.Chat.Channel.channel.ToChatType(); var inputType = TempChannel?.ToChatType() ?? activeTab?.Channel?.ToChatType() ?? Plugin.Functions.Chat.Channel.Channel.ToChatType();
var isCommand = Chat.Trim().StartsWith('/'); var isCommand = Chat.Trim().StartsWith('/');
if (isCommand) if (isCommand)
{ {
@@ -691,7 +691,7 @@ public sealed class ChatLogWindow : Window
HandleKeybinds(true); HandleKeybinds(true);
// Only trigger unfocused if we are currently not calling the auto complete // Only trigger unfocused if we are currently not calling the auto complete
if (!Activate && !ImGui.IsItemActive() && _autoCompleteInfo == null) if (!Activate && !ImGui.IsItemActive() && AutoCompleteInfo == null)
{ {
if (Plugin.Config.PlaySounds && !PlayedClosingSound) if (Plugin.Config.PlaySounds && !PlayedClosingSound)
{ {
@@ -699,10 +699,10 @@ public sealed class ChatLogWindow : Window
UIModule.PlaySound(ChatCloseSfx); UIModule.PlaySound(ChatCloseSfx);
} }
if (_tempChannel is InputChannel.Tell) if (TempChannel is InputChannel.Tell)
_tellTarget = null; TellTarget = null;
_tempChannel = null; TempChannel = null;
if (Plugin.Functions.Chat.UsesTellTempChannel) if (Plugin.Functions.Chat.UsesTellTempChannel)
{ {
Plugin.Functions.Chat.UsesTellTempChannel = false; Plugin.Functions.Chat.UsesTellTempChannel = false;
@@ -738,7 +738,7 @@ public sealed class ChatLogWindow : Window
internal void SetChannel(InputChannel? channel) internal void SetChannel(InputChannel? channel)
{ {
channel ??= InputChannel.Say; channel ??= InputChannel.Say;
_tellTarget = null; TellTarget = null;
// Instead of calling SetChannel(), we ask the ExtraChat plugin to set a // Instead of calling SetChannel(), we ask the ExtraChat plugin to set a
// channel override by just calling the command directly. // channel override by just calling the command directly.
@@ -767,13 +767,13 @@ public sealed class ChatLogWindow : Window
{ {
var trimmed = Chat.Trim(); var trimmed = Chat.Trim();
AddBacklog(trimmed); AddBacklog(trimmed);
_inputBacklogIdx = -1; InputBacklogIdx = -1;
if (!trimmed.StartsWith('/')) if (!trimmed.StartsWith('/'))
{ {
if (_tellTarget != null) if (TellTarget != null)
{ {
var target = _tellTarget; var target = TellTarget;
var reason = target.Reason; var reason = target.Reason;
var world = WorldSheet.GetRow(target.World); var world = WorldSheet.GetRow(target.World);
if (world is { IsPublic: true }) if (world is { IsPublic: true })
@@ -787,16 +787,16 @@ public sealed class ChatLogWindow : Window
Plugin.Functions.Chat.SendTell(reason, target.ContentId, target.Name, (ushort) world.RowId, tellBytes); Plugin.Functions.Chat.SendTell(reason, target.ContentId, target.Name, (ushort) world.RowId, tellBytes);
} }
if (_tempChannel is InputChannel.Tell) if (TempChannel is InputChannel.Tell)
_tellTarget = null; TellTarget = null;
Chat = string.Empty; Chat = string.Empty;
return; return;
} }
if (_tempChannel != null) if (TempChannel != null)
trimmed = $"{_tempChannel.Value.Prefix()} {trimmed}"; trimmed = $"{TempChannel.Value.Prefix()} {trimmed}";
else if (activeTab is { Channel: { } channel }) else if (activeTab is { Channel: { } channel })
trimmed = $"{channel.Prefix()} {trimmed}"; trimmed = $"{channel.Prefix()} {trimmed}";
} }
@@ -876,10 +876,10 @@ public sealed class ChatLogWindow : Window
tab.MessagesMutex.Wait(); tab.MessagesMutex.Wait();
var reset = false; var reset = false;
if (_lastResize is { IsRunning: true, Elapsed.TotalSeconds: > 0.25 }) if (LastResize is { IsRunning: true, Elapsed.TotalSeconds: > 0.25 })
{ {
_lastResize.Stop(); LastResize.Stop();
_lastResize.Reset(); LastResize.Reset();
reset = true; reset = true;
} }
@@ -1186,41 +1186,41 @@ public sealed class ChatLogWindow : Window
private unsafe void DrawAutoComplete() private unsafe void DrawAutoComplete()
{ {
if (_autoCompleteInfo == null) if (AutoCompleteInfo == null)
return; return;
_autoCompleteList ??= AutoTranslate.Matching(Plugin.DataManager, _autoCompleteInfo.ToComplete, Plugin.Config.SortAutoTranslate); AutoCompleteList ??= AutoTranslate.Matching(Plugin.DataManager, AutoCompleteInfo.ToComplete, Plugin.Config.SortAutoTranslate);
if (_autoCompleteOpen) if (AutoCompleteOpen)
{ {
ImGui.OpenPopup(AutoCompleteId); ImGui.OpenPopup(AutoCompleteId);
_autoCompleteOpen = false; AutoCompleteOpen = false;
} }
ImGui.SetNextWindowSize(new Vector2(400, 300) * ImGuiHelpers.GlobalScale); ImGui.SetNextWindowSize(new Vector2(400, 300) * ImGuiHelpers.GlobalScale);
using var popup = ImRaii.Popup(AutoCompleteId); using var popup = ImRaii.Popup(AutoCompleteId);
if (!popup.Success) if (!popup.Success)
{ {
if (_activatePos == -1) if (ActivatePos == -1)
_activatePos = _autoCompleteInfo.EndPos; ActivatePos = AutoCompleteInfo.EndPos;
_autoCompleteInfo = null; AutoCompleteInfo = null;
_autoCompleteList = null; AutoCompleteList = null;
Activate = true; Activate = true;
return; return;
} }
ImGui.SetNextItemWidth(-1); ImGui.SetNextItemWidth(-1);
if (ImGui.InputTextWithHint("##auto-complete-filter", Language.AutoTranslate_Search_Hint, ref _autoCompleteInfo.ToComplete, 256, ImGuiInputTextFlags.CallbackAlways | ImGuiInputTextFlags.CallbackHistory, AutoCompleteCallback)) if (ImGui.InputTextWithHint("##auto-complete-filter", Language.AutoTranslate_Search_Hint, ref AutoCompleteInfo.ToComplete, 256, ImGuiInputTextFlags.CallbackAlways | ImGuiInputTextFlags.CallbackHistory, AutoCompleteCallback))
{ {
_autoCompleteList = AutoTranslate.Matching(Plugin.DataManager, _autoCompleteInfo.ToComplete, Plugin.Config.SortAutoTranslate); AutoCompleteList = AutoTranslate.Matching(Plugin.DataManager, AutoCompleteInfo.ToComplete, Plugin.Config.SortAutoTranslate);
_autoCompleteSelection = 0; AutoCompleteSelection = 0;
_autoCompleteShouldScroll = true; AutoCompleteShouldScroll = true;
} }
var selected = -1; var selected = -1;
if (ImGui.IsItemActive() && ImGui.GetIO().KeyCtrl) if (ImGui.IsItemActive() && ImGui.GetIO().KeyCtrl)
{ {
for (var i = 0; i < 10 && i < _autoCompleteList.Count; i++) for (var i = 0; i < 10 && i < AutoCompleteList.Count; i++)
{ {
var num = (i + 1) % 10; var num = (i + 1) % 10;
var key = ImGuiKey._0 + num; var key = ImGuiKey._0 + num;
@@ -1239,13 +1239,13 @@ public sealed class ChatLogWindow : Window
} }
var enter = ImGui.IsKeyDown(ImGuiKey.Enter) || ImGui.IsKeyDown(ImGuiKey.KeypadEnter); var enter = ImGui.IsKeyDown(ImGuiKey.Enter) || ImGui.IsKeyDown(ImGuiKey.KeypadEnter);
if (_autoCompleteList.Count > 0 && enter) if (AutoCompleteList.Count > 0 && enter)
selected = _autoCompleteSelection; selected = AutoCompleteSelection;
} }
if (ImGui.IsWindowAppearing()) if (ImGui.IsWindowAppearing())
{ {
_fixCursor = true; FixCursor = true;
ImGui.SetKeyboardFocusHere(-1); ImGui.SetKeyboardFocusHere(-1);
} }
@@ -1255,14 +1255,14 @@ public sealed class ChatLogWindow : Window
var clipper = new ImGuiListClipperPtr(ImGuiNative.ImGuiListClipper_ImGuiListClipper()); var clipper = new ImGuiListClipperPtr(ImGuiNative.ImGuiListClipper_ImGuiListClipper());
clipper.Begin(_autoCompleteList.Count); clipper.Begin(AutoCompleteList.Count);
while (clipper.Step()) while (clipper.Step())
{ {
for (var i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) for (var i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
{ {
var entry = _autoCompleteList[i]; var entry = AutoCompleteList[i];
var highlight = _autoCompleteSelection == i; var highlight = AutoCompleteSelection == i;
var clicked = ImGui.Selectable($"{entry.String}##{entry.Group}/{entry.Row}", highlight) || selected == i; var clicked = ImGui.Selectable($"{entry.String}##{entry.Group}/{entry.Row}", highlight) || selected == i;
if (i < 10) if (i < 10)
{ {
@@ -1278,53 +1278,53 @@ public sealed class ChatLogWindow : Window
if (!clicked) if (!clicked)
continue; continue;
var before = Chat[.._autoCompleteInfo.StartPos]; var before = Chat[..AutoCompleteInfo.StartPos];
var after = Chat[_autoCompleteInfo.EndPos..]; var after = Chat[AutoCompleteInfo.EndPos..];
var replacement = $"<at:{entry.Group},{entry.Row}>"; var replacement = $"<at:{entry.Group},{entry.Row}>";
Chat = $"{before}{replacement}{after}"; Chat = $"{before}{replacement}{after}";
ImGui.CloseCurrentPopup(); ImGui.CloseCurrentPopup();
Activate = true; Activate = true;
_activatePos = _autoCompleteInfo.StartPos + replacement.Length; ActivatePos = AutoCompleteInfo.StartPos + replacement.Length;
} }
} }
if (!_autoCompleteShouldScroll) if (!AutoCompleteShouldScroll)
return; return;
_autoCompleteShouldScroll = false; AutoCompleteShouldScroll = false;
var selectedPos = clipper.StartPosY + clipper.ItemsHeight * (_autoCompleteSelection * 1f); var selectedPos = clipper.StartPosY + clipper.ItemsHeight * (AutoCompleteSelection * 1f);
ImGui.SetScrollFromPosY(selectedPos - ImGui.GetWindowPos().Y); ImGui.SetScrollFromPosY(selectedPos - ImGui.GetWindowPos().Y);
} }
private unsafe int AutoCompleteCallback(ImGuiInputTextCallbackData* data) private unsafe int AutoCompleteCallback(ImGuiInputTextCallbackData* data)
{ {
if (_fixCursor && _autoCompleteInfo != null) if (FixCursor && AutoCompleteInfo != null)
{ {
_fixCursor = false; FixCursor = false;
data->CursorPos = _autoCompleteInfo.ToComplete.Length; data->CursorPos = AutoCompleteInfo.ToComplete.Length;
data->SelectionStart = data->SelectionEnd = data->CursorPos; data->SelectionStart = data->SelectionEnd = data->CursorPos;
} }
if (_autoCompleteList == null) if (AutoCompleteList == null)
return 0; return 0;
switch (data->EventKey) switch (data->EventKey)
{ {
case ImGuiKey.UpArrow: case ImGuiKey.UpArrow:
if (_autoCompleteSelection == 0) if (AutoCompleteSelection == 0)
_autoCompleteSelection = _autoCompleteList.Count - 1; AutoCompleteSelection = AutoCompleteList.Count - 1;
else else
_autoCompleteSelection--; AutoCompleteSelection--;
_autoCompleteShouldScroll = true; AutoCompleteShouldScroll = true;
return 1; return 1;
case ImGuiKey.DownArrow: case ImGuiKey.DownArrow:
if (_autoCompleteSelection == _autoCompleteList.Count - 1) if (AutoCompleteSelection == AutoCompleteList.Count - 1)
_autoCompleteSelection = 0; AutoCompleteSelection = 0;
else else
_autoCompleteSelection++; AutoCompleteSelection++;
_autoCompleteShouldScroll = true; AutoCompleteShouldScroll = true;
return 1; return 1;
} }
@@ -1345,13 +1345,13 @@ public sealed class ChatLogWindow : Window
{ {
if (ptr.CursorPos == 0) if (ptr.CursorPos == 0)
{ {
_autoCompleteInfo = new AutoCompleteInfo( AutoCompleteInfo = new AutoCompleteInfo(
string.Empty, string.Empty,
ptr.CursorPos, ptr.CursorPos,
ptr.CursorPos ptr.CursorPos
); );
_autoCompleteOpen = true; AutoCompleteOpen = true;
_autoCompleteSelection = 0; AutoCompleteSelection = 0;
return 0; return 0;
} }
@@ -1365,13 +1365,13 @@ public sealed class ChatLogWindow : Window
var end = ptr.CursorPos - white - 1; var end = ptr.CursorPos - white - 1;
var utf8Message = Marshal.PtrToStringUTF8(start, end); var utf8Message = Marshal.PtrToStringUTF8(start, end);
var correctedCursor = ptr.CursorPos - (end - utf8Message.Length); var correctedCursor = ptr.CursorPos - (end - utf8Message.Length);
_autoCompleteInfo = new AutoCompleteInfo( AutoCompleteInfo = new AutoCompleteInfo(
utf8Message, utf8Message,
white + 1, white + 1,
correctedCursor correctedCursor
); );
_autoCompleteOpen = true; AutoCompleteOpen = true;
_autoCompleteSelection = 0; AutoCompleteSelection = 0;
return 0; return 0;
} }
@@ -1382,9 +1382,9 @@ public sealed class ChatLogWindow : Window
if (Activate) if (Activate)
{ {
Activate = false; Activate = false;
data->CursorPos = _activatePos > -1 ? _activatePos : Chat.Length; data->CursorPos = ActivatePos > -1 ? ActivatePos : Chat.Length;
data->SelectionStart = data->SelectionEnd = data->CursorPos; data->SelectionStart = data->SelectionEnd = data->CursorPos;
_activatePos = -1; ActivatePos = -1;
} }
Plugin.CommandHelpWindow.IsOpen = false; Plugin.CommandHelpWindow.IsOpen = false;
@@ -1403,11 +1403,11 @@ public sealed class ChatLogWindow : Window
if (data->EventFlag != ImGuiInputTextFlags.CallbackHistory) if (data->EventFlag != ImGuiInputTextFlags.CallbackHistory)
return 0; return 0;
var prevPos = _inputBacklogIdx; var prevPos = InputBacklogIdx;
switch (data->EventKey) switch (data->EventKey)
{ {
case ImGuiKey.UpArrow: case ImGuiKey.UpArrow:
switch (_inputBacklogIdx) switch (InputBacklogIdx)
{ {
case -1: case -1:
var offset = 0; var offset = 0;
@@ -1418,24 +1418,24 @@ public sealed class ChatLogWindow : Window
offset = 1; offset = 1;
} }
_inputBacklogIdx = _inputBacklog.Count - 1 - offset; InputBacklogIdx = InputBacklog.Count - 1 - offset;
break; break;
case > 0: case > 0:
_inputBacklogIdx--; InputBacklogIdx--;
break; break;
} }
break; break;
case ImGuiKey.DownArrow: case ImGuiKey.DownArrow:
if (_inputBacklogIdx != -1) if (InputBacklogIdx != -1)
if (++_inputBacklogIdx >= _inputBacklog.Count) if (++InputBacklogIdx >= InputBacklog.Count)
_inputBacklogIdx = -1; InputBacklogIdx = -1;
break; break;
} }
if (prevPos == _inputBacklogIdx) if (prevPos == InputBacklogIdx)
return 0; return 0;
var historyStr = _inputBacklogIdx >= 0 ? _inputBacklog[_inputBacklogIdx] : string.Empty; var historyStr = InputBacklogIdx >= 0 ? InputBacklog[InputBacklogIdx] : string.Empty;
ptr.DeleteChars(0, ptr.BufTextLen); ptr.DeleteChars(0, ptr.BufTextLen);
ptr.InsertChars(0, historyStr); ptr.InsertChars(0, historyStr);
@@ -1459,13 +1459,13 @@ public sealed class ChatLogWindow : Window
private void DrawChunk(Chunk chunk, bool wrap = true, PayloadHandler? handler = null, float lineWidth = 0f) private void DrawChunk(Chunk chunk, bool wrap = true, PayloadHandler? handler = null, float lineWidth = 0f)
{ {
if (chunk is IconChunk icon && _fontIcon != null) if (chunk is IconChunk icon && FontIcon != null)
{ {
var bounds = IconUtil.GfdFileView.TryGetEntry((uint) icon.Icon, out var entry); var bounds = IconUtil.GfdFileView.TryGetEntry((uint) icon.Icon, out var entry);
if (!bounds) if (!bounds)
return; return;
var texSize = new Vector2(_fontIcon.Width, _fontIcon.Height); var texSize = new Vector2(FontIcon.Width, FontIcon.Height);
var sizeRatio = Plugin.Config.FontSize / entry.Height; var sizeRatio = Plugin.Config.FontSize / entry.Height;
var size = new Vector2(entry.Width, entry.Height) * sizeRatio * ImGuiHelpers.GlobalScale; var size = new Vector2(entry.Width, entry.Height) * sizeRatio * ImGuiHelpers.GlobalScale;
@@ -1473,7 +1473,7 @@ public sealed class ChatLogWindow : Window
var uv0 = new Vector2(entry.Left, entry.Top + 170) * 2 / texSize; var uv0 = new Vector2(entry.Left, entry.Top + 170) * 2 / texSize;
var uv1 = new Vector2(entry.Left + entry.Width, entry.Top + entry.Height + 170) * 2 / texSize; var uv1 = new Vector2(entry.Left + entry.Width, entry.Top + entry.Height + 170) * 2 / texSize;
ImGui.Image(_fontIcon.ImGuiHandle, size, uv0, uv1); ImGui.Image(FontIcon.ImGuiHandle, size, uv0, uv1);
ImGuiUtil.PostPayload(chunk, handler); ImGuiUtil.PostPayload(chunk, handler);
return; return;