Skip to content

Commit

Permalink
GGG are sending duplicate item data in the json, added check to disca…
Browse files Browse the repository at this point in the history
…rd duplicates for stash rendering
  • Loading branch information
Stickymaddness committed Aug 22, 2014
1 parent 4a1b635 commit bb4d4dd
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions Procurement/Controls/StashControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using POEApi.Model;
using Procurement.ViewModel;
using Procurement.ViewModel.Filters;
using System.Diagnostics;
using POEApi.Infrastructure;

namespace Procurement.Controls
{
Expand All @@ -34,7 +36,7 @@ public void ForceUpdate()
refresh();

FilterResults = Filter.Count() == 0 ? -1 : 0;

foreach (var item in Stash)
updateResult(borderByLocation[Tuple.Create<int, int>(item.X, item.Y)], search(item));

Expand Down Expand Up @@ -69,6 +71,7 @@ public StashControl()
InitializeComponent();
this.Loaded += new RoutedEventHandler(StashControl_Loaded);
ApplicationState.LeagueChanged += new System.ComponentModel.PropertyChangedEventHandler(ApplicationState_LeagueChanged);
stashByLocation = new Dictionary<Tuple<int, int>, Item>();
}

void ApplicationState_LeagueChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
Expand All @@ -84,14 +87,32 @@ void StashControl_Loaded(object sender, RoutedEventArgs e)
refresh();
}

Dictionary<string, Item> test = new Dictionary<string, Item>();

private void refresh()
{
this.Stash = ApplicationState.Stash[ApplicationState.CurrentLeague].GetItemsByTab(TabNumber);
stashByLocation = Stash.ToDictionary(item => new Tuple<int, int>(item.X, item.Y));
borderByLocation = new Dictionary<Tuple<int, int>, Border>();
updateStashByLocation();
render();
}

private void updateStashByLocation()
{

stashByLocation.Clear();


foreach (var item in this.Stash)
{
var key = Tuple.Create<int, int>(item.X, item.Y);

if (stashByLocation.ContainsKey(key))
continue;

stashByLocation.Add(key, item);
}
}

private void render()
{
const int columns = 12, rows = 12;
Expand All @@ -100,6 +121,8 @@ private void render()
grid.RowDefinitions.Clear();
grid.Children.Clear();

borderByLocation = new Dictionary<Tuple<int, int>, Border>();

for (int i = 0; i < columns; i++)
{
grid.ColumnDefinitions.Add(new ColumnDefinition());
Expand All @@ -110,7 +133,7 @@ private void render()

Grid childGrid = new Grid();
childGrid.Margin = new Thickness(1);

Tuple<int, int> currentKey = new Tuple<int, int>(i, j);

if (!stashByLocation.ContainsKey(currentKey))
Expand Down Expand Up @@ -168,7 +191,7 @@ private void setBackround(Grid childGrid, Item item)
childGrid.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#21007F"));



childGrid.Background.Opacity = 0.3;
}

Expand Down

0 comments on commit bb4d4dd

Please sign in to comment.