更新最新

This commit is contained in:
GukSang.Jin
2026-06-02 18:53:31 +08:00
parent 212dca6abe
commit 34f03d0ed0
4 changed files with 190 additions and 20 deletions

View File

@@ -1,23 +1,111 @@
using Avalonia.Controls;
using Avalonia.Input;
using Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModels;
using SukiUI.Controls;
using System;
using Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModels;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.Views
{
public partial class MainWindow : SukiWindow
{
private readonly HashSet<string> activeMotionTags = [];
public MainWindow()
{
InitializeComponent();
Closed += OnClosed;
Deactivated += OnDeactivated;
}
private void OnClosed(object? sender, EventArgs e)
private async void MotionButton_PointerPressed(object? sender, PointerPressedEventArgs e)
{
if (sender is not Button button || button.Tag is not string tag || DataContext is not MainWindowViewModel viewModel)
{
return;
}
if (!activeMotionTags.Add(tag))
{
return;
}
e.Pointer.Capture(button);
e.Handled = true;
await StartMotionAsync(viewModel, tag);
}
private async void MotionButton_PointerReleased(object? sender, PointerReleasedEventArgs e)
{
if (sender is not Button button || button.Tag is not string tag || DataContext is not MainWindowViewModel viewModel)
{
return;
}
e.Pointer.Capture(null);
e.Handled = true;
await StopMotionAsync(viewModel, tag);
}
private async void MotionButton_PointerCaptureLost(object? sender, PointerCaptureLostEventArgs e)
{
if (sender is not Button button || button.Tag is not string tag || DataContext is not MainWindowViewModel viewModel)
{
return;
}
await StopMotionAsync(viewModel, tag);
}
private async void OnDeactivated(object? sender, EventArgs e)
{
await StopAllMotionAsync();
}
private async void OnClosed(object? sender, EventArgs e)
{
await StopAllMotionAsync();
if (DataContext is MainWindowViewModel viewModel)
{
viewModel.Dispose();
}
}
private static Task StartMotionAsync(MainWindowViewModel viewModel, string tag) =>
tag switch
{
"Lift" => viewModel.StartLiftMotionAsync(),
"Lower" => viewModel.StartLowerMotionAsync(),
"MoveLeft" => viewModel.StartMoveLeftMotionAsync(),
"MoveRight" => viewModel.StartMoveRightMotionAsync(),
_ => Task.CompletedTask
};
private async Task StopMotionAsync(MainWindowViewModel viewModel, string tag)
{
if (!activeMotionTags.Remove(tag))
{
return;
}
await (tag switch
{
"Lift" => viewModel.StopLiftMotionAsync(),
"Lower" => viewModel.StopLowerMotionAsync(),
"MoveLeft" => viewModel.StopMoveLeftMotionAsync(),
"MoveRight" => viewModel.StopMoveRightMotionAsync(),
_ => Task.CompletedTask
});
}
private async Task StopAllMotionAsync()
{
activeMotionTags.Clear();
if (DataContext is MainWindowViewModel viewModel)
{
await viewModel.StopAllMotionAsync();
}
}
}
}