using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class StoryBossBattleWin : UIBase { // 组件引用 public Transform mountPoint; private BattleRootNode battleRootNode = null; private StoryBossBattleField battleField; [SerializeField] private Button btnSpeed; [SerializeField] private Text textSpeed; [SerializeField] private Button btnPass; [SerializeField] private Button btnPause; public RendererAdjuster buttonsAdjuster; public BossLifeBar bossLifeBar; public SkillWordCell[] skillWordCells; public BossHeadCell bossHeadCell; public Text txtBossName; public Text txtBattleRound; public TotalDamageDisplayer totalDamageDisplayer; private BattleObject bossBattleObject = null; [SerializeField] public List 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); BattleManager.Instance.onBattleFieldCreate += OnCreateBattleField; EventBroadcast.Instance.AddListener(EventName.BATTLE_DAMAGE_TAKEN, OnDamageTaken); UIManager.Instance.CloseWindow(); } protected override void OnPreClose() { base.OnPreClose(); BattleManager.Instance.onBattleFieldCreate -= OnCreateBattleField; EventBroadcast.Instance.RemoveListener(EventName.BATTLE_DAMAGE_TAKEN, OnDamageTaken); UIManager.Instance.CloseWindow(); if (!UIManager.Instance.IsOpened()) UIManager.Instance.OpenWindow(); } private void OnCreateBattleField(string arg1, BattleField field) { if (field.GetType() == battleField.GetType()) { SetBattleField(field as StoryBossBattleField); } } protected override void OnOpen() { base.OnOpen(); } public override void Refresh() { base.Refresh(); // bossLifeBar.SetBaseInfo(battleField); // skillWordCells; NPCLineupConfig lineupConfig = battleField.GetBossLineupConfig(); 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); } else { bossHeadCell.SetTeamHero(null); txtBossName.text = string.Empty; bossLifeBar.SetBaseInfo(2, 2, 2); Debug.LogError("找不到boss"); } txtBattleRound.text = string.Format("{0}/{1}", battleField.round, battleField.turnMax); } 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.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(StoryBossBattleField _battleField) { 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(); if (null == ui) { ui = UIManager.Instance.OpenWindow(); } ui.SetBattleField(battleField); battleField.UpdateCanvas(canvas); buttonsAdjuster.SetSortingOrder(BattleConst.ActiveHeroActionSortingOrder); Refresh(); 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(); }); } else { skillWordCells[i].SetActive(false); } } } public void RefreshBuff(List 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); } } } }