New Building buttons integrated + global leaderboard
This commit is contained in:
@@ -42,9 +42,9 @@ public class CollectBtn : MonoBehaviour
|
||||
DBmanager.SetMetal(DBmanager.Metal + (int)collectableAmount);
|
||||
break;
|
||||
|
||||
case CollectablesData.ResourceType.Oxygen:
|
||||
DBmanager.SetOxygen(DBmanager.Oxygen + (int)collectableAmount);
|
||||
break;
|
||||
// case CollectablesData.ResourceType.Oxygen:
|
||||
// DBmanager.SetOxygen(DBmanager.Trophies + (int)collectableAmount);
|
||||
// break;
|
||||
}
|
||||
DBmanager.CollectBuilding(buildingId);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public class DBmanager : MonoBehaviour
|
||||
private static int coins = 0;
|
||||
private static int gems = 0;
|
||||
private static int metal = 0;
|
||||
private static int oxygen = 0;
|
||||
private static int trophies = 0;
|
||||
private static List<InventoryEntry> inventory;
|
||||
private static List<int> expPassCollected = new List<int>();
|
||||
private static List<string> skinsPurchased = new List<string>();
|
||||
@@ -30,7 +30,7 @@ public class DBmanager : MonoBehaviour
|
||||
public static int Coins => coins;
|
||||
public static int Gems => gems;
|
||||
public static int Metal => metal;
|
||||
public static int Oxygen => oxygen;
|
||||
public static int Trophies => trophies;
|
||||
public static float Level => level;
|
||||
public static int LevelInt => Mathf.CeilToInt(level);
|
||||
public static List<int> ExpPassCollected => expPassCollected;
|
||||
@@ -264,13 +264,13 @@ public class DBmanager : MonoBehaviour
|
||||
OnStateChanged.Invoke();
|
||||
}
|
||||
|
||||
public async static void SetOxygen(int newValue, bool justOffline = false)
|
||||
public async static void SetTrophies(int newValue, bool justOffline = false)
|
||||
{
|
||||
WWWForm form = new WWWForm();
|
||||
form.AddField("name", username);
|
||||
form.AddField("oxygen", newValue);
|
||||
if (justOffline) { oxygen = newValue; return; }
|
||||
using (UnityWebRequest www = UnityWebRequest.Post(phpRoot + "set_oxygen.php", form))
|
||||
form.AddField("trophies", newValue);
|
||||
if (justOffline) { trophies = newValue; return; }
|
||||
using (UnityWebRequest www = UnityWebRequest.Post(phpRoot + "set_trophies.php", form))
|
||||
{
|
||||
var operation = www.SendWebRequest();
|
||||
while (!operation.isDone)
|
||||
@@ -280,12 +280,12 @@ public class DBmanager : MonoBehaviour
|
||||
|
||||
if (www.downloadHandler.text == "0")
|
||||
{
|
||||
oxygen = newValue;
|
||||
trophies = newValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Response : " + www.downloadHandler.text);
|
||||
Debug.LogWarning("Failed to set oxygen to " + newValue);
|
||||
Debug.LogWarning("Failed to set trophies to " + newValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -659,4 +659,43 @@ public class DBmanager : MonoBehaviour
|
||||
OnStateChanged.Invoke();
|
||||
}
|
||||
|
||||
|
||||
public async static Task<List<LeaderboardUserData>> GetLeaderboard()
|
||||
{
|
||||
|
||||
WWWForm form = new WWWForm();
|
||||
List<LeaderboardUserData> leaderboard = new List<LeaderboardUserData>();
|
||||
using (UnityWebRequest www = UnityWebRequest.Post(phpRoot + "get_leaderboard.php", form))
|
||||
{
|
||||
var operation = www.SendWebRequest();
|
||||
while (!operation.isDone)
|
||||
{
|
||||
await Task.Yield();
|
||||
}
|
||||
|
||||
|
||||
|
||||
try{
|
||||
string[] split = {"<td>"};
|
||||
string[] players = www.downloadHandler.text.Split(split, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
foreach(string player in players){
|
||||
leaderboard.Add(JsonConvert.DeserializeObject<LeaderboardUserData>(player));
|
||||
}
|
||||
}catch{
|
||||
Debug.Log("Failed fetching Leaderboard");
|
||||
Debug.Log("Response : " + www.downloadHandler.text);
|
||||
}
|
||||
}
|
||||
|
||||
return leaderboard;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class LeaderboardUserData{
|
||||
public string username;
|
||||
public int trophies;
|
||||
public int position;
|
||||
}
|
||||
@@ -15,7 +15,8 @@ public class GameManager : MonoBehaviour
|
||||
public TMP_Text[] coinsTxt;
|
||||
public TMP_Text[] gemsTxt;
|
||||
public TMP_Text metalTxt;
|
||||
public TMP_Text oxygenTxt;
|
||||
// public TMP_Text oxygenTxt;
|
||||
public TMP_Text trophiesTxt;
|
||||
public TMP_Text[] levelTxts;
|
||||
public Slider[] levelSliders;
|
||||
public TMP_Text[] levelProgressTxts;
|
||||
@@ -84,7 +85,8 @@ public class GameManager : MonoBehaviour
|
||||
txt.text = DBmanager.Gems.ToString();
|
||||
}
|
||||
metalTxt.text = DBmanager.Metal.ToString();
|
||||
oxygenTxt.text = DBmanager.Oxygen.ToString();
|
||||
trophiesTxt.text = DBmanager.Trophies.ToString();
|
||||
// oxygenTxt.text = DBmanager.Trophies.ToString();
|
||||
foreach (TMP_Text levelTxt in levelTxts)
|
||||
{
|
||||
levelTxt.text = Mathf.CeilToInt(DBmanager.Level).ToString();
|
||||
|
||||
21
Assets/Game/Scripts/GlobalLeaderboard.cs
Normal file
21
Assets/Game/Scripts/GlobalLeaderboard.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class GlobalLeaderboard : MonoBehaviour
|
||||
{
|
||||
public Transform leaderboardItemsParent;
|
||||
public async void Show(){
|
||||
List<LeaderboardUserData> leaderboard = await DBmanager.GetLeaderboard();
|
||||
for(int i =0; i < leaderboardItemsParent.childCount; i++){
|
||||
if(i > leaderboard.Count-1){
|
||||
leaderboardItemsParent.GetChild(i).gameObject.SetActive(false);
|
||||
continue;
|
||||
}
|
||||
leaderboardItemsParent.GetChild(i).gameObject.SetActive(true);
|
||||
leaderboardItemsParent.GetChild(i).GetComponent<LeaderboardItem>().Set(leaderboard[i]);
|
||||
}
|
||||
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
11
Assets/Game/Scripts/GlobalLeaderboard.cs.meta
Normal file
11
Assets/Game/Scripts/GlobalLeaderboard.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11cca7ac4fcb17067bf28778d64a6db8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
26
Assets/Game/Scripts/LeaderboardItem.cs
Normal file
26
Assets/Game/Scripts/LeaderboardItem.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using UnityEngine.UI;
|
||||
public class LeaderboardItem : MonoBehaviour
|
||||
{
|
||||
public TMP_Text positionTxt;
|
||||
public Image img_place;
|
||||
public Sprite[] specialPlaces;
|
||||
public TMP_Text usernameTxt;
|
||||
public TMP_Text trophiesTxt;
|
||||
|
||||
public void Set(LeaderboardUserData data){
|
||||
positionTxt.text = data.position.ToString();
|
||||
if(data.position > specialPlaces.Length){
|
||||
img_place.enabled = false;
|
||||
}else{
|
||||
img_place.enabled = true;
|
||||
img_place.sprite = specialPlaces[data.position-1];
|
||||
}
|
||||
|
||||
usernameTxt.text = data.username;
|
||||
trophiesTxt.text = data.trophies.ToString();
|
||||
}
|
||||
}
|
||||
11
Assets/Game/Scripts/LeaderboardItem.cs.meta
Normal file
11
Assets/Game/Scripts/LeaderboardItem.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4cdc757f589c2e4d992857163d178f0b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -86,7 +86,7 @@ public class LoginManager : MonoBehaviour
|
||||
DBmanager.SetExpPassCollected(www.text.Split('\t')[7]);
|
||||
DBmanager.SetXp(int.Parse(www.text.Split('\t')[6]),true);
|
||||
DBmanager.GetBuildingStates(www.text.Split('\t')[5]);
|
||||
DBmanager.SetOxygen(int.Parse(www.text.Split('\t')[4]),true);
|
||||
DBmanager.SetTrophies(int.Parse(www.text.Split('\t')[4]),true);
|
||||
DBmanager.SetMetal(int.Parse(www.text.Split('\t')[3]),true);
|
||||
DBmanager.SetGems(int.Parse(www.text.Split('\t')[2]),true);
|
||||
DBmanager.SetCoins(int.Parse(www.text.Split('\t')[1]),true);
|
||||
|
||||
@@ -9,6 +9,7 @@ public class SkinShopManager : MonoBehaviour
|
||||
{
|
||||
public static SkinShopManager instance;
|
||||
public SkinsData skinsData;
|
||||
public GameObject popup;
|
||||
|
||||
public GameObject listItemPrefab;
|
||||
public Transform listItemsParent;
|
||||
@@ -28,6 +29,11 @@ public class SkinShopManager : MonoBehaviour
|
||||
btn_Buy.onClick.AddListener(onBuy);
|
||||
}
|
||||
|
||||
public void Show(){
|
||||
Populate();
|
||||
popup.SetActive(true);
|
||||
}
|
||||
|
||||
public void Populate(){
|
||||
//Validate skins list
|
||||
if(DBmanager.SkinsPurchased.Count <=0){
|
||||
|
||||
@@ -10,7 +10,7 @@ public class SelectedItemMenu : MonoBehaviour
|
||||
public Button infoBtn;
|
||||
public CollectBtn collectBtn;
|
||||
// public Button joinHallBtn;
|
||||
// public Button repairRocketsBtn;
|
||||
public Button repairRocketsBtn;
|
||||
|
||||
[Header("info menu")]
|
||||
public GameObject infoMenu;
|
||||
@@ -36,6 +36,7 @@ public class SelectedItemMenu : MonoBehaviour
|
||||
infoBtn.onClick.AddListener(OnInfoClicked);
|
||||
upgradeBtn.onClick.AddListener(OnUpgrade);
|
||||
collectBtn.btn.onClick.AddListener(OnCollect);
|
||||
repairRocketsBtn.onClick.AddListener(OpenSkinMenu);
|
||||
}
|
||||
|
||||
void OnSelectionChanged()
|
||||
@@ -62,7 +63,7 @@ public class SelectedItemMenu : MonoBehaviour
|
||||
}
|
||||
|
||||
// joinHallBtn.gameObject.SetActive((Selector.selectedData == mainHall));
|
||||
// repairRocketsBtn.gameObject.SetActive((Selector.selectedData == rocketRepair));
|
||||
repairRocketsBtn.gameObject.SetActive((Selector.selectedData == rocketRepair));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -70,7 +71,7 @@ public class SelectedItemMenu : MonoBehaviour
|
||||
infoBtn.gameObject.SetActive(false);
|
||||
collectBtn.gameObject.SetActive(false);
|
||||
// joinHallBtn.gameObject.SetActive(false);
|
||||
// repairRocketsBtn.gameObject.SetActive(false);
|
||||
repairRocketsBtn.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
upgradeMenu.SetActive(false);
|
||||
@@ -138,6 +139,10 @@ public class SelectedItemMenu : MonoBehaviour
|
||||
descriptionTxt.text = Selector.selectedBuilding.buildingData.description;
|
||||
}
|
||||
|
||||
void OpenSkinMenu(){
|
||||
SkinShopManager.instance.Show();
|
||||
}
|
||||
|
||||
void OnCollect(){
|
||||
Debug.Log("Collecting from : " + Selector.selectedData.buildingName);
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ refreshIndicator.interactable=true;
|
||||
acceptBtn.interactable = !myTrade && isTradeAffordable(selectedTrade);
|
||||
}
|
||||
|
||||
public bool isTradeAffordable(TradeRequest trade) => (DBmanager.Coins >= trade.coins) && (DBmanager.Gems >= trade.gems) && (DBmanager.Metal >= trade.metals) && (DBmanager.Oxygen >= trade.oxygen);
|
||||
public bool isTradeAffordable(TradeRequest trade) => (DBmanager.Coins >= trade.coins) && (DBmanager.Gems >= trade.gems) && (DBmanager.Metal >= trade.metals) && (DBmanager.Trophies >= trade.oxygen);
|
||||
|
||||
public void OnAcceptClicked(){
|
||||
if(selectedTrade==null){Debug.Log("No offer is selected to accept"); return;}
|
||||
@@ -230,7 +230,7 @@ refreshIndicator.interactable=true;
|
||||
//change local stuff
|
||||
DBmanager.SetCoins(DBmanager.Coins - trade.coins,true);
|
||||
DBmanager.SetGems(DBmanager.Gems - trade.gems,true);
|
||||
DBmanager.SetOxygen(DBmanager.Oxygen - trade.oxygen,true);
|
||||
DBmanager.SetTrophies(DBmanager.Trophies - trade.oxygen,true);
|
||||
DBmanager.SetMetal(DBmanager.Metal - trade.metals, true);
|
||||
DBmanager.AddInventoryItem(Inventory.GetInventoryItem(trade.item));
|
||||
Refresh();
|
||||
|
||||
Reference in New Issue
Block a user