Files
HellionChat/HellionChat/Ui/CommandHelpWindow.cs
T
JonKazama-Hellion 5b738e6885 chore: comments say what the code does, not which task produced it
A comment that reads "MUST stay in lockstep with TryGetActiveCrossfade (K8)"
helps nobody outside the plan that used to have a K8 in it, and the plans are
not in this repo. Same for "Spec FR-4", "plan §B.2", "Sub-Task 4.4" and the
F/R/M/A/S round codes scattered through the style engine and the self-tests.

Personal names go too. "tester feedback from Jin (v1.4.7)" and "Flo decision
2026-06-15" carry the reason fine without naming anyone -- the version and the
reason are the parts a reader can act on, and a public repo should not need a
cast list to be read.

The rule applied throughout: keep the why, drop the reference. Version numbers
stay, since those resolve through the changelog. 77 files.

ChunkUtil also carried 281 lines of commented-out code -- an older ToChunks
variant and two helpers with no callers, inherited and never removed. Deleted;
git remembers them.
2026-08-19 21:50:31 +02:00

104 lines
3.4 KiB
C#

using System.Numerics;
using Dalamud.Bindings.ImGui;
using Dalamud.Interface.Utility;
using Dalamud.Interface.Windowing;
using Dalamud.Utility;
using HellionChat.Ui.Components;
using HellionChat.Util;
using Lumina.Text.ReadOnly;
using Microsoft.Extensions.Logging;
namespace HellionChat.Ui;
internal sealed class CommandHelpWindow : Window
{
private readonly ChunkRenderer _chunkRenderer;
private readonly ILogger<CommandHelpWindow> _logger;
// Setter-injected post-ctor to break the InputBar -> CommandHelpWindow ->
// MainWindow -> InputBar singleton cycle (MS.DI does not detect cycles
// through FactoryCallSite registrations). Wired in
// CommandHelpWindowInitHostedService.StartAsync, same setter-injection pattern as
// MessageList.AttachPayloadHandler.
private Windows.MainWindow? _mainWindow;
private ReadOnlySeString? _commandDescription;
internal CommandHelpWindow(ChunkRenderer chunkRenderer, ILogger<CommandHelpWindow> logger)
: base("command help##chat2-commandhelp")
{
_chunkRenderer = chunkRenderer;
_logger = logger;
Flags =
ImGuiWindowFlags.NoSavedSettings
| ImGuiWindowFlags.NoTitleBar
| ImGuiWindowFlags.NoMove
| ImGuiWindowFlags.NoResize
| ImGuiWindowFlags.NoFocusOnAppearing
| ImGuiWindowFlags.AlwaysAutoResize;
RespectCloseHotkey = false;
DisableWindowSounds = true;
// Logger injected for future diagnostic hooks; no call sites yet.
_ = _logger;
}
internal void AttachMainWindow(Windows.MainWindow mainWindow) => _mainWindow = mainWindow;
public void UpdateContent(ReadOnlySeString commandDesc)
{
// Loud-fail if the HostedService didn't run AttachMainWindow before
// the first slash-command call — better than a silent NullRef during
// input draw.
if (_mainWindow is null)
throw new InvalidOperationException(
"CommandHelpWindow.UpdateContent called before AttachMainWindow."
);
_commandDescription = commandDesc;
var width = 350;
var scaledWidth = width * ImGuiHelpers.GlobalScale;
var pos = _mainWindow.LastWindowPos;
switch (Plugin.Config.CommandHelpSide)
{
case CommandHelpSide.Right:
pos.X += _mainWindow.LastWindowSize.X;
break;
case CommandHelpSide.Left:
pos.X -= scaledWidth;
break;
case CommandHelpSide.None:
default:
IsOpen = false;
return;
}
Position = pos;
SizeConstraints = new WindowSizeConstraints
{
// scaledWidth keeps size constraints in the same coordinate space as
// Position so the help window stays correct width at non-100% DPI.
MinimumSize = new Vector2(scaledWidth, 0),
MaximumSize = _mainWindow.LastWindowSize with { X = scaledWidth },
};
IsOpen = true;
}
public override void Draw()
{
if (_commandDescription == null)
return;
var chunks = ChunkUtil
.ToChunks(_commandDescription.Value.ToDalamudString(), ChunkSource.None, null)
.ToList();
// Command-help chunks are read-only description text — no click-targets.
_chunkRenderer.DrawChunks(chunks, wrap: true, handler: null, lineWidth: 0f);
}
}