//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Thursday, October 26, 2017 //-------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; //关于Buff面板的设置 namespace Snxxz.UI { public class BuffListWin : Window { public float UpperAndLower = 50f; public float ItemHeight = 50f; public float MaxHeight = 300f; [SerializeField] Transform Viewport; [SerializeField] ScrollerController m_ScrollerController; private ScrollRect _ScrollRect; private Dictionary objBuffic; private List _SortList = new List();//排序列表 BuffModel m_BuffModel; BuffModel Buffmodel { get { return m_BuffModel ?? (m_BuffModel = ModelCenter.Instance.GetModel()); } } #region Built-in protected override void BindController() { _ScrollRect = Viewport.GetComponent(); } protected override void AddListeners() { } protected override void OnPreOpen() { objBuffic = Buffmodel._BuffDic; m_ScrollerController.OnRefreshCell += OnRefreshGridCell; BuffModel.Even_ObjAddBuf += AddBuff; BuffModel.Even_ObjDelBuff += DelBuff; BuffScheduling(); UpdateControllerPosition(); OnCreateGridLineCell(m_ScrollerController); } protected override void OnAfterOpen() { } protected override void OnPreClose() { } protected override void OnAfterClose() { m_ScrollerController.OnRefreshCell -= OnRefreshGridCell; BuffModel.Even_ObjAddBuf -= AddBuff; BuffModel.Even_ObjDelBuff -= DelBuff; } #endregion void UpdateControllerPosition() { if (_SortList.Count == 0) { Close(); return; } if (_SortList.Count * ItemHeight >= MaxHeight) { _ScrollRect.vertical = true; (Viewport as RectTransform).sizeDelta = (Viewport as RectTransform).sizeDelta.SetY(MaxHeight + UpperAndLower); } else { _ScrollRect.vertical = false; (Viewport as RectTransform).sizeDelta = (Viewport as RectTransform).sizeDelta.SetY(_SortList.Count * ItemHeight + UpperAndLower); } } void OnCreateGridLineCell(ScrollerController gridCtrl)//预制体创建 { gridCtrl.Refresh(); for (int i = 0; i < _SortList.Count; i++) { gridCtrl.AddCell(ScrollerDataType.Header, i); } gridCtrl.Restart(); } void OnRefreshGridCell(ScrollerDataType type, CellView cell) { int _index = cell.index; BuffBGMScripts _buffBGM = cell.GetComponent(); int _INList = _SortList[_index]; _buffBGM.b_BuffIcon.SetSprite(objBuffic[_INList].ImagKey); _buffBGM.b_BuffName.text = objBuffic[_INList].BuffName; _buffBGM.b_BuffContent.text = objBuffic[_INList].BuffConent; int _UseTheSecond = Mathf.FloorToInt((float)(DateTime.Now - objBuffic[_INList]._dattTime).TotalSeconds); if (objBuffic[_INList].LastTime - _UseTheSecond > 0) { _buffBGM.b_BuffTime.gameObject.SetActive(true); _buffBGM._currentime = 0; _buffBGM._time = objBuffic[_INList].LastTime - _UseTheSecond; _buffBGM._OnOff = true; } else { _buffBGM.b_BuffTime.gameObject.SetActive(false); _buffBGM.b_BuffTime.text = ""; } if (objBuffic[_INList].Layer > 0) { _buffBGM.BiBuffText.gameObject.SetActive(true); _buffBGM.BiBuffText.text = objBuffic[_INList].Layer.ToString(); } else { _buffBGM.BiBuffText.gameObject.SetActive(false); } } void BuffScheduling()//buff排序 { _SortList.Clear(); foreach (int key in objBuffic.Keys) { _SortList.Add(key); } _SortList.Sort(Compare); } int Compare(int x, int y) { bool havex = IsExperience(x); bool havey = IsExperience(y); if (havex.CompareTo(havey) != 0) { return -havex.CompareTo(havey); } int havex1 = TimeClassification(x); int havey1 = TimeClassification(y); if (havex1.CompareTo(havey1) != 0) { return havex1.CompareTo(havey1); } ObjBuff xPack = objBuffic[x]; ObjBuff yPack = objBuffic[y]; if (xPack._dattTime.CompareTo(yPack._dattTime) != 0) { return -xPack._dattTime.CompareTo(yPack._dattTime); } return 1; } private bool IsExperience(int BuffID)//判断是否是经验类型Buff { bool IsBool = false; if (objBuffic.ContainsKey(BuffID)) { if (objBuffic[BuffID].BuffType == 9) { IsBool = true; } } return IsBool; } private int TimeClassification(int BuffID)//时间分类 { int Type = 0; return Type; int Use_TheSecond = Mathf.FloorToInt((float)(DateTime.Now - objBuffic[BuffID]._dattTime).TotalSeconds); if (objBuffic[BuffID].LastTime - Use_TheSecond > 0) { float time = objBuffic[BuffID].LastTime - Use_TheSecond; if (time >= 86400)//天 { return 4; } else if (time < 86400 && time >= 3600)//时 { return 3; } else if (time < 3600 && time >= 60)//分 { return 2; } else if (time < 60 && time > 0)//秒 { return 1; } else { return 0; } } else { return 0; } } List Priority() { List _List = new List(); string[] _strList = FuncConfigConfig.Get("BuffType").Numerical2.Split('|'); for (int i = 0; i < _strList.Length; i++) { _List.Add(int.Parse(_strList[i])); } return _List; } void AddBuff()//buff的增加 { objBuffic = Buffmodel._BuffDic; BuffScheduling(); UpdateControllerPosition(); OnCreateGridLineCell(m_ScrollerController); } void DelBuff()//buff的删除 { objBuffic = Buffmodel._BuffDic; BuffScheduling(); UpdateControllerPosition(); OnCreateGridLineCell(m_ScrollerController); } } }