private System.Collections.IEnumerator getLeaderboard(int tournamentId) { UnityWebRequest www = UnityWebRequest.Get(Constants.BaseUrl + "api/tournament/leaderboard/" + TacoSetup.Instance.SiteId + "/" + tournamentId); www.SetRequestHeader("x-access-token", TacoManager.User.token); yield return(www.SendWebRequest()); if (www.isNetworkError) { Debug.Log("Error getting leaderboard : " + www.error); } else { LeaderboardResult r = JsonUtility.FromJson <LeaderboardResult> (www.downloadHandler.text); Reload(r.leaderboard, !string.IsNullOrEmpty(r.tournament.endDate)); } }
public void LoadLeaderboard(Tournament tournament) { TacoManager.OpenMessage(TacoConfig.TacoRefreshing); ResetUIValue(); Action <string> success = (string data) => { LeaderboardResult r = JsonUtility.FromJson <LeaderboardResult> (data); UpdateUIValue(r); TacoManager.CloseMessage(); }; Action <string, string> fail = (string data, string error) => { TacoManager.OpenModalGeneralResultPanel(false, TacoConfig.Error, TacoConfig.TacoTournamentError); }; var url = "api/tournament/leaderboard/" + TacoSetup.Instance.SiteId + "/" + tournament.id; StartCoroutine(ApiManager.Instance.GetWithToken(url, success, fail)); }
private System.Collections.IEnumerator getLeaderboard(int tournamentId) { UnityWebRequest www = UnityWebRequest.Get(Constants.BaseUrl + "api/tournament/leaderboard/" + TacoConfig.SiteId + "/" + tournamentId); www.SetRequestHeader("x-access-token", TacoManager.User.token); yield return(www.Send()); if (www.isError) { TacoConfig.print("Error getting leaderboard : " + www.error); TacoConfig.print("URL = " + www.url); } else { LeaderboardResult r = JsonUtility.FromJson <LeaderboardResult>(www.downloadHandler.text); this.Reload(r.leaderboard); } }
public void LoadLeaderboard(Tournament t) { Action <string> success = (string data) => { LeaderboardResult r = JsonUtility.FromJson <LeaderboardResult>(data); Double prize = Double.Parse(r.tournament.prize.ToString()); Double entryFee = Double.Parse(r.tournament.entryFee.ToString()); string details; if (r.tournament.typeCurrency == 0) { details = TacoConfig.LeaderboardResults.Replace("&prize", TacoManager.FormatMoney(prize)); details = details.Replace("&name", r.tournament.name); details = details.Replace("&fee", TacoManager.FormatMoney(entryFee)); } else { details = TacoConfig.LeaderboardResults.Replace("&prize", TacoManager.FormatGTokens(prize)); details = details.Replace("&name", r.tournament.name); details = details.Replace("&fee", TacoManager.FormatGTokens(entryFee)); } TacoConfig.print(details); tournamentDetailsText.text = details; this.Reload(r.leaderboard); }; Action <string, string> fail = (string data, string error) => { TacoManager.OpenModal(TacoConfig.Error, TacoConfig.TacoTournamentError + " | " + error + " | " + data); }; var url = "api/tournament/leaderboard/" + TacoConfig.SiteId + "/" + t.id; StartCoroutine(ApiManager.Instance.GetWithToken(url, success, fail)); }
private void UpdateUIValue(LeaderboardResult r) { Tournament t = r.tournament; string tournamentType = t.Type; double prizePool = t.PrizePool; double entryFee = double.Parse(t.entryFee.ToString()); LeaderboardRow currentUserRank = r.leaderboard.First(x => x.userId == TacoManager.User.userId); string infos = string.Empty; string details; double moneyValue = 0; int winnerNb = r.winner.Length; prizeIcon.sprite = TacoConfig.currencySprites [t.typeCurrency]; tournamentTypeText.text = TacoConfig.LeaderboardTournamentType.Replace("&type", tournamentType).Replace("&gameName", TacoSetup.Instance.gameName); details = TacoConfig.LeaderboardResultDetails.Replace("&player", t.size.ToString()).Replace("&winner", TacoConfig.Pluralize(t.prize_structure, "Winner")); if (!string.IsNullOrEmpty(t.endDate)) { FinishedButtons.SetActive(true); endedLeaderboardFooter.SetActive(true); rankIcon.transform.parent.gameObject.SetActive(true); int userRank = int.Parse(currentUserRank.rank); if (userRank < 4) { rankIcon.gameObject.SetActive(true); rankIcon.sprite = imageList.Images [currentUserRank.rank]; } else { rankText.transform.parent.gameObject.SetActive(true); rankText.text = TacoConfig.ToShortOrdinal(userRank); } string formatedDay = t.endDate.Substring(5, 2) + "-" + t.endDate.Substring(8, 2) + "-" + t.endDate.Substring(0, 4); infos += TacoConfig.LeaderboardResultEndOn.Replace("&day", formatedDay); if (userRank <= t.prize_structure) { resultStatus.text = "You Won!"; prizeAmount.text = "+ "; moneyValue = t.PrizePool / winnerNb; int rpModifier = 0; if (t.typeCurrency == 0) { rpModifier = 50; } else { rpModifier = 5; } redeemAmount.text = "+ " + TacoManager.FormatRP(Mathf.RoundToInt((float)(moneyValue * rpModifier))); } else { resultStatus.text = "You Lost!"; prizeAmount.text = "+ "; moneyValue = 0; redeemAmount.text = "+ " + TacoManager.FormatRP(0); } } else { resultStatus.text = "Beautiful Job!"; playingLeaderboardFooter.SetActive(true); /*if (currentUserRank.playable) * { * FinishedButtons.SetActive(true); * } * else * { * UnfinishedButtons.SetActive(true); * }*/ rankIcon.transform.parent.gameObject.SetActive(false); countdownTime = Mathf.Max((float)t.RemainingTimeSpan.TotalSeconds, -1); if (countdownTime < 0) { remainingTime.text = "00:00:00"; } } if (t.typeCurrency == 0) { prizePoolText.text = TacoManager.FormatCash(prizePool); entryFeeText.text = TacoManager.FormatCash(entryFee); prizeAmount.text += TacoManager.FormatCash(moneyValue); } else { prizePoolText.text = TacoManager.FormatGTokens(prizePool); entryFeeText.text = TacoManager.FormatGTokens(entryFee); prizeAmount.text += TacoManager.FormatGTokens(moneyValue); } for (int i = 0; i < LeaderBoardMoneyTypeImages.Count; i++) { LeaderBoardMoneyTypeImages [i].sprite = TacoConfig.currencySprites [t.typeCurrency]; } infos += TacoConfig.LeaderboardResultTournamentID.Replace("&id", t.id.ToString()); resultScore.text = "Score: " + currentUserRank.score.ToString(); tournamentDetailsText0.text = infos; tournamentDetailsText1.text = details; /*playAgain.onClick.RemoveAllListeners(); * playAgain.onClick.AddListener (() => { * TacoManager.OpenModalReEnterPanel ( * TacoConfig.ReEnterNotice.Replace ("&type", tournamentType).Replace("&gameName", t.accessType == "public" ? "Public" : "Private"), * entryFeeText.text); * });*/ Reload(r.leaderboard, !string.IsNullOrEmpty(t.endDate)); }