117 lines
3.1 KiB
C#
117 lines
3.1 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class RankPanel : BasePanel
|
|
{
|
|
public Button btnClose;
|
|
public Button btnHelp;
|
|
//总排行榜
|
|
public Button btnAllRank;
|
|
//所有关卡
|
|
public Button btnAllLev;
|
|
|
|
//关卡
|
|
public Text txtLev;
|
|
|
|
//玩家头像
|
|
public Image imgHead;
|
|
//玩家名次
|
|
public Text txtRank;
|
|
//玩家名字
|
|
public Text txtName;
|
|
//本机玩家分数
|
|
public Text txtScore;
|
|
|
|
//那一关的排行榜数据
|
|
public int levInfo = 1;
|
|
|
|
public ScrollRect svRank;
|
|
|
|
//创建的游戏对象
|
|
private List<GameObject> rankObjects;
|
|
|
|
public override void Init()
|
|
{
|
|
rankObjects = new List<GameObject>();
|
|
UpdatePanel(levInfo);
|
|
GameDataMgr.Instance.levRankMsg.id = 1;
|
|
|
|
StartCoroutine(NetMgr.Instance.RankPost(GameDataMgr.Instance.levRankMsg));
|
|
|
|
btnClose.onClick.AddListener(() =>
|
|
{
|
|
UIManager.Instance.HidePanel<RankPanel>(false);
|
|
});
|
|
|
|
//点击全部关卡按钮做什么
|
|
btnAllLev.onClick.AddListener(() =>
|
|
{
|
|
UIManager.Instance.ShowPanel<AllLevPanel>();
|
|
});
|
|
btnAllRank.onClick.AddListener(() =>
|
|
{
|
|
StartCoroutine(NetMgr.Instance.RankAllGet());
|
|
});
|
|
}
|
|
|
|
//更新面板显示
|
|
public void UpdatePanel(int lev)
|
|
{
|
|
levInfo = lev;
|
|
//关卡显示更新
|
|
txtLev.text = "第" + lev.ToString() + "关";
|
|
|
|
}
|
|
|
|
|
|
//给外界更新面板
|
|
public void UpdatePanel(List<PlayerData> rankData)
|
|
{
|
|
for (int i = 0; i < rankObjects.Count; i++)
|
|
{
|
|
Destroy(rankObjects[i]);
|
|
}
|
|
for (int i = 0; i < rankData.Count; i++)
|
|
{
|
|
//动态创建预设体对象
|
|
if (i < 3)
|
|
{
|
|
GameObject item = Instantiate(Resources.Load<GameObject>("UI/RankItem1"));
|
|
item.transform.SetParent(svRank.content, false);
|
|
RankItem1 rankItem1 = item.GetComponent<RankItem1>();
|
|
rankItem1.InitInfo(rankData[i], i + 1);
|
|
rankObjects.Add(item);
|
|
}
|
|
else
|
|
{
|
|
GameObject item = Instantiate(Resources.Load<GameObject>("UI/RankItem2"));
|
|
item.transform.SetParent(svRank.content, false);
|
|
RankItem2 rankItem2 = item.GetComponent<RankItem2>();
|
|
rankItem2.InitInfo(rankData[i], i + 1);
|
|
rankObjects.Add(item);
|
|
}
|
|
}
|
|
|
|
UpdatePlayer(GameDataMgr.Instance.rankData);
|
|
}
|
|
|
|
public void UpdatePlayer(Dictionary<string, List<PlayerData>> rankData)
|
|
{
|
|
for (int i = 0; i < rankData["UserList"].Count; i++)
|
|
{
|
|
if (GameDataMgr.Instance.player.openId == rankData["UserList"][i].openId)
|
|
{
|
|
txtRank.text = (i+1).ToString();
|
|
txtName.text = GameDataMgr.Instance.player.username;
|
|
txtScore.text = rankData["UserList"][i].weekScore.ToString();
|
|
return;
|
|
}
|
|
}
|
|
|
|
txtRank.text = "";
|
|
txtName.text = GameDataMgr.Instance.player.username;
|
|
txtScore.text = "无";
|
|
}
|
|
}
|