// // 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; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Collections.Specialized; using System.Linq; using MaaWpfGui.Constants; using MaaWpfGui.Helper; using MaaWpfGui.Models; using MaaWpfGui.Utilities.ValueType; using MaaWpfGui.ViewModels.UI; using Microsoft.Win32; namespace MaaWpfGui.ViewModels.UserControl.TaskQueue; /// /// 基建任务 /// public class InfrastSettingsUserControlModel : TaskViewModel { static InfrastSettingsUserControlModel() { Instance = new(); } public static InfrastSettingsUserControlModel Instance { get; } /// /// Gets the visibility of task setting views. /// public static TaskSettingVisibilityInfo TaskSettingVisibilities => TaskSettingVisibilityInfo.Current; public void InitInfrast() { var facilityList = new[] { "Mfg", "Trade", "Control", "Power", "Reception", "Office", "Dorm", "Processing", "Training", }; var tempOrderList = new List(new DragItemViewModel[facilityList.Length]); var nonOrderList = new List(); for (int i = 0; i != facilityList.Length; ++i) { var facility = facilityList[i]; bool parsed = int.TryParse(ConfigurationHelper.GetFacilityOrder(facility, "-1"), out int order); DragItemViewModel vm = new DragItemViewModel( LocalizationHelper.GetString(facility), facility, "Infrast."); if (!parsed || order < 0 || order >= tempOrderList.Count || tempOrderList[order] != null) { nonOrderList.Add(vm); } else { tempOrderList[order] = vm; } } foreach (var newVm in nonOrderList) { int i = 0; while (i < tempOrderList.Count && tempOrderList[i] != null) { ++i; } tempOrderList[i] = newVm; ConfigurationHelper.SetFacilityOrder(newVm.OriginalName, i.ToString()); } InfrastItemViewModels = new ObservableCollection(tempOrderList!); InfrastItemViewModels.CollectionChanged += InfrastOrderSelectionChanged; _dormThresholdLabel = LocalizationHelper.GetString("DormThreshold") + ": " + _dormThreshold + "%"; } /// /// Gets or sets the infrast item view models. /// public ObservableCollection InfrastItemViewModels { get; set; } = []; /// /// Gets the list of uses of drones. /// public List UsesOfDronesList { get; } = [ new() { Display = LocalizationHelper.GetString("DronesNotUse"), Value = "_NotUse" }, new() { Display = LocalizationHelper.GetString("Money"), Value = "Money" }, new() { Display = LocalizationHelper.GetString("SyntheticJade"), Value = "SyntheticJade" }, new() { Display = LocalizationHelper.GetString("CombatRecord"), Value = "CombatRecord" }, new() { Display = LocalizationHelper.GetString("PureGold"), Value = "PureGold" }, new() { Display = LocalizationHelper.GetString("OriginStone"), Value = "OriginStone" }, new() { Display = LocalizationHelper.GetString("Chip"), Value = "Chip" }, ]; /// /// Gets the list of uses of default infrast. /// public List DefaultInfrastList { get; } = [ new() { Display = LocalizationHelper.GetString("UserDefined"), Value = UserDefined }, new() { Display = LocalizationHelper.GetString("153Time3"), Value = "153_layout_3_times_a_day.json" }, new() { Display = LocalizationHelper.GetString("153Time4"), Value = "153_layout_4_times_a_day.json" }, new() { Display = LocalizationHelper.GetString("243Time3"), Value = "243_layout_3_times_a_day.json" }, new() { Display = LocalizationHelper.GetString("243Time4"), Value = "243_layout_4_times_a_day.json" }, new() { Display = LocalizationHelper.GetString("333Time3"), Value = "333_layout_for_Orundum_3_times_a_day.json" }, ]; private int _dormThreshold = Convert.ToInt32(ConfigurationHelper.GetValue(ConfigurationKeys.DormThreshold, "30")); /// /// Gets or sets the threshold to enter dormitory. /// public int DormThreshold { get => _dormThreshold; set { SetAndNotify(ref _dormThreshold, value); DormThresholdLabel = LocalizationHelper.GetString("DormThreshold") + ": " + _dormThreshold + "%"; ConfigurationHelper.SetValue(ConfigurationKeys.DormThreshold, value.ToString()); } } private string _dormThresholdLabel = string.Empty; /// /// Gets or sets the label of dormitory threshold. /// public string DormThresholdLabel { get => _dormThresholdLabel; set => SetAndNotify(ref _dormThresholdLabel, value); } /// /// Gets infrast order list. /// /// The infrast order list. public List GetInfrastOrderList() { return (from item in InfrastItemViewModels where item.IsChecked select item.OriginalName).ToList(); } // UI 绑定的方法 // ReSharper disable once UnusedMember.Global public void InfrastItemSelectedAll() { foreach (var item in InfrastItemViewModels) { item.IsChecked = true; } } // UI 绑定的方法 // ReSharper disable once UnusedMember.Global public void InfrastItemUnselectedAll() { foreach (var item in InfrastItemViewModels) { item.IsChecked = false; } } /// /// 实时更新基建换班顺序 /// /// ignored object /// ignored NotifyCollectionChangedEventArgs public void InfrastOrderSelectionChanged(object? sender = null, NotifyCollectionChangedEventArgs? e = null) { _ = (sender, e); int index = 0; foreach (var item in InfrastItemViewModels) { ConfigurationHelper.SetFacilityOrder(item.OriginalName, index.ToString()); ++index; } } private string _usesOfDrones = ConfigurationHelper.GetValue(ConfigurationKeys.UsesOfDrones, "Money"); /// /// Gets or sets the uses of drones. /// public string UsesOfDrones { get => _usesOfDrones; set { SetAndNotify(ref _usesOfDrones, value); ConfigurationHelper.SetValue(ConfigurationKeys.UsesOfDrones, value); } } private bool _continueTraining = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.ContinueTraining, bool.FalseString)); /// /// Gets or sets a value indicating whether to continue training after current training completed. /// public bool ContinueTraining { get => _continueTraining; set { SetAndNotify(ref _continueTraining, value); ConfigurationHelper.SetValue(ConfigurationKeys.ContinueTraining, value.ToString()); } } private string _defaultInfrast = ConfigurationHelper.GetValue(ConfigurationKeys.DefaultInfrast, UserDefined); private const string UserDefined = "user_defined"; /// /// Gets or sets the uses of drones. /// public string DefaultInfrast { get => _defaultInfrast; set { SetAndNotify(ref _defaultInfrast, value); if (_defaultInfrast != UserDefined) { CustomInfrastFile = @"resource\custom_infrast\" + value; IsCustomInfrastFileReadOnly = true; } else { IsCustomInfrastFileReadOnly = false; } ConfigurationHelper.SetValue(ConfigurationKeys.DefaultInfrast, value); } } private bool _isCustomInfrastFileReadOnly = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.IsCustomInfrastFileReadOnly, bool.FalseString)); /// /// Gets or sets a value indicating whether CustomInfrastFile is read-only /// public bool IsCustomInfrastFileReadOnly { get => _isCustomInfrastFileReadOnly; set { SetAndNotify(ref _isCustomInfrastFileReadOnly, value); ConfigurationHelper.SetValue(ConfigurationKeys.IsCustomInfrastFileReadOnly, value.ToString()); } } private bool _dormFilterNotStationedEnabled = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.DormFilterNotStationedEnabled, bool.TrueString)); /// /// Gets or sets a value indicating whether the not stationed filter in dorm is enabled. /// public bool DormFilterNotStationedEnabled { get => _dormFilterNotStationedEnabled; set { SetAndNotify(ref _dormFilterNotStationedEnabled, value); ConfigurationHelper.SetValue(ConfigurationKeys.DormFilterNotStationedEnabled, value.ToString()); } } private bool _dormTrustEnabled = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.DormTrustEnabled, bool.FalseString)); /// /// Gets or sets a value indicating whether trust in dorm is enabled. /// public bool DormTrustEnabled { get => _dormTrustEnabled; set { SetAndNotify(ref _dormTrustEnabled, value); ConfigurationHelper.SetValue(ConfigurationKeys.DormTrustEnabled, value.ToString()); } } private bool _originiumShardAutoReplenishment = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.OriginiumShardAutoReplenishment, bool.TrueString)); /// /// Gets or sets a value indicating whether Originium shard auto replenishment is enabled. /// public bool OriginiumShardAutoReplenishment { get => _originiumShardAutoReplenishment; set { SetAndNotify(ref _originiumShardAutoReplenishment, value); ConfigurationHelper.SetValue(ConfigurationKeys.OriginiumShardAutoReplenishment, value.ToString()); } } private bool _customInfrastEnabled = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.CustomInfrastEnabled, bool.FalseString)); public bool CustomInfrastEnabled { get => _customInfrastEnabled; set { SetAndNotify(ref _customInfrastEnabled, value); ConfigurationHelper.SetValue(ConfigurationKeys.CustomInfrastEnabled, value.ToString()); Instances.TaskQueueViewModel.RefreshCustomInfrastPlan(); } } /// /// Selects infrast config file. /// // UI 绑定的方法 // ReSharper disable once UnusedMember.Global public void SelectCustomInfrastFile() { var dialog = new OpenFileDialog { Filter = LocalizationHelper.GetString("CustomInfrastFile") + "|*.json", }; if (dialog.ShowDialog() == true) { CustomInfrastFile = dialog.FileName; } DefaultInfrast = UserDefined; } private string _customInfrastFile = ConfigurationHelper.GetValue(ConfigurationKeys.CustomInfrastFile, string.Empty); public string CustomInfrastFile { get => _customInfrastFile; set { SetAndNotify(ref _customInfrastFile, value); ConfigurationHelper.SetValue(ConfigurationKeys.CustomInfrastFile, value); Instances.TaskQueueViewModel.RefreshCustomInfrastPlan(); // SetAndNotify 在值没有变化时不会触发 PropertyChanged 事件,所以这里手动触发一下 Instances.TaskQueueViewModel.NeedAddCustomInfrastPlanInfo = false; { Instances.TaskQueueViewModel.CustomInfrastPlanIndex--; Instances.TaskQueueViewModel.CustomInfrastPlanIndex++; } Instances.TaskQueueViewModel.NeedAddCustomInfrastPlanInfo = true; } } }