feat(ui): Display tab + settings.json persistence — first non-keybind tab lands

Phase L.0 (cont.) — first concrete tab on the new Settings shell, in
the Easy-wins build order agreed in the brainstorm
(Display → Audio → Gameplay → Chat → Character).

DisplaySettings (immutable record): Resolution / Fullscreen / VSync /
FieldOfView (30-120°) / Gamma (0.5-2.0) / ShowFps. Six common 16:9
resolutions in the dropdown. Defaults: 1920×1080, windowed, vsync on,
75° FOV, gamma 1.0, FPS off — matches the brainstorm UX agreement.

SettingsStore: JSON persistence at %LOCALAPPDATA%\acdream\settings.json
(coexists with keybinds.json — own load/save path stays put, no
migration needed). LoadDisplay falls back per-field when keys are
missing (partial-file tolerant) and falls back to defaults when the
file is corrupt or the JSON is unparseable. SaveDisplay round-trips
preserved — unknown top-level keys (e.g. an `audio` section written
by a future client) are kept on save so older builds don't silently
drop newer-tab data.

SettingsVM gains a parallel display-state machine: persistedDisplay +
draftDisplay, SetDisplay mutator, HasUnsavedChanges checks both
keybinds and display deltas, Save/Cancel/ResetAll cover both
atomically from the user's POV (one Save commits everything, one
Cancel reverts everything). Constructor signature extends with two
new params; existing keybinds-only callers updated.

SettingsPanel.RenderDisplayTab replaces the L.0-shell placeholder —
Combo for resolution, Checkboxes for fullscreen/vsync/show-fps,
SliderFloat for FOV + gamma. Live-preview note in the panel body
matches the agreed UX: FOV + gamma update visibly while the user
drags; resolution / fullscreen / vsync apply on Save (live preview
would be too jarring).

GameWindow wires SettingsStore into the existing SettingsVM construct
site — load on startup, save on each tab Save. Errors print to
console and don't crash the panel.

19 new tests:
 · DisplaySettings record (4) — defaults pinned, value equality, with-
   expressions, AvailableResolutions sorted ascending
 · SettingsStore (6) — round trip, missing-file → defaults, corrupt-
   file → defaults, partial-file → per-field fallback, unknown-key
   preservation, DefaultPath shape
 · SettingsVM display (6) — initial draft tracks persisted, SetDisplay
   marks dirty, Save invokes display callback, Cancel reverts,
   ResetAllToDefaults covers display, Save-then-Cancel is no-op
 · SettingsPanel display tab (3) — widgets render only when active,
   resolution combo uses AvailableResolutions, no Combo emitted on
   inactive tabs

dotnet build green (0 warnings); dotnet test 1,246 / 1,246 green
(243 Core.Net + 330 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 17:46:31 +02:00
parent 7665cdf642
commit 382f0ad3fa
9 changed files with 653 additions and 33 deletions

View file

@ -83,7 +83,7 @@ public sealed class SettingsPanel : IPanel
}
if (renderer.BeginTabItem("Display"))
{
RenderPlaceholder(renderer, "Display");
RenderDisplayTab(renderer);
renderer.EndTabItem();
}
if (renderer.BeginTabItem("Audio"))
@ -194,6 +194,51 @@ public sealed class SettingsPanel : IPanel
+ "Build order: Display → Audio → Gameplay → Chat → Character.");
}
/// <summary>
/// Render the Display tab — resolution / fullscreen / vsync /
/// FOV / gamma / show-FPS. FOV + Gamma are live-preview sliders;
/// the others apply on Save (matches the brainstorm UX agreement —
/// resolution change live would be too jarring).
/// </summary>
private void RenderDisplayTab(IPanelRenderer renderer)
{
var d = _vm.DisplayDraft;
// Resolution dropdown. Index falls back to the highest available
// option when the persisted resolution isn't one of the presets
// (e.g. user hand-edited settings.json with a non-standard size).
var resolutions = DisplaySettings.AvailableResolutions.ToArray();
int idx = System.Array.IndexOf(resolutions, d.Resolution);
if (idx < 0) idx = resolutions.Length - 1;
if (renderer.Combo("Resolution", ref idx, resolutions))
_vm.SetDisplay(d with { Resolution = resolutions[idx] });
bool fullscreen = d.Fullscreen;
if (renderer.Checkbox("Fullscreen", ref fullscreen))
_vm.SetDisplay(d with { Fullscreen = fullscreen });
bool vsync = d.VSync;
if (renderer.Checkbox("V-Sync", ref vsync))
_vm.SetDisplay(d with { VSync = vsync });
float fov = d.FieldOfView;
if (renderer.SliderFloat("Field of View", ref fov, 30f, 120f))
_vm.SetDisplay(d with { FieldOfView = fov });
float gamma = d.Gamma;
if (renderer.SliderFloat("Gamma", ref gamma, 0.5f, 2.0f))
_vm.SetDisplay(d with { Gamma = gamma });
bool showFps = d.ShowFps;
if (renderer.Checkbox("Show FPS", ref showFps))
_vm.SetDisplay(d with { ShowFps = showFps });
renderer.Spacing();
renderer.TextWrapped(
"Resolution / Fullscreen / V-Sync apply on Save. FOV + Gamma "
+ "preview live as you drag; Cancel reverts to the saved value.");
}
private void RenderSection(IPanelRenderer renderer, string label, InputAction[] actions)
{
// Movement defaults open; other sections collapsed for first-run UX.