283 lines
7.9 KiB
C#
283 lines
7.9 KiB
C#
using UnityEngine;
|
||
using System.Collections;
|
||
using UnityEngine.UI;
|
||
using System.Collections.Generic;
|
||
|
||
public class RoleChallengeRankInfo
|
||
{
|
||
public string name;
|
||
public int curRank;
|
||
public int totalRnak;
|
||
public int level;
|
||
public RoleChallengeRankInfo(string Name, int CurRank, int TotalRank, int Level)
|
||
{
|
||
name = Name;
|
||
curRank = CurRank;
|
||
totalRnak = TotalRank;
|
||
level = Level;
|
||
}
|
||
}
|
||
|
||
|
||
public enum LevelGroup //等级分组
|
||
{
|
||
Level_All,
|
||
Level_0_69,
|
||
Level_70_89,
|
||
Level_90_109,
|
||
Level_110_129,
|
||
Level_130_150,
|
||
}
|
||
|
||
|
||
|
||
public class FactionRankPanelCtr : MonoBehaviour {
|
||
|
||
#region UI拖拽控件
|
||
|
||
//初始化玩家自身的信息
|
||
public Text m_RankInfoText;
|
||
public Text m_TotalRankInfoText; //总榜排名
|
||
public Text m_NameText;
|
||
public Text m_LevelInfoText;
|
||
|
||
//预设体
|
||
public GameObject PlayerRankInfoItem;
|
||
public Transform prefabParent;
|
||
|
||
public GameObject MyRankInfoPanel; //个人排名
|
||
public GameObject NoPlayerRankInfoPanel; //
|
||
public GameObject RankInfoPanel; //总榜排名
|
||
|
||
public GameObject NoInfoObj; //无分组信息的时候显示
|
||
public List<GameObject> _MarkIconList;
|
||
public List<GameObject> _CareerMarkIconList;
|
||
#endregion
|
||
|
||
private List<FactionPlayerRankInfoItem> roleInfoPrefabList = new List<FactionPlayerRankInfoItem>();
|
||
|
||
public static FactionRankPanelCtr Instance;
|
||
private void Awake()
|
||
{
|
||
Instance = this;
|
||
createPrefab(); //Awake的时候就创建吧(否则:信息同步过来的时候有可能itemPrefab还没有创建出来)
|
||
}
|
||
|
||
private void OnDestroy()
|
||
{
|
||
Instance = null;
|
||
}
|
||
|
||
bool isSelfGroup()
|
||
{
|
||
int profession = GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Profession;
|
||
if(CurSelectedCarrer == profession)
|
||
{
|
||
if(GetLevelGroup() == CurSelectedGroup || CurSelectedGroup == 0)//0为全部的分组
|
||
{
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
|
||
int GetLevelGroup()
|
||
{
|
||
int level = GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Level;
|
||
if (level > 0 && level <= 69)
|
||
{
|
||
return 1;
|
||
}else if(level >= 70 && level <= 89)
|
||
{
|
||
return 2;
|
||
}else if(level >= 90 && level <= 109)
|
||
{
|
||
return 3;
|
||
}else if(level >= 110 && level <= 129)
|
||
{
|
||
return 4;
|
||
}else
|
||
{
|
||
return 5;
|
||
}
|
||
}
|
||
|
||
private void OnEnable()
|
||
{
|
||
ShowDefaultFirst();
|
||
JudgeShowMySelfInfoPanel(); //每次打开界面的时候都要判断下当前是否在该分组
|
||
}
|
||
|
||
private void ShowDefaultFirst()
|
||
{
|
||
OnFactionToggleChange(0);
|
||
OnGroupToggleChange(0);
|
||
}
|
||
|
||
//初始化玩家自身的信息
|
||
public void InitMySelfRankInfo()
|
||
{
|
||
int profession = GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Profession;
|
||
if (profession == CurSelectedCarrer)
|
||
{
|
||
for (int index = 0; index < roleInfoPrefabList.Count; index++)
|
||
{
|
||
if (roleInfoPrefabList[index].GetComponent<FactionPlayerRankInfoItem>().PlayerNameText.text.Equals(GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.RoleName))
|
||
{
|
||
m_RankInfoText.text = roleInfoPrefabList[index].GetComponent<FactionPlayerRankInfoItem>().RankText.text;
|
||
break;
|
||
}
|
||
}
|
||
if (FactionChallengeCtr.Instace.m_TotalRank != 0)
|
||
{
|
||
m_TotalRankInfoText.text = FactionChallengeCtr.Instace.m_TotalRank.ToString();
|
||
}
|
||
else
|
||
{
|
||
m_TotalRankInfoText.text = GCGame.Table.StrDictionary.GetClientDictionaryString("#{2049}");
|
||
}
|
||
|
||
m_NameText.text = GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.RoleName;
|
||
m_LevelInfoText.text = GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Level.ToString();
|
||
}
|
||
}
|
||
|
||
//是否要显示自身InfoPanel
|
||
void JudgeShowMySelfInfoPanel()
|
||
{
|
||
if(isSelfGroup())
|
||
{
|
||
MyRankInfoPanel.gameObject.SetActive(true);
|
||
NoPlayerRankInfoPanel.gameObject.SetActive(false);
|
||
InitMySelfRankInfo();
|
||
}
|
||
else
|
||
{
|
||
MyRankInfoPanel.gameObject.SetActive(false);
|
||
NoPlayerRankInfoPanel.gameObject.SetActive(true);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
//默认选择的都是第一个
|
||
private int CurSelectedCarrer = -1;
|
||
private int CurSelectedGroup = -1;
|
||
|
||
public void AskRankInfo()
|
||
{
|
||
CG_REQ_USER_CHALLENGE_RANK_LIST ask = (CG_REQ_USER_CHALLENGE_RANK_LIST)PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_USER_CHALLENGE_RANK_LIST);
|
||
ask.SetCareer(CurSelectedCarrer);
|
||
ask.SetLevelFlag(CurSelectedGroup);
|
||
ask.SendPacket();
|
||
}
|
||
|
||
public void OnFactionToggleChange(int index) //选择职业
|
||
{
|
||
if(CurSelectedCarrer == index)
|
||
{
|
||
return;
|
||
}
|
||
for(int _index = 0; _index < _CareerMarkIconList.Count; _index++)
|
||
{
|
||
_CareerMarkIconList[_index].SetActive(index == _index);
|
||
}
|
||
CurSelectedCarrer = index;
|
||
if(CurSelectedGroup == -1)
|
||
{
|
||
return;
|
||
}
|
||
AskRankInfo(); //刷新排行榜信息
|
||
}
|
||
|
||
public void OnGroupToggleChange(int index) //选择分组
|
||
{
|
||
if(index == CurSelectedGroup) // 必做判断 不然刷新100个信息会特别卡
|
||
{
|
||
return;
|
||
}
|
||
for(int _Index = 0; _Index < _MarkIconList.Count; _Index++)
|
||
{
|
||
_MarkIconList[_Index].SetActive(index == _Index);
|
||
}
|
||
CurSelectedGroup = index;
|
||
if(CurSelectedCarrer == -1)
|
||
{
|
||
return;
|
||
}
|
||
AskRankInfo(); //刷新排行榜信息
|
||
}
|
||
|
||
private List<RoleChallengeRankInfo> roleInfoList = new List<RoleChallengeRankInfo>();
|
||
public void InitRankListInfo(GC_RET_USER_CHALLENGE_RANK_LIST packet)
|
||
{
|
||
StartCoroutine(OnPacket(packet));
|
||
}
|
||
|
||
IEnumerator OnPacket(GC_RET_USER_CHALLENGE_RANK_LIST packet)
|
||
{
|
||
yield return new WaitForEndOfFrame();
|
||
for (int index = 0; index < packet.rankListCount; index++)
|
||
{
|
||
RoleChallengeRankInfo roleInfo = new RoleChallengeRankInfo(packet.GetRankList(index).Name,
|
||
packet.GetRankList(index).CurTypeRank + 1,
|
||
packet.GetRankList(index).TotalRank + 1,
|
||
packet.GetRankList(index).Level);
|
||
|
||
//roleInfoList.Add(roleInfo);
|
||
roleInfoPrefabList[index].gameObject.SetActive(true);
|
||
roleInfoPrefabList[index].SetRoleInfo(roleInfo);
|
||
}
|
||
//隐藏剩下的Prefab
|
||
for (int index = packet.rankListCount; index < roleInfoPrefabList.Count; index++)
|
||
{
|
||
roleInfoPrefabList[index].gameObject.SetActive(false);
|
||
}
|
||
|
||
if (packet.rankListCount == 0)
|
||
{
|
||
NoInfoObj.gameObject.SetActive(true);
|
||
}
|
||
else
|
||
{
|
||
NoInfoObj.gameObject.SetActive(false);
|
||
}
|
||
yield return new WaitForEndOfFrame();
|
||
|
||
JudgeShowMySelfInfoPanel();
|
||
|
||
yield break;
|
||
}
|
||
|
||
void createPrefab()
|
||
{
|
||
for (int index = 0; index < 100; index++)
|
||
{
|
||
CreateRoleInfoItemPrefab();
|
||
}
|
||
}
|
||
|
||
|
||
|
||
void CreateRoleInfoItemPrefab()
|
||
{
|
||
GameObject roleInfoPrefab = GameObject.Instantiate(PlayerRankInfoItem);
|
||
|
||
roleInfoPrefab.transform.SetParent(prefabParent);
|
||
roleInfoPrefab.transform.localPosition = Vector3.zero;
|
||
roleInfoPrefab.transform.localRotation = Quaternion.Euler(Vector3.zero);
|
||
roleInfoPrefab.transform.localScale = Vector3.one;
|
||
|
||
roleInfoPrefabList.Add(roleInfoPrefab.GetComponent<FactionPlayerRankInfoItem>());
|
||
}
|
||
|
||
|
||
|
||
|
||
public void OnCloseBtnClick()
|
||
{
|
||
UIManager.CloseUI(UIInfo.FactionRankPanel);
|
||
}
|
||
|
||
}
|