Files
HellionChat/HellionChat/Ui/Windows/ChannelPopoutWindow.cs
T
JonKazama-Hellion eca566321a fix(tells): a tell no longer takes the keyboard mid-sentence
Reported by Carla: a tell arriving while you are typing pulls the focus
away. The interruption is the visible half. The sharp half is that the
input buffer belongs to the WINDOW while the send target is read off
whatever tab is active at Enter -- so a line typed at one person could
leave addressed to whoever just wrote, and in this game losing the
keyboard means the next sentence walks the character around.

Nothing is revealed now while any chat surface is mid-sentence, in any
mode. The tab still appears and still carries its unread mark. The check
lives in its own file because the answer has to be identical everywhere:
it started inside the reveal plan, and a second pop-out path walked
straight past it -- AutoTellTabsService opened windows off its own flag,
at tab creation, a tick before the router was ever asked.

Those two paths are one now. AutoTellTabsOpenAsPopout and TellAutoOpenMode
were two settings for one decision, and the older one won every race,
which is why the other looked inert. Config schema 28 carries the old flag
forward so nobody's behaviour changes. "Off" went with it: it never
stopped the tab from being created -- that is the auto-tell switch -- it
only stopped the jump to it, which is what the switch below it does.

Also in here, all from the same corner of the code:

- Closing a tab was lost in the v2.0.0 rebuild. The trash entry lived in
  the retired ChatLogWindow menu, and the rebuilt one restored rename,
  sound, pop-out and pinning but not this. For tell tabs that left no way
  out at all: IsEditable keeps them out of the settings editor on purpose
  and points at the context menu, which could not close them either.
  Pinned tell tabs stay disabled with a tooltip rather than absent.
- Re-anchoring the active tab used an unconditional Tabs[0] in three
  places, and Tabs[0] can be popped out -- so it ran OnTabActivated over a
  tab live in its own window and stripped its tell binding. With every tab
  popped, the seed and the re-anchor also fought each other every frame.
- PinTab_LimitReached still pointed at "Promote to permanent", removed in
  May. Spanish said "Desija", which is not a word; Greek left "tell tabs"
  untranslated; pt-PT broke its own unpin verb.
- Pop Out was a hardcoded English literal despite the key existing in all
  25 languages since v1.5.6, and the tell-open modes were the last English
  display names in the plugin.
- Segmented setting rows measured 200px flat, which cut German labels in
  half. They size to their longest label now.
- Metrics.Scale still called GlobalScaleSafe. It is an alias for
  GlobalScale in current Dalamud, and dropping it clears the last compiler
  warning in the project.
2026-08-23 02:12:27 +02:00

187 lines
6.8 KiB
C#

