231 lines
7.6 KiB
C#
231 lines
7.6 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using TMPro;
|
|
using UnityEngine.UI;
|
|
using NaughtyAttributes;
|
|
|
|
public class WeaponExchangeController : MonoBehaviour
|
|
{
|
|
[BoxGroup("Inventory Assignments"), SerializeField]
|
|
private Transform inventoryPlayerRender;
|
|
|
|
[BoxGroup("Inventory Assignments"), SerializeField]
|
|
private Transform inventoryEquiptmentBar;
|
|
|
|
[BoxGroup("Inventory Assignments"), SerializeField]
|
|
private Transform inventoryBanner;
|
|
|
|
[BoxGroup("Inventory Assignments"), SerializeField]
|
|
private Transform inventoryText;
|
|
|
|
[BoxGroup("Inventory Assignments"), SerializeField]
|
|
private Transform inventoryKeyCodes;
|
|
|
|
[BoxGroup("Inventory Assignments"), SerializeField]
|
|
private Transform inventoryInspectionText;
|
|
|
|
[BoxGroup("Inventory Assignments"), SerializeField]
|
|
private Image inventoryBackground;
|
|
|
|
private const float cachedInventoryBackgroundAlpha = 0.9568627f;
|
|
[SerializeField] private Transform centerSelectedContainer;
|
|
|
|
[BoxGroup("Search Functionality"), SerializeField]
|
|
private TMP_InputField searchInput;
|
|
|
|
[BoxGroup("Search Functionality"), SerializeField]
|
|
private Button searchBuyListButton;
|
|
|
|
[BoxGroup("Sell List Parents"), SerializeField]
|
|
private Transform buyListParent;
|
|
|
|
[BoxGroup("Sell List Parents"), SerializeField]
|
|
private Transform sellListParent;
|
|
|
|
[BoxGroup("Buttons"), SerializeField] private Button deListItemButton;
|
|
[BoxGroup("Buttons"), SerializeField] private Button sellItemButton;
|
|
[BoxGroup("Buttons"), SerializeField] private Button exitExchangeButton;
|
|
|
|
[BoxGroup("Exchange Element Prefab"), SerializeField]
|
|
private ExchangeElement exchangeElementPrefab;
|
|
|
|
[BoxGroup("List Item"), SerializeField]
|
|
private Image listItemBackground;
|
|
|
|
[BoxGroup("List Item"), SerializeField]
|
|
private ListItemPopup listItemPopup;
|
|
|
|
[BoxGroup("Buy Listing")] public BuyListing BuyListing;
|
|
private int listingItemID;
|
|
private string listingItemLevel;
|
|
private string listingItemName;
|
|
|
|
private int delistItemID = -1;
|
|
private int delistItemAmount = -1;
|
|
private int delistItemCost = -1;
|
|
|
|
private void OnEnable()
|
|
{
|
|
listItemBackground.gameObject.SetActive(false);
|
|
listItemPopup.gameObject.SetActive(false);
|
|
sellItemButton.gameObject.SetActive(false);
|
|
centerSelectedContainer.gameObject.SetActive(false);
|
|
deListItemButton.gameObject.SetActive(false);
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
exitExchangeButton.onClick.AddListener(HandleExitExchange);
|
|
sellItemButton.onClick.AddListener(HandleListItem);
|
|
deListItemButton.onClick.AddListener(HandleDelistItem);
|
|
searchBuyListButton.onClick.AddListener(HandleSearchBuyList);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (inventoryBanner.gameObject.activeInHierarchy)
|
|
{
|
|
ToggleInventoryMenus(false);
|
|
}
|
|
}
|
|
|
|
public Transform GetSellButton() => sellItemButton.transform;
|
|
public GameObject GetCenterContainer() => centerSelectedContainer.gameObject;
|
|
|
|
public void SetSellButtonText(string itemLevel, string itemName, int itemID)
|
|
{
|
|
sellItemButton.gameObject.SetActive(true);
|
|
sellItemButton.GetComponentInChildren<TMP_Text>().SetText($"Click To Sell{(string.IsNullOrEmpty(itemLevel) ? string.Empty : $" {itemLevel}")} {itemName}");
|
|
SetSellButtonData(itemLevel, itemName, itemID);
|
|
}
|
|
|
|
private void SetSellButtonData(string itemLevel, string itemName, int itemID)
|
|
{
|
|
this.listingItemLevel = itemLevel;
|
|
this.listingItemName = itemName;
|
|
this.listingItemID = itemID;
|
|
}
|
|
|
|
private void HandleListItem()
|
|
{
|
|
listItemPopup.gameObject.SetActive(true);
|
|
listItemBackground.gameObject.SetActive(true);
|
|
listItemPopup.SetListingData(listingItemID, listingItemLevel, listingItemName);
|
|
}
|
|
|
|
private void HandleDelistItem()
|
|
{
|
|
sellItemButton.gameObject.SetActive(false);
|
|
centerSelectedContainer.gameObject.SetActive(false);
|
|
|
|
if (delistItemID != -1)
|
|
{
|
|
PacketManager.sendChatMessage($"/delist {delistItemID} {delistItemAmount} {delistItemCost}");
|
|
ResetDelistVariables();
|
|
deListItemButton.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
|
|
public void SetDelistItemData(int delistItemID, int delistItemAmount, int delistItemCost, string itemName)
|
|
{
|
|
deListItemButton.gameObject.SetActive(true);
|
|
this.delistItemID = delistItemID;
|
|
this.delistItemAmount = delistItemAmount;
|
|
this.delistItemCost = delistItemCost;
|
|
deListItemButton.GetComponentInChildren<TMP_Text>().SetText($"De-List {itemName}");
|
|
centerSelectedContainer.gameObject.SetActive(false);
|
|
}
|
|
|
|
public void UpdateBuyItems(int[] ids, int[] amounts, int[] prices, string[] sellernames)
|
|
{
|
|
foreach (Transform element in buyListParent)
|
|
{
|
|
Destroy(element.gameObject);
|
|
}
|
|
|
|
int size = ids.Length;
|
|
ItemDef itemDef = ItemDef.GetInstance();
|
|
|
|
for (int i = 0; i < size; i++)
|
|
{
|
|
ExchangeElement element = Instantiate(exchangeElementPrefab, buyListParent);
|
|
int itemID = ids[i];
|
|
int itemAmount = amounts[i];
|
|
string itemLevel = itemDef.getItemLevel(ids[i]);
|
|
string itemName = itemDef.getItemName(ids[i]);
|
|
int itemCost = prices[i];
|
|
string sellerName = sellernames[i];
|
|
|
|
element.SetData(ExchangeElementType.BUY, itemID, itemLevel, itemName, itemCost, itemAmount, sellerName);
|
|
}
|
|
}
|
|
|
|
public void UpdateSellItems(int[] ids, int[] amounts, int[] prices)
|
|
{
|
|
foreach (Transform element in sellListParent)
|
|
{
|
|
Destroy(element.gameObject);
|
|
}
|
|
|
|
int size = ids.Length;
|
|
ItemDef itemDef = ItemDef.GetInstance();
|
|
|
|
for (int i = 0; i < size; i++)
|
|
{
|
|
ExchangeElement element = Instantiate(exchangeElementPrefab, sellListParent);
|
|
int itemID = ids[i];
|
|
int itemAmount = amounts[i];
|
|
string itemLevel = itemDef.getItemLevel(ids[i]);
|
|
string itemName = itemDef.getItemName(ids[i]);
|
|
int itemCost = prices[i];
|
|
|
|
element.SetData(ExchangeElementType.SELL, itemID, itemLevel, itemName, itemCost, itemAmount);
|
|
}
|
|
}
|
|
|
|
private void HandleSearchBuyList()
|
|
{
|
|
string input = searchInput.text;
|
|
PacketManager.sendChatMessage("/search " + input.Trim());
|
|
}
|
|
|
|
private void ToggleInventoryMenus(bool isOn)
|
|
{
|
|
inventoryEquiptmentBar.gameObject.SetActive(isOn);
|
|
inventoryPlayerRender.gameObject.SetActive(isOn);
|
|
inventoryBanner.gameObject.SetActive(isOn);
|
|
inventoryText.gameObject.SetActive(isOn);
|
|
inventoryInspectionText.gameObject.SetActive(isOn);
|
|
inventoryKeyCodes.gameObject.SetActive(isOn);
|
|
|
|
Color tempCol = inventoryBackground.color;
|
|
tempCol.a = isOn ? cachedInventoryBackgroundAlpha : 1.0f;
|
|
inventoryBackground.color = tempCol;
|
|
}
|
|
|
|
private void HandleExitExchange()
|
|
{
|
|
PacketManager.sendChatMessage("/closeExchange");
|
|
searchInput.text = "";
|
|
UIManager.Instance.Inventory.SetActive(false);
|
|
gameObject.SetActive(false);
|
|
Player.Instance.UpdatePlayerOnMenuClose();
|
|
UIManager.Instance.WeaponStatsManager.GetCanvasGroup().alpha = 0;
|
|
}
|
|
|
|
private void ResetDelistVariables()
|
|
{
|
|
delistItemID = -1;
|
|
delistItemAmount = -1;
|
|
delistItemCost = -1;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
ToggleInventoryMenus(true);
|
|
UIManager.Instance.WeaponStatsManager?.HideCall();
|
|
}
|
|
} |