UI/UX: use MessageBox from Violeta

This commit is contained in:
ema 2024-08-20 23:43:38 +08:00
parent 447fd103de
commit 24d798d6b2
18 changed files with 68 additions and 90 deletions

View File

@ -239,7 +239,7 @@ public partial class App : Application
e = e.InnerException;
}
MessageBox.Show("程序异常:" + e.Source + "\r\n--" + Environment.NewLine + e.StackTrace + "\r\n---" + Environment.NewLine + e.Message);
MessageBox.Error("程序异常:" + e.Source + "\r\n--" + Environment.NewLine + e.StackTrace + "\r\n---" + Environment.NewLine + e.Message);
// log
GetLogger<App>().LogDebug(e, "UnHandle Exception");

View File

@ -60,7 +60,7 @@
<PackageReference Include="Vanara.PInvoke.User32" Version="4.0.2" />
<PackageReference Include="WPF-UI" Version="3.0.5" />
<PackageReference Include="WPF-UI.Tray" Version="3.0.5" />
<PackageReference Include="WPF-UI.Violeta" Version="3.0.5.2" />
<PackageReference Include="WPF-UI.Violeta" Version="3.0.5.3" />
<PackageReference Include="YoloV8" Version="4.1.7" />
<PackageReference Include="gong-wpf-dragdrop" Version="3.2.1" />
</ItemGroup>

View File

@ -95,7 +95,7 @@ public class ScriptParser
catch (System.Exception ex)
{
MyLogger.LogError($"解析脚本错误,行号:{i + 1},错误信息:{ex}");
MessageBox.Show($"解析脚本错误,行号:{i + 1},错误信息:{ex}", "策略解析失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Error($"解析脚本错误,行号:{i + 1},错误信息:{ex}", "策略解析失败");
return default!;
}
@ -195,4 +195,4 @@ public class ScriptParser
throw new System.Exception(msg);
}
}
}
}

View File

