SkinShop done and building menus integrated
This commit is contained in:
1281
Assets/Game/Prefabs/Skins/SkinShopItem.prefab
Normal file
1281
Assets/Game/Prefabs/Skins/SkinShopItem.prefab
Normal file
File diff suppressed because it is too large
Load Diff
7
Assets/Game/Prefabs/Skins/SkinShopItem.prefab.meta
Normal file
7
Assets/Game/Prefabs/Skins/SkinShopItem.prefab.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0cf4a9b3fa28e873d883f846ed616805
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
3821
Assets/Game/Scenes/TestScene/Skin select_buy.prefab
Normal file
3821
Assets/Game/Scenes/TestScene/Skin select_buy.prefab
Normal file
File diff suppressed because it is too large
Load Diff
7
Assets/Game/Scenes/TestScene/Skin select_buy.prefab.meta
Normal file
7
Assets/Game/Scenes/TestScene/Skin select_buy.prefab.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e14cc4e73f5c837c4aac9f21a879de8b
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
2058
Assets/Game/Scenes/TestScene/Structure Update menu.prefab
Normal file
2058
Assets/Game/Scenes/TestScene/Structure Update menu.prefab
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4504a93d75dd06098a35a997fdec247
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -53,7 +53,7 @@ public class Building : MonoBehaviour
|
||||
public void Upgrade(){
|
||||
if(curLevel >= buildingData.levels.Count-1){Debug.Log("Already max");return;}
|
||||
int cost = buildingData.levels[curLevel+1].price;
|
||||
// Debug.Log("Upgrading " + buildingData.buildingName + " for " + cost + " coins");
|
||||
Debug.Log("Upgrading " + buildingData.buildingName + " for " + cost + " coins");
|
||||
|
||||
switch (curLevel)
|
||||
{
|
||||
|
||||
@@ -28,12 +28,13 @@ public static class CollectablesData{
|
||||
public class BuildingStat{
|
||||
public string name;
|
||||
public string value;
|
||||
public Sprite image;
|
||||
|
||||
|
||||
public BuildingStat(string _name, string _value){
|
||||
public BuildingStat(string _name, string _value, Sprite _image){
|
||||
name= _name;
|
||||
value = _value;
|
||||
|
||||
image= _image;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,22 @@ public class BuildingManager : MonoBehaviour
|
||||
}
|
||||
|
||||
|
||||
public void UpdateBuildings(){
|
||||
Debug.Log("Im getting called");
|
||||
public async void UpdateBuildings(){
|
||||
foreach (Building building in buildings){
|
||||
if(!building.gameObject.activeSelf){
|
||||
continue;
|
||||
}
|
||||
bool buildingExists = false;
|
||||
foreach (BuildingState buildingState in DBmanager.buildingStates){
|
||||
if(buildingState.id == building.buildingData.buildingName){
|
||||
buildingExists =true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!buildingExists){
|
||||
await DBmanager.AddBuilding(building.buildingData);
|
||||
}
|
||||
}
|
||||
foreach (Building building in buildings){
|
||||
bool buildingExists = false;
|
||||
foreach (BuildingState buildingState in DBmanager.buildingStates){
|
||||
|
||||
@@ -21,7 +21,7 @@ public class CollectBtn : MonoBehaviour
|
||||
|
||||
void Update()
|
||||
{
|
||||
collectableAmount=((DateTime.UtcNow - lastCollected).TotalSeconds * productionRate);
|
||||
collectableAmount=((DateTime.UtcNow - lastCollected).TotalSeconds * ((productionRate/60f)/60f));
|
||||
txt.text = ((int)collectableAmount).ToString();
|
||||
|
||||
btn.interactable = collectableAmount > 1;
|
||||
@@ -35,7 +35,7 @@ public class CollectBtn : MonoBehaviour
|
||||
}
|
||||
|
||||
async void OnClick(){
|
||||
collectableAmount=((DateTime.Now - lastCollected).TotalSeconds * productionRate);
|
||||
collectableAmount=((DateTime.UtcNow - lastCollected).TotalSeconds * ((productionRate/60f)/60f));
|
||||
lastCollected = await DBmanager.GetNetworkTime();
|
||||
switch (resourceType){
|
||||
case CollectablesData.ResourceType.Metal:
|
||||
|
||||
@@ -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){
|
||||
|
||||
@@ -9,16 +9,20 @@ public class SelectedItemMenu : MonoBehaviour
|
||||
public Button upgradeMenuBtn;
|
||||
public Button infoBtn;
|
||||
public CollectBtn collectBtn;
|
||||
public Button joinHallBtn;
|
||||
public Button repairRocketsBtn;
|
||||
// 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")]
|
||||
@@ -57,16 +61,16 @@ public class SelectedItemMenu : MonoBehaviour
|
||||
collectBtn.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
joinHallBtn.gameObject.SetActive((Selector.selectedData == mainHall));
|
||||
repairRocketsBtn.gameObject.SetActive((Selector.selectedData == rocketRepair));
|
||||
// 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);
|
||||
// joinHallBtn.gameObject.SetActive(false);
|
||||
// repairRocketsBtn.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
upgradeMenu.SetActive(false);
|
||||
@@ -78,7 +82,10 @@ public class SelectedItemMenu : MonoBehaviour
|
||||
// Debug.Log("Opening Upgrade Menu for : " + Selector.selectedBuilding.buildingData.name);
|
||||
|
||||
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);
|
||||
@@ -102,10 +109,11 @@ public class SelectedItemMenu : MonoBehaviour
|
||||
{
|
||||
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)
|
||||
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");
|
||||
}
|
||||
@@ -123,6 +131,10 @@ public class SelectedItemMenu : MonoBehaviour
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user