mirror of
https://github.com/maker-community/ElectronBot.DotNet.git
synced 2026-10-28 20:57:53 +08:00
添加选择器到电子的实现
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<!-- Copyright (c) Microsoft Corporation and Contributors. -->
|
||||
<!-- Licensed under the MIT License. -->
|
||||
|
||||
<UserControl
|
||||
x:Class="ClockViews.RandomContentView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:i="using:Microsoft.Xaml.Interactivity"
|
||||
xmlns:ic="using:Microsoft.Xaml.Interactions.Core"
|
||||
xmlns:local="using:ClockViews"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d">
|
||||
<i:Interaction.Behaviors>
|
||||
<ic:EventTriggerBehavior EventName="Loaded">
|
||||
<ic:InvokeCommandAction Command="{x:Bind ViewModel.LoadedCommand}" CommandParameter="{x:Bind RandomContentSB}" />
|
||||
</ic:EventTriggerBehavior>
|
||||
</i:Interaction.Behaviors>
|
||||
<UserControl.Resources>
|
||||
<Storyboard x:Name="RandomContentSB">
|
||||
<DoubleAnimation
|
||||
Storyboard.TargetName="RandomContentTranslation"
|
||||
Storyboard.TargetProperty="Y"
|
||||
From="0"
|
||||
To="200">
|
||||
<DoubleAnimation.EasingFunction>
|
||||
<BackEase />
|
||||
</DoubleAnimation.EasingFunction>
|
||||
</DoubleAnimation>
|
||||
</Storyboard>
|
||||
</UserControl.Resources>
|
||||
<Viewbox>
|
||||
<Grid
|
||||
x:Name="Root"
|
||||
Width="200"
|
||||
Height="200">
|
||||
<TextBlock
|
||||
x:Name="RandomContentTb"
|
||||
Margin="0,0,0,0"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Top"
|
||||
FontFamily="/Assets/Font/SmileySans-Oblique.ttf#µÃÒâºÚ"
|
||||
FontSize="32"
|
||||
Text="{x:Bind ViewModel.RandomContentText, Mode=OneWay}">
|
||||
<TextBlock.RenderTransform>
|
||||
<TranslateTransform x:Name="RandomContentTranslation" />
|
||||
</TextBlock.RenderTransform>
|
||||
</TextBlock>
|
||||
<TextBlock
|
||||
x:Name="RandomContentResultTb"
|
||||
Margin="0,0,0,0"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
FontFamily="/Assets/Font/SmileySans-Oblique.ttf#µÃÒâºÚ"
|
||||
FontSize="32"
|
||||
Text="{x:Bind ViewModel.RandomContentResultText, Mode=OneWay}" />
|
||||
</Grid>
|
||||
</Viewbox>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,36 @@
|
||||
// Copyright (c) Microsoft Corporation and Contributors.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using ElectronBot.BraincasePreview;
|
||||
using ElectronBot.BraincasePreview.ViewModels;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Controls.Primitives;
|
||||
using Microsoft.UI.Xaml.Data;
|
||||
using Microsoft.UI.Xaml.Input;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using Microsoft.UI.Xaml.Navigation;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
|
||||
// To learn more about WinUI, the WinUI project structure,
|
||||
// and more about our project templates, see: http://aka.ms/winui-project-info.
|
||||
|
||||
namespace ClockViews;
|
||||
public sealed partial class RandomContentView : UserControl
|
||||
{
|
||||
public GestureClassificationViewModel ViewModel
|
||||
{
|
||||
get;
|
||||
}
|
||||
public RandomContentView(GestureClassificationViewModel viewModel)
|
||||
{
|
||||
ViewModel = viewModel;
|
||||
this.InitializeComponent();
|
||||
}
|
||||
}
|
||||
@@ -43,6 +43,7 @@
|
||||
<None Remove="Assets\pig.ico" />
|
||||
<None Remove="ClockViews\GooeyFooter.xaml" />
|
||||
<None Remove="ClockViews\GradientsWithBlend.xaml" />
|
||||
<None Remove="ClockViews\RandomContentView.xaml" />
|
||||
<None Remove="Controls\ActionTimeline.xaml" />
|
||||
<None Remove="Controls\AddEmojisContentDialog.xaml" />
|
||||
<None Remove="Controls\AppQuitPage.xaml" />
|
||||
@@ -186,6 +187,9 @@
|
||||
<None Update="Assets\xbox-one-controller.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<Page Update="ClockViews\RandomContentView.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Update="Controls\RandomContentPage.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using ClockViews;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Controls;
|
||||
@@ -33,14 +34,30 @@ public partial class GestureClassificationViewModel : ObservableRecipient, INavi
|
||||
|
||||
DispatcherTimer dispatcherTimer = new DispatcherTimer();
|
||||
|
||||
private readonly DispatcherTimer _dispatcherTimer;
|
||||
|
||||
private readonly string modelPath = Package.Current.InstalledLocation.Path + $"\\Assets\\MLModel1.zip";
|
||||
private readonly ILocalSettingsService _localSettingsService;
|
||||
public GestureClassificationViewModel(ILocalSettingsService localSettingsService)
|
||||
public GestureClassificationViewModel(DispatcherTimer dispatcherTimer1,
|
||||
ILocalSettingsService localSettingsService)
|
||||
{
|
||||
calculator = new HandsCpuSolution();
|
||||
dispatcherTimer.Interval = TimeSpan.FromMilliseconds(400);
|
||||
dispatcherTimer.Tick += DispatcherTimer_Tick;
|
||||
_localSettingsService = localSettingsService;
|
||||
_dispatcherTimer = dispatcherTimer1;
|
||||
_dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 40);
|
||||
|
||||
_dispatcherTimer.Tick += DispatcherTimer_ClockTick;
|
||||
Element = new RandomContentView(this);
|
||||
}
|
||||
|
||||
private async void DispatcherTimer_ClockTick(object? sender, object e)
|
||||
{
|
||||
if (ElectronBotHelper.Instance.EbConnected)
|
||||
{
|
||||
await EbHelper.ShowClockCanvasToDeviceAsync(Element);
|
||||
}
|
||||
}
|
||||
|
||||
private Storyboard storyboard = new();
|
||||
@@ -58,12 +75,16 @@ public partial class GestureClassificationViewModel : ObservableRecipient, INavi
|
||||
}
|
||||
private void DispatcherTimer_Tick(object sender, object e)
|
||||
{
|
||||
var index = new Random().Next(0, RandomContentList.Count);
|
||||
var text = RandomContentList[index].Content;
|
||||
RandomContentText = $"{text}";
|
||||
storyboard.Children[0].SetValue(DoubleAnimation.FromProperty, 0);
|
||||
storyboard.Children[0].SetValue(DoubleAnimation.ToProperty, 180);
|
||||
storyboard.Begin();
|
||||
if (RandomContentList.Count > 0)
|
||||
{
|
||||
var index = new Random().Next(0, RandomContentList.Count);
|
||||
|
||||
var text = RandomContentList[index].Content;
|
||||
RandomContentText = $"{text}";
|
||||
storyboard.Children[0].SetValue(DoubleAnimation.FromProperty, 0);
|
||||
storyboard.Children[0].SetValue(DoubleAnimation.ToProperty, 180);
|
||||
storyboard.Begin();
|
||||
}
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
@@ -72,6 +93,12 @@ public partial class GestureClassificationViewModel : ObservableRecipient, INavi
|
||||
[ObservableProperty]
|
||||
private string randomContentResultText;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 随机内容
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
UIElement element;
|
||||
[RelayCommand]
|
||||
private async Task TestGestureClassficationAsync()
|
||||
{
|
||||
@@ -161,7 +188,7 @@ public partial class GestureClassificationViewModel : ObservableRecipient, INavi
|
||||
public async void OnNavigatedTo(object parameter)
|
||||
{
|
||||
await InitAsync();
|
||||
//dispatcherTimer.Start();
|
||||
_dispatcherTimer.Start();
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
@@ -228,28 +255,31 @@ public partial class GestureClassificationViewModel : ObservableRecipient, INavi
|
||||
{
|
||||
ResultLabel = e;
|
||||
|
||||
if (e == "back" && _isBeginning == false)
|
||||
if(RandomContentList.Count > 0)
|
||||
{
|
||||
//todo:启动动画 并播放
|
||||
_isBeginning = true;
|
||||
RandomContentResultText = "";
|
||||
dispatcherTimer.Start();
|
||||
Debug.WriteLine("启动动画");
|
||||
}
|
||||
else if (e == "back" && _isBeginning == true)
|
||||
{
|
||||
//当前处于启动状态
|
||||
//不做处理
|
||||
}
|
||||
else if (e == "land" && _isBeginning == true)
|
||||
{
|
||||
var index = new Random().Next(0, RandomContentList.Count);
|
||||
var text = RandomContentList[index].Content;
|
||||
RandomContentResultText = $"{text}";
|
||||
_isBeginning = false;
|
||||
Debug.WriteLine("停止动画");
|
||||
RandomContentText = "";
|
||||
dispatcherTimer.Stop();
|
||||
if (e == "back" && _isBeginning == false)
|
||||
{
|
||||
//todo:启动动画 并播放
|
||||
_isBeginning = true;
|
||||
RandomContentResultText = "";
|
||||
dispatcherTimer.Start();
|
||||
Debug.WriteLine("启动动画");
|
||||
}
|
||||
else if (e == "back" && _isBeginning == true)
|
||||
{
|
||||
//当前处于启动状态
|
||||
//不做处理
|
||||
}
|
||||
else if (e == "land" && _isBeginning == true)
|
||||
{
|
||||
var index = new Random().Next(0, RandomContentList.Count);
|
||||
var text = RandomContentList[index].Content;
|
||||
RandomContentResultText = $"{text}";
|
||||
_isBeginning = false;
|
||||
Debug.WriteLine("停止动画");
|
||||
RandomContentText = "";
|
||||
dispatcherTimer.Stop();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -265,7 +295,6 @@ public partial class GestureClassificationViewModel : ObservableRecipient, INavi
|
||||
e.SoftwareBitmap = SoftwareBitmap.Convert(
|
||||
e.SoftwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied);
|
||||
}
|
||||
|
||||
var service = App.GetService<GestureClassificationService>();
|
||||
|
||||
_ = await service.HandPredictResultUnUseQueueAsync(calculator, modelPath, e.SoftwareBitmap);
|
||||
@@ -275,6 +304,7 @@ public partial class GestureClassificationViewModel : ObservableRecipient, INavi
|
||||
{
|
||||
await CleanUpAsync();
|
||||
dispatcherTimer.Stop();
|
||||
_dispatcherTimer.Stop();
|
||||
}
|
||||
|
||||
private async Task CleanUpAsync()
|
||||
|
||||
@@ -6,30 +6,10 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:i="using:Microsoft.Xaml.Interactivity"
|
||||
xmlns:ic="using:Microsoft.Xaml.Interactions.Core"
|
||||
xmlns:local="using:Views"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:ui="using:CommunityToolkit.WinUI.UI"
|
||||
mc:Ignorable="d">
|
||||
<i:Interaction.Behaviors>
|
||||
<ic:EventTriggerBehavior EventName="Loaded">
|
||||
<ic:InvokeCommandAction Command="{x:Bind ViewModel.LoadedCommand}" CommandParameter="{x:Bind RandomContentSB}" />
|
||||
</ic:EventTriggerBehavior>
|
||||
</i:Interaction.Behaviors>
|
||||
<Page.Resources>
|
||||
<Storyboard x:Name="RandomContentSB">
|
||||
<DoubleAnimation
|
||||
Storyboard.TargetName="RandomContentTranslation"
|
||||
Storyboard.TargetProperty="Y"
|
||||
From="0"
|
||||
To="200">
|
||||
<DoubleAnimation.EasingFunction>
|
||||
<BackEase />
|
||||
</DoubleAnimation.EasingFunction>
|
||||
</DoubleAnimation>
|
||||
</Storyboard>
|
||||
</Page.Resources>
|
||||
<Grid x:Name="ContentArea">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="auto" />
|
||||
@@ -74,31 +54,8 @@
|
||||
ui:UIElementExtensions.ClipToBounds="True"
|
||||
BorderBrush="{ThemeResource SystemAccentColor}"
|
||||
BorderThickness="4"
|
||||
CornerRadius="8">
|
||||
<Grid>
|
||||
<TextBlock
|
||||
x:Name="RandomContentTb"
|
||||
Margin="0,0,0,0"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Top"
|
||||
FontFamily="/Assets/Font/SmileySans-Oblique.ttf#得意黑"
|
||||
FontSize="32"
|
||||
Text="{x:Bind ViewModel.RandomContentText, Mode=OneWay}">
|
||||
<TextBlock.RenderTransform>
|
||||
<TranslateTransform x:Name="RandomContentTranslation" />
|
||||
</TextBlock.RenderTransform>
|
||||
</TextBlock>
|
||||
<TextBlock
|
||||
x:Name="RandomContentResultTb"
|
||||
Margin="0,0,0,0"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
FontFamily="/Assets/Font/SmileySans-Oblique.ttf#得意黑"
|
||||
FontSize="32"
|
||||
Text="{x:Bind ViewModel.RandomContentResultText, Mode=OneWay}" />
|
||||
</Grid>
|
||||
|
||||
</Border>
|
||||
Child="{x:Bind ViewModel.Element, Mode=OneWay}"
|
||||
CornerRadius="8" />
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock
|
||||
|
||||
Reference in New Issue
Block a user