//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Thursday, October 26, 2017
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
//关于Buff面板的设置
|
namespace vnxbqy.UI
|
{
|
|
public class BuffInfoWin : 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<int, ObjBuff> objBuffic;
|
private List<int> _SortList = new List<int>();//排序列表
|
|
BuffModel Buffmodel { get { return ModelCenter.Instance.GetModel<BuffModel>(); } }
|
|
#region Built-in
|
protected override void BindController()
|
{
|
_ScrollRect = Viewport.GetComponent<ScrollRect>();
|
}
|
|
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<BuffBGMScripts>();
|
|
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.SetActive(true);
|
_buffBGM._currentime = 0;
|
_buffBGM._time = objBuffic[_INList].LastTime - _UseTheSecond;
|
_buffBGM._OnOff = true;
|
|
}
|
else
|
{
|
_buffBGM.b_BuffTime.SetActive(false);
|
_buffBGM.b_BuffTime.text = "";
|
}
|
if (objBuffic[_INList].Layer > 0)
|
{
|
_buffBGM.BiBuffText.SetActive(true);
|
_buffBGM.BiBuffText.text = objBuffic[_INList].Layer.ToString();
|
}
|
else
|
{
|
_buffBGM.BiBuffText.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;
|
}
|
|
List<int> Priority()
|
{
|
List<int> _List = new List<int>();
|
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()
|
{
|
objBuffic = Buffmodel._BuffDic;
|
BuffScheduling();
|
UpdateControllerPosition();
|
OnCreateGridLineCell(m_ScrollerController);
|
}
|
|
void DelBuff()
|
{
|
objBuffic = Buffmodel._BuffDic;
|
BuffScheduling();
|
UpdateControllerPosition();
|
OnCreateGridLineCell(m_ScrollerController);
|
}
|
|
}
|
|
}
|