mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-20 10:57:45 +08:00
rft: 拆分 设置-连接设置 (#11120)
* rft: 拆分 设置-连接设置 * rft: 迁移Model路径以细分ViewModel * rft: 迁移Model及UserControl路径以细分Views
This commit is contained in:
@@ -320,9 +320,9 @@ namespace MaaWpfGui.Main
|
||||
|
||||
Instances.TaskQueueViewModel.SetInited();
|
||||
_runningState.SetIdle(true);
|
||||
AsstSetInstanceOption(InstanceOptionKey.TouchMode, Instances.SettingsViewModel.TouchMode);
|
||||
AsstSetInstanceOption(InstanceOptionKey.DeploymentWithPause, Instances.SettingsViewModel.DeploymentWithPause ? "1" : "0");
|
||||
AsstSetInstanceOption(InstanceOptionKey.AdbLiteEnabled, Instances.SettingsViewModel.AdbLiteEnabled ? "1" : "0");
|
||||
AsstSetInstanceOption(InstanceOptionKey.TouchMode, SettingsViewModel.ConnectSettingsDataContext.TouchMode);
|
||||
AsstSetInstanceOption(InstanceOptionKey.DeploymentWithPause, SettingsViewModel.ConnectSettingsDataContext.DeploymentWithPause ? "1" : "0");
|
||||
AsstSetInstanceOption(InstanceOptionKey.AdbLiteEnabled, SettingsViewModel.ConnectSettingsDataContext.AdbLiteEnabled ? "1" : "0");
|
||||
|
||||
// TODO: 之后把这个 OnUIThread 拆出来
|
||||
// ReSharper disable once AsyncVoidLambda
|
||||
@@ -460,7 +460,7 @@ namespace MaaWpfGui.Main
|
||||
Connected = true;
|
||||
_connectedAdb = details["details"]?["adb"]?.ToString();
|
||||
_connectedAddress = details["details"]?["address"]?.ToString();
|
||||
Instances.SettingsViewModel.ConnectAddress = _connectedAddress;
|
||||
SettingsViewModel.ConnectSettingsDataContext.ConnectAddress = _connectedAddress;
|
||||
break;
|
||||
|
||||
case "UnsupportedResolution":
|
||||
@@ -499,7 +499,7 @@ namespace MaaWpfGui.Main
|
||||
Execute.OnUIThread(
|
||||
async () =>
|
||||
{
|
||||
if (!Instances.SettingsViewModel.RetryOnDisconnected)
|
||||
if (!SettingsViewModel.ConnectSettingsDataContext.RetryOnDisconnected)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -527,7 +527,7 @@ namespace MaaWpfGui.Main
|
||||
{
|
||||
string costString = details["details"]?["cost"]?.ToString() ?? "???";
|
||||
string method = details["details"]?["method"]?.ToString() ?? "???";
|
||||
Instances.SettingsViewModel.ScreencapMethod = method;
|
||||
SettingsViewModel.ConnectSettingsDataContext.ScreencapMethod = method;
|
||||
|
||||
StringBuilder fastestScreencapStringBuilder = new();
|
||||
string color = UiLogColor.Trace;
|
||||
@@ -551,10 +551,10 @@ namespace MaaWpfGui.Main
|
||||
}
|
||||
|
||||
var needToStop = false;
|
||||
switch (Instances.SettingsViewModel.ConnectConfig)
|
||||
switch (SettingsViewModel.ConnectSettingsDataContext.ConnectConfig)
|
||||
{
|
||||
case "MuMuEmulator12":
|
||||
if (Instances.SettingsViewModel.MuMuEmulator12Extras.Enable && method != "MumuExtras")
|
||||
if (SettingsViewModel.ConnectSettingsDataContext.MuMuEmulator12Extras.Enable && method != "MumuExtras")
|
||||
{
|
||||
Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("MuMuExtrasNotEnabledMessage"), UiLogColor.Error);
|
||||
Instances.CopilotViewModel.AddLog(LocalizationHelper.GetString("MuMuExtrasNotEnabledMessage"), UiLogColor.Error, showTime: false);
|
||||
@@ -568,7 +568,7 @@ namespace MaaWpfGui.Main
|
||||
|
||||
break;
|
||||
case "LDPlayer":
|
||||
if (Instances.SettingsViewModel.LdPlayerExtras.Enable && method != "LDExtras")
|
||||
if (SettingsViewModel.ConnectSettingsDataContext.LdPlayerExtras.Enable && method != "LDExtras")
|
||||
{
|
||||
Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("LdExtrasNotEnabledMessage"), UiLogColor.Error);
|
||||
Instances.CopilotViewModel.AddLog(LocalizationHelper.GetString("LdExtrasNotEnabledMessage"), UiLogColor.Error, showTime: false);
|
||||
@@ -585,7 +585,7 @@ namespace MaaWpfGui.Main
|
||||
|
||||
fastestScreencapStringBuilder.Insert(0, string.Format(LocalizationHelper.GetString("FastestWayToScreencap"), costString, method));
|
||||
var fastestScreencapString = fastestScreencapStringBuilder.ToString();
|
||||
Instances.SettingsViewModel.ScreencapTestCost = fastestScreencapString;
|
||||
SettingsViewModel.ConnectSettingsDataContext.ScreencapTestCost = fastestScreencapString;
|
||||
Instances.TaskQueueViewModel.AddLog(fastestScreencapString, color);
|
||||
Instances.CopilotViewModel.AddLog(fastestScreencapString, color, showTime: false);
|
||||
|
||||
@@ -1798,17 +1798,17 @@ namespace MaaWpfGui.Main
|
||||
/// <returns>是否成功。</returns>
|
||||
public bool AsstConnect(ref string error)
|
||||
{
|
||||
switch (Instances.SettingsViewModel.ConnectConfig)
|
||||
switch (SettingsViewModel.ConnectSettingsDataContext.ConnectConfig)
|
||||
{
|
||||
case "MuMuEmulator12":
|
||||
AsstSetConnectionExtrasMuMu12(Instances.SettingsViewModel.MuMuEmulator12Extras.Config);
|
||||
AsstSetConnectionExtrasMuMu12(SettingsViewModel.ConnectSettingsDataContext.MuMuEmulator12Extras.Config);
|
||||
break;
|
||||
case "LDPlayer":
|
||||
AsstSetConnectionExtrasLdPlayer(Instances.SettingsViewModel.LdPlayerExtras.Config);
|
||||
AsstSetConnectionExtrasLdPlayer(SettingsViewModel.ConnectSettingsDataContext.LdPlayerExtras.Config);
|
||||
break;
|
||||
}
|
||||
|
||||
if (Instances.SettingsViewModel.AutoDetectConnection)
|
||||
if (SettingsViewModel.ConnectSettingsDataContext.AutoDetectConnection)
|
||||
{
|
||||
if (!AutoDetectConnection(ref error))
|
||||
{
|
||||
@@ -1816,8 +1816,8 @@ namespace MaaWpfGui.Main
|
||||
}
|
||||
}
|
||||
|
||||
if (Connected && _connectedAdb == Instances.SettingsViewModel.AdbPath &&
|
||||
_connectedAddress == Instances.SettingsViewModel.ConnectAddress)
|
||||
if (Connected && _connectedAdb == SettingsViewModel.ConnectSettingsDataContext.AdbPath &&
|
||||
_connectedAddress == SettingsViewModel.ConnectSettingsDataContext.ConnectAddress)
|
||||
{
|
||||
_logger.Information($"Already connected to {_connectedAdb} {_connectedAddress}");
|
||||
if (!_forcedReloadResource)
|
||||
@@ -1837,23 +1837,23 @@ namespace MaaWpfGui.Main
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ret = AsstConnect(_handle, Instances.SettingsViewModel.AdbPath, Instances.SettingsViewModel.ConnectAddress, Instances.SettingsViewModel.ConnectConfig);
|
||||
bool ret = AsstConnect(_handle, SettingsViewModel.ConnectSettingsDataContext.AdbPath, SettingsViewModel.ConnectSettingsDataContext.ConnectAddress, SettingsViewModel.ConnectSettingsDataContext.ConnectConfig);
|
||||
|
||||
// 尝试默认的备选端口
|
||||
if (!ret && Instances.SettingsViewModel.AutoDetectConnection)
|
||||
if (!ret && SettingsViewModel.ConnectSettingsDataContext.AutoDetectConnection)
|
||||
{
|
||||
if (Instances.SettingsViewModel.DefaultAddress.TryGetValue(Instances.SettingsViewModel.ConnectConfig, out var value))
|
||||
if (SettingsViewModel.ConnectSettingsDataContext.DefaultAddress.TryGetValue(SettingsViewModel.ConnectSettingsDataContext.ConnectConfig, out var value))
|
||||
{
|
||||
foreach (var address in value
|
||||
.TakeWhile(_ => !_runningState.GetIdle()))
|
||||
{
|
||||
ret = AsstConnect(_handle, Instances.SettingsViewModel.AdbPath, address, Instances.SettingsViewModel.ConnectConfig);
|
||||
ret = AsstConnect(_handle, SettingsViewModel.ConnectSettingsDataContext.AdbPath, address, SettingsViewModel.ConnectSettingsDataContext.ConnectConfig);
|
||||
if (!ret)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Instances.SettingsViewModel.ConnectAddress = address;
|
||||
SettingsViewModel.ConnectSettingsDataContext.ConnectAddress = address;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1871,9 +1871,9 @@ namespace MaaWpfGui.Main
|
||||
{
|
||||
error = LocalizationHelper.GetString("ConnectFailed") + "\n" + LocalizationHelper.GetString("CheckSettings");
|
||||
}
|
||||
else if (Instances.SettingsViewModel.AutoDetectConnection && !Instances.SettingsViewModel.AlwaysAutoDetectConnection)
|
||||
else if (SettingsViewModel.ConnectSettingsDataContext.AutoDetectConnection && !SettingsViewModel.ConnectSettingsDataContext.AlwaysAutoDetectConnection)
|
||||
{
|
||||
Instances.SettingsViewModel.AutoDetectConnection = false;
|
||||
SettingsViewModel.ConnectSettingsDataContext.AutoDetectConnection = false;
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -1891,11 +1891,11 @@ namespace MaaWpfGui.Main
|
||||
IfPortEstablished(Instances.SettingsViewModel.ConnectAddress));
|
||||
*/
|
||||
|
||||
var adbPath = Instances.SettingsViewModel.AdbPath;
|
||||
var adbPath = SettingsViewModel.ConnectSettingsDataContext.AdbPath;
|
||||
bool adbResult = !string.IsNullOrEmpty(adbPath) &&
|
||||
File.Exists(adbPath) &&
|
||||
Path.GetFileName(adbPath).Contains("adb", StringComparison.InvariantCultureIgnoreCase) &&
|
||||
IfPortEstablished(Instances.SettingsViewModel.ConnectAddress);
|
||||
IfPortEstablished(SettingsViewModel.ConnectSettingsDataContext.ConnectAddress);
|
||||
|
||||
if (adbResult)
|
||||
{
|
||||
@@ -1905,22 +1905,22 @@ namespace MaaWpfGui.Main
|
||||
|
||||
// 蓝叠的特殊处理
|
||||
{
|
||||
string bsHvAddress = Instances.SettingsViewModel.TryToSetBlueStacksHyperVAddress() ?? string.Empty;
|
||||
string bsHvAddress = SettingsViewModel.ConnectSettingsDataContext.TryToSetBlueStacksHyperVAddress() ?? string.Empty;
|
||||
bool bsResult = IfPortEstablished(bsHvAddress);
|
||||
if (bsResult)
|
||||
{
|
||||
error = string.Empty;
|
||||
if (string.IsNullOrEmpty(Instances.SettingsViewModel.AdbPath) && Instances.SettingsViewModel.DetectAdbConfig(ref error))
|
||||
if (string.IsNullOrEmpty(SettingsViewModel.ConnectSettingsDataContext.AdbPath) && SettingsViewModel.ConnectSettingsDataContext.DetectAdbConfig(ref error))
|
||||
{
|
||||
return string.IsNullOrEmpty(error);
|
||||
}
|
||||
|
||||
Instances.SettingsViewModel.ConnectAddress = bsHvAddress;
|
||||
SettingsViewModel.ConnectSettingsDataContext.ConnectAddress = bsHvAddress;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (Instances.SettingsViewModel.DetectAdbConfig(ref error))
|
||||
if (SettingsViewModel.ConnectSettingsDataContext.DetectAdbConfig(ref error))
|
||||
{
|
||||
// https://github.com/MaaAssistantArknights/MaaAssistantArknights/issues/8547
|
||||
// DetectAdbConfig 会把 ConnectAddress 变成第一个不是 emulator 开头的地址,可能会存在多开问题
|
||||
|
||||
@@ -27,6 +27,7 @@ using System.Windows.Media.Imaging;
|
||||
using MaaWpfGui.Constants;
|
||||
using MaaWpfGui.Helper;
|
||||
using MaaWpfGui.States;
|
||||
using MaaWpfGui.ViewModels.UI;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Serilog;
|
||||
@@ -447,7 +448,7 @@ namespace MaaWpfGui.Services.RemoteControl
|
||||
// ConfigurationHelper.SetValue(type.Split('-')[1], data);
|
||||
await Execute.OnUIThreadAsync(() =>
|
||||
{
|
||||
Instances.SettingsViewModel.ConnectAddress = data;
|
||||
SettingsViewModel.ConnectSettingsDataContext.ConnectAddress = data;
|
||||
});
|
||||
break;
|
||||
case "Settings-Stage1":
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1056,7 +1056,7 @@ namespace MaaWpfGui.ViewModels.UI
|
||||
bool connected = await Task.Run(() => Instances.AsstProxy.AsstConnect(ref errMsg));
|
||||
|
||||
// 尝试启动模拟器
|
||||
if (!connected && Instances.SettingsViewModel.RetryOnDisconnected)
|
||||
if (!connected && SettingsViewModel.ConnectSettingsDataContext.RetryOnDisconnected)
|
||||
{
|
||||
AddLog(LocalizationHelper.GetString("ConnectFailed") + "\n" + LocalizationHelper.GetString("TryToStartEmulator"));
|
||||
|
||||
@@ -1088,7 +1088,7 @@ namespace MaaWpfGui.ViewModels.UI
|
||||
}
|
||||
|
||||
// 尝试重启 ADB
|
||||
if (!connected && Instances.SettingsViewModel.AllowAdbRestart)
|
||||
if (!connected && SettingsViewModel.ConnectSettingsDataContext.AllowAdbRestart)
|
||||
{
|
||||
AddLog(LocalizationHelper.GetString("ConnectFailed") + "\n" + LocalizationHelper.GetString("RestartAdb"));
|
||||
|
||||
@@ -1104,7 +1104,7 @@ namespace MaaWpfGui.ViewModels.UI
|
||||
}
|
||||
|
||||
// 尝试杀掉 ADB 进程
|
||||
if (!connected && Instances.SettingsViewModel.AllowAdbHardRestart)
|
||||
if (!connected && SettingsViewModel.ConnectSettingsDataContext.AllowAdbHardRestart)
|
||||
{
|
||||
AddLog(LocalizationHelper.GetString("ConnectFailed") + "\n" + LocalizationHelper.GetString("HardRestartAdb"));
|
||||
|
||||
@@ -1796,7 +1796,7 @@ namespace MaaWpfGui.ViewModels.UI
|
||||
{
|
||||
try
|
||||
{
|
||||
string emulatorMode = Instances.SettingsViewModel.ConnectConfig;
|
||||
string emulatorMode = SettingsViewModel.ConnectSettingsDataContext.ConnectConfig;
|
||||
Instances.AsstProxy.Connected = false;
|
||||
return emulatorMode switch
|
||||
{
|
||||
@@ -1821,7 +1821,7 @@ namespace MaaWpfGui.ViewModels.UI
|
||||
/// <returns>是否关闭成功</returns>
|
||||
private static bool KillEmulatorMuMuEmulator12()
|
||||
{
|
||||
string address = Instances.SettingsViewModel.ConnectAddress;
|
||||
string address = SettingsViewModel.ConnectSettingsDataContext.ConnectAddress;
|
||||
int emuIndex;
|
||||
if (address == "127.0.0.1:16384")
|
||||
{
|
||||
@@ -1895,7 +1895,7 @@ namespace MaaWpfGui.ViewModels.UI
|
||||
/// <returns>是否关闭成功</returns>
|
||||
private static bool KillEmulatorLdPlayer()
|
||||
{
|
||||
string address = Instances.SettingsViewModel.ConnectAddress;
|
||||
string address = SettingsViewModel.ConnectSettingsDataContext.ConnectAddress;
|
||||
int emuIndex;
|
||||
if (address.Contains(":"))
|
||||
{
|
||||
@@ -1971,7 +1971,7 @@ namespace MaaWpfGui.ViewModels.UI
|
||||
/// <returns>是否关闭成功</returns>
|
||||
private static bool KillEmulatorNox()
|
||||
{
|
||||
string address = Instances.SettingsViewModel.ConnectAddress;
|
||||
string address = SettingsViewModel.ConnectSettingsDataContext.ConnectAddress;
|
||||
int emuIndex;
|
||||
if (address == "127.0.0.1:62001")
|
||||
{
|
||||
@@ -2045,7 +2045,7 @@ namespace MaaWpfGui.ViewModels.UI
|
||||
/// <returns>是否关闭成功</returns>
|
||||
private static bool KillEmulatorXyaz()
|
||||
{
|
||||
string address = Instances.SettingsViewModel.ConnectAddress;
|
||||
string address = SettingsViewModel.ConnectSettingsDataContext.ConnectAddress;
|
||||
string portStr = address.Split(':')[1];
|
||||
int port = int.Parse(portStr);
|
||||
var emuIndex = (port - 21503) / 10;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -11,6 +11,7 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:properties="clr-namespace:MaaWpfGui.Styles.Properties"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:settingsViews="clr-namespace:MaaWpfGui.Views.UserControl.Settings"
|
||||
xmlns:ui="clr-namespace:MaaWpfGui.ViewModels.UI"
|
||||
xmlns:userControl="clr-namespace:MaaWpfGui.Views.UserControl"
|
||||
xmlns:viewModels="clr-namespace:MaaWpfGui.ViewModels"
|
||||
@@ -61,10 +62,11 @@
|
||||
<userControl:GameClientUserControl Margin="0,20" HorizontalAlignment="Center" />
|
||||
|
||||
<hc:Divider Content="{Binding ListTitle[4]}" />
|
||||
<userControl:ConnectSettingsUserControl
|
||||
<settingsViews:ConnectSettingsUserControl
|
||||
Margin="0,20"
|
||||
HorizontalAlignment="Center"
|
||||
IsEnabled="{Binding Idle}" />
|
||||
DataContext="{Binding ConnectSettingsDataContext}"
|
||||
IsEnabled="{Binding DataContext.Idle, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}" />
|
||||
|
||||
<hc:Divider Content="{Binding ListTitle[5]}" />
|
||||
<userControl:StartSettingsUserControl Margin="0,20" HorizontalAlignment="Center" />
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<UserControl
|
||||
x:Class="MaaWpfGui.Views.UserControl.ConnectSettingsUserControl"
|
||||
x:Class="MaaWpfGui.Views.UserControl.Settings.ConnectSettingsUserControl"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:c="clr-namespace:CalcBinding;assembly=CalcBinding"
|
||||
@@ -9,12 +9,11 @@
|
||||
xmlns:hc="https://handyorg.github.io/handycontrol"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:styles="clr-namespace:MaaWpfGui.Styles"
|
||||
xmlns:ui="clr-namespace:MaaWpfGui.ViewModels.UI"
|
||||
xmlns:viewModels="clr-namespace:MaaWpfGui.ViewModels"
|
||||
xmlns:vm="clr-namespace:MaaWpfGui"
|
||||
d:DataContext="{d:DesignInstance {x:Type ui:SettingsViewModel}}"
|
||||
xmlns:viewModels="clr-namespace:MaaWpfGui.ViewModels.UserControl.Settings"
|
||||
d:Background="White"
|
||||
d:DataContext="{d:DesignInstance {x:Type viewModels:ConnectSettingsUserControlModel}}"
|
||||
d:DesignWidth="550"
|
||||
s:View.ActionTarget="{Binding}"
|
||||
mc:Ignorable="d">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
@@ -14,7 +14,7 @@
|
||||
using System.Windows;
|
||||
using MaaWpfGui.Helper;
|
||||
|
||||
namespace MaaWpfGui.Views.UserControl
|
||||
namespace MaaWpfGui.Views.UserControl.Settings
|
||||
{
|
||||
/// <summary>
|
||||
/// ConnectSettingsUserControl.xaml 的交互逻辑
|
||||
@@ -37,7 +37,7 @@ namespace MaaWpfGui.Views.UserControl
|
||||
}
|
||||
|
||||
// Note that you can have more than one file.
|
||||
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
||||
var files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
||||
Instances.SettingsViewModel.StartsWithScript = files?[0] ?? string.Empty;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace MaaWpfGui.Views.UserControl
|
||||
}
|
||||
|
||||
// Note that you can have more than one file.
|
||||
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
||||
var files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
||||
Instances.SettingsViewModel.EndsWithScript = files?[0] ?? string.Empty;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user