| | |
| | | using System.Collections.Generic; |
| | | using LitJson; |
| | | using UnityEngine; |
| | | using UnityEngine.UI; |
| | | |
| | | public class ArenaBattleWin : UIBase |
| | | public class ArenaBattleWin : BaseBattleWin |
| | | { |
| | | // 组件引用 |
| | | [SerializeField] Transform mountPoint; |
| | | [SerializeField] Button btnSpeed; |
| | | [SerializeField] Text textSpeed; |
| | | [SerializeField] Button btnPass; |
| | | [SerializeField] Button btnPause; |
| | | [SerializeField] RendererAdjuster buttonsAdjuster; |
| | | private BattleRootNode battleRootNode = null; |
| | | public BattleField battleField; |
| | | |
| | | [SerializeField] Transform transButtons; |
| | | [SerializeField] HeroCountryComponent myCountry; |
| | | [SerializeField] TextEx txtMyLV; |
| | | [SerializeField] TextEx txtMyName; |
| | |
| | | [SerializeField] AvatarCell enemyAvatarCell; |
| | | [SerializeField] List<ArenaHeroHead> enemyHeroHeads; |
| | | |
| | | [SerializeField] TextEx txtWaveInfo; |
| | | // 生命周期 |
| | | protected override void InitComponent() |
| | | protected override void RegisterBattleEvents() |
| | | { |
| | | 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<BattleDmgInfo>(EventName.BATTLE_DAMAGE_TAKEN, OnDamageTaken); |
| | | base.RegisterBattleEvents(); |
| | | EventBroadcast.Instance.AddListener<string, JsonData>(EventName.BATTLE_END, OnBattleEnd); |
| | | //UIManager.Instance.CloseWindow<MainWin>(); |
| | | } |
| | | |
| | | protected override void OnPreClose() |
| | | protected override void UnregisterBattleEvents() |
| | | { |
| | | base.OnPreClose(); |
| | | UIManager.Instance.CloseWindow<BattleHUDWin>(); |
| | | BattleManager.Instance.onBattleFieldCreate -= OnCreateBattleField; |
| | | EventBroadcast.Instance.RemoveListener<BattleDmgInfo>(EventName.BATTLE_DAMAGE_TAKEN, OnDamageTaken); |
| | | base.UnregisterBattleEvents(); |
| | | EventBroadcast.Instance.RemoveListener<string, JsonData>(EventName.BATTLE_END, OnBattleEnd); |
| | | //UIManager.Instance.OpenWindow<MainWin>(0); |
| | | } |
| | | private void OnBattleEnd(string guid, JsonData endData) |
| | | |
| | | protected virtual void OnBattleEnd(string guid, JsonData endData) |
| | | { |
| | | if (battleField != null && guid == battleField.guid) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | private void OnDamageTaken(BattleDmgInfo damageInfo) |
| | | protected override void OnPreOpen() |
| | | { |
| | | base.OnPreOpen(); |
| | | MainWin.TabChangeEvent += OnTabChangeEvent; |
| | | bool isOpenBattleChangeTab = IsOpenBattleChangeTab(); |
| | | transButtons.localPosition = new Vector3(0, isOpenBattleChangeTab ? 130 : 0, 0); |
| | | if (isOpenBattleChangeTab) |
| | | { |
| | | UIManager.Instance.GetUI<MainWin>()?.CloseSubUI(); |
| | | } |
| | | else |
| | | { |
| | | UIManager.Instance.CloseWindow<MainWin>(); |
| | | } |
| | | } |
| | | |
| | | protected override void OnPreClose() |
| | | { |
| | | base.OnPreClose(); |
| | | MainWin.TabChangeEvent -= OnTabChangeEvent; |
| | | bool isOpenBattleChangeTab = IsOpenBattleChangeTab(); |
| | | if (isOpenBattleChangeTab) |
| | | { |
| | | UIManager.Instance.GetUI<MainWin>()?.RestoreSubUI(); |
| | | } |
| | | else |
| | | { |
| | | UIManager.Instance.OpenWindow<MainWin>(); |
| | | } |
| | | } |
| | | |
| | | private void OnTabChangeEvent() |
| | | { |
| | | UIManager.Instance.CloseWindow<ArenaBattleWin>(); |
| | | } |
| | | |
| | | protected override void OnDamageTaken(BattleDmgInfo damageInfo) |
| | | { |
| | | base.OnDamageTaken(damageInfo); |
| | | if (battleField == null) |
| | | return; |
| | | if (damageInfo.battleFieldGuid == battleField.guid) |
| | |
| | | } |
| | | } |
| | | |
| | | private void OnCreateBattleField(string arg1, BattleField field) |
| | | protected override void OnCreateBattleField(string guid, BattleField field) |
| | | { |
| | | if (field.GetType() == battleField.GetType()) |
| | | if (field is ArenaBattleField) |
| | | { |
| | | SetBattleField(field); |
| | | } |
| | | } |
| | | |
| | | protected override void OnOpen() |
| | | protected override void RefreshSpecific() |
| | | { |
| | | base.OnOpen(); |
| | | } |
| | | |
| | | 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(BattleField _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<BattleHUDWin>(); |
| | | |
| | | if (null == ui) |
| | | { |
| | | ui = UIManager.Instance.OpenWindow<BattleHUDWin>(); |
| | | } |
| | | ui.SetBattleField(battleField); |
| | | battleField.UpdateCanvas(canvas); |
| | | buttonsAdjuster.SetSortingOrder(BattleConst.ActiveHeroActionSortingOrder); |
| | | textSpeed.text = (BattleManager.Instance.speedIndex + 1).ToString(); |
| | | DisplayHpInfo(); |
| | | DisplayPlayerInfo(); |
| | | UpdateRoundDisplay(); |
| | | } |
| | | |
| | | private void DisplayHpInfo() |
| | | { |
| | | if (battleField == null) |
| | |
| | | return teamHeroes; |
| | | |
| | | } |
| | | public void UpdateRoundDisplay() |
| | | |
| | | bool IsOpenBattleChangeTab() |
| | | { |
| | | if (battleField == null) |
| | | return; |
| | | txtWaveInfo.text = Language.Get("BoneField09", battleField.round, battleField.turnMax); |
| | | Debug.LogFormat("当前波数:{0} 最大轮数:{1}", battleField.round, battleField.turnMax); |
| | | return FuncOpen.Instance.IsFuncOpen(ArenaManager.Instance.BattleChangeTabFuncId); |
| | | } |
| | | } |
| | | } |