using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
///
/// 武将图鉴界面
///
public class HeroCollectionWin : UIBase
{
[SerializeField] Button heroPackBtn;
[SerializeField] Text heroPackText;
[SerializeField] ScrollerController heroListScroller;
// [SerializeField] List totalAttrList;
[SerializeField] Button attrBtn;
[SerializeField] Transform heroSelectBehaviour;
HeroSelectBehaviour fiterManager; //武将筛选
SinglePack singlePack;
protected override void InitComponent()
{
attrBtn.AddListener(() =>
{
SmallTipWin.worldPos = CameraManager.uiCamera.ScreenToWorldPoint(Input.mousePosition);
SmallTipWin.showText = Language.Get("herocard6");
UIManager.Instance.OpenWindow();
});
heroPackBtn.AddListener(() =>
{
HeroUIManager.Instance.QueryUnLockHeroPack();
});
fiterManager = HeroSelectBehaviour.Create(heroSelectBehaviour);
}
protected override void OnPreOpen()
{
singlePack = PackManager.Instance.GetSinglePack(PackType.Hero);
PackManager.Instance.gridRefreshEvent += GridRefreshEvent;
PackManager.Instance.RefreshItemEvent += RefreshItemEvent;
HeroUIManager.Instance.OnHeroCollectEvent += OnHeroCollectEvent;
heroListScroller.OnRefreshCell += OnRefreshCell;
HeroUIManager.Instance.SortHeroCollectList();
Display();
}
protected override void OnPreClose()
{
PackManager.Instance.gridRefreshEvent -= GridRefreshEvent;
PackManager.Instance.RefreshItemEvent -= RefreshItemEvent;
HeroUIManager.Instance.OnHeroCollectEvent -= OnHeroCollectEvent;
heroListScroller.OnRefreshCell -= OnRefreshCell;
}
void Display()
{
fiterManager.Display(0, SelectJobCountry);
// CreateScroller();
// RefreshTotalAttr();
RefreshPackCount();
}
void RefreshItemEvent(PackType type, int index, int itemID)
{
if (type != PackType.Hero)
return;
RefreshPackCount();
}
void RefreshPackCount()
{
int count = singlePack.GetAllItems().Count;
heroPackText.text = UIHelper.AppendColor(count >= singlePack.unlockedGridCount ? TextColType.Red : TextColType.NavyBrown,
string.Format("{0}/{1}", count, singlePack.unlockedGridCount));
}
void GridRefreshEvent(PackType type)
{
if (type != PackType.Hero)
return;
RefreshPackCount();
}
// void RefreshTotalAttr()
// {
// for (int i = 0; i < totalAttrList.Count; i++)
// {
// totalAttrList[i].text = PlayerPropertyConfig.GetFullDescription(PlayerPropertyConfig.basePerAttrs[i],
// HeroUIManager.Instance.allHeroBookPer);
// }
// }
/// 回调参数: 职业,国家,伤害类型,6大战斗属性,特殊属性
void SelectJobCountry(List selects)
{
HeroUIManager.Instance.selectHeroCollectList = selects;
HeroUIManager.Instance.SortHeroCollectList();
CreateScroller();
}
void CreateScroller()
{
int jumpIndex = -1;
int index = -1;
heroListScroller.Refresh();
var _List = HeroUIManager.Instance.heroCollectDict.Keys.ToList();
_List.Reverse();
for (int i = 0; i < _List.Count; i++)
{
var ids = HeroUIManager.Instance.heroCollectDict[_List[i]];
if (ids.Count == 0)
continue;
//品质
heroListScroller.AddCell(ScrollerDataType.Header, _List[i]);
//武将
for (int j = 0; j < ids.Count; j++)
{
if (j % 4 == 0)
{
index++;
CellInfo cellInfo = new CellInfo();
cellInfo.infoInt1 = _List[i];
heroListScroller.AddCell(ScrollerDataType.Normal, j, cellInfo);
}
if (jumpIndex == -1)
{
//检查每个武将
if (HeroUIManager.Instance.IsBookShowRedPoint(ids[j]))
{
jumpIndex = index;
HeroUIManager.Instance.firstHeroIDBookUpdate = ids[j];
}
}
}
index++;
}
heroListScroller.Restart();
heroListScroller.JumpIndex(jumpIndex);
}
void OnRefreshCell(ScrollerDataType type, CellView cell)
{
if (type == ScrollerDataType.Header)
{
var _cell = cell.GetComponent();
_cell.SetSprite("herocoltitle" + cell.index);
}
else if (type == ScrollerDataType.Normal)
{
var _cell = cell as HeroCollectionLineCell;
_cell?.Display(cell.index, cell.info.Value.infoInt1);
}
}
void OnHeroCollectEvent()
{
// RefreshTotalAttr();
heroListScroller.m_Scorller.RefreshActiveCellViews();
}
}