feat(ui): centralize retail selection state
This commit is contained in:
parent
c7607f019c
commit
7983309d23
30 changed files with 591 additions and 108 deletions
|
|
@ -4,6 +4,7 @@ using System.Linq;
|
|||
using System.Numerics;
|
||||
using AcDream.App.UI;
|
||||
using AcDream.App.UI.Layout;
|
||||
using AcDream.Core.Selection;
|
||||
using Xunit;
|
||||
|
||||
namespace AcDream.App.Tests.UI.Layout;
|
||||
|
|
@ -65,7 +66,7 @@ public class SelectedObjectControllerTests
|
|||
|
||||
private sealed class Harness
|
||||
{
|
||||
public Action<uint?>? SelectionHandler;
|
||||
public readonly SelectionState Selection = new();
|
||||
public Action<uint, float>? HealthHandler;
|
||||
public readonly List<uint> QueryHealthCalls = new();
|
||||
|
||||
|
|
@ -75,17 +76,19 @@ public class SelectedObjectControllerTests
|
|||
public readonly Dictionary<uint, bool> HasHealthMap = new();
|
||||
public readonly Dictionary<uint, uint> StackMap = new();
|
||||
|
||||
public void FireSelection(uint? g) => SelectionHandler?.Invoke(g);
|
||||
public void FireSelection(uint? g)
|
||||
{
|
||||
if (g is { } guid)
|
||||
Selection.Select(guid, SelectionChangeSource.System);
|
||||
else
|
||||
Selection.Clear(SelectionChangeSource.System);
|
||||
}
|
||||
public void FireHealth(uint g, float pct) => HealthHandler?.Invoke(g, pct);
|
||||
|
||||
public SelectedObjectController Bind(ImportedLayout layout, UiDatFont? datFont = null)
|
||||
=> SelectedObjectController.Bind(
|
||||
layout,
|
||||
subscribeSelectionChanged: h => SelectionHandler = h,
|
||||
unsubscribeSelectionChanged: h =>
|
||||
{
|
||||
if (SelectionHandler == h) SelectionHandler = null;
|
||||
},
|
||||
selection: Selection,
|
||||
subscribeHealthChanged: h => HealthHandler = h,
|
||||
unsubscribeHealthChanged: h =>
|
||||
{
|
||||
|
|
@ -362,7 +365,6 @@ public class SelectedObjectControllerTests
|
|||
h.NameMap[0x12345678u] = "Something";
|
||||
var c = h.Bind(layout);
|
||||
|
||||
Assert.NotNull(h.SelectionHandler);
|
||||
Assert.Null(Record.Exception(() => h.FireSelection(0x12345678u)));
|
||||
Assert.Null(Record.Exception(() => h.FireHealth(0x12345678u, 0.5f)));
|
||||
Assert.Null(Record.Exception(() => c.Tick(0.5)));
|
||||
|
|
@ -425,7 +427,6 @@ public class SelectedObjectControllerTests
|
|||
h.FireSelection(0xAA09u);
|
||||
h.FireHealth(0xAA09u, 0.5f);
|
||||
|
||||
Assert.Null(h.SelectionHandler);
|
||||
Assert.Null(h.HealthHandler);
|
||||
Assert.False(healthMeterEl.Visible);
|
||||
Assert.Empty(h.QueryHealthCalls);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue