139 lines
3.5 KiB
C#
139 lines
3.5 KiB
C#
using BitStrap;
|
|
using UIWidgets;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class EquipmentTileViewComponent : ListViewItem
|
|
{
|
|
[SerializeField]
|
|
public Image icon;
|
|
|
|
public Image iconEquiped;
|
|
|
|
public Image iconBought;
|
|
|
|
public Image iconProducer;
|
|
|
|
public Image separator;
|
|
|
|
[SerializeField]
|
|
public Text equipmentName;
|
|
|
|
public Text amount;
|
|
|
|
[ReadOnly]
|
|
public EquipmentObject equipmentObject;
|
|
|
|
public GameObject dlcInfoParent;
|
|
|
|
public Image dlcBanner;
|
|
|
|
public bool SetNativeSize = true;
|
|
|
|
public EquipmentTileView equipmentTileView;
|
|
|
|
public void Remove()
|
|
{
|
|
equipmentTileView.DataSource.RemoveAt(Index);
|
|
}
|
|
|
|
public void SetData(EquipmentTileViewItem item)
|
|
{
|
|
if (item == null)
|
|
{
|
|
icon.sprite = null;
|
|
iconProducer.sprite = null;
|
|
equipmentName.text = string.Empty;
|
|
}
|
|
else
|
|
{
|
|
if ((bool)item.icon)
|
|
{
|
|
icon.sprite = item.icon;
|
|
icon.rectTransform.sizeDelta = new Vector2(icon.rectTransform.sizeDelta.y * (item.icon.rect.width / item.icon.rect.height), icon.rectTransform.sizeDelta.y);
|
|
}
|
|
equipmentObject = item.equipmentObject;
|
|
iconEquiped.gameObject.SetActive(equipmentTileView.equipmentGui.IsEquippedInCurrentSet(equipmentObject));
|
|
if (equipmentObject.hasAmount)
|
|
{
|
|
iconBought.gameObject.SetActive(equipmentObject.amount > 0 || equipmentObject.isEquipped);
|
|
}
|
|
else
|
|
{
|
|
iconBought.gameObject.SetActive(equipmentObject.isBought);
|
|
}
|
|
if (!equipmentObject.hasAmount)
|
|
{
|
|
amount.text = string.Empty;
|
|
}
|
|
else if (equipmentObject.amount > 0 || equipmentObject.isEquipped)
|
|
{
|
|
amount.text = equipmentObject.amount.ToString();
|
|
}
|
|
else
|
|
{
|
|
amount.text = string.Empty;
|
|
}
|
|
iconProducer.sprite = equipmentObject.producerIcon;
|
|
equipmentName.text = equipmentObject.GetFullName();
|
|
}
|
|
if (SetNativeSize)
|
|
{
|
|
icon.SetNativeSize();
|
|
}
|
|
icon.color = ((!(icon.sprite == null)) ? Color.white : Color.clear);
|
|
iconProducer.gameObject.SetActive(iconProducer.sprite != null);
|
|
RefreshDLC();
|
|
}
|
|
|
|
[Button]
|
|
public void Refresh()
|
|
{
|
|
icon.rectTransform.anchoredPosition = new Vector2(0f, 2f);
|
|
iconEquiped.rectTransform.anchoredPosition = new Vector2(65f, 35f);
|
|
iconBought.rectTransform.anchoredPosition = new Vector2(95f, 35f);
|
|
iconProducer.rectTransform.anchoredPosition = new Vector2(-80f, 36f);
|
|
separator.rectTransform.anchoredPosition = new Vector2(-5f, -63f);
|
|
equipmentName.rectTransform.anchoredPosition = new Vector2(0f, -94f);
|
|
amount.rectTransform.anchoredPosition = new Vector2(88f, 41f);
|
|
iconEquiped.gameObject.SetActive(equipmentTileView.equipmentGui.IsEquippedInCurrentSet(equipmentObject));
|
|
if (equipmentObject.hasAmount)
|
|
{
|
|
iconBought.gameObject.SetActive(equipmentObject.amount > 0 || equipmentObject.isEquipped);
|
|
}
|
|
else
|
|
{
|
|
iconBought.gameObject.SetActive(equipmentObject.isBought);
|
|
}
|
|
iconProducer.gameObject.SetActive(iconProducer.sprite != null);
|
|
if (!equipmentObject.hasAmount)
|
|
{
|
|
amount.text = string.Empty;
|
|
}
|
|
else if (equipmentObject.amount > 0 || equipmentObject.isEquipped)
|
|
{
|
|
amount.text = equipmentObject.amount.ToString();
|
|
}
|
|
else
|
|
{
|
|
amount.text = string.Empty;
|
|
}
|
|
RefreshDLC();
|
|
}
|
|
|
|
public void RefreshDLC()
|
|
{
|
|
dlcInfoParent.SetActive(!equipmentObject.isAvailableFromDLCs);
|
|
if (dlcInfoParent.activeSelf)
|
|
{
|
|
if (equipmentObject.fromDLC.Count > 0)
|
|
{
|
|
dlcBanner.sprite = DLCManager.Instance.FindDLCSettings(equipmentObject.fromDLC[0]).banner;
|
|
}
|
|
dlcInfoParent.transform.localPosition = new Vector3(0f, 12f, 0f);
|
|
dlcInfoParent.transform.localScale = new Vector3(0.6f, 0.6f, 0.6f);
|
|
dlcBanner.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|