add WelcomeDialog

This commit is contained in:
辉鸭蛋
2025-03-09 18:55:25 +08:00
parent 4fc2417f26
commit 366e5d140a
6 changed files with 181 additions and 4 deletions

View File

@@ -43,6 +43,10 @@
<PackageReference Include="AvalonEdit" Version="6.3.0.90" />
<PackageReference Include="BehaviourTree" Version="1.0.73" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="DeviceId" Version="6.8.0" />
<PackageReference Include="DeviceId.Windows" Version="6.8.0" />
<PackageReference Include="DeviceId.Windows.Wmi" Version="6.8.0" />
<PackageReference Include="Emoji.Wpf" Version="0.3.4" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
@@ -153,4 +157,19 @@
<Folder Include="User\AutoPathing\" />
</ItemGroup>
<ItemGroup>
<Page Update="View\Windows\WelcomeDialog.xaml">
<Generator>MSBuild:Compile</Generator>
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Update="View\Windows\WelcomeDialog.xaml.cs">
<SubType>Code</SubType>
<DependentUpon>WelcomeDialog.xaml</DependentUpon>
</Compile>
</ItemGroup>
</Project>

View File

@@ -1,5 +1,6 @@
using CommunityToolkit.Mvvm.ComponentModel;
using System;
using System.Collections.Generic;
using Wpf.Ui.Controls;
namespace BetterGenshinImpact.Core.Config;
@@ -45,4 +46,10 @@ public partial class CommonConfig : ObservableObject
/// </summary>
[ObservableProperty]
private string _runForVersion = string.Empty;
/// <summary>
/// 一个设备只运行一次的已运行设备ID列表
/// </summary>
[ObservableProperty]
private List<string> _onceHadRunDeviceIdList = new();
}

View File

@@ -25,7 +25,7 @@ public class AssertUtils
var gameScreenSize = SystemControl.GetGameScreenRect(TaskContext.Instance().GameHandle);
if (gameScreenSize.Width * 9 != gameScreenSize.Height * 16)
{
TaskControl.Logger.LogError("游戏窗口分辨率不是 16:9 !当前分辨率为 {Width}x{Height} , 非 16:9 分辨率的游戏无法正常使用{}功能 !", gameScreenSize.Width, gameScreenSize.Height, msg);
TaskControl.Logger.LogError("游戏窗口分辨率不是 16:9 !当前分辨率为 {Width}x{Height} , 非 16:9 分辨率的游戏无法正常使用{Msg}功能 !", gameScreenSize.Width, gameScreenSize.Height, msg);
throw new Exception("游戏窗口分辨率不是 16:9");
}
}

View File

@@ -0,0 +1,74 @@
<ui:FluentWindow x:Class="BetterGenshinImpact.View.Windows.WelcomeDialog"
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
Width="500"
Height="210"
MinWidth="400"
MinHeight="230"
ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}"
ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}"
ExtendsContentIntoTitleBar="True"
FontFamily="{DynamicResource TextThemeFontFamily}"
ResizeMode="CanMinimize"
WindowBackdropType="Mica"
WindowStartupLocation="CenterScreen"
WindowStyle="SingleBorderWindow"
xmlns:emoji="clr-namespace:Emoji.Wpf;assembly=Emoji.Wpf"
mc:Ignorable="d">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="1" Margin="12">
<emoji:TextBlock Text="🔹 本软件开源且免费喜欢的可以点🌟Star -> " Margin="5" FontSize="16">
<Hyperlink NavigateUri="https://github.com/babalae/better-genshin-impact"
RequestNavigate="HyperlinkRequestNavigate" Foreground="#1E9BFA">
Github
</Hyperlink>
</emoji:TextBlock>
<emoji:TextBlock Text="🔹 首次使用请先查看" Margin="5" FontSize="16">
<Hyperlink NavigateUri="https://bettergi.com/quickstart.html"
RequestNavigate="HyperlinkRequestNavigate" Foreground="#1E9BFA">
《快速上手教程》
</Hyperlink>
</emoji:TextBlock>
<emoji:TextBlock
Margin="5"
FontSize="16"
TextWrapping="Wrap">
<Run Text="❗本软件从未授权任何第三方平台进行" /><Run Text="售卖" Foreground="Red" />
<Run Text="。如果你是付费获取的本软件(闲鱼、淘宝等),凭此界面向商家" /><Run Text="退款" Foreground="Red" /><Run Text="" />
</emoji:TextBlock>
<!--<StackPanel Margin="5"
Orientation="Horizontal">
<ui:TextBlock Text="本软件" VerticalAlignment="Bottom"/>
<emoji:TextBlock Text="🔄开源" FontSize="20" />
<ui:TextBlock Text="且" VerticalAlignment="Bottom"/>
<emoji:TextBlock Text="🆓免费" FontSize="20"/>
</StackPanel>-->
<StackPanel Margin="5"
HorizontalAlignment="Right"
Orientation="Horizontal">
<ui:Button Name="BtnOk"
Margin="5"
Appearance="Primary"
Click="BtnOkClick"
Content="确定"
IsDefault="True" />
</StackPanel>
</StackPanel>
<ui:TitleBar Title="BetterGI" Grid.Row="0">
<ui:TitleBar.Icon>
<ui:ImageIcon Source="pack://application:,,,/Assets/Images/logo.png" />
</ui:TitleBar.Icon>
</ui:TitleBar>
</Grid>
</ui:FluentWindow>

