97 lines
2.4 KiB
C#
97 lines
2.4 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class ShopOfferPage : MonoBehaviour
|
|
{
|
|
public Text itemName;
|
|
|
|
public Text itemDescription;
|
|
|
|
public Text itemPrice;
|
|
|
|
public Text itemPriceOff;
|
|
|
|
public Button buyButton;
|
|
|
|
public Button addToBasketButton;
|
|
|
|
public Text[] itemStatsLabels;
|
|
|
|
public Text[] itemStatsValues;
|
|
|
|
public Image itemImage;
|
|
|
|
public Image brandLogo;
|
|
|
|
public Image[] itemRenders;
|
|
|
|
public ShopManager.Categories category;
|
|
|
|
public int itemID;
|
|
|
|
public ShopManager.Categories itemCategory;
|
|
|
|
public string sortName = "ALL";
|
|
|
|
public float itemPriceValue;
|
|
|
|
public Color overPriceColor = Color.red;
|
|
|
|
private ShopManager shopManager;
|
|
|
|
private int levelReq;
|
|
|
|
public static event Action OnUIBuyGlobal;
|
|
|
|
public static event Action OnUIAddBasketGlobal;
|
|
|
|
private void Start()
|
|
{
|
|
shopManager = UnityEngine.Object.FindObjectOfType<ShopManager>();
|
|
if (!(itemPrice == null))
|
|
{
|
|
GameManager.ItemType itemType = shopManager.CastItemCategoryToType(category);
|
|
int gameItemIndexByItemId = GameManager.Instance._playerData.GetGameItemIndexByItemId(itemType, itemID);
|
|
levelReq = shopManager.GetLevelReq(itemType, gameItemIndexByItemId);
|
|
if ((itemPriceValue > Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerCash || levelReq > Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerLevel) && !Singleton<SaveDataManager>.Instance.IsCurrentlySandbox())
|
|
{
|
|
itemPrice.color = overPriceColor;
|
|
buyButton.interactable = false;
|
|
addToBasketButton.interactable = false;
|
|
}
|
|
else
|
|
{
|
|
itemPrice.color = Color.white;
|
|
buyButton.interactable = true;
|
|
addToBasketButton.interactable = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
}
|
|
|
|
public void AddToBasket()
|
|
{
|
|
Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerShopBasket.AddToBasket(category, itemID, itemPriceValue, sortName);
|
|
shopManager.UpdatebasketCounter();
|
|
ShopOfferPage.OnUIAddBasketGlobal?.Invoke();
|
|
UnityEngine.Object.FindObjectOfType<MyBasketInfo>().UpdateMyBasket();
|
|
}
|
|
|
|
public void Show3DModel()
|
|
{
|
|
Debug.Log("Show: " + itemCategory.ToString() + " id:" + itemID);
|
|
shopManager.Show3Dmodel(itemCategory, itemID);
|
|
}
|
|
|
|
public void BuyItemOneByButton()
|
|
{
|
|
shopManager.BuyItem(category, itemID, 1, itemPriceValue, sortName);
|
|
ShopOfferPage.OnUIBuyGlobal?.Invoke();
|
|
GameManager.Instance.ShowMessagePopup(LanguageManager.Instance.GetText("BUY_ONE_DONE"), shopManager.transform, deleteLast: true);
|
|
}
|
|
}
|