diff --git a/Aetheria.State.Verify/Program.cs b/Aetheria.State.Verify/Program.cs index cde1dd076..0664023e3 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); +RequireTradeFilterAndRowActionsUseEveSurface(root); RequireInventoryDropdownUseEveSurface(root); RequirePlayerSettingsEveSurface(root); RequireMainMenuContinueRunState(root); @@ -507,6 +508,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("Trade filter and row-action shells: filter selection and buy-quantity entry lower through Eve UI Toolkit surfaces instead of ContextMenu dropdowns"); 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"); @@ -2697,6 +2699,67 @@ static void RequireTradeCargoSelectorUseEveSurface(string root) } } +static void RequireTradeFilterAndRowActionsUseEveSurface(string root) +{ + var tradeMenuPath = Path.Combine(root, "Assets", "Scripts", "UI", "Menu", "TradeMenu.cs"); + if (!File.Exists(tradeMenuPath)) + { + throw new InvalidOperationException("Cannot verify trade filter and row-action shells; TradeMenu.cs is missing."); + } + + var source = File.ReadAllText(tradeMenuPath); + var requiredSymbols = new[] + { + "FilterSurfaceId", + "RowActionSurfaceId", + "RenderFilterSurface(", + "BuildFilterSurfaceCommands(", + "HandleFilterSurfaceCommand(", + "ResolveFilterSurfaceDocument(", + "BuildFilterSurfaceDefinition(", + "RenderRowActionSurface(", + "BuildRowActionSurfaceCommands(", + "HandleRowActionSurfaceCommand(", + "ResolveRowActionSurfaceDocument(", + "BuildRowActionSurfaceDefinition(", + "ShowBuyQuantityDialog(", + "CloseFilterSurfaceCommand", + "CloseRowActionSurfaceCommand", + "new EveUiToolkitSurfaceLowerer()" + }; + + var missingSymbols = requiredSymbols + .Where(symbol => !source.Contains(symbol, StringComparison.Ordinal)) + .ToArray(); + + if (missingSymbols.Length > 0) + { + throw new InvalidOperationException( + "TradeMenu no longer lowers filter and row-action shells through Eve surfaces: " + + string.Join(", ", missingSymbols)); + } + + var forbiddenSymbols = new[] + { + "public ContextMenu ContextMenu;", + "ContextMenu.Clear();", + "ContextMenu.AddDropdown(", + "ContextMenu.AddOption(", + "ContextMenu.Show();" + }; + + var hits = forbiddenSymbols + .Where(symbol => source.Contains(symbol, StringComparison.Ordinal)) + .ToArray(); + + if (hits.Length > 0) + { + throw new InvalidOperationException( + "TradeMenu still owns filter or row-action behavior through the old context-menu path: " + + string.Join(", ", hits)); + } +} + static void RequireInventoryDropdownUseEveSurface(string root) { var inventoryPanelPath = Path.Combine(root, "Assets", "Scripts", "UI", "Menu", "InventoryPanel.cs"); diff --git a/Assets/Scripts/UI/Menu/TradeMenu.cs b/Assets/Scripts/UI/Menu/TradeMenu.cs index decbac3fa..d3a8a2e28 100644 --- a/Assets/Scripts/UI/Menu/TradeMenu.cs +++ b/Assets/Scripts/UI/Menu/TradeMenu.cs @@ -20,9 +20,12 @@ public class TradeMenu : MonoBehaviour private const string CargoSelectorSurfaceProviderKind = "trade.menu"; private const string CargoSelectorSurfaceId = "aetheria.trade.target_cargo_selector"; private const string CloseCargoSelectorCommand = "aetheria.trade.target_cargo_selector.close"; + private const string FilterSurfaceId = "aetheria.trade.filter_selector"; + private const string CloseFilterSurfaceCommand = "aetheria.trade.filter_selector.close"; + private const string RowActionSurfaceId = "aetheria.trade.row_actions"; + private const string CloseRowActionSurfaceCommand = "aetheria.trade.row_actions.close"; public ActionGameManager GameManager; - public ContextMenu ContextMenu; public ConfirmationDialog Dialog; public UnityEngine.UI.Button NewFilterButton; public Prototype FilterPrototype; @@ -39,9 +42,14 @@ public class TradeMenu : MonoBehaviour private (ItemFilter filter, SimpleCommodityCategory type) _commodityFilter; private (ItemFilter filter, CompoundCommodityCategory type) _compoundCommodityFilter; private List _behaviorFilters = new List(); + private readonly Dictionary _filterSurfaceCommands = new Dictionary(StringComparer.Ordinal); + private readonly Dictionary _rowActionSurfaceCommands = new Dictionary(StringComparer.Ordinal); private readonly Dictionary _cargoSelectionCommands = new Dictionary(StringComparer.Ordinal); private UIDocument _cargoSelectorSurfaceDocument; + private UIDocument _filterSurfaceDocument; + private UIDocument _rowActionSurfaceDocument; + private string _rowActionTitle = "Trade Actions"; public EquippedCargoBay Inventory { get; set; } @@ -51,6 +59,8 @@ public class TradeMenu : MonoBehaviour _targetCargo = GameManager.DockingBay; TargetCargoLabel.text = "Docking Bay"; HideCargoSelectorSurface(); + HideFilterSurface(); + HideRowActionSurface(); Properties.GameManager = GameManager; UpdateCreditsLabel(); @@ -65,138 +75,11 @@ public class TradeMenu : MonoBehaviour MaximumSizeFilter.Height.onEndEdit.RemoveAllListeners(); MaximumSizeFilter.Height.onEndEdit.AddListener(_ => Populate()); - + + NewFilterButton.onClick.RemoveAllListeners(); NewFilterButton.onClick.AddListener(() => { - ContextMenu.Clear(); - IEnumerable hardpointTypes = (HardpointType[]) Enum.GetValues(typeof(HardpointType)); - if (_hardpointFilter.filter != null) - hardpointTypes = hardpointTypes.Where(x => x != _hardpointFilter.type); - - IEnumerable commodityTypes = (SimpleCommodityCategory[]) Enum.GetValues(typeof(SimpleCommodityCategory)); - if (_commodityFilter.filter != null) - commodityTypes = commodityTypes.Where(x => x != _commodityFilter.type); - - IEnumerable compoundCommodityTypes = (CompoundCommodityCategory[]) Enum.GetValues(typeof(CompoundCommodityCategory)); - if (_compoundCommodityFilter.filter != null) - compoundCommodityTypes = compoundCommodityTypes.Where(x => x != _compoundCommodityFilter.type); - - ContextMenu.AddDropdown("Gear Type", hardpointTypes - .Select(x => (Enum.GetName(typeof(HardpointType), x), () => - { - if (!_hardpointFilter.filter) - { - _hardpointFilter.filter = FilterPrototype.Instantiate(); - _hardpointFilter.filter.OnDisable += () => - { - _hardpointFilter.filter = null; - Populate(); - }; - } - if(_commodityFilter.filter) - { - _commodityFilter.filter.GetComponent().ReturnToPool(); - _commodityFilter.filter = null; - } - if(_compoundCommodityFilter.filter) - { - _compoundCommodityFilter.filter.GetComponent().ReturnToPool(); - _compoundCommodityFilter.filter = null; - } - - _hardpointFilter.filter.Label.text = $"Hardpoint: {Enum.GetName(typeof(HardpointType), x)}"; - _hardpointFilter.type = x; - Populate(); - }, true))); - ContextMenu.AddDropdown("Simple Commodity", commodityTypes - .Select(x => (Enum.GetName(typeof(SimpleCommodityCategory), x), () => - { - if (!_commodityFilter.filter) - { - _commodityFilter.filter = FilterPrototype.Instantiate(); - _commodityFilter.filter.OnDisable += () => - { - _commodityFilter.filter = null; - Populate(); - }; - } - if(_hardpointFilter.filter) - { - _hardpointFilter.filter.GetComponent().ReturnToPool(); - _hardpointFilter.filter = null; - } - if(_compoundCommodityFilter.filter) - { - _compoundCommodityFilter.filter.GetComponent().ReturnToPool(); - _compoundCommodityFilter.filter = null; - } - - _commodityFilter.filter.Label.text = $"Hardpoint: {Enum.GetName(typeof(SimpleCommodityCategory), x)}"; - _commodityFilter.type = x; - Populate(); - }, true))); - ContextMenu.AddDropdown("Compound Commodity", compoundCommodityTypes - .Select(x => (Enum.GetName(typeof(CompoundCommodityCategory), x), () => - { - if (!_compoundCommodityFilter.filter) - { - _compoundCommodityFilter.filter = FilterPrototype.Instantiate(); - _compoundCommodityFilter.filter.OnDisable += () => - { - _compoundCommodityFilter.filter = null; - Populate(); - }; - } - if(_hardpointFilter.filter) - { - _hardpointFilter.filter.GetComponent().ReturnToPool(); - _hardpointFilter.filter = null; - } - if(_commodityFilter.filter) - { - _commodityFilter.filter.GetComponent().ReturnToPool(); - _commodityFilter.filter = null; - } - - _compoundCommodityFilter.filter.Label.text = $"Hardpoint: {Enum.GetName(typeof(CompoundCommodityCategory), x)}"; - _compoundCommodityFilter.type = x; - Populate(); - }, true))); - ContextMenu.AddDropdown("Item Behavior", AetheriaRuntimeBehaviorMetadataCatalog.All - .Where(option => _behaviorFilters.All(filter => filter.Kind != option.Kind)) - .OrderBy(option => option.Kind, StringComparer.Ordinal) - .Select(x=> (x.Kind.FormatTypeName(), () => - { - var matchingType = _behaviorFilters.FirstOrDefault(y => - AetheriaRuntimeBehaviorMetadataCatalog.IsKindOrDescendant(y.Kind, x.Kind) || - AetheriaRuntimeBehaviorMetadataCatalog.IsKindOrDescendant(x.Kind, y.Kind)); - if (matchingType?.Filter != null) matchingType.Filter.DisableButton.onClick.Invoke(); - var filter = FilterPrototype.Instantiate(); - filter.Label.text = x.Kind.FormatTypeName(); - var behaviorFilter = new BehaviorFilter(filter, x); - filter.OnDisable += () => - { - _behaviorFilters.Remove(behaviorFilter); - Populate(); - }; - _behaviorFilters.Add(behaviorFilter); - Populate(); - }, true))); - if(!MinimumSizeFilter.gameObject.activeSelf) - ContextMenu.AddOption("Minimum Size", - () => - { - MinimumSizeFilter.gameObject.SetActive(true); - MinimumSizeFilter.OnDisable += () => Populate(); - }); - if(!MaximumSizeFilter.gameObject.activeSelf) - ContextMenu.AddOption("Maximum Size", - () => - { - MaximumSizeFilter.gameObject.SetActive(true); - MaximumSizeFilter.OnDisable += () => Populate(); - }); - ContextMenu.Show(); + RenderFilterSurface(); }); Populate(); } @@ -359,25 +242,9 @@ public class TradeMenu : MonoBehaviour { if (i.Item is SimpleCommodity s) { - ContextMenu.Clear(); - ContextMenu.AddOption("Buy Quantity", - () => - { - int quantity = 1; - Dialog.Clear(); - Dialog.Title.text = $"Buying {i.Name}"; - Dialog.AddField("Quantity", - () => quantity, - q => quantity = min(min(q, GameManager.Credits / i.Price), s.Quantity)); - Dialog.Show(() => - { - Buy(s,quantity); - - Populate(); - }); - Dialog.MoveToCursor(); - }); - ContextMenu.Show(); + RenderRowActionSurface( + $"Buying {i.Name}", + ("Buy Quantity", () => ShowBuyQuantityDialog(i.Name, i.Price, s))); } } })); @@ -614,6 +481,23 @@ public class TradeMenu : MonoBehaviour Dialog.MoveToCursor(); } + private void ShowBuyQuantityDialog(string itemName, int price, SimpleCommodity simpleCommodity) + { + int quantity = 1; + Dialog.Clear(); + Dialog.Title.text = $"Buying {itemName}"; + Dialog.AddField( + "Quantity", + () => quantity, + q => quantity = min(min(q, GameManager.Credits / price), simpleCommodity.Quantity)); + Dialog.Show(() => + { + Buy(simpleCommodity, quantity); + Populate(); + }); + Dialog.MoveToCursor(); + } + void Start() { FoldoutButton.onClick.AddListener(() => @@ -627,6 +511,553 @@ public class TradeMenu : MonoBehaviour } + private void RenderFilterSurface() + { + BuildFilterSurfaceCommands(); + + var document = ResolveFilterSurfaceDocument(); + document.gameObject.SetActive(true); + + var root = document.rootVisualElement; + root.Clear(); + root.style.flexGrow = 1; + root.style.position = Position.Absolute; + root.style.left = 0; + root.style.top = 0; + root.style.right = 0; + root.style.bottom = 0; + root.style.alignItems = Align.FlexStart; + root.style.justifyContent = Justify.FlexStart; + root.style.paddingTop = 16; + root.style.paddingLeft = 16; + root.pickingMode = PickingMode.Ignore; + + var shell = new 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 = PickingMode.Position; + root.Add(shell); + + var lowerer = new EveUiToolkitSurfaceLowerer(); + shell.Add(lowerer.Lower(BuildFilterSurfaceDefinition(), HandleFilterSurfaceCommand)); + } + + private void BuildFilterSurfaceCommands() + { + _filterSurfaceCommands.Clear(); + + foreach (var hardpointType in ((HardpointType[])Enum.GetValues(typeof(HardpointType))) + .Where(type => _hardpointFilter.filter == null || type != _hardpointFilter.type)) + { + var command = $"{FilterSurfaceId}.hardpoint.{hardpointType}"; + _filterSurfaceCommands[command] = () => ApplyHardpointFilter(hardpointType); + } + + foreach (var commodityType in ((SimpleCommodityCategory[])Enum.GetValues(typeof(SimpleCommodityCategory))) + .Where(type => _commodityFilter.filter == null || type != _commodityFilter.type)) + { + var command = $"{FilterSurfaceId}.simple.{commodityType}"; + _filterSurfaceCommands[command] = () => ApplySimpleCommodityFilter(commodityType); + } + + foreach (var commodityType in ((CompoundCommodityCategory[])Enum.GetValues(typeof(CompoundCommodityCategory))) + .Where(type => _compoundCommodityFilter.filter == null || type != _compoundCommodityFilter.type)) + { + var command = $"{FilterSurfaceId}.compound.{commodityType}"; + _filterSurfaceCommands[command] = () => ApplyCompoundCommodityFilter(commodityType); + } + + foreach (var metadata in AetheriaRuntimeBehaviorMetadataCatalog.All + .Where(option => _behaviorFilters.All(filter => filter.Kind != option.Kind)) + .OrderBy(option => option.Kind, StringComparer.Ordinal)) + { + var command = $"{FilterSurfaceId}.behavior.{metadata.Kind}"; + _filterSurfaceCommands[command] = () => ApplyBehaviorFilter(metadata); + } + + if (!MinimumSizeFilter.gameObject.activeSelf) + { + _filterSurfaceCommands[$"{FilterSurfaceId}.size.minimum"] = EnableMinimumSizeFilter; + } + + if (!MaximumSizeFilter.gameObject.activeSelf) + { + _filterSurfaceCommands[$"{FilterSurfaceId}.size.maximum"] = EnableMaximumSizeFilter; + } + } + + private void HandleFilterSurfaceCommand(EveSurfaceCommandRequest request) + { + if (string.Equals(request.Command, CloseFilterSurfaceCommand, StringComparison.Ordinal)) + { + HideFilterSurface(); + return; + } + + if (_filterSurfaceCommands.TryGetValue(request.Command, out var action)) + { + action(); + HideFilterSurface(); + return; + } + + Debug.LogWarning($"Unknown trade filter command: {request.Command}"); + } + + private void HideFilterSurface() + { + if (_filterSurfaceDocument == null) + return; + + _filterSurfaceDocument.rootVisualElement.Clear(); + _filterSurfaceDocument.gameObject.SetActive(false); + } + + private UIDocument ResolveFilterSurfaceDocument() + { + if (_filterSurfaceDocument != null) + return _filterSurfaceDocument; + + var host = new GameObject("Aetheria Trade Filter Surface"); + host.transform.SetParent(transform, false); + var document = host.AddComponent(); + document.sortingOrder = 1001; + host.SetActive(false); + _filterSurfaceDocument = document; + return document; + } + + private EveSurfaceDocument BuildFilterSurfaceDefinition() + { + var cards = new List + { + Card( + $"{FilterSurfaceId}.summary", + "Trade Filters", + Text( + $"{FilterSurfaceId}.note", + "Trade still owns filter state and population. This surface just removes the old context-menu shell."), + Text( + $"{FilterSurfaceId}.active", + BuildFilterSummary())) + }; + + var hardpointButtons = _filterSurfaceCommands.Keys + .Where(command => command.StartsWith($"{FilterSurfaceId}.hardpoint.", StringComparison.Ordinal)) + .OrderBy(command => command, StringComparer.Ordinal) + .Select(command => Button( + command, + command.Split('.').Last().FormatTypeName(), + command)) + .ToArray(); + if (hardpointButtons.Length > 0) + { + cards.Add(Card($"{FilterSurfaceId}.hardpoint.card", "Gear Type", ButtonColumn($"{FilterSurfaceId}.hardpoint.options", hardpointButtons))); + } + + var simpleButtons = _filterSurfaceCommands.Keys + .Where(command => command.StartsWith($"{FilterSurfaceId}.simple.", StringComparison.Ordinal)) + .OrderBy(command => command, StringComparer.Ordinal) + .Select(command => Button( + command, + command.Split('.').Last().FormatTypeName(), + command)) + .ToArray(); + if (simpleButtons.Length > 0) + { + cards.Add(Card($"{FilterSurfaceId}.simple.card", "Simple Commodity", ButtonColumn($"{FilterSurfaceId}.simple.options", simpleButtons))); + } + + var compoundButtons = _filterSurfaceCommands.Keys + .Where(command => command.StartsWith($"{FilterSurfaceId}.compound.", StringComparison.Ordinal)) + .OrderBy(command => command, StringComparer.Ordinal) + .Select(command => Button( + command, + command.Split('.').Last().FormatTypeName(), + command)) + .ToArray(); + if (compoundButtons.Length > 0) + { + cards.Add(Card($"{FilterSurfaceId}.compound.card", "Compound Commodity", ButtonColumn($"{FilterSurfaceId}.compound.options", compoundButtons))); + } + + var behaviorButtons = _filterSurfaceCommands.Keys + .Where(command => command.StartsWith($"{FilterSurfaceId}.behavior.", StringComparison.Ordinal)) + .OrderBy(command => command, StringComparer.Ordinal) + .Select(command => Button( + command, + command.Split('.').Last().FormatTypeName(), + command)) + .ToArray(); + if (behaviorButtons.Length > 0) + { + cards.Add(Card($"{FilterSurfaceId}.behavior.card", "Item Behavior", ButtonColumn($"{FilterSurfaceId}.behavior.options", behaviorButtons))); + } + + var sizeButtons = _filterSurfaceCommands.Keys + .Where(command => command.StartsWith($"{FilterSurfaceId}.size.", StringComparison.Ordinal)) + .OrderBy(command => command, StringComparer.Ordinal) + .Select(command => Button( + command, + command.EndsWith(".minimum", StringComparison.Ordinal) ? "Minimum Size" : "Maximum Size", + command)) + .ToArray(); + if (sizeButtons.Length > 0) + { + cards.Add(Card($"{FilterSurfaceId}.size.card", "Size", ButtonColumn($"{FilterSurfaceId}.size.options", sizeButtons))); + } + + cards.Add(ButtonRow($"{FilterSurfaceId}.actions", Button($"{FilterSurfaceId}.close", "Close", CloseFilterSurfaceCommand))); + + return new EveSurfaceDocument( + CargoSelectorSurfaceType, + CargoSelectorSurfaceSchema, + CargoSelectorSurfaceProviderId, + CargoSelectorSurfaceProviderKind, + "Trade Filter Selector", + version: 1, + DateTime.UtcNow.ToString("O"), + new EveSurfaceTree( + FilterSurfaceId, + Node( + $"{FilterSurfaceId}.root", + "surface", + Array.Empty<(string Key, string Value)>(), + cards.ToArray()), + Array.Empty()), + _filterSurfaceCommands.Keys + .Select(command => new EveCommandTemplate(command, command.Split('.').Last().FormatTypeName(), "unity-uitoolkit")) + .Append(new EveCommandTemplate(CloseFilterSurfaceCommand, "Close", "unity-uitoolkit")) + .ToArray()); + } + + private void RenderRowActionSurface(string title, params (string Label, Action Action)[] actions) + { + _rowActionTitle = title; + BuildRowActionSurfaceCommands(actions); + + var document = ResolveRowActionSurfaceDocument(); + document.gameObject.SetActive(true); + + var root = document.rootVisualElement; + root.Clear(); + root.style.flexGrow = 1; + root.style.position = Position.Absolute; + root.style.left = 0; + root.style.top = 0; + root.style.right = 0; + root.style.bottom = 0; + root.style.alignItems = Align.FlexStart; + root.style.justifyContent = Justify.FlexStart; + root.style.paddingTop = 16; + root.style.paddingLeft = 16; + root.pickingMode = PickingMode.Ignore; + + var shell = new VisualElement(); + shell.style.width = 320; + shell.style.maxWidth = 360; + 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 = PickingMode.Position; + root.Add(shell); + + var lowerer = new EveUiToolkitSurfaceLowerer(); + shell.Add(lowerer.Lower(BuildRowActionSurfaceDefinition(), HandleRowActionSurfaceCommand)); + } + + private void BuildRowActionSurfaceCommands(IEnumerable<(string Label, Action Action)> actions) + { + _rowActionSurfaceCommands.Clear(); + + foreach (var actionEntry in actions.Select((entry, index) => (entry, index))) + { + var command = $"{RowActionSurfaceId}.action_{actionEntry.index}"; + _rowActionSurfaceCommands[command] = actionEntry.entry.Action; + } + } + + private void HandleRowActionSurfaceCommand(EveSurfaceCommandRequest request) + { + if (string.Equals(request.Command, CloseRowActionSurfaceCommand, StringComparison.Ordinal)) + { + HideRowActionSurface(); + return; + } + + if (_rowActionSurfaceCommands.TryGetValue(request.Command, out var action)) + { + action(); + HideRowActionSurface(); + return; + } + + Debug.LogWarning($"Unknown trade row action command: {request.Command}"); + } + + private void HideRowActionSurface() + { + if (_rowActionSurfaceDocument == null) + return; + + _rowActionSurfaceDocument.rootVisualElement.Clear(); + _rowActionSurfaceDocument.gameObject.SetActive(false); + } + + private UIDocument ResolveRowActionSurfaceDocument() + { + if (_rowActionSurfaceDocument != null) + return _rowActionSurfaceDocument; + + var host = new GameObject("Aetheria Trade Row Action Surface"); + host.transform.SetParent(transform, false); + var document = host.AddComponent(); + document.sortingOrder = 1002; + host.SetActive(false); + _rowActionSurfaceDocument = document; + return document; + } + + private EveSurfaceDocument BuildRowActionSurfaceDefinition() + { + var commands = _rowActionSurfaceCommands.Keys.OrderBy(command => command, StringComparer.Ordinal).ToArray(); + var buttons = commands + .Select(command => Button(command, command.EndsWith("action_0", StringComparison.Ordinal) ? "Buy Quantity" : command.Split('.').Last(), command)) + .ToArray(); + + return new EveSurfaceDocument( + CargoSelectorSurfaceType, + CargoSelectorSurfaceSchema, + CargoSelectorSurfaceProviderId, + CargoSelectorSurfaceProviderKind, + "Trade Row Actions", + version: 1, + DateTime.UtcNow.ToString("O"), + new EveSurfaceTree( + RowActionSurfaceId, + Node( + $"{RowActionSurfaceId}.root", + "surface", + Array.Empty<(string Key, string Value)>(), + Card( + $"{RowActionSurfaceId}.card", + "Trade Action", + Text($"{RowActionSurfaceId}.title", _rowActionTitle), + Text( + $"{RowActionSurfaceId}.note", + "Trade still owns the quantity dialog and purchase commit. This surface just removes the old right-click context-menu shell."), + ButtonColumn($"{RowActionSurfaceId}.options", buttons), + ButtonRow($"{RowActionSurfaceId}.actions", Button($"{RowActionSurfaceId}.close", "Close", CloseRowActionSurfaceCommand)))), + Array.Empty()), + commands + .Select(command => new EveCommandTemplate(command, command.EndsWith("action_0", StringComparison.Ordinal) ? "Buy Quantity" : command.Split('.').Last(), "unity-uitoolkit")) + .Append(new EveCommandTemplate(CloseRowActionSurfaceCommand, "Close", "unity-uitoolkit")) + .ToArray()); + } + + private void ApplyHardpointFilter(HardpointType hardpointType) + { + EnsureHardpointFilter(); + ClearCommodityFilters(); + _hardpointFilter.filter.Label.text = $"Hardpoint: {Enum.GetName(typeof(HardpointType), hardpointType)}"; + _hardpointFilter.type = hardpointType; + Populate(); + } + + private void ApplySimpleCommodityFilter(SimpleCommodityCategory category) + { + EnsureCommodityFilter(); + ClearHardpointFilter(); + ClearCompoundCommodityFilter(); + _commodityFilter.filter.Label.text = $"Simple Commodity: {Enum.GetName(typeof(SimpleCommodityCategory), category)}"; + _commodityFilter.type = category; + Populate(); + } + + private void ApplyCompoundCommodityFilter(CompoundCommodityCategory category) + { + EnsureCompoundCommodityFilter(); + ClearHardpointFilter(); + ClearCommodityFilter(); + _compoundCommodityFilter.filter.Label.text = $"Compound Commodity: {Enum.GetName(typeof(CompoundCommodityCategory), category)}"; + _compoundCommodityFilter.type = category; + Populate(); + } + + private void ApplyBehaviorFilter(AetheriaRuntimeBehaviorMetadata metadata) + { + var matchingType = _behaviorFilters.FirstOrDefault(filter => + AetheriaRuntimeBehaviorMetadataCatalog.IsKindOrDescendant(filter.Kind, metadata.Kind) || + AetheriaRuntimeBehaviorMetadataCatalog.IsKindOrDescendant(metadata.Kind, filter.Kind)); + if (matchingType?.Filter != null) + { + matchingType.Filter.DisableButton.onClick.Invoke(); + } + + var filter = FilterPrototype.Instantiate(); + filter.Label.text = metadata.Kind.FormatTypeName(); + var behaviorFilter = new BehaviorFilter(filter, metadata); + filter.OnDisable += () => + { + _behaviorFilters.Remove(behaviorFilter); + Populate(); + }; + _behaviorFilters.Add(behaviorFilter); + Populate(); + } + + private void EnableMinimumSizeFilter() + { + MinimumSizeFilter.gameObject.SetActive(true); + MinimumSizeFilter.OnDisable += () => Populate(); + Populate(); + } + + private void EnableMaximumSizeFilter() + { + MaximumSizeFilter.gameObject.SetActive(true); + MaximumSizeFilter.OnDisable += () => Populate(); + Populate(); + } + + private void EnsureHardpointFilter() + { + if (_hardpointFilter.filter != null) + return; + + _hardpointFilter.filter = FilterPrototype.Instantiate(); + _hardpointFilter.filter.OnDisable += () => + { + _hardpointFilter.filter = null; + Populate(); + }; + } + + private void EnsureCommodityFilter() + { + if (_commodityFilter.filter != null) + return; + + _commodityFilter.filter = FilterPrototype.Instantiate(); + _commodityFilter.filter.OnDisable += () => + { + _commodityFilter.filter = null; + Populate(); + }; + } + + private void EnsureCompoundCommodityFilter() + { + if (_compoundCommodityFilter.filter != null) + return; + + _compoundCommodityFilter.filter = FilterPrototype.Instantiate(); + _compoundCommodityFilter.filter.OnDisable += () => + { + _compoundCommodityFilter.filter = null; + Populate(); + }; + } + + private void ClearHardpointFilter() + { + if (_hardpointFilter.filter == null) + return; + + _hardpointFilter.filter.GetComponent().ReturnToPool(); + _hardpointFilter.filter = null; + } + + private void ClearCommodityFilter() + { + if (_commodityFilter.filter == null) + return; + + _commodityFilter.filter.GetComponent().ReturnToPool(); + _commodityFilter.filter = null; + } + + private void ClearCompoundCommodityFilter() + { + if (_compoundCommodityFilter.filter == null) + return; + + _compoundCommodityFilter.filter.GetComponent().ReturnToPool(); + _compoundCommodityFilter.filter = null; + } + + private void ClearCommodityFilters() + { + ClearCommodityFilter(); + ClearCompoundCommodityFilter(); + } + + private string BuildFilterSummary() + { + var activeFilters = new List(); + if (_hardpointFilter.filter != null) + { + activeFilters.Add($"Gear: {Enum.GetName(typeof(HardpointType), _hardpointFilter.type)}"); + } + + if (_commodityFilter.filter != null) + { + activeFilters.Add($"Simple: {Enum.GetName(typeof(SimpleCommodityCategory), _commodityFilter.type)}"); + } + + if (_compoundCommodityFilter.filter != null) + { + activeFilters.Add($"Compound: {Enum.GetName(typeof(CompoundCommodityCategory), _compoundCommodityFilter.type)}"); + } + + activeFilters.AddRange(_behaviorFilters.Select(filter => $"Behavior: {filter.Kind.FormatTypeName()}")); + + if (MinimumSizeFilter.gameObject.activeSelf) + { + activeFilters.Add("Minimum size active"); + } + + if (MaximumSizeFilter.gameObject.activeSelf) + { + activeFilters.Add("Maximum size active"); + } + + return activeFilters.Count == 0 + ? "No active filters" + : string.Join(" | ", activeFilters); + } + private void RenderCargoSelectorSurface() { BuildCargoSelectionCommands(); @@ -842,6 +1273,8 @@ public class TradeMenu : MonoBehaviour private void OnDisable() { HideCargoSelectorSurface(); + HideFilterSurface(); + HideRowActionSurface(); } private void OnDestroy() @@ -851,5 +1284,17 @@ public class TradeMenu : MonoBehaviour Destroy(_cargoSelectorSurfaceDocument.gameObject); _cargoSelectorSurfaceDocument = null; } + + if (_filterSurfaceDocument != null) + { + Destroy(_filterSurfaceDocument.gameObject); + _filterSurfaceDocument = null; + } + + if (_rowActionSurfaceDocument != null) + { + Destroy(_rowActionSurfaceDocument.gameObject); + _rowActionSurfaceDocument = null; + } } } diff --git a/docs/aetheria-perfect-machine-map.md b/docs/aetheria-perfect-machine-map.md index 9b5abed3d..655a9c645 100644 --- a/docs/aetheria-perfect-machine-map.md +++ b/docs/aetheria-perfect-machine-map.md @@ -126,6 +126,9 @@ legacy catalog cache, and legacy UI paths should be migration-only or deleted. Inventory entity/bay/loadout dropdown navigation now lowers through a local Eve/UI Toolkit surface instead of rebuilding nested `ContextMenu` dropdowns/options. + Trade filter selection and simple-commodity buy-quantity entry now lower + through local Eve/UI Toolkit surfaces instead of rebuilding `ContextMenu` + dropdowns/options in `TradeMenu`. - 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 @@ -1577,6 +1580,11 @@ First Aetheria surfaces to publish: 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: replace the remaining `TradeMenu` filter-selector and row-action + popups with Eve-owned UI Toolkit surfaces. `TradeMenu` still owns local + filter state and the quantity dialog still delegates to gameplay-owned + purchase commits, but the old `ContextMenu` dropdown/option tree no longer + owns any live trade-menu 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 @@ -1951,6 +1959,10 @@ First Aetheria surfaces to publish: UI Toolkit `UIDocument` host and a local Eve surface document instead of rebuilding nested `ContextMenu.AddDropdown(...)` and `ContextMenu.AddOption(...)` menus. +- Trade filter selection and simple-commodity buy-quantity entry now lower + through shared UI Toolkit `UIDocument` hosts and local Eve surface documents + instead of rebuilding `ContextMenu.AddDropdown(...)`, `ContextMenu.AddOption(...)`, + and `ContextMenu.Show()` shells in `TradeMenu`. - 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