Lower provider-authored cockpit overlays
This commit is contained in:
parent
84d781c4b1
commit
4d0cbe0185
4 changed files with 72 additions and 5 deletions
|
|
@ -27,6 +27,13 @@ Nested CultUI regions use component `EmbeddedDocuments`. Pass an
|
|||
mounts the resolved child surface under the slot while preserving the child
|
||||
document's command surface id.
|
||||
|
||||
`progress` components lower to native UI Toolkit `ProgressBar` elements. The
|
||||
provider supplies a normalized `ratio` (falling back to `value`), label, and
|
||||
layout; Unity clamps the native visual to `[0,1]` without becoming the value
|
||||
authority. Generated layout supports relative or absolute positioning plus
|
||||
`inset`, `top`, `right`, `bottom`, and `left`, so provider-authored overlays
|
||||
can compose over scene lowerers without consumer-specific HUD code.
|
||||
|
||||
Discovery and test coverage for this feature live in the shared Eve parity
|
||||
matrix: `../../tools/parity/parity-manifest.json` names `embeddedDocuments` and
|
||||
`../../web/fixtures/cultui-embedded-surface.json` is the canonical fixture.
|
||||
|
|
|
|||
|
|
@ -129,11 +129,14 @@ namespace GameCult.Eve.UnityUIToolkit
|
|||
}
|
||||
case "progress":
|
||||
{
|
||||
var progress = new VisualElement();
|
||||
var progress = new ProgressBar
|
||||
{
|
||||
title = component.GetProp("label"),
|
||||
lowValue = 0f,
|
||||
highValue = 1f,
|
||||
value = ParseRatio(component.GetProp("ratio", component.GetProp("value")))
|
||||
};
|
||||
progress.AddToClassList("eve-progress");
|
||||
progress.style.flexDirection = FlexDirection.Column;
|
||||
progress.Add(MutedLabel(component.GetProp("label")));
|
||||
progress.Add(ValueLabel(component.GetProp("value")));
|
||||
return progress;
|
||||
}
|
||||
case "options":
|
||||
|
|
@ -313,6 +316,26 @@ namespace GameCult.Eve.UnityUIToolkit
|
|||
element.style.display = string.Equals(display, "none", StringComparison.OrdinalIgnoreCase)
|
||||
? DisplayStyle.None
|
||||
: DisplayStyle.Flex;
|
||||
if (TryGet(layout, "position", out var position))
|
||||
element.style.position = string.Equals(position, "absolute", StringComparison.OrdinalIgnoreCase)
|
||||
? Position.Absolute
|
||||
: Position.Relative;
|
||||
if (TryGet(layout, "inset", out var inset))
|
||||
{
|
||||
var value = ParseLength(inset);
|
||||
element.style.top = value;
|
||||
element.style.right = value;
|
||||
element.style.bottom = value;
|
||||
element.style.left = value;
|
||||
}
|
||||
if (TryGet(layout, "top", out var top))
|
||||
element.style.top = ParseLength(top);
|
||||
if (TryGet(layout, "right", out var right))
|
||||
element.style.right = ParseLength(right);
|
||||
if (TryGet(layout, "bottom", out var bottom))
|
||||
element.style.bottom = ParseLength(bottom);
|
||||
if (TryGet(layout, "left", out var left))
|
||||
element.style.left = ParseLength(left);
|
||||
if (TryGet(layout, "direction", out var direction))
|
||||
{
|
||||
if (string.Equals(direction, "horizontal", StringComparison.OrdinalIgnoreCase) ||
|
||||
|
|
@ -430,6 +453,13 @@ namespace GameCult.Eve.UnityUIToolkit
|
|||
: StyleKeyword.Null;
|
||||
}
|
||||
|
||||
private static float ParseRatio(string value)
|
||||
{
|
||||
return float.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out var ratio)
|
||||
? Mathf.Clamp01(ratio)
|
||||
: 0f;
|
||||
}
|
||||
|
||||
private static void ApplyBoxLength(string value, Action<StyleLength> apply)
|
||||
{
|
||||
apply(ParseLength(value));
|
||||
|
|
|
|||
|
|
@ -112,6 +112,36 @@ namespace GameCult.Eve.UnityUIToolkit.Tests
|
|||
Assert.That(embedded.ClassListContains("eve-embedded-kind-inline"), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProgressAndAbsoluteLayoutLowerToNativeUiToolkitPrimitives()
|
||||
{
|
||||
var progress = new EveSurfaceComponent(
|
||||
"hull",
|
||||
"progress",
|
||||
new Dictionary<string, string>
|
||||
{
|
||||
["label"] = "Hull",
|
||||
["ratio"] = "0.625"
|
||||
},
|
||||
Array.Empty<EveSurfaceComponent>(),
|
||||
Array.Empty<CultMeshStateBindingDescriptor>(),
|
||||
Array.Empty<EveEmbeddedDocumentSlot>(),
|
||||
new Dictionary<string, string>
|
||||
{
|
||||
["position"] = "absolute",
|
||||
["right"] = "24",
|
||||
["bottom"] = "32"
|
||||
});
|
||||
|
||||
var root = new EveUiToolkitSurfaceLowerer().Lower(Document(progress));
|
||||
|
||||
Assert.That(root, Is.TypeOf<ProgressBar>());
|
||||
Assert.That(((ProgressBar)root).value, Is.EqualTo(0.625f));
|
||||
Assert.That(root.style.position.value, Is.EqualTo(Position.Absolute));
|
||||
Assert.That(root.style.right.value.value, Is.EqualTo(24f));
|
||||
Assert.That(root.style.bottom.value.value, Is.EqualTo(32f));
|
||||
}
|
||||
|
||||
private static EveSurfaceDocument Document(EveSurfaceComponent root, string surfaceId = "test-surface")
|
||||
{
|
||||
return new EveSurfaceDocument(
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "org.gamecult.eve.unity-uitoolkit",
|
||||
"displayName": "Eve UI Toolkit Lowering",
|
||||
"version": "0.1.0",
|
||||
"version": "0.1.1",
|
||||
"unity": "2021.3",
|
||||
"description": "Unity UI Toolkit lowering for gamecult.eve.surface.v1 documents.",
|
||||
"dependencies": {
|
||||
|
|
|
|||
Reference in a new issue