using System.Numerics;
using Dalamud.Bindings.ImGui;
using Dalamud.Interface;
using Dalamud.Interface.Utility.Raii;
using Dalamud.Interface.Windowing;
using HellionChat.Themes;
using HellionChat.Ui.Components;
using HellionChat.Ui.StyleEngine.Widgets;
using HellionChat.Util;
using Microsoft.Extensions.Logging;
namespace HellionChat.Ui.Windows;
// One pre-allocated pop-out window bound to a single Tab. Pure DI-sink: the
// PayloadHandler arrives via AttachPayloadHandler (post-build setter), NEVER
// via ctor. The ###id carries the slot index so all N
// instances are unique for WindowSystem.AddWindow and ImGui state is stable
// per slot (not per bound tab).
internal sealed class ChannelPopoutWindow : Window, IFocusableChatWindow
{
private readonly int _slotIndex;
private readonly MessageList _messages;
private readonly InputBar _input;
private readonly ILogger<ChannelPopoutWindow> _logger;
private readonly FontManager _fonts;
private readonly Ui.StyleEngine.SurfaceBackdrop _backdrop;
private readonly ThemeRegistry _themes;
private readonly Ui.StyleEngine.TokenResolver _resolver;
public ChannelPopoutWindow(
int slotIndex,
MessageList messages,
InputBar input,
ILogger<ChannelPopoutWindow> logger,
FontManager fonts,
Ui.StyleEngine.SurfaceBackdrop backdrop,
ThemeRegistry themes,
Ui.StyleEngine.TokenResolver resolver
)
: base($"{Plugin.PluginName}###hellion_popout_{slotIndex}")
{
_slotIndex = slotIndex;
_messages = messages;
_input = input;
_logger = logger;
_fonts = fonts;
_backdrop = backdrop;
_themes = themes;
_resolver = resolver;
// The pop-in button lives in the input row. Wired here rather than
// through the constructor because this window is what it has to call.
_input.OnPopIn = () =>
{
if (Bound is { } tab)
CloseRequested?.Invoke(tab.Identifier);
};
IsOpen = false;
RespectCloseHotkey = false;
ShowCloseButton = false;
}
public int SlotIndex => _slotIndex;
public Tab? Bound { get; private set; }
// Wired post-build by ChannelPopoutPool so closing routes through the pool
// (which owns the slot map). The window can't reach the pool by ctor without
// a DI cycle, so the pool sets this after construction.
public Action<Guid>? CloseRequested { get; set; }
// Post-build setter. Wired by ChannelPopoutInitHostedService.
public void AttachPayloadHandler(PayloadHandler handler) =>
_messages.AttachPayloadHandler(handler);
public void Bind(Tab tab)
{
Bound = tab;
var isTell = tab is { IsTempTab: true, TellTarget: { } target } && target.IsSet();
// Default sizes: Tell is the more compact conversation window.
Size = isTell ? new Vector2(380f, 320f) : new Vector2(420f, 320f);
SizeCondition = ImGuiCond.FirstUseEver;
// Visible label tracks the bound tab; the ###id stays slot-stable so
// ImGui keeps this slot's position/size across binds.
// The title bar is a surface too, and the header deliberately stays
// silent in this mode because the title already carries the name.
var label = Util.TabDisplayName.Resolve(
tab.Name,
tab.NameCameFromPartner,
Plugin.Config.ScreenshotMode
);
WindowName = $"{label}###hellion_popout_{_slotIndex}";
IsOpen = true;
}
public void Unbind()
{
Bound = null;
IsOpen = false;
}
// IFocusableChatWindow — this pop-out's own InputBar carries the focus state
// the keybind tail checks when deciding whether to route at this surface.
public bool HasFocusedInput => _input.IsFocused;
// See IFocusableChatWindow.IsInputBusy.
public bool IsInputBusy => _input.IsFocused || _input.PendingLength > 0;
// Arm-and-hold the one-frame Activate flag; the pop-out's Draw applies the
// ImGui focus next frame. Framework-thread safe (field write only).
public void RequestInputFocus()
{
BringToFront();
_input.Activate = true;
}
public override void PreDraw()
{
// Gate the native title bar on the user toggle (1.5.6 parity). DrawHeader
// carries the close button in-body regardless, so hiding the title bar
// never strands the pop-out. Reset from a fresh base each frame so
// toggling the bar back on clears NoTitleBar.
Flags = Plugin.Config.ShowPopOutTitleBar
? ImGuiWindowFlags.None
: ImGuiWindowFlags.NoTitleBar;
}
public override void Draw()
{
if (Bound is null)
return;
// v1.13.0: the plain title row became the channel header. The warning it
// left behind still holds and is now the rule the header follows -- with
// the title bar on, the window title already carries the tab name, so the
// header drops the name and shows only the world and the clock.
//
// Drawn before the body child on purpose, and the child's height is left
// alone: it is a negative value, which ImGui resolves against the space
// still available from the current cursor, and the header has already
// taken its share.
StyleEngine.Widgets.ChannelHeader.Draw(
Bound,
Plugin.Config.ShowPopOutTitleBar
? StyleEngine.Widgets.ChannelHeaderMode.DetailOnly
: StyleEngine.Widgets.ChannelHeaderMode.Full,
Plugin.Instance.FontManager,
StyleEngine.Widgets.ChannelHeader.CurrentDetail(),
InputBar.Height
);
// Anything drawn above can unbind us mid-frame (CloseRequested ->
// pool.TryClose -> Unbind nulls Bound). Re-check before the body so we
// never hand a null tab to MessageList/InputBar in this same Draw call.
if (Bound is null)
return;
// The bound tab is live-visible in this pop-out, so it carries no
// unread badge — mirror MainWindow's per-frame zero for the active tab.
// View-state reset only (tab.Messages store is untouched).
Bound.Unread = 0;
var inputHeight = InputBar.Height;
using (
var body = ImRaii.Child(
$"##hellion-popout-body-{_slotIndex}",
new Vector2(-1f, -inputHeight)
)
)
{
if (body.Success)
{
// Same floor as the main window's log, and the same reasoning:
// no accent wash and barely any motes, because a chat log is read
// line by line.
_backdrop.Draw(accentWashHeight: 0f, moteIntensity: 0.10f, strength: 0.45f);
_messages.Draw(Bound);
}
}
_input.Draw(Bound);
}
}