User directive (gate 2, verbatim): "mark all options that are not implemented now, so I can clearly see what is not implemented." Store-only rows keep full interactivity (still persist/send) but render their caption in a shared dimmed grey (UiRenderContext.StoreOnlyCaptionColor, matching the existing UiMenu.TextColorGhosted convention) instead of white/DAT color. No invented marker text anywhere -- the dim IS the marker. Config tab (ConfigOptionsPageController, 21 of 27 rows dimmed): Sound Features menu, Interface Sound trio, Play Sound Only When Active (AP-199); Screen Brightness, Automatic Degrades, Graphics Performance, Degrade Distance, the four Rendering Quality menus, Building Detail Textures, Multi-Pass Alpha (AP-198); Camera Stiffness, Camera Adjustment Speed, Align To Slope, Mouse Look Sensitivity, Invert Mouselook Y Axis, Use Mouse Turning (TS-74); Chat Font Face/Size (AP-200). NOT dimmed: Sound/Ambient trios, Resolution, Full Screen (LIVE), VSync and Field of View (NEXT-LAUNCH -- still implemented, just deferred to next process start, per the controller's own doc). Character tab (CharacterOptionsPageController, 35 of 50 rows dimmed): every Group A (wire+store only) and Group D (deferred) row, plus the Group B rows the OP4 gate script's own step 16 confirms are unbound (ShowTooltips, SideBySideVitals, SpellDuration, AdvancedCombatUI, StayInChatMode, DisableMostWeatherEffects, PersistentAtDay, FilterLanguage, MainPackPreferred). NOT dimmed (15 rows): the six ListenTo*Chat ids (TurbineChatMembershipGate), DisableDistanceFog/ DisplayTimeStamps/ToggleRun (bound at GameWindow.cs), the Group-C re-point (ViewCombatTarget/VividTargetingIndicator/CoordinatesOnRadar/ AutoTarget/AutoRepeatAttack), and DragItemOnPlayerOpensSecureTrade (TS-48). Cross-checked against actual shipped consumers via source grep, not just the research doc's Group table, since OP4 only wired a subset of the doc's aspirational Group B. Configure Keyboard (KeyboardConfigController): a row whose RetailActionIdentityTable lookup fails (MappedAction null -- AP-203's Emote/CharacterSettings set) dims its synthesized caption; the key buttons stay fully bindable/persisted/conflict-checked. Chat tab (ChatOptionsPageController): audited, zero store-only rows -- every filter block and both opacity sliders already have a live consumer (ChatWindowState / RetailWindowOpacityController). Ambiguity flagged, not guessed: the character-options-map.md research doc lists AcceptLootPermits in BOTH Group A and Group C; its only code site (LiveSessionRuntimeFactory.cs, the /consent command) is a second setter for the same server bit, not a behavioral reader, so it is classified Group A / dimmed here. Register: AD-78 documents the convention (retail dims nothing; this is a deliberate acdream-only divergence that retires as consumers land). New per-surface conformance tests pin the exact dimmed/live set against a literal expected list, so wiring a future consumer without also flipping its row's literal fails the build: CharacterOptionsPageControllerTests.StoreOnlyRows_MatchTheDerivationTableExactly + Bind_AppliesDimmedCaptionColor_ForStoreOnlyRows_AndWhiteForLiveRows, ConfigOptionsPageControllerTests.CaptionDimming_MatchesTheStoreOnlySetExactly, KeyboardConfigControllerTests.UnmappedRows_DimTheirCaption_MappedRowsStayWhite. Build green; full Release suite 13,086 passed / 4 skipped / 0 failed (baseline 13,082/4/0 -- delta is exactly the four new tests above). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
659 lines
30 KiB
C#
659 lines
30 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Numerics;
|
|
using AcDream.App.UI;
|
|
using AcDream.App.UI.Layout;
|
|
using AcDream.Core.Input;
|
|
using AcDream.UI.Abstractions.Input;
|
|
|
|
namespace AcDream.App.Tests.UI.Layout;
|
|
|
|
/// <summary>
|
|
/// Campaign OP slice OP8 conformance + behavior tests for
|
|
/// <see cref="KeyboardConfigController"/> — built against the committed
|
|
/// <c>keyboard_config_21000009.json</c> fixture (real DAT structure, no live dat
|
|
/// access at test time), fed a small synthetic <see cref="RetailActionMapSnapshot"/>
|
|
/// so the behavioral assertions stay focused. Live-DAT row-count/label conformance
|
|
/// lives in <c>AcDream.Core.Tests.Input.RetailActionMapReaderTests</c> and
|
|
/// <c>RetailActionIdentityRoundTripTests</c>.
|
|
///
|
|
/// <para>
|
|
/// Reworked at the 2026-08-11 combined review (M1/M2/M3/S1/S4): the seam now
|
|
/// carries <see cref="Binding"/> (chord + activation + scope), the M2 fix means
|
|
/// only ONE camera InputMap context maps live, and conflicts open a real confirm
|
|
/// dialog instead of auto-reassigning silently.
|
|
/// </para>
|
|
/// </summary>
|
|
public sealed class KeyboardConfigControllerTests
|
|
{
|
|
private static (uint, int, int) NoTex(uint _) => (0, 0, 0);
|
|
|
|
private static ElementInfo? Find(ElementInfo n, uint id)
|
|
{
|
|
if (n.Id == id) return n;
|
|
foreach (ElementInfo c in n.Children)
|
|
{
|
|
ElementInfo? f = Find(c, id);
|
|
if (f is not null) return f;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private static Func<uint, uint, UiElement?> MakeTemplateResolver()
|
|
{
|
|
ElementInfo root = FixtureLoader.LoadKeyboardConfigInfos();
|
|
return (layoutId, elementId) =>
|
|
{
|
|
if (layoutId != KeyboardConfigController.LayoutId) return null;
|
|
ElementInfo? templateInfo = Find(root, elementId);
|
|
return templateInfo is null ? null : LayoutImporter.Build(templateInfo, NoTex, null).Root;
|
|
};
|
|
}
|
|
|
|
private static RetailActionMapRow Row(
|
|
uint inputMapId, uint actionId, RetailActionClass cls,
|
|
uint labelHash = 0, uint tooltipHash = 0,
|
|
params RetailKeyChord[] defaults) =>
|
|
new(inputMapId, actionId, cls, labelHash, tooltipHash, defaults);
|
|
|
|
private sealed class FakeBindings
|
|
{
|
|
public Dictionary<InputAction, List<Binding>> Mapped { get; } = new();
|
|
public Dictionary<(uint, uint), List<KeyChord>> Unmapped { get; } = new();
|
|
public List<(InputAction Action, IReadOnlyList<Binding> Value)> MappedSets { get; } = new();
|
|
public List<((uint, uint) Row, IReadOnlyList<KeyChord> Value)> UnmappedSets { get; } = new();
|
|
public List<string> Messages { get; } = new();
|
|
public int SaveCalls { get; private set; }
|
|
public int ToggleCalls { get; private set; }
|
|
public Action<KeyChord?>? PendingCapture { get; private set; }
|
|
public (string Message, Action<bool> OnResult)? PendingConfirm { get; private set; }
|
|
|
|
public void Capture(KeyChord? chord)
|
|
{
|
|
Action<KeyChord?>? cb = PendingCapture;
|
|
PendingCapture = null;
|
|
cb?.Invoke(chord);
|
|
}
|
|
|
|
public void RespondToConfirm(bool accept)
|
|
{
|
|
var pending = PendingConfirm ?? throw new InvalidOperationException("no pending confirm");
|
|
PendingConfirm = null;
|
|
pending.OnResult(accept);
|
|
}
|
|
|
|
public KeyboardConfigController.Bindings ToBindings() => new(
|
|
CurrentForAction: a => Mapped.TryGetValue(a, out var v) ? v : Array.Empty<Binding>(),
|
|
SetForAction: (a, v) =>
|
|
{
|
|
Mapped[a] = v.ToList();
|
|
MappedSets.Add((a, v));
|
|
},
|
|
CurrentForUnmapped: k => Unmapped.TryGetValue(k, out var v) ? v : Array.Empty<KeyChord>(),
|
|
SetForUnmapped: (k, v) =>
|
|
{
|
|
Unmapped[k] = v.ToList();
|
|
UnmappedSets.Add((k, v));
|
|
},
|
|
BeginCapture: cb => PendingCapture = cb,
|
|
Save: () => SaveCalls++,
|
|
Toggle: () => ToggleCalls++,
|
|
DisplaySystemMessage: msg => Messages.Add(msg),
|
|
NonBindableRefusalText: "cannot overwrite",
|
|
ConfirmOverwrite: (message, onResult) => PendingConfirm = (message, onResult));
|
|
}
|
|
|
|
private static readonly KeyChord ChordW = new(Silk.NET.Input.Key.W, ModifierMask.None);
|
|
private static readonly KeyChord ChordUp = new(Silk.NET.Input.Key.Up, ModifierMask.None);
|
|
private static readonly KeyChord ChordA = new(Silk.NET.Input.Key.A, ModifierMask.None);
|
|
|
|
[Fact]
|
|
public void Bind_Succeeds_AndBuildsOneRowPerSnapshotRow()
|
|
{
|
|
var snapshot = new RetailActionMapSnapshot(new[]
|
|
{
|
|
Row(0x4, 0x29, RetailActionClass.Movement), // MovementForward
|
|
Row(0x4, 0x2A, RetailActionClass.Movement), // MovementBackup
|
|
Row(0x5, 0x33, RetailActionClass.Camera), // CameraMoveToward
|
|
});
|
|
|
|
ImportedLayout layout = FixtureLoader.LoadKeyboardConfig();
|
|
var fake = new FakeBindings();
|
|
KeyboardConfigController? controller = KeyboardConfigController.Bind(
|
|
layout, snapshot, MakeTemplateResolver(), (_, _) => null, fake.ToBindings());
|
|
|
|
Assert.NotNull(controller);
|
|
Assert.Equal(3, controller!.Rows.Count);
|
|
Assert.Equal(3, controller.Page.Rows.Count);
|
|
}
|
|
|
|
[Fact]
|
|
public void Bind_MapsKnownActionsAndLeavesUnknownOnesUnmapped()
|
|
{
|
|
var snapshot = new RetailActionMapSnapshot(new[]
|
|
{
|
|
Row(0x4, 0x29, RetailActionClass.Movement), // -> MovementForward
|
|
Row(0x10000006, 0x100000A0, RetailActionClass.Emote), // "Bow Deep" -> no InputAction
|
|
});
|
|
|
|
ImportedLayout layout = FixtureLoader.LoadKeyboardConfig();
|
|
var fake = new FakeBindings();
|
|
KeyboardConfigController controller = KeyboardConfigController.Bind(
|
|
layout, snapshot, MakeTemplateResolver(), (_, _) => null, fake.ToBindings())!;
|
|
|
|
KeyboardConfigController.RowView forward = controller.Rows.Single(r => r.ActionId == 0x29u);
|
|
Assert.Equal(InputAction.MovementForward, forward.MappedAction);
|
|
|
|
KeyboardConfigController.RowView bowDeep = controller.Rows.Single(r => r.ActionId == 0x100000A0u);
|
|
Assert.Null(bowDeep.MappedAction);
|
|
}
|
|
|
|
[Fact]
|
|
public void Bind_SeedsRowFromLiveBindings_MappedAndUnmapped()
|
|
{
|
|
var snapshot = new RetailActionMapSnapshot(new[]
|
|
{
|
|
Row(0x4, 0x29, RetailActionClass.Movement),
|
|
Row(0x10000006, 0x100000A0, RetailActionClass.Emote),
|
|
});
|
|
|
|
var fake = new FakeBindings();
|
|
fake.Mapped[InputAction.MovementForward] = new List<Binding>
|
|
{
|
|
new(ChordW, InputAction.MovementForward),
|
|
new(ChordUp, InputAction.MovementForward),
|
|
};
|
|
fake.Unmapped[(0x10000006u, 0x100000A0u)] = new List<KeyChord> { ChordA };
|
|
|
|
ImportedLayout layout = FixtureLoader.LoadKeyboardConfig();
|
|
KeyboardConfigController controller = KeyboardConfigController.Bind(
|
|
layout, snapshot, MakeTemplateResolver(), (_, _) => null, fake.ToBindings())!;
|
|
|
|
KeyboardConfigController.RowView forward = controller.Rows.Single(r => r.ActionId == 0x29u);
|
|
Assert.Equal(new[] { ChordW, ChordUp }, forward.Model.Current);
|
|
|
|
KeyboardConfigController.RowView bowDeep = controller.Rows.Single(r => r.ActionId == 0x100000A0u);
|
|
Assert.Equal(new[] { ChordA }, bowDeep.Model.Current);
|
|
}
|
|
|
|
[Fact]
|
|
public void KeyButtonClick_CapturesAndAppliesNewBinding()
|
|
{
|
|
var snapshot = new RetailActionMapSnapshot(new[] { Row(0x4, 0x29, RetailActionClass.Movement) });
|
|
var fake = new FakeBindings();
|
|
ImportedLayout layout = FixtureLoader.LoadKeyboardConfig();
|
|
KeyboardConfigController controller = KeyboardConfigController.Bind(
|
|
layout, snapshot, MakeTemplateResolver(), (_, _) => null, fake.ToBindings())!;
|
|
|
|
KeyboardConfigController.RowView row = controller.Rows.Single();
|
|
Assert.NotEmpty(row.KeyButtons);
|
|
|
|
row.KeyButtons[0].OnClick!.Invoke();
|
|
Assert.NotNull(fake.PendingCapture);
|
|
fake.Capture(ChordW);
|
|
|
|
Assert.Contains(ChordW, row.Model.Current);
|
|
(InputAction Action, IReadOnlyList<Binding> Value) written = Assert.Single(fake.MappedSets);
|
|
Assert.Equal(InputAction.MovementForward, written.Action);
|
|
Binding onlyBinding = Assert.Single(written.Value);
|
|
Assert.Equal(ChordW, onlyBinding.Chord);
|
|
// No live binding existed at build time — falls back to the Binding
|
|
// record's own defaults (Press/Game), same as before M1.
|
|
Assert.Equal(ActivationType.Press, onlyBinding.Activation);
|
|
Assert.Equal(InputScope.Game, onlyBinding.Scope);
|
|
Assert.Equal("W", row.KeyButtons[0].Label);
|
|
}
|
|
|
|
[Fact]
|
|
public void KeyButtonCapture_EscapeCancel_LeavesBindingUnchanged()
|
|
{
|
|
var snapshot = new RetailActionMapSnapshot(new[] { Row(0x4, 0x29, RetailActionClass.Movement) });
|
|
var fake = new FakeBindings();
|
|
fake.Mapped[InputAction.MovementForward] = new List<Binding> { new(ChordW, InputAction.MovementForward) };
|
|
ImportedLayout layout = FixtureLoader.LoadKeyboardConfig();
|
|
KeyboardConfigController controller = KeyboardConfigController.Bind(
|
|
layout, snapshot, MakeTemplateResolver(), (_, _) => null, fake.ToBindings())!;
|
|
|
|
KeyboardConfigController.RowView row = controller.Rows.Single();
|
|
row.KeyButtons[0].OnClick!.Invoke();
|
|
fake.Capture(null); // Escape sentinel
|
|
|
|
Assert.Equal(new[] { ChordW }, row.Model.Current);
|
|
Assert.Empty(fake.MappedSets);
|
|
}
|
|
|
|
[Fact]
|
|
public void KeyButtonRightClick_ErasesThatSlot()
|
|
{
|
|
var snapshot = new RetailActionMapSnapshot(new[] { Row(0x4, 0x29, RetailActionClass.Movement) });
|
|
var fake = new FakeBindings();
|
|
fake.Mapped[InputAction.MovementForward] = new List<Binding>
|
|
{
|
|
new(ChordW, InputAction.MovementForward),
|
|
new(ChordUp, InputAction.MovementForward),
|
|
};
|
|
ImportedLayout layout = FixtureLoader.LoadKeyboardConfig();
|
|
KeyboardConfigController controller = KeyboardConfigController.Bind(
|
|
layout, snapshot, MakeTemplateResolver(), (_, _) => null, fake.ToBindings())!;
|
|
|
|
KeyboardConfigController.RowView row = controller.Rows.Single();
|
|
Assert.Equal(2, row.Model.Current.Count);
|
|
|
|
row.KeyButtons[0].OnRightClick!.Invoke();
|
|
|
|
Assert.Single(row.Model.Current);
|
|
Assert.DoesNotContain(ChordW, row.Model.Current);
|
|
}
|
|
|
|
[Fact]
|
|
public void KeyButtonRightClick_OnAlreadyEmptySlot_IsANoOp()
|
|
{
|
|
var snapshot = new RetailActionMapSnapshot(new[] { Row(0x4, 0x29, RetailActionClass.Movement) });
|
|
var fake = new FakeBindings();
|
|
ImportedLayout layout = FixtureLoader.LoadKeyboardConfig();
|
|
KeyboardConfigController controller = KeyboardConfigController.Bind(
|
|
layout, snapshot, MakeTemplateResolver(), (_, _) => null, fake.ToBindings())!;
|
|
|
|
KeyboardConfigController.RowView row = controller.Rows.Single();
|
|
Assert.Empty(row.Model.Current);
|
|
|
|
row.KeyButtons[0].OnRightClick!.Invoke();
|
|
|
|
Assert.Empty(row.Model.Current);
|
|
Assert.Empty(fake.MappedSets);
|
|
}
|
|
|
|
/// <summary>S4 (2026-08-11 review): clicking "Mapping 3" (slot index 2) on a
|
|
/// row with NO existing bindings must land the captured chord on display
|
|
/// index 2, not collapse it onto index 0.</summary>
|
|
[Fact]
|
|
public void KeyButtonClick_OnSparseRow_ThirdSlotLandsOnThirdButton()
|
|
{
|
|
var snapshot = new RetailActionMapSnapshot(new[] { Row(0x4, 0x29, RetailActionClass.Movement) });
|
|
var fake = new FakeBindings();
|
|
ImportedLayout layout = FixtureLoader.LoadKeyboardConfig();
|
|
KeyboardConfigController controller = KeyboardConfigController.Bind(
|
|
layout, snapshot, MakeTemplateResolver(), (_, _) => null, fake.ToBindings())!;
|
|
|
|
KeyboardConfigController.RowView row = controller.Rows.Single();
|
|
Assert.Equal(3, row.KeyButtons.Count);
|
|
Assert.Empty(row.Model.Current);
|
|
|
|
row.KeyButtons[2].OnClick!.Invoke(); // "Mapping 3"
|
|
fake.Capture(ChordW);
|
|
|
|
Assert.Null(row.KeyButtons[0].Label);
|
|
Assert.Null(row.KeyButtons[1].Label);
|
|
Assert.Equal("W", row.KeyButtons[2].Label);
|
|
|
|
// The write to the live seam only ever carries the REAL chord — no
|
|
// default(KeyChord) padding leaks into the persisted Binding list.
|
|
(InputAction Action, IReadOnlyList<Binding> Value) written = Assert.Single(fake.MappedSets);
|
|
Binding onlyBinding = Assert.Single(written.Value);
|
|
Assert.Equal(ChordW, onlyBinding.Chord);
|
|
}
|
|
|
|
[Fact]
|
|
public void Capture_ConflictWithAnotherRow_OpensConfirmDialog_AcceptReassigns()
|
|
{
|
|
var snapshot = new RetailActionMapSnapshot(new[]
|
|
{
|
|
Row(0x4, 0x29, RetailActionClass.Movement), // MovementForward
|
|
Row(0x4, 0x2A, RetailActionClass.Movement), // MovementBackup — will hold ChordA
|
|
});
|
|
var fake = new FakeBindings();
|
|
fake.Mapped[InputAction.MovementBackup] = new List<Binding> { new(ChordA, InputAction.MovementBackup) };
|
|
ImportedLayout layout = FixtureLoader.LoadKeyboardConfig();
|
|
KeyboardConfigController controller = KeyboardConfigController.Bind(
|
|
layout, snapshot, MakeTemplateResolver(), (_, _) => null, fake.ToBindings())!;
|
|
|
|
KeyboardConfigController.RowView forward = controller.Rows.Single(r => r.ActionId == 0x29u);
|
|
KeyboardConfigController.RowView backup = controller.Rows.Single(r => r.ActionId == 0x2Au);
|
|
|
|
forward.KeyButtons[0].OnClick!.Invoke();
|
|
fake.Capture(ChordA); // steal MovementBackup's chord
|
|
|
|
// M3: nothing is applied yet — a confirm dialog is pending.
|
|
Assert.NotNull(fake.PendingConfirm);
|
|
Assert.DoesNotContain(ChordA, forward.Model.Current);
|
|
Assert.Contains(ChordA, backup.Model.Current);
|
|
Assert.Empty(fake.Messages);
|
|
|
|
fake.RespondToConfirm(true);
|
|
|
|
Assert.Contains(ChordA, forward.Model.Current);
|
|
Assert.DoesNotContain(ChordA, backup.Model.Current);
|
|
}
|
|
|
|
[Fact]
|
|
public void Capture_ConflictWithAnotherRow_DeclineLeavesBothRowsUnchanged()
|
|
{
|
|
var snapshot = new RetailActionMapSnapshot(new[]
|
|
{
|
|
Row(0x4, 0x29, RetailActionClass.Movement),
|
|
Row(0x4, 0x2A, RetailActionClass.Movement),
|
|
});
|
|
var fake = new FakeBindings();
|
|
fake.Mapped[InputAction.MovementForward] = new List<Binding> { new(ChordW, InputAction.MovementForward) };
|
|
fake.Mapped[InputAction.MovementBackup] = new List<Binding> { new(ChordA, InputAction.MovementBackup) };
|
|
ImportedLayout layout = FixtureLoader.LoadKeyboardConfig();
|
|
KeyboardConfigController controller = KeyboardConfigController.Bind(
|
|
layout, snapshot, MakeTemplateResolver(), (_, _) => null, fake.ToBindings())!;
|
|
|
|
KeyboardConfigController.RowView forward = controller.Rows.Single(r => r.ActionId == 0x29u);
|
|
KeyboardConfigController.RowView backup = controller.Rows.Single(r => r.ActionId == 0x2Au);
|
|
|
|
forward.KeyButtons[0].OnClick!.Invoke();
|
|
fake.Capture(ChordA);
|
|
fake.RespondToConfirm(false);
|
|
|
|
Assert.Equal(new[] { ChordW }, forward.Model.Current); // untouched
|
|
Assert.Equal(new[] { ChordA }, backup.Model.Current); // untouched
|
|
}
|
|
|
|
[Fact]
|
|
public void Capture_ConflictWithNonBindableAcdreamAction_RefusesWithoutADialog()
|
|
{
|
|
var snapshot = new RetailActionMapSnapshot(new[] { Row(0x4, 0x29, RetailActionClass.Movement) });
|
|
var fake = new FakeBindings();
|
|
// AcdreamToggleAudioMute has no RetailActionIdentityTable row at all.
|
|
var muteChord = new KeyChord(Silk.NET.Input.Key.M, ModifierMask.Ctrl);
|
|
fake.Mapped[InputAction.AcdreamToggleAudioMute] =
|
|
new List<Binding> { new(muteChord, InputAction.AcdreamToggleAudioMute) };
|
|
ImportedLayout layout = FixtureLoader.LoadKeyboardConfig();
|
|
KeyboardConfigController controller = KeyboardConfigController.Bind(
|
|
layout, snapshot, MakeTemplateResolver(), (_, _) => null, fake.ToBindings())!;
|
|
|
|
KeyboardConfigController.RowView forward = controller.Rows.Single();
|
|
forward.KeyButtons[0].OnClick!.Invoke();
|
|
fake.Capture(muteChord);
|
|
|
|
// S1: refused outright, no confirm dialog offered.
|
|
Assert.Null(fake.PendingConfirm);
|
|
Assert.DoesNotContain(muteChord, forward.Model.Current);
|
|
Assert.Contains("cannot overwrite", fake.Messages);
|
|
Assert.Equal(muteChord, Assert.Single(fake.Mapped[InputAction.AcdreamToggleAudioMute]).Chord);
|
|
}
|
|
|
|
/// <summary>S1: retail checks the non-user-bindable target BEFORE any
|
|
/// user-bindable row conflict, even when both exist for the same chord.</summary>
|
|
[Fact]
|
|
public void Capture_ConflictWithBothARowAndANonBindableAction_NonBindableWins()
|
|
{
|
|
var snapshot = new RetailActionMapSnapshot(new[]
|
|
{
|
|
Row(0x4, 0x29, RetailActionClass.Movement),
|
|
Row(0x4, 0x2A, RetailActionClass.Movement),
|
|
});
|
|
var fake = new FakeBindings();
|
|
var sharedChord = new KeyChord(Silk.NET.Input.Key.M, ModifierMask.Ctrl);
|
|
fake.Mapped[InputAction.MovementBackup] = new List<Binding> { new(sharedChord, InputAction.MovementBackup) };
|
|
fake.Mapped[InputAction.AcdreamToggleAudioMute] =
|
|
new List<Binding> { new(sharedChord, InputAction.AcdreamToggleAudioMute) };
|
|
ImportedLayout layout = FixtureLoader.LoadKeyboardConfig();
|
|
KeyboardConfigController controller = KeyboardConfigController.Bind(
|
|
layout, snapshot, MakeTemplateResolver(), (_, _) => null, fake.ToBindings())!;
|
|
|
|
KeyboardConfigController.RowView forward = controller.Rows.Single(r => r.ActionId == 0x29u);
|
|
forward.KeyButtons[0].OnClick!.Invoke();
|
|
fake.Capture(sharedChord);
|
|
|
|
Assert.Null(fake.PendingConfirm);
|
|
Assert.Contains("cannot overwrite", fake.Messages);
|
|
Assert.DoesNotContain(sharedChord, forward.Model.Current);
|
|
}
|
|
|
|
[Fact]
|
|
public void OkButton_AppliesCommitsSavesAndToggles()
|
|
{
|
|
var snapshot = new RetailActionMapSnapshot(new[] { Row(0x4, 0x29, RetailActionClass.Movement) });
|
|
var fake = new FakeBindings();
|
|
ImportedLayout layout = FixtureLoader.LoadKeyboardConfig();
|
|
KeyboardConfigController controller = KeyboardConfigController.Bind(
|
|
layout, snapshot, MakeTemplateResolver(), (_, _) => null, fake.ToBindings())!;
|
|
|
|
KeyboardConfigController.RowView row = controller.Rows.Single();
|
|
row.KeyButtons[0].OnClick!.Invoke();
|
|
fake.Capture(ChordW);
|
|
Assert.True(row.Model.Changed);
|
|
|
|
UiButton ok = (UiButton)layout.FindElement(0x1000002Cu)!;
|
|
ok.OnClick!.Invoke();
|
|
|
|
Assert.False(row.Model.Changed); // Apply committed saved=current
|
|
Assert.Equal(1, fake.SaveCalls);
|
|
Assert.Equal(1, fake.ToggleCalls);
|
|
}
|
|
|
|
[Fact]
|
|
public void CancelButton_RevertsUncommittedEditAndToggles()
|
|
{
|
|
var snapshot = new RetailActionMapSnapshot(new[] { Row(0x4, 0x29, RetailActionClass.Movement) });
|
|
var fake = new FakeBindings();
|
|
fake.Mapped[InputAction.MovementForward] = new List<Binding> { new(ChordW, InputAction.MovementForward) };
|
|
ImportedLayout layout = FixtureLoader.LoadKeyboardConfig();
|
|
KeyboardConfigController controller = KeyboardConfigController.Bind(
|
|
layout, snapshot, MakeTemplateResolver(), (_, _) => null, fake.ToBindings())!;
|
|
|
|
KeyboardConfigController.RowView row = controller.Rows.Single();
|
|
row.KeyButtons[0].OnClick!.Invoke();
|
|
fake.Capture(ChordUp); // now [Up] uncommitted (slot 0 replaced)
|
|
|
|
UiButton cancel = (UiButton)layout.FindElement(0x1000002Du)!;
|
|
cancel.OnClick!.Invoke();
|
|
|
|
Assert.Equal(new[] { ChordW }, row.Model.Current); // reverted to Saved
|
|
Assert.Equal(1, fake.ToggleCalls);
|
|
Assert.Equal(0, fake.SaveCalls);
|
|
}
|
|
|
|
[Fact]
|
|
public void DefaultsButton_RestoresDatDefaultLive_WithoutCommitting()
|
|
{
|
|
var snapshot = new RetailActionMapSnapshot(new[]
|
|
{
|
|
Row(0x4, 0x29, RetailActionClass.Movement, defaults:
|
|
new[] { new RetailKeyChord(0x11, 0, 0, 3) }), // DIK_W
|
|
});
|
|
var fake = new FakeBindings();
|
|
fake.Mapped[InputAction.MovementForward] = new List<Binding> { new(ChordUp, InputAction.MovementForward) };
|
|
ImportedLayout layout = FixtureLoader.LoadKeyboardConfig();
|
|
KeyboardConfigController controller = KeyboardConfigController.Bind(
|
|
layout, snapshot, MakeTemplateResolver(), (_, _) => null, fake.ToBindings())!;
|
|
|
|
KeyboardConfigController.RowView row = controller.Rows.Single();
|
|
Assert.Equal(new[] { ChordUp }, row.Model.Current);
|
|
|
|
UiButton defaultsButton = (UiButton)layout.FindElement(0x1000002Au)!;
|
|
defaultsButton.OnClick!.Invoke();
|
|
|
|
Assert.Equal(new[] { ChordW }, row.Model.Current);
|
|
Assert.True(row.Model.Changed); // live but uncommitted, matching retail
|
|
}
|
|
|
|
/// <summary>M1 (2026-08-11 review): Defaults must restore the DAT-sourced
|
|
/// KEY only — the row's live Activation/Scope (Hold + MeleeCombat here,
|
|
/// captured from the action's live binding at build time) must survive the
|
|
/// click unchanged, across the FULL 306-row shape this test represents with
|
|
/// one Hold+scoped action.</summary>
|
|
[Fact]
|
|
public void DefaultsButton_PreservesActivationAndScope_ForAHoldScopedAction()
|
|
{
|
|
var snapshot = new RetailActionMapSnapshot(new[]
|
|
{
|
|
Row(0x10000003, 0x1000005D, RetailActionClass.Combat, defaults:
|
|
new[] { new RetailKeyChord(0xD3, 0, 0, 3) }), // CombatLowAttack, DIK_DELETE
|
|
});
|
|
var fake = new FakeBindings();
|
|
fake.Mapped[InputAction.CombatLowAttack] = new List<Binding>
|
|
{
|
|
new(ChordUp, InputAction.CombatLowAttack, ActivationType.Hold, InputScope.MeleeCombat),
|
|
};
|
|
ImportedLayout layout = FixtureLoader.LoadKeyboardConfig();
|
|
KeyboardConfigController controller = KeyboardConfigController.Bind(
|
|
layout, snapshot, MakeTemplateResolver(), (_, _) => null, fake.ToBindings())!;
|
|
|
|
UiButton defaultsButton = (UiButton)layout.FindElement(0x1000002Au)!;
|
|
defaultsButton.OnClick!.Invoke();
|
|
|
|
(InputAction Action, IReadOnlyList<Binding> Value) written = Assert.Single(fake.MappedSets);
|
|
Assert.Equal(InputAction.CombatLowAttack, written.Action);
|
|
Binding result = Assert.Single(written.Value);
|
|
Assert.Equal(Silk.NET.Input.Key.Delete, result.Chord.Key); // the DAT default key
|
|
Assert.Equal(ActivationType.Hold, result.Activation); // preserved, not reset to Press
|
|
Assert.Equal(InputScope.MeleeCombat, result.Scope); // preserved, not reset to Game
|
|
}
|
|
|
|
/// <summary>M1: Cancel/Revert (RestoreSavedValue) must ALSO preserve
|
|
/// Activation/Scope, not just Defaults.</summary>
|
|
[Fact]
|
|
public void CancelButton_PreservesActivationAndScope()
|
|
{
|
|
var snapshot = new RetailActionMapSnapshot(new[] { Row(0x4, 0x32, RetailActionClass.Movement) });
|
|
var fake = new FakeBindings();
|
|
fake.Mapped[InputAction.MovementWalkMode] = new List<Binding>
|
|
{
|
|
new(ChordW, InputAction.MovementWalkMode, ActivationType.Hold, InputScope.Game),
|
|
};
|
|
ImportedLayout layout = FixtureLoader.LoadKeyboardConfig();
|
|
KeyboardConfigController controller = KeyboardConfigController.Bind(
|
|
layout, snapshot, MakeTemplateResolver(), (_, _) => null, fake.ToBindings())!;
|
|
|
|
KeyboardConfigController.RowView row = controller.Rows.Single();
|
|
row.KeyButtons[0].OnClick!.Invoke();
|
|
fake.Capture(ChordUp); // uncommitted edit
|
|
|
|
UiButton cancel = (UiButton)layout.FindElement(0x1000002Du)!;
|
|
cancel.OnClick!.Invoke();
|
|
|
|
// MappedSets also carries the capture's own write (ChordUp) before the
|
|
// revert — take the LAST write, which is Cancel's RestoreSavedValue.
|
|
(InputAction Action, IReadOnlyList<Binding> Value) written = fake.MappedSets[^1];
|
|
Binding result = Assert.Single(written.Value);
|
|
Assert.Equal(ChordW, result.Chord); // reverted to saved
|
|
Assert.Equal(ActivationType.Hold, result.Activation);
|
|
}
|
|
|
|
/// <summary>M2 (2026-08-11 review): InputMap 0x6 (CameraAlternateControls) no
|
|
/// longer aliases InputMap 0x5's (CameraControls) InputAction — each row is
|
|
/// independent, so rebinding one never clobbers the other, and a row cannot
|
|
/// conflict with its own former twin.</summary>
|
|
[Fact]
|
|
public void CameraContext5And6_AreIndependentRows_NotAliased()
|
|
{
|
|
var snapshot = new RetailActionMapSnapshot(new[]
|
|
{
|
|
Row(0x5, 0x35, RetailActionClass.Camera, defaults: new[] { new RetailKeyChord(0x4B, 0, 0, 3) }),
|
|
Row(0x6, 0x35, RetailActionClass.Camera, defaults: new[] { new RetailKeyChord(0xCB, 0, 0, 3) }),
|
|
});
|
|
var fake = new FakeBindings();
|
|
ImportedLayout layout = FixtureLoader.LoadKeyboardConfig();
|
|
KeyboardConfigController controller = KeyboardConfigController.Bind(
|
|
layout, snapshot, MakeTemplateResolver(), (_, _) => null, fake.ToBindings())!;
|
|
|
|
KeyboardConfigController.RowView ctx5 = controller.Rows.Single(r => r.InputMapId == 0x5u);
|
|
KeyboardConfigController.RowView ctx6 = controller.Rows.Single(r => r.InputMapId == 0x6u);
|
|
|
|
Assert.Equal(InputAction.CameraRotateLeft, ctx5.MappedAction);
|
|
Assert.Null(ctx6.MappedAction); // unmapped — no live dual-binding infrastructure (M2)
|
|
|
|
// Round-2 SHOULD-FIX: an unmapped row with no persisted chords now
|
|
// DISPLAYS its DAT defaults (retail shows the arrow keys; blank read
|
|
// as "unbound"). Display-only — storage stays untouched until the
|
|
// user edits THIS row.
|
|
Assert.NotEmpty(ctx6.Model.Current);
|
|
var ctx6InitialDisplay = ctx6.Model.Current.ToArray();
|
|
|
|
// Rebinding ctx5's row must not touch ctx6's display or storage.
|
|
ctx5.KeyButtons[0].OnClick!.Invoke();
|
|
fake.Capture(ChordW);
|
|
Assert.Contains(ChordW, ctx5.Model.Current);
|
|
Assert.Equal(ctx6InitialDisplay, ctx6.Model.Current); // unchanged by ctx5's edit
|
|
Assert.Empty(fake.Unmapped); // ctx6's STORE untouched — display seeding writes nothing
|
|
|
|
ctx6.KeyButtons[0].OnClick!.Invoke();
|
|
fake.Capture(ChordA);
|
|
Assert.Contains(ChordA, ctx6.Model.Current);
|
|
Assert.Contains(ChordW, ctx5.Model.Current); // ctx5 unaffected by ctx6's edit
|
|
Assert.True(fake.Unmapped.ContainsKey((0x6u, 0x35u)));
|
|
}
|
|
|
|
[Fact]
|
|
public void Bind_MissingWindowRoot_ReturnsNull()
|
|
{
|
|
ElementInfo empty = new() { Id = 0x99999999u, Type = 3 };
|
|
ImportedLayout emptyLayout = LayoutImporter.Build(empty, NoTex, null);
|
|
var snapshot = new RetailActionMapSnapshot(Array.Empty<RetailActionMapRow>());
|
|
var fake = new FakeBindings();
|
|
|
|
KeyboardConfigController? controller = KeyboardConfigController.Bind(
|
|
emptyLayout, snapshot, (_, _) => null, (_, _) => null, fake.ToBindings());
|
|
|
|
Assert.Null(controller);
|
|
}
|
|
|
|
// ── OP8 re-review round 2: identity-map injectivity is load-bearing for
|
|
// BOTH M1 (per-row activation capture) and M2 (no dual rows editing one
|
|
// action) — pin it so a future mapping addition cannot silently alias. ──
|
|
|
|
[Fact]
|
|
public void IdentityMap_IsInjective_NoTwoRowsShareOneInputAction()
|
|
{
|
|
var seen = new Dictionary<InputAction, (uint MapId, uint ActionId)>();
|
|
foreach (((uint mapId, uint actionId), InputAction action) in RetailActionIdentityTable.Map)
|
|
{
|
|
Assert.False(
|
|
seen.TryGetValue(action, out (uint MapId, uint ActionId) prior),
|
|
$"InputAction.{action} is mapped by BOTH (0x{prior.MapId:X}, 0x{prior.ActionId:X}) "
|
|
+ $"and (0x{mapId:X}, 0x{actionId:X}) — aliasing reintroduces the M2 twin-row clobber.");
|
|
seen[action] = (mapId, actionId);
|
|
}
|
|
Assert.True(seen.Count > 100, $"sanity: only {seen.Count} mapped actions seen");
|
|
}
|
|
|
|
// ── AD-78 caption dimming (user-directed, 2026-08-11, gate 2) ───────────
|
|
|
|
[Fact]
|
|
public void UnmappedRows_DimTheirCaption_MappedRowsStayWhite()
|
|
{
|
|
// AP-203's store-only set: a row whose RetailActionIdentityTable
|
|
// lookup fails (MappedAction null -- mostly Emotes/CharacterSettings)
|
|
// never reaches the InputDispatcher, so its caption dims. Wiring a
|
|
// future mapping for "Bow Deep" (or any other unmapped row) means
|
|
// this assertion flips from StoreOnlyCaptionColor to Vector4.One --
|
|
// a conscious edit, not a silent pass.
|
|
var snapshot = new RetailActionMapSnapshot(new[]
|
|
{
|
|
Row(0x4, 0x29, RetailActionClass.Movement), // -> MovementForward (mapped)
|
|
Row(0x10000006, 0x100000A0, RetailActionClass.Emote), // "Bow Deep" -> unmapped
|
|
});
|
|
|
|
ImportedLayout layout = FixtureLoader.LoadKeyboardConfig();
|
|
var fake = new FakeBindings();
|
|
KeyboardConfigController controller = KeyboardConfigController.Bind(
|
|
layout, snapshot, MakeTemplateResolver(), (_, _) => null, fake.ToBindings())!;
|
|
|
|
KeyboardConfigController.RowView forward = controller.Rows.Single(r => r.ActionId == 0x29u);
|
|
Assert.NotNull(forward.MappedAction);
|
|
UiText forwardCaption = RowCaption(forward);
|
|
Assert.Equal(Vector4.One, forwardCaption.DefaultColor);
|
|
|
|
KeyboardConfigController.RowView bowDeep = controller.Rows.Single(r => r.ActionId == 0x100000A0u);
|
|
Assert.Null(bowDeep.MappedAction);
|
|
UiText bowDeepCaption = RowCaption(bowDeep);
|
|
Assert.Equal(UiRenderContext.StoreOnlyCaptionColor, bowDeepCaption.DefaultColor);
|
|
}
|
|
|
|
/// <summary>The row's synthesized caption (composed beside the authored key
|
|
/// buttons -- see KeyboardConfigController's class doc) has no stable dat
|
|
/// element id of its own, so it is located structurally: the ONLY
|
|
/// <see cref="UiText"/> direct child of the key buttons' shared parent
|
|
/// (the row container <c>BuildActionRow</c> builds).</summary>
|
|
private static UiText RowCaption(KeyboardConfigController.RowView row)
|
|
{
|
|
UiElement parent = row.KeyButtons.First().Parent
|
|
?? throw new InvalidOperationException("row's key button has no parent element");
|
|
return parent.Children.OfType<UiText>().Single();
|
|
}
|
|
}
|