using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
public class HeroGiftRoleListCell : CellView
|
{
|
[SerializeField] Button addHeroBtn;
|
[SerializeField] HeroShowBaseCell addHeroShow;
|
[SerializeField] GiftBaseCell[] addGiftCells;
|
[SerializeField] Image onTeamImg;
|
[SerializeField] Toggle selectToggle;
|
|
public void Display(int index)
|
{
|
addHeroBtn.AddListener(()=> { AddHero(index); });
|
|
var hero = HeroManager.Instance.GetHero(HeroUIManager.Instance.heroEatList[index]);
|
addHeroShow.Init(hero.heroId, hero.SkinID, hero.breakLevel, hero.heroStar, hero.awakeLevel, hero.heroLevel, hero.isLock);
|
HeroUIManager.Instance.RefreshGiftCell(addGiftCells, hero);
|
|
onTeamImg.SetActive(hero.IsInAnyTeam());
|
int girdIndex = hero.itemHero.gridIndex;
|
selectToggle.isOn = HeroUIManager.Instance.selectEatHeroIndexList.Contains(girdIndex);
|
|
}
|
|
void AddHero(int index)
|
{
|
var hero = HeroManager.Instance.GetHero(HeroUIManager.Instance.heroEatList[index]);
|
//上阵 锁定 觉醒 的情况
|
if (hero.awakeLevel > 0)
|
{
|
SysNotifyMgr.Instance.ShowTip("HeroReborn1");
|
return;
|
}
|
|
if (hero.IsInAnyTeamJustOne())
|
{
|
//阵容至少要有一个武将上阵
|
SysNotifyMgr.Instance.ShowTip("HeroFunc3");
|
return;
|
}
|
|
if (hero.isLock)
|
{
|
ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"),
|
Language.Get("herocard66"), (bool isOK) =>
|
{
|
if (isOK)
|
{
|
hero.ChangeLockState();
|
}
|
});
|
return;
|
}
|
|
if (hero.IsInAnyTeam())
|
{
|
ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"),
|
Language.Get("herocard65"), (bool isOK) =>
|
{
|
if (isOK)
|
{
|
hero.LeaveAllTeam();
|
}
|
});
|
return;
|
}
|
|
if (hero.heroLevel > 1)
|
{
|
HeroUIManager.Instance.ResetBtnClick(hero);
|
return;
|
}
|
|
int maxStarCnt = HeroUIManager.Instance.GetMaxStarCount(hero.heroId, hero.Quality);
|
int girdIndex = hero.itemHero.gridIndex;
|
if (hero.heroStar > 0 && !selectToggle.isOn)
|
{
|
ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"),
|
Language.Get("HeroGift13"), (bool isOK) =>
|
{
|
if (isOK)
|
{
|
SelectHero(girdIndex, maxStarCnt);
|
}
|
});
|
return;
|
}
|
|
SelectHero(girdIndex, maxStarCnt);
|
|
}
|
|
void SelectHero(int girdIndex, int maxStarCnt)
|
{
|
if (!selectToggle.isOn)
|
{
|
|
//需要统计被吞噬的武将星数
|
int eatStar = 0;
|
for (int i = 0; i < HeroUIManager.Instance.selectEatHeroIndexList.Count; i++)
|
{
|
var hero = HeroManager.Instance.GetHero(HeroUIManager.Instance.heroEatList[i]);
|
if (hero == null)
|
continue;
|
eatStar += hero.heroStar + 1; //本体也算可增加1星
|
}
|
// 需增加待选这只的星级
|
var selectStar = HeroManager.Instance.GetHeroByIndex(girdIndex).heroStar + 1; //本体也算可增加1星
|
|
// 主武将星级
|
var star = HeroManager.Instance.GetHero(HeroUIManager.Instance.selectHeroGuidForGiftFunc)?.heroStar;
|
|
// 只选1只的情况下,如果 39星 + 5星超过了也让可选,其他情况的话需判断星上限
|
if (!(HeroUIManager.Instance.selectEatHeroIndexList.Count == 0 && selectStar > 1))
|
{
|
if (eatStar + selectStar + star > maxStarCnt)
|
{
|
SysNotifyMgr.Instance.ShowTip("HeroGiftEat1");
|
return;
|
}
|
}
|
|
if (!HeroUIManager.Instance.selectEatHeroIndexList.Contains(girdIndex))
|
{
|
HeroUIManager.Instance.selectEatHeroIndexList.Add(girdIndex);
|
selectToggle.isOn = true;
|
|
}
|
}
|
else
|
{
|
if (HeroUIManager.Instance.selectEatHeroIndexList.Contains(girdIndex))
|
{
|
HeroUIManager.Instance.selectEatHeroIndexList.Remove(girdIndex);
|
selectToggle.isOn = false;
|
}
|
}
|
}
|
}
|