del UndoButton
This commit is contained in:
parent
ea08ff9a5b
commit
0a7fb1f0af
|
|
@ -1,103 +0,0 @@
|
||||||
@using Koogle.Web.Store.GameState
|
|
||||||
@inherits FluxorComponent
|
|
||||||
|
|
||||||
@inject IState<GameState> GameState
|
|
||||||
@inject IDispatcher Dispatcher
|
|
||||||
|
|
||||||
@* Only show when undo is available *@
|
|
||||||
@if (CanUndo)
|
|
||||||
{
|
|
||||||
<MudButton Variant="@Variant"
|
|
||||||
Color="Color.Secondary"
|
|
||||||
FullWidth="@FullWidth"
|
|
||||||
Size="@Size"
|
|
||||||
Disabled="@IsDisabled"
|
|
||||||
OnClick="HandleUndo"
|
|
||||||
StartIcon="@Icons.Material.Filled.Undo"
|
|
||||||
Class="@Class">
|
|
||||||
@ButtonText
|
|
||||||
</MudButton>
|
|
||||||
}
|
|
||||||
|
|
||||||
@code {
|
|
||||||
/// <summary>
|
|
||||||
/// Whether to show the button even when no undo is available.
|
|
||||||
/// </summary>
|
|
||||||
[Parameter]
|
|
||||||
public bool AlwaysShow { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Button variant (default: Outlined).
|
|
||||||
/// </summary>
|
|
||||||
[Parameter]
|
|
||||||
public Variant Variant { get; set; } = Variant.Outlined;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Whether button should be full width.
|
|
||||||
/// </summary>
|
|
||||||
[Parameter]
|
|
||||||
public bool FullWidth { get; set; } = true;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Button size.
|
|
||||||
/// </summary>
|
|
||||||
[Parameter]
|
|
||||||
public Size Size { get; set; } = Size.Medium;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Additional CSS classes.
|
|
||||||
/// </summary>
|
|
||||||
[Parameter]
|
|
||||||
public string? Class { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Optional custom button text. If not set, shows count.
|
|
||||||
/// </summary>
|
|
||||||
[Parameter]
|
|
||||||
public string? CustomText { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Whether to show the undo count in the button text.
|
|
||||||
/// </summary>
|
|
||||||
[Parameter]
|
|
||||||
public bool ShowCount { get; set; } = true;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Callback when undo is triggered.
|
|
||||||
/// </summary>
|
|
||||||
[Parameter]
|
|
||||||
public EventCallback OnUndoTriggered { get; set; }
|
|
||||||
|
|
||||||
private int UndoCount => GameState.Value.UndoStack.Count;
|
|
||||||
private bool CanUndo => UndoCount > 0 || AlwaysShow;
|
|
||||||
private bool IsDisabled => UndoCount == 0 || GameState.Value.IsSaving;
|
|
||||||
|
|
||||||
private string ButtonText
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (!string.IsNullOrEmpty(CustomText))
|
|
||||||
return CustomText;
|
|
||||||
|
|
||||||
var baseText = "Letzten Wurf rückgängig";
|
|
||||||
return ShowCount && UndoCount > 0
|
|
||||||
? $"{baseText} ({UndoCount})"
|
|
||||||
: baseText;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task HandleUndo()
|
|
||||||
{
|
|
||||||
if (UndoCount == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var lastSnapshot = GameState.Value.UndoStack[^1];
|
|
||||||
|
|
||||||
Dispatcher.Dispatch(new UndoThrowSuccessAction(
|
|
||||||
lastSnapshot.ThrowPanel,
|
|
||||||
lastSnapshot.Participants,
|
|
||||||
lastSnapshot.GameModel));
|
|
||||||
|
|
||||||
await OnUndoTriggered.InvokeAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue