using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
using TableConfig;
|
using System.Linq;
|
using Snxxz.UI;
|
namespace Snxxz.UI
|
{
|
public class RankPanel : Window
|
{
|
[SerializeField] FunctionButton titleRank;
|
[SerializeField] Text m_RankTip;
|
[SerializeField] ScrollerController rankTypeCtrl;
|
private List<RankListConfig> m_RankTypeCfgList;
|
private List<RankListConfig> m_SubRankCfgList = new List<RankListConfig>();
|
private Dictionary<int, bool> m_SubRankSpread = new Dictionary<int, bool>();
|
private int sltRankType = 0;
|
private int sltSubRank = 0;
|
private int sltRankServerType = -1;
|
|
[SerializeField] List<Text> textAttrList;
|
|
[SerializeField] Text textSelfRank;
|
|
[SerializeField] ScrollerController rankListCtrl;
|
|
List<PlayerRankData.RankData> rankList = null;
|
|
FuncConfigConfig funcRankCnt;
|
|
[SerializeField] Button closeBtn;
|
|
private RankModel m_Model;
|
private RankModel model
|
{
|
get
|
{
|
return m_Model ?? (m_Model = ModelCenter.Instance.GetModel<RankModel>());
|
}
|
}
|
|
private RoleParticularModel m_RoleParticularModel;
|
private RoleParticularModel particularModel
|
{
|
get
|
{
|
return m_RoleParticularModel ?? (m_RoleParticularModel = ModelCenter.Instance.GetModel<RoleParticularModel>());
|
}
|
}
|
|
private void OnCloseClick()
|
{
|
Close();
|
}
|
|
void OnRefreshRankType()
|
{
|
if (m_RankTypeCfgList == null)
|
{
|
m_RankTypeCfgList = RankListConfig.GetAllRankType().Values.ToList();
|
for (int i = 0; i < m_RankTypeCfgList.Count; i++)
|
{
|
m_SubRankSpread.Add(m_RankTypeCfgList[i].ID, false);
|
}
|
}
|
rankTypeCtrl.Refresh();
|
m_SubRankCfgList.Clear();
|
for (int i = 0; i < m_RankTypeCfgList.Count; i++)
|
{
|
RankListConfig rank = m_RankTypeCfgList[i];
|
List<RankListConfig> list = RankListConfig.GetAllSubRank(rank.ID);
|
rankTypeCtrl.AddCell(ScrollerDataType.Header, i, OnRankTypeClick);
|
if (list != null && sltRankType == rank.ID && m_SubRankSpread[rank.ID])
|
{
|
for (int j = 0; j < list.Count; j++)
|
{
|
rankTypeCtrl.AddCell(ScrollerDataType.Normal, list[j].ID);
|
}
|
m_SubRankCfgList.AddRange(list);
|
}
|
}
|
rankTypeCtrl.Restart();
|
}
|
|
private void OnRankTypeClick(CellView cell)
|
{
|
OnRankTypeClick(m_RankTypeCfgList[cell.index].ID);
|
}
|
|
private void OnRankTypeClick(int type)
|
{
|
if (type == sltRankType && RankListConfig.GetAllSubRank(type) == null) return;
|
if (RankListConfig.GetAllSubRank(type) != null)
|
{
|
bool _same = sltRankType == type;
|
if (!_same)
|
{
|
m_SubRankSpread[sltRankType] = !m_SubRankSpread[sltRankType];
|
}
|
sltRankType = type;
|
m_SubRankSpread[type] = !m_SubRankSpread[type];
|
OnRefreshRankType();
|
if (!_same) OnSubRankClick(RankListConfig.GetAllSubRank(type)[0]);
|
}
|
else
|
{
|
ClearSubRankSpread();
|
sltRankType = type;
|
OnRefreshRankType();
|
string[] strs = ConfigParse.GetMultipleStr(RankListConfig.GetRankType(sltRankType).RankAtt);
|
SetRankAttr(strs);
|
sltRankServerType = RankListConfig.GetRankType(sltRankType).type;
|
SendBegRank(RankListConfig.GetRankType(sltRankType));
|
sltSubRank = 0;
|
}
|
m_RankTip.text = UIHelper.ReplaceNewLine(Language.Get(StringUtility.Contact("RankTip_", sltRankType)));
|
}
|
|
private void ClearSubRankSpread()
|
{
|
for (int i = 0; i < m_RankTypeCfgList.Count; i++)
|
{
|
m_SubRankSpread[m_RankTypeCfgList[i].ID] = false;
|
}
|
}
|
|
private void OnRefreshRankTypeCell(ScrollerDataType type, CellView cell)
|
{
|
switch (type)
|
{
|
case ScrollerDataType.Header:
|
{
|
RankListConfig cfg = m_RankTypeCfgList[cell.index];
|
if (cfg != null)
|
{
|
Text text = cell.transform.Find("Txt").GetComponent<Text>();
|
text.text = cfg.ListName;
|
Image img = cell.GetComponent<Image>();
|
if (cfg.ID == sltRankType)
|
{
|
img.SetSprite("ListBtn_Select");
|
}
|
else
|
{
|
img.SetSprite("ListBtn_UnSelect");
|
}
|
if (RankListConfig.GetAllSubRank(cfg.ID) == null)
|
{
|
img = cell.transform.Find("Arrow").GetComponent<Image>();
|
img.gameObject.SetActive(false);
|
}
|
else
|
{
|
if (m_SubRankSpread[cfg.ID])
|
{
|
img.SetSprite("ListBtn_UnSelect");
|
}
|
img = cell.transform.Find("Arrow").GetComponent<Image>();
|
img.gameObject.SetActive(true);
|
img.transform.localEulerAngles = m_SubRankSpread[cfg.ID] ? new Vector3(0, 0, -90) : Vector3.zero;
|
img.SetSprite(m_SubRankSpread[cfg.ID] ? "Arrow_a" : "ArrowLight_a");
|
}
|
}
|
}
|
break;
|
case ScrollerDataType.Normal:
|
{
|
RankListConfig cfg = RankListConfig.GetSubRank(cell.index);
|
if (cfg != null)
|
{
|
Text text = cell.transform.Find("Button/Text").GetComponent<Text>();
|
text.text = cfg.ListName;
|
Button btn = cell.transform.Find("Button").GetComponent<Button>();
|
btn.onClick.RemoveAllListeners();
|
btn.onClick.AddListener(() =>
|
{
|
OnSubRankClick(cfg);
|
});
|
Image img = btn.GetComponent<Image>();
|
if (cfg.ID == sltSubRank)
|
{
|
img.SetSprite("ChildListBtn_Select");
|
}
|
else
|
{
|
img.SetSprite("ChildListBtn_UnSelect");
|
}
|
}
|
}
|
break;
|
}
|
}
|
|
private void OnSubRankClick(RankListConfig cfg)
|
{
|
if (sltSubRank == cfg.ID) return;
|
sltRankServerType = cfg.type;
|
sltSubRank = cfg.ID;
|
string[] strs = ConfigParse.GetMultipleStr(cfg.RankAtt);
|
SetRankAttr(strs);
|
rankTypeCtrl.m_Scorller.RefreshActiveCellViews();
|
SendBegRank(cfg);
|
}
|
|
private void SendBegRank(RankListConfig cfg)
|
{
|
OnRefreshRankList(cfg.type);
|
if (PlayerDatas.Instance.rank.GetRankList((int)cfg.type) != null)
|
{
|
if (!CoroutineMgr.Instance.CanBegRank(cfg.type))
|
{
|
return;
|
}
|
}
|
if (CoroutineMgr.Instance.CanBegRank(cfg.type))
|
{
|
CoroutineMgr.Instance.StartBegRank(cfg.type);
|
}
|
C1001_tagCWatchBillboard rankPack = new C1001_tagCWatchBillboard();
|
rankPack.Type = (byte)cfg.type;
|
GameNetSystem.Instance.SendInfo(rankPack);
|
}
|
|
private void SetRankAttr(string[] strs)
|
{
|
for (int i = 0; i < textAttrList.Count; i++)
|
{
|
if (strs != null && i < strs.Length)
|
{
|
textAttrList[i].gameObject.SetActive(true);
|
textAttrList[i].text = strs[i];
|
}
|
else
|
{
|
textAttrList[i].gameObject.SetActive(false);
|
}
|
}
|
}
|
|
private void OnRefreshRankList(int type)
|
{
|
if (type != sltRankServerType) return;
|
model.rankType = type;
|
rankList = PlayerDatas.Instance.rank.GetRankList(type);
|
if (rankListCtrl.GetNumberOfCells(rankListCtrl.m_Scorller) < 1)
|
{
|
rankListCtrl.Refresh();
|
for (int i = 0; i < int.Parse(funcRankCnt.Numerical1); i++)
|
{
|
if (i % 2 == 0)
|
{
|
rankListCtrl.AddCell(ScrollerDataType.Normal, i, OnRankListClick);
|
}
|
else
|
{
|
rankListCtrl.AddCell(ScrollerDataType.Header, i, OnRankListClick);
|
}
|
}
|
rankListCtrl.Restart();
|
}
|
else
|
{
|
rankListCtrl.m_Scorller.RefreshActiveCellViews();
|
rankListCtrl.JumpIndex(0);
|
}
|
int rank = PlayerDatas.Instance.rank.GetSelfRank(type);
|
if (rank == -1)
|
{
|
textSelfRank.text = Language.Get("L1045");
|
}
|
else
|
{
|
textSelfRank.text = Language.Get("L1092", rank);
|
}
|
}
|
private void OnRankListClick(CellView cell)
|
{
|
int index = cell.index;
|
if (index < model.rankList.Count)
|
{
|
if (model.rankList[index].ID == PlayerDatas.Instance.baseData.PlayerID)
|
{
|
SysNotifyMgr.Instance.ShowTip("SeePlayer_Cannot");
|
return;
|
}
|
particularModel.ViewRoleEquip((int)model.rankList[index].ID);
|
}
|
}
|
|
protected override void BindController()
|
{
|
|
}
|
|
protected override void AddListeners()
|
{
|
rankTypeCtrl.OnRefreshCell += OnRefreshRankTypeCell;
|
rankTypeCtrl.lockType = EnhanceLockType.KeepVertical;
|
closeBtn.onClick.AddListener(OnCloseClick);
|
|
}
|
|
protected override void OnPreOpen()
|
{
|
PlayerDatas.Instance.rank.OnRefreshRank += OnRefreshRankList;
|
|
if (funcRankCnt == null) funcRankCnt = Config.Instance.Get<FuncConfigConfig>("RankListCnt");
|
|
sltRankType = 0;
|
sltSubRank = 0;
|
|
OnRefreshRankType();
|
rankTypeCtrl.JumpIndex(0);
|
OnRankTypeClick(1);
|
}
|
|
protected override void OnActived()
|
{
|
base.OnActived();
|
titleRank.state = TitleBtnState.Click;
|
}
|
|
protected override void OnAfterOpen()
|
{
|
|
}
|
|
protected override void OnPreClose()
|
{
|
ClearSubRankSpread();
|
}
|
|
protected override void OnAfterClose()
|
{
|
PlayerDatas.Instance.rank.OnRefreshRank -= OnRefreshRankList;
|
if (!WindowJumpMgr.Instance.IsJumpState)
|
{
|
WindowCenter.Instance.Open<MainInterfaceWin>();
|
}
|
}
|
}
|
}
|
|