| using System.Collections.Generic; | 
| using System.Linq; | 
| using UnityEngine; | 
| using UnityEngine.UI; | 
|   | 
|   | 
| /// <summary> | 
| /// 武将培养界面 | 
| /// </summary> | 
| public class HeroTrainWin : UIBase | 
| { | 
|     [SerializeField] Button showFuncBtn;    //只显示立绘时点击,显示功能 | 
|     [SerializeField] Transform funcForm; | 
|     [SerializeField] UIHeroController roleLhModel;    //展示英雄立绘 | 
|     [SerializeField] Button rightBtn; | 
|     [SerializeField] Button leftBtn; | 
|     [SerializeField] UIHeroController roleXsModel;  //像素 | 
|     [SerializeField] UIEffectPlayer lvupEffect; | 
|     [SerializeField] Image jobImg; | 
|     [SerializeField] Text jobPosNameText; | 
|     [SerializeField] Text descText; | 
|     [SerializeField] Text fightPowerText;   //由客户端自己预算的战力 | 
|     [SerializeField] Button lockBtn; | 
|     [SerializeField] Image lockImg; | 
|     [SerializeField] Image unLockImg; | 
|     [SerializeField] HeroConnectionCell connetionForm;  //羁绊 | 
|     [SerializeField] Button resetBtn; | 
|     [SerializeField] Button deleteBtn; | 
|     [SerializeField] Button seeLhBtn;   //查看立绘 | 
|     [SerializeField] SkillBaseCell normalSkillCell; | 
|     [SerializeField] SkillBaseCell angerSkillCell; | 
|     [SerializeField] Button awakeBtn; | 
|   | 
|     [SerializeField] Button closeBtn;   //关闭按钮 | 
|   | 
|     [SerializeField] List<Image> starImgList; | 
|     [SerializeField] Text nameText; | 
|     [SerializeField] UIEffectPlayer nameEffect; | 
|     [SerializeField] Image countryImg; | 
|     [SerializeField] Text awakeLVText; | 
|   | 
|     [SerializeField] Button attrBtn; | 
|     [SerializeField] Image unfoldImg; //展开时按钮的图标 | 
|     [SerializeField] Image foldImg; //收起时按钮的图标 | 
|     bool unfoldState = false;//是否展开 | 
|     [SerializeField] Transform foldPos; | 
|     [SerializeField] Transform unfoldPos;   //展开时的位置 | 
|     [SerializeField] RectTransform attrPanel;  //显示的属性栏 | 
|     [SerializeField] RectTransform attrScroll; | 
|     [SerializeField] RichText inheritText;   //武将继承描述 | 
|     [SerializeField] Text[] inheritAttrText;    //武将会继承的属性 | 
|     [SerializeField] RichText heroAddPerText; //主公(上阵)加成描述 | 
|     [SerializeField] Text[] heroAddAttrPerText; //主公(上阵)加成 | 
|     [SerializeField] Text[] addPerText;    //增加百分比(飘动) | 
|     [SerializeField] PositionTween addPerObject; | 
|     [SerializeField] Image lvupMoneyIcon; | 
|     [SerializeField] Text lvupMoneyText; | 
|     [SerializeField] Text lvupBtnText; | 
|     [SerializeField] LongPressButton lvupBtn; | 
|     [SerializeField] Button allAttrBtn; | 
|     [SerializeField] Text allPotentialText; //潜能 | 
|     string guid; | 
|     HeroInfo hero; | 
|     protected override void InitComponent() | 
|     { | 
|         showFuncBtn.AddListener(() => | 
|         { | 
|             funcForm.SetActive(true); | 
|         }); | 
|         seeLhBtn.AddListener(() => | 
|         { | 
|             funcForm.SetActive(false); | 
|         }); | 
|         closeBtn.AddListener(CloseWindow); | 
|         rightBtn.AddListener(() => | 
|         { | 
|             ChangeHero(1); | 
|         }); | 
|         leftBtn.AddListener(() => | 
|         { | 
|             ChangeHero(-1); | 
|         }); | 
|   | 
|         lockBtn.AddListener(SetLockState); | 
|         resetBtn.AddListener(ResetBtnClick); | 
|         deleteBtn.AddListener(DeleteHero); | 
|         awakeBtn.AddListener(() => | 
|         { | 
|             // UIManager.Instance.OpenWindow<HeroAwakeWin>(hero.heroId); | 
|         }); | 
|         inheritText.OnClick = () => | 
|         { | 
|             SmallTipWin.showText = Language.Get("herocard47"); | 
|             SmallTipWin.worldPos = CameraManager.uiCamera.ScreenToWorldPoint(Input.mousePosition); | 
|             UIManager.Instance.OpenWindow<SmallTipWin>(); | 
|         }; | 
|         heroAddPerText.OnClick = () => | 
|         { | 
|             SmallTipWin.showText = Language.Get("herocard48"); | 
|             SmallTipWin.worldPos = CameraManager.uiCamera.ScreenToWorldPoint(Input.mousePosition); | 
|             UIManager.Instance.OpenWindow<SmallTipWin>(); | 
|         }; | 
|         attrBtn.AddListener(() => | 
|         { | 
|             unfoldState = !unfoldState; | 
|             RefreshFoldState(); | 
|         }); | 
|   | 
|         allAttrBtn.AddListener(() => | 
|         { | 
|             UIManager.Instance.OpenWindow<HeroAllAttrWin>(hero.itemHero.gridIndex); | 
|         }); | 
|         lvupBtn.AddListener(LVUp); | 
|         lvupBtn.onPress.AddListener(LVUp); | 
|     } | 
|   | 
|   | 
|     protected override void OnPreOpen() | 
|     { | 
|         PackManager.Instance.RefreshItemLockEvent += RefreshItemLockEvent; | 
|         HeroManager.Instance.onHeroChangeEvent += RefreshHeroEvent; | 
|         guid = HeroUIManager.Instance.selectHeroGuid; | 
|         hero = HeroManager.Instance.GetHero(guid); | 
|         unfoldState = false; | 
|         addPerObject.SetActive(false); | 
|         Refresh(); | 
|     } | 
|   | 
|     protected override void OnPreClose() | 
|     { | 
|         PackManager.Instance.RefreshItemLockEvent -= RefreshItemLockEvent; | 
|         HeroManager.Instance.onHeroChangeEvent -= RefreshHeroEvent; | 
|     } | 
|   | 
|   | 
|     public override void Refresh() | 
|     { | 
|         roleLhModel.Create(hero.SkinID, 0.6f, motionName: "", isLh: true); | 
|         roleXsModel.Create(hero.SkinID); | 
|         jobImg.SetSprite(HeroUIManager.Instance.GetJobIconName(hero.heroConfig.Class)); | 
|         jobPosNameText.text = HeroUIManager.Instance.GetJobName(hero.heroConfig.Class); | 
|         descText.text = hero.heroConfig.Desc; | 
|         fightPowerText.text = UIHelper.ReplaceLargeArtNum(hero.CalculatePower()); | 
|         lockImg.SetActive(hero.isLock); | 
|         unLockImg.SetActive(!hero.isLock); | 
|         nameText.text = hero.breakLevel == 0 ? hero.heroConfig.Name : Language.Get("herocardbreaklv", hero.heroConfig.Name, hero.breakLevel); | 
|   | 
|         RefreshConn(); | 
|         normalSkillCell.Init(hero.heroConfig.AtkSkillID, () => | 
|         { | 
|             UIManager.Instance.OpenWindow<HeroSkillWin>(hero.heroId); | 
|         }, true); | 
|         angerSkillCell.Init(hero.heroConfig.AngerSkillID, () => | 
|         { | 
|             UIManager.Instance.OpenWindow<HeroSkillWin>(hero.heroId); | 
|         }, true); | 
|   | 
|         awakeBtn.SetActive(HeroAwakeConfig.CanAwake(hero.heroId, 1)); | 
|   | 
|         RefreshName(); | 
|         RefreshFoldState(); | 
|         RefreshAttr(); | 
|         RefreshAllPotential(); | 
|     } | 
|   | 
|     void RefreshItemLockEvent(PackType type, string guid, bool lockState) | 
|     { | 
|         if (type != PackType.Hero) | 
|             return; | 
|         lockImg.SetActive(hero.isLock); | 
|         unLockImg.SetActive(!hero.isLock); | 
|     } | 
|   | 
|     void RefreshHeroEvent(HeroInfo hero) | 
|     { | 
|         Refresh(); | 
|     } | 
|   | 
|     void RefreshConn() | 
|     { | 
|         if (hero.heroConfig.FetterIDList.Length > 0) | 
|         { | 
|             connetionForm.SetActive(true); | 
|             connetionForm.Display(hero.heroConfig.FetterIDList[0], Language.Get("herocard40"), true, guid); | 
|         } | 
|         else | 
|         { | 
|             connetionForm.SetActive(false); | 
|         } | 
|   | 
|     } | 
|   | 
|     void ChangeHero(int changeValue) | 
|     { | 
|         var index = HeroUIManager.Instance.heroSortList.IndexOf(guid); | 
|         if (index == -1) | 
|             return; | 
|         int resultIndex = index + changeValue; | 
|         //循环处理 | 
|         if (resultIndex < 0) | 
|         { | 
|             resultIndex = HeroUIManager.Instance.heroSortList.Count - 1; | 
|         } | 
|         else if (resultIndex > HeroUIManager.Instance.heroSortList.Count - 1) | 
|         { | 
|             resultIndex = 0; | 
|         } | 
|         guid = HeroUIManager.Instance.heroSortList[resultIndex]; | 
|         hero = HeroManager.Instance.GetHero(guid); | 
|         Refresh(); | 
|     } | 
|   | 
|     void SetLockState() | 
|     { | 
|         var pack = new CB238_tagCSHeroLock(); | 
|         pack.ItemIndex = (ushort)hero.itemHero.gridIndex; | 
|         pack.IsLock = hero.isLock ? (byte)0 : (byte)1; | 
|         GameNetSystem.Instance.SendInfo(pack); | 
|     } | 
|   | 
|     void ResetBtnClick() | 
|     { | 
|         //升级、突破、觉醒 | 
|         if (hero.heroLevel == 1 && hero.breakLevel == 0 && hero.awakeLevel == 0) | 
|         { | 
|             SysNotifyMgr.Instance.ShowTip("HeroCanNotReset"); | 
|             return; | 
|         } | 
|   | 
|         List<Item> items = new List<Item>(); | 
|   | 
|   | 
|         var payBack1 = CommonFunc.AddDict(HeroUIManager.Instance.GetHeroLVPayBack(hero.Quality, hero.heroLevel), | 
|         HeroUIManager.Instance.GetHeroBreakPayBack(hero.heroId, hero.breakLevel)); | 
|   | 
|         //已觉醒的需要消耗货币 | 
|         if (hero.awakeLevel == 0) | 
|         { | 
|             items = CommonFunc.ChangeToItemList(payBack1); | 
|             ConfirmCancel.ShowItemsConfirm(items, Language.Get("herocard42"), Language.Get("herocard43"), (bool isOk) => | 
|             { | 
|                 if (isOk) | 
|                 { | 
|                     //发包 | 
|                     SendReborn(hero.itemHero.gridIndex); | 
|                 } | 
|             }); | 
|         } | 
|         else | 
|         { | 
|             payBack1 = CommonFunc.AddDict(payBack1, HeroUIManager.Instance.GetHeroQualityAwakePayBack(hero.heroId, hero.awakeLevel)); | 
|             items = CommonFunc.ChangeToItemList(payBack1); | 
|             var info2 = Language.Get("herocard44", HeroUIManager.Instance.awakeRebirthCnt); | 
|             ConfirmCancel.ShowItemsConfirm(items, Language.Get("herocard42"), Language.Get("herocard43"), (bool isOk) => | 
|             { | 
|                 if (isOk) | 
|                 { | 
|                     //发包 | 
|                     SendReborn(hero.itemHero.gridIndex); | 
|                 } | 
|             }, info2, "", HeroUIManager.Instance.payBackMoney, HeroUIManager.Instance.payBackMoneyType); | 
|   | 
|         } | 
|   | 
|     } | 
|   | 
|     void SendReborn(int index) | 
|     { | 
|         var pack = new CB239_tagCSHeroRebirth(); | 
|         pack.ItemIndex = (ushort)index; | 
|         GameNetSystem.Instance.SendInfo(pack); | 
|     } | 
|   | 
|     void DeleteHero() | 
|     { | 
|         if (hero.isLock) | 
|         { | 
|             SysNotifyMgr.Instance.ShowTip("UnlockHero"); | 
|             return; | 
|         } | 
|     } | 
|   | 
|     void RefreshStars() | 
|     { | 
|         for (int i = 0; i < starImgList.Count; i++) | 
|         { | 
|             if (hero.heroStar == 0 && i == 0) | 
|             { | 
|                 // 无星级 特殊处理 | 
|                 starImgList[i].SetActive(true); | 
|                 starImgList[i].SetSprite("herostar" + hero.heroStar); | 
|             } | 
|             else if ((hero.heroStar - 1) % starImgList.Count >= i) | 
|             { | 
|                 starImgList[i].SetActive(true); | 
|                 starImgList[i].SetSprite("herostar" + (((hero.heroStar - 1) / starImgList.Count) + 1) * starImgList.Count); | 
|             } | 
|             else | 
|             { | 
|                 starImgList[i].SetActive(false); | 
|             } | 
|         } | 
|     } | 
|   | 
|     void RefreshName() | 
|     { | 
|         RefreshStars(); | 
|         nameText.text = hero.breakLevel == 0 ? hero.heroConfig.Name : Language.Get("herocardbreaklv", hero.heroConfig.Name, hero.breakLevel); | 
|         nameText.color = UIHelper.GetUIColorByFunc(hero.Quality); | 
|   | 
|         if (hero.Quality >= 4) | 
|         { | 
|             nameEffect.SetActive(true); | 
|             nameEffect.Play(hero.Quality == 4 ? 0 : 1); | 
|         } | 
|         else | 
|         { | 
|             nameEffect.SetActive(false); | 
|         } | 
|         countryImg.SetSprite(HeroUIManager.Instance.GetCountryIconName(hero.heroConfig.Country)); | 
|         if (hero.awakeLevel == 0) | 
|         { | 
|             awakeLVText.text = Language.Get("L1094") + hero.heroLevel; | 
|             awakeLVText.GetComponent<OutlineEx>().colorType = QualityTextColType.itemcucao; | 
|         } | 
|         else | 
|         { | 
|             awakeLVText.text = Language.Get("L1094") + hero.heroLevel + " " + Language.Get("herocard12", hero.awakeLevel); | 
|             awakeLVText.GetComponent<OutlineEx>().colorType = QualityTextColType.red; | 
|         } | 
|     } | 
|   | 
|     void RefreshFoldState() | 
|     { | 
|         if (!unfoldState) | 
|         { | 
|             foldImg.SetActive(true); | 
|             unfoldImg.SetActive(false); | 
|             attrPanel.localPosition = foldPos.localPosition; | 
|             attrScroll.sizeDelta = new Vector2(attrScroll.rect.width, 445); | 
|         } | 
|         else | 
|         { | 
|             foldImg.SetActive(false); | 
|             unfoldImg.SetActive(true); | 
|             attrPanel.localPosition = unfoldPos.localPosition; | 
|             attrScroll.sizeDelta = new Vector2(attrScroll.rect.width, 933); | 
|         } | 
|     } | 
|   | 
|     void RefreshAttr() | 
|     { | 
|         inheritAttrText[0].text = PlayerPropertyConfig.GetFullDescription(new Int2(PlayerPropertyConfig.inheritAttrs[0], hero.heroConfig.AtkInheritPer)); | 
|         inheritAttrText[1].text = PlayerPropertyConfig.GetFullDescription(new Int2(PlayerPropertyConfig.inheritAttrs[1], hero.heroConfig.DefInheritPer)); | 
|         inheritAttrText[2].text = PlayerPropertyConfig.GetFullDescription(new Int2(PlayerPropertyConfig.inheritAttrs[2], hero.heroConfig.HPInheritPer)); | 
|   | 
|         //上阵属性 | 
|         int valuePer = hero.GetOnBattleAddPer(); | 
|         for (int i = 0; i < heroAddAttrPerText.Length; i++) | 
|         { | 
|             heroAddAttrPerText[i].text = PlayerPropertyConfig.GetFullDescription(new Int2(PlayerPropertyConfig.basePerAttrs[i], valuePer)); | 
|         } | 
|   | 
|   | 
|   | 
|         //区分突破和最大等级 | 
|         if (!HeroUIManager.Instance.IsLVMax(hero)) | 
|         { | 
|             lvupBtnText.text = Language.Get("L1109"); | 
|             lvupBtn.interactable = true; | 
|             lvupBtn.SetColorful(null, true); | 
|             lvupMoneyIcon.SetActive(true); | 
|   | 
|             if (HeroUIManager.Instance.IsLVMaxByBreakLevel(hero)) | 
|             { | 
|                 lvupBtnText.text = Language.Get("L1111"); | 
|                 var breakConfig = HeroQualityBreakConfig.GetQualityBreakConfig(hero.Quality, hero.breakLevel); | 
|                 lvupMoneyIcon.SetOrgSprite(ItemConfig.Get(breakConfig.UPCostItem[0]).IconKey); | 
|                 lvupMoneyText.text = UIHelper.ShowUseItem(PackType.Item, breakConfig.UPCostItem[0], (ulong)breakConfig.UPCostItem[1]); | 
|             } | 
|             else | 
|             { | 
|                 lvupBtnText.text = Language.Get("L1109"); | 
|                 var lvupConfig = HeroQualityLVConfig.GetQualityLVConfig(hero.Quality, hero.heroLevel); | 
|                 lvupMoneyIcon.SetOrgSprite(ItemConfig.Get(lvupConfig.UPCostItem[0]).IconKey); | 
|                 lvupMoneyText.text = UIHelper.ShowUseItem(PackType.Item, lvupConfig.UPCostItem[0], (ulong)lvupConfig.UPCostItem[1]); | 
|             } | 
|   | 
|         } | 
|         else | 
|         { | 
|             lvupBtnText.text = Language.Get("L1110"); | 
|             lvupBtn.interactable = false; | 
|             lvupBtn.SetColorful(null, false); | 
|             lvupMoneyIcon.SetActive(false); | 
|   | 
|         } | 
|     } | 
|   | 
|     void LVUp() | 
|     { | 
|         int itemID = 0; | 
|         ulong needCount = 0; | 
|         if (HeroUIManager.Instance.IsLVMaxByBreakLevel(hero)) | 
|         { | 
|             //突破 | 
|             if (!UIManager.Instance.IsOpened<HeroLVBreakWin>()) | 
|             { | 
|                 HeroUIManager.Instance.selectHeroGuid = guid; | 
|                 UIManager.Instance.OpenWindow<HeroLVBreakWin>(); | 
|             } | 
|         } | 
|         else | 
|         { | 
|             //升级 | 
|             var lvupConfig = HeroQualityLVConfig.GetQualityLVConfig(hero.Quality, hero.heroLevel); | 
|             itemID = lvupConfig.UPCostItem[0]; | 
|             needCount = (ulong)lvupConfig.UPCostItem[1]; | 
|             if (ItemLogicUtility.CheckItemCount(PackType.Item, itemID, needCount, 2)) | 
|             { | 
|                 var pack = new CB230_tagCSHeroLVUP(); | 
|                 pack.ItemIndex = (ushort)hero.itemHero.gridIndex; | 
|                 GameNetSystem.Instance.SendInfo(pack); | 
|                 //预显示 | 
|                 lvupEffect.Play(); | 
|                 addPerObject.SetActive(true); | 
|                 for (int i = 0; i < addPerText.Length; i++) | 
|                 { | 
|                     addPerText[i].text = "+" + PlayerPropertyConfig.GetValueDescription(PlayerPropertyConfig.basePerAttrs[i], hero.qualityConfig.BreakLVAddPer); | 
|                 } | 
|                 addPerObject.Play(() => | 
|                 { | 
|                     addPerObject.SetActive(false); | 
|                 }); | 
|             } | 
|   | 
|         } | 
|   | 
|     } | 
|   | 
|     void RefreshAllPotential() | 
|     { | 
|         if (!HeroBreakConfig.configDics.ContainsKey(hero.heroId)) | 
|             return; | 
|   | 
|         var list = HeroBreakConfig.configDics[hero.heroId].Keys.ToList(); | 
|   | 
|         list.Sort(); | 
|   | 
|         string allAttrStr = string.Empty; | 
|         for (int i = 0; i < list.Count; i++) | 
|         { | 
|             var nextQualityBreakConfig = HeroBreakConfig.GetHeroBreakConfig(hero.heroId, i + 1); | 
|             if (nextQualityBreakConfig == null) | 
|                 break; | 
|             List<string> attrStrArr = new List<string>(); | 
|             for (int j = 0; j < nextQualityBreakConfig.AttrIDList.Length; j++) | 
|             { | 
|                 string format = i < hero.breakLevel ? "{0}" + UIHelper.AppendColor(TextColType.Green, "+{1}") : "{0}+{1}"; | 
|                 attrStrArr.Add(PlayerPropertyConfig.GetFullDescription(nextQualityBreakConfig.AttrIDList[j], nextQualityBreakConfig.AttrValueList[j], format)); | 
|             } | 
|             if (nextQualityBreakConfig.SkillID != 0) | 
|             { | 
|                 attrStrArr.Add(SkillConfig.Get(nextQualityBreakConfig.SkillID)?.Description); | 
|             } | 
|             if (i < hero.breakLevel) | 
|             { | 
|                 allAttrStr += Language.Get("herocard63", i + 1, string.Join(Language.Get("L1112"), attrStrArr)) + "\n"; | 
|             } | 
|             else | 
|             { | 
|                 //置灰 | 
|                 allAttrStr += UIHelper.AppendColor(TextColType.Gray, Language.Get("herocard63", i + 1, string.Join(Language.Get("L1112"), attrStrArr))) + "\n"; | 
|             } | 
|         } | 
|   | 
|         allPotentialText.text = allAttrStr.Trim(); | 
|      | 
|     } | 
| } |