feat(ui): Chat tab — channel filters + display prefs + font slider

Phase L.0 (cont.) — fourth tab on the Settings shell. Mixes retail's
CharacterOptions2 chat-channel filter bits (Hear*Chat / TimeStamp /
FilterLanguage / AppearOffline) with a font-size slider that has no
retail bitfield equivalent.

ChatSettings record (9 fields):
 · 5 channel filters: HearGeneralChat, HearTradeChat, HearLFGChat,
   HearRoleplayChat, HearSocietyChat
 · 3 display flags: ShowTimestamps, FilterProfanity, AppearOffline
 · 1 visual: FontSize (10..20 pt)

Local-only this phase per the brainstorm — Hear*Chat flags affect
client-side display filtering only; the server still streams every
channel. Server-sync arrives later when the protocol round-trip is
in place.

SettingsStore grows LoadChat / SaveChat using the existing generic
SaveSection helper. All four non-keybind sections (display, audio,
gameplay, chat) now coexist non-destructively in settings.json.

SettingsVM grows the parallel chat state machine. HasUnsavedChanges,
Save, Cancel, ResetAllToDefaults all cover chat. Constructor signature
adds two more params; existing call sites updated.

SettingsPanel.RenderChatTab replaces the L.0-shell placeholder —
8 Checkbox calls grouped under "Channel filters" + "Display"
headers, plus a font-size SliderFloat. The "Coming soon" placeholder
test was retargeted from "Chat" to "Character" since Chat is no
longer a placeholder.

GameWindow wires SettingsStore.LoadChat / SaveChat + a TODO comment
for the future ChatPanel filter integration (read SettingsVM.ChatDraft
when filtering inbound chat lines).

13 new tests:
 · ChatSettings record (3) — defaults pinned, value equality, with-
   expressions
 · SettingsStore chat (3) — missing-file → defaults, round-trip, all
   four sections coexist
 · SettingsVM chat (5) — initial draft, SetChat marks dirty, Save
   invokes callback, Cancel reverts, ResetAllToDefaults covers
 · SettingsPanel chat tab (2) — checkboxes + slider render only when
   active

dotnet build green (0 warnings); dotnet test 1,289 / 1,289 green
(243 Core.Net + 373 UI.Abstractions + 673 Core).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Erik 2026-04-26 18:21:14 +02:00
parent b7165e5b17
commit 356b5f219e
9 changed files with 440 additions and 42 deletions

View file

@ -909,6 +909,7 @@ public sealed class GameWindow : IDisposable
var persistedDisplay = settingsStore.LoadDisplay();
var persistedAudio = settingsStore.LoadAudio();
var persistedGameplay = settingsStore.LoadGameplay();
var persistedChat = settingsStore.LoadChat();
// Apply persisted audio to the engine BEFORE the panel
// host starts pushing per-frame so the first frame uses
@ -987,6 +988,25 @@ public sealed class GameWindow : IDisposable
{
Console.WriteLine($"settings: gameplay save failed: {ex.Message}");
}
},
persistedChat: persistedChat,
onSaveChat: chat =>
{
try
{
settingsStore.SaveChat(chat);
Console.WriteLine(
"settings: chat saved to "
+ AcDream.UI.Abstractions.Panels.Settings.SettingsStore.DefaultPath());
// Channel filters affect client-side display
// only this phase. ChatPanel will read them
// off SettingsVM.ChatDraft when filtering is
// wired into the chat-line render path.
}
catch (Exception ex)
{
Console.WriteLine($"settings: chat save failed: {ex.Message}");
}
});
_settingsPanel = new AcDream.UI.Abstractions.Panels.Settings.SettingsPanel(_settingsVm);
_panelHost.Register(_settingsPanel);

View file

