// // 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.Diagnostics; using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using System.Windows; using MeoAsstGui.MaaHotKeys; using Stylet; using StyletIoC; namespace MeoAsstGui { /// /// The view model of settings. /// public class SettingsViewModel : Screen { private readonly IWindowManager _windowManager; private readonly IContainer _container; private readonly IMaaHotKeyManager _maaHotKeyManager; [DllImport("MeoAssistant.dll")] private static extern IntPtr AsstGetVersion(); private static readonly string s_versionId = Marshal.PtrToStringAnsi(AsstGetVersion()); /// /// Gets the version id. /// public string VersionId => s_versionId; private static readonly string s_versionInfo = Localization.GetString("Version") + ": " + s_versionId; /// /// Gets the version info. /// public string VersionInfo => s_versionInfo; /// /// The Pallas language key. /// public static readonly string PallasLangKey = "pallas"; /// /// Initializes a new instance of the class. /// /// The IoC container. /// The window manager. public SettingsViewModel(IContainer container, IWindowManager windowManager) { _container = container; _windowManager = windowManager; _maaHotKeyManager = _container.Get(); DisplayName = Localization.GetString("Settings"); _listTitle.Add(Localization.GetString("BaseSettings")); _listTitle.Add(Localization.GetString("RoguelikeSettings")); _listTitle.Add(Localization.GetString("RecruitingSettings")); _listTitle.Add(Localization.GetString("MallSettings")); _listTitle.Add(Localization.GetString("OtherCombatSettings")); _listTitle.Add(Localization.GetString("ConnectionSettings")); _listTitle.Add(Localization.GetString("StartupSettings")); _listTitle.Add(Localization.GetString("ScheduleSettings")); _listTitle.Add(Localization.GetString("UISettings")); _listTitle.Add(Localization.GetString("HotKeySettings")); _listTitle.Add(Localization.GetString("UpdateSettings")); _listTitle.Add(Localization.GetString("AboutUs")); InfrastInit(); var trayObj = _container.Get(); var mainWindowManager = _container.Get(); trayObj.SetVisible(UseTray); trayObj.SetSettingsViewModel(this); mainWindowManager.SetMinimizeToTaskbar(MinimizeToTray); Bootstrapper.SetTrayIconInSettingsViewModel(this); if (Hangover) { _windowManager.ShowMessageBox( Localization.GetString("Hangover"), Localization.GetString("Burping"), MessageBoxButton.OK, MessageBoxImage.Hand); Hangover = false; } } private List _listTitle = new List(); /// /// Gets or sets the list title. /// public List ListTitle { get => _listTitle; set => SetAndNotify(ref _listTitle, value); } private void InfrastInit() { /* 基建设置 */ var facility_list = new string[] { "Mfg", "Trade", "Control", "Power", "Reception", "Office", "Dorm", }; var temp_order_list = new List(new DragItemViewModel[facility_list.Length]); for (int i = 0; i != facility_list.Length; ++i) { var facility = facility_list[i]; bool parsed = int.TryParse(ViewStatusStorage.Get("Infrast.Order." + facility, "-1"), out int order); if (!parsed || order < 0) { temp_order_list[i] = new DragItemViewModel(Localization.GetString(facility), facility, "Infrast."); } else { temp_order_list[order] = new DragItemViewModel(Localization.GetString(facility), facility, "Infrast."); } } InfrastItemViewModels = new ObservableCollection(temp_order_list); DefaultInfrastList = new List { new CombData { Display = Localization.GetString("UserDefined"), Value = _userDefined }, new CombData { Display = Localization.GetString("153_3"), Value = "153_layout_3_times_a_day.json" }, new CombData { Display = Localization.GetString("243_3"), Value = "243_layout_3_times_a_day.json" }, new CombData { Display = Localization.GetString("243_4"), Value = "243_layout_4_times_a_day.json" }, new CombData { Display = Localization.GetString("252_3"), Value = "252_layout_3_times_a_day.json" }, new CombData { Display = Localization.GetString("333_3"), Value = "333_layout_for_Orundum_3_times_a_day.json" }, }; UsesOfDronesList = new List { new CombData { Display = Localization.GetString("DronesNotUse"), Value = "_NotUse" }, new CombData { Display = Localization.GetString("Money"), Value = "Money" }, new CombData { Display = Localization.GetString("SyntheticJade"), Value = "SyntheticJade" }, new CombData { Display = Localization.GetString("CombatRecord"), Value = "CombatRecord" }, new CombData { Display = Localization.GetString("PureGold"), Value = "PureGold" }, new CombData { Display = Localization.GetString("OriginStone"), Value = "OriginStone" }, new CombData { Display = Localization.GetString("Chip"), Value = "Chip" }, }; ConnectConfigList = new List { new CombData { Display = Localization.GetString("General"), Value = "General" }, new CombData { Display = Localization.GetString("BlueStacks"), Value = "BlueStacks" }, new CombData { Display = Localization.GetString("MuMuEmulator"), Value = "MuMuEmulator" }, new CombData { Display = Localization.GetString("LDPlayer"), Value = "LDPlayer" }, new CombData { Display = Localization.GetString("Nox"), Value = "Nox" }, new CombData { Display = Localization.GetString("XYAZ"), Value = "XYAZ" }, new CombData { Display = Localization.GetString("WSA"), Value = "WSA" }, new CombData { Display = Localization.GetString("Compatible"), Value = "Compatible" }, }; _dormThresholdLabel = Localization.GetString("DormThreshold") + ": " + _dormThreshold + "%"; RoguelikeModeList = new List { new CombData { Display = Localization.GetString("RoguelikeStrategyExp"), Value = "0" }, new CombData { Display = Localization.GetString("RoguelikeStrategyGold"), Value = "1" }, // new CombData { Display = "两者兼顾,投资过后退出", Value = "2" } // 弃用 // new CombData { Display = Localization.GetString("3"), Value = "3" }, // 开发中 }; RoguelikeThemeList = new List { new CombData { Display = Localization.GetString("RoguelikeThemePhantom"), Value = "Phantom" }, new CombData { Display = Localization.GetString("RoguelikeThemeMizuki"), Value = "Mizuki" }, }; RoguelikeSquadList = new List { new CombData { Display = Localization.GetString("DefaultSquad"), Value = string.Empty }, new CombData { Display = Localization.GetString("IS2NewSquad1"), Value = "心胜于物分队" }, new CombData { Display = Localization.GetString("IS2NewSquad2"), Value = "物尽其用分队" }, new CombData { Display = Localization.GetString("IS2NewSquad3"), Value = "以人为本分队" }, new CombData { Display = Localization.GetString("LeaderSquad"), Value = "指挥分队" }, new CombData { Display = Localization.GetString("GatheringSquad"), Value = "集群分队" }, new CombData { Display = Localization.GetString("SupportSquad"), Value = "后勤分队" }, new CombData { Display = Localization.GetString("SpearheadSquad"), Value = "矛头分队" }, new CombData { Display = Localization.GetString("TacticalAssaultOperative"), Value = "突击战术分队" }, new CombData { Display = Localization.GetString("TacticalFortificationOperative"), Value = "堡垒战术分队" }, new CombData { Display = Localization.GetString("TacticalRangedOperative"), Value = "远程战术分队" }, new CombData { Display = Localization.GetString("TacticalDestructionOperative"), Value = "破坏战术分队" }, new CombData { Display = Localization.GetString("ResearchSquad"), Value = "研究分队" }, new CombData { Display = Localization.GetString("First-ClassSquad"), Value = "高规格分队" }, }; RoguelikeRolesList = new List { new CombData { Display = Localization.GetString("DefaultRoles"), Value = string.Empty }, new CombData { Display = Localization.GetString("FirstMoveAdvantage"), Value = "先手必胜" }, new CombData { Display = Localization.GetString("SlowAndSteadyWinsTheRace"), Value = "稳扎稳打" }, new CombData { Display = Localization.GetString("OvercomingYourWeaknesses"), Value = "取长补短" }, new CombData { Display = Localization.GetString("AsYourHeartDesires"), Value = "随心所欲" }, }; ClientTypeList = new List { new CombData { Display = Localization.GetString("NotSelected"), Value = string.Empty }, new CombData { Display = Localization.GetString("Official"), Value = "Official" }, new CombData { Display = Localization.GetString("Bilibili"), Value = "Bilibili" }, new CombData { Display = Localization.GetString("YoStarEN"), Value = "YoStarEN" }, new CombData { Display = Localization.GetString("YoStarJP"), Value = "YoStarJP" }, new CombData { Display = Localization.GetString("YoStarKR"), Value = "YoStarKR" }, new CombData { Display = Localization.GetString("txwy"), Value = "txwy" }, }; InverseClearModeList = new List { new CombData { Display = Localization.GetString("Clear"), Value = "Clear" }, new CombData { Display = Localization.GetString("Inverse"), Value = "Inverse" }, new CombData { Display = Localization.GetString("Switchable"), Value = "ClearInverse" }, }; VersionTypeList = new List> { new GenericCombData { Display = Localization.GetString("UpdateCheckNightly"), Value = UpdateVersionType.Nightly }, new GenericCombData { Display = Localization.GetString("UpdateCheckBeta"), Value = UpdateVersionType.Beta }, new GenericCombData { Display = Localization.GetString("UpdateCheckStable"), Value = UpdateVersionType.Stable }, }; LanguageList = new List(); foreach (var pair in Localization.SupportedLanguages) { if (pair.Key == PallasLangKey && !Cheers) { continue; } LanguageList.Add(new CombData { Display = pair.Value, Value = pair.Key }); } } private bool _idle = true; /// /// Gets or sets a value indicating whether it is idle. /// public bool Idle { get => _idle; set => SetAndNotify(ref _idle, value); } /* 启动设置 */ private bool _startSelf = StartSelfModel.CheckStart(); /// /// Gets or sets a value indicating whether to start itself. /// public bool StartSelf { get => _startSelf; set { SetAndNotify(ref _startSelf, value); StartSelfModel.SetStart(value); } } private bool _runDirectly = Convert.ToBoolean(ViewStatusStorage.Get("Start.RunDirectly", bool.FalseString)); /// /// Gets or sets a value indicating whether to run directly. /// public bool RunDirectly { get => _runDirectly; set { SetAndNotify(ref _runDirectly, value); ViewStatusStorage.Set("Start.RunDirectly", value.ToString()); } } private bool _startEmulator = Convert.ToBoolean(ViewStatusStorage.Get("Start.StartEmulator", bool.FalseString)); /// /// Gets or sets a value indicating whether to start emulator. /// public bool StartEmulator { get => _startEmulator; set { SetAndNotify(ref _startEmulator, value); ViewStatusStorage.Set("Start.StartEmulator", value.ToString()); if (ClientType == string.Empty && Idle) { ClientType = "Official"; } } } private string _emulatorPath = ViewStatusStorage.Get("Start.EmulatorPath", string.Empty); /// /// Gets or sets the emulator path. /// public string EmulatorPath { get => _emulatorPath; set { SetAndNotify(ref _emulatorPath, value); ViewStatusStorage.Set("Start.EmulatorPath", value); } } private string _emulatorAddCommand = ViewStatusStorage.Get("Start.EmulatorAddCommand", string.Empty); /// /// Gets or sets the command to append after the emulator command. /// public string EmulatorAddCommand { get => _emulatorAddCommand; set { SetAndNotify(ref _emulatorAddCommand, value); ViewStatusStorage.Set("Start.EmulatorAddCommand", value); } } private string _emulatorWaitSeconds = ViewStatusStorage.Get("Start.EmulatorWaitSeconds", "60"); /// /// Gets or sets the seconds to wait for the emulator. /// public string EmulatorWaitSeconds { get => _emulatorWaitSeconds; set { SetAndNotify(ref _emulatorWaitSeconds, value); ViewStatusStorage.Set("Start.EmulatorWaitSeconds", value); } } /// /// Tries to start the emulator. /// /// Whether to start manually. public void TryToStartEmulator(bool manual = false) { if ((EmulatorPath.Length == 0 || !File.Exists(EmulatorPath)) || !(StartEmulator || manual)) { return; } if (EmulatorAddCommand.Length != 0) { Process.Start(EmulatorPath, EmulatorAddCommand); } else { Process.Start(EmulatorPath); } if (!int.TryParse(EmulatorWaitSeconds, out int delay)) { delay = 60; } Thread.Sleep(delay * 1000); } /// /// Selects the emulator to execute. /// public void SelectEmulatorExec() { var dialog = new Microsoft.Win32.OpenFileDialog { Filter = Localization.GetString("Executable") + "|*.exe;*.bat;*.lnk", }; if (dialog.ShowDialog() == true) { EmulatorPath = dialog.FileName; } } private string _clientType = ViewStatusStorage.Get("Start.ClientType", string.Empty); /// /// Gets or sets the client type. /// public string ClientType { get => _clientType; set { SetAndNotify(ref _clientType, value); ViewStatusStorage.Set("Start.ClientType", value); } } /// /// Gets the client type. /// public string ClientName { get { foreach (var item in ClientTypeList) { if (item.Value == ClientType) { return item.Display; } } return "Unknown Client"; } } private readonly Dictionary _serverMapping = new Dictionary { { string.Empty, "CN" }, { "Official", "CN" }, { "Bilibili", "CN" }, { "YoStarEN", "US" }, { "YoStarJP", "JP" }, { "YoStarKR", "KR" }, { "txwy", "ZH_TW" }, }; /// /// Gets the server type. /// public string ServerType => _serverMapping[ClientType]; /* 基建设置 */ /// /// Gets or sets the infrast item view models. /// public ObservableCollection InfrastItemViewModels { get; set; } /// /// Gets or sets the list of uses of drones. /// public List UsesOfDronesList { get; set; } /// /// Gets or sets the list of uses of default infrast. /// public List DefaultInfrastList { get; set; } /// /// Gets or sets the list of roguelike lists. /// public List RoguelikeThemeList { get; set; } /// /// Gets or sets the list of roguelike modes. /// public List RoguelikeModeList { get; set; } /// /// Gets or sets the list of roguelike squad. /// public List RoguelikeSquadList { get; set; } /// /// Gets or sets the list of roguelike roles. /// public List RoguelikeRolesList { get; set; } // public List RoguelikeCoreCharList { get; set; } /// /// Gets or sets the list of the client types. /// public List ClientTypeList { get; set; } /// /// Gets or sets the list of the configuration of connection. /// public List ConnectConfigList { get; set; } /// /// Gets or sets the list of inverse clear modes. /// public List InverseClearModeList { get; set; } /// /// Gets or sets the list of the version type. /// public List> VersionTypeList { get; set; } /// /// Gets or sets the language list. /// public List LanguageList { get; set; } private int _dormThreshold = Convert.ToInt32(ViewStatusStorage.Get("Infrast.DormThreshold", "30")); /// /// Gets or sets the threshold to enter dormitory. /// public int DormThreshold { get => _dormThreshold; set { SetAndNotify(ref _dormThreshold, value); DormThresholdLabel = Localization.GetString("DormThreshold") + ": " + _dormThreshold + "%"; ViewStatusStorage.Set("Infrast.DormThreshold", value.ToString()); } } private string _dormThresholdLabel; /// /// 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() { var orderList = new List(); foreach (var item in InfrastItemViewModels) { if (item.IsChecked == false) { continue; } orderList.Add(item.OriginalName); } return orderList; } /// /// 实时更新基建换班顺序 /// public void InfrastOrderSelectionChanged() { int index = 0; foreach (var item in InfrastItemViewModels) { ViewStatusStorage.Set("Infrast.Order." + item.OriginalName, index.ToString()); ++index; } } private string _usesOfDrones = ViewStatusStorage.Get("Infrast.UsesOfDrones", "Money"); /// /// Gets or sets the uses of drones. /// public string UsesOfDrones { get => _usesOfDrones; set { SetAndNotify(ref _usesOfDrones, value); ViewStatusStorage.Set("Infrast.UsesOfDrones", value); } } private string _defaultInfrast = ViewStatusStorage.Get("Infrast.DefaultInfrast", _userDefined); private static readonly 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; } ViewStatusStorage.Set("Infrast.DefaultInfrast", value); } } private string _isCustomInfrastFileReadOnly = ViewStatusStorage.Get("Infrast.IsCustomInfrastFileReadOnly", false.ToString()); /// /// Gets or sets a value indicating whether CustomInfrastFile is read-only /// public bool IsCustomInfrastFileReadOnly { get => bool.Parse(_isCustomInfrastFileReadOnly); set { SetAndNotify(ref _isCustomInfrastFileReadOnly, value.ToString()); ViewStatusStorage.Set("Infrast.IsCustomInfrastFileReadOnly", value.ToString()); } } private string _dormFilterNotStationedEnabled = ViewStatusStorage.Get("Infrast.DormFilterNotStationedEnabled", false.ToString()); /// /// Gets or sets a value indicating whether the not stationed filter in dorm is enabled. /// public bool DormFilterNotStationedEnabled { get => bool.Parse(_dormFilterNotStationedEnabled); set { SetAndNotify(ref _dormFilterNotStationedEnabled, value.ToString()); ViewStatusStorage.Set("Infrast.DormFilterNotStationedEnabled", value.ToString()); } } private string _dormTrustEnabled = ViewStatusStorage.Get("Infrast.DormTrustEnabled", true.ToString()); /// /// Gets or sets a value indicating whether get trust in dorm is enabled. /// public bool DormTrustEnabled { get => bool.Parse(_dormTrustEnabled); set { SetAndNotify(ref _dormTrustEnabled, value.ToString()); ViewStatusStorage.Set("Infrast.DormTrustEnabled", value.ToString()); } } private string _originiumShardAutoReplenishment = ViewStatusStorage.Get("Infrast.OriginiumShardAutoReplenishment", true.ToString()); /// /// Gets or sets a value indicating whether Originium shard auto replenishment is enabled. /// public bool OriginiumShardAutoReplenishment { get => bool.Parse(_originiumShardAutoReplenishment); set { SetAndNotify(ref _originiumShardAutoReplenishment, value.ToString()); ViewStatusStorage.Set("Infrast.OriginiumShardAutoReplenishment", value.ToString()); } } private bool _customInfrastEnabled = bool.Parse(ViewStatusStorage.Get("Infrast.CustomInfrastEnabled", false.ToString())); public bool CustomInfrastEnabled { get => _customInfrastEnabled; set { SetAndNotify(ref _customInfrastEnabled, value); ViewStatusStorage.Set("Infrast.CustomInfrastEnabled", value.ToString()); var mainModel = _container.Get(); mainModel.CustomInfrastEnabled = value; } } /// /// Selects infrast config file. /// public void SelectCustomInfrastFile() { var dialog = new Microsoft.Win32.OpenFileDialog { Filter = Localization.GetString("CustomInfrastFile") + "|*.json", }; if (dialog.ShowDialog() == true) { CustomInfrastFile = dialog.FileName; } DefaultInfrast = _userDefined; } private string _customInfrastFile = ViewStatusStorage.Get("Infrast.CustomInfrastFile", string.Empty); public string CustomInfrastFile { get => _customInfrastFile; set { SetAndNotify(ref _customInfrastFile, value); ViewStatusStorage.Set("Infrast.CustomInfrastFile", value); var mainModel = _container.Get(); mainModel.RefreshCustonInfrastPlan(); } } #region 设置页面列表和滚动视图联动绑定 private enum NotifyType { None, SelectedIndex, ScrollOffset, } private NotifyType _notifySource = NotifyType.None; private System.Timers.Timer _resetNotifyTimer; private void ResetNotifySource() { if (_resetNotifyTimer != null) { _resetNotifyTimer.Stop(); _resetNotifyTimer.Close(); } _resetNotifyTimer = new System.Timers.Timer(20); _resetNotifyTimer.Elapsed += (source, e) => { _notifySource = NotifyType.None; }; _resetNotifyTimer.AutoReset = false; _resetNotifyTimer.Enabled = true; _resetNotifyTimer.Start(); } /// /// Gets or sets the height of scroll viewport. /// public double ScrollViewportHeight { get; set; } /// /// Gets or sets the extent height of scroll. /// public double ScrollExtentHeight { get; set; } /// /// Gets or sets the list of rectangle vertical offset. /// public List RectangleVerticalOffsetList { get; set; } private int _selectedIndex = 0; /// /// Gets or sets the index selected. /// public int SelectedIndex { get => _selectedIndex; set { switch (_notifySource) { case NotifyType.None: _notifySource = NotifyType.SelectedIndex; SetAndNotify(ref _selectedIndex, value); var isInRange = RectangleVerticalOffsetList != null && RectangleVerticalOffsetList.Count > 0 && value < RectangleVerticalOffsetList.Count; if (isInRange) { ScrollOffset = RectangleVerticalOffsetList[value]; } ResetNotifySource(); break; case NotifyType.ScrollOffset: SetAndNotify(ref _selectedIndex, value); break; } } } private double _scrollOffset = 0; /// /// Gets or sets the scroll offset. /// public double ScrollOffset { get => _scrollOffset; set { switch (_notifySource) { case NotifyType.None: _notifySource = NotifyType.ScrollOffset; SetAndNotify(ref _scrollOffset, value); // 设置 ListBox SelectedIndex 为当前 ScrollOffset 索引 var isInRange = RectangleVerticalOffsetList != null && RectangleVerticalOffsetList.Count > 0; if (isInRange) { // 滚动条滚动到底部,返回最后一个 Rectangle 索引 if (value + ScrollViewportHeight >= ScrollExtentHeight) { SelectedIndex = RectangleVerticalOffsetList.Count - 1; ResetNotifySource(); break; } // 根据出当前 ScrollOffset 选出最后一个在可视范围的 Rectangle 索引 var rectangleSelect = RectangleVerticalOffsetList.Select((n, i) => ( rectangleAppeared: value >= n, index: i)); var index = rectangleSelect.LastOrDefault(n => n.rectangleAppeared).index; SelectedIndex = index; } ResetNotifySource(); break; case NotifyType.SelectedIndex: SetAndNotify(ref _scrollOffset, value); break; } } } #endregion 设置页面列表和滚动视图联动绑定 /* 肉鸽设置 */ private string _roguelikeTheme = ViewStatusStorage.Get("Roguelike.RoguelikeTheme", "Phantom"); /// /// Gets or sets the Roguelike theme. /// public string RoguelikeTheme { get => _roguelikeTheme; set { SetAndNotify(ref _roguelikeTheme, value); ViewStatusStorage.Set("Roguelike.RoguelikeTheme", value); } } private string _roguelikeMode = ViewStatusStorage.Get("Roguelike.Mode", "0"); /// /// Gets or sets the roguelike mode. /// public string RoguelikeMode { get => _roguelikeMode; set { SetAndNotify(ref _roguelikeMode, value); ViewStatusStorage.Set("Roguelike.Mode", value); if (value == "1") { RoguelikeInvestmentEnabled = true; } } } private string _roguelikeSquad = ViewStatusStorage.Get("Roguelike.Squad", string.Empty); /// /// Gets or sets the roguelike squad. /// public string RoguelikeSquad { get => _roguelikeSquad; set { SetAndNotify(ref _roguelikeSquad, value); ViewStatusStorage.Set("Roguelike.Squad", value); } } private string _roguelikeRoles = ViewStatusStorage.Get("Roguelike.Roles", string.Empty); /// /// Gets or sets the roguelike roles. /// public string RoguelikeRoles { get => _roguelikeRoles; set { SetAndNotify(ref _roguelikeRoles, value); ViewStatusStorage.Set("Roguelike.Roles", value); } } private string _roguelikeCoreChar = ViewStatusStorage.Get("Roguelike.CoreChar", string.Empty); /// /// Gets or sets the roguelike core character. /// public string RoguelikeCoreChar { get => _roguelikeCoreChar; set { SetAndNotify(ref _roguelikeCoreChar, value); ViewStatusStorage.Set("Roguelike.CoreChar", value); } } private string _roguelikeStartsCount = ViewStatusStorage.Get("Roguelike.StartsCount", "9999999"); /// /// Gets or sets the start count of roguelike. /// public int RoguelikeStartsCount { get => int.Parse(_roguelikeStartsCount); set { SetAndNotify(ref _roguelikeStartsCount, value.ToString()); ViewStatusStorage.Set("Roguelike.StartsCount", value.ToString()); } } private string _roguelikeInvestmentEnabled = ViewStatusStorage.Get("Roguelike.InvestmentEnabled", true.ToString()); /// /// Gets or sets a value indicating whether investment is enabled. /// public bool RoguelikeInvestmentEnabled { get => bool.Parse(_roguelikeInvestmentEnabled); set { SetAndNotify(ref _roguelikeInvestmentEnabled, value.ToString()); ViewStatusStorage.Set("Roguelike.InvestmentEnabled", value.ToString()); } } private string _roguelikeInvestsCount = ViewStatusStorage.Get("Roguelike.InvestsCount", "9999999"); /// /// Gets or sets the invests count of roguelike. /// public int RoguelikeInvestsCount { get => int.Parse(_roguelikeInvestsCount); set { SetAndNotify(ref _roguelikeInvestsCount, value.ToString()); ViewStatusStorage.Set("Roguelike.InvestsCount", value.ToString()); } } private string _roguelikeStopWhenInvestmentFull = ViewStatusStorage.Get("Roguelike.StopWhenInvestmentFull", false.ToString()); /// /// Gets or sets a value indicating whether to stop when investment is full. /// public bool RoguelikeStopWhenInvestmentFull { get => bool.Parse(_roguelikeStopWhenInvestmentFull); set { SetAndNotify(ref _roguelikeStopWhenInvestmentFull, value.ToString()); ViewStatusStorage.Set("Roguelike.StopWhenInvestmentFull", value.ToString()); } } /* 信用商店设置 */ private bool _creditShopping = Convert.ToBoolean(ViewStatusStorage.Get("Mall.CreditShopping", bool.TrueString)); /// /// Gets or sets a value indicating whether to shop with credit. /// public bool CreditShopping { get => _creditShopping; set { SetAndNotify(ref _creditShopping, value); ViewStatusStorage.Set("Mall.CreditShopping", value.ToString()); } } private string _creditFirstList = ViewStatusStorage.Get("Mall.CreditFirstListNew", Localization.GetString("HighPriorityDefault")); /// /// Gets or sets the priority item list of credit shop. /// public string CreditFirstList { get => _creditFirstList; set { SetAndNotify(ref _creditFirstList, value); ViewStatusStorage.Set("Mall.CreditFirstListNew", value); } } private string _creditBlackList = ViewStatusStorage.Get("Mall.CreditBlackListNew", Localization.GetString("BlacklistDefault")); /// /// Gets or sets the blacklist of credit shop. /// public string CreditBlackList { get => _creditBlackList; set { SetAndNotify(ref _creditBlackList, value); ViewStatusStorage.Set("Mall.CreditBlackListNew", value); } } private string _creditForceShoppingIfCreditFull = ViewStatusStorage.Get("Mall.CreditForceShoppingIfCreditFull", false.ToString()); /// /// Gets or sets a value indicating whether save credit is enabled. /// public bool CreditForceShoppingIfCreditFull { get { return bool.Parse(_creditForceShoppingIfCreditFull); } set { SetAndNotify(ref _creditForceShoppingIfCreditFull, value.ToString()); ViewStatusStorage.Set("Mall.CreditForceShoppingIfCreditFull", value.ToString()); } } /* 定时设置 */ private bool _timer1 = ViewStatusStorage.Get("Timer.Timer1", bool.FalseString) == bool.TrueString; private bool _timer2 = ViewStatusStorage.Get("Timer.Timer2", bool.FalseString) == bool.TrueString; private bool _timer3 = ViewStatusStorage.Get("Timer.Timer3", bool.FalseString) == bool.TrueString; private bool _timer4 = ViewStatusStorage.Get("Timer.Timer4", bool.FalseString) == bool.TrueString; private bool _timer5 = ViewStatusStorage.Get("Timer.Timer5", bool.FalseString) == bool.TrueString; private bool _timer6 = ViewStatusStorage.Get("Timer.Timer6", bool.FalseString) == bool.TrueString; private bool _timer7 = ViewStatusStorage.Get("Timer.Timer7", bool.FalseString) == bool.TrueString; private bool _timer8 = ViewStatusStorage.Get("Timer.Timer8", bool.FalseString) == bool.TrueString; private int _timer1hour = int.Parse(ViewStatusStorage.Get("Timer.Timer1Hour", "0")); private int _timer2hour = int.Parse(ViewStatusStorage.Get("Timer.Timer2Hour", "6")); private int _timer3hour = int.Parse(ViewStatusStorage.Get("Timer.Timer3Hour", "12")); private int _timer4hour = int.Parse(ViewStatusStorage.Get("Timer.Timer4Hour", "18")); private int _timer5hour = int.Parse(ViewStatusStorage.Get("Timer.Timer5Hour", "3")); private int _timer6hour = int.Parse(ViewStatusStorage.Get("Timer.Timer6Hour", "9")); private int _timer7hour = int.Parse(ViewStatusStorage.Get("Timer.Timer7Hour", "15")); private int _timer8hour = int.Parse(ViewStatusStorage.Get("Timer.Timer8Hour", "21")); /// /// Gets or sets a value indicating whether the 1st timer is set. /// public bool Timer1 { get => _timer1; set { SetAndNotify(ref _timer1, value); ViewStatusStorage.Set("Timer.Timer1", value.ToString()); } } /// /// Gets or sets a value indicating whether the 2nd timer is set. /// public bool Timer2 { get => _timer2; set { SetAndNotify(ref _timer2, value); ViewStatusStorage.Set("Timer.Timer2", value.ToString()); } } /// /// Gets or sets a value indicating whether the 3rd timer is set. /// public bool Timer3 { get => _timer3; set { SetAndNotify(ref _timer3, value); ViewStatusStorage.Set("Timer.Timer3", value.ToString()); } } /// /// Gets or sets a value indicating whether the 4th timer is set. /// public bool Timer4 { get => _timer4; set { SetAndNotify(ref _timer4, value); ViewStatusStorage.Set("Timer.Timer4", value.ToString()); } } /// /// Gets or sets a value indicating whether the 5th timer is set. /// public bool Timer5 { get => _timer5; set { SetAndNotify(ref _timer5, value); ViewStatusStorage.Set("Timer.Timer5", value.ToString()); } } /// /// Gets or sets a value indicating whether the 6th timer is set. /// public bool Timer6 { get => _timer6; set { SetAndNotify(ref _timer6, value); ViewStatusStorage.Set("Timer.Timer6", value.ToString()); } } /// /// Gets or sets a value indicating whether the 7th timer is set. /// public bool Timer7 { get => _timer7; set { SetAndNotify(ref _timer7, value); ViewStatusStorage.Set("Timer.Timer7", value.ToString()); } } /// /// Gets or sets a value indicating whether the 8th timer is set. /// public bool Timer8 { get => _timer8; set { SetAndNotify(ref _timer8, value); ViewStatusStorage.Set("Timer.Timer8", value.ToString()); } } /// /// Gets or sets the hour of the 1st timer. /// public int Timer1Hour { get => _timer1hour; set { SetAndNotify(ref _timer1hour, value); ViewStatusStorage.Set("Timer.Timer1Hour", value.ToString()); } } /// /// Gets or sets the hour of the 2nd timer. /// public int Timer2Hour { get => _timer2hour; set { SetAndNotify(ref _timer2hour, value); ViewStatusStorage.Set("Timer.Timer2Hour", value.ToString()); } } /// /// Gets or sets the hour of the 3rd timer. /// public int Timer3Hour { get => _timer3hour; set { SetAndNotify(ref _timer3hour, value); ViewStatusStorage.Set("Timer.Timer3Hour", value.ToString()); } } /// /// Gets or sets the hour of the 4th timer. /// public int Timer4Hour { get => _timer4hour; set { SetAndNotify(ref _timer4hour, value); ViewStatusStorage.Set("Timer.Timer4Hour", value.ToString()); } } /// /// Gets or sets the hour of the 5th timer. /// public int Timer5Hour { get => _timer5hour; set { SetAndNotify(ref _timer5hour, value); ViewStatusStorage.Set("Timer.Timer5Hour", value.ToString()); } } /// /// Gets or sets the hour of the 6th timer. /// public int Timer6Hour { get => _timer6hour; set { SetAndNotify(ref _timer6hour, value); ViewStatusStorage.Set("Timer.Timer6Hour", value.ToString()); } } /// /// Gets or sets the hour of the 7th timer. /// public int Timer7Hour { get => _timer7hour; set { SetAndNotify(ref _timer7hour, value); ViewStatusStorage.Set("Timer.Timer7Hour", value.ToString()); } } /// /// Gets or sets the hour of the 8th timer. /// public int Timer8Hour { get => _timer8hour; set { SetAndNotify(ref _timer8hour, value); ViewStatusStorage.Set("Timer.Timer8Hour", value.ToString()); } } /* 刷理智设置 */ private string _penguinId = ViewStatusStorage.Get("Penguin.Id", string.Empty); /// /// Gets or sets the id of PenguinStats. /// public string PenguinId { get => _penguinId; set { SetAndNotify(ref _penguinId, value); ViewStatusStorage.Set("Penguin.Id", value); } } private bool _isDrGrandet = Convert.ToBoolean(ViewStatusStorage.Get("Penguin.IsDrGrandet", bool.FalseString)); /// /// Gets or sets a value indicating whether to use DrGrandet mode. /// public bool IsDrGrandet { get => _isDrGrandet; set { SetAndNotify(ref _isDrGrandet, value); ViewStatusStorage.Set("Penguin.IsDrGrandet", value.ToString()); } } /* 自动公招设置 */ private string _recruitMaxTimes = ViewStatusStorage.Get("AutoRecruit.MaxTimes", "4"); /// /// Gets or sets the maximum times of recruit. /// public string RecruitMaxTimes { get => _recruitMaxTimes; set { SetAndNotify(ref _recruitMaxTimes, value); ViewStatusStorage.Set("AutoRecruit.MaxTimes", value); } } private bool _refreshLevel3 = Convert.ToBoolean(ViewStatusStorage.Get("AutoRecruit.RefreshLevel3", bool.TrueString)); /// /// Gets or sets a value indicating whether to refresh level 3. /// public bool RefreshLevel3 { get => _refreshLevel3; set { SetAndNotify(ref _refreshLevel3, value); ViewStatusStorage.Set("AutoRecruit.RefreshLevel3", value.ToString()); } } private bool _useExpedited = false; /// /// Gets or sets a value indicating whether to use expedited. /// public bool UseExpedited { get => _useExpedited; set => SetAndNotify(ref _useExpedited, value); } private bool _isLevel3UseShortTime = Convert.ToBoolean(ViewStatusStorage.Get("AutoRecruit.IsLevel3UseShortTime", bool.FalseString)); /// /// Gets or sets a value indicating whether to shorten the time for level 3. /// public bool IsLevel3UseShortTime { get => _isLevel3UseShortTime; set { SetAndNotify(ref _isLevel3UseShortTime, value); ViewStatusStorage.Set("AutoRecruit.IsLevel3UseShortTime", value.ToString()); } } private bool _notChooseLevel1 = Convert.ToBoolean(ViewStatusStorage.Get("AutoRecruit.NotChooseLevel1", bool.TrueString)); /// /// Gets or sets a value indicating whether not to choose level 1. /// public bool NotChooseLevel1 { get => _notChooseLevel1; set { SetAndNotify(ref _notChooseLevel1, value); ViewStatusStorage.Set("AutoRecruit.NotChooseLevel1", value.ToString()); } } private bool _chooseLevel3 = Convert.ToBoolean(ViewStatusStorage.Get("AutoRecruit.ChooseLevel3", bool.TrueString)); /// /// Gets or sets a value indicating whether to choose level 3. /// public bool ChooseLevel3 { get => _chooseLevel3; set { SetAndNotify(ref _chooseLevel3, value); ViewStatusStorage.Set("AutoRecruit.ChooseLevel3", value.ToString()); } } private bool _chooseLevel4 = Convert.ToBoolean(ViewStatusStorage.Get("AutoRecruit.ChooseLevel4", bool.TrueString)); /// /// Gets or sets a value indicating whether to choose level 4. /// public bool ChooseLevel4 { get => _chooseLevel4; set { SetAndNotify(ref _chooseLevel4, value); ViewStatusStorage.Set("AutoRecruit.ChooseLevel4", value.ToString()); } } private bool _chooseLevel5 = Convert.ToBoolean(ViewStatusStorage.Get("AutoRecruit.ChooseLevel5", bool.FalseString)); /// /// Gets or sets a value indicating whether to choose level 5. /// public bool ChooseLevel5 { get => _chooseLevel5; set { SetAndNotify(ref _chooseLevel5, value); ViewStatusStorage.Set("AutoRecruit.ChooseLevel5", value.ToString()); } } public enum UpdateVersionType { Nightly, Beta, Stable, } /* 软件更新设置 */ private UpdateVersionType _versionType = (UpdateVersionType)Enum.Parse(typeof(UpdateVersionType), ViewStatusStorage.Get("VersionUpdate.VersionType", UpdateVersionType.Stable.ToString())); /// /// Gets or sets the type of version to update. /// public UpdateVersionType VersionType { get => _versionType; set { SetAndNotify(ref _versionType, value); ViewStatusStorage.Set("VersionUpdate.VersionType", value.ToString()); } } /// /// Gets a value indicating whether to update nightly. /// public bool UpdateNightly { get => _versionType == UpdateVersionType.Nightly; } /// /// Gets a value indicating whether to update beta version. /// public bool UpdateBeta { get => _versionType == UpdateVersionType.Beta; } private bool _updateCheck = Convert.ToBoolean(ViewStatusStorage.Get("VersionUpdate.UpdateCheck", bool.TrueString)); /// /// Gets or sets a value indicating whether to check update. /// public bool UpdateCheck { get => _updateCheck; set { SetAndNotify(ref _updateCheck, value); ViewStatusStorage.Set("VersionUpdate.UpdateCheck", value.ToString()); } } private string _proxy = ViewStatusStorage.Get("VersionUpdate.Proxy", string.Empty); /// /// Gets or sets the proxy settings. /// public string Proxy { get => _proxy; set { SetAndNotify(ref _proxy, value); ViewStatusStorage.Set("VersionUpdate.Proxy", value); } } private bool _useAria2 = Convert.ToBoolean(ViewStatusStorage.Get("VersionUpdate.UseAria2", bool.TrueString)); /// /// Gets or sets a value indicating whether to use Aria 2. /// public bool UseAria2 { get => _useAria2; set { SetAndNotify(ref _useAria2, value); ViewStatusStorage.Set("VersionUpdate.UseAria2", value.ToString()); } } private bool _autoDownloadUpdatePackage = Convert.ToBoolean(ViewStatusStorage.Get("VersionUpdate.AutoDownloadUpdatePackage", bool.TrueString)); /// /// Gets or sets a value indicating whether to auto download update package. /// public bool AutoDownloadUpdatePackage { get => _autoDownloadUpdatePackage; set { SetAndNotify(ref _autoDownloadUpdatePackage, value); ViewStatusStorage.Set("VersionUpdate.AutoDownloadUpdatePackage", value.ToString()); } } /// /// Updates manually. /// // TODO: 你确定要用 async void 不是 async Task? public async void ManualUpdate() { var updateModel = _container.Get(); var task = Task.Run(() => { return updateModel.CheckAndDownloadUpdate(true); }); var ret = await task; string toastMessage = null; switch (ret) { case VersionUpdateViewModel.CheckUpdateRetT.NoNeedToUpdate: break; case VersionUpdateViewModel.CheckUpdateRetT.AlreadyLatest: toastMessage = Localization.GetString("AlreadyLatest"); break; case VersionUpdateViewModel.CheckUpdateRetT.UnknownError: toastMessage = Localization.GetString("NewVersionDetectFailedTitle"); break; case VersionUpdateViewModel.CheckUpdateRetT.NetworkError: toastMessage = Localization.GetString("CheckNetworking"); break; case VersionUpdateViewModel.CheckUpdateRetT.FailedToGetInfo: toastMessage = Localization.GetString("GetReleaseNoteFailed"); break; case VersionUpdateViewModel.CheckUpdateRetT.OK: updateModel.AskToRestart(); break; case VersionUpdateViewModel.CheckUpdateRetT.NewVersionIsBeingBuilt: toastMessage = Localization.GetString("NewVersionIsBeingBuilt"); break; } if (toastMessage != null) { Execute.OnUIThread(() => { using (var toast = new ToastNotification(toastMessage)) { toast.Show(); } }); } } /* 连接设置 */ private bool _autoDetectConnection = bool.Parse(ViewStatusStorage.Get("Connect.AutoDetect", true.ToString())); public bool AutoDetectConnection { get => _autoDetectConnection; set { SetAndNotify(ref _autoDetectConnection, value); ViewStatusStorage.Set("Connect.AutoDetect", value.ToString()); } } private bool _alwaysAutoDetectConnection = bool.Parse(ViewStatusStorage.Get("Connect.AlwaysAutoDetect", false.ToString())); public bool AlwaysAutoDetectConnection { get => _alwaysAutoDetectConnection; set { SetAndNotify(ref _alwaysAutoDetectConnection, value); ViewStatusStorage.Set("Connect.AlwaysAutoDetect", value.ToString()); } } private string _connectAddress = ViewStatusStorage.Get("Connect.Address", string.Empty); /// /// Gets or sets the connection address. /// public string ConnectAddress { get => _connectAddress; set { SetAndNotify(ref _connectAddress, value); ViewStatusStorage.Set("Connect.Address", value); UpdateWindowTitle(); /* 每次修改连接地址时更新WindowTitle */ } } private string _adbPath = ViewStatusStorage.Get("Connect.AdbPath", string.Empty); /// /// Gets or sets the ADB path. /// public string AdbPath { get => _adbPath; set { SetAndNotify(ref _adbPath, value); ViewStatusStorage.Set("Connect.AdbPath", value); } } private string _connectConfig = ViewStatusStorage.Get("Connect.ConnectConfig", "General"); /// /// Gets or sets the connection config. /// public string ConnectConfig { get => _connectConfig; set { SetAndNotify(ref _connectConfig, value); ViewStatusStorage.Set("Connect.ConnectConfig", value); } } private bool _retryOnDisconnected = Convert.ToBoolean(ViewStatusStorage.Get("Connect.RetryOnDisconnected", bool.FalseString)); /// /// Gets or sets a value indicating whether to retry task after adb disconnected. /// public bool RetryOnDisconnected { get => _retryOnDisconnected; set { SetAndNotify(ref _retryOnDisconnected, value); ViewStatusStorage.Set("Connect.RetryOnDisconnected", value.ToString()); } } private readonly Dictionary> _defaultAddress = new Dictionary> { { "General", new List { string.Empty } }, { "BlueStacks", new List { "127.0.0.1:5555", "127.0.0.1:5556", "127.0.0.1:5565", "127.0.0.1:5575", "127.0.0.1:5585", "127.0.0.1:5595", "127.0.0.1:5554" } }, { "MuMuEmulator", new List { "127.0.0.1:7555" } }, { "LDPlayer", new List { "emulator-5554", "127.0.0.1:5555", "127.0.0.1:5556", "127.0.0.1:5554" } }, { "Nox", new List { "127.0.0.1:62001", "127.0.0.1:59865" } }, { "XYAZ", new List { "127.0.0.1:21503" } }, { "WSA", new List { "127.0.0.1:58526" } }, }; /// /// Gets the default addresses. /// public Dictionary> DefaultAddress => _defaultAddress; /// /// Refreshes ADB config. /// /// Errors when doing this operation. /// Whether the operation is successful. public bool DetectAdbConfig(ref string error) { var adapter = new WinAdapter(); List emulators; try { emulators = adapter.RefreshEmulatorsInfo(); } catch (Exception) { error = Localization.GetString("EmulatorException"); return false; } if (emulators.Count == 0) { error = Localization.GetString("EmulatorNotFound"); return false; } else if (emulators.Count > 1) { error = Localization.GetString("EmulatorTooMany"); return false; } ConnectConfig = emulators.First(); AdbPath = adapter.GetAdbPathByEmulatorName(ConnectConfig) ?? AdbPath; if (ConnectAddress.Length == 0) { var addresses = adapter.GetAdbAddresses(AdbPath); // 傻逼雷电已经关掉了,用别的 adb 还能检测出来这个端口 device if (addresses.Count == 1 && addresses.First() != "emulator-5554") { ConnectAddress = addresses.First(); } else if (addresses.Count > 1) { foreach (var address in addresses) { if (address == "emulator-5554" && ConnectConfig != "LDPlayer") { continue; } ConnectAddress = address; break; } } if (ConnectAddress.Length == 0) { ConnectAddress = DefaultAddress[ConnectConfig][0]; } } return true; } /// /// Selects ADB program file. /// public void SelectFile() { var dialog = new Microsoft.Win32.OpenFileDialog { Filter = Localization.GetString("ADBProgram") + "|*.exe", }; if (dialog.ShowDialog() == true) { AdbPath = dialog.FileName; } } /// /// 标题栏显示模拟器名称和IP端口。 /// public void UpdateWindowTitle() { var rvm = (RootViewModel)this.Parent; var connectConfigName = string.Empty; foreach (var data in ConnectConfigList) { if (data.Value == ConnectConfig) { connectConfigName = data.Display; } } rvm.WindowTitle = $"MAA - {VersionId} - {connectConfigName} ({ConnectAddress}) - {ClientName}"; } private readonly string _bluestacksConfig = ViewStatusStorage.Get("Bluestacks.Config.Path", string.Empty); private readonly string _bluestacksKeyWord = ViewStatusStorage.Get("Bluestacks.Config.Keyword", "bst.instance.Nougat64.status.adb_port"); /// /// Tries to set Bluestack Hyper V address. /// public void TryToSetBlueStacksHyperVAddress() { if (_bluestacksConfig.Length == 0) { return; } if (!File.Exists(_bluestacksConfig)) { ViewStatusStorage.Set("Bluestacks.Config.Error", "File not exists"); return; } var all_lines = File.ReadAllLines(_bluestacksConfig); foreach (var line in all_lines) { if (line.StartsWith(_bluestacksKeyWord)) { var sp = line.Split('"'); ConnectAddress = "127.0.0.1:" + sp[1]; } } } private static readonly string GoogleAdbDownloadUrl = "https://dl.google.com/android/repository/platform-tools-latest-windows.zip"; private static readonly string GoogleAdbFilename = "adb.zip"; public async void ReplaceADB() { if (!File.Exists(AdbPath)) { Execute.OnUIThread(() => { using (var toast = new ToastNotification(Localization.GetString("ReplaceADBNotExists"))) { toast.Show(); } }); return; } if (!File.Exists(GoogleAdbFilename)) { var downloadTask = Task.Run(() => { return VersionUpdateViewModel.DownloadFile(GoogleAdbDownloadUrl, GoogleAdbFilename); }); var downloadResult = await downloadTask; if (!downloadResult) { Execute.OnUIThread(() => { using (var toast = new ToastNotification(Localization.GetString("AdbDownloadFailedTitle"))) { toast.AppendContentText(Localization.GetString("AdbDownloadFailedDesc")) .Show(); } }); return; } } const string UnzipDir = "adb_unzip"; if (Directory.Exists(UnzipDir)) { Directory.Delete(UnzipDir, true); } var procTask = Task.Run(() => { // ErrorView.xaml.cs里有个报错的逻辑,这里如果改的话那边也要对应改一下 System.IO.Compression.ZipFile.ExtractToDirectory(GoogleAdbFilename, UnzipDir); File.Copy(AdbPath, AdbPath + ".bak", true); File.Copy(UnzipDir + "/platform-tools/adb.exe", AdbPath, true); Directory.Delete(UnzipDir, true); }); await procTask; Execute.OnUIThread(() => { using (var toast = new ToastNotification(Localization.GetString("SuccessfullyReplacedADB"))) { toast.Show(); } }); } /* 界面设置 */ /// /// Gets a value indicating whether to use tray icon. /// public bool UseTray => true; /* private bool _useTray = Convert.ToBoolean(ViewStatusStorage.Get("GUI.UseTray", bool.TrueString)); public bool UseTray { get => _useTray; set { SetAndNotify(ref _useTray, value); ViewStatusStorage.Set("GUI.UseTray", value.ToString()); var trayObj = _container.Get(); trayObj.SetVisible(value); if (!Convert.ToBoolean(value)) { MinimizeToTray = false; } } }*/ private bool _minimizeToTray = Convert.ToBoolean(ViewStatusStorage.Get("GUI.MinimizeToTray", bool.FalseString)); /// /// Gets or sets a value indicating whether to minimize to tray. /// public bool MinimizeToTray { get => _minimizeToTray; set { SetAndNotify(ref _minimizeToTray, value); ViewStatusStorage.Set("GUI.MinimizeToTray", value.ToString()); var mainWindowManager = _container.Get(); mainWindowManager.SetMinimizeToTaskbar(value); } } private bool _useNotify = Convert.ToBoolean(ViewStatusStorage.Get("GUI.UseNotify", bool.TrueString)); /// /// Gets or sets a value indicating whether to use notification. /// public bool UseNotify { get => _useNotify; set { SetAndNotify(ref _useNotify, value); ViewStatusStorage.Set("GUI.UseNotify", value.ToString()); if (value) { Execute.OnUIThread(() => { using (var toast = new ToastNotification("Test test")) { toast.Show(); } }); } } } private bool _useAlternateStage = Convert.ToBoolean(ViewStatusStorage.Get("GUI.UseAlternateStage", bool.FalseString)); /// /// Gets or sets a value indicating whether to use alternate stage. /// public bool UseAlternateStage { get => _useAlternateStage; set { SetAndNotify(ref _useAlternateStage, value); var taskQueueViewModel = _container.Get(); taskQueueViewModel.AlternateStageDisplay = value; ViewStatusStorage.Set("GUI.UseAlternateStage", value.ToString()); if (value) { HideUnavailableStage = false; } } } private bool _hideUnavailableStage = Convert.ToBoolean(ViewStatusStorage.Get("GUI.HideUnavailableStage", bool.TrueString)); /// /// Gets or sets a value indicating whether to hide unavailable stages. /// public bool HideUnavailableStage { get => _hideUnavailableStage; set { SetAndNotify(ref _hideUnavailableStage, value); ViewStatusStorage.Set("GUI.HideUnavailableStage", value.ToString()); if (value) { UseAlternateStage = false; } var mainModel = _container.Get(); mainModel.UpdateStageList(true); } } private bool _customStageCode = Convert.ToBoolean(ViewStatusStorage.Get("GUI.CustomStageCode", bool.FalseString)); /// /// Gets or sets a value indicating whether to use custom stage code. /// public bool CustomStageCode { get => _customStageCode; set { SetAndNotify(ref _customStageCode, value); ViewStatusStorage.Set("GUI.CustomStageCode", value.ToString()); var mainModel = _container.Get(); mainModel.CustomStageCode = value; } } private enum InverseClearType { Clear, Inverse, ClearInverse, } private InverseClearType _inverseClearMode = Enum.TryParse(ViewStatusStorage.Get("GUI.InverseClearMode", InverseClearType.Clear.ToString()), out InverseClearType temp) ? temp : InverseClearType.Clear; /// /// Gets or sets the inverse clear mode. /// public string InverseClearMode { get => _inverseClearMode.ToString(); set { if (!Enum.TryParse(value, out InverseClearType tempEnumValue)) { return; } SetAndNotify(ref _inverseClearMode, tempEnumValue); ViewStatusStorage.Set("GUI.InverseClearMode", value); var taskQueueModel = _container.Get(); switch (tempEnumValue) { case InverseClearType.Clear: taskQueueModel.InverseMode = false; taskQueueModel.ShowInverse = false; taskQueueModel.SelectedAllWidth = 90; break; case InverseClearType.Inverse: taskQueueModel.InverseMode = true; taskQueueModel.ShowInverse = false; taskQueueModel.SelectedAllWidth = 90; break; case InverseClearType.ClearInverse: taskQueueModel.ShowInverse = true; taskQueueModel.SelectedAllWidth = TaskQueueViewModel.SelectedAllWidthWhenBoth; break; } } } private string _language = ViewStatusStorage.Get("GUI.Localization", Localization.DefaultLanguage); /// /// Gets or sets the language. /// public string Language { get => _language; set { if (value == _language) { return; } if (_language == PallasLangKey) { Hangover = true; Cheers = false; } // var backup = _language; ViewStatusStorage.Set("GUI.Localization", value); System.Windows.Forms.MessageBoxManager.Yes = Localization.GetString("Ok", value); System.Windows.Forms.MessageBoxManager.No = Localization.GetString("ManualRestart", value); System.Windows.Forms.MessageBoxManager.Register(); var result = MessageBox.Show( Localization.GetString("LanguageChangedTip", value), Localization.GetString("Tip", value), MessageBoxButton.YesNo, MessageBoxImage.Question); System.Windows.Forms.MessageBoxManager.Unregister(); SetAndNotify(ref _language, value); if (result == MessageBoxResult.Yes) { Application.Current.Shutdown(); System.Windows.Forms.Application.Restart(); } } } private bool _cheers = bool.Parse(ViewStatusStorage.Get("GUI.Cheers", bool.FalseString)); /// /// Gets or sets a value indicating whether to cheer. /// public bool Cheers { get => _cheers; set { if (_cheers == value) { return; } SetAndNotify(ref _cheers, value); ViewStatusStorage.Set("GUI.Cheers", value.ToString()); if (_cheers) { SetPallasLanguage(); } } } private bool _hangover = bool.Parse(ViewStatusStorage.Get("GUI.Hangover", bool.FalseString)); /// /// Gets or sets a value indicating whether to hangover. /// public bool Hangover { get => _hangover; set { SetAndNotify(ref _hangover, value); ViewStatusStorage.Set("GUI.Hangover", value.ToString()); } } private void SetPallasLanguage() { ViewStatusStorage.Set("GUI.Localization", PallasLangKey); var result = _windowManager.ShowMessageBox( Localization.GetString("DrunkAndStaggering"), Localization.GetString("Burping"), MessageBoxButton.OK, MessageBoxImage.Asterisk); if (result == MessageBoxResult.OK) { Application.Current.Shutdown(); System.Windows.Forms.Application.Restart(); } } /// /// Gets or sets the hotkey: ShowGui. /// public MaaHotKey HotKeyShowGui { get => _maaHotKeyManager.GetOrNull(MaaHotKeyAction.ShowGui); set => SetHotKey(MaaHotKeyAction.ShowGui, value); } /// /// Gets or sets the hotkey: LinkStart. /// public MaaHotKey HotKeyLinkStart { get => _maaHotKeyManager.GetOrNull(MaaHotKeyAction.LinkStart); set => SetHotKey(MaaHotKeyAction.LinkStart, value); } private void SetHotKey(MaaHotKeyAction action, MaaHotKey value) { if (value != null) { _maaHotKeyManager.TryRegister(action, value); } else { _maaHotKeyManager.Unregister(action); } } /// /// Did you buy wine? /// /// The answer. public bool DidYouBuyWine() { var wine_list = new[] { "酒", "drink", "wine", "beer", "술", "🍷", "🍸", "🍺", "🍻", "🥃", "🍶" }; foreach (var wine in wine_list) { if (CreditFirstList.Contains(wine)) { return true; } } return false; } } }