diff --git a/Procurement/Controls/StashControl.xaml.cs b/Procurement/Controls/StashControl.xaml.cs index 776e2752..e074e08d 100644 --- a/Procurement/Controls/StashControl.xaml.cs +++ b/Procurement/Controls/StashControl.xaml.cs @@ -9,6 +9,8 @@ using POEApi.Model; using Procurement.ViewModel; using Procurement.ViewModel.Filters; +using System.Diagnostics; +using POEApi.Infrastructure; namespace Procurement.Controls { @@ -34,7 +36,7 @@ public void ForceUpdate() refresh(); FilterResults = Filter.Count() == 0 ? -1 : 0; - + foreach (var item in Stash) updateResult(borderByLocation[Tuple.Create(item.X, item.Y)], search(item)); @@ -69,6 +71,7 @@ public StashControl() InitializeComponent(); this.Loaded += new RoutedEventHandler(StashControl_Loaded); ApplicationState.LeagueChanged += new System.ComponentModel.PropertyChangedEventHandler(ApplicationState_LeagueChanged); + stashByLocation = new Dictionary, Item>(); } void ApplicationState_LeagueChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) @@ -84,14 +87,32 @@ void StashControl_Loaded(object sender, RoutedEventArgs e) refresh(); } + Dictionary test = new Dictionary(); + private void refresh() { this.Stash = ApplicationState.Stash[ApplicationState.CurrentLeague].GetItemsByTab(TabNumber); - stashByLocation = Stash.ToDictionary(item => new Tuple(item.X, item.Y)); - borderByLocation = new Dictionary, Border>(); + updateStashByLocation(); render(); } + private void updateStashByLocation() + { + + stashByLocation.Clear(); + + + foreach (var item in this.Stash) + { + var key = Tuple.Create(item.X, item.Y); + + if (stashByLocation.ContainsKey(key)) + continue; + + stashByLocation.Add(key, item); + } + } + private void render() { const int columns = 12, rows = 12; @@ -100,6 +121,8 @@ private void render() grid.RowDefinitions.Clear(); grid.Children.Clear(); + borderByLocation = new Dictionary, Border>(); + for (int i = 0; i < columns; i++) { grid.ColumnDefinitions.Add(new ColumnDefinition()); @@ -110,7 +133,7 @@ private void render() Grid childGrid = new Grid(); childGrid.Margin = new Thickness(1); - + Tuple currentKey = new Tuple(i, j); if (!stashByLocation.ContainsKey(currentKey)) @@ -168,7 +191,7 @@ private void setBackround(Grid childGrid, Item item) childGrid.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#21007F")); - + childGrid.Background.Opacity = 0.3; }