View File

@@ -0,0 +1,40 @@
using System;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Windows.System;
namespace BetterGenshinImpact.View.Windows;
public partial class WelcomeDialog
{
public WelcomeDialog()
{
InitializeComponent();
this.Loaded += WelcomeDialogLoaded;
}
private void WelcomeDialogLoaded(object sender, RoutedEventArgs e)
{
}
public static void Prompt(string question, string title, string defaultValue = "")
{
var inst = new WelcomeDialog();
inst.ShowDialog();
}
private void BtnOkClick(object sender, RoutedEventArgs e)
{
DialogResult = true;
Close();
}
private void HyperlinkRequestNavigate(object sender, RequestNavigateEventArgs e)
{
string uri = e.Uri.AbsoluteUri;
Launcher.LaunchUriAsync(new Uri(uri)).Wait();
}
}

View File

@@ -21,7 +21,9 @@ using System.Net.Http.Json;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using BetterGenshinImpact.View.Windows;
using BetterGenshinImpact.ViewModel.Pages;
using DeviceId;
using Wpf.Ui;
using Wpf.Ui.Controls;
@@ -113,7 +115,7 @@ public partial class MainWindowViewModel : ObservableObject, IViewModel
// 自动处理目录配置
await Patch1();
// 首次运行
if (Config.CommonConfig.IsFirstRun)
@@ -122,14 +124,16 @@ public partial class MainWindowViewModel : ObservableObject, IViewModel
// InitKeyBinding();
Config.AutoFightConfig.TeamNames = ""; // 此配置以后无用
Config.CommonConfig.IsFirstRun = false;
}
// 版本是否运行过
if (Config.CommonConfig.RunForVersion != Global.Version)
{
ModifyFolderSecurity();
Config.CommonConfig.RunForVersion = Global.Version;
}
OnceRun();
// 检查更新
await App.GetService<IUpdateService>()!.CheckUpdateAsync(new UpdateOption());
@@ -142,7 +146,7 @@ public partial class MainWindowViewModel : ObservableObject, IViewModel
// 更新仓库
ScriptRepoUpdater.Instance.AutoUpdate();
// 清理临时目录
TempManager.CleanUp();
}
@@ -243,4 +247,37 @@ public partial class MainWindowViewModel : ObservableObject, IViewModel
MessageBox.Warning("PaddleOcr预热失败解决方案https://bettergi.com/faq.html" + e.Source + "\r\n--" + Environment.NewLine + e.StackTrace + "\r\n---" + Environment.NewLine + e.Message);
}
}
private void OnceRun()
{
string deviceId = "default";
try
{
deviceId = new DeviceIdBuilder()
.OnWindows(windows => windows
.AddMacAddressFromWmi(excludeWireless: true, excludeNonPhysical: true)
.AddProcessorId()
.AddMotherboardSerialNumber()
)
.ToString();
}
catch (Exception e)
{
_logger.LogDebug("获取设备ID异常" + e.Source + "\r\n--" + Environment.NewLine + e.StackTrace + "\r\n---" + Environment.NewLine + e.Message);
}
// 每个设备只运行一次
if (!Config.CommonConfig.OnceHadRunDeviceIdList.Contains(deviceId))
{
WelcomeDialog prompt = new WelcomeDialog
{
Owner = Application.Current.MainWindow
};
prompt.ShowDialog();
prompt.Focus();
Config.CommonConfig.OnceHadRunDeviceIdList.Add(deviceId);
_configService.Save();
}
}
}