initial script control but debug only

This commit is contained in:
ema 2023-12-17 17:18:45 +08:00
parent ddfca0340e
commit efd6d1ea41
7 changed files with 185 additions and 0 deletions

View File

@ -73,6 +73,8 @@ public partial class App : Application
// Views and ViewModels
services.AddSingleton<HomePage>();
services.AddSingleton<HomePageViewModel>();
services.AddSingleton<ScriptControlPage>();
services.AddSingleton<ScriptControlViewModel>();
services.AddSingleton<TriggerSettingsPage>();
services.AddSingleton<TriggerSettingsPageViewModel>();
services.AddSingleton<MacroSettingsPage>();

View File

@ -50,6 +50,11 @@
<PackageReference Include="YoloV8" Version="2.0.1" />
</ItemGroup>
<ItemGroup Condition=" '$(Configuration)' == 'Debug'">
<PackageReference Include="Microsoft.ClearScript.V8" Version="7.4.4" />
<PackageReference Include="Microsoft.ClearScript.V8.Native.win-x64" Version="7.4.4" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Fischless.GameCapture\Fischless.GameCapture.csproj" />
<ProjectReference Include="..\Fischless.HotkeyCapture\Fischless.HotkeyCapture.csproj" />

View File

@ -0,0 +1,49 @@
using System;
using System.Globalization;
using System.Reflection;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;
namespace BetterGenshinImpact.Markup;
[MarkupExtensionReturnType(typeof(object))]
public class ConverterExtension : MarkupExtension
{
public object? Value { get; set; } = null;
public IValueConverter Converter { get; set; } = null!;
public object? Parameter { get; set; } = null;
public CultureInfo Culture { get; set; } = null!;
public ConverterExtension()
{
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
if (Converter == null)
{
return Value!;
}
else
{
Type targetType = typeof(object);
if (serviceProvider.GetService(typeof(IProvideValueTarget)) is IProvideValueTarget provideValueTarget)
{
var targetProperty = provideValueTarget.TargetProperty;
if (targetProperty is DependencyProperty dp)
{
targetType = dp.PropertyType;
}
else if (targetProperty is PropertyInfo prop)
{
targetType = prop.PropertyType;
}
}
return Converter.Convert(Value, targetType, Parameter, Culture);
}
}
}

View File

@ -3,6 +3,8 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:helpers="clr-namespace:BetterGenshinImpact.Helpers"
xmlns:markup="clr-namespace:BetterGenshinImpact.Markup"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:pages="clr-namespace:BetterGenshinImpact.View.Pages"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
@ -10,11 +12,15 @@
Title="更好的原神"
Width="900"
Height="600"
d:Background="#D2D2D2"
d:DataContext="{d:DesignInstance Type=viewModel:MainWindowViewModel}"
ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}"
ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}"
ExtendsContentIntoTitleBar="True"
mc:Ignorable="d">
<Window.Resources>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
</Window.Resources>
<b:Interaction.Triggers>
<b:EventTrigger EventName="Loaded">
<b:InvokeCommandAction Command="{Binding LoadedCommand}" CommandParameter="{Binding}" />
@ -64,6 +70,15 @@
<ui:SymbolIcon Symbol="XboxController24" />
</ui:NavigationViewItem.Icon>
</ui:NavigationViewItem>
<ui:NavigationViewItem Content="脚本控制"
NavigationCacheMode="Enabled"
TargetPageType="{x:Type pages:ScriptControlPage}"
Visibility="{markup:Converter Value={x:Static helpers:RuntimeHelper.IsDebuggerAttached},
Converter={StaticResource BooleanToVisibilityConverter}}">
<ui:NavigationViewItem.Icon>
<ui:SymbolIcon Symbol="WebAsset16" />
</ui:NavigationViewItem.Icon>
</ui:NavigationViewItem>
<ui:NavigationViewItem Content="快捷键"
NavigationCacheMode="Enabled"
TargetPageType="{x:Type pages:HotKeyPage}">

View File

@ -0,0 +1,63 @@
<Page x:Class="BetterGenshinImpact.View.Pages.ScriptControlPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:BetterGenshinImpact.View.Pages"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:pages="clr-namespace:BetterGenshinImpact.ViewModel.Pages"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
Title="HomePage"
d:DataContext="{d:DesignInstance Type=pages:ScriptControlViewModel}"
d:DesignHeight="850"
d:DesignWidth="800"
ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}"
ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
mc:Ignorable="d">
<Grid>
<StackPanel Margin="42,16,42,12">
<ui:TextBlock Margin="0,0,0,8"
FontTypography="BodyStrong"
Text="脚本控制设置" />
<ui:CardExpander Margin="0,0,0,12"
ContentPadding="0"
Icon="{ui:SymbolIcon CodeJsRectangle16}">
<ui:CardExpander.Header>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ui:TextBlock Grid.Row="0"
Grid.Column="0"
FontTypography="Body"
Text="执行脚本"
TextWrapping="Wrap" />
<ui:TextBlock Grid.Row="1"
Grid.Column="0"
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
TextWrapping="Wrap">
<ui:TextBlock.Inlines>
<Run Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}" Text="实验性功能仅支持JS、TS脚本。" />
<Hyperlink Command="{Binding GoToAutoScriptUrlCommand}" Foreground="{ui:ThemeResource TextFillColorSecondaryBrush}">
<Run Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}" Text="点击查看使用教程" />
</Hyperlink>
</ui:TextBlock.Inlines>
</ui:TextBlock>
<ui:Button Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="1"
Margin="0,0,24,0"
Command="{Binding SwitchAutoScriptCommand}"
Content="启动" />
</Grid>
</ui:CardExpander.Header>
</ui:CardExpander>
</StackPanel>
</Grid>
</Page>

View File

@ -0,0 +1,14 @@
using BetterGenshinImpact.ViewModel.Pages;
namespace BetterGenshinImpact.View.Pages;
public partial class ScriptControlPage
{
public ScriptControlViewModel ViewModel { get; }
public ScriptControlPage(ScriptControlViewModel viewModel)
{
DataContext = ViewModel = viewModel;
InitializeComponent();
}
}

View File

@ -0,0 +1,37 @@
#if DEBUG
using CommunityToolkit.Mvvm.ComponentModel;
using Microsoft.ClearScript;
using Microsoft.ClearScript.V8;
using Vanara.PInvoke;
using Wpf.Ui.Controls;
using System.Diagnostics;
namespace BetterGenshinImpact.ViewModel.Pages;
public partial class ScriptControlViewModel : ObservableObject, INavigationAware
{
public ScriptControlViewModel()
{
using IScriptEngine engine = new V8ScriptEngine();
engine.AddHostObject("lib", new HostTypeCollection("mscorlib", "System.Core"));
engine.AddHostObject("win32", new HostTypeCollection("Vanara.PInvoke.User32"));
object test = engine.Evaluate("win32.Vanara.PInvoke.User32.GetActiveWindow()");
Debug.WriteLine((int)User32.GetActiveWindow());
Debug.WriteLine((int)(HWND)test);
}
public void OnNavigatedFrom()
{
}
public void OnNavigatedTo()
{
}
}
#else
public partial class ScriptControlViewModel : CommunityToolkit.Mvvm.ComponentModel.ObservableObject { }
#endif