diff --git a/EDEngineer/Views/CommanderViewModel.cs b/EDEngineer/Views/CommanderViewModel.cs index f5f31d1f..f3d72d1b 100644 --- a/EDEngineer/Views/CommanderViewModel.cs +++ b/EDEngineer/Views/CommanderViewModel.cs @@ -175,12 +175,15 @@ public ICollectionView FilterView(MainWindowViewModel parentViewModel, Kind kind e.Accepted = ((entry.Data.Kind & kind) == entry.Data.Kind || entry.Data.Kind == Kind.Unknown) && (parentViewModel.MaterialSubkindFilter == null || entry.Data.Kind == Kind.Data || parentViewModel.MaterialSubkindFilter == entry.Data.Subkind) && (parentViewModel.ShowZeroes || entry.Count != 0) && + (parentViewModel.ShowFull || entry.Count < entry.Data.MaximumCapacity) && (!parentViewModel.ShowOnlyForFavorites || favoritedBlueprints.Any(b => b.Ingredients.Any(i => i.Entry == entry))); }; parentViewModel.PropertyChanged += (o, e) => { - if (e.PropertyName == nameof(parentViewModel.ShowZeroes) || e.PropertyName == nameof(parentViewModel.ShowOnlyForFavorites)) + if (e.PropertyName == nameof(parentViewModel.ShowZeroes) || + e.PropertyName == nameof(parentViewModel.ShowFull) || + e.PropertyName == nameof(parentViewModel.ShowOnlyForFavorites)) { source.View.Refresh(); } @@ -242,7 +245,6 @@ private void LoadBlueprints(ILanguage languages, IEnumerable blueprin if (Settings.Default.Favorites.Contains($"{blueprint}")) { Settings.Default.Favorites.Remove($"{blueprint}"); - Settings.Default.Save(); } } else if (Settings.Default.Favorites.Contains($"{blueprint}")) @@ -251,7 +253,6 @@ private void LoadBlueprints(ILanguage languages, IEnumerable blueprin favoritedBlueprints.Add(blueprint); Settings.Default.Favorites.Remove($"{blueprint}"); Settings.Default.Favorites.Add(text); - Settings.Default.Save(); } if (Settings.Default.Ignored.Contains(text)) @@ -261,7 +262,6 @@ private void LoadBlueprints(ILanguage languages, IEnumerable blueprin if (Settings.Default.Ignored.Contains($"{blueprint}")) { Settings.Default.Ignored.Remove($"{blueprint}"); - Settings.Default.Save(); } } else if (Settings.Default.Ignored.Contains($"{blueprint}")) @@ -269,7 +269,6 @@ private void LoadBlueprints(ILanguage languages, IEnumerable blueprin blueprint.Ignored = true; Settings.Default.Ignored.Remove($"{blueprint}"); Settings.Default.Ignored.Add(text); - Settings.Default.Save(); } blueprint.ShoppingListCount = Settings.Default.ShoppingList.Cast().Count(l => l == text); @@ -316,11 +315,15 @@ private void LoadBlueprints(ILanguage languages, IEnumerable blueprin Settings.Default.ShoppingList.Add(text); } - Settings.Default.Save(); + if (!importingShoppingList) + { + Settings.Default.Save(); + } } }; } + Settings.Default.Save(); Filters = new BlueprintFilters(languages, State.Blueprints); ShoppingList = new ShoppingListViewModel(State.Cargo, State.Blueprints, languages); @@ -403,8 +406,12 @@ public void ShoppingListChange(Blueprint blueprint, int i) { blueprint.ShoppingListCount += i; - OnPropertyChanged(nameof(ShoppingList)); - OnPropertyChanged(nameof(ShoppingListItem)); + // Don't bother UI when there is import in progress. + if (!importingShoppingList) + { + OnPropertyChanged(nameof(ShoppingList)); + OnPropertyChanged(nameof(ShoppingListItem)); + } } } @@ -412,6 +419,7 @@ public void ImportShoppingList() { if (Helpers.TryRetrieveShoppingList(out var shoppingListItems)) { + importingShoppingList = true; var blueprints = State.Blueprints; if (shoppingListItems != null && shoppingListItems.Count > 0) @@ -436,6 +444,7 @@ public void ImportShoppingList() break; case MessageBoxResult.Cancel: // User pressed Cancel button so skip out of Import + importingShoppingList = false; return; } @@ -444,7 +453,7 @@ public void ImportShoppingList() } RefreshShoppingList(); - + importingShoppingList = false; } } @@ -481,14 +490,26 @@ public void ExportShoppingList() public void ClearShoppingList() { + var importingShoppingListOld = importingShoppingList; + importingShoppingList = true; + foreach (var tuple in ShoppingList.Composition.ToList()) { ShoppingListChange(tuple.Item1, tuple.Item2 * -1); } + + importingShoppingList = importingShoppingListOld; + + if (!importingShoppingList) + { + RefreshShoppingList(); + } } public int ShoppingListItem => 0; + public bool importingShoppingList { get; private set; } + public override string ToString() { return $"CMDR {CommanderName}"; diff --git a/EDEngineer/Views/MainWindow.cs b/EDEngineer/Views/MainWindow.cs index ed866947..a6703700 100644 --- a/EDEngineer/Views/MainWindow.cs +++ b/EDEngineer/Views/MainWindow.cs @@ -107,6 +107,7 @@ public MainWindow() { if (e.PropertyName == "ShowOnlyForFavorites" || e.PropertyName == "ShowZeroes" || + e.PropertyName == "ShowFull" || e.PropertyName == "CurrentCommander" || e.PropertyName == "MaterialSubkindFilter" || e.PropertyName == "IngredientsGrouped") diff --git a/EDEngineer/Views/MainWindow.xaml b/EDEngineer/Views/MainWindow.xaml index 57612516..053fe19a 100644 --- a/EDEngineer/Views/MainWindow.xaml +++ b/EDEngineer/Views/MainWindow.xaml @@ -485,6 +485,7 @@ + + + + @@ -505,7 +514,7 @@ @@ -513,14 +522,14 @@ + Grid.Column="5"> showFull; + set + { + showFull = value; + OnPropertyChanged(); + } + } public Subkind? MaterialSubkindFilter { diff --git a/EDEngineer/Views/ShoppingListViewModel.cs b/EDEngineer/Views/ShoppingListViewModel.cs index cb77a55c..b0274139 100644 --- a/EDEngineer/Views/ShoppingListViewModel.cs +++ b/EDEngineer/Views/ShoppingListViewModel.cs @@ -18,12 +18,25 @@ public class ShoppingListViewModel : INotifyPropertyChanged, IShoppingList private readonly StateCargo stateCargo; private readonly ILanguage languages; private readonly List, Blueprint>> blueprints; + public List list = null; public ShoppingListViewModel(StateCargo stateCargo, List blueprints, ILanguage languages) { this.blueprints = blueprints.GroupBy(b => Tuple.Create(b.Type, b.BlueprintName)).ToList(); this.stateCargo = stateCargo; this.languages = languages; + list = this.ToList(); + + foreach (var blueprint in blueprints) + { + blueprint.PropertyChanged += (o, e) => + { + if (e.PropertyName == "ShoppingListCount") + { + list = this.ToList(); + } + }; + } foreach (var ingredientsValue in stateCargo.Ingredients) { @@ -44,7 +57,7 @@ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } - public List List => this.ToList(); + public List List => list; public ILanguage Languages => this.languages; public List> Composition @@ -205,36 +218,37 @@ public bool SynchronizeWithLogs } public Dictionary Deduction => - this.ToList() - .FirstOrDefault() + list.FirstOrDefault() ?.Ingredients .ToDictionary(i => i.Entry.Data, i => i.Size); public Dictionary MissingIngredients => - this.ToList() - .FirstOrDefault() + list.FirstOrDefault() ?.Ingredients .Where(i => i.Size - i.Entry.Count > 0) .ToDictionary(i => i.Entry, i => i.Size - i.Entry.Count); public IEnumerator GetEnumerator() { - var ingredients = blueprints - .SelectMany(b => b) - .SelectMany(b => Enumerable.Repeat(b, b.ShoppingListCount)) - .SelectMany(b => b.Ingredients) - .ToList(); + var ingredients = new Dictionary(); + foreach (var b in blueprints.SelectMany(b => b).Where(b => b.ShoppingListCount > 0)) + { + foreach (var ingredient in b.Ingredients) + { + if (!ingredients.ContainsKey(ingredient.Entry)) + { + ingredients[ingredient.Entry] = 0; + } + ingredients[ingredient.Entry] += ingredient.Size * b.ShoppingListCount; + } + } if (!ingredients.Any()) { yield break; } - var composition = ingredients.GroupBy(i => i.Entry.Data.Name) - .Select( - i => - new BlueprintIngredient(i.First().Entry, - i.Sum(c => c.Size))) + var composition = ingredients.Select(i => new BlueprintIngredient(i.Key, i.Value)) .OrderBy(i => i.Entry.Count - i.Size > 0 ? 1 : 0) .ThenByDescending(i => i.Entry.Data.Subkind) .ThenBy(i => i.Entry.Data.Kind)