mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-15 17:30:27 +08:00
feat. 自动战斗初版UI
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -140,6 +140,7 @@
|
||||
</Compile>
|
||||
<Compile Include="ViewModels\RecruitViewModel.cs" />
|
||||
<Compile Include="ViewModels\RootViewModel.cs" />
|
||||
<Compile Include="ViewModels\CopilotViewModel.cs" />
|
||||
<Compile Include="ViewModels\SettingsViewModel.cs" />
|
||||
<Compile Include="ViewModels\TaskQueueViewModel.cs" />
|
||||
<Compile Include="ViewModels\VersionUpdateViewModel.cs" />
|
||||
@@ -191,6 +192,10 @@
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\CopilotView.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Include="Views\SettingsView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
|
||||
113
src/MeoAsstGui/ViewModels/CopilotViewModel.cs
Normal file
113
src/MeoAsstGui/ViewModels/CopilotViewModel.cs
Normal file
@@ -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<AsstProxy>();
|
||||
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>();
|
||||
asstProxy.AsstStop();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,7 +152,6 @@ namespace MeoAsstGui
|
||||
}
|
||||
|
||||
asstProxy.AsstStartRecruitCalc(levelList.ToArray(), levelList.Count, AutoSetTime);
|
||||
asstProxy.AsstStart();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,10 +51,12 @@ namespace MeoAsstGui
|
||||
var rvm = _container.Get<RecruitViewModel>();
|
||||
//var ivm = _container.Get<InfrastViewModel>();
|
||||
var svm = _container.Get<SettingsViewModel>();
|
||||
var cvm = _container.Get<CopilotViewModel>();
|
||||
|
||||
Items.Add(tvm);
|
||||
Items.Add(rvm);
|
||||
//Items.Add(ivm);
|
||||
Items.Add(cvm);
|
||||
Items.Add(svm);
|
||||
ActiveItem = tvm;
|
||||
}
|
||||
|
||||
31
src/MeoAsstGui/Views/CopilotView.xaml
Normal file
31
src/MeoAsstGui/Views/CopilotView.xaml
Normal file
@@ -0,0 +1,31 @@
|
||||
<UserControl x:Class="MeoAsstGui.CopilotView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:c="clr-namespace:CalcBinding;assembly=CalcBinding"
|
||||
xmlns:local="clr-namespace:MeoAsstGui"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="495" d:DesignWidth="800">
|
||||
<Grid Margin="20">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center" Orientation="Horizontal">
|
||||
<TextBlock Style="{StaticResource TextBlockDefault}" Block.TextAlignment="Center"
|
||||
Text="作业路径" Margin="10" />
|
||||
<TextBox Text="{Binding Filename}" Margin="10"
|
||||
Width="500" Height="30" InputMethod.IsInputMethodEnabled="False" />
|
||||
<Button Command="{s:Action SelectFile}" IsEnabled="{Binding Idle}" Content="选择作业" Width="120" Height="50" Margin="10" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center" Orientation="Horizontal">
|
||||
<CheckBox IsChecked="{Binding Form}" IsHitTestVisible="{Binding Idle}" Content="编队" Height="50" Margin="10" />
|
||||
<Button Command="{s:Action Start}" IsEnabled="{Binding Idle}" Content="开始" Width="120" Height="50" Margin="10" />
|
||||
<Button Command="{s:Action Stop}" Content="停止" Width="120" Height="50" Margin="10" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
Reference in New Issue
Block a user