UPF/Assets/Game/Scripts/Minigame/Skin/SkinShopItem.cs
2023-02-24 22:14:55 +05:30

123 lines
4.3 KiB
C#
Executable File

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class SkinShopItem : MonoBehaviour
{
public Image spaceshipImg;
[Tooltip("In order of: normal, rare, legendary. 5 items required")]
public GameObject[] banners;
public Image frame;
public bool Available;
// public GameObject notPurchasedIndicator;
public SkinShopItemData skinData;
[Header("Stats")]
public TMP_Text txtLevel;
public TMP_Text txtEnergyGain;
public TMP_Text txtSpeed;
public TMP_Text txtBoostConsumption;
public float curSpeed => SkinShopManager.GetStatsForRarity(rarity)[curSpeedLevel].speedMultiplier;
public float curEnergy => SkinShopManager.GetStatsForRarity(rarity)[curEnergyLevel].moonMultiplier;
public float curBoost => SkinShopManager.GetStatsForRarity(rarity)[curBoostLevel].boostConsumption;
SkinType rarity;
int curSpeedLevel;
int curEnergyLevel;
int curBoostLevel;
public int curRocketLevel => Mathf.Clamp(curBoostLevel + curEnergyLevel + curSpeedLevel+1,1,10);
public void Set(SkinShopItemData data, bool available){
skinData = data;
// newItem.backgroundImg.color = (skinsData.skins[i].skinType==SkinType.Base) ? basicColor : (skinsData.skins[i].skinType==SkinType.Rare ? rareColor : legendaryColor);
if(available){spaceshipImg.sprite = data.image;}
spaceshipImg.color = available ? Color.white : Color.black;
Available = available;
UpdateFrame();
if(data.price_metal <=0 && data.price_gold <=0){
banners[0].SetActive(true);
banners[1].SetActive(false);
}else{
banners[0].SetActive(false);
banners[1].SetActive(data.skinType== SkinType.Base);
}
banners[2].SetActive(data.skinType== SkinType.Rare);
banners[3].SetActive(data.skinType== SkinType.Epic);
banners[4].SetActive(data.skinType== SkinType.Legendary);
//Level
rarity = SkinShopManager.GetRarityFromName(data.name);
PurchasedSkin purchasedSkin = DBmanager.GetSkinByName(data.name);
if(purchasedSkin != null){
curSpeedLevel = purchasedSkin.speedLevel;
curEnergyLevel = purchasedSkin.energyLevel;
curBoostLevel = purchasedSkin.boostLevel;
}
txtLevel.text = "Level " +curRocketLevel;
txtEnergyGain.transform.parent.gameObject.SetActive(available);
txtSpeed.transform.parent.gameObject.SetActive(available);
txtBoostConsumption.transform.parent.gameObject.SetActive(available);
if(available){
txtEnergyGain.text = curEnergy.ToString();
txtSpeed.text = (curSpeed * 100).ToString("n0") + "%";
txtBoostConsumption.text = (curBoost * 100).ToString("n0") + "%";
}
}
public void UpdateFrame(){
if(SkinShopManager.GetEquipedSkin() == skinData.name){
frame.enabled=true;
frame.color = Color.cyan;
}else{
frame.enabled=false;
}
if(DBmanager.GetSkinIdByName(skinData.name) < 0){
frame.color = Color.red;
// notPurchasedIndicator.SetActive(true);
// notPurchasedIndicator.GetComponentInChildren<TMP_Text>().text = skinData.price.ToString();
}else{
// notPurchasedIndicator.SetActive(false);
}
if(!Available){
// notPurchasedIndicator.SetActive(false);
}
}
public void OnClick(){
SkinShopManager.instance.SelectItem(skinData,Available);
}
public void OnSelectionChanged(string selectedItem){
if(selectedItem == skinData.name){
frame.enabled=true;
}else{
frame.enabled = false;
}
if(SkinShopManager.GetEquipedSkin() == skinData.name){
frame.enabled = true;
}
}
// void onEquip(){
// SkinShopManager.EquipSkin(name);
// SkinShopManager.instance.Populate();
// }
// void onBuy(){
// SkinShopItemData data = new SkinShopItemData(){name=name, price=price};
// DBmanager.PurchaseSkin(data);
// SkinShopManager.instance.Populate();
// }
}