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:
parent
7665cdf642
commit
382f0ad3fa
9 changed files with 653 additions and 33 deletions
|
|
@ -29,7 +29,9 @@ public sealed class SettingsPanelTests
|
|||
persisted.Add(new Binding(new KeyChord(Key.W, ModifierMask.None), InputAction.MovementForward));
|
||||
persisted.Add(new Binding(new KeyChord(Key.A, ModifierMask.None), InputAction.MovementTurnLeft));
|
||||
var dispatcher = new InputDispatcher(kb, mouse, persisted);
|
||||
var vm = new SettingsVM(persisted, dispatcher, _ => { });
|
||||
var vm = new SettingsVM(
|
||||
persisted, dispatcher, _ => { },
|
||||
DisplaySettings.Default, _ => { });
|
||||
var panel = new SettingsPanel(vm);
|
||||
return (panel, vm, kb, dispatcher);
|
||||
}
|
||||
|
|
@ -234,6 +236,54 @@ public sealed class SettingsPanelTests
|
|||
Assert.Contains(wrapped, t => t.Contains("Audio settings coming soon"));
|
||||
}
|
||||
|
||||
// -- Display tab content ---------------------------------------------
|
||||
|
||||
[Fact]
|
||||
public void Display_tab_when_active_renders_resolution_combo_plus_sliders()
|
||||
{
|
||||
var (panel, _, _, _) = Build();
|
||||
var r = new FakePanelRenderer { ActiveTabLabel = "Display" };
|
||||
|
||||
panel.Render(new PanelContext(0.016f, new NullBus()), r);
|
||||
|
||||
var combos = r.Calls.Where(c => c.Method == "Combo").Select(c => (string)c.Args[0]!).ToList();
|
||||
var checks = r.Calls.Where(c => c.Method == "Checkbox").Select(c => (string)c.Args[0]!).ToList();
|
||||
var sliders = r.Calls.Where(c => c.Method == "SliderFloat").Select(c => (string)c.Args[0]!).ToList();
|
||||
|
||||
Assert.Contains("Resolution", combos);
|
||||
Assert.Contains("Fullscreen", checks);
|
||||
Assert.Contains("V-Sync", checks);
|
||||
Assert.Contains("Show FPS", checks);
|
||||
Assert.Contains("Field of View", sliders);
|
||||
Assert.Contains("Gamma", sliders);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Display_tab_does_not_render_when_a_different_tab_is_active()
|
||||
{
|
||||
var (panel, _, _, _) = Build();
|
||||
var r = new FakePanelRenderer { ActiveTabLabel = "Audio" };
|
||||
|
||||
panel.Render(new PanelContext(0.016f, new NullBus()), r);
|
||||
|
||||
var combos = r.Calls.Where(c => c.Method == "Combo").Select(c => (string)c.Args[0]!).ToList();
|
||||
Assert.DoesNotContain("Resolution", combos);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Display_tab_resolution_combo_uses_AvailableResolutions_list()
|
||||
{
|
||||
var (panel, _, _, _) = Build();
|
||||
var r = new FakePanelRenderer { ActiveTabLabel = "Display" };
|
||||
|
||||
panel.Render(new PanelContext(0.016f, new NullBus()), r);
|
||||
|
||||
var resCall = r.Calls.First(c => c.Method == "Combo" && (string)c.Args[0]! == "Resolution");
|
||||
var items = (string[])resCall.Args[2]!;
|
||||
Assert.Contains("1920x1080", items);
|
||||
Assert.Contains("3840x2160", items);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Save_Cancel_buttons_render_outside_the_tab_bar()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue