// *********************************************************************** // Assembly : Game // Author : Kimch // Created : 2020-09-17 // Description : // Last Modified By : // Last Modified On : // *********************************************************************** // // // *********************************************************************** using DG.Tweening; using PureMVC.Interfaces; using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; namespace G.UI { /// /// /// public class BattlePanel : KUIWidget { #region Field #pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null [KUIFlag] Button _btnMenu; [KUIFlag] GameObject _goHpHint; [KUIFlag] ComboText _comboText; [KUIFlag] GameObject _goStageInfo; [KUIFlag] TextMeshProUGUI _tmpStageName; [KUIFlag] TextMeshProUGUI _tmpStageValue; [KUIFlag] TextMeshProUGUI _tmpTimeFinish; [KUIFlag] TextMeshProUGUI _tmpWave; [KUIFlag] TextMeshProUGUI _tmpEnemyCount; [KUIFlag] TextMeshProUGUI _tmpModeTime; [KUIFlag] Slider _sldModeProgress; [KUIFlag] GameObject _goChaLevel; [KUIFlag] Slider _sliChaLevel; [KUIFlag] TextMeshProUGUI _tmpChaLevel; [KUIFlag] GameObject _goForceDown; [KUIFlag] TextMeshProUGUI _tmpFdValue; [KUIFlag] Button _btnFdTips; [KUIFlag] KUIList _buffList; [KUIFlag] GameObject _goBallisticTime;//怪物暴走 [KUIFlag] TextMeshProUGUI _tmpCountDown;//倒计时 [KUIFlag] GameObject _goAttributes;//属性显示 [KUIFlag] TextMeshProUGUI _tmpDetailName;//属性名字 [KUIFlag] TextMeshProUGUI _tmpDetailAttributes;//属性值 #pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null private float _levelCountdown; private float _showBuff; #endregion #region Method public override void Refresh() { _levelCountdown = 0f; ClearCombo(); SetBuff(); } private void OnShopBtnClick() { } private void OnMenuBtnClick() { SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND); UI_Ingame.Instance.PauseOn(); } public void ShowLvUp(int value) { StartCoroutine(LevelUp(value, 1)); } private IEnumerator LevelUp(int level, int up) { while (up > 0) { _sliChaLevel.value = 0f; _sliChaLevel.DOValue(1f, 1f); up--; _tmpChaLevel.text = $"LV.{level - up}"; UI_Ingame.Instance.GainExp(1); yield return new WaitForSeconds(1.1f); } _sliChaLevel.value = 0f; _tmpChaLevel.text = $"LV.{level}"; } void SetBuff() { _buffList.Clear(); foreach (var item in GameLevel.Instance.buffInfoDict) { var widget = _buffList.GetItem(); widget.SetType(item.Key); widget.SetNumber(item.Value.value); } } void ClearCombo() { _comboText.ShowNumber(""); } private void OnFdTipsBtnClick() { MessageBox.ShowMessage(KLocalization.GetLocalString(73), KLocalization.GetLocalString(74)); } public void OpenAttributesPanle(int id,int num) { _goAttributes.SetActive(true); if (id ==0) { _tmpDetailName.text = KLocalization.GetLocalString(94); _tmpDetailAttributes.text = string.Format(KLocalization.GetLocalString(95), num); } else if (id ==1) { _tmpDetailName.text = KLocalization.GetLocalString(96); _tmpDetailAttributes.text = string.Format(KLocalization.GetLocalString(97), num); } else { _tmpDetailName.text = KLocalization.GetLocalString(98); _tmpDetailAttributes.text = string.Format(KLocalization.GetLocalString(99), num); } _showBuff = 2; } public void CloseAttributesPanle() { _goAttributes.SetActive(false); } #endregion #region Unity /// /// /// private void Awake() { SetViewData(); _btnMenu.onClick.AddListener(this.OnMenuBtnClick); _btnFdTips.onClick.AddListener(this.OnFdTipsBtnClick); _buffList.AddTemplate(); } private float _lastUpdate; private void LateUpdate() { if (_levelCountdown > 0f) { _levelCountdown -= Time.deltaTime; _tmpTimeFinish.text = $"{(int)_levelCountdown} 秒"; if (_levelCountdown <= 0f) { _tmpTimeFinish.gameObject.SetActive(false); UI_Ingame.Instance.Settle("count_down"); } } if (_showBuff >0f) { _showBuff -= Time.deltaTime; if (_showBuff <=0f) { _goAttributes.SetActive(false); } } if (Time.time - _lastUpdate < 1.0f) return; _lastUpdate = Time.time; if (GameLevel.Instance.supportRampage && GameLevel.Instance.rampageTime > 0 && GameLevel.Instance.rampageTime < 10)//暴走计时提示 { _goBallisticTime.SetActive(true); _tmpCountDown.text = GameLevel.Instance.rampageTime.ToString(); } else { _goBallisticTime.SetActive(false); } if (GameLevel.Instance.isRampage && !_goHpHint.activeSelf) { _goHpHint.SetActive(true); _goHpHint.GetComponent().Play("hp_hint", -1, 0f); } if (GameLevel.Instance.stageMode == GameMode.Escort) { _sldModeProgress.gameObject.SetActive(true); _sldModeProgress.value = GameLevel.Instance.stageProgress; } else { _sldModeProgress.gameObject.SetActive(false); } if (GameLevel.Instance.stageMode == GameMode.Limit) { var stageTime = (int)GameLevel.Instance.stageTime; _tmpModeTime.transform.parent.gameObject.SetActive(true); _tmpModeTime.text = F.Utils.Text.Format("{0:00}:{1:00}", stageTime / 60, stageTime % 60);// $"{(stageTime / 60):D2}:{(stageTime % 60):D2}"; } else { _tmpModeTime.transform.parent.gameObject.SetActive(false); } //_tmpTimeStage.text = UI_Ingame.Instance.stage_num_text; } private void OnEnable() { RegisterThis(); Reset(); Refresh(); } private void OnDisable() { UnregisterThis(); } private void Reset() { _comboText.ShowNumber(""); _levelCountdown = 0f; _tmpTimeFinish.gameObject.SetActive(false); _goForceDown.SetActive(false); } #endregion #region Mediator readonly int[] _notificationInterests = new int[] { GlobalDefine.EVENT_STAGE_STATE, GlobalDefine.EVENT_PLAYER_EQUIPMENT_CHANGED, GlobalDefine.EVENT_LEVEL_STATE, GlobalDefine.EVENT_BATTLE_STAGE_HINT, GlobalDefine.EVENT_SHOW_TEXT_EFFECT, GlobalDefine.EVENT_SHOW_LVUP_EFFECT, GlobalDefine.EVENT_SHOW_BUFF, GlobalDefine.EVENT_OPEN_BUFF, GlobalDefine.EVENT_CLOSE_BUFF, }; public override IList ListNotificationInterests() { return _notificationInterests; } public override void HandleNotification(INotification notification) { if (notification.Name == GlobalDefine.EVENT_STAGE_STATE) { if (notification.Type == "enemy") { _tmpEnemyCount.text = notification.Body.ToString(); } else if (notification.Type == "start") { var world = GameLevel.Instance; _tmpStageName.text = world.curLevelItem.name; if (world.normalMode) { _goChaLevel.SetActive(true); _tmpStageValue.text = $"{world.curStageIndex}/{world.maxStageIndex}"; } else { _goChaLevel.SetActive(false); _tmpStageValue.text = $"{world.curStageIndex}"; } if (world.levelMode == 1 && world.difficultyValue > 1f) { _tmpFdValue.text = $"{(int)((world.difficultyValue - 1f) * 100)}%"; _goForceDown.SetActive(true); } else { _goForceDown.SetActive(false); } } else if (notification.Type == "finish") { } else if (notification.Type == "wave") { _tmpWave.text = notification.Body.ToString(); } } else if (notification.Name == GlobalDefine.EVENT_PLAYER_EQUIPMENT_CHANGED) { UI_Ingame.Instance.OnEquipmentChanged(); } else if (notification.Name == GlobalDefine.EVENT_LEVEL_STATE) { if (notification.Type == "finish") { _tmpTimeFinish.gameObject.SetActive(true); _levelCountdown = 5f; } } else if (notification.Name == GlobalDefine.EVENT_BATTLE_STAGE_HINT) { if (notification.Type == "combo") { _comboText.ShowNumber((string)notification.Body); } else if (notification.Type == "dying") { _goHpHint.SetActive(true); _goHpHint.GetComponent().Play("died_hint", -1, 0f); } else if (notification.Type == "danger") { _goHpHint.SetActive(true); _goHpHint.GetComponent().Play("hp_hint", -1, 0f); } else if (notification.Type == "heal") { _goHpHint.SetActive(false); } } else if (notification.Name == GlobalDefine.EVENT_SHOW_TEXT_EFFECT) { //_effectText.TxtEfOn((int)notification.Body); } else if (notification.Name == GlobalDefine.EVENT_SHOW_LVUP_EFFECT) { ShowLvUp((int)notification.Body); } else if (notification.Name == GlobalDefine.EVENT_SHOW_BUFF) { SetBuff(); } else if (notification.Name == GlobalDefine.EVENT_OPEN_BUFF) { OpenAttributesPanle(((int[])notification.Body)[0], ((int[])notification.Body)[1]); } else if (notification.Name == GlobalDefine.EVENT_CLOSE_BUFF) { CloseAttributesPanle(); } } #endregion } }