feat: 为MessageBox添加反色

This commit is contained in:
枫雨
2023-04-08 20:56:37 +08:00
parent 76c09a630a
commit 810e1b215f
10 changed files with 132 additions and 40 deletions

View File

@@ -21,6 +21,7 @@ using System.Security.Permissions;
using System.Text;
using System.Windows;
using System.Windows.Interop;
using HandyControl.Data;
using Point = System.Windows.Point;
[assembly: SecurityPermission(SecurityAction.RequestMinimum, UnmanagedCode = true)]
@@ -290,5 +291,86 @@ namespace MaaWpfGui.Helper
return true;
}
private static void SetImage(MessageBoxImage messageBoxImage, ref string iconKey, ref string iconBrushKey)
{
var key = string.Empty;
var brushKey = string.Empty;
switch (messageBoxImage)
{
case MessageBoxImage.Question:
key = ResourceToken.AskGeometry;
brushKey = ResourceToken.AccentBrush;
break;
case MessageBoxImage.Error:
key = ResourceToken.ErrorGeometry;
brushKey = ResourceToken.DangerBrush;
break;
case MessageBoxImage.Warning:
key = ResourceToken.WarningGeometry;
brushKey = ResourceToken.WarningBrush;
break;
case MessageBoxImage.Information:
key = ResourceToken.InfoGeometry;
brushKey = ResourceToken.InfoBrush;
break;
}
iconKey = string.IsNullOrEmpty(iconKey) ? key : iconKey;
iconBrushKey = string.IsNullOrEmpty(iconBrushKey) ? brushKey : iconBrushKey;
}
public static MessageBoxResult Show(MessageBoxInfo info) => HandyControl.Controls.MessageBox.Show(info);
public static MessageBoxResult Show(
string messageBoxText,
string caption = "",
MessageBoxButton buttons = MessageBoxButton.OK,
MessageBoxImage icon = MessageBoxImage.None,
string iconKey = "",
string iconBrushKey = "",
string ok = "",
string cancel = "",
string yes = "",
string no = "",
bool useNativeMethod = false)
{
caption = string.IsNullOrEmpty(caption) ? LocalizationHelper.GetString("Tip") : caption;
ok = string.IsNullOrEmpty(ok) ? LocalizationHelper.GetString("Ok") : ok;
cancel = string.IsNullOrEmpty(cancel) ? LocalizationHelper.GetString("ManualRestart") : cancel;
yes = string.IsNullOrEmpty(yes) ? LocalizationHelper.GetString("Yes") : yes;
no = string.IsNullOrEmpty(no) ? LocalizationHelper.GetString("No") : no;
if (useNativeMethod)
{
Unregister();
OK = ok;
Cancel = cancel;
Yes = yes;
No = no;
Register();
var result = MessageBox.Show(messageBoxText, caption, buttons, icon);
Unregister();
return result;
}
else
{
SetImage(icon, ref iconKey, ref iconBrushKey);
var info = new MessageBoxInfo
{
Message = messageBoxText,
Caption = caption,
Button = buttons,
IconKey = iconKey,
IconBrushKey = iconBrushKey,
ConfirmContent = ok,
CancelContent = cancel,
YesContent = yes,
NoContent = no,
};
return HandyControl.Controls.MessageBox.Show(info);
}
}
}
}

View File

@@ -19,6 +19,7 @@ using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using HandyControl.Data;
using MaaWpfGui.Constants;
using MaaWpfGui.Extensions;
using MaaWpfGui.Helper;
@@ -283,7 +284,7 @@ namespace MaaWpfGui.Main
{
Execute.OnUIThread(() =>
{
_windowManager.ShowMessageBox(LocalizationHelper.GetString("ResourceBroken"), LocalizationHelper.GetString("Error"), icon: MessageBoxImage.Error);
MessageBoxHelper.Show(LocalizationHelper.GetString("ResourceBroken"), LocalizationHelper.GetString("Error"), iconKey: ResourceToken.FatalGeometry, iconBrushKey: ResourceToken.DangerBrush);
Application.Current.Shutdown();
});
}
@@ -373,7 +374,7 @@ namespace MaaWpfGui.Main
break;
case AsstMsg.InitFailed:
_windowManager.ShowMessageBox(LocalizationHelper.GetString("InitializationError"), LocalizationHelper.GetString("Error"), icon: MessageBoxImage.Error);
MessageBoxHelper.Show(LocalizationHelper.GetString("InitializationError"), LocalizationHelper.GetString("Error"), iconKey: ResourceToken.FatalGeometry, iconBrushKey: ResourceToken.DangerBrush);
Application.Current.Shutdown();
break;

View File

