feat(ui): port retained widget foundations
This commit is contained in:
parent
44f9ec13d9
commit
d825572e31
44 changed files with 84813 additions and 292 deletions
|
|
@ -10,11 +10,10 @@ namespace AcDream.App.UI.Layout;
|
|||
/// <see cref="UiDatElement"/>.
|
||||
///
|
||||
/// <para>
|
||||
/// Type 12 = UIElement_Text — a scrollable colored-line text view. Every Type-12
|
||||
/// element is now built as a <see cref="UiText"/>. Elements that carry their own
|
||||
/// dat sprite media keep it as the <see cref="UiText.BackgroundSprite"/>. Pure
|
||||
/// prototype elements (no state media, no controller binding) draw nothing because
|
||||
/// <see cref="UiText.BackgroundColor"/> defaults to transparent.
|
||||
/// Type 12 = UIElement_Text. Editable `0x16` elements become <see cref="UiField"/>
|
||||
/// in place; other elements become display/selectable <see cref="UiText"/> widgets.
|
||||
/// Elements that carry their own DAT sprite media keep it as widget background art.
|
||||
/// Pure prototype elements draw nothing because text backgrounds default transparent.
|
||||
/// </para>
|
||||
///
|
||||
/// <para>
|
||||
|
|
@ -102,9 +101,31 @@ public static class DatWidgetFactory
|
|||
e.ZOrder = (int)info.ReadOrder - (int)info.ZLevel * 10000;
|
||||
|
||||
// Map the four raw edge-anchor values to the AnchorEdges bit-flag that the
|
||||
// UI layout engine uses for reflow.
|
||||
// compatibility layout engine uses for programmatic overrides.
|
||||
e.Anchors = ElementReader.ToAnchors(info.Left, info.Top, info.Right, info.Bottom);
|
||||
|
||||
// Imported descendants use the exact four-mode retail policy. Roots have no
|
||||
// design parent and intentionally remain on the compatibility path until a
|
||||
// window mount assigns its own outer-frame policy.
|
||||
if (info.HasOriginalParentSize)
|
||||
{
|
||||
e.LayoutPolicy = new UiLayoutPolicy(
|
||||
info.Left,
|
||||
info.Top,
|
||||
info.Right,
|
||||
info.Bottom,
|
||||
UiPixelRect.FromPositionAndSize(
|
||||
(int)info.X,
|
||||
(int)info.Y,
|
||||
(int)info.Width,
|
||||
(int)info.Height),
|
||||
UiPixelRect.FromPositionAndSize(
|
||||
0,
|
||||
0,
|
||||
(int)info.OriginalParentWidth,
|
||||
(int)info.OriginalParentHeight));
|
||||
}
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
|
|
@ -253,7 +274,8 @@ public static class DatWidgetFactory
|
|||
|
||||
// ── Text ─────────────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>Type-12 UIElement_Text: a scrollable colored-line text view. The element's
|
||||
/// <summary>Type-12 UIElement_Text: an editable field or colored-line text view,
|
||||
/// selected from the canonical property bag. The element's
|
||||
/// own Direct/Normal media (if any) becomes the background sprite, drawn under the text —
|
||||
/// so a Type-12 element that previously rendered via UiDatElement keeps its sprite. Lines
|
||||
/// are bound later by the controller (LinesProvider). An unbound UiText draws nothing
|
||||
|
|
@ -273,7 +295,7 @@ public static class DatWidgetFactory
|
|||
/// font; otherwise it is the shared global fallback. Controllers that call
|
||||
/// <see cref="ImportedLayout.FindElement"/> and set <see cref="UiText.DatFont"/> afterward
|
||||
/// still override this — the build-time value is just the starting point.</param>
|
||||
private static UiText BuildText(ElementInfo info, Func<uint, (uint, int, int)> resolve,
|
||||
private static UiElement BuildText(ElementInfo info, Func<uint, (uint, int, int)> resolve,
|
||||
UiDatFont? elementFont = null)
|
||||
{
|
||||
uint bg = info.StateMedia.TryGetValue(
|
||||
|
|
@ -281,6 +303,35 @@ public static class DatWidgetFactory
|
|||
: info.StateMedia.ContainsKey("Normal") ? "Normal" : "", out var m)
|
||||
? m.File : 0u;
|
||||
|
||||
bool editable = info.TryGetEffectiveBool(0x16u, out var editableValue)
|
||||
&& editableValue;
|
||||
bool selectable = info.TryGetEffectiveBool(0x27u, out var selectableValue)
|
||||
&& selectableValue;
|
||||
bool oneLine = info.TryGetEffectiveBool(0x20u, out var oneLineValue)
|
||||
&& oneLineValue;
|
||||
|
||||
if (editable)
|
||||
{
|
||||
uint focusSprite = info.StateMedia.TryGetValue("Normal_focussed", out var focus)
|
||||
? focus.File
|
||||
: 0u;
|
||||
var field = new UiField
|
||||
{
|
||||
ElementId = info.Id,
|
||||
DatFont = elementFont,
|
||||
SpriteResolve = resolve,
|
||||
BackgroundSprite = bg,
|
||||
FocusFieldSprite = focusSprite,
|
||||
Selectable = selectable,
|
||||
OneLine = oneLine,
|
||||
};
|
||||
if (info.TryGetEffectiveInteger(0x1Eu, out int maxCharacters))
|
||||
field.MaxCharacters = maxCharacters;
|
||||
if (info.FontColor.HasValue)
|
||||
field.TextColor = info.FontColor.Value;
|
||||
return field;
|
||||
}
|
||||
|
||||
// Apply horizontal + vertical justification from the dat at build time.
|
||||
// Controllers that call FindElement and set Centered/RightAligned/VerticalJustify
|
||||
// afterward will override these — this is only the dat-driven default.
|
||||
|
|
@ -301,6 +352,8 @@ public static class DatWidgetFactory
|
|||
Centered = centered,
|
||||
RightAligned = rightAligned,
|
||||
VerticalJustify = vJustify,
|
||||
OneLine = oneLine,
|
||||
Selectable = selectable,
|
||||
// Seed the dat-driven font. When a font resolver was supplied and the element
|
||||
// carries a non-zero FontDid, elementFont is the element-specific dat font; otherwise
|
||||
// it is the shared global fallback. Controllers that call FindElement and explicitly
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue