using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
namespace Snxxz.UI
|
{
|
[XLua.LuaCallCSharp]
|
public class RankModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
|
{
|
Dictionary<int, List<RankData>> m_RankDatas = new Dictionary<int, List<RankData>>();
|
|
public Dictionary<int, List<int>> displaySubRanks = new Dictionary<int, List<int>>();
|
public Dictionary<int, bool> subRankSpreads = new Dictionary<int, bool>();
|
public List<int> displayRanks = new List<int>();
|
|
int m_SelectRankId = 0;
|
public int selectRankId
|
{
|
get { return m_SelectRankId; }
|
set
|
{
|
if (m_SelectRankId != value)
|
{
|
m_SelectRankId = value;
|
if (selectRankIdRefresh != null)
|
{
|
selectRankIdRefresh();
|
}
|
}
|
}
|
}
|
|
int m_SelectSubRankId = 0;
|
public int selectSubRankId
|
{
|
get { return m_SelectSubRankId; }
|
set
|
{
|
if (m_SelectSubRankId != value)
|
{
|
m_SelectSubRankId = value;
|
if (selectSubRankIdRefresh != null)
|
{
|
selectSubRankIdRefresh();
|
}
|
}
|
}
|
}
|
|
public int selectRankType
|
{
|
get
|
{
|
if (displaySubRanks.ContainsKey(selectRankId))
|
{
|
var config = RankListConfig.Get(selectSubRankId);
|
return config == null ? 0 : config.type;
|
}
|
else
|
{
|
var config = RankListConfig.Get(selectRankId);
|
return config == null ? 0 : config.type;
|
}
|
}
|
}
|
|
public int displayRankCount { get; private set; }
|
public int jumpRankType { get; set; }
|
|
readonly ObjectPool<RankData> m_RankDataPool = new ObjectPool<RankData>(OnGetRankData, OnReleaseRankData);
|
|
public event Action selectRankIdRefresh;
|
public event Action selectSubRankIdRefresh;
|
public event Action<int> onRankRefresh;
|
|
public override void Init()
|
{
|
jumpRankType = -1;
|
ParseConfig();
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
foreach (var rankDatas in m_RankDatas.Values)
|
{
|
foreach (var item in rankDatas)
|
{
|
m_RankDataPool.Release(item);
|
}
|
}
|
m_RankDatas.Clear();
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
SendBegRank(RankType.JadeDynastyTower);
|
}
|
|
public override void UnInit()
|
{
|
}
|
|
void ParseConfig()
|
{
|
{
|
var config = FuncConfigConfig.Get("RankListCnt");
|
displayRankCount = int.Parse(config.Numerical1);
|
}
|
|
{
|
var configs = RankListConfig.GetValues();
|
foreach (var config in configs)
|
{
|
if (config.ID >= 100)
|
{
|
var rankId = config.ID / 100;
|
List<int> subRanks = null;
|
if (!displaySubRanks.TryGetValue(rankId, out subRanks))
|
{
|
subRanks = new List<int>();
|
displaySubRanks.Add(rankId, subRanks);
|
}
|
subRanks.Add(config.ID);
|
}
|
else
|
{
|
displayRanks.Add(config.ID);
|
}
|
}
|
}
|
}
|
|
public bool TryGetRanks(int type, out List<RankData> ranks)
|
{
|
return m_RankDatas.TryGetValue(type, out ranks);
|
}
|
|
public bool TryGetMyRank(int type, out int rank)
|
{
|
rank = 0;
|
var playerId = PlayerDatas.Instance.baseData.PlayerID;
|
List<RankData> rankDatas = null;
|
if (TryGetRanks(type, out rankDatas))
|
{
|
for (int i = 0; i < rankDatas.Count; i++)
|
{
|
if (rankDatas[i].id == playerId)
|
{
|
rank = i + 1;
|
return true;
|
}
|
}
|
}
|
return false;
|
}
|
|
public void SendBegRank(RankType rankType)
|
{
|
C1001_tagCWatchBillboard rankPack = new C1001_tagCWatchBillboard();
|
rankPack.Type = (byte)rankType;
|
GameNetSystem.Instance.SendInfo(rankPack);
|
}
|
|
|
public void ReceivePackage(H1001_tagBillboard package)
|
{
|
List<RankData> rankDatas = null;
|
if (!m_RankDatas.TryGetValue(package.Type, out rankDatas))
|
{
|
rankDatas = new List<RankData>();
|
m_RankDatas.Add(package.Type, rankDatas);
|
}
|
for (int i = 0; i < package.BillboardCount; i++)
|
{
|
if (i < rankDatas.Count)
|
{
|
rankDatas[i].type = package.Type;
|
ReSetRankData(rankDatas[i], package.Billboard[i]);
|
}
|
else
|
{
|
var rankData = m_RankDataPool.inactivedCount > 0 ?
|
m_RankDataPool.Get() : new RankData();
|
rankData.type = package.Type;
|
ReSetRankData(rankData, package.Billboard[i]);
|
rankDatas.Add(rankData);
|
}
|
}
|
var start = package.BillboardCount;
|
var end = rankDatas.Count;
|
for (int i = end - 1; i >= start; i--)
|
{
|
RankData data = rankDatas[i];
|
rankDatas.RemoveAt(i);
|
m_RankDataPool.Release(data);
|
}
|
if (onRankRefresh != null)
|
{
|
onRankRefresh(package.Type);
|
}
|
}
|
|
void ReSetRankData(RankData data, H1001_tagBillboard.tagBillboardList serverData)
|
{
|
data.id = serverData.ID;
|
data.name1 = serverData.Name1;
|
data.name2 = serverData.Name2;
|
data.subType = serverData.Type2;
|
data.value1 = serverData.Value1;
|
data.value2 = serverData.Value2;
|
data.cmpValue = serverData.CmpValue;
|
data.cmpValue2 = serverData.CmpValue2;
|
data.cmpValue3 = serverData.CmpValue3;
|
}
|
|
static void OnGetRankData(RankData data)
|
{
|
|
}
|
|
static void OnReleaseRankData(RankData data)
|
{
|
|
}
|
}
|
|
public class RankData
|
{
|
public int type;
|
public int subType;
|
public uint id;
|
public string name1;
|
public string name2;
|
public uint value1;
|
public uint value2;
|
public uint cmpValue;
|
public uint cmpValue2;
|
public uint cmpValue3;
|
}
|
}
|