diff --git a/src/Koogle.Application/Games/ChristmasTree/ChristmasTreeGameLogicService.cs b/src/Koogle.Application/Games/ChristmasTree/ChristmasTreeGameLogicService.cs index 6a30f34..50dd8d5 100644 --- a/src/Koogle.Application/Games/ChristmasTree/ChristmasTreeGameLogicService.cs +++ b/src/Koogle.Application/Games/ChristmasTree/ChristmasTreeGameLogicService.cs @@ -453,7 +453,21 @@ public class ChristmasTreeGameLogicService : IGameLogicService Icon = "TouchApp", Color = "Primary", Tooltip = $"Wähle eine Zahl zum Streichen: {string.Join(", ", availableNumbers)}", - Order = 1 + Order = 1, + Parameters = + [ + new ActionParameterDefinition + { + Key = "number", + Label = "Wähle eine Zahl", + Type = "select", + Options = availableNumbers.Select(n => new ActionParameterOption + { + Value = n, + Label = n.ToString() + }).ToList() + } + ] } ]; } diff --git a/src/Koogle.Application/Games/GameActionTypes.cs b/src/Koogle.Application/Games/GameActionTypes.cs index 4f1170e..74c5596 100644 --- a/src/Koogle.Application/Games/GameActionTypes.cs +++ b/src/Koogle.Application/Games/GameActionTypes.cs @@ -39,6 +39,53 @@ public record GameActionDescriptor /// Display order for sorting (lower = first). /// public int Order { get; init; } = 100; + + /// + /// Parameter definitions if action requires user input. + /// + public IReadOnlyList? Parameters { get; init; } +} + +/// +/// Defines a parameter that must be collected from the user before executing an action. +/// +public record ActionParameterDefinition +{ + /// + /// Parameter key (used in the parameters dictionary). + /// + public required string Key { get; init; } + + /// + /// Display label for the parameter. + /// + public required string Label { get; init; } + + /// + /// Parameter type: "select" for dropdown, "number" for numeric input. + /// + public string Type { get; init; } = "select"; + + /// + /// Available options for "select" type. + /// + public IReadOnlyList? Options { get; init; } +} + +/// +/// An option for a select-type parameter. +/// +public record ActionParameterOption +{ + /// + /// The value to use when this option is selected. + /// + public required object Value { get; init; } + + /// + /// Display label for the option. + /// + public required string Label { get; init; } } /// diff --git a/src/Koogle.Web/Components/Game/GameActionPanel.razor b/src/Koogle.Web/Components/Game/GameActionPanel.razor index 6dfaa22..7e2424e 100644 --- a/src/Koogle.Web/Components/Game/GameActionPanel.razor +++ b/src/Koogle.Web/Components/Game/GameActionPanel.razor @@ -17,7 +17,7 @@ Color="@GetColor(action.Color)" StartIcon="@GetIcon(action.Icon)" Disabled="@(!action.IsEnabled || GameState.Value.IsSaving || GameState.Value.IsLoading)" - OnClick="@(() => ExecuteAction(action.ActionId))" + OnClick="@(() => OnActionClick(action))" Title="@action.Tooltip" Class="game-action-button"> @action.Label @@ -26,6 +26,40 @@ } + + + @_currentAction?.Label + + + @if (_currentAction?.Parameters != null) + { + @foreach (var param in _currentAction.Parameters) + { + @if (param.Type == "select" && param.Options != null) + { + + @param.Label + + @foreach (var option in param.Options) + { + + @option.Label + + } + + + } + } + } + + + Abbrechen + + + @code { private IReadOnlyList _availableActions = []; + private bool _dialogVisible; + private GameActionDescriptor? _currentAction; + private readonly DialogOptions _dialogOptions = new() { CloseOnEscapeKey = true, MaxWidth = MaxWidth.Small }; protected override void OnInitialized() { @@ -81,9 +126,32 @@ } } - private void ExecuteAction(string actionId) + private void OnActionClick(GameActionDescriptor action) { - Dispatcher.Dispatch(new ExecuteGameActionAction(actionId)); + if (action.Parameters is { Count: > 0 }) + { + _currentAction = action; + _dialogVisible = true; + } + else + { + Dispatcher.Dispatch(new ExecuteGameActionAction(action.ActionId)); + } + } + + private void SelectOption(string paramKey, object value) + { + if (_currentAction == null) return; + + var parameters = new Dictionary { [paramKey] = value }; + Dispatcher.Dispatch(new ExecuteGameActionAction(_currentAction.ActionId, parameters)); + CloseDialog(); + } + + private void CloseDialog() + { + _dialogVisible = false; + _currentAction = null; } private static Color GetColor(string colorName) => colorName switch