@@ -128,9 +128,13 @@
<system:String x:Key="SwitchLanguage">Switch Language</system:String>
<system:String x:Key="Language">Language</system:String>
<system:String x:Key="LanguageChangedTip">the language settings has been changed, restart the app now?</system:String>
<system:String x:Key="Ok">OK</system:String>
<system:String x:Key="ManualRestart">Later</system:String>
<system:String x:Key="Tip">Tip</system:String>
<system:String x:Key="Yes">Yes</system:String>
<system:String x:Key="No">No</system:String>
<system:String x:Key="Ok">OK</system:String>
<system:String x:Key="Cancel">Cancel</system:String>
<system:String x:Key="HotKeyShowGui">[HotKey] Show/collapse MAA</system:String>
<system:String x:Key="HotKeyLinkStart">[HotKey] Link start/stop</system:String>

View File

@@ -127,9 +127,13 @@
<system:String x:Key="SwitchLanguage">言語を切り替える</system:String>
<system:String x:Key="Language">言語</system:String>
<system:String x:Key="LanguageChangedTip">言語設定が変更されました、今すぐMAAを再起動して言語設定を適用しますか</system:String>
<system:String x:Key="Ok">はい</system:String>
<system:String x:Key="ManualRestart">後で</system:String>
<system:String x:Key="Tip">ヒント</system:String>
<system:String x:Key="Yes">はい</system:String>
<system:String x:Key="No">いいえ</system:String>
<system:String x:Key="Ok">はい</system:String>
<system:String x:Key="Cancel">キャンセル</system:String>
<system:String x:Key="HotKeyShowGui">[ホットキー] MAAの表示/最小化</system:String>
<system:String x:Key="HotKeyLinkStart">[ホットキー] Link 開始/停止</system:String>
@@ -524,4 +528,4 @@
<system:String x:Key="Hangover">つ、次は飲みすぎないようにしないと……</system:String>
<system:String x:Key="HelloWorld">Hello World!</system:String>
<!-- EasterEggs -->
</ResourceDictionary>
</ResourceDictionary>

View File

@@ -121,9 +121,13 @@
<system:String x:Key="SwitchLanguage">언어 전환</system:String>
<system:String x:Key="Language">언어</system:String>
<system:String x:Key="LanguageChangedTip">언어가 변경되었습니다. 지금 MAA를 재실행하여 새 설정을 적용하시겠습니까?</system:String>
<system:String x:Key="Ok">확인</system:String>
<system:String x:Key="ManualRestart">나중에</system:String>
<system:String x:Key="Tip">도움말</system:String>
<system:String x:Key="Yes">예</system:String>
<system:String x:Key="No">아니요</system:String>
<system:String x:Key="Ok">확인</system:String>
<system:String x:Key="Cancel">취소</system:String>
<system:String x:Key="HotKeyShowGui">[단축키] MAA 보이기/숨기기</system:String>
<system:String x:Key="HotKeyLinkStart">[단축키] Link 시작/중지</system:String>
@@ -511,4 +515,4 @@
<system:String x:Key="Hangover">다, 다음엔 적당히 마셔야지……</system:String>
<system:String x:Key="HelloWorld">Hello World!</system:String>
<!-- EasterEggs -->
</ResourceDictionary>
</ResourceDictionary>

View File

@@ -129,9 +129,13 @@
<system:String x:Key="SwitchLanguage">切换语言</system:String>
<system:String x:Key="Language">语言</system:String>
<system:String x:Key="LanguageChangedTip">语言设置已更改,是否现在重启 MAA 以应用语言设置?</system:String>
<system:String x:Key="Ok">好的</system:String>
<system:String x:Key="ManualRestart">稍后</system:String>
<system:String x:Key="Tip">提示</system:String>
<system:String x:Key="Yes">是</system:String>
<system:String x:Key="No">否</system:String>
<system:String x:Key="Ok">好的</system:String>
<system:String x:Key="Cancel">取消</system:String>
<system:String x:Key="HotKeyShowGui">[热键] 显示/收起 MAA</system:String>
<system:String x:Key="HotKeyLinkStart">[热键] Link start/stop</system:String>

View File

@@ -112,9 +112,13 @@
<system:String x:Key="SwitchLanguage">切換語言</system:String>
<system:String x:Key="Language">語言</system:String>
<system:String x:Key="LanguageChangedTip">語言設定已變更,是否現在重啟 MAA 以套用語言設定?</system:String>
<system:String x:Key="Ok">好的</system:String>
<system:String x:Key="ManualRestart">稍後</system:String>
<system:String x:Key="Tip">提示</system:String>
<system:String x:Key="Yes">是</system:String>
<system:String x:Key="No">否</system:String>
<system:String x:Key="Ok">好的</system:String>
<system:String x:Key="Cancel">取消</system:String>
<system:String x:Key="HotKeyShowGui">[熱鍵] 顯示/收起 MAA</system:String>
<system:String x:Key="HotKeyLinkStart">[熱鍵] Link start/stop</system:String>
@@ -458,4 +462,4 @@
<system:String x:Key="Hangover">下次不能喝、喝這麼多了......</system:String>
<system:String x:Key="HelloWorld">Hello World!</system:String>
<!-- EasterEggs -->
</ResourceDictionary>
</ResourceDictionary>

View File

