acdream/src/AcDream.App/UI/UiViewport.cs
Erik 0b74d19475 fix(ui): port exact paperdoll body selection
Resolve and sample retail's authored nine-color paperdoll click map, preserve local click coordinates, and select the stable highest-priority worn item with the player fallback. Keep targeted-use body clicks routed to self and pin both synthetic and live-DAT conformance.

Co-Authored-By: Codex <codex@openai.com>
2026-07-11 11:56:26 +02:00

49 lines
2.2 KiB
C#

using System.Numerics;
namespace AcDream.App.UI;
/// <summary>Leaf widget for dat Type 0xD (UIElement_Viewport). Blits the texture produced by its
/// IUiViewportRenderer (run in the pre-UI hook) as a single sprite at its own rect. The 3-D render
/// does NOT happen here (OnDraw only has a 2-D context).</summary>
public sealed class UiViewport : UiElement
{
public override bool ConsumesDatChildren => true;
/// <summary>Optional click action. Non-null makes the viewport handle the press
/// itself instead of it being captured as a window move.</summary>
public System.Action? Clicked { get; set; }
/// <summary>Position-aware variant with viewport-local pixel coordinates.</summary>
public System.Action<int, int>? ClickedAt { get; set; }
public override bool HandlesClick => Clicked is not null || ClickedAt is not null;
public override bool OnEvent(in UiEvent e)
{
if (Clicked is null && ClickedAt is null) return base.OnEvent(e);
switch (e.Type)
{
case UiEventType.MouseDown: return true; // consume the press; act on Click
case UiEventType.Click:
Clicked?.Invoke();
ClickedAt?.Invoke(e.Data1, e.Data2);
return true;
}
return base.OnEvent(e);
}
/// <summary>Renderer that produces the off-screen texture. Set by GameWindow wiring (later task).</summary>
public IUiViewportRenderer? Renderer { get; set; }
/// <summary>Last GL color-texture handle produced by the pre-UI hook. 0 = nothing to blit.</summary>
public uint TextureHandle { get; set; }
protected override void OnDraw(UiRenderContext ctx)
{
if (!Visible || TextureHandle == 0) return;
// Local origin is already at this widget's Left/Top (PushTransform applied by DrawSelfAndChildren).
// V is FLIPPED (v0=1, v1=0): TextureHandle is an off-screen FBO color texture, whose origin is
// bottom-left (GL), while the UI sprite convention is top-left. Without the flip the doll renders
// upside-down. (If the doll appears upside-down at the visual gate, this is the line to revisit.)
ctx.DrawSprite(TextureHandle, 0f, 0f, Width, Height, 0f, 1f, 1f, 0f, Vector4.One);
}
}