@ -15,7 +15,6 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Vanara.PInvoke;
namespace BetterGenshinImpact.GameTask.AutoPick;
@ -98,7 +97,7 @@ public partial class AutoPickTrigger : ITaskTrigger
catch (Exception e)
{
_logger.LogError(e, "读取拾取黑名单失败");
MessageBox.Show("读取拾取黑名单失败,请确认修改后的拾取黑名单内容格式是否正确!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Error("读取拾取黑名单失败,请确认修改后的拾取黑名单内容格式是否正确!");
}
try
@ -112,7 +111,7 @@ public partial class AutoPickTrigger : ITaskTrigger
catch (Exception e)
{
_logger.LogError(e, "读取拾取白名单失败");
MessageBox.Show("读取拾取白名单失败,请确认修改后的拾取白名单内容格式是否正确!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Error("读取拾取白名单失败,请确认修改后的拾取白名单内容格式是否正确!");
}
}

View File

@ -84,7 +84,7 @@ public partial class AutoSkipTrigger : ITaskTrigger
catch (Exception e)
{
_logger.LogError(e, "读取自动剧情默认暂停点击关键词列表失败");
MessageBox.Show("读取自动剧情默认暂停点击关键词列表失败,请确认修改后的自动剧情默认暂停点击关键词内容格式是否正确!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Error("读取自动剧情默认暂停点击关键词列表失败,请确认修改后的自动剧情默认暂停点击关键词内容格式是否正确!");
}
try
@ -98,7 +98,7 @@ public partial class AutoSkipTrigger : ITaskTrigger
catch (Exception e)
{
_logger.LogError(e, "读取自动剧情暂停点击关键词列表失败");
MessageBox.Show("读取自动剧情暂停点击关键词列表失败,请确认修改后的自动剧情暂停点击关键词内容格式是否正确!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Error("读取自动剧情暂停点击关键词列表失败,请确认修改后的自动剧情暂停点击关键词内容格式是否正确!");
}
try
@ -112,7 +112,7 @@ public partial class AutoSkipTrigger : ITaskTrigger
catch (Exception e)
{
_logger.LogError(e, "读取自动剧情优先点击选项列表失败");
MessageBox.Show("读取自动剧情优先点击选项列表失败,请确认修改后的自动剧情优先点击选项内容格式是否正确!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Error("读取自动剧情优先点击选项列表失败,请确认修改后的自动剧情优先点击选项内容格式是否正确!");
}
}

View File

@ -122,7 +122,7 @@ public partial class AutoWoodTask
{
Logger.LogError(e.Message);
Logger.LogDebug(e.StackTrace);
System.Windows.MessageBox.Show("自动伐木时异常:" + e.Source + "\r\n--" + Environment.NewLine + e.StackTrace + "\r\n---" + Environment.NewLine + e.Message);
MessageBox.Error("自动伐木时异常:" + e.Source + "\r\n--" + Environment.NewLine + e.StackTrace + "\r\n---" + Environment.NewLine + e.Message);
}
finally
{

View File

@ -1,6 +1,6 @@
using BetterGenshinImpact.GameTask.Model.Area;
using System.Threading;
using System.Windows;
using Wpf.Ui.Violeta.Controls;
namespace BetterGenshinImpact.GameTask.Macro;
@ -13,7 +13,7 @@ public class QuickEnhanceArtifactMacro
{
if (!TaskContext.Instance().IsInitialized)
{
MessageBox.Show("请先启动");
Toast.Warning("请先启动");
return;
}

View File

@ -3,7 +3,7 @@ using BetterGenshinImpact.GameTask.Common;
using BetterGenshinImpact.GameTask.Model.Area;
using Microsoft.Extensions.Logging;
using System;
using System.Windows;
using Wpf.Ui.Violeta.Controls;
namespace BetterGenshinImpact.GameTask.QucikBuy;
@ -13,7 +13,7 @@ public class QuickBuyTask
{
if (!TaskContext.Instance().IsInitialized)
{
MessageBox.Show("请先启动");
Toast.Warning("请先启动");
return;
}
if (!SystemControl.IsGenshinImpactActiveByProcess())

View File

@ -6,6 +6,7 @@ using BetterGenshinImpact.GameTask.QuickSereniteaPot.Assets;
using BetterGenshinImpact.View.Drawable;
using Microsoft.Extensions.Logging;
using System;
using Wpf.Ui.Violeta.Controls;
using static Vanara.PInvoke.User32;
namespace BetterGenshinImpact.GameTask.QuickSereniteaPot;
@ -46,7 +47,7 @@ public class QuickSereniteaPotTask
{
if (!TaskContext.Instance().IsInitialized)
{
System.Windows.MessageBox.Show("请先启动");
Toast.Warning("请先启动");
return;
}

View File

@ -0,0 +1 @@
global using MessageBox = Wpf.Ui.Violeta.Controls.MessageBox;

View File

@ -9,7 +9,6 @@ using System.Security.Principal;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
namespace BetterGenshinImpact.Helpers;
@ -85,8 +84,7 @@ internal static class RuntimeHelper
catch (Exception ex)
{
Debug.WriteLine(ex);
MessageBox.Show("以管理员权限启动 BetterGI 失败,非管理员权限下所有模拟操作功能均不可用!\r\n请尝试 右键 —— 以管理员身份运行 的方式启动 BetterGI",
"警告", MessageBoxButton.OK, MessageBoxImage.Warning);
MessageBox.Error("以管理员权限启动 BetterGI 失败,非管理员权限下所有模拟操作功能均不可用!\r\n请尝试 右键 —— 以管理员身份运行 的方式启动 BetterGI");
return;
}
}
@ -142,8 +140,7 @@ internal static class RuntimeHelper
? "请不要把主程序exe文件剪切到桌面。正确的做法请右键点击主程序在弹出的菜单中选择“发送到”选项然后选择“桌面创建快捷方式”。"
: "请重新安装软件");
MessageBox.Show(stringBuilder.ToString(),
"警告", MessageBoxButton.OK, MessageBoxImage.Warning);
MessageBox.Warning(stringBuilder.ToString());
Environment.Exit(0xFFFF);
}
}

View File

@ -1,23 +0,0 @@
using Wpf.Ui.Controls;
namespace BetterGenshinImpact.Helpers;
public class WpfUiMessageBoxHelper
{
public static void Show(string title, string content)
{
var uiMessageBox = new MessageBox
{
Title = title,
Content = content,
CloseButtonText = "确定",
};
uiMessageBox.ShowDialogAsync();
}
public static void Show(string content)
{
Show("提示", content);
}
}

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Media;
using Wpf.Ui.Violeta.Controls;
namespace BetterGenshinImpact.View
{
@ -42,7 +43,7 @@ namespace BetterGenshinImpact.View
{
if (hWnd == IntPtr.Zero)
{
MessageBox.Show("请选择窗口");
Toast.Warning("请选择窗口");
return;
}

View File

@ -88,7 +88,7 @@ public partial class MainWindowViewModel : ObservableObject, IViewModel
}
catch (Exception e)
{
MessageBox.Show("PaddleOcr预热失败" + e.Source + "\r\n--" + Environment.NewLine + e.StackTrace + "\r\n---" + Environment.NewLine + e.Message);
MessageBox.Warning("PaddleOcr预热失败" + e.Source + "\r\n--" + Environment.NewLine + e.StackTrace + "\r\n---" + Environment.NewLine + e.Message);
}
try

View File

@ -152,7 +152,7 @@ public partial class HomePageViewModel : ObservableObject, INavigationAware, IVi
}
else
{
System.Windows.MessageBox.Show("选择的窗体句柄为空!");
MessageBox.Error("选择的窗体句柄为空!");
}
}
@ -184,7 +184,7 @@ public partial class HomePageViewModel : ObservableObject, INavigationAware, IVi
if (hWnd == IntPtr.Zero)
{
System.Windows.MessageBox.Show("未找到原神窗口,请先启动原神!");
MessageBox.Error("未找到原神窗口,请先启动原神!");
return;
}
}

View File

@ -7,7 +7,6 @@ using BetterGenshinImpact.View.Windows.Editable;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.Extensions.Logging;
using SharpDX.Direct3D11;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@ -16,6 +15,7 @@ using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using Wpf.Ui;
using Wpf.Ui.Controls;
@ -195,11 +195,12 @@ public partial class ScriptControlViewModel : ObservableObject, INavigationAware
public static void ShowEditWindow(object viewModel)
{
var uiMessageBox = new MessageBox
var uiMessageBox = new Wpf.Ui.Controls.MessageBox
{
Title = "修改通用设置",
Content = new ScriptGroupProjectEditor { DataContext = viewModel },
CloseButtonText = "确定",
Owner = Application.Current.MainWindow,
};
uiMessageBox.ShowDialogAsync();
}

View File

@ -13,12 +13,13 @@ using BetterGenshinImpact.View.Pages;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Windows.System;
using Wpf.Ui;
using Wpf.Ui.Controls;
using MessageBox = System.Windows.MessageBox;
using Wpf.Ui.Violeta.Controls;
namespace BetterGenshinImpact.ViewModel.Pages;
@ -120,7 +121,7 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw
{
if (string.IsNullOrEmpty(Config.AutoGeniusInvokationConfig.StrategyName))
{
MessageBox.Show("请先选择策略");
Toast.Warning("请先选择策略");
return;
}
@ -128,7 +129,7 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw
if (!File.Exists(path))
{
MessageBox.Show("策略文件不存在");
Toast.Error("策略文件不存在");
return;
}
@ -146,16 +147,16 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw
}
}
}
catch (System.Exception ex)
catch (Exception ex)
{
MessageBox.Show(ex.Message);
MessageBox.Error(ex.Message);
}
}
[RelayCommand]
public void OnGoToAutoGeniusInvokationUrl()
public async Task OnGoToAutoGeniusInvokationUrlAsync()
{
Process.Start(new ProcessStartInfo("https://bgi.huiyadan.com/doc.html#%E8%87%AA%E5%8A%A8%E4%B8%83%E5%9C%A3%E5%8F%AC%E5%94%A4") { UseShellExecute = true });
await Launcher.LaunchUriAsync(new Uri("https://bgi.huiyadan.com/doc.html#%E8%87%AA%E5%8A%A8%E4%B8%83%E5%9C%A3%E5%8F%AC%E5%94%A4"));
}
[RelayCommand]
@ -180,16 +181,16 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw
}
}
}
catch (System.Exception ex)
catch (Exception ex)
{
MessageBox.Show(ex.Message);
MessageBox.Error(ex.Message);
}
}
[RelayCommand]
public void OnGoToAutoWoodUrl()
public async Task OnGoToAutoWoodUrlAsync()
{
Process.Start(new ProcessStartInfo("https://bgi.huiyadan.com/feats/felling.html") { UseShellExecute = true });
await Launcher.LaunchUriAsync(new Uri("https://bgi.huiyadan.com/feats/felling.html"));
}
[RelayCommand]
@ -208,7 +209,7 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw
}
if (!File.Exists(path) && !Directory.Exists(path))
{
MessageBox.Show("战斗策略文件不存在");
Toast.Error("战斗策略文件不存在");
return;
}
@ -225,9 +226,9 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw
}
}
}
catch (System.Exception ex)
catch (Exception ex)
{
MessageBox.Show(ex.Message);
MessageBox.Error(ex.Message);
}
}
@ -236,7 +237,7 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw
{
if (string.IsNullOrEmpty(strategyName))
{
MessageBox.Show("请先选择战斗策略");
Toast.Warning("请先选择战斗策略");
return null;
}
@ -244,7 +245,7 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw
if (!File.Exists(path))
{
MessageBox.Show("战斗策略文件不存在");
Toast.Error("战斗策略文件不存在");
return null;
}
@ -253,9 +254,9 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw
}
[RelayCommand]
public void OnGoToAutoFightUrl()
public async Task OnGoToAutoFightUrlAsync()
{
Process.Start(new ProcessStartInfo("https://bgi.huiyadan.com/feats/domain.html") { UseShellExecute = true });
await Launcher.LaunchUriAsync(new Uri("https://bgi.huiyadan.com/feats/domain.html"));
}
[RelayCommand]
@ -274,7 +275,7 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw
}
if (!File.Exists(path) && !Directory.Exists(path))
{
MessageBox.Show("战斗策略文件不存在");
Toast.Error("战斗策略文件不存在");
return;
}
@ -291,16 +292,16 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw
}
}
}
catch (System.Exception ex)
catch (Exception ex)
{
MessageBox.Show(ex.Message);
MessageBox.Error(ex.Message);
}
}
[RelayCommand]
public void OnGoToAutoDomainUrl()
public async Task OnGoToAutoDomainUrlAsync()
{
Process.Start(new ProcessStartInfo("https://bgi.huiyadan.com/feats/domain.html") { UseShellExecute = true });
await Launcher.LaunchUriAsync(new Uri("https://bgi.huiyadan.com/feats/domain.html"));
}
[RelayCommand]
@ -325,16 +326,16 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw
}
}
}
catch (System.Exception ex)
catch (Exception ex)
{
MessageBox.Show(ex.Message);
MessageBox.Error(ex.Message);
}
}
[RelayCommand]
public void OnGoToAutoTrackUrl()
public async Task OnGoToAutoTrackUrlAsync()
{
Process.Start(new ProcessStartInfo("https://bgi.huiyadan.com/feats/track.html") { UseShellExecute = true });
await Launcher.LaunchUriAsync(new Uri("https://bgi.huiyadan.com/feats/track.html"));
}
[RelayCommand]
@ -361,14 +362,14 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
MessageBox.Error(ex.Message);
}
}
[RelayCommand]
public void OnGoToAutoTrackPathUrl()
public async Task OnGoToAutoTrackPathUrlAsync()
{
Process.Start(new ProcessStartInfo("https://bgi.huiyadan.com/feats/track.html") { UseShellExecute = true });
await Launcher.LaunchUriAsync(new Uri("https://bgi.huiyadan.com/feats/track.html"));
}
[RelayCommand]
@ -393,16 +394,16 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw
}
}
}
catch (System.Exception ex)
catch (Exception ex)
{
MessageBox.Show(ex.Message);
MessageBox.Error(ex.Message);
}
}
[RelayCommand]
public void OnGoToAutoMusicGameUrl()
public async Task OnGoToAutoMusicGameUrlAsync()
{
Process.Start(new ProcessStartInfo("https://bgi.huiyadan.com/feats/music.html") { UseShellExecute = true });
await Launcher.LaunchUriAsync(new Uri("https://bgi.huiyadan.com/feats/music.html"));
}
public static void SetSwitchAutoTrackButtonText(bool running)

View File

@ -1,5 +1,4 @@
using BetterGenshinImpact.Core.Config;
using BetterGenshinImpact.Helpers;
using BetterGenshinImpact.Service;
using BetterGenshinImpact.View.Windows;
using CommunityToolkit.Mvvm.ComponentModel;
@ -8,6 +7,7 @@ using System;
using System.Linq;
using System.Text.Json;
using System.Windows;
using Wpf.Ui.Violeta.Controls;
namespace BetterGenshinImpact.ViewModel.Windows;
@ -28,7 +28,7 @@ public partial class JsonMonoViewModel : ObservableObject
}
catch (Exception e)
{
WpfUiMessageBoxHelper.Show("读取黑白名单出错:" + e.ToString());
MessageBox.Error("读取黑白名单出错:" + e.ToString());
}
}
@ -41,18 +41,18 @@ public partial class JsonMonoViewModel : ObservableObject
}
catch (Exception e)
{
WpfUiMessageBoxHelper.Show("保存失败:" + e.ToString());
MessageBox.Error("保存失败:" + e.ToString());
return;
}
try
{
Global.WriteAllText(JsonPath, JsonText);
// WpfUiMessageBoxHelper.Show("保存成功");
Toast.Success("保存成功");
}
catch (Exception e)
{
WpfUiMessageBoxHelper.Show("保存失败:" + e.ToString());
MessageBox.Error("保存失败:" + e.ToString());
}
}