116 lines
3.4 KiB
C#
116 lines
3.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Kill.Managers;
|
|
using Kill.Network;
|
|
using Kill.UI.Components;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
namespace Kill.UI.Pages
|
|
{
|
|
public class RankPageCtrl : MonoBehaviour
|
|
{
|
|
public Image logoImage; public Sprite[] logos;
|
|
public Transform rankContent;
|
|
public RankItem rankItemPrefab;
|
|
public RankItem[] top3Rank;
|
|
public RankItem selfRank;
|
|
public Button back;
|
|
public enum RankType
|
|
{
|
|
daily,
|
|
weekly,
|
|
monthly,
|
|
cumulative
|
|
}
|
|
RankType rankType = RankType.daily;
|
|
|
|
void Start()
|
|
{
|
|
GetRankList();
|
|
int lt = (int)LanguageManager.Instance.languageType;
|
|
logoImage.sprite = logos[lt];
|
|
logoImage.SetNativeSize();
|
|
back.onClick.RemoveAllListeners();
|
|
UIManager.Instance.RegisterBackAction(Back);
|
|
back.onClick.AddListener(() => { Back(); });
|
|
|
|
}
|
|
public GameObject[] changeTypeBtns;
|
|
public void Back()
|
|
{
|
|
UIManager.Instance.OpenMainPage(UIManager.PageName.homePage);
|
|
}
|
|
public void OnClickRankType(int type)
|
|
{
|
|
for (int i = 0; i < changeTypeBtns.Length; i++)
|
|
{
|
|
if (i == type || (i > 3 && (i != type + 4)))
|
|
changeTypeBtns[i].gameObject.SetActive(true);
|
|
else
|
|
changeTypeBtns[i].gameObject.SetActive(false);
|
|
}
|
|
|
|
rankType = (RankType)type;
|
|
GetRankList();
|
|
}
|
|
async Task GetRankList()
|
|
{
|
|
LoadingUI.Show();
|
|
|
|
var response = await NetworkCtrl.Instance.Get<RankDataListResponse>($"/api/v1/stats/device/leaderboard?time_type={rankType}");
|
|
|
|
LoadingUI.Hide();
|
|
|
|
ResponseCodeHandler.HandleResponse(response,
|
|
onSuccess: (data) =>
|
|
{
|
|
Debug.Log(data.data.top_list.Count);
|
|
InitRankUI(data.data.top_list, data.data.my_rank);
|
|
},
|
|
onError: (code, msg) =>
|
|
{
|
|
Debug.LogError("获取排行榜失败: " + msg);
|
|
}
|
|
);
|
|
}
|
|
List<GameObject> rankItems = new List<GameObject>();
|
|
|
|
public void InitRankUI(List<RankData> ranks, RankData self)
|
|
{
|
|
Debug.Log(ranks.Count);
|
|
if (rankItems.Count > 0)
|
|
{
|
|
foreach (var item in rankItems)
|
|
{
|
|
Destroy(item);
|
|
}
|
|
rankItems.Clear();
|
|
rankItems = new List<GameObject>();
|
|
}
|
|
foreach (var rank in top3Rank)
|
|
{
|
|
rank.gameObject.SetActive(false);
|
|
}
|
|
|
|
for (int i = 0; i < ranks.Count; i++)
|
|
{
|
|
if (i < 3)
|
|
{
|
|
top3Rank[i].SetData(ranks[i]);
|
|
top3Rank[i].gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
RankItem rankItem = Instantiate(rankItemPrefab, rankContent);
|
|
rankItem.SetData(ranks[i]);
|
|
rankItems.Add(rankItem.gameObject);
|
|
rankItem.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
selfRank.SetData(self);
|
|
}
|
|
|
|
}
|
|
}
|