| using System.Collections.Generic; | 
| using UnityEngine; | 
| using UnityEngine.UI; | 
|   | 
| public class BoneFieldBattleWin : UIBase | 
| { | 
|     [SerializeField] Transform transButtons; | 
|     public Transform mountPoint; | 
|     private BattleRootNode battleRootNode = null; | 
|     private BoneBattleField battleField; | 
|     [SerializeField] private Button btnSpeed; | 
|   | 
|     [SerializeField] private Text textSpeed; | 
|   | 
|     [SerializeField] private Button btnPass; | 
|   | 
|     [SerializeField] private Button btnPause; | 
|   | 
|     public BossLifeBar bossLifeBar; | 
|     public SkillWordCell[] skillWordCells; | 
|     public BossHeadCell bossHeadCell; | 
|     public Text txtBossName; | 
|     public Text txtBattleRound; | 
|     public TotalDamageDisplayer totalDamageDisplayer; | 
|     // public SkillTips skillTipsRed; | 
|     // public SkillTips skillTipsBlue; | 
|     private BattleObject bossBattleObject = null; | 
|     // [SerializeField] public List<BattleBuffCell> buffCells; | 
|   | 
|     // 生命周期 | 
|     protected override void InitComponent() | 
|     { | 
|         base.InitComponent(); | 
|         // 初始化组件引用 绑定按钮等UI组件事件 | 
|         btnSpeed.AddListener(ChangeSpeed); | 
|         btnPass.AddListener(OnClickPass); | 
|         btnPause.AddListener(OnClickPause); | 
|     } | 
|   | 
|     private void OnClickPause() | 
|     { | 
|         if (null == battleField) | 
|             return; | 
|         battleField.IsPause = !battleField.IsPause; | 
|     } | 
|   | 
|     private void OnClickPass() | 
|     { | 
|         if (null == battleField) | 
|             return; | 
|         battleField.ForceFinish(); | 
|     } | 
|   | 
|     private void ChangeSpeed() | 
|     { | 
|         if (null == battleField) | 
|             return; | 
|         BattleManager.Instance.speedIndex = (BattleManager.Instance.speedIndex + 1) % BattleManager.Instance.speedGear.Length; | 
|         battleField.SetSpeedRatio(BattleManager.Instance.speedGear[BattleManager.Instance.speedIndex]); | 
|         textSpeed.text = (BattleManager.Instance.speedIndex + 1).ToString(); | 
|     } | 
|   | 
|     protected override void OnPreOpen() | 
|     { | 
|         base.OnPreOpen(); | 
|         // SetBattleField(BattleManager.Instance.storyBattleField); | 
|         MainWin.TabChangeEvent += OnTabChangeEvent; | 
|         BattleManager.Instance.onBattleFieldCreate += OnCreateBattleField; | 
|         EventBroadcast.Instance.AddListener<BattleDmgInfo>(EventName.BATTLE_DAMAGE_TAKEN, OnDamageTaken); | 
|         EventBroadcast.Instance.AddListener<string, SkillConfig, TeamHero>(EventName.BATTLE_CAST_SKILL, OnCastSkill); | 
|         BattleManager.Instance.storyBattleField.IsPause = true; | 
|         bool isOpenBattleChangeTab = IsOpenBattleChangeTab(); | 
|         transButtons.localPosition = new Vector3(0, isOpenBattleChangeTab ? 200 : 0, 0); | 
|         if (isOpenBattleChangeTab) | 
|         { | 
|             UIManager.Instance.GetUI<MainWin>()?.CloseSubUI(); | 
|         } | 
|         else | 
|         { | 
|             UIManager.Instance.CloseWindow<MainWin>(); | 
|         } | 
|     } | 
|   | 
|   | 
|   | 
|     protected override void OnPreClose() | 
|     { | 
|         base.OnPreClose(); | 
|         MainWin.TabChangeEvent -= OnTabChangeEvent; | 
|         BattleManager.Instance.onBattleFieldCreate -= OnCreateBattleField; | 
|         EventBroadcast.Instance.RemoveListener<BattleDmgInfo>(EventName.BATTLE_DAMAGE_TAKEN, OnDamageTaken); | 
|         EventBroadcast.Instance.RemoveListener<string, SkillConfig, TeamHero>(EventName.BATTLE_CAST_SKILL, OnCastSkill); | 
|         UIManager.Instance.CloseWindow<BattleHUDWin>(); | 
|   | 
|         bool isOpenBattleChangeTab = IsOpenBattleChangeTab(); | 
|         if (isOpenBattleChangeTab) | 
|         { | 
|             UIManager.Instance.GetUI<MainWin>()?.RestoreSubUI(); | 
|         } | 
|         else | 
|         { | 
|             UIManager.Instance.OpenWindow<MainWin>(); | 
|         } | 
|   | 
|         if (bossBattleObject != null) | 
|         { | 
|             if (bossBattleObject.buffMgr != null) | 
|             { | 
|                 bossBattleObject.buffMgr.onBuffChanged -= OnBuffChanged; | 
|             } | 
|             bossBattleObject = null; | 
|         } | 
|   | 
|         if (battleField != null) | 
|         { | 
|             battleField.OnRoundChange -= OnRoundChange; | 
|             battleField = null; | 
|         } | 
|     } | 
|   | 
|     private void OnTabChangeEvent() | 
|     { | 
|         UIManager.Instance.CloseWindow<BoneFieldBattleWin>(); | 
|     } | 
|      | 
|     private void OnCastSkill(string guid, SkillConfig skillConfig, TeamHero teamHero) | 
|     { | 
|         if (battleField == null) | 
|             return; | 
|   | 
|         if (battleField.guid != guid) | 
|             return; | 
|   | 
|         BattleObject battleObject = battleField.battleObjMgr.GetBattleObject(teamHero.ObjID); | 
|         bool isRed = battleObject.Camp == BattleCamp.Red; | 
|         // SkillTips tips = isRed ? skillTipsRed : skillTipsBlue; | 
|         // tips.PlayMotion(battleField, isRed, teamHero, skillConfig); | 
|     } | 
|   | 
|     private void OnCreateBattleField(string arg1, BattleField field) | 
|     { | 
|         if (field.GetType() == battleField.GetType()) | 
|         { | 
|             SetBattleField(field as BoneBattleField); | 
|         } | 
|     } | 
|   | 
|   | 
|     public void Display() | 
|     { | 
|   | 
|         NPCLineupConfig lineupConfig = battleField.GetBossLineupConfig(); | 
|   | 
|         if (bossBattleObject != null) | 
|         { | 
|             if (bossBattleObject.buffMgr != null) | 
|             { | 
|                 bossBattleObject.buffMgr.onBuffChanged -= OnBuffChanged; | 
|             } | 
|             bossBattleObject = null; | 
|         } | 
|   | 
|         bossBattleObject = battleField.FindBoss(); | 
|   | 
|         DisplaySkillWordsList(lineupConfig); | 
|   | 
|         if (null != bossBattleObject) | 
|         { | 
|             TeamHero teamHero = bossBattleObject.teamHero; | 
|             bossHeadCell.SetTeamHero(teamHero); | 
|             txtBossName.text = teamHero.name; | 
|             NPCConfig npcConfig = NPCConfig.Get(teamHero.NPCID); | 
|             bossLifeBar.SetBaseInfo(Mathf.Max(1, npcConfig.LifeBarCount), (ulong)teamHero.curHp, (ulong)teamHero.maxHp); | 
|             bossBattleObject.buffMgr.onBuffChanged -= OnBuffChanged; | 
|             bossBattleObject.buffMgr.onBuffChanged += OnBuffChanged; | 
|         } | 
|         else | 
|         { | 
|             bossHeadCell.SetTeamHero(null); | 
|             txtBossName.text = string.Empty; | 
|             bossLifeBar.SetBaseInfo(2, 2, 2); | 
|             Debug.LogError("找不到boss"); | 
|         } | 
|   | 
|         OnRoundChange(battleField.round, battleField.turnMax); | 
|   | 
|         OnBuffChanged(); | 
|   | 
|         totalDamageDisplayer.SetActive(false); | 
|   | 
|         // skillTipsBlue.SetActive(false); | 
|         // skillTipsRed.SetActive(false); | 
|     } | 
|   | 
|     private void OnBuffChanged() | 
|     { | 
|         var buffList = new List<HB428_tagSCBuffRefresh>(); | 
|         if (null != bossBattleObject) | 
|         { | 
|             buffList = bossBattleObject.buffMgr.GetBuffList(); | 
|         } | 
|         // RefreshBuff(buffList); | 
|     } | 
|   | 
|     private void RefreshHP() | 
|     { | 
|         if (null != bossBattleObject) | 
|         { | 
|             TeamHero teamHero = bossBattleObject.teamHero; | 
|             bossLifeBar.Show((ulong)teamHero.curHp, (ulong)teamHero.maxHp); | 
|         } | 
|     } | 
|   | 
|   | 
|     private void OnDamageTaken(BattleDmgInfo info) | 
|     { | 
|         if (info.battleFieldGuid != battleField.guid) | 
|             return; | 
|   | 
|         if (info.hurtObj.ObjID == bossBattleObject.ObjID) | 
|         { | 
|             // Update the boss's health bar | 
|             RefreshHP(); | 
|         } | 
|   | 
|         totalDamageDisplayer.SetDamage(info); | 
|     } | 
|   | 
|     protected override void OnClose() | 
|     { | 
|         base.OnClose(); | 
|   | 
|         if (battleRootNode != null) | 
|         { | 
|             battleRootNode.transform.SetParent(Launch.Instance.transform); | 
|             battleRootNode.transform.localPosition = new Vector3(-10000, -10000, 0); | 
|         } | 
|   | 
|         battleField = null; | 
|     } | 
|   | 
|     protected override void NextFrameAfterOpen() | 
|     { | 
|         base.NextFrameAfterOpen(); | 
|     } | 
|   | 
|     protected override void CompleteClose() | 
|     { | 
|         base.CompleteClose(); | 
|     } | 
|   | 
|     public void SetBattleField(BoneBattleField _battleField) | 
|     { | 
|         if (battleField != null) | 
|         { | 
|             battleField.OnRoundChange -= OnRoundChange; | 
|             battleField = null; | 
|         } | 
|   | 
|         battleField = _battleField; | 
|         if (battleRootNode != null) | 
|         { | 
|             battleRootNode.transform.localPosition = Vector3.zero; | 
|             battleRootNode.transform.SetParent(Launch.Instance.transform); | 
|         } | 
|   | 
|         battleRootNode = battleField.battleRootNode; | 
|   | 
|         battleRootNode.transform.SetParent(mountPoint); | 
|         battleRootNode.transform.localPosition = Vector3.zero; | 
|         battleRootNode.transform.localScale = Vector3.one; | 
|   | 
|         BattleHUDWin ui = UIManager.Instance.GetUI<BattleHUDWin>(); | 
|   | 
|         if (null == ui) | 
|         { | 
|             ui = UIManager.Instance.OpenWindow<BattleHUDWin>(); | 
|         } | 
|   | 
|         ui.SetBattleField(battleField); | 
|         battleField.UpdateCanvas(canvas); | 
|         Display(); | 
|         battleField.OnRoundChange += OnRoundChange; | 
|         textSpeed.text = (BattleManager.Instance.speedIndex + 1).ToString(); | 
|     } | 
|   | 
|     public void DisplaySkillWordsList(NPCLineupConfig lineUPConfig) | 
|     { | 
|         if (skillWordCells.IsNullOrEmpty()) | 
|             return; | 
|   | 
|         if (null == lineUPConfig) | 
|             return; | 
|   | 
|         for (int i = 0; i < skillWordCells.Length; i++) | 
|         { | 
|             if (i < lineUPConfig.SkillIDExList.Length) | 
|             { | 
|                 skillWordCells[i].SetActive(true); | 
|                 int skillID = lineUPConfig.SkillIDExList[i]; | 
|                 skillWordCells[i].Init(skillID, () => | 
|                 { | 
|                     SmallTipWin.showText = Language.Get("SmallTipFomat", SkillConfig.Get(skillID)?.SkillName, SkillConfig.Get(skillID)?.Description); | 
|                     SmallTipWin.worldPos = CameraManager.uiCamera.ScreenToWorldPoint(Input.mousePosition); | 
|                     SmallTipWin.isDownShow = true; | 
|                     UIManager.Instance.OpenWindow<SmallTipWin>(); | 
|                 }); | 
|             } | 
|             else | 
|             { | 
|                 skillWordCells[i].SetActive(false); | 
|             } | 
|         } | 
|     } | 
|   | 
|     // public void RefreshBuff(List<HB428_tagSCBuffRefresh> datas) | 
|     // { | 
|     //     if (buffCells.IsNullOrEmpty()) | 
|     //         return; | 
|   | 
|   | 
|     //     for (int i = 0; i < buffCells.Count; i++) | 
|     //     { | 
|     //         if (i < datas.Count) | 
|     //         { | 
|     //             buffCells[i].SetActive(true); | 
|     //             HB428_tagSCBuffRefresh buffData = datas[i]; | 
|     //             buffCells[i].Init(buffData, () => | 
|     //             { | 
|     //                 //  点击buff图标 显示buff描述/当前身上所有buff | 
|     //             }); | 
|     //         } | 
|     //         else | 
|     //         { | 
|     //             buffCells[i].SetActive(false); | 
|     //         } | 
|     //     } | 
|     // } | 
|   | 
|     private void OnRoundChange(int round, int maxRound) | 
|     { | 
|         txtBattleRound.text = string.Format("{0}/{1}", round, maxRound); | 
|     } | 
|     bool IsOpenBattleChangeTab() | 
|     { | 
|         return FuncOpen.Instance.IsFuncOpen(ArenaManager.Instance.BattleChangeTabFuncId); | 
|     } | 
| } |