using System.Collections.Generic;
using System.Linq;
using Assets.HeroEditor4D.InventorySystem.Scripts.Data;
using Assets.HeroEditor4D.InventorySystem.Scripts.Enums;
using UnityEngine;
using UnityEngine.UI;
namespace Assets.HeroEditor4D.InventorySystem.Scripts.Elements
{
///
/// Represents item when it was selected. Displays icon, name, price and properties.
///
public class ItemInfo : MonoBehaviour
{
public GameObject Selection;
public GameObject Buttons;
public Text Name;
public Text Labels;
public Text Values;
public Text Price;
public Image Icon;
public Image Background;
public Item Item { get; protected set; }
protected static readonly List Sorting = new List
{
PropertyId.Damage,
PropertyId.StaminaMax,
PropertyId.Blocking,
PropertyId.Resistance
};
public void OnEnable()
{
if (Item == null)
{
Reset();
}
}
public void Reset()
{
Selection.SetActive(false);
Buttons.SetActive(false);
if (Name) Name.text = null;
if (Labels) Labels.text = null;
if (Values) Values.text = null;
if (Price) Price.text = null;
}
public virtual void Initialize(Item item, int price, bool trader = false)
{
Item = item;
if (item == null)
{
Reset();
return;
}
Selection.SetActive(true);
Buttons.SetActive(true);
Name.text = item.Params.GetLocalizedName(Application.systemLanguage.ToString());
Icon.sprite = ItemCollection.Active.FindIcon(item.Params.IconId);
Background.sprite = ItemCollection.Active.GetBackground(item);
UpdatePrice(item, price, trader);
var main = new List