// *********************************************************************** // Assembly : Game // Author : Kimch // Created : 2020-09-07 // Description : // Last Modified By : // Last Modified On : // *********************************************************************** // // // *********************************************************************** using PureMVC.Interfaces; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; namespace G.UI { partial class ChaPanel : KUIWidget { #region Field #pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null [KUIFlag] ToggleGroup __goPageType; [KUIFlag] Button _btnClose; [KUIFlag] GameObject __goEquipmentSlotPage; [KUIFlag] GameObject __goBagPage; [KUIFlag] GameObject __goUpgradePage; [KUIFlag] GameObject __goCompose; [KUIFlag] TextMeshProUGUI _tmpCombatValue; [KUIFlag] Button _btnDetails; [KUIFlag] GameObject _goChaRoot; [KUIFlag] KUIToggleGroup _goPages; [KUIFlag] Button _btnSkin; #pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null /// /// /// ChaWidget _chaWidget; /// /// /// private EquipmentSlotPage __equipmentSlotPage; /// /// /// private BagPage __bagPage; #endregion #region Method public override void Refresh() { RefreshEquipment(); RefreshBag(); PostNotification(GlobalDefine.EVENT_WINDOW_OPENED, 3, ""); } /// /// /// void RefreshEquipment(bool set = true) { SetCombatValue(); var slots = PlayerProxy.Instance.GetEquipmentSlots(); for (int i = 0; i < slots.Length; i++) { __equipmentSlotPage.SetEquipmentSlot(slots[i]); } if (set) { var weapon = slots[0].equipment; if (weapon != null) { SetEquipment(weapon); } } } /// /// /// void RefreshBag() { if (!_goPages.toggles[0].isOn) { _goPages.toggles[0].isOn = true; _goPages.toggles[1].isOn = false; } } void SetEquipment(EntityItemEquipment equipment) { if (equipment.isWeapon) { int kind = equipment.weaponKind; var skin = ChaSkinProxy.Instance.GetCurrentSkin(0).item; _chaWidget.Show(skin.GetUIAssetByWeapon(kind), $"{equipment.assets}_ui", null); } } void SetCombatValue() { _tmpCombatValue.text = PlayerProxy.Instance.combatValue.ToString(); } public void OnCloseBtnClick() { //this.transform.parent.gameObject.SetActive(false); } void OnSkinBtnClick() { KUIWindow.OpenWindow(); SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND); } public void OnDetailBtnClick() { KUIWindow.OpenWindow(); SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND); } private void OnPageSelect(int index) { __bagPage.ShowPage(index); SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND); } #endregion // Start is called before the first frame update private void Awake() { SetViewData(); __equipmentSlotPage = __goEquipmentSlotPage.GetComponent(); __bagPage = __goBagPage.AddComponent(); _goPages.onToggleSelected.AddListener(this.OnPageSelect); // _btnDetails.onClick.AddListener(this.OnDetailBtnClick); //if (_btnClose) //{ // _btnClose.onClick.AddListener(this.OnCloseBtnClick); //} _btnSkin.gameObject.SetActive(true); _btnSkin.onClick.AddListener(this.OnSkinBtnClick); _chaWidget = _goChaRoot.AddComponent(); } private void OnEnable() { if (!_start) return; this.RegisterThis(); this.Refresh(); } private void OnDisable() { this.UnregisterThis(); } private bool _start; private System.Collections.IEnumerator Start() { if (!_start) { _start = true; OnEnable(); } yield return null; } private readonly int[] _notificationInterests = new int[] { GlobalDefine.EVENT_PLAYER_EQUIPMENT_CHANGED, GlobalDefine.EVENT_EQUIPMENT_SUIT, }; public override IList ListNotificationInterests() { return _notificationInterests; } public override void HandleNotification(INotification notification) { if (notification.Name == GlobalDefine.EVENT_PLAYER_EQUIPMENT_CHANGED) { if (notification.Type == "set" || notification.Type == "sets") { RefreshEquipment(true); SoundProxy.PlayFxAsync("Sounds/main_equipment_btn.mp3"); } else if (notification.Type == "upgrade") { RefreshEquipment(false); SoundProxy.PlayFxAsync("Sounds/voice_eq_up.mp3"); } } else if (notification.Name == GlobalDefine.EVENT_EQUIPMENT_SUIT) { RefreshEquipment(false); SoundProxy.PlayFxAsync("Sounds/voice_eq_up.mp3"); } } } }