Add animated classroom grouping with saved editable plans
CI / build-and-test (push) Canceled after 0s
CI / build-and-test (push) Canceled after 0s
This commit is contained in:
1 parent
d4b1419f9a
commit
f0462bd2a1
27 files changed
+775
-46
No files matched your search
@@ -1,26 +1,60 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Labs.Lottie;
|
||||
using LehrerApp.Desktop.ViewModels.Groups;
|
||||
|
||||
namespace LehrerApp.Desktop.Views.Groups;
|
||||
|
||||
public partial class RandomStudentPickerWindow : Window
|
||||
{
|
||||
private bool _isAnimating;
|
||||
private bool _isSpinning;
|
||||
private DateTime _spinStartedAt;
|
||||
|
||||
public RandomStudentPickerWindow() => InitializeComponent();
|
||||
|
||||
private async void OnDraw(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_isAnimating || DataContext is not RandomStudentPickerViewModel vm ||
|
||||
if (DataContext is not RandomStudentPickerViewModel vm ||
|
||||
!vm.DrawCommand.CanExecute(null)) return;
|
||||
|
||||
_isAnimating = true;
|
||||
var card = this.FindControl<Border>("RevealCard");
|
||||
if (card is not null) card.Opacity = 0.15;
|
||||
await Task.Delay(150);
|
||||
var wheel = this.FindControl<Lottie>("WheelAnimation");
|
||||
var button = this.FindControl<Button>("DrawButton");
|
||||
if (card is null || wheel is null || button is null) return;
|
||||
|
||||
if (!_isSpinning)
|
||||
{
|
||||
_isSpinning = true;
|
||||
_spinStartedAt = DateTime.UtcNow;
|
||||
card.IsVisible = false;
|
||||
wheel.IsVisible = true;
|
||||
this.FindControl<Expander>("OptionsExpander")!.IsEnabled = false;
|
||||
this.FindControl<Button>("ResetButton")!.IsEnabled = false;
|
||||
button.Content = "Dreht …";
|
||||
// Erst nach dem Layoutwechsel starten, damit das erste Bild sichtbar ist.
|
||||
await Task.Yield();
|
||||
if (!_isSpinning) return;
|
||||
wheel.Start();
|
||||
button.Content = "Ergebnis anzeigen";
|
||||
return;
|
||||
}
|
||||
|
||||
// Ein Doppelklick soll die Ziehung nicht unbemerkt sofort auflösen.
|
||||
if (DateTime.UtcNow - _spinStartedAt < TimeSpan.FromSeconds(1.2)) return;
|
||||
wheel.Stop();
|
||||
wheel.IsVisible = false;
|
||||
vm.DrawCommand.Execute(null);
|
||||
if (card is not null) card.Opacity = 1;
|
||||
_isAnimating = false;
|
||||
card.IsVisible = true;
|
||||
this.FindControl<Expander>("OptionsExpander")!.IsEnabled = true;
|
||||
this.FindControl<Button>("ResetButton")!.IsEnabled = true;
|
||||
button.Content = "🎲 Ziehen";
|
||||
_isSpinning = false;
|
||||
}
|
||||
|
||||
protected override void OnClosed(EventArgs e)
|
||||
{
|
||||
_isSpinning = false;
|
||||
this.FindControl<Lottie>("WheelAnimation")?.Stop();
|
||||
base.OnClosed(e);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user