111 lines
3.2 KiB
C#
111 lines
3.2 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
using DG.Tweening;
|
|
using Microsoft.Win32.SafeHandles;
|
|
using NaughtyAttributes;
|
|
|
|
public class ListItemPopup : MonoBehaviour
|
|
{
|
|
[SerializeField] private WeaponExchangeController exchangeController;
|
|
|
|
[SerializeField] private Image itemToListImage;
|
|
[SerializeField] private TMP_Text itemToListName;
|
|
|
|
[SerializeField] private TMP_Text itemAmountText;
|
|
|
|
[SerializeField] private Button cancelListingButton;
|
|
[SerializeField] private Button listItemButton;
|
|
[SerializeField] private Button minusAmountButton;
|
|
[SerializeField] private Button addAmountButton;
|
|
|
|
[SerializeField] private TMP_InputField costInput;
|
|
|
|
[SerializeField] private Image background;
|
|
|
|
|
|
private int itemID;
|
|
private int itemCost;
|
|
private int itemAmount;
|
|
|
|
|
|
private void OnEnable()
|
|
{
|
|
transform.localScale = Vector3.zero;
|
|
transform.DOScale(Vector3.one, 0.15f);
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
cancelListingButton.onClick.AddListener(HandleCancelListing);
|
|
listItemButton.onClick.AddListener(HandleListItem);
|
|
minusAmountButton.onClick.AddListener(HandleSubtractAmount);
|
|
addAmountButton.onClick.AddListener(HandleAddAmount);
|
|
}
|
|
|
|
public void SetListingData(int itemID, string level, string name)
|
|
{
|
|
itemToListImage.sprite = UIManager.Instance.RenderItem(itemID);
|
|
itemToListName.text = $"{level} {name}";
|
|
this.itemID = itemID;
|
|
itemAmount = InventoryManager.Instance.GetItemCount(itemID);
|
|
itemAmountText.SetText(itemAmount.ToString());
|
|
}
|
|
|
|
private void HandleCancelListing()
|
|
{
|
|
ClearData();
|
|
gameObject.SetActive(false);
|
|
exchangeController.GetSellButton().gameObject.SetActive(false);
|
|
}
|
|
|
|
private void HandleListItem()
|
|
{
|
|
itemCost = int.Parse(costInput.text);
|
|
PacketManager.sendChatMessage("/sell " + itemID + " " + itemAmount + " " + itemCost);
|
|
ClearData();
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
listItemButton.gameObject.SetActive(!string.IsNullOrEmpty(costInput.text));
|
|
}
|
|
|
|
private void HandleAddAmount()
|
|
{
|
|
InventoryManager inventoryManager = InventoryManager.Instance;
|
|
int itemCount = inventoryManager.GetItemCount(itemID);
|
|
itemAmount += 1;
|
|
itemAmount = Mathf.Clamp(itemAmount, 1, itemCount);
|
|
itemAmountText.SetText(itemAmount.ToString());
|
|
}
|
|
|
|
private void HandleSubtractAmount()
|
|
{
|
|
InventoryManager inventoryManager = InventoryManager.Instance;
|
|
itemAmount--;
|
|
if (itemAmount < 1)
|
|
{
|
|
itemAmount = inventoryManager.GetItemCount(itemID);
|
|
}
|
|
itemAmount = Mathf.Clamp(itemAmount, 1, inventoryManager.GetItemCount(itemID));
|
|
itemAmountText.SetText(itemAmount.ToString());
|
|
}
|
|
|
|
private void ClearData()
|
|
{
|
|
costInput.text = "";
|
|
itemToListImage.sprite = null;
|
|
itemToListName.text = "";
|
|
itemAmountText.text = "0";
|
|
itemAmount = 1;
|
|
itemID = -1;
|
|
itemCost = 0;
|
|
background.gameObject.SetActive(false);
|
|
}
|
|
}
|