using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using TMPro; using UnityEngine; using UnityEngine.UI; public enum ShopItemCardMode { Buy, Sell } class ShopItemCardKeeper : MonoBehaviour { [Header("Current Item")] public EquippableItem SelectedItem; public int OriginSlotNumver; [Header("Shopping Card")] [SerializeField] private Button _buyButton; [SerializeField] private Button _sellButton; [Header("Item Preveiw Section")] [SerializeField] public ShopItemCardMode ShopMode; [SerializeField] private TextMeshProUGUI _itemPreviewName; [SerializeField] private TextMeshProUGUI _itemPreviewDescription; [SerializeField] private TextMeshProUGUI _itemPreviewStats; [SerializeField] private TextMeshProUGUI _itemPreviewStatsValue; [SerializeField] private Text _itemPreviewPrice; public void ShowItemDetails(ItemSlot itemSlot, ShopItemCardMode mode = ShopItemCardMode.Buy) { SelectedItem = itemSlot.Item; OriginSlotNumver = itemSlot.Number; ShopMode = mode; gameObject.active = true; BildCardContent(); } public void BildCardContent() { // Clear poanel if (!SelectedItem) { _itemPreviewName.text = ""; _itemPreviewDescription.text = ""; _itemPreviewStats.text = ""; _itemPreviewStatsValue.text = ""; _itemPreviewPrice.text = ""; _buyButton.gameObject.SetActive(false); _sellButton.gameObject.SetActive(false); return; } _itemPreviewName.text = SelectedItem.Name; _itemPreviewDescription.text = SelectedItem.Description; _itemPreviewStats.text = BuildItemStats(); _itemPreviewStatsValue.text = SelectedItem.Value.ToString(); _itemPreviewPrice.text = $"Price: {CountPrice()}"; switch(ShopMode) { case ShopItemCardMode.Buy: { _sellButton.gameObject.SetActive(false); _buyButton.gameObject.SetActive(true); break; } case ShopItemCardMode.Sell: { _buyButton.gameObject.SetActive(false); _sellButton.gameObject.SetActive(true); break; } } } public string BuildItemStats() { if(SelectedItem.EquipmentType == EquipmentTypeEnum.Weapon) return $"Attack: \n"; if (SelectedItem.EquipmentType == EquipmentTypeEnum.Helmet || SelectedItem.EquipmentType == EquipmentTypeEnum.Chest) return $"Deffence: \n"; if (SelectedItem.EquipmentType == EquipmentTypeEnum.Boots) return $"Speed: \n"; return ""; } public int CountPrice() { return SelectedItem.Price; } public void BuyItem() { Debug.Log("Buy item"); if (!_buyButton.IsActive()) return; // TODO - CHECK PLAYER ACCOUNT // 1. Buy transaction // 1.1.1 Add to player Inventory Panel + refresh view InventoryUIManager.Instance.Add(SelectedItem); if (InventoryUIManager.Instance.GetPanelStatus()) GameObject.FindObjectOfType().BuildPanelContent(InventoryUIManager.Instance.GetList()); // 1.1.2 Save chnages in Inventory Panel SceneInventoryDataManager.Instance.SaveDynamicData(); // 1.2.1 Remove item from Shop Panel ShopContentUIManager.Instance.RemoveByPosition(OriginSlotNumver); if (ShopUIManager.Instance.GetPanelStatus()) GameObject.FindObjectOfType().BuildPanelContent(ShopContentUIManager.Instance.GetList()); // 1.2.2 Save chnages in Shop Panel SceneInventoryDataManager.Instance.SaveDynamicData(); // 2. TODO - Player gold change & save } public void SellItem() { Debug.Log("Sell item"); if (!_sellButton.IsActive()) return; // 1. Sell transaction // 1.1.1 Remove from player Inventory Panel by position + refresh view InventoryUIManager.Instance.RemoveByPosition(OriginSlotNumver); if (InventoryUIManager.Instance.GetPanelStatus()) GameObject.FindObjectOfType().BuildPanelContent(InventoryUIManager.Instance.GetList()); // 1.1.2 Save chnages in Inventory Panel SceneInventoryDataManager.Instance.SaveDynamicData(); // 2. TODO - Player gold change & save } }