using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
///
/// 武将皮肤形象选择
///
public class HeroSkinChooseWin : UIBase
{
[SerializeField] Button closeBtn;
[SerializeField] Button okBtn;
[SerializeField] ScrollerController skinScroller;
public static int selectIndex;
public static List activeIndexList = new List();
HeroConfig heroConfig;
protected override void InitComponent()
{
closeBtn.AddListener(() =>
{
CloseWindow();
});
okBtn.AddListener(() =>
{
var hero = HeroManager.Instance.GetHero(HeroUIManager.Instance.selectHeroGuid);
HeroUIManager.Instance.SendSkinOP(hero.heroId, heroConfig.SkinIDList[selectIndex], 2, hero.itemHero.gridIndex);
CloseWindow();
});
}
protected override void OnPreOpen()
{
var hero = HeroManager.Instance.GetHero(HeroUIManager.Instance.selectHeroGuid);
heroConfig = hero.heroConfig;
skinScroller.OnRefreshCell += OnRefreshCell;
selectIndex = hero.SkinIndex;
activeIndexList = new List();
for (int i = 0; i < heroConfig.SkinIDList.Length; i++)
{
if (HeroUIManager.Instance.IsHeroSkinActive(hero.heroId, heroConfig.SkinIDList[i]))
{
activeIndexList.Add(i);
}
}
CreateScroller();
}
protected override void OnPreClose()
{
skinScroller.OnRefreshCell -= OnRefreshCell;
heroConfig = null;
}
void CreateScroller()
{
skinScroller.Refresh();
for (int i = 0; i < activeIndexList.Count; i++)
{
if (i % 4 == 0)
{
skinScroller.AddCell(ScrollerDataType.Header, i);
}
}
skinScroller.Restart();
}
void OnRefreshCell(ScrollerDataType type, CellView cell)
{
var _cell = cell as HeroSkinRoleLineCell;
_cell.Display(heroConfig, cell.index);
}
public void SetSelectIndex(int index)
{
selectIndex = index;
skinScroller.m_Scorller.RefreshActiveCellViews();
}
}