@ -0,0 +1,44 @@
namespace AcDream.UI.Abstractions.Panels.Settings;
/// <summary>
/// Chat-related preferences persisted to <c>settings.json</c>. Mixes
/// retail's <c>CharacterOptions2</c> chat-channel filter bits (Hear*Chat
/// + TimeStamp + FilterLanguage + AppearOffline) with a few visual
/// preferences (font size) that don't have a retail bitfield.
/// See <c>docs/research/named-retail/acclient.h:3451+</c> for the
/// retail bit values.
///
/// <para>
/// L.0 scope: <b>local-only</b> like the rest of L.0. The Hear*Chat
/// flags affect client-side <i>display</i> filtering of the existing
/// channels — the server still streams every line; the client decides
/// what to render. Server-sync arrives in a later phase that flips the
/// retail-faithful "tell server which channels I'm subscribed to"
/// switch.
/// </para>
/// </summary>
public sealed record ChatSettings(
// CharacterOptions2 (32-bit) channel filters.
bool HearGeneralChat, // 0x100 — General channel
bool HearTradeChat, // 0x200 — Trade channel
bool HearLFGChat, // 0x400 — LFG channel
bool HearRoleplayChat, // 0x800 — RP channel
bool HearSocietyChat, // 0x80000 — Society chat (CD/EW/RB)
bool AppearOffline, // 0x1000 — hide /who status
bool ShowTimestamps, // 0x40 — TimeStamp prefix on chat lines
bool FilterProfanity, // 0x20000 — FilterLanguage (Turbine's profanity filter)
// Visual / UX (no retail bitfield).
float FontSize) // chat panel font, 10..20 pt
{
/// <summary>Sensible starting values matching the retail "all on" stance.</summary>
public static ChatSettings Default { get; } = new(
HearGeneralChat: true,
HearTradeChat: true,
HearLFGChat: true,
HearRoleplayChat: true,
HearSocietyChat: true,
AppearOffline: false,
ShowTimestamps: true,
FilterProfanity: true,
FontSize: 12f);
}

View file

