private bool InternalSave() { if (IsModified == false) { return(true); } if (CurrentLoadoutName == null) { return(InternalSaveAs()); } else { Dictionary <string, SkillLoadoutItemConfigurationV3> loadoutConfig = GlobalData.Instance.Configuration.SkillLoadouts; loadoutConfig[CurrentLoadoutName] = new SkillLoadoutItemConfigurationV3 { WeaponSlots = rootViewModel.InParameters.Slots.Where(x => x.Value > 0).Select(x => x.Value).ToArray(), Skills = CreateSelectedSkillsArray() }; IsModified = false; ConfigurationManager.Save(GlobalData.Instance.Configuration); return(true); } }
public void Open(string loadoutName, SkillLoadoutItemConfigurationV3 loadoutConfig) { if (loadoutName == null) { throw new ArgumentNullException(nameof(loadoutName)); } if (loadoutConfig == null) { throw new ArgumentNullException(nameof(loadoutConfig)); } InternalOpen(loadoutName, loadoutConfig); }
private bool InternalOpen(string loadoutName, SkillLoadoutItemConfigurationV3 loadoutConfig) { if (IsModified) { if (InternalClose(false) == false) { return(false); } } if (loadoutName == null || loadoutConfig == null) { var loadoutWindow = new LoadoutWindow(false, currentLoadoutName, rootViewModel.SelectedAbilities) { Owner = Application.Current.MainWindow }; WindowManager.RestoreWindowState(loadoutWindow); bool?showResult = loadoutWindow.ShowDialog(); WindowManager.StoreWindowState(loadoutWindow); if (showResult != true) { return(false); } bool hasLoadoutChanged = CurrentLoadoutName != loadoutWindow.SelectedLoadout.Name; if (isModified || hasLoadoutChanged) { LoadLoadoutFromViewModel(loadoutWindow.SelectedLoadout); } if (hasLoadoutChanged) { CurrentLoadoutName = loadoutWindow.SelectedLoadout.Name; ConfigurationManager.Save(GlobalData.Instance.Configuration); } } else { LoadLoadoutFromConfig(loadoutConfig); CurrentLoadoutName = loadoutName; } // Postponing rest of the IsModified flag to false to the next scheduler frame is // because of a change in the way ability/skill checkboxes are processed, for performance reasons. rootViewModel.Dispatcher.BeginInvoke((Action) delegate { IsModified = false; }); return(true); }
private void LoadLoadoutFromConfig(SkillLoadoutItemConfigurationV3 loadoutConfig) { for (int i = 0; i < rootViewModel.InParameters.Slots.Length; i++) { if (i < loadoutConfig.WeaponSlots.Length) { rootViewModel.InParameters.Slots[i].Value = loadoutConfig.WeaponSlots[i]; } else { rootViewModel.InParameters.Slots[i].Value = 0; } } foreach (AbilityViewModel ability in rootViewModel.SelectedAbilities) { ability.IsChecked = loadoutConfig.Skills.Any(x => x.SkillName == Core.Localization.GetDefault(ability.SkillName) && x.Level == ability.Level ); } }