From 524d5fa2a0fe63e9b24b2e5bcd047001999e0ec8 Mon Sep 17 00:00:00 2001
From: status102 <102887808+status102@users.noreply.github.com>
Date: Mon, 9 Dec 2024 21:07:53 +0800
Subject: [PATCH] =?UTF-8?q?rft:=20WpfGui=E9=87=8D=E6=9E=84=20=E6=8B=86?=
=?UTF-8?q?=E5=88=86`=E8=AE=BE=E7=BD=AE-=E6=80=A7=E8=83=BD=E8=AE=BE?=
=?UTF-8?q?=E7=BD=AE`=20(#11329)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/MaaWpfGui/Main/AsstProxy.cs | 2 +-
.../ViewModels/UI/SettingsViewModel.cs | 39 ++---------
.../TaskQueue/PerformanceUserControlModel.cs | 56 ++++++++++++++++
src/MaaWpfGui/Views/UI/SettingsView.xaml | 5 +-
.../PerformanceUserControl.xaml | 67 +++++++++----------
.../PerformanceUserControl.xaml.cs | 2 +-
6 files changed, 98 insertions(+), 73 deletions(-)
create mode 100644 src/MaaWpfGui/ViewModels/UserControl/TaskQueue/PerformanceUserControlModel.cs
rename src/MaaWpfGui/Views/UserControl/{ => Settings}/PerformanceUserControl.xaml (51%)
rename src/MaaWpfGui/Views/UserControl/{ => Settings}/PerformanceUserControl.xaml.cs (95%)
diff --git a/src/MaaWpfGui/Main/AsstProxy.cs b/src/MaaWpfGui/Main/AsstProxy.cs
index 994821e599..e224d09da3 100644
--- a/src/MaaWpfGui/Main/AsstProxy.cs
+++ b/src/MaaWpfGui/Main/AsstProxy.cs
@@ -608,7 +608,7 @@ namespace MaaWpfGui.Main
var screencapCostAvg = details["details"]?["avg"]?.ToString() ?? "???";
var screencapCostMax = details["details"]?["max"]?.ToString() ?? "???";
var currentTime = DateTimeOffset.Now.ToString("HH:mm:ss");
- Instances.SettingsViewModel.ScreencapCost = string.Format(LocalizationHelper.GetString("ScreencapCost"), screencapCostMin, screencapCostAvg, screencapCostMax, currentTime);
+ SettingsViewModel.PerformanceSettings.ScreencapCost = string.Format(LocalizationHelper.GetString("ScreencapCost"), screencapCostMin, screencapCostAvg, screencapCostMax, currentTime);
if (!HasPrintedScreencapWarning && int.TryParse(screencapCostAvg, out var screencapCostAvgInt))
{
static void AddLog(string message, string color)
diff --git a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs
index d81c17627d..c8780abc0c 100644
--- a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs
+++ b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs
@@ -149,6 +149,11 @@ namespace MaaWpfGui.ViewModels.UI
///
public static ExternalNotificationSettingsUserControlModel ExternalNotificationSettings { get; } = new();
+ ///
+ /// Gets 性能设置model
+ ///
+ public static PerformanceUserControlModel PerformanceSettings { get; } = new();
+
#endregion 设置界面Model
///
@@ -375,40 +380,6 @@ namespace MaaWpfGui.ViewModels.UI
#endregion EasterEggs
- #region Performance
-
- public List GpuOptions => GpuOption.GetGpuOptions();
-
- public GpuOption ActiveGpuOption
- {
- get => GpuOption.GetCurrent();
- set
- {
- GpuOption.SetCurrent(value);
- AskRestartToApplySettings();
- }
- }
-
- public bool AllowDeprecatedGpu
- {
- get => GpuOption.AllowDeprecatedGpu;
- set
- {
- GpuOption.AllowDeprecatedGpu = value;
- NotifyOfPropertyChange();
- }
- }
-
- private string _screencapCost = string.Format(LocalizationHelper.GetString("ScreencapCost"), "---", "---", "---", "---");
-
- public string ScreencapCost
- {
- get => _screencapCost;
- set => SetAndNotify(ref _screencapCost, value);
- }
-
- #endregion Performance
-
#region 开始唤醒
private string _accountName = ConfigurationHelper.GetValue(ConfigurationKeys.AccountName, string.Empty);
diff --git a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/PerformanceUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/PerformanceUserControlModel.cs
new file mode 100644
index 0000000000..3396976eed
--- /dev/null
+++ b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/PerformanceUserControlModel.cs
@@ -0,0 +1,56 @@
+//
+// MaaWpfGui - A part of the MaaCoreArknights project
+// Copyright (C) 2021 MistEO and Contributors
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License v3.0 only as published by
+// the Free Software Foundation, either version 3 of the License, or
+// any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY
+//
+
+#nullable enable
+using System.Collections.Generic;
+using MaaWpfGui.Helper;
+using MaaWpfGui.ViewModels.UI;
+using Stylet;
+
+namespace MaaWpfGui.ViewModels.UserControl.TaskQueue;
+
+///
+/// 性能设置
+///
+public class PerformanceUserControlModel : PropertyChangedBase
+{
+ public List GpuOptions => GpuOption.GetGpuOptions();
+
+ public GpuOption ActiveGpuOption
+ {
+ get => GpuOption.GetCurrent();
+ set
+ {
+ GpuOption.SetCurrent(value);
+ SettingsViewModel.AskRestartToApplySettings();
+ }
+ }
+
+ public bool AllowDeprecatedGpu
+ {
+ get => GpuOption.AllowDeprecatedGpu;
+ set
+ {
+ GpuOption.AllowDeprecatedGpu = value;
+ NotifyOfPropertyChange();
+ }
+ }
+
+ private string _screencapCost = string.Format(LocalizationHelper.GetString("ScreencapCost"), "---", "---", "---", "---");
+
+ public string ScreencapCost
+ {
+ get => _screencapCost;
+ set => SetAndNotify(ref _screencapCost, value);
+ }
+}
diff --git a/src/MaaWpfGui/Views/UI/SettingsView.xaml b/src/MaaWpfGui/Views/UI/SettingsView.xaml
index 061b6728ab..8060ad9d25 100644
--- a/src/MaaWpfGui/Views/UI/SettingsView.xaml
+++ b/src/MaaWpfGui/Views/UI/SettingsView.xaml
@@ -55,10 +55,11 @@
DataContext="{Binding TimerSettings}" />
-
+ DataContext="{Binding PerformanceSettings}"
+ IsEnabled="{Binding DataContext.Idle, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" />
-
+
-
-
-
+
+
+
-
-
+
+
-
+
+ Grid.Column="1"
+ Width="240"
+ Margin="10,5"
+ HorizontalAlignment="Center"
+ VerticalAlignment="Center"
+ ItemsSource="{Binding GpuOptions}"
+ SelectedValue="{Binding ActiveGpuOption}">
-
-
+
+ HorizontalAlignment="Center"
+ Text="{c:Binding ScreencapCost}" />
diff --git a/src/MaaWpfGui/Views/UserControl/PerformanceUserControl.xaml.cs b/src/MaaWpfGui/Views/UserControl/Settings/PerformanceUserControl.xaml.cs
similarity index 95%
rename from src/MaaWpfGui/Views/UserControl/PerformanceUserControl.xaml.cs
rename to src/MaaWpfGui/Views/UserControl/Settings/PerformanceUserControl.xaml.cs
index a78a6a58b9..8d2d41bdfc 100644
--- a/src/MaaWpfGui/Views/UserControl/PerformanceUserControl.xaml.cs
+++ b/src/MaaWpfGui/Views/UserControl/Settings/PerformanceUserControl.xaml.cs
@@ -11,7 +11,7 @@
// but WITHOUT ANY WARRANTY
//
-namespace MaaWpfGui.Views.UserControl
+namespace MaaWpfGui.Views.UserControl.Settings
{
///
/// GameSettingsUserControl.xaml 的交互逻辑