135 lines
4.0 KiB
C#
135 lines
4.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using DG.Tweening;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
using UnityEngine.EventSystems;
|
|
|
|
public class ExchangeElement : Selectable, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler
|
|
{
|
|
[SerializeField] private TMP_Text itemLevelText;
|
|
[SerializeField] private TMP_Text itemNameText;
|
|
|
|
[SerializeField] private TMP_Text costText;
|
|
[SerializeField] private Image itemImage;
|
|
[SerializeField] private TMP_Text itemAmountText;
|
|
|
|
[SerializeField] private TMP_Text soldByText;
|
|
|
|
public ExchangeElementType ExchangeType;
|
|
|
|
[SerializeField] private Image SelectionOutline;
|
|
private WeaponStatsManager statsManager;
|
|
|
|
private int itemID;
|
|
private string itemLevel;
|
|
private string itemName;
|
|
private int itemAmount;
|
|
private int itemCost;
|
|
private string sellerName;
|
|
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
interactable = false;
|
|
}
|
|
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
statsManager = UIManager.Instance.WeaponStatsManager;
|
|
}
|
|
|
|
public void SetData(ExchangeElementType type, int itemID, string itemLevel, string itemName, int cost, int itemAmount, string soldByName = "")
|
|
{
|
|
ExchangeType = type;
|
|
itemLevelText.text = itemLevel;
|
|
itemNameText.text = itemName;
|
|
costText.text = cost.ToString();
|
|
itemAmountText.text = "x" + itemAmount;
|
|
soldByText.text = ExchangeType == ExchangeElementType.BUY ? "Sold By: " + soldByName : "Your Item";
|
|
itemImage.sprite = UIManager.Instance.RenderItem(itemID);
|
|
|
|
this.itemID = itemID;
|
|
this.itemLevel = itemLevel;
|
|
this.itemName = itemName;
|
|
this.itemAmount = itemAmount;
|
|
this.itemCost = cost;
|
|
this.sellerName = soldByName;
|
|
|
|
if (ExchangeType != ExchangeElementType.NONE) { interactable = true; }
|
|
|
|
//TODO
|
|
//Add clicking func based on ExchangeType. Sell == enable / handle delisting functionality.
|
|
//Buy == configure center menu and actual buying functionality.
|
|
//None == nothing.
|
|
}
|
|
public void OnPointerClick(PointerEventData eventData)
|
|
{
|
|
if (ExchangeType == ExchangeElementType.NONE) return;
|
|
HandleSelection();
|
|
}
|
|
public override void OnPointerEnter(PointerEventData eventData)
|
|
{
|
|
if (ExchangeType == ExchangeElementType.NONE) return;
|
|
ShowWeaponStats();
|
|
}
|
|
public override void OnPointerExit(PointerEventData eventData)
|
|
{
|
|
if (ExchangeType == ExchangeElementType.NONE) return;
|
|
HideWeaponStats();
|
|
}
|
|
|
|
public override void OnSelect(BaseEventData data)
|
|
{
|
|
base.OnSelect(data);
|
|
if (ExchangeType == ExchangeElementType.NONE) return;
|
|
if (!Player.Instance.GetInputHandler().UsingGamePad) return;
|
|
|
|
ShowWeaponStats();
|
|
HandleSelection();
|
|
}
|
|
|
|
public override void OnDeselect(BaseEventData data)
|
|
{
|
|
base.OnDeselect(data);
|
|
if (ExchangeType == ExchangeElementType.NONE) return;
|
|
if (!Player.Instance.GetInputHandler().UsingGamePad) return;
|
|
|
|
HideWeaponStats();
|
|
HandleSelection();
|
|
}
|
|
|
|
private void ShowWeaponStats()
|
|
{
|
|
statsManager.GetCanvasGroup().DOFade(1, 0.15f);
|
|
statsManager.SetWeaponStatData(OpenWeaponStatType.Exchange, itemID);
|
|
}
|
|
private void HideWeaponStats()
|
|
{
|
|
statsManager.GetCanvasGroup().DOFade(0, 0.15f);
|
|
}
|
|
|
|
private void HandleSelection()
|
|
{
|
|
WeaponExchangeController exchangeController = UIManager.Instance.WeaponExchangeController;
|
|
if (ExchangeType == ExchangeElementType.BUY)
|
|
{
|
|
exchangeController.BuyListing.SetData(itemID, itemLevel, itemName, itemCost, itemAmount, sellerName);
|
|
}
|
|
else if (ExchangeType == ExchangeElementType.SELL)
|
|
{
|
|
exchangeController.SetDelistItemData(itemID, itemAmount, itemCost, itemName);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public enum ExchangeElementType
|
|
{
|
|
NONE,
|
|
BUY,
|
|
SELL
|
|
}
|