using System.Collections.Generic;
|
using System.Linq;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
|
/// <summary>
|
/// 武将图鉴界面
|
/// </summary>
|
public class HeroCollectionWin : UIBase
|
{
|
[SerializeField] Button heroPackBtn;
|
[SerializeField] Text heroPackText;
|
[SerializeField] ScrollerController heroListScroller;
|
[SerializeField] List<Text> totalAttrList;
|
[SerializeField] Button attrBtn;
|
[SerializeField] 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<SmallTipWin>();
|
});
|
|
heroPackBtn.AddListener(() =>
|
{
|
HeroUIManager.Instance.QueryUnLockHeroPack();
|
});
|
}
|
|
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.selectHeroCollectListJob = 0;
|
HeroUIManager.Instance.selectHeroCollectListCountry = 0;
|
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, HeroUIManager.Instance.selectHeroCollectListJob, HeroUIManager.Instance.selectHeroCollectListCountry, 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);
|
}
|
}
|
|
|
void SelectJobCountry(int job, int country)
|
{
|
HeroUIManager.Instance.selectHeroCollectListJob = job;
|
HeroUIManager.Instance.selectHeroCollectListCountry = country;
|
HeroUIManager.Instance.SortHeroCollectList();
|
CreateScroller();
|
}
|
|
|
void CreateScroller()
|
{
|
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)
|
{
|
CellInfo cellInfo = new CellInfo();
|
cellInfo.infoInt1 = _List[i];
|
heroListScroller.AddCell(ScrollerDataType.Normal, j, cellInfo);
|
}
|
}
|
}
|
heroListScroller.Restart();
|
}
|
|
|
void OnRefreshCell(ScrollerDataType type, CellView cell)
|
{
|
if (type == ScrollerDataType.Header)
|
{
|
var _cell = cell.GetComponent<Image>();
|
_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();
|
}
|
|
}
|