UPF/Assets/Game/Scripts/Minigame/Skin/RocketUpgradePanel.cs
2022-10-22 00:29:09 +05:30

66 lines
2.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
public class RocketUpgradePanel : MonoBehaviour
{
public TMP_Text txtEnergyGain;
public TMP_Text txtSpeed;
public TMP_Text txtBoostConsumption;
public TMP_Text txtLevel;
public TMP_Text txtCostGold;
public TMP_Text txtCostMetal;
public Button btn_upgrade;
RocketLevel CurrentLevel,NextLevel;
SkinShopItemData selectedRocket;
public bool Affordable => DBmanager.Metal >= NextLevel.metalCost && DBmanager.Coins >= NextLevel.goldCost;
void Awake(){
btn_upgrade.onClick.AddListener(OnUpgrade);
}
public void Show(RocketLevel currentLevel, RocketLevel nextLevel, SkinShopItemData rocketData){
CurrentLevel = currentLevel;
NextLevel = nextLevel;
selectedRocket = rocketData;
txtLevel.text = "Level " +currentLevel.Level;
txtEnergyGain.text = $"{currentLevel.moonMultiplier} Per moon";
txtSpeed.text = $"{currentLevel.speedMultiplier*100}%";
txtBoostConsumption.text = $"{currentLevel.boostConsumption*100}%";
if(nextLevel != null){
txtLevel.text += $" -> <color=green> Level {nextLevel.Level}</color>";
txtEnergyGain.text += $" -> <color=green> {nextLevel.moonMultiplier}</color>";
txtSpeed.text += $" -> <color=green> {nextLevel.speedMultiplier*100}%</color>";
txtBoostConsumption.text += $" -> <color=green> {nextLevel.boostConsumption*100}%</color>";
}
btn_upgrade.interactable = Affordable;
txtCostGold.text = nextLevel.goldCost.ToString();
txtCostMetal.text = nextLevel.metalCost.ToString();
txtCostGold.transform.parent.gameObject.SetActive(nextLevel.goldCost > 0);
txtCostMetal.transform.parent.gameObject.SetActive(nextLevel.metalCost > 0);
gameObject.SetActive(true);
}
void OnUpgrade(){
if(!Affordable){
MessageDialog.instance.ShowMessage("Error","Not enough resources to upgrade.");
return;
}
DBmanager.UpgradeRocket(selectedRocket.name, NextLevel);
SkinShopManager.instance.Populate();
MessageDialog.instance.ShowMessage("Success","Rocket Upgraded Successfully!");
AudioManager.instnace.ChestOpen();
Hide();
}
public void Hide(){
gameObject.SetActive(false);
}
}