155 lines
5.7 KiB
C#
155 lines
5.7 KiB
C#
using UnityEngine.UI;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using TMPro;
|
|
public class SelectedItemMenu : MonoBehaviour
|
|
{
|
|
public Text nameTxt;
|
|
public Button upgradeMenuBtn;
|
|
public Button infoBtn;
|
|
public CollectBtn collectBtn;
|
|
// public Button joinHallBtn;
|
|
public Button repairRocketsBtn;
|
|
|
|
[Header("info menu")]
|
|
public GameObject infoMenu;
|
|
public GameObject[] tierIndicators;
|
|
public TMP_Text buildingName;
|
|
public TMP_Text descriptionTxt;
|
|
|
|
[Header("upgrade menu")]
|
|
public GameObject upgradeMenu;
|
|
public Transform upgrade_statParent;
|
|
public GameObject[] upgrade_tierIndicators;
|
|
public TMP_Text upgrade_buildingName;
|
|
public Button upgradeBtn;
|
|
|
|
[Header("Special buildings")]
|
|
public BuildingData mainHall;
|
|
public BuildingData rocketRepair;
|
|
|
|
void Start()
|
|
{
|
|
Selector.OnSelectedChanged.AddListener(OnSelectionChanged);
|
|
upgradeMenuBtn.onClick.AddListener(OnUpgradeMenuClicked);
|
|
infoBtn.onClick.AddListener(OnInfoClicked);
|
|
upgradeBtn.onClick.AddListener(OnUpgrade);
|
|
collectBtn.btn.onClick.AddListener(OnCollect);
|
|
repairRocketsBtn.onClick.AddListener(OpenSkinMenu);
|
|
}
|
|
|
|
void OnSelectionChanged()
|
|
{
|
|
if (Selector.selectedBuilding != null)
|
|
{
|
|
infoBtn.gameObject.SetActive(true);
|
|
if (Selector.selectedData.levels.Count <= 1)
|
|
{
|
|
upgradeMenuBtn.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
upgradeMenuBtn.gameObject.SetActive(true);
|
|
}
|
|
|
|
|
|
if(Selector.selectedData.collectable){
|
|
collectBtn.gameObject.SetActive(true);
|
|
Debug.Log("Last collected : " +Selector.selectedBuilding.lastCollected );
|
|
collectBtn.Set(Selector.selectedData.buildingName,Selector.selectedBuilding.lastCollected,Selector.selectedData.productinoRates[Selector.selectedBuilding.curLevel],Selector.selectedData.resourceType);
|
|
}else{
|
|
collectBtn.gameObject.SetActive(false);
|
|
}
|
|
|
|
// joinHallBtn.gameObject.SetActive((Selector.selectedData == mainHall));
|
|
repairRocketsBtn.gameObject.SetActive((Selector.selectedData == rocketRepair));
|
|
}
|
|
else
|
|
{
|
|
upgradeMenuBtn.gameObject.SetActive(false);
|
|
infoBtn.gameObject.SetActive(false);
|
|
collectBtn.gameObject.SetActive(false);
|
|
// joinHallBtn.gameObject.SetActive(false);
|
|
repairRocketsBtn.gameObject.SetActive(false);
|
|
}
|
|
|
|
upgradeMenu.SetActive(false);
|
|
infoMenu.SetActive(false);
|
|
}
|
|
|
|
void OnUpgradeMenuClicked()
|
|
{
|
|
// Debug.Log("Opening Upgrade Menu for : " + Selector.selectedBuilding.buildingData.name);
|
|
AudioManager.instnace.UIPopup();
|
|
|
|
upgradeMenu.SetActive(true);
|
|
upgrade_buildingName.text = Selector.selectedBuilding.buildingData.buildingName;
|
|
for(int i=0; i < upgrade_tierIndicators.Length;i++){
|
|
upgrade_tierIndicators[i].SetActive( Selector.selectedBuilding.curLevel == i);
|
|
}
|
|
if (Selector.selectedBuilding.curLevel < Selector.selectedData.levels.Count - 1)
|
|
{
|
|
upgradeBtn.interactable = (Selector.selectedData.levels[Selector.selectedBuilding.curLevel + 1].price < DBmanager.Coins);
|
|
upgradeBtn.GetComponentInChildren<TMP_Text>().text = Selector.selectedData.levels[Selector.selectedBuilding.curLevel + 1].price.ToString();
|
|
|
|
}
|
|
else
|
|
{
|
|
upgradeBtn.interactable = false;
|
|
upgradeBtn.GetComponentInChildren<TMP_Text>().text = "MAX!";
|
|
|
|
Debug.Log("Already max");
|
|
}
|
|
|
|
List<BuildingStat> stats = Selector.selectedBuilding.buildingData.levels[Selector.selectedBuilding.curLevel].stats;
|
|
for (int i = 0; i < upgrade_statParent.childCount; i++)
|
|
{
|
|
bool hasDataForThis = i < stats.Count;
|
|
upgrade_statParent.GetChild(i).gameObject.SetActive(hasDataForThis);
|
|
if (hasDataForThis)
|
|
{
|
|
upgrade_statParent.GetChild(i).GetChild(0).GetComponent<TMP_Text>().text = stats[i].name;
|
|
upgrade_statParent.GetChild(i).GetChild(1).GetComponent<TMP_Text>().text = stats[i].value;
|
|
upgrade_statParent.GetChild(i).GetChild(2).GetComponent<Image>().sprite = stats[i].image;
|
|
}
|
|
}
|
|
|
|
if (upgrade_statParent.childCount < stats.Count)
|
|
{
|
|
Debug.LogError("Please add another slot for stats in upgrade menu.\nSlots not enough for " + Selector.selectedBuilding.buildingData.name + " , " + upgrade_statParent.childCount + " slots for " + stats.Count + " stats");
|
|
}
|
|
}
|
|
|
|
void OnUpgrade()
|
|
{
|
|
upgradeBtn.interactable= false;
|
|
Selector.selectedBuilding.Upgrade();
|
|
OnUpgradeMenuClicked();
|
|
}
|
|
|
|
void OnInfoClicked()
|
|
{
|
|
Debug.Log("Opening Info Menu for : " + Selector.selectedBuilding.buildingData.name);
|
|
|
|
infoMenu.SetActive(true);
|
|
buildingName.text = Selector.selectedBuilding.buildingData.buildingName;
|
|
for(int i=0; i < tierIndicators.Length;i++){
|
|
tierIndicators[i].SetActive( Selector.selectedBuilding.curLevel == i);
|
|
}
|
|
descriptionTxt.text = Selector.selectedBuilding.buildingData.description;
|
|
|
|
AudioManager.instnace.UIPopup();
|
|
}
|
|
|
|
void OpenSkinMenu(){
|
|
SkinShopManager.instance.Show();
|
|
AudioManager.instnace.UIPopup();
|
|
|
|
}
|
|
|
|
void OnCollect(){
|
|
Debug.Log("Collecting from : " + Selector.selectedData.buildingName);
|
|
}
|
|
|
|
} |