diff --git a/nekoyume/Assets/_Scripts/UI/Module/Inventory.cs b/nekoyume/Assets/_Scripts/UI/Module/Inventory.cs index 222d72990c..3ca37cd23f 100644 --- a/nekoyume/Assets/_Scripts/UI/Module/Inventory.cs +++ b/nekoyume/Assets/_Scripts/UI/Module/Inventory.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; +using Nekoyume.Action; using Nekoyume.Battle; using Nekoyume.Game.Controller; using Nekoyume.Helper; @@ -807,8 +808,8 @@ public void SetAvatarInformation( public void SetShop(Action clickItem) { _checkTradable = true; - SetAction(clickItem); - SetInventoryTab(); + SetAction(clickItem, onClickTab: OnClickTapShop); + SetInventoryTab(onUpdateInventory: OnUpdateInventoryShop); _toggleGroup.DisabledFunc = () => false; } @@ -1083,5 +1084,78 @@ public bool TryGetCellByIndex(int index, out InventoryCell cell) } #endregion + +#region ShopEvents + + private void OnClickTapShop(InventoryTabType tabType) + { + SortInventoryInShop(tabType); + } + + private void OnUpdateInventoryShop(Inventory inventory, Nekoyume.Model.Item.Inventory nekoyumeInventory) + { + SortInventoryInShop(_activeTabType); + } + + private void SortInventoryInShop(InventoryTabType tabType) + { + var data = GetModels(tabType); + if (tabType == InventoryTabType.Equipment) + { + data = data + .OrderByDescending(x => x.ItemBase is ITradableItem) + .ThenByDescending(x => x.ItemBase.Grade) + .ThenByDescending(x => CPHelper.GetCP(x.ItemBase as Equipment)) + .ToList(); + } + + if (tabType == InventoryTabType.Consumable) + { + data = data + .OrderByDescending(x => x.ItemBase is ITradableItem) + .ThenByDescending(x => x.ItemBase.Grade) + .ToList(); + } + + if (tabType == InventoryTabType.Material) + { + data = data + .OrderByDescending(x => x.ItemBase is ITradableItem) + .ThenByDescending(x => x.ItemBase.Grade) + .ToList(); + } + + if (tabType == InventoryTabType.Costume) + { + var costumeSheet = Game.Game.instance.TableSheets.CostumeStatSheet; + data = data + .OrderByDescending(x => x.ItemBase is ITradableItem) + .ThenByDescending(x => x.ItemBase.Grade) + .ThenByDescending(x => CPHelper.GetCP(x.ItemBase as Costume, costumeSheet)) + .ToList(); + } + + if (tabType == InventoryTabType.FungibleAsset) + { + var runeListSheet = Game.Game.instance.TableSheets.RuneListSheet; + data = data + .OrderByDescending(x => x.Tradable.Value) + .ThenByDescending(x => x.ItemBase is ITradableItem) + .ThenByDescending(x => + { + if (!RuneFrontHelper.TryGetRuneData(x.FungibleAssetValue.Currency.Ticker, out var value)) + { + return 0; + } + + return runeListSheet.TryGetValue(value.id, out var row) ? row.Grade : 0; + }) + .ToList(); + } + + scroll.UpdateData(data); + } + +#endregion ShopEvents } }