81 lines
2.8 KiB
C#
81 lines
2.8 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
|
|
|
|
public class BuyListing : MonoBehaviour
|
|
{
|
|
[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;
|
|
|
|
[SerializeField] private Button buyButton;
|
|
private TMP_Text buyButtonText;
|
|
|
|
[SerializeField] private Slider buyListingAmountSlider;
|
|
[SerializeField] private TMP_Text buyListingAmountText;
|
|
|
|
|
|
private int itemID;
|
|
private int itemCost;
|
|
private int itemAmount;
|
|
private string sellerName;
|
|
private int totalPurchaseCost;
|
|
private int totalPurchaseAmount = 1;
|
|
private void Awake()
|
|
{
|
|
totalPurchaseAmount = 1;
|
|
buyListingAmountSlider.minValue = 1;
|
|
buyListingAmountSlider.value = 1;
|
|
buyButton.onClick.AddListener(HandleBuy);
|
|
buyListingAmountSlider.onValueChanged.AddListener(HandleAmountSlider);
|
|
buyButtonText = buyButton.transform.GetChild(0).GetComponent<TMP_Text>();
|
|
HandleAmountSlider(1);
|
|
}
|
|
|
|
public void SetData(int itemID, string itemLevel, string itemName, int itemCost, int itemAmount, string soldByName = "")
|
|
{
|
|
itemLevelText.text = itemLevel;
|
|
itemNameText.text = itemName;
|
|
costText.text = itemCost.ToString();
|
|
itemAmountText.text = "x" + itemAmount;
|
|
soldByText.text = "Sold By: " + soldByName;
|
|
itemImage.sprite = UIManager.Instance.RenderItem(itemID);
|
|
|
|
this.itemID = itemID;
|
|
this.itemCost = itemCost;
|
|
this.itemAmount = itemAmount;
|
|
this.sellerName = soldByName;
|
|
|
|
buyListingAmountSlider.maxValue = itemAmount > 24 ? 24 : itemAmount;
|
|
buyButton.interactable = true;
|
|
|
|
//enable the center container after values assigned. (no popping)
|
|
UIManager.Instance.WeaponExchangeController.GetCenterContainer().SetActive(true);
|
|
}
|
|
|
|
private void HandleAmountSlider(float value)
|
|
{
|
|
ItemDef itemDef = ItemDef.GetInstance();
|
|
string itemLevel = itemDef.getItemLevel(itemID);
|
|
string itemName = itemDef.getItemName(itemID);
|
|
buyListingAmountText.SetText($"Amount To Buy: {value}");
|
|
buyButtonText.SetText($" Buy {value} of {itemLevel} {itemName} for {itemCost * value} Divi");
|
|
totalPurchaseCost = itemCost;
|
|
totalPurchaseAmount = (int)value;
|
|
}
|
|
|
|
private void HandleBuy()
|
|
{
|
|
PacketManager.sendChatMessage($"/buy {sellerName} {itemID} {totalPurchaseAmount} {this.itemCost}");
|
|
buyButton.interactable = false;
|
|
buyButtonText.SetText("Please Confirm Purchase On Your DiviGO Wallet.");
|
|
}
|
|
}
|