SkinShop done and building menus integrated
This commit is contained in:
@@ -5,49 +5,68 @@ using UnityEngine.UI;
|
||||
public class SkinShopItem : MonoBehaviour
|
||||
{
|
||||
public Image spaceshipImg;
|
||||
public Image backgroundImg;
|
||||
public Button buyBtn;
|
||||
public Button equipBtn;
|
||||
public GameObject equippedIndicator;
|
||||
public new string name;
|
||||
public int price;
|
||||
public TMPro.TMP_Text nameTxt;
|
||||
|
||||
void Start(){
|
||||
buyBtn.onClick.AddListener(onBuy);
|
||||
equipBtn.onClick.AddListener(onEquip);
|
||||
}
|
||||
[Tooltip("In order of: normal, rare, legendary. 3 items required")]
|
||||
public GameObject[] banners;
|
||||
public Image frame;
|
||||
public GameObject notPurchasedIndicator;
|
||||
public SkinShopItemData skinData;
|
||||
|
||||
public void Set(SkinShopItemData data){
|
||||
name = data.name;
|
||||
nameTxt.text = data.name;
|
||||
price = data.price;
|
||||
|
||||
skinData = data;
|
||||
// newItem.backgroundImg.color = (skinsData.skins[i].skinType==SkinType.Base) ? basicColor : (skinsData.skins[i].skinType==SkinType.Rare ? rareColor : legendaryColor);
|
||||
spaceshipImg.sprite = data.image;
|
||||
buyBtn.GetComponentInChildren<TMPro.TMP_Text>().text = price.ToString();
|
||||
buyBtn.interactable = DBmanager.Metal >= price;
|
||||
|
||||
buyBtn.gameObject.SetActive(!(DBmanager.SkinsPurchased.Contains(name) || price<=0));
|
||||
equipBtn.gameObject.SetActive(!buyBtn.gameObject.activeSelf);
|
||||
UpdateFrame();
|
||||
|
||||
if(SkinShopManager.GetEquipedSkin() == name){
|
||||
equipBtn.gameObject.SetActive(false);
|
||||
equippedIndicator.SetActive(true);
|
||||
banners[0].SetActive(data.skinType== SkinType.Base);
|
||||
banners[1].SetActive(data.skinType== SkinType.Rare);
|
||||
banners[2].SetActive(data.skinType== SkinType.Legendary);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void UpdateFrame(){
|
||||
if(SkinShopManager.GetEquipedSkin() == skinData.name){
|
||||
frame.enabled=true;
|
||||
frame.color = Color.cyan;
|
||||
}else{
|
||||
equippedIndicator.SetActive(false);
|
||||
frame.enabled=false;
|
||||
}
|
||||
|
||||
if(!DBmanager.SkinsPurchased.Contains(skinData.name)){
|
||||
frame.color = Color.red;
|
||||
notPurchasedIndicator.SetActive(true);
|
||||
}else{
|
||||
notPurchasedIndicator.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
void onEquip(){
|
||||
SkinShopManager.EquipSkin(name);
|
||||
SkinShopManager.instance.Populate();
|
||||
public void OnClick(){
|
||||
SkinShopManager.instance.SelectItem(skinData);
|
||||
}
|
||||
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 onBuy(){
|
||||
SkinShopItemData data = new SkinShopItemData(){name=name, price=price};
|
||||
DBmanager.PurchaseSkin(data);
|
||||
|
||||
SkinShopManager.instance.Populate();
|
||||
}
|
||||
|
||||
// void onEquip(){
|
||||
// SkinShopManager.EquipSkin(name);
|
||||
// SkinShopManager.instance.Populate();
|
||||
// }
|
||||
|
||||
// void onBuy(){
|
||||
// SkinShopItemData data = new SkinShopItemData(){name=name, price=price};
|
||||
// DBmanager.PurchaseSkin(data);
|
||||
|
||||
// SkinShopManager.instance.Populate();
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
using TMPro;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SkinShopManager : MonoBehaviour
|
||||
{
|
||||
public static SkinShopManager instance;
|
||||
public SkinsData skinsData;
|
||||
public TMPro.TMP_Text metalsTxt;
|
||||
|
||||
public GameObject listItemPrefab;
|
||||
public Transform listItemsParent;
|
||||
|
||||
public Color basicColor = Color.grey;
|
||||
public Color rareColor = Color.blue;
|
||||
public Color legendaryColor = Color.red;
|
||||
public Button btn_Equip;
|
||||
public Button btn_Buy;
|
||||
public static SkinShopItemData selectedSkin;
|
||||
List<SkinShopItem> skinShopItems=new List<SkinShopItem>();
|
||||
|
||||
void Awake() {
|
||||
instance = this;
|
||||
@@ -22,27 +23,72 @@ public class SkinShopManager : MonoBehaviour
|
||||
void Start()
|
||||
{
|
||||
Populate();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
btn_Equip.onClick.AddListener(onEquip);
|
||||
btn_Buy.onClick.AddListener(onBuy);
|
||||
}
|
||||
|
||||
public void Populate(){
|
||||
//Validate skins list
|
||||
if(DBmanager.SkinsPurchased.Count <=0){
|
||||
foreach(SkinShopItemData skin in skinsData.skins){
|
||||
if(skin.price==0){ //Defaults
|
||||
DBmanager.PurchaseSkin(skin);
|
||||
if(GetEquipedSkin().Length <=0){
|
||||
EquipSkin(skin.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//PURGE
|
||||
for(int i=0;i < listItemsParent.childCount;i++){
|
||||
Destroy(listItemsParent.GetChild(i).gameObject);
|
||||
}
|
||||
|
||||
skinShopItems = new List<SkinShopItem>();
|
||||
for(int i=0; i<skinsData.skins.Length;i++){
|
||||
SkinShopItem newItem = Instantiate(listItemPrefab, listItemsParent).GetComponent<SkinShopItem>();
|
||||
newItem.Set(skinsData.skins[i]);
|
||||
newItem.backgroundImg.color = (skinsData.skins[i].skinType==SkinType.Base) ? basicColor : (skinsData.skins[i].skinType==SkinType.Rare ? rareColor : legendaryColor);
|
||||
skinShopItems.Add(newItem);
|
||||
// newItem.backgroundImg.color = (skinsData.skins[i].skinType==SkinType.Base) ? basicColor : (skinsData.skins[i].skinType==SkinType.Rare ? rareColor : legendaryColor);
|
||||
}
|
||||
|
||||
metalsTxt.text = DBmanager.Metal.ToString();
|
||||
SelectItem(selectedSkin);
|
||||
}
|
||||
|
||||
public void SelectItem(SkinShopItemData data){
|
||||
selectedSkin = data;
|
||||
if(data==null){
|
||||
btn_Equip.gameObject.SetActive(false); btn_Buy.gameObject.SetActive(false);
|
||||
return;
|
||||
}
|
||||
if(DBmanager.SkinsPurchased.Contains(data.name)){ // <-- purchased
|
||||
btn_Equip.gameObject.SetActive(true);
|
||||
btn_Buy.gameObject.SetActive(false);
|
||||
btn_Equip.interactable = GetEquipedSkin() != data.name; // <-- disable equip button if already equipped
|
||||
}else{
|
||||
btn_Buy.gameObject.SetActive(true);
|
||||
btn_Equip.gameObject.SetActive(false);
|
||||
|
||||
btn_Buy.interactable = DBmanager.Metal >= data.price;
|
||||
btn_Buy.GetComponentInChildren<TMP_Text>().text = data.price.ToString();
|
||||
}
|
||||
|
||||
foreach(SkinShopItem item in skinShopItems){
|
||||
item.OnSelectionChanged(data.name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void onEquip(){
|
||||
EquipSkin(selectedSkin.name);
|
||||
Populate();
|
||||
}
|
||||
|
||||
void onBuy(){
|
||||
DBmanager.PurchaseSkin(selectedSkin);
|
||||
|
||||
SkinShopManager.instance.Populate();
|
||||
}
|
||||
|
||||
public static void EquipSkin(string skin){
|
||||
|
||||
Reference in New Issue
Block a user