upd bell button

This commit is contained in:
beo3000 2025-11-10 11:12:05 +01:00
parent b93a7048fd
commit acb9201725
9 changed files with 92 additions and 99 deletions

View File

@ -1,52 +1,51 @@
@if (!Value) @using KoogleApp.Model
{ @using KoogleApp.Store.Game.ThrowPanel
<MudButton OnClick="ToggleClick" Disabled="Disabled">
<MudIcon Class="ma-2" Icon="@Icons.Material.Filled.AddAlert" Color="Color.Dark" Style="font-size: 3rem;" />
</MudButton>
}
else
{
<MudButton OnClick="ToggleClick" Disabled="Disabled">
<MudIcon Class="ma-2" Icon="@Icons.Material.Filled.AddAlert" Color="Color.Tertiary"
Style="font-size: 3rem;"/>
</MudButton>
}
<MudSwitch T="bool" Label="" Size="Size.Medium" Disabled="Disabled" @inherits FluxorComponent
ThumbIcon="@(Value ? Icons.Material.Filled.Done : @Icons.Material.Filled.AddAlert)" ThumbIconColor="@(Value ? Color.Success : Color.Primary)"
@bind-Value="Value"/> @inject IDispatcher Dispatcher
@inject IState<ThrowPanelState> State
<MudButton OnClick="ToggleClick" Disabled="false">
<MudIcon Class="ma-2" Icon="@Icons.Material.Filled.AddAlert"
Color="@(State.Value.BellValue ? Color.Primary : Color.Warning)"
Style="font-size: 3rem;"/>
</MudButton>
@* <MudSwitch T="bool" Label="" Size="Size.Medium" Disabled="false"
@bind-Value="MudSwitchValue"
ThumbIcon="@(State.Value.BellValue ? Icons.Material.Filled.Done : @Icons.Material.Filled.AddAlert)"
ThumbIconColor="@(State.Value.BellValue ? Color.Success : Color.Primary)" /> *@
@code { @code {
private bool _value; // private bool _mudSwitchValue;
[Parameter] // private bool MudSwitchValue
public bool Value // {
// get => _mudSwitchValue;
// set
// {
// if (_mudSwitchValue == value)
// {
// return;
// }
// _mudSwitchValue = value;
// Dispatcher.Dispatch(new ToggleBellAction());
// }
// }
// protected override void OnAfterRender(bool firstRender)
// {
// base.OnAfterRender(firstRender);
// _mudSwitchValue = State.Value.BellValue;
// }
private void ToggleClick(MouseEventArgs obj)
{ {
get => _value; Dispatcher.Dispatch(new ToggleBellAction());
set
{
if (_value == value) return;
_value = value;
InvokeAsync(async () => await ValueChanged.InvokeAsync(value));
InvokeAsync(async () => await OnStateChanged.InvokeAsync(Value));
}
}
[Parameter]
public EventCallback<bool> ValueChanged { get; set; }
[Parameter]
public EventCallback<bool> OnStateChanged { get; set; }
[Parameter]
public bool Disabled { get; set; } = false;
private async Task ToggleClick(MouseEventArgs obj)
{
Value = !Value;
} }
} }

View File

@ -6,7 +6,6 @@
@inherits FluxorComponent @inherits FluxorComponent
@inject IMyEventAggregator EventAggregator
@inject IState<ThrowPanelState> ThrowPanelState @inject IState<ThrowPanelState> ThrowPanelState
@inject IDispatcher Dispatcher @inject IDispatcher Dispatcher
@ -33,8 +32,7 @@
</MudItem> </MudItem>
<MudItem xs="4"> <MudItem xs="4">
<MudPaper Class="d-flex align-center justify-center mud-width-full py-0"> <MudPaper Class="d-flex align-center justify-center mud-width-full py-0">
<BellButton <BellButton />
OnStateChanged="OnBellStateChanged" />
</MudPaper> </MudPaper>
</MudItem> </MudItem>
@ -138,11 +136,6 @@
@code { @code {
// [Parameter]
// public ThrowPanelState? ThrowPanelState { get; set; }
[Parameter]
public EventCallback<ThrowPanelState> OnStateChanged { get; set; }
[Parameter] [Parameter]
public bool ShowNumbers public bool ShowNumbers
@ -161,19 +154,10 @@
private void ToggleClick(MouseEventArgs obj) private void ToggleClick(MouseEventArgs obj)
{ {
Dispatcher.Dispatch(new ToggleAllPinsAction()); Dispatcher.Dispatch(new ToggleAllPinsAction());
// await EventAggregator.PublishAsync(new PinToggleMessage());
} }
private async Task OneClick(int number) private async Task OneClick(int number)
{ {
Dispatcher.Dispatch(new UpdatePinStateByNumber(number)); Dispatcher.Dispatch(new UpdatePinStateByNumberAction(number));
// await EventAggregator.PublishAsync(new NumberPanelMessage(number));
} }
private async Task OnBellStateChanged(bool obj)
{
Dispatcher.Dispatch(new ToggleBellAction());
// await OnStateChanged.InvokeAsync(ThrowPanelState);
}
} }

