using System;
using UnityEngine;
using UnityEngine.UI;
///
/// 武将皮肤
///
public class HeroSkinWin : UIBase
{
[SerializeField] RawImage bgTexture;
[SerializeField] Button showFuncBtn; //只显示立绘时点击,显示功能
[SerializeField] Transform funcForm;
[SerializeField] UIHeroController roleLhModel; //展示英雄立绘
[SerializeField] UIHeroController roleXsModel; //像素
[SerializeField] Button seeLhBtn; //查看立绘
[SerializeField] Button previewFightBtn; //预览战斗
[SerializeField] Button shopBtn; //商店
[SerializeField] Button changeClothBtn; //只更换服装外观
[SerializeField] GradientText nameText;
[SerializeField] Text skinNameText;
// [SerializeField] Text skinLVText;
//属性区
[SerializeField] Text[] onAttrText; //穿戴属性
[SerializeField] Text[] allAttrText; //全体加成
[SerializeField] Transform attrObj;
[SerializeField] ScrollerController skinScroller;
[SerializeField] Button unlockBtn;
[SerializeField] Image itemIcon;
[SerializeField] Text itemCountText;
[SerializeField] Button putonBtn;
[SerializeField] GameObject putonYetObj;
[SerializeField] Button showGetObj;
[SerializeField] GameObject showNormalObj;
HeroConfig heroConfig;
int heroID;
int skinID;
public HeroInfo hero;
int tmpIndex; //皮肤界面可以同时从图鉴和培养界面打开,所以需要一个临时变量来缓存避免报错
protected override void InitComponent()
{
showFuncBtn.AddListener(() =>
{
funcForm.SetActive(true);
ChangeParentWinAlpha(1);
});
seeLhBtn.AddListener(() =>
{
funcForm.SetActive(false);
ChangeParentWinAlpha(0);
});
previewFightBtn.AddListener(() =>
{
var config = HeroConfig.Get(heroID);
int index = Array.IndexOf(config.SkinIDList, skinID);
BattleManager.Instance.SendTurnFight(30000, valueList: new uint[] { (uint)heroID, (uint)index });
});
shopBtn.AddListener(() =>
{
UIManager.Instance.OpenWindow(1);
});
unlockBtn.AddListener(() =>
{
UnLockSkin();
});
putonBtn.AddListener(() =>
{
if (hero == null)
{
return;
}
HeroUIManager.Instance.SendSkinOP(heroID, skinID, 4, hero.itemHero.gridIndex);
});
showGetObj.AddListener(() =>
{
showGetObj.SetActive(false);
showNormalObj.SetActive(true);
ChangeParentWinAlpha(1);
});
changeClothBtn.AddListener(() =>
{
UIManager.Instance.OpenWindow();
});
}
int activeSkinID;
protected override void OnPreOpen()
{
activeSkinID = 0;
skinScroller.OnRefreshCell += OnRefreshCell;
if (functionOrder == 0)
{
//代表从培养界面打开
hero = HeroManager.Instance.GetHero(HeroUIManager.Instance.selectHeroGuid);
heroConfig = hero.heroConfig;
if (HeroUIManager.Instance.selectSkinIndex == -1)
{
HeroUIManager.Instance.selectSkinIndex = hero.SkinIndex;
}
}
else
{
//从图鉴界面打开
heroConfig = HeroConfig.Get(HeroUIManager.Instance.selectForPreviewHeroID);
if (HeroUIManager.Instance.selectSkinIndex == -1)
{
HeroUIManager.Instance.selectSkinIndex = 0;
}
}
tmpIndex = HeroUIManager.Instance.selectSkinIndex;
heroID = heroConfig.HeroID;
HeroUIManager.Instance.OnSkinIndexChanged += OnSkinIndexChanged;
HeroUIManager.Instance.OnHeroCollectEvent += OnHeroCollectEvent;
PackManager.Instance.RefreshItemEvent += OnRefreshItemEvent;
showGetObj.SetActive(false);
showNormalObj.SetActive(true);
Display();
CreateScroller();
}
protected override void OnPreClose()
{
skinScroller.OnRefreshCell -= OnRefreshCell;
HeroUIManager.Instance.OnSkinIndexChanged -= OnSkinIndexChanged;
HeroUIManager.Instance.OnHeroCollectEvent -= OnHeroCollectEvent;
PackManager.Instance.RefreshItemEvent -= OnRefreshItemEvent;
hero = null;
heroConfig = null;
HeroUIManager.Instance.selectSkinIndex = -1;
}
public void Display()
{
//只对异常处理
if (HeroUIManager.Instance.selectSkinIndex >= heroConfig.SkinIDList.Length ||
HeroUIManager.Instance.selectSkinIndex < 0)
{
if (HeroUIManager.Instance.selectSkinIndex == -1)
{
HeroUIManager.Instance.selectSkinIndex = 0; //默认第一个 说明是另外地方清除(关闭)
}
tmpIndex = 0;
}
else
{
tmpIndex = HeroUIManager.Instance.selectSkinIndex;
}
skinID = heroConfig.SkinIDList[tmpIndex];
bgTexture.SetTexture2D(HeroUIManager.Instance.GetBGName(skinID, heroConfig.Country));
roleLhModel.Create(skinID, 1, motionName: "", isLh: true);
roleXsModel.Create(skinID, 1);
HeroUIManager.Instance.PlayerLHSound(skinID);
nameText.text = heroConfig.Name;
switch (heroConfig.Quality)
{
case 3:
//fff8db
// nameText.topLeftColor = new Color(0.98f, 0.94f, 0.91f);
nameText.topLeftColor = new Color(1f, 1f, 1f);
//ffe050
nameText.bottomLeftColor = new Color(0.98f, 0.88f, 0.25f);
break;
case 4:
// ffe8db
// ff9250
// nameText.topLeftColor = new Color(0.98f, 0.94f, 0.91f);
nameText.topLeftColor = new Color(1f, 1f, 1f);
nameText.bottomLeftColor = new Color(0.98f, 0.41f, 0.25f);
break;
case 5:
// ffdbdb
// ff5050
// nameText.topLeftColor = new Color(0.98f, 0.88f, 0.88f);
nameText.topLeftColor = new Color(1f, 1f, 1f);
nameText.bottomLeftColor = new Color(0.98f, 0.25f, 0.25f);
break;
}
skinNameText.text = HeroSkinConfig.Get(skinID).SkinName;
RefreshAttr();
ShowBtns();
HeroUIManager.Instance.skinRedpoint.state = HeroUIManager.Instance.HeroAllSkinStateForRedpoint(heroID, hero == null) > 0 ? RedPointState.Simple : RedPointState.None;
}
void RefreshAttr()
{
var cfg = HeroSkinAttrConfig.Get(skinID);
if (cfg == null)
{
attrObj.SetActive(false);
return;
}
attrObj.SetActive(true);
string format = "{0}" + UIHelper.AppendColor(TextColType.Green, "+{1}", false);
for (int i = 0; i < onAttrText.Length; i++)
{
if (i < cfg.WearAttrIDList.Length)
{
onAttrText[i].text = PlayerPropertyConfig.GetFullDescription(cfg.WearAttrIDList[i], cfg.WearAttrValueList[i], format);
}
else
{
onAttrText[i].text = "";
}
}
for (int i = 0; i < allAttrText.Length; i++)
{
if (i < cfg.RoleAttrIDList.Length)
{
allAttrText[i].text = PlayerPropertyConfig.GetFullDescription(cfg.RoleAttrIDList[i], cfg.RoleAttrValueList[i], format);
}
else
{
allAttrText[i].text = "";
}
}
}
void CreateScroller()
{
skinScroller.Refresh();
for (int i = 0; i < heroConfig.SkinIDList.Length; i++)
{
skinScroller.AddCell(ScrollerDataType.Header, i);
}
skinScroller.Restart();
if (tmpIndex > 2)
{
skinScroller.JumpIndex(tmpIndex - 1);
}
}
void OnRefreshCell(ScrollerDataType type, CellView cell)
{
var _cell = cell as HeroSkinCell;
_cell.Display(heroID, cell.index, hero != null);
}
void OnSkinIndexChanged()
{
Display();
skinScroller.m_Scorller.RefreshActiveCellViews();
}
void OnHeroCollectEvent()
{
if (activeSkinID == skinID && HeroUIManager.Instance.IsHeroSkinActive(heroID, skinID))
{
showGetObj.SetActive(true);
ChangeParentWinAlpha(0);
showNormalObj.SetActive(false);
Display();
skinScroller.m_Scorller.RefreshActiveCellViews();
activeSkinID = 0;
return;
}
}
void OnRefreshItemEvent(PackType type, int index, int itemID)
{
if (type == PackType.Hero)
{
ShowBtns();
skinScroller.m_Scorller.RefreshActiveCellViews();
}
}
void UnLockSkin()
{
var cfg = HeroSkinAttrConfig.Get(skinID);
if (cfg == null)
{
return;
}
if (!ItemLogicUtility.CheckItemCount(PackType.Item, cfg.NeedItemID, 1, 2))
{
return;
}
activeSkinID = skinID;
HeroUIManager.Instance.SendSkinOP(heroID, skinID, 1);
}
void ShowBtns()
{
if (hero == null)
{
putonBtn.SetActive(false);
putonYetObj.SetActive(false);
shopBtn.SetActive(false);
changeClothBtn.SetActive(false);
}
else
{
shopBtn.SetActive(true);
changeClothBtn.SetActive(true);
}
if (!HeroUIManager.Instance.IsHeroSkinActive(heroID, skinID))
{
var cfg = HeroSkinAttrConfig.Get(skinID);
if (cfg == null)
{
unlockBtn.SetActive(false);
}
else
{
unlockBtn.SetActive(true);
int itemID = cfg.NeedItemID;
itemIcon.SetItemSprite(itemID);
itemCountText.text = UIHelper.ShowUseItem(PackType.Item, itemID, 1, bright: false);
}
putonBtn.SetActive(false);
putonYetObj.SetActive(false);
return;
}
unlockBtn.SetActive(false);
if (hero == null) return;
putonBtn.SetActive(hero.SkinAttrID != skinID);
putonYetObj.SetActive(hero.SkinAttrID == skinID);
}
void ChangeParentWinAlpha(float alpha)
{
if (hero != null)
{
UIManager.Instance.GetUI().GetCanvasGroup().alpha = alpha;
}
else
{
UIManager.Instance.GetUI().GetCanvasGroup().alpha = alpha;
}
}
}