@ -98,7 +98,7 @@ public sealed class SettingsPanel : IPanel
}
if (renderer.BeginTabItem("Chat"))
{
RenderPlaceholder(renderer, "Chat");
RenderChatTab(renderer);
renderer.EndTabItem();
}
if (renderer.BeginTabItem("Character"))
@ -356,6 +356,67 @@ public sealed class SettingsPanel : IPanel
+ "follow-up phase.");
}
/// <summary>
/// Render the Chat tab — channel filters (Hear*Chat), display
/// preferences (timestamps / profanity filter / appear offline),
/// and a font-size slider. Channel filters affect client-side
/// display only this phase — the server still sends every line,
/// the client decides what to render.
/// </summary>
private void RenderChatTab(IPanelRenderer renderer)
{
var c = _vm.ChatDraft;
renderer.Text("Channel filters");
renderer.Separator();
bool general = c.HearGeneralChat;
if (renderer.Checkbox("General", ref general))
_vm.SetChat(c with { HearGeneralChat = general });
bool trade = c.HearTradeChat;
if (renderer.Checkbox("Trade", ref trade))
_vm.SetChat(c with { HearTradeChat = trade });
bool lfg = c.HearLFGChat;
if (renderer.Checkbox("LFG (looking for group)", ref lfg))
_vm.SetChat(c with { HearLFGChat = lfg });
bool rp = c.HearRoleplayChat;
if (renderer.Checkbox("Roleplay", ref rp))
_vm.SetChat(c with { HearRoleplayChat = rp });
bool society = c.HearSocietyChat;
if (renderer.Checkbox("Society (CD / EW / RB)", ref society))
_vm.SetChat(c with { HearSocietyChat = society });
renderer.Spacing();
renderer.Text("Display");
renderer.Separator();
bool timestamps = c.ShowTimestamps;
if (renderer.Checkbox("Show timestamps", ref timestamps))
_vm.SetChat(c with { ShowTimestamps = timestamps });
bool profanity = c.FilterProfanity;
if (renderer.Checkbox("Filter profanity", ref profanity))
_vm.SetChat(c with { FilterProfanity = profanity });
bool offline = c.AppearOffline;
if (renderer.Checkbox("Appear offline (hide from /who)", ref offline))
_vm.SetChat(c with { AppearOffline = offline });
float fontSize = c.FontSize;
if (renderer.SliderFloat("Font size (pt)", ref fontSize, 10f, 20f))
_vm.SetChat(c with { FontSize = fontSize });
renderer.Spacing();
renderer.TextWrapped(
"Channel filters hide messages from the chat window without "
+ "changing your server-side subscriptions. Save persists; "
+ "Cancel reverts.");
}
private void RenderSection(IPanelRenderer renderer, string label, InputAction[] actions)
{
// Movement defaults open; other sections collapsed for first-run UX.

View file

@ -167,6 +167,56 @@ public sealed class SettingsStore
public void SaveGameplay(GameplaySettings gameplay)
=> SaveSection("gameplay", BuildGameplayObject(gameplay));
/// <summary>Load Chat settings. Same fall-back behaviour as <see cref="LoadDisplay"/>.</summary>
public ChatSettings LoadChat()
{
if (!File.Exists(_path)) return ChatSettings.Default;
try
{
using var stream = File.OpenRead(_path);
var doc = JsonDocument.Parse(stream);
var root = doc.RootElement;
if (!root.TryGetProperty("chat", out var chat)
|| chat.ValueKind != JsonValueKind.Object)
return ChatSettings.Default;
var d = ChatSettings.Default;
return new ChatSettings(
HearGeneralChat: ReadBool (chat, "hearGeneralChat", d.HearGeneralChat),
HearTradeChat: ReadBool (chat, "hearTradeChat", d.HearTradeChat),
HearLFGChat: ReadBool (chat, "hearLFGChat", d.HearLFGChat),
HearRoleplayChat: ReadBool (chat, "hearRoleplayChat", d.HearRoleplayChat),
HearSocietyChat: ReadBool (chat, "hearSocietyChat", d.HearSocietyChat),
AppearOffline: ReadBool (chat, "appearOffline", d.AppearOffline),
ShowTimestamps: ReadBool (chat, "showTimestamps", d.ShowTimestamps),
FilterProfanity: ReadBool (chat, "filterProfanity", d.FilterProfanity),
FontSize: ReadFloat(chat, "fontSize", d.FontSize));
}
catch (Exception ex)
{
Console.WriteLine($"settings: failed to load {_path}: {ex.Message} — using defaults");
return ChatSettings.Default;
}
}
/// <summary>Save Chat settings, preserving all other top-level keys.</summary>
public void SaveChat(ChatSettings chat)
=> SaveSection("chat", BuildChatObject(chat));
private static SortedDictionary<string, object> BuildChatObject(ChatSettings c)
=> new(StringComparer.Ordinal)
{
["appearOffline"] = c.AppearOffline,
["filterProfanity"] = c.FilterProfanity,
["fontSize"] = c.FontSize,
["hearGeneralChat"] = c.HearGeneralChat,
["hearLFGChat"] = c.HearLFGChat,
["hearRoleplayChat"] = c.HearRoleplayChat,
["hearSocietyChat"] = c.HearSocietyChat,
["hearTradeChat"] = c.HearTradeChat,
["showTimestamps"] = c.ShowTimestamps,
};
private static SortedDictionary<string, object> BuildGameplayObject(GameplaySettings g)
=> new(StringComparer.Ordinal)
{

View file

@ -46,6 +46,11 @@ public sealed class SettingsVM
private GameplaySettings _gameplayDraft;
private readonly Action<GameplaySettings> _onSaveGameplay;
// L.0 — Chat tab (CharacterOptions2 channel filters + visual prefs).
private ChatSettings _chatPersisted;
private ChatSettings _chatDraft;
private readonly Action<ChatSettings> _onSaveChat;
/// <summary>The action currently being rebound, or null when idle.</summary>
public InputAction? RebindInProgress { get; private set; }
@ -70,7 +75,8 @@ public sealed class SettingsVM
=> !KeyBindingsEqual(_persisted, _draft)
|| _displayPersisted != _displayDraft
|| _audioPersisted != _audioDraft
|| _gameplayPersisted != _gameplayDraft;
|| _gameplayPersisted != _gameplayDraft
|| _chatPersisted != _chatDraft;
/// <summary>The current Display draft. Panel reads from here;
/// mutation goes through <see cref="SetDisplay"/>.</summary>
@ -84,6 +90,10 @@ public sealed class SettingsVM
/// mutation goes through <see cref="SetGameplay"/>.</summary>
public GameplaySettings GameplayDraft => _gameplayDraft;
/// <summary>The current Chat draft. Panel reads from here;
/// mutation goes through <see cref="SetChat"/>.</summary>
public ChatSettings ChatDraft => _chatDraft;
public SettingsVM(
KeyBindings persisted,
InputDispatcher dispatcher,
@ -93,7 +103,9 @@ public sealed class SettingsVM
AudioSettings persistedAudio,
Action<AudioSettings> onSaveAudio,
GameplaySettings persistedGameplay,
Action<GameplaySettings> onSaveGameplay)
Action<GameplaySettings> onSaveGameplay,
ChatSettings persistedChat,
Action<ChatSettings> onSaveChat)
{
_persisted = persisted ?? throw new ArgumentNullException(nameof(persisted));
_dispatcher = dispatcher ?? throw new ArgumentNullException(nameof(dispatcher));
@ -104,10 +116,13 @@ public sealed class SettingsVM
_onSaveAudio = onSaveAudio ?? throw new ArgumentNullException(nameof(onSaveAudio));
_gameplayPersisted = persistedGameplay ?? throw new ArgumentNullException(nameof(persistedGameplay));
_onSaveGameplay = onSaveGameplay ?? throw new ArgumentNullException(nameof(onSaveGameplay));
_chatPersisted = persistedChat ?? throw new ArgumentNullException(nameof(persistedChat));
_onSaveChat = onSaveChat ?? throw new ArgumentNullException(nameof(onSaveChat));
_draft = CloneBindings(persisted);
_displayDraft = persistedDisplay;
_audioDraft = persistedAudio;
_gameplayDraft = persistedGameplay;
_chatDraft = persistedChat;
}
/// <summary>
@ -144,6 +159,17 @@ public sealed class SettingsVM
_gameplayDraft = value ?? throw new ArgumentNullException(nameof(value));
}
/// <summary>
/// Replace the entire Chat draft with <paramref name="value"/>.
/// Local-only this phase — values persist on Save but the Hear*Chat
/// flags affect client-side display filtering, not server-side
/// channel subscriptions.
/// </summary>
public void SetChat(ChatSettings value)
{
_chatDraft = value ?? throw new ArgumentNullException(nameof(value));
}
/// <summary>
/// Begin rebinding <paramref name="action"/>. The supplied
/// <paramref name="original"/> binding will be removed when the new
@ -255,6 +281,7 @@ public sealed class SettingsVM
_displayDraft = DisplaySettings.Default;
_audioDraft = AudioSettings.Default;
_gameplayDraft = GameplaySettings.Default;
_chatDraft = ChatSettings.Default;
}
/// <summary>
@ -271,10 +298,12 @@ public sealed class SettingsVM
_onSaveDisplay(_displayDraft);
_onSaveAudio(_audioDraft);
_onSaveGameplay(_gameplayDraft);
_onSaveChat(_chatDraft);
_persisted = CloneBindings(_draft);
_displayPersisted = _displayDraft;
_audioPersisted = _audioDraft;
_gameplayPersisted = _gameplayDraft;
_chatPersisted = _chatDraft;
}
/// <summary>
@ -288,6 +317,7 @@ public sealed class SettingsVM
_displayDraft = _displayPersisted;
_audioDraft = _audioPersisted;
_gameplayDraft = _gameplayPersisted;
_chatDraft = _chatPersisted;
CancelRebind();
}