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>
191 lines
8.6 KiB
C#
191 lines
8.6 KiB
C#
using System.Collections.Generic;
|
|
using AcDream.App.UI;
|
|
using AcDream.App.UI.Layout;
|
|
using AcDream.Core.Items;
|
|
using Xunit;
|
|
|
|
namespace AcDream.App.Tests.UI.Layout;
|
|
|
|
public class PaperdollControllerTests
|
|
{
|
|
private const uint Player = 0x50000001u;
|
|
private const uint Pack = 0x40000005u;
|
|
private const uint HeadSlot = 0x100005ABu; // HeadWear 0x1
|
|
private const uint ChestSlot = 0x100001E2u; // ChestWear 0x2
|
|
private const uint ChestArmorSlot = 0x100005ACu; // ChestArmor 0x200
|
|
private const uint ShieldSlot = 0x100001E1u; // Shield 0x200000
|
|
private const uint WeaponSlot = 0x100001DFu; // composite 0x3500000
|
|
private const uint FingerLSlot= 0x100001DCu; // FingerWearLeft 0x40000
|
|
|
|
private sealed class RootElement : UiElement { }
|
|
|
|
private static (ImportedLayout layout, Dictionary<uint, UiItemList> lists) BuildLayout()
|
|
{
|
|
var ids = new[] { HeadSlot, ChestSlot, ChestArmorSlot, ShieldSlot, WeaponSlot, FingerLSlot };
|
|
var lists = new Dictionary<uint, UiItemList>();
|
|
var byId = new Dictionary<uint, UiElement>();
|
|
var root = new RootElement { Width = 224, Height = 214 };
|
|
foreach (var id in ids)
|
|
{
|
|
var list = new UiItemList { Width = 32, Height = 32 };
|
|
lists[id] = list; byId[id] = list; root.AddChild(list);
|
|
}
|
|
return (new ImportedLayout(root, byId), lists);
|
|
}
|
|
|
|
private static PaperdollController Bind(ImportedLayout layout, ClientObjectTable objects,
|
|
List<(uint item, uint mask)>? wields = null, uint emptySlot = 0u)
|
|
=> PaperdollController.Bind(layout, objects, () => Player,
|
|
iconIds: (_, _, _, _, _) => 0x1234u,
|
|
sendWield: wields is null ? null : (i, m) => wields.Add((i, m)),
|
|
emptySlotSprite: emptySlot);
|
|
|
|
private static void SeedEquipped(ClientObjectTable t, uint guid, EquipMask loc)
|
|
{
|
|
t.AddOrUpdate(new ClientObject { ObjectId = guid, WielderId = Player });
|
|
t.MoveItem(guid, Player, newSlot: -1, newEquipLocation: loc);
|
|
}
|
|
|
|
private static void SeedPackItem(ClientObjectTable t, uint guid, EquipMask validLocations)
|
|
{
|
|
t.AddOrUpdate(new ClientObject { ObjectId = guid, ValidLocations = validLocations });
|
|
t.MoveItem(guid, Pack, newSlot: 0);
|
|
}
|
|
|
|
[Fact]
|
|
public void Populate_shows_equipped_item_in_its_slot()
|
|
{
|
|
var (layout, lists) = BuildLayout();
|
|
var objects = new ClientObjectTable();
|
|
SeedEquipped(objects, 0xA01u, EquipMask.HeadWear);
|
|
Bind(layout, objects);
|
|
Assert.Equal(0xA01u, lists[HeadSlot].Cell.ItemId); // helm in the head slot
|
|
Assert.Equal(0u, lists[ShieldSlot].Cell.ItemId); // shield slot empty
|
|
}
|
|
|
|
[Fact]
|
|
public void Populate_matches_a_weapon_into_the_composite_slot()
|
|
{
|
|
var (layout, lists) = BuildLayout();
|
|
var objects = new ClientObjectTable();
|
|
SeedEquipped(objects, 0xB01u, EquipMask.MeleeWeapon); // a sword's actual equip loc
|
|
Bind(layout, objects);
|
|
Assert.Equal(0xB01u, lists[WeaponSlot].Cell.ItemId); // matched via (loc & composite) != 0
|
|
}
|
|
|
|
[Fact]
|
|
public void OnDragOver_accepts_only_valid_locations()
|
|
{
|
|
var (layout, lists) = BuildLayout();
|
|
var objects = new ClientObjectTable();
|
|
SeedPackItem(objects, 0xC01u, EquipMask.HeadWear); // a helm in the pack
|
|
var ctrl = Bind(layout, objects);
|
|
var payload = new ItemDragPayload(0xC01u, ItemDragSource.Inventory, 0, lists[HeadSlot].Cell);
|
|
Assert.True(ctrl.OnDragOver(lists[HeadSlot], lists[HeadSlot].Cell, payload)); // helm → head OK
|
|
Assert.False(ctrl.OnDragOver(lists[ShieldSlot], lists[ShieldSlot].Cell, payload)); // helm → shield NO
|
|
}
|
|
|
|
[Fact]
|
|
public void HandleDropRelease_wields_optimistically_and_sends_wire()
|
|
{
|
|
var (layout, lists) = BuildLayout();
|
|
var objects = new ClientObjectTable();
|
|
SeedPackItem(objects, 0xD01u, EquipMask.HeadWear);
|
|
var wields = new List<(uint item, uint mask)>();
|
|
var ctrl = Bind(layout, objects, wields);
|
|
var payload = new ItemDragPayload(0xD01u, ItemDragSource.Inventory, 0, lists[HeadSlot].Cell);
|
|
ctrl.HandleDropRelease(lists[HeadSlot], lists[HeadSlot].Cell, payload);
|
|
Assert.Equal(EquipMask.HeadWear, objects.Get(0xD01u)!.CurrentlyEquippedLocation); // equipped instantly
|
|
Assert.Equal(Player, objects.Get(0xD01u)!.ContainerId); // contained-by-wielder (the optimistic wield is ContainerId-based; it does NOT write WielderId)
|
|
Assert.Single(wields);
|
|
Assert.Equal((0xD01u, (uint)EquipMask.HeadWear), wields[0]); // GetAndWieldItem wire
|
|
}
|
|
|
|
[Fact]
|
|
public void HandleDropRelease_resolves_the_finger_bit_for_a_dual_finger_ring()
|
|
{
|
|
var (layout, lists) = BuildLayout();
|
|
var objects = new ClientObjectTable();
|
|
SeedPackItem(objects, 0xE01u, EquipMask.FingerWearLeft | EquipMask.FingerWearRight);
|
|
var wields = new List<(uint item, uint mask)>();
|
|
var ctrl = Bind(layout, objects, wields);
|
|
var payload = new ItemDragPayload(0xE01u, ItemDragSource.Inventory, 0, lists[FingerLSlot].Cell);
|
|
ctrl.HandleDropRelease(lists[FingerLSlot], lists[FingerLSlot].Cell, payload);
|
|
Assert.Equal((uint)EquipMask.FingerWearLeft, wields[0].mask); // ValidLocations & slotMask = left finger only
|
|
}
|
|
|
|
[Fact]
|
|
public void HandleDropRelease_onAutoWearSlot_sendsFullValidLocations()
|
|
{
|
|
var (layout, lists) = BuildLayout();
|
|
var objects = new ClientObjectTable();
|
|
const EquipMask coatMask =
|
|
EquipMask.ChestWear
|
|
| EquipMask.UpperArmWear
|
|
| EquipMask.LowerArmWear;
|
|
SeedPackItem(objects, 0xE02u, coatMask);
|
|
var wields = new List<(uint item, uint mask)>();
|
|
var ctrl = Bind(layout, objects, wields);
|
|
var payload = new ItemDragPayload(0xE02u, ItemDragSource.Inventory, 0, lists[ChestSlot].Cell);
|
|
|
|
ctrl.HandleDropRelease(lists[ChestSlot], lists[ChestSlot].Cell, payload);
|
|
|
|
Assert.Equal((uint)coatMask, wields[0].mask);
|
|
Assert.Equal(coatMask, objects.Get(0xE02u)!.CurrentlyEquippedLocation);
|
|
}
|
|
|
|
[Fact]
|
|
public void HandleDropRelease_onArmorAutoWearSlot_sendsFullValidLocations()
|
|
{
|
|
var (layout, lists) = BuildLayout();
|
|
var objects = new ClientObjectTable();
|
|
const EquipMask hauberkMask =
|
|
EquipMask.ChestArmor
|
|
| EquipMask.AbdomenArmor
|
|
| EquipMask.UpperArmArmor
|
|
| EquipMask.LowerArmArmor;
|
|
SeedPackItem(objects, 0xE03u, hauberkMask);
|
|
var wields = new List<(uint item, uint mask)>();
|
|
var ctrl = Bind(layout, objects, wields);
|
|
var payload = new ItemDragPayload(0xE03u, ItemDragSource.Inventory, 0, lists[ChestArmorSlot].Cell);
|
|
|
|
ctrl.HandleDropRelease(lists[ChestArmorSlot], lists[ChestArmorSlot].Cell, payload);
|
|
|
|
Assert.Equal((uint)hauberkMask, wields[0].mask);
|
|
Assert.Equal(hauberkMask, objects.Get(0xE03u)!.CurrentlyEquippedLocation);
|
|
}
|
|
|
|
[Fact]
|
|
public void Empty_equip_slot_shows_the_configured_frame() // visible frame so all positions are usable (Slice 1; the doll is Slice 2)
|
|
{
|
|
var (layout, lists) = BuildLayout();
|
|
Bind(layout, new ClientObjectTable(), emptySlot: 0x06004D20u);
|
|
Assert.Equal(0x06004D20u, lists[HeadSlot].Cell.EmptySprite);
|
|
}
|
|
|
|
[Fact]
|
|
public void Live_player_wield_repaints_the_slot() // event-driven: ObjectMoved → Concerns → Populate
|
|
{
|
|
var (layout, lists) = BuildLayout();
|
|
var objects = new ClientObjectTable();
|
|
Bind(layout, objects); // slots empty at bind
|
|
SeedPackItem(objects, 0xF01u, EquipMask.HeadWear); // a helm appears in the pack (not on the doll)
|
|
Assert.Equal(0u, lists[HeadSlot].Cell.ItemId);
|
|
objects.WieldItemOptimistic(0xF01u, Player, EquipMask.HeadWear); // player wields it → ObjectMoved(to=player)
|
|
Assert.Equal(0xF01u, lists[HeadSlot].Cell.ItemId); // the head slot repainted with the helm
|
|
}
|
|
|
|
[Fact]
|
|
public void Live_npc_equip_does_not_appear_on_the_doll() // player-scoped: a remote creature's wielded item never leaks
|
|
{
|
|
var (layout, lists) = BuildLayout();
|
|
var objects = new ClientObjectTable();
|
|
Bind(layout, objects);
|
|
const uint npc = 0x60000001u;
|
|
objects.AddOrUpdate(new ClientObject
|
|
{
|
|
ObjectId = 0xF02u, WielderId = npc, CurrentlyEquippedLocation = EquipMask.HeadWear,
|
|
});
|
|
Assert.Equal(0u, lists[HeadSlot].Cell.ItemId); // the NPC's helm is NOT on the player's doll
|
|
}
|
|
}
|