Files
Fishing2/Assets/Scripts/UI/Shops/ShopItemHelper.cs
2026-02-20 21:03:17 +08:00

42 lines
1.2 KiB
C#

using System.Collections.Generic;
using Fantasy;
namespace NBF
{
public static class ShopItemHelper
{
public static List<TabItemData> ToTabItemData(this List<ShopItemInfo> shopItems)
{
List<TabItemData> ret = new List<TabItemData>();
Dictionary<ItemType, List<ShopItemInfo>> tabDic = new Dictionary<ItemType, List<ShopItemInfo>>();
foreach (var shopItemInfo in shopItems)
{
var type = shopItemInfo.ItemType;
if (!tabDic.ContainsKey(type))
{
tabDic.Add(type, new List<ShopItemInfo>());
}
tabDic[type].Add(shopItemInfo);
}
foreach (var (key, list) in tabDic)
{
list.Sort((x, y) => (int)(y.Price1 - x.Price1));
}
foreach (var (type, list) in tabDic)
{
TabItemData tabItem = new TabItemData
{
Key = type.ToString()
};
tabItem.Items.AddRange(list);
ret.Add(tabItem);
}
return ret;
}
}
}