// *********************************************************************** // Assembly : Game // Author : Kimch // Created : 2020-11-03 // Description : // Last Modified By : // Last Modified On : // *********************************************************************** // // // *********************************************************************** using TMPro; using UnityEngine; using UnityEngine.UI; namespace G.UI { /// /// /// public class MovesWidget : KUIWidget { #region Field #pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null [KUIFlag] TextMeshProUGUI _tmpTitle; [KUIFlag] TextMeshProUGUI _tmpDescription; [KUIFlag] KUIImage _imgFrame; [KUIFlag] Image _imgIcon; [KUIFlag] Button _btnBuy; [KUIFlag] Transform _goLabels; [KUIFlag] GameObject _goRecommend; [KUIFlag] Toggle _tgSelect; #pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null #endregion #region Property #endregion #region Method public override void Refresh() { if (_tgSelect && _tgSelect.isOn) { _tgSelect.isOn = false; } if (this.data is ItemMoves movesItem) { _tmpTitle.text = movesItem.name; _tmpDescription.text = movesItem.description; _imgFrame.ShowSprite(movesItem.quality); IconProxy.Instance.SetSprite(_imgIcon, movesItem.icon); if (_goLabels) for (int i = _goLabels.childCount - 1; i >= 0; i--) { _goLabels.GetChild(i).gameObject.SetActive(movesItem.label == i); } if (_goRecommend) _goRecommend.SetActive(false); } } public void ShowRecomment() { if (_goRecommend) _goRecommend.SetActive(true); } private void OnBuyBtnClick() { GlobalNotifier.PostNotification(GlobalDefine.EVENT_SKILL_CARD_STATE_CHANGED, this.data, "study"); } bool _ignoreValueChanged; private void OnToggleValueChanged(bool value) { if (_ignoreValueChanged) return; if (this.data is ItemMoves movesItem) { var selectedMoves = MovesShopPanel.Instance.selectedMoves; if (value) { if (MovesShopPanel.Instance.selectedMoves.Count >= MovesShop.Instance.movesPoint) { ToastBox.ShowText("技能已学满"); _ignoreValueChanged = true; _tgSelect.isOn = false; _ignoreValueChanged = false; return; } if (movesItem.parent > 0 && !selectedMoves.Contains(movesItem.parent)) { ToastBox.ShowText("需要学习基本技能,才能学习进阶技能"); _ignoreValueChanged = true; _tgSelect.isOn = false; _ignoreValueChanged = false; return; } } else { if (movesItem.children.Count > 0 && selectedMoves.Overlaps(movesItem.children)) { ToastBox.ShowText("请先取消基本技能"); _ignoreValueChanged = true; _tgSelect.isOn = true; _ignoreValueChanged = false; return; } } } PostNotification(GlobalDefine.EVENT_SKILL_CARD_SELECTED, this.data, value.ToString()); } #endregion #region Unity /// /// /// private void Awake() { SetViewData(); if (_btnBuy) { _btnBuy.onClick.AddListener(this.OnBuyBtnClick); } if (_tgSelect) { _tgSelect.onValueChanged.AddListener(this.OnToggleValueChanged); } } #endregion } }