acdream/src/AcDream.App/UI/UiScrollablePanel.cs
Erik b7dc91a053 feat(ui): D.2b item interaction + retail cursors + live character sheet
Lands the codex-worktree D.2b stream plus the extraction the 2026-07-02
UI architecture review mandated before commit:

- ItemInteractionController: single owner of double-click use/equip/
  container-open, targeted-use mode (health kits), drag-out drop;
  toolbar shortcut drags don't drop the real item. ItemEquipRules for
  multi-slot (coat) coverage via equip masks.
- Cursor phase: CursorFeedbackController (semantic priority chain:
  drag > resize > window-move > target-mode > text) + RetailCursorCatalog
  (enums 0x27/0x28/0x29, hotspot 14,14; ClientUISystem::UpdateCursorState
  0x00564630) resolved through the portal EnumIDMap chain by
  RetailCursorResolver; RetailCursorManager applies dat cursor art to the
  OS cursor. Register row AP-72 covers the OS standard-cursor fallback.
- Character window goes live: CharacterSheetProvider owns sheet assembly,
  XP-curve/raise-cost math and the raise flow — extracted out of
  GameWindow per Code Structure Rule 1 instead of committing the ~430-line
  feature body there. Optimistic XP/credit debits go through eventful
  store APIs (new ClientObjectTable.UpdateInt64Property +
  LocalPlayerState.DebitIntProperty/DebitInt64Property) instead of raw
  property-dictionary writes; register row AP-73 covers the still-missing
  raise ledger (#163).
- RetailWindowFrame: the shared nine-slice window mount recipe; the
  character window uses it, remaining windows migrate via #164.
- Status-bar buttons toggle inventory/character windows; retail row-major
  backpack ordering; WorldSession.SendUseWithTarget + raise/train sends.

GameWindow shrinks 14,214 -> 13,877 lines despite the new features; the
sheet/raise logic is unit-tested in CharacterSheetProviderTests instead
of trapped in the god object. Build green; full suite 3,286 tests pass.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 09:18:43 +02:00

109 lines
2.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
namespace AcDream.App.UI;
/// <summary>
/// Simple vertical viewport for controller-built row lists. It shares the same
/// pixel scroll model as chat text and item grids, and clips whole rows because
/// the UI renderer does not have a scissor stack yet.
/// </summary>
public sealed class UiScrollablePanel : UiPanel
{
private readonly Dictionary<UiElement, float> _baseTops = new(ReferenceEqualityComparer.Instance);
public UiScrollable Scroll { get; } = new();
public int LineHeight { get; set; } = 16;
public int ContentHeight { get; private set; }
public UiScrollablePanel()
{
BackgroundColor = Vector4.Zero;
BorderColor = Vector4.Zero;
}
public override void AddChild(UiElement child)
{
base.AddChild(child);
Track(child);
}
public override bool RemoveChild(UiElement child)
{
bool removed = base.RemoveChild(child);
if (removed)
{
_baseTops.Remove(child);
RecomputeContentHeight();
}
return removed;
}
public void ClearContent()
{
foreach (var child in Children.ToArray())
RemoveChild(child);
_baseTops.Clear();
ContentHeight = 0;
Scroll.SetScrollY(0);
}
internal void LayoutScrollableChildren()
{
Scroll.LineHeight = Math.Max(1, LineHeight);
Scroll.ContentHeight = ContentHeight;
Scroll.ViewHeight = Math.Max(0, (int)MathF.Floor(Height));
Scroll.SetScrollY(Scroll.ScrollY);
foreach (var child in Children)
{
if (!_baseTops.TryGetValue(child, out float baseTop))
continue;
float top = baseTop - Scroll.ScrollY;
child.Top = top;
child.Visible = top >= -0.5f && top + child.Height <= Height + 0.5f;
}
}
public override bool OnEvent(in UiEvent e)
{
if (e.Type == UiEventType.Scroll)
{
Scroll.ScrollByLines(-e.Data0);
LayoutScrollableChildren();
return true;
}
return base.OnEvent(e);
}
protected override void OnDraw(UiRenderContext ctx)
{
LayoutScrollableChildren();
base.OnDraw(ctx);
}
private void Track(UiElement child)
{
child.Anchors = AnchorEdges.None;
_baseTops[child] = child.Top;
RecomputeContentHeight();
}
private void RecomputeContentHeight()
{
float bottom = 0f;
foreach (var child in Children)
{
if (!_baseTops.TryGetValue(child, out float top))
continue;
bottom = MathF.Max(bottom, top + child.Height);
}
ContentHeight = (int)MathF.Ceiling(bottom);
Scroll.SetScrollY(Scroll.ScrollY);
}
}