mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-19 10:32:19 +08:00
215 lines
6.7 KiB
C#
215 lines
6.7 KiB
C#
// <copyright file="RecruitViewModel.cs" company="MaaAssistantArknights">
|
|
// 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 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
|
|
// </copyright>
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using MaaWpfGui.Constants;
|
|
using MaaWpfGui.Helper;
|
|
using MaaWpfGui.Main;
|
|
using Stylet;
|
|
using StyletIoC;
|
|
|
|
namespace MaaWpfGui.ViewModels.UI
|
|
{
|
|
/// <summary>
|
|
/// The view model of recruit.
|
|
/// </summary>
|
|
public class RecruitViewModel : Screen
|
|
{
|
|
private readonly IWindowManager _windowManager;
|
|
private readonly IContainer _container;
|
|
|
|
private AsstProxy _asstProxy;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="RecruitViewModel"/> class.
|
|
/// </summary>
|
|
/// <param name="container">The IoC container.</param>
|
|
/// <param name="windowManager">The window manager.</param>
|
|
public RecruitViewModel(IContainer container, IWindowManager windowManager)
|
|
{
|
|
_container = container;
|
|
_windowManager = windowManager;
|
|
DisplayName = LocalizationHelper.GetString("RecruitmentRecognition");
|
|
}
|
|
|
|
protected override void OnInitialActivate()
|
|
{
|
|
base.OnInitialActivate();
|
|
_asstProxy = _container.Get<AsstProxy>();
|
|
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
|
|
{
|
|
App.SetAllControlColors(Application.Current.MainWindow);
|
|
}));
|
|
}
|
|
|
|
private string _recruitInfo = LocalizationHelper.GetString("RecruitmentRecognitionTip");
|
|
|
|
/// <summary>
|
|
/// Gets or sets the recruit info.
|
|
/// </summary>
|
|
public string RecruitInfo
|
|
{
|
|
get => _recruitInfo;
|
|
set => SetAndNotify(ref _recruitInfo, value);
|
|
}
|
|
|
|
private string _recruitResult;
|
|
|
|
/// <summary>
|
|
/// Gets or sets the recruit result.
|
|
/// </summary>
|
|
public string RecruitResult
|
|
{
|
|
get => _recruitResult;
|
|
set => SetAndNotify(ref _recruitResult, value);
|
|
}
|
|
|
|
private bool _chooseLevel3 = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.ChooseLevel3, bool.FalseString));
|
|
|
|
/// <summary>
|
|
/// Gets or sets a value indicating whether to choose level 3.
|
|
/// </summary>
|
|
public bool ChooseLevel3
|
|
{
|
|
get => _chooseLevel3;
|
|
set
|
|
{
|
|
SetAndNotify(ref _chooseLevel3, value);
|
|
ConfigurationHelper.SetValue(ConfigurationKeys.ChooseLevel3, value.ToString());
|
|
}
|
|
}
|
|
|
|
private bool _chooseLevel4 = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.ChooseLevel4, bool.TrueString));
|
|
|
|
/// <summary>
|
|
/// Gets or sets a value indicating whether to choose level 4.
|
|
/// </summary>
|
|
public bool ChooseLevel4
|
|
{
|
|
get => _chooseLevel4;
|
|
set
|
|
{
|
|
SetAndNotify(ref _chooseLevel4, value);
|
|
ConfigurationHelper.SetValue(ConfigurationKeys.ChooseLevel4, value.ToString());
|
|
}
|
|
}
|
|
|
|
private bool _chooseLevel5 = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.ChooseLevel5, bool.TrueString));
|
|
|
|
/// <summary>
|
|
/// Gets or sets a value indicating whether to choose level 5.
|
|
/// </summary>
|
|
public bool ChooseLevel5
|
|
{
|
|
get => _chooseLevel5;
|
|
set
|
|
{
|
|
SetAndNotify(ref _chooseLevel5, value);
|
|
ConfigurationHelper.SetValue(ConfigurationKeys.ChooseLevel5, value.ToString());
|
|
}
|
|
}
|
|
|
|
private bool _chooseLevel6 = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.ChooseLevel6, bool.TrueString));
|
|
|
|
/// <summary>
|
|
/// Gets or sets a value indicating whether to choose level 6.
|
|
/// </summary>
|
|
public bool ChooseLevel6
|
|
{
|
|
get => _chooseLevel6;
|
|
set
|
|
{
|
|
SetAndNotify(ref _chooseLevel6, value);
|
|
ConfigurationHelper.SetValue(ConfigurationKeys.ChooseLevel6, value.ToString());
|
|
}
|
|
}
|
|
|
|
private bool _autoSetTime = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.AutoSetTime, bool.TrueString));
|
|
|
|
/// <summary>
|
|
/// Gets or sets a value indicating whether to set time automatically.
|
|
/// </summary>
|
|
public bool AutoSetTime
|
|
{
|
|
get => _autoSetTime;
|
|
set
|
|
{
|
|
SetAndNotify(ref _autoSetTime, value);
|
|
ConfigurationHelper.SetValue(ConfigurationKeys.AutoSetTime, value.ToString());
|
|
}
|
|
}
|
|
|
|
private bool _isLevel3UseShortTime = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.Level3UseShortTime, bool.FalseString));
|
|
|
|
/// <summary>
|
|
/// Gets or sets a value indicating whether to shorten the time for level 3.
|
|
/// </summary>
|
|
public bool IsLevel3UseShortTime
|
|
{
|
|
get => _isLevel3UseShortTime;
|
|
set
|
|
{
|
|
SetAndNotify(ref _isLevel3UseShortTime, value);
|
|
ConfigurationHelper.SetValue(ConfigurationKeys.Level3UseShortTime, value.ToString());
|
|
}
|
|
}
|
|
|
|
private bool _caught = false;
|
|
|
|
/// <summary>
|
|
/// Starts calculation.
|
|
/// </summary>
|
|
public async void StartCalc()
|
|
{
|
|
string errMsg = string.Empty;
|
|
RecruitInfo = LocalizationHelper.GetString("ConnectingToEmulator");
|
|
_caught = await Task.Run(() => _asstProxy.AsstConnect(ref errMsg));
|
|
if (!_caught)
|
|
{
|
|
RecruitInfo = errMsg;
|
|
return;
|
|
}
|
|
|
|
RecruitInfo = LocalizationHelper.GetString("Identifying");
|
|
RecruitResult = string.Empty;
|
|
|
|
var levelList = new List<int>();
|
|
|
|
if (ChooseLevel3)
|
|
{
|
|
levelList.Add(3);
|
|
}
|
|
|
|
if (ChooseLevel4)
|
|
{
|
|
levelList.Add(4);
|
|
}
|
|
|
|
if (ChooseLevel5)
|
|
{
|
|
levelList.Add(5);
|
|
}
|
|
|
|
if (ChooseLevel6)
|
|
{
|
|
levelList.Add(6);
|
|
}
|
|
|
|
_asstProxy.AsstStartRecruitCalc(levelList.ToArray(), AutoSetTime);
|
|
}
|
|
}
|
|
}
|