From 50e07b88dac67e50249455c84e5a89ca20040e7b Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 16 Jun 2026 22:08:16 +0100 Subject: [PATCH] Move inventory dropdown onto Eve surfaces --- Aetheria.State.Verify/Program.cs | 56 ++++ Assets/Scripts/UI/Menu/InventoryPanel.cs | 399 +++++++++++++++++++++-- docs/aetheria-perfect-machine-map.md | 12 + 3 files changed, 436 insertions(+), 31 deletions(-) diff --git a/Aetheria.State.Verify/Program.cs b/Aetheria.State.Verify/Program.cs index b3e6eb87a..cde1dd076 100644 --- a/Aetheria.State.Verify/Program.cs +++ b/Aetheria.State.Verify/Program.cs @@ -37,6 +37,7 @@ RequireSectorMapZoneDetailsUseEveSurface(root); RequireRuntimeMenuTabsUseEveSurface(root); RequireInventoryShipSettingsUseEveSurface(root); RequireTradeCargoSelectorUseEveSurface(root); +RequireInventoryDropdownUseEveSurface(root); RequirePlayerSettingsEveSurface(root); RequireMainMenuContinueRunState(root); RequirePropertiesPanelReadOnlyInspector(root); @@ -506,6 +507,7 @@ Console.WriteLine("Sector-map zone details shell: zone inspection lowers through Console.WriteLine("Runtime menu tab shell: tab navigation lowers through an Eve UI Toolkit surface instead of MenuTabButton click wiring"); Console.WriteLine("Inventory ship-settings shell: background ship tuning lowers through an Eve UI Toolkit surface instead of PropertiesPanel.AddField"); Console.WriteLine("Trade cargo-selector shell: target cargo selection lowers through an Eve UI Toolkit surface instead of ContextMenu.AddOption"); +Console.WriteLine("Inventory dropdown shell: entity and loadout navigation lowers through an Eve UI Toolkit surface instead of ContextMenu.AddDropdown"); Console.WriteLine("Main-menu Continue authority: Continue selects typed run state instead of a null button"); Console.WriteLine("PropertiesPanel inspector authority: dead generic reflection inspector path is deleted"); Console.WriteLine("Typed behavior metadata authority: live heat/mining/thermotoggle payload kinds stay owned by package metadata"); @@ -2695,6 +2697,60 @@ static void RequireTradeCargoSelectorUseEveSurface(string root) } } +static void RequireInventoryDropdownUseEveSurface(string root) +{ + var inventoryPanelPath = Path.Combine(root, "Assets", "Scripts", "UI", "Menu", "InventoryPanel.cs"); + if (!File.Exists(inventoryPanelPath)) + { + throw new InvalidOperationException("Cannot verify inventory dropdown shell; InventoryPanel.cs is missing."); + } + + var source = File.ReadAllText(inventoryPanelPath); + var requiredSymbols = new[] + { + "DropdownSurfaceId", + "RenderDropdownSurface(", + "BuildDropdownCommands(", + "HandleDropdownSurfaceCommand(", + "ResolveDropdownSurfaceDocument(", + "BuildDropdownSurfaceDefinition(", + "SaveLoadoutCommand", + "CloseDropdownSurfaceCommand", + "new EveUiToolkitSurfaceLowerer()" + }; + + var missingSymbols = requiredSymbols + .Where(symbol => !source.Contains(symbol, StringComparison.Ordinal)) + .ToArray(); + + if (missingSymbols.Length > 0) + { + throw new InvalidOperationException( + "InventoryPanel no longer lowers the dropdown shell through an Eve surface: " + + string.Join(", ", missingSymbols)); + } + + var forbiddenSymbols = new[] + { + "ContextMenu.AddDropdown(entity.Name", + "ContextMenu.AddOption(GameManager.DockingBay.Name", + "ContextMenu.AddOption(\"Save Loadout\"", + "ContextMenu.AddDropdown(\"Restore Loadout\"", + "ContextMenu.Show();" + }; + + var hits = forbiddenSymbols + .Where(symbol => source.Contains(symbol, StringComparison.Ordinal)) + .ToArray(); + + if (hits.Length > 0) + { + throw new InvalidOperationException( + "InventoryPanel still owns dropdown behavior through the old ContextMenu path: " + + string.Join(", ", hits)); + } +} + static void RequirePlayerSettingsEveSurface(string root) { var projectorPath = Path.Combine(root, "Aetheria.State", "AetheriaPlayerSettingsSurfaceProjector.cs"); diff --git a/Assets/Scripts/UI/Menu/InventoryPanel.cs b/Assets/Scripts/UI/Menu/InventoryPanel.cs index e929132e3..8b5a3c04c 100644 --- a/Assets/Scripts/UI/Menu/InventoryPanel.cs +++ b/Assets/Scripts/UI/Menu/InventoryPanel.cs @@ -7,6 +7,8 @@ using System.Collections; using System.Collections.Generic; using System.Linq; using GameCult.Aetheria.State.Unity; +using GameCult.Eve.Surface; +using GameCult.Eve.UnityUIToolkit; using TMPro; using UniRx; using UniRx.Triggers; @@ -16,11 +18,20 @@ using UnityEngine.EventSystems; using UnityEngine.Experimental.Rendering; using Unity.Mathematics; using UnityEngine.Serialization; +using UIE = UnityEngine.UIElements; using static Unity.Mathematics.math; using int2 = Unity.Mathematics.int2; public class InventoryPanel : MonoBehaviour, IPointerClickHandler { + private const string DropdownSurfaceType = "surface-state"; + private const string DropdownSurfaceSchema = "gamecult.eve.surface.v1"; + private const string DropdownSurfaceProviderId = "aetheria"; + private const string DropdownSurfaceProviderKind = "inventory.panel"; + private const string DropdownSurfaceId = "aetheria.inventory.panel.dropdown"; + private const string CloseDropdownSurfaceCommand = "aetheria.inventory.panel.dropdown.close"; + private const string SaveLoadoutCommand = "aetheria.inventory.panel.dropdown.save_loadout"; + public ConfirmationDialog Dialog; public RectTransform DragParent; public bool Flip; @@ -81,6 +92,8 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler private int _clickCount; private InventoryCell _clickCell; private float _clickTime; + private readonly Dictionary _dropdownCommands = new Dictionary(StringComparer.Ordinal); + private UIE.UIDocument _dropdownSurfaceDocument; private bool _hud; @@ -107,6 +120,7 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler { Thermal.onClick.AddListener(() => { + HideDropdownSurface(); Display(_displayedEntity, false, !_thermal); }); } @@ -115,6 +129,7 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler { Current.onClick.AddListener(() => { + HideDropdownSurface(); if (_displayedEntity != GameManager.CurrentEntity) { if(_displayedEntity is Ship ship) @@ -137,6 +152,7 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler { EditName.onClick.AddListener(() => { + HideDropdownSurface(); Dialog.Clear(); var entityName = _displayedEntity.Name; Dialog.AddField("Name", () => entityName, s => entityName = s); @@ -153,37 +169,7 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler { Dropdown.onClick.AddListener(() => { - ContextMenu.Clear(); - foreach (var entity in GameManager.AvailableEntities()) - { - if (entity.CargoBays.Any()) - { - var options = entity.CargoBays - .Where(bay => bay != _displayedCargo) - .Select((bay, index) => - ($"Bay {index+1}", () => Display(bay), true)); - if(entity != _displayedEntity) options = options.Prepend(("Equipment", () => Display(entity), true)); - ContextMenu.AddDropdown(entity.Name, options); - } - else if(entity != _displayedEntity) ContextMenu.AddOption(entity.Name, () => Display(entity)); - } - - if(GameManager.DockingBay!=null && _displayedCargo!=GameManager.DockingBay) - ContextMenu.AddOption(GameManager.DockingBay.Name, () => Display(GameManager.DockingBay)); - - ContextMenu.AddOption("Save Loadout", - () => - { - GameManager.QueueRuntimeLoadoutTemplateCommit(EntityConstructionBlueprintProjector.CaptureBlueprint(_displayedEntity)); - }); - - if (GameManager.LoadoutTemplates.Any()) - { - ContextMenu.AddDropdown("Restore Loadout", - GameManager.LoadoutTemplates.Select(LoadoutOption)); - } - - ContextMenu.Show(); + RenderDropdownSurface(); }); } } @@ -202,6 +188,346 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler }, price < GameManager.Credits); } + private void RenderDropdownSurface() + { + BuildDropdownCommands(); + + var document = ResolveDropdownSurfaceDocument(); + document.gameObject.SetActive(true); + + var root = document.rootVisualElement; + root.Clear(); + root.style.flexGrow = 1; + root.style.position = UIE.Position.Absolute; + root.style.left = 0; + root.style.top = 0; + root.style.right = 0; + root.style.bottom = 0; + root.style.alignItems = UIE.Align.FlexStart; + root.style.justifyContent = UIE.Justify.FlexStart; + root.pickingMode = UIE.PickingMode.Ignore; + + var shell = new UIE.VisualElement(); + shell.style.width = 420; + shell.style.maxWidth = 520; + shell.style.backgroundColor = new Color(0.08f, 0.1f, 0.14f, 0.94f); + shell.style.borderTopLeftRadius = 8; + shell.style.borderTopRightRadius = 8; + shell.style.borderBottomLeftRadius = 8; + shell.style.borderBottomRightRadius = 8; + shell.style.paddingLeft = 18; + shell.style.paddingRight = 18; + shell.style.paddingTop = 18; + shell.style.paddingBottom = 18; + shell.style.borderLeftWidth = 1; + shell.style.borderRightWidth = 1; + shell.style.borderTopWidth = 1; + shell.style.borderBottomWidth = 1; + shell.style.borderLeftColor = new Color(0.3f, 0.47f, 0.71f, 0.8f); + shell.style.borderRightColor = new Color(0.3f, 0.47f, 0.71f, 0.8f); + shell.style.borderTopColor = new Color(0.3f, 0.47f, 0.71f, 0.8f); + shell.style.borderBottomColor = new Color(0.3f, 0.47f, 0.71f, 0.8f); + shell.pickingMode = UIE.PickingMode.Position; + root.Add(shell); + + var lowerer = new EveUiToolkitSurfaceLowerer(); + shell.Add(lowerer.Lower(BuildDropdownSurfaceDefinition(), HandleDropdownSurfaceCommand)); + } + + private void BuildDropdownCommands() + { + _dropdownCommands.Clear(); + + foreach (var entityEntry in GameManager.AvailableEntities().Select((entity, entityIndex) => (entity, entityIndex))) + { + if (entityEntry.entity.CargoBays.Any()) + { + if (entityEntry.entity != _displayedEntity) + { + var equipmentCommand = $"aetheria.inventory.panel.dropdown.entity_{entityEntry.entityIndex}.equipment"; + _dropdownCommands[equipmentCommand] = () => Display(entityEntry.entity); + } + + foreach (var bayEntry in entityEntry.entity.CargoBays + .Where(bay => bay != _displayedCargo) + .Select((bay, bayIndex) => (bay, bayIndex))) + { + var bayCommand = $"aetheria.inventory.panel.dropdown.entity_{entityEntry.entityIndex}.bay_{bayEntry.bayIndex}"; + _dropdownCommands[bayCommand] = () => Display(bayEntry.bay); + } + } + else if (entityEntry.entity != _displayedEntity) + { + var entityCommand = $"aetheria.inventory.panel.dropdown.entity_{entityEntry.entityIndex}"; + _dropdownCommands[entityCommand] = () => Display(entityEntry.entity); + } + } + + if (GameManager.DockingBay != null && _displayedCargo != GameManager.DockingBay) + { + _dropdownCommands["aetheria.inventory.panel.dropdown.docking_bay"] = () => Display(GameManager.DockingBay); + } + + if (_displayedEntity != null) + { + _dropdownCommands[SaveLoadoutCommand] = () => + { + GameManager.QueueRuntimeLoadoutTemplateCommit(EntityConstructionBlueprintProjector.CaptureBlueprint(_displayedEntity)); + }; + } + + foreach (var loadoutEntry in GameManager.LoadoutTemplates.Select((template, templateIndex) => (template, templateIndex))) + { + var blueprint = GameManager.CreateEntityConstructionBlueprint(loadoutEntry.template); + if (blueprint == null) + continue; + + var price = blueprint.Price(GameManager.ItemManager); + if (price >= GameManager.Credits) + continue; + + var restoreCommand = $"aetheria.inventory.panel.dropdown.loadout_{loadoutEntry.templateIndex}"; + _dropdownCommands[restoreCommand] = () => + { + if (GameManager.CommitRuntimeLoadoutRestore(loadoutEntry.template, out var entity)) + Display(entity); + }; + } + } + + private void HandleDropdownSurfaceCommand(EveSurfaceCommandRequest request) + { + if (string.Equals(request.Command, CloseDropdownSurfaceCommand, StringComparison.Ordinal)) + { + HideDropdownSurface(); + return; + } + + if (_dropdownCommands.TryGetValue(request.Command, out var action)) + { + action(); + HideDropdownSurface(); + return; + } + + Debug.LogWarning($"Unknown inventory dropdown command: {request.Command}"); + } + + private void HideDropdownSurface() + { + if (_dropdownSurfaceDocument == null) + return; + + _dropdownSurfaceDocument.rootVisualElement.Clear(); + _dropdownSurfaceDocument.gameObject.SetActive(false); + } + + private UIE.UIDocument ResolveDropdownSurfaceDocument() + { + if (_dropdownSurfaceDocument != null) + return _dropdownSurfaceDocument; + + var host = new GameObject("Aetheria Inventory Dropdown Surface"); + host.transform.SetParent(transform, false); + var document = host.AddComponent(); + document.sortingOrder = 1000; + host.SetActive(false); + _dropdownSurfaceDocument = document; + return document; + } + + private EveSurfaceDocument BuildDropdownSurfaceDefinition() + { + var children = new List + { + Card( + $"{DropdownSurfaceId}.summary", + "Inventory Actions", + Metric( + $"{DropdownSurfaceId}.current", + "Current View", + Title?.text ?? "None"), + Text( + $"{DropdownSurfaceId}.note", + "Gameplay still owns entity and cargo selection plus loadout restore. This surface just kills the old context-menu shell.")) + }; + + foreach (var entityEntry in GameManager.AvailableEntities().Select((entity, entityIndex) => (entity, entityIndex))) + { + var buttons = new List(); + var equipmentCommand = $"aetheria.inventory.panel.dropdown.entity_{entityEntry.entityIndex}.equipment"; + if (_dropdownCommands.ContainsKey(equipmentCommand)) + { + buttons.Add(Button( + $"{DropdownSurfaceId}.entity_{entityEntry.entityIndex}.equipment", + "Equipment", + equipmentCommand)); + } + + foreach (var bayEntry in entityEntry.entity.CargoBays.Select((bay, bayIndex) => (bay, bayIndex))) + { + var bayCommand = $"aetheria.inventory.panel.dropdown.entity_{entityEntry.entityIndex}.bay_{bayEntry.bayIndex}"; + if (_dropdownCommands.ContainsKey(bayCommand)) + { + buttons.Add(Button( + $"{DropdownSurfaceId}.entity_{entityEntry.entityIndex}.bay_{bayEntry.bayIndex}", + $"Bay {bayEntry.bayIndex + 1}", + bayCommand)); + } + } + + var entityCommand = $"aetheria.inventory.panel.dropdown.entity_{entityEntry.entityIndex}"; + if (_dropdownCommands.ContainsKey(entityCommand)) + { + buttons.Add(Button( + $"{DropdownSurfaceId}.entity_{entityEntry.entityIndex}.select", + entityEntry.entity.Name, + entityCommand)); + } + + if (buttons.Count > 0) + { + children.Add(Card( + $"{DropdownSurfaceId}.entity_{entityEntry.entityIndex}.card", + entityEntry.entity.Name, + ButtonColumn($"{DropdownSurfaceId}.entity_{entityEntry.entityIndex}.options", buttons.ToArray()))); + } + } + + if (_dropdownCommands.ContainsKey("aetheria.inventory.panel.dropdown.docking_bay")) + { + children.Add(Card( + $"{DropdownSurfaceId}.dockingBay.card", + "Docking Bay", + ButtonColumn( + $"{DropdownSurfaceId}.dockingBay.options", + Button( + $"{DropdownSurfaceId}.dockingBay.select", + GameManager.DockingBay.Name, + "aetheria.inventory.panel.dropdown.docking_bay")))); + } + + var loadoutChildren = new List(); + if (_dropdownCommands.ContainsKey(SaveLoadoutCommand)) + { + loadoutChildren.Add(Button( + $"{DropdownSurfaceId}.loadouts.save", + "Save Loadout", + SaveLoadoutCommand)); + } + + foreach (var loadoutEntry in GameManager.LoadoutTemplates.Select((template, templateIndex) => (template, templateIndex))) + { + var restoreCommand = $"aetheria.inventory.panel.dropdown.loadout_{loadoutEntry.templateIndex}"; + var blueprint = GameManager.CreateEntityConstructionBlueprint(loadoutEntry.template); + if (blueprint == null) + { + loadoutChildren.Add(Text( + $"{DropdownSurfaceId}.loadouts.unavailable_{loadoutEntry.templateIndex}", + $"{loadoutEntry.template.Name} - unavailable")); + continue; + } + + var price = blueprint.Price(GameManager.ItemManager); + if (_dropdownCommands.ContainsKey(restoreCommand)) + { + loadoutChildren.Add(Button( + $"{DropdownSurfaceId}.loadouts.restore_{loadoutEntry.templateIndex}", + $"{loadoutEntry.template.Name} - {price:n0}", + restoreCommand)); + } + else + { + loadoutChildren.Add(Text( + $"{DropdownSurfaceId}.loadouts.locked_{loadoutEntry.templateIndex}", + $"{loadoutEntry.template.Name} - {price:n0} (unavailable)")); + } + } + + if (loadoutChildren.Count > 0) + { + children.Add(Card( + $"{DropdownSurfaceId}.loadouts.card", + "Loadouts", + ButtonColumn($"{DropdownSurfaceId}.loadouts.options", loadoutChildren.ToArray()))); + } + + children.Add(ButtonRow( + $"{DropdownSurfaceId}.actions", + Button($"{DropdownSurfaceId}.close", "Close", CloseDropdownSurfaceCommand))); + + return new EveSurfaceDocument( + DropdownSurfaceType, + DropdownSurfaceSchema, + DropdownSurfaceProviderId, + DropdownSurfaceProviderKind, + "Inventory Dropdown", + version: 1, + DateTime.UtcNow.ToString("O"), + new EveSurfaceTree( + DropdownSurfaceId, + Node( + $"{DropdownSurfaceId}.root", + "surface", + Array.Empty<(string Key, string Value)>(), + children.ToArray()), + Array.Empty()), + _dropdownCommands + .Select(pair => new EveCommandTemplate(pair.Key, pair.Key.Split('.').Last(), "unity-uitoolkit")) + .Append(new EveCommandTemplate(CloseDropdownSurfaceCommand, "Close", "unity-uitoolkit")) + .ToArray()); + } + + private static EveSurfaceComponent Card( + string id, + string title, + params EveSurfaceComponent[] children) + { + return Node(id, "card", new[] { ("title", title) }, children); + } + + private static EveSurfaceComponent Metric(string id, string label, string value) + { + return Node(id, "metric", new[] { ("label", label), ("value", value) }); + } + + private static EveSurfaceComponent Text(string id, string value) + { + return Node(id, "text", new[] { ("value", value) }); + } + + private static EveSurfaceComponent Button(string id, string label, string command) + { + return Node(id, "control.button", new[] { ("label", label), ("command", command) }); + } + + private static EveSurfaceComponent ButtonRow( + string id, + params EveSurfaceComponent[] children) + { + return Node(id, "row", Array.Empty<(string Key, string Value)>(), children); + } + + private static EveSurfaceComponent ButtonColumn( + string id, + params EveSurfaceComponent[] children) + { + return Node(id, "column", Array.Empty<(string Key, string Value)>(), children); + } + + private static EveSurfaceComponent Node( + string id, + string kind, + IEnumerable<(string Key, string Value)> props, + params EveSurfaceComponent[] children) + { + return new EveSurfaceComponent( + id, + kind, + props.ToDictionary(prop => prop.Key, prop => prop.Value, StringComparer.Ordinal), + children ?? Array.Empty()); + } + private void Update() { if (_displayedEntity != null && TemperatureDisplay) @@ -235,12 +561,14 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler private void OnDisable() { + HideDropdownSurface(); Clear(); } public void Clear() { + HideDropdownSurface(); _displayedCargo = null; _displayedEntity = null; _displayedHullShape = null; @@ -948,6 +1276,15 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler Dialog.MoveToCursor(); } + private void OnDestroy() + { + if (_dropdownSurfaceDocument != null) + { + Destroy(_dropdownSurfaceDocument.gameObject); + _dropdownSurfaceDocument = null; + } + } + public Subject OnBackgroundClick = new Subject(); private Transform[] _dragCells; private Vector2[] _dragOffsets; diff --git a/docs/aetheria-perfect-machine-map.md b/docs/aetheria-perfect-machine-map.md index dfd4ff44c..9b5abed3d 100644 --- a/docs/aetheria-perfect-machine-map.md +++ b/docs/aetheria-perfect-machine-map.md @@ -123,6 +123,9 @@ legacy catalog cache, and legacy UI paths should be migration-only or deleted. local Eve/UI Toolkit surface instead of rebuilding a `PropertiesPanel` float field. Trade target-cargo selection now lowers through a local Eve/UI Toolkit surface instead of rebuilding a `ContextMenu` option list. + Inventory entity/bay/loadout dropdown navigation now lowers through a local + Eve/UI Toolkit surface instead of rebuilding nested `ContextMenu` + dropdowns/options. - The combat schematic HUD uses typed runtime catalog weapon facets for its static weapon icon strip; missing typed weapon facets no longer fall back to legacy `WeaponItemData`. Schematic weapon-row selection now uses typed @@ -1569,6 +1572,11 @@ First Aetheria surfaces to publish: Toolkit surface. `TradeMenu` still owns local target-cargo presentation state, but the old `ContextMenu.AddOption(...)` popup path no longer owns that selector shell. + - Done: replace the inventory entity/bay/loadout dropdown popup with an + Eve-owned UI Toolkit surface. `InventoryPanel` still owns local display + projection and gameplay still owns entity/cargo selection plus loadout + restore/save effects, but the old `ContextMenu` dropdown tree no longer + owns that shell. - Done: move the shared `org.gamecult.eve.surface` and `org.gamecult.eve.unity-uitoolkit` packages into the Eve repo and retarget Aetheria to import them from there instead of carrying local staged @@ -1939,6 +1947,10 @@ First Aetheria surfaces to publish: - Trade target-cargo selection now lowers through a shared UI Toolkit `UIDocument` host and a local Eve surface document instead of rebuilding a `ContextMenu.AddOption(...)` popup for docking-bay and ship-bay choices. +- Inventory entity/bay/loadout dropdown navigation now lowers through a shared + UI Toolkit `UIDocument` host and a local Eve surface document instead of + rebuilding nested `ContextMenu.AddDropdown(...)` and `ContextMenu.AddOption(...)` + menus. - Keyboard display layout parsing is no longer JSON-backed: `InputDisplayLayout` builds its static ANSI-104 display projection from typed `InputLayout` rows/columns. The dead commented Ink `ToJson` write path and