Skip to content

Commit

Permalink
Fire onStashLoaded for loading inventories.
Browse files Browse the repository at this point in the history
The onStashLoaded events were not being fired when loading character
inventories, so 1) there was no loading message for these "tabs" when
refreshing [used] tabs, and 2) the appropriate actions to take when
reloading tabs were not happening.
  • Loading branch information
thailyn committed Oct 5, 2019
1 parent 9ed2ba4 commit 219b8ee
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 9 deletions.
12 changes: 10 additions & 2 deletions POEApi.Model/POEModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,22 @@ public List<Character> GetCharacters(string realm)
return GetProperObjectFromTransport<List<Character>>(Transport.GetCharacters(realm));
}

public List<Item> GetInventory(string characterName, bool forceRefresh, string accountName, string realm)
public List<Item> GetInventory(string characterName, int index, bool forceRefresh, string accountName, string realm)
{
try
{
onStashLoaded(POEEventState.BeforeEvent, index, -1);

if (downOnlyMyCharacters && !Settings.Lists["MyCharacters"].Contains(characterName))
return new List<Item>();

Inventory item = GetProperObjectFromTransport<Inventory>(Transport.GetInventory(characterName, forceRefresh, accountName, realm));
Inventory item = null;
using (var stream = Transport.GetInventory(characterName, forceRefresh, accountName, realm))
{
item = GetProperObjectFromTransport<Inventory>(stream);
}

onStashLoaded(POEEventState.AfterEvent, index, -1);

if (item?.Items == null)
return new List<Item>();
Expand Down
2 changes: 1 addition & 1 deletion POEApi.Model/Stash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private void refreshCharacterTab(POEModel currentModel, int tabId, string accoun
var charTab = Tabs.First(t => t.i == tabId);

var characterName = charTab.Name;
var characterItems = currentModel.GetInventory(characterName, true, accountName, realm);
var characterItems = currentModel.GetInventory(characterName, tabId, true, accountName, realm);
var characterStashItems = CharacterStashBuilder.GetCharacterStashItems(characterName, characterItems, tabId + 1);

items.AddRange(characterStashItems);
Expand Down
5 changes: 4 additions & 1 deletion Procurement/Controls/Equipped.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ void Equipped_Loaded(object sender, RoutedEventArgs e)

private void render()
{
equipped = new EquipedItems(ApplicationState.Model.GetInventory(Character, false, ApplicationState.AccountName, ApplicationState.CurrentRealm).Where(i => i.InventoryId != "MainInventory"));
// TODO: Get the correct tabId to use (instead of -1).
equipped = new EquipedItems(ApplicationState.Model.GetInventory(Character, -1, false,
ApplicationState.AccountName, ApplicationState.CurrentRealm).Where(
i => i.InventoryId != "MainInventory"));
davinci.Children.Clear();
Dictionary<string, Item> itemsAtPosition = equipped.GetItems();

Expand Down
4 changes: 3 additions & 1 deletion Procurement/Controls/Inventory.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ void Inventory_Loaded(object sender, RoutedEventArgs e)

private void refresh(string accountName)
{
this.Invent = ApplicationState.Model.GetInventory(Character, false, accountName, ApplicationState.CurrentRealm).Where(i => i.InventoryId == "MainInventory").ToList();
// TODO: Get the correct tabId to use (instead of -1).
this.Invent = ApplicationState.Model.GetInventory(Character, -1, false, accountName,
ApplicationState.CurrentRealm).Where(i => i.InventoryId == "MainInventory").ToList();
inventByLocation = Invent.ToDictionary(item => new Tuple<int, int>(item.X, item.Y));
render();
}
Expand Down
11 changes: 10 additions & 1 deletion Procurement/ViewModel/LoginWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,19 @@ private IEnumerable<Item> LoadCharacterInventoryItems(Character character, bool
if (!offline)
_statusController.DisplayMessage((string.Format("Loading {0}'s inventory...", character.Name)));

// TODO: It looks like the character's fake stash tab does not exist at this point. Confirm, and determine
// the best course of action at this point.
var tab = ApplicationState.Stash[character.League].Tabs.FirstOrDefault(
t => t.Name == character.Name && t.IsFakeTab);
int tabId = 0;
if (tab != null)
tabId = tab.i;

List<Item> inventory;
try
{
inventory = ApplicationState.Model.GetInventory(character.Name, false, ApplicationState.AccountName, ApplicationState.CurrentRealm);
inventory = ApplicationState.Model.GetInventory(character.Name, tabId, false, ApplicationState.AccountName,
ApplicationState.CurrentRealm);
success = true;
}
catch (WebException)
Expand Down
6 changes: 3 additions & 3 deletions Tests/POEApi.Model.Tests/PoeModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void GetInventoryTest()
{
_mockTransport.Setup(m => m.GetInventory("", false, "", Realm.PC)).Returns(stream);

var inventory = _model.GetInventory("", false, "", Realm.PC);
var inventory = _model.GetInventory("", -1, false, "", Realm.PC);

Assert.IsNotNull(inventory);
}
Expand Down Expand Up @@ -273,7 +273,7 @@ public void GetPantheonSoulInventoryTest()
using (var stream = GenerateStreamFromString(fakeInventoryInfo))
{
_mockTransport.Setup(m => m.GetInventory(string.Empty, false, string.Empty, Realm.PC)).Returns(stream);
var inventory = _model.GetInventory(string.Empty, false, string.Empty, Realm.PC);
var inventory = _model.GetInventory(string.Empty, -1, false, string.Empty, Realm.PC);

inventory.Should().NotBeNull();
inventory.Should().HaveCount(3);
Expand Down Expand Up @@ -435,7 +435,7 @@ public void GetInventoryWithQuestItemsTest()
{
_mockTransport.Setup(m => m.GetInventory("", false, "", Realm.PC)).Returns(stream);

var inventory = _model.GetInventory("", false, "", Realm.PC);
var inventory = _model.GetInventory("", -1, false, "", Realm.PC);

Assert.IsNotNull(inventory);

Expand Down

0 comments on commit 219b8ee

Please sign in to comment.