Move trade row actions into runtime projection
This commit is contained in:
parent
48c794de21
commit
5f068a4737
3 changed files with 105 additions and 38 deletions
|
|
@ -4654,11 +4654,12 @@ static void RequireTradeFilterAndRowActionsUseEveSurface(string root)
|
|||
"AetheriaRuntimeTradeInteractionSurfaceBuilder.BuildFilter(ProjectTradeFilterSurfaceState(",
|
||||
"ProjectTradeFilterSurfaceState(",
|
||||
"RenderRowActionSurface(",
|
||||
"BuildRowActionSurfaceCommands(",
|
||||
"HandleRowActionSurfaceCommand(",
|
||||
"AetheriaEveUnitySurfaceHost.Hide(_rowActionSurfaceDocument)",
|
||||
"AetheriaRuntimeTradeInteractionSurfaceBuilder.BuildRowActions(ProjectTradeRowActionSurfaceState(",
|
||||
"ProjectTradeRowActionSurfaceState(",
|
||||
"AetheriaRuntimeTradeInteractionSurfaceBuilder.ProjectRowActions(",
|
||||
"AetheriaRuntimeTradeInteractionSurfaceBuilder.BuildRowActions(_rowActionSurfaceProjection.State)",
|
||||
"_rowActionSurfaceProjection?.TryResolve(command.Command, out var selection) == true",
|
||||
"new AetheriaRuntimeTradeRowActionOption(index, action.Label)",
|
||||
"ShowBuyQuantityDialog(",
|
||||
"AetheriaRuntimeTradeInteractionSurfaceCommands.TryReadFilter(request, out var command)",
|
||||
"AetheriaRuntimeTradeInteractionSurfaceCommands.TryReadRowAction(request, out var command)",
|
||||
|
|
@ -4699,7 +4700,10 @@ static void RequireTradeFilterAndRowActionsUseEveSurface(string root)
|
|||
"string.Equals(request.Command, AetheriaRuntimeTradeInteractionSurfaceBuilder.CloseFilter",
|
||||
"string.Equals(request.Command, AetheriaRuntimeTradeInteractionSurfaceBuilder.CloseRowAction",
|
||||
"_filterSurfaceCommands.TryGetValue(request.Command",
|
||||
"_rowActionSurfaceCommands.TryGetValue(request.Command"
|
||||
"_rowActionSurfaceCommands.TryGetValue(request.Command",
|
||||
"private readonly Dictionary<string, Action> _rowActionSurfaceCommands",
|
||||
"BuildRowActionSurfaceCommands(",
|
||||
"ProjectTradeRowActionSurfaceState("
|
||||
};
|
||||
|
||||
var hits = forbiddenSymbols
|
||||
|
|
@ -4727,10 +4731,15 @@ static void RequireTradeFilterAndRowActionsUseEveSurface(string root)
|
|||
"public static bool TryReadRowAction(",
|
||||
"AetheriaRuntimeTradeFilterSurfaceState",
|
||||
"AetheriaRuntimeTradeRowActionSurfaceState",
|
||||
"AetheriaRuntimeTradeRowActionOption",
|
||||
"AetheriaRuntimeTradeRowActionSelection",
|
||||
"AetheriaRuntimeTradeRowActionSurfaceProjection",
|
||||
"AetheriaRuntimeTradeSurfaceGroup",
|
||||
"AetheriaRuntimeTradeSurfaceOption",
|
||||
"public static string HardpointFilterCommand(",
|
||||
"public static string RowActionCommand(",
|
||||
"public static AetheriaRuntimeTradeRowActionSurfaceProjection ProjectRowActions(",
|
||||
"public bool TryResolve(string command, out AetheriaRuntimeTradeRowActionSelection selection)",
|
||||
"public static AetheriaRuntimeSurfaceDocument BuildFilter(",
|
||||
"public static AetheriaRuntimeSurfaceDocument BuildRowActions(",
|
||||
"providerKind: \"trade.menu\""
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ public class TradeMenu : MonoBehaviour
|
|||
private (ItemFilter filter, CompoundCommodityCategory type) _compoundCommodityFilter;
|
||||
private List<BehaviorFilter> _behaviorFilters = new List<BehaviorFilter>();
|
||||
private readonly Dictionary<string, Action> _filterSurfaceCommands = new Dictionary<string, Action>(StringComparer.Ordinal);
|
||||
private readonly Dictionary<string, Action> _rowActionSurfaceCommands = new Dictionary<string, Action>(StringComparer.Ordinal);
|
||||
private readonly Dictionary<string, (EquippedCargoBay Cargo, string Label)> _cargoSelectionCommands =
|
||||
new Dictionary<string, (EquippedCargoBay Cargo, string Label)>(StringComparer.Ordinal);
|
||||
private UIDocument _cargoSelectorSurfaceDocument;
|
||||
|
|
@ -41,7 +40,8 @@ public class TradeMenu : MonoBehaviour
|
|||
private readonly AetheriaEveUnitySurfaceChrome _filterSurfaceChrome = PanelChrome(420f, 520f, Align.FlexStart);
|
||||
private readonly AetheriaEveUnitySurfaceChrome _rowActionSurfaceChrome = PanelChrome(320f, 360f, Align.FlexStart);
|
||||
private readonly AetheriaEveUnitySurfaceChrome _tradeItemSurfaceChrome = PanelChrome(420f, 520f, Align.FlexStart);
|
||||
private string _rowActionTitle = "Trade Actions";
|
||||
private Action[] _rowActionCallbacks = Array.Empty<Action>();
|
||||
private AetheriaRuntimeTradeRowActionSurfaceProjection _rowActionSurfaceProjection;
|
||||
|
||||
public EquippedCargoBay Inventory { get; set; }
|
||||
|
||||
|
|
@ -794,30 +794,24 @@ public class TradeMenu : MonoBehaviour
|
|||
|
||||
private void RenderRowActionSurface(string title, params (string Label, Action Action)[] actions)
|
||||
{
|
||||
_rowActionTitle = title;
|
||||
BuildRowActionSurfaceCommands(actions);
|
||||
_rowActionCallbacks = actions
|
||||
.Select(action => action.Action)
|
||||
.ToArray();
|
||||
_rowActionSurfaceProjection = AetheriaRuntimeTradeInteractionSurfaceBuilder.ProjectRowActions(
|
||||
title,
|
||||
actions.Select((action, index) => new AetheriaRuntimeTradeRowActionOption(index, action.Label)),
|
||||
DateTime.UtcNow.ToString("O"));
|
||||
|
||||
_rowActionSurfaceDocument = AetheriaEveUnitySurfaceHost.RenderRuntime(
|
||||
transform,
|
||||
_rowActionSurfaceDocument,
|
||||
"Aetheria Trade Row Action Surface",
|
||||
AetheriaRuntimeTradeInteractionSurfaceBuilder.BuildRowActions(ProjectTradeRowActionSurfaceState()),
|
||||
AetheriaRuntimeTradeInteractionSurfaceBuilder.BuildRowActions(_rowActionSurfaceProjection.State),
|
||||
HandleRowActionSurfaceCommand,
|
||||
_rowActionSurfaceChrome,
|
||||
sortingOrder: 1002);
|
||||
}
|
||||
|
||||
private void BuildRowActionSurfaceCommands(IEnumerable<(string Label, Action Action)> actions)
|
||||
{
|
||||
_rowActionSurfaceCommands.Clear();
|
||||
|
||||
foreach (var actionEntry in actions.Select((entry, index) => (entry, index)))
|
||||
{
|
||||
var command = AetheriaRuntimeTradeInteractionSurfaceBuilder.RowActionCommand(actionEntry.index);
|
||||
_rowActionSurfaceCommands[command] = actionEntry.entry.Action;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleRowActionSurfaceCommand(EveSurfaceCommandRequest request)
|
||||
{
|
||||
if (!AetheriaRuntimeTradeInteractionSurfaceCommands.TryReadRowAction(request, out var command))
|
||||
|
|
@ -833,9 +827,11 @@ public class TradeMenu : MonoBehaviour
|
|||
}
|
||||
|
||||
if (command.Kind == AetheriaRuntimeTradeInteractionCommandKind.Select &&
|
||||
_rowActionSurfaceCommands.TryGetValue(command.Command, out var action))
|
||||
_rowActionSurfaceProjection?.TryResolve(command.Command, out var selection) == true &&
|
||||
selection.Index >= 0 &&
|
||||
selection.Index < _rowActionCallbacks.Length)
|
||||
{
|
||||
action();
|
||||
_rowActionCallbacks[selection.Index]?.Invoke();
|
||||
HideRowActionSurface();
|
||||
return;
|
||||
}
|
||||
|
|
@ -851,22 +847,6 @@ public class TradeMenu : MonoBehaviour
|
|||
AetheriaEveUnitySurfaceHost.Hide(_rowActionSurfaceDocument);
|
||||
}
|
||||
|
||||
private AetheriaRuntimeTradeRowActionSurfaceState ProjectTradeRowActionSurfaceState()
|
||||
{
|
||||
var actions = _rowActionSurfaceCommands.Keys
|
||||
.OrderBy(command => command, StringComparer.Ordinal)
|
||||
.Select(command => new AetheriaRuntimeTradeSurfaceOption(
|
||||
command,
|
||||
command.EndsWith("action_0", StringComparison.Ordinal) ? "Buy Quantity" : command.Split('.').Last(),
|
||||
command))
|
||||
.ToArray();
|
||||
|
||||
return new AetheriaRuntimeTradeRowActionSurfaceState(
|
||||
_rowActionTitle,
|
||||
actions,
|
||||
DateTime.UtcNow.ToString("O"));
|
||||
}
|
||||
|
||||
private void ApplyHardpointFilter(HardpointType hardpointType)
|
||||
{
|
||||
EnsureHardpointFilter();
|
||||
|
|
|
|||
|
|
@ -70,6 +70,52 @@ namespace GameCult.Aetheria.State.Verse
|
|||
public string UpdatedAtUtc { get; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeTradeRowActionOption
|
||||
{
|
||||
public AetheriaRuntimeTradeRowActionOption(int index, string label)
|
||||
{
|
||||
Index = index;
|
||||
Label = label ?? "";
|
||||
}
|
||||
|
||||
public int Index { get; }
|
||||
public string Label { get; }
|
||||
}
|
||||
|
||||
public readonly struct AetheriaRuntimeTradeRowActionSelection
|
||||
{
|
||||
public AetheriaRuntimeTradeRowActionSelection(string command, int index)
|
||||
{
|
||||
Command = command ?? "";
|
||||
Index = index;
|
||||
}
|
||||
|
||||
public string Command { get; }
|
||||
public int Index { get; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeTradeRowActionSurfaceProjection
|
||||
{
|
||||
public AetheriaRuntimeTradeRowActionSurfaceProjection(
|
||||
AetheriaRuntimeTradeRowActionSurfaceState state,
|
||||
IReadOnlyDictionary<string, AetheriaRuntimeTradeRowActionSelection> selections)
|
||||
{
|
||||
State = state ?? new AetheriaRuntimeTradeRowActionSurfaceState(
|
||||
"",
|
||||
Array.Empty<AetheriaRuntimeTradeSurfaceOption>(),
|
||||
"");
|
||||
Selections = selections ?? new Dictionary<string, AetheriaRuntimeTradeRowActionSelection>(StringComparer.Ordinal);
|
||||
}
|
||||
|
||||
public AetheriaRuntimeTradeRowActionSurfaceState State { get; }
|
||||
public IReadOnlyDictionary<string, AetheriaRuntimeTradeRowActionSelection> Selections { get; }
|
||||
|
||||
public bool TryResolve(string command, out AetheriaRuntimeTradeRowActionSelection selection)
|
||||
{
|
||||
return Selections.TryGetValue(command ?? "", out selection);
|
||||
}
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeTradeInteractionSurfaceBuilder
|
||||
{
|
||||
public const string FilterSurfaceId = "aetheria.trade.filter_selector";
|
||||
|
|
@ -112,6 +158,38 @@ namespace GameCult.Aetheria.State.Verse
|
|||
return $"{RowActionSurfaceId}.action_{index}";
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeTradeRowActionSurfaceProjection ProjectRowActions(
|
||||
string title,
|
||||
IEnumerable<AetheriaRuntimeTradeRowActionOption> actions,
|
||||
string updatedAtUtc)
|
||||
{
|
||||
var options = new List<AetheriaRuntimeTradeSurfaceOption>();
|
||||
var selections = new Dictionary<string, AetheriaRuntimeTradeRowActionSelection>(StringComparer.Ordinal);
|
||||
|
||||
foreach (var action in actions ?? Array.Empty<AetheriaRuntimeTradeRowActionOption>())
|
||||
{
|
||||
if (action == null || action.Index < 0)
|
||||
continue;
|
||||
|
||||
var command = RowActionCommand(action.Index);
|
||||
var label = string.IsNullOrWhiteSpace(action.Label)
|
||||
? $"Action {action.Index + 1}"
|
||||
: action.Label;
|
||||
options.Add(new AetheriaRuntimeTradeSurfaceOption(
|
||||
$"{RowActionSurfaceId}.action_{action.Index}",
|
||||
label,
|
||||
command));
|
||||
selections[command] = new AetheriaRuntimeTradeRowActionSelection(command, action.Index);
|
||||
}
|
||||
|
||||
return new AetheriaRuntimeTradeRowActionSurfaceProjection(
|
||||
new AetheriaRuntimeTradeRowActionSurfaceState(
|
||||
title,
|
||||
options,
|
||||
updatedAtUtc),
|
||||
selections);
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeSurfaceDocument BuildFilter(
|
||||
AetheriaRuntimeTradeFilterSurfaceState state,
|
||||
long version = 1)
|
||||
|
|
|
|||
Loading…
Reference in a new issue