@@ -121,7 +121,7 @@ namespace MaaWpfGui.ViewModels.UI
if (Hangover)
{
Hangover = false;
_windowManager.ShowMessageBox(
MessageBoxHelper.Show(
LocalizationHelper.GetString("Hangover"),
LocalizationHelper.GetString("Burping"),
MessageBoxButton.OK, MessageBoxImage.Hand);
@@ -2536,17 +2536,12 @@ namespace MaaWpfGui.ViewModels.UI
SwitchDarkMode();
/*
MessageBoxHelper.Unregister();
MessageBoxHelper.Yes = LocalizationHelper.GetString("Ok");
MessageBoxHelper.No = LocalizationHelper.GetString("ManualRestart");
MessageBoxHelper.Register();
var result = MessageBox.Show(
var result = MessageBoxHelper.Show(
LocalizationHelper.GetString("DarkModeSetColorsTip"),
LocalizationHelper.GetString("Tip"),
MessageBoxButton.YesNo,
MessageBoxButton.OKCancel,
MessageBoxImage.Question);
MessageBoxHelper.Unregister();
if (result == MessageBoxResult.Yes)
if (result == MessageBoxResult.OK)
{
Application.Current.Shutdown();
System.Windows.Forms.Application.Restart();
@@ -2671,26 +2666,25 @@ namespace MaaWpfGui.ViewModels.UI
string FormatText(string text, string key)
=> string.Format(text, LocalizationHelper.GetString(key, value), LocalizationHelper.GetString(key, _language));
MessageBoxHelper.Unregister();
MessageBoxHelper.Yes = FormatText("{0}({1})", "Ok");
MessageBoxHelper.No = FormatText("{0}({1})", "ManualRestart");
MessageBoxHelper.Register();
Window mainWindow = Application.Current.MainWindow;
mainWindow.Show();
mainWindow.WindowState = mainWindow.WindowState = WindowState.Normal;
mainWindow.Activate();
var result = MessageBox.Show(
var result = MessageBoxHelper.Show(
FormatText("{0}\n{1}", "LanguageChangedTip"),
FormatText("{0}({1})", "Tip"),
MessageBoxButton.YesNo,
MessageBoxImage.Question);
MessageBoxHelper.Unregister();
SetAndNotify(ref _language, value);
if (result == MessageBoxResult.Yes)
MessageBoxButton.OKCancel,
MessageBoxImage.Question,
ok: FormatText("{0}({1})", "Ok"),
cancel: FormatText("{0}({1})", "ManualRestart"));
if (result == MessageBoxResult.OK)
{
Application.Current.Shutdown();
System.Windows.Forms.Application.Restart();
}
SetAndNotify(ref _language, value);
}
}
@@ -2736,7 +2730,7 @@ namespace MaaWpfGui.ViewModels.UI
private void SetPallasLanguage()
{
ConfigurationHelper.SetValue(ConfigurationKeys.Localization, PallasLangKey);
var result = _windowManager.ShowMessageBox(
var result = MessageBoxHelper.Show(
LocalizationHelper.GetString("DrunkAndStaggering"),
LocalizationHelper.GetString("Burping"),
MessageBoxButton.OK, MessageBoxImage.Asterisk);

View File

@@ -1480,7 +1480,7 @@ namespace MaaWpfGui.ViewModels.UI
Process.Start("shutdown.exe", "-s -t 60");
// 关机询问
var shutdownResult = _windowManager.ShowMessageBox(LocalizationHelper.GetString("AboutToShutdown"), LocalizationHelper.GetString("ShutdownPrompt"), MessageBoxButton.OK, MessageBoxImage.Question);
var shutdownResult = MessageBoxHelper.Show(LocalizationHelper.GetString("AboutToShutdown"), LocalizationHelper.GetString("ShutdownPrompt"), MessageBoxButton.OK, MessageBoxImage.Question, ok: LocalizationHelper.GetString("Cancel"));
if (shutdownResult == MessageBoxResult.OK)
{
Process.Start("shutdown.exe", "-a");

View File

@@ -515,17 +515,12 @@ namespace MaaWpfGui.ViewModels.UI
public void AskToRestart()
{
MessageBoxHelper.Unregister();
MessageBoxHelper.Yes = LocalizationHelper.GetString("Ok");
MessageBoxHelper.No = LocalizationHelper.GetString("ManualRestart");
MessageBoxHelper.Register();
var result = MessageBox.Show(
var result = MessageBoxHelper.Show(
LocalizationHelper.GetString("NewVersionDownloadCompletedDesc"),
LocalizationHelper.GetString("NewVersionDownloadCompletedTitle"),
MessageBoxButton.YesNo,
MessageBoxImage.Question);
MessageBoxHelper.Unregister();
if (result == MessageBoxResult.Yes)
MessageBoxButton.OKCancel,
MessageBoxImage.Question, useNativeMethod: true);
if (result == MessageBoxResult.OK)
{
Application.Current.Shutdown();
System.Windows.Forms.Application.Restart();