From f2dfcf3e727c3e7dec15ad873080f09fd0a5d58f Mon Sep 17 00:00:00 2001 From: MistEO Date: Thu, 19 May 2022 00:29:33 +0800 Subject: [PATCH] =?UTF-8?q?feat.=20=E8=87=AA=E5=8A=A8=E6=88=98=E6=96=97?= =?UTF-8?q?=E5=88=9D=E7=89=88UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MeoAsstGui/Helper/AsstProxy.cs | 11 +- src/MeoAsstGui/MeoAsstGui.csproj | 5 + src/MeoAsstGui/ViewModels/CopilotViewModel.cs | 113 ++++++++++++++++++ src/MeoAsstGui/ViewModels/RecruitViewModel.cs | 1 - src/MeoAsstGui/ViewModels/RootViewModel.cs | 2 + src/MeoAsstGui/Views/CopilotView.xaml | 31 +++++ 6 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 src/MeoAsstGui/ViewModels/CopilotViewModel.cs create mode 100644 src/MeoAsstGui/Views/CopilotView.xaml diff --git a/src/MeoAsstGui/Helper/AsstProxy.cs b/src/MeoAsstGui/Helper/AsstProxy.cs index 46e37ff562..7953a724c6 100644 --- a/src/MeoAsstGui/Helper/AsstProxy.cs +++ b/src/MeoAsstGui/Helper/AsstProxy.cs @@ -662,7 +662,16 @@ namespace MeoAsstGui task_params["set_time"] = true; task_params["expedite"] = false; task_params["expedite_times"] = 0; - return AsstAppendTaskWithEncoding("Recruit", task_params); + return AsstAppendTaskWithEncoding("Recruit", task_params) && AsstStart(); + } + + public bool AsstStartCopilot(string stage_name, string filename, bool formation) + { + var task_params = new JObject(); + task_params["stage_name"] = stage_name; + task_params["filename"] = filename; + task_params["formation"] = formation; + return AsstAppendTaskWithEncoding("Copilot", task_params) && AsstStart(); } public bool AsstStart() diff --git a/src/MeoAsstGui/MeoAsstGui.csproj b/src/MeoAsstGui/MeoAsstGui.csproj index 6507455599..fe9581f252 100644 --- a/src/MeoAsstGui/MeoAsstGui.csproj +++ b/src/MeoAsstGui/MeoAsstGui.csproj @@ -140,6 +140,7 @@ + @@ -191,6 +192,10 @@ Designer MSBuild:Compile + + MSBuild:Compile + Designer + Designer MSBuild:Compile diff --git a/src/MeoAsstGui/ViewModels/CopilotViewModel.cs b/src/MeoAsstGui/ViewModels/CopilotViewModel.cs new file mode 100644 index 0000000000..3a72e029db --- /dev/null +++ b/src/MeoAsstGui/ViewModels/CopilotViewModel.cs @@ -0,0 +1,113 @@ +// MeoAsstGui - A part of the MeoAssistantArknights 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 General Public License 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 + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using System.Threading.Tasks; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Notification.Wpf.Constants; +using Notification.Wpf.Controls; +using Stylet; +using StyletIoC; + +namespace MeoAsstGui +{ + public class CopilotViewModel : Screen + { + private readonly IWindowManager _windowManager; + private readonly IContainer _container; + + public CopilotViewModel(IContainer container, IWindowManager windowManager) + { + _container = container; + _windowManager = windowManager; + DisplayName = "自动战斗"; + } + + private string _filename; + + public string Filename + { + get => _filename; + set => SetAndNotify(ref _filename, value); + } + + public void SelectFile() + { + var dialog = new Microsoft.Win32.OpenFileDialog(); + + dialog.Filter = "作业文件|*.json"; + + if (dialog.ShowDialog() == true) + { + Filename = dialog.FileName; + } + } + + private bool _form = true; + + public bool Form + { + get => _form; + set => SetAndNotify(ref _form, value); + } + + private bool _catched = false; + + public async void Start() + { + var asstProxy = _container.Get(); + if (!_catched) + { + var task = Task.Run(() => + { + return asstProxy.AsstConnect(); + }); + _catched = await task; + } + if (!_catched) + { + return; + } + if (Filename.Length == 0 || !File.Exists(Filename)) + { + return; + } + + JObject data; + + try + { + string jsonStr = File.ReadAllText(Filename); + + // 文件存在但为空,会读出来一个null,感觉c#这库有bug,如果是null 就赋值一个空JObject + data = (JObject)JsonConvert.DeserializeObject(jsonStr) ?? new JObject(); + } + catch (Exception) + { + return; + } + + asstProxy.AsstStartCopilot(data["stage_name"].ToString(), Filename, Form); + } + + public void Stop() + { + var asstProxy = _container.Get(); + asstProxy.AsstStop(); + } + } +} diff --git a/src/MeoAsstGui/ViewModels/RecruitViewModel.cs b/src/MeoAsstGui/ViewModels/RecruitViewModel.cs index 3d2c33f5b0..b9dcb85399 100644 --- a/src/MeoAsstGui/ViewModels/RecruitViewModel.cs +++ b/src/MeoAsstGui/ViewModels/RecruitViewModel.cs @@ -152,7 +152,6 @@ namespace MeoAsstGui } asstProxy.AsstStartRecruitCalc(levelList.ToArray(), levelList.Count, AutoSetTime); - asstProxy.AsstStart(); } } } diff --git a/src/MeoAsstGui/ViewModels/RootViewModel.cs b/src/MeoAsstGui/ViewModels/RootViewModel.cs index ecabc4abc6..f087096616 100644 --- a/src/MeoAsstGui/ViewModels/RootViewModel.cs +++ b/src/MeoAsstGui/ViewModels/RootViewModel.cs @@ -51,10 +51,12 @@ namespace MeoAsstGui var rvm = _container.Get(); //var ivm = _container.Get(); var svm = _container.Get(); + var cvm = _container.Get(); Items.Add(tvm); Items.Add(rvm); //Items.Add(ivm); + Items.Add(cvm); Items.Add(svm); ActiveItem = tvm; } diff --git a/src/MeoAsstGui/Views/CopilotView.xaml b/src/MeoAsstGui/Views/CopilotView.xaml new file mode 100644 index 0000000000..08cf4918f2 --- /dev/null +++ b/src/MeoAsstGui/Views/CopilotView.xaml @@ -0,0 +1,31 @@ + + + + + + + + + + +