View File

@ -6,7 +6,6 @@
<MudItem xs="12" md="6"> <MudItem xs="12" md="6">
<NumberPanel ShowNumbers="ShowNumbers" <NumberPanel ShowNumbers="ShowNumbers"
CanSelectPlayer="CanSelectPlayers" CanSelectPlayer="CanSelectPlayers"
OnStateChanged="OnThrowPanelStateChanged"
/> />
</MudItem> </MudItem>
@ -21,8 +20,7 @@
// [Parameter] // [Parameter]
// public ThrowPanelState? ThrowPanelState { get; set; } // public ThrowPanelState? ThrowPanelState { get; set; }
[Parameter]
public EventCallback<ThrowPanelState> OnStateChanged { get; set; }
PinPanel _pinPanel; PinPanel _pinPanel;
NumberPanel _numberPanel; NumberPanel _numberPanel;
@ -47,9 +45,5 @@
// } // }
private async Task OnThrowPanelStateChanged(ThrowPanelState arg)
{
await OnStateChanged.InvokeAsync(arg);
}
} }

View File

@ -11,9 +11,7 @@
{ {
<MudGrid> <MudGrid>
<NumberPinPanel @ref="_numberPinPanel" <NumberPinPanel ShowNumbers="true"
ShowNumbers="true"
OnStateChanged="OnNumberPinStateChanged"
CanSelectPlayers="true" CanSelectPlayers="true"
/> />
@ -49,7 +47,6 @@
@code { @code {
private NumberPinPanel _numberPinPanel;
[Parameter] [Parameter]
public EventCallback<ThrowEventArgs> OnClick { get; set; } public EventCallback<ThrowEventArgs> OnClick { get; set; }
@ -106,11 +103,5 @@
} }
// public void UpdatePanelState(ThrowPanelState state)
// {
// _numberPinPanel.UpdatePanelState(state);
// }
} }

View File

@ -40,7 +40,7 @@ namespace KoogleApp.Hub
_hubConnection.On<ThrowPanelState>("ReceiveThrowPanelState", state => _hubConnection.On<ThrowPanelState>("ReceiveThrowPanelState", state =>
{ {
dispatcher.Dispatch(new ReceiveStateFromServer(state)); dispatcher.Dispatch(new ReceiveStateFromServerAction(state));
}); });
// _hubConnection.On<string>("ReceiveTextUpdate", (newText) => // _hubConnection.On<string>("ReceiveTextUpdate", (newText) =>

View File

@ -12,9 +12,9 @@ namespace KoogleApp.Store.Game.ThrowPanel
public record ToggleBellAction(); public record ToggleBellAction();
public record UpdatePinStateByNumber(int Number); public record UpdatePinStateByNumberAction(int Number);
public record ReceiveStateFromServer(ThrowPanelState State); public record ReceiveStateFromServerAction(ThrowPanelState State);
public record LoadStateFromSessionAction(); public record LoadStateFromSessionAction();

View File

@ -37,6 +37,31 @@ namespace KoogleApp.Store.Game.ThrowPanel
dispatcher.Dispatch(new BroadcastThrowPanelStateAction(_state.Value)); dispatcher.Dispatch(new BroadcastThrowPanelStateAction(_state.Value));
} }
[EffectMethod]
public async Task HandleToggleAllPinsAction(ToggleAllPinsAction stopAction, IDispatcher dispatcher)
{
dispatcher.Dispatch(new BroadcastThrowPanelStateAction(_state.Value));
}
[EffectMethod]
public async Task HandleTogglePinValueAction(TogglePinValueAction stopAction, IDispatcher dispatcher)
{
dispatcher.Dispatch(new BroadcastThrowPanelStateAction(_state.Value));
}
[EffectMethod]
public async Task HandleUpdatePinStateByNumberAction(UpdatePinStateByNumberAction stopAction, IDispatcher dispatcher)
{
dispatcher.Dispatch(new BroadcastThrowPanelStateAction(_state.Value));
}
[EffectMethod]
public async Task HandleToggleBellAction(ToggleBellAction stopAction, IDispatcher dispatcher)
{
dispatcher.Dispatch(new BroadcastThrowPanelStateAction(_state.Value));
}
[EffectMethod] [EffectMethod]
public async Task HandleConnectToHubAction(ConnectToHubAction action, IDispatcher dispatcher) public async Task HandleConnectToHubAction(ConnectToHubAction action, IDispatcher dispatcher)
{ {

View File

@ -7,13 +7,13 @@ namespace KoogleApp.Store.Game.ThrowPanel
public static class ThrowPanelStateReducer public static class ThrowPanelStateReducer
{ {
[ReducerMethod] [ReducerMethod]
public static ThrowPanelState ReceiveStateFromServer(ThrowPanelState state, ReceiveStateFromServer action) public static ThrowPanelState OnReceiveStateFromServer(ThrowPanelState state, ReceiveStateFromServerAction action)
{ {
return action.State; return action.State;
} }
[ReducerMethod] [ReducerMethod]
public static ThrowPanelState OnToggleDevice(ThrowPanelState state, TogglePinValueAction action) public static ThrowPanelState OnTogglePinValue(ThrowPanelState state, TogglePinValueAction action)
{ {
switch (action.PinNumber) switch (action.PinNumber)
{ {
@ -41,7 +41,7 @@ namespace KoogleApp.Store.Game.ThrowPanel
} }
[ReducerMethod] [ReducerMethod]
public static ThrowPanelState OnStart(ThrowPanelState state, StartStopAction stopAction) public static ThrowPanelState OnStartStop(ThrowPanelState state, StartStopAction stopAction)
{ {
return state with { IsStated = !state.IsStated }; return state with { IsStated = !state.IsStated };
} }
@ -70,7 +70,7 @@ namespace KoogleApp.Store.Game.ThrowPanel
} }
[ReducerMethod] [ReducerMethod]
public static ThrowPanelState OnUpdatePinStateByNumber(ThrowPanelState state, UpdatePinStateByNumber action) public static ThrowPanelState OnUpdatePinStateByNumber(ThrowPanelState state, UpdatePinStateByNumberAction action)
{ {
var chgCnt = 0; var chgCnt = 0;
@ -112,13 +112,13 @@ namespace KoogleApp.Store.Game.ThrowPanel
} }
[ReducerMethod] [ReducerMethod]
public static ThrowPanelState OnUpdatePinStateByNumber(ThrowPanelState state, ToggleBellAction action) public static ThrowPanelState OnToggleBell(ThrowPanelState state, ToggleBellAction action)
{ {
return state with { BellValue = !state.BellValue }; return state with { BellValue = !state.BellValue };
} }
[ReducerMethod] [ReducerMethod]
public static ThrowPanelState OnLoadState(ThrowPanelState state, StateLoadedAction action) public static ThrowPanelState OnStateLoaded(ThrowPanelState state, StateLoadedAction action)
{ {
return action.State; return action.State;
} }

View File

@ -1,15 +1,15 @@
{ {
"IsStated": false, "IsStated": true,
"BellValue": false, "BellValue": true,
"Pin1Value": false, "Pin1Value": true,
"Pin2Value": false, "Pin2Value": true,
"Pin3Value": false, "Pin3Value": true,
"Pin4Value": false, "Pin4Value": true,
"Pin5Value": false, "Pin5Value": true,
"Pin6Value": false, "Pin6Value": true,
"Pin7Value": false, "Pin7Value": false,
"Pin8Value": false, "Pin8Value": true,
"Pin9Value": false, "Pin9Value": true,
"Pin1Disabled": false, "Pin1Disabled": false,
"Pin2Disabled": false, "Pin2Disabled": false,
"Pin3Disabled": false, "Pin3Disabled": false,