// *********************************************************************** // Assembly : Game // Author : Kimch // Created : 2021-05-14 // Description : // Last Modified By : // Last Modified On : // *********************************************************************** // // // *********************************************************************** namespace G.UI { using UnityEngine; using UnityEngine.UI; using Text = TMPro.TextMeshProUGUI; /// /// /// partial class PropTipsBox { #region Field #pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null [KUIFlag] Button _btnClose; [KUIFlag] Button _btnBack; [KUIFlag] Text _tmpDescription; [KUIFlag] Text _tmpName; [KUIFlag] Text _tmpGrade; [KUIFlag] GameObject _goProp; [KUIFlag] Button _btnAccess; [KUIFlag] Text _tmpAccess; [KUIFlag] Button _btnSell; #pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null PropWidget _propWidget; #endregion #region Method /// /// /// public void InitView() { SetViewData(); _btnClose.onClick.AddListener(this.OnCloseBtnClick); _btnBack.onClick.AddListener(this.OnCloseBtnClick); _btnAccess.onClick.AddListener(this.OnAccessBtnClick); //_btnSell.onClick.AddListener(this.OnSellBtnClick); _propWidget = _goProp.AddComponent(); } /// /// /// public void RefreshView() { if (this.data is ItemProp propItem) { _tmpName.text = propItem.name; _tmpDescription.text = propItem.text; _tmpGrade.text = $"等级: {propItem.level.ToString()}"; _propWidget.SetItem(propItem.id); if (propItem.isProp) { if (GlobalVar.BagPageShow) { var propEntity = ItemProxy.Instance.GetProp(propItem.id); var sellPrice = propItem.sellPriceInfo; if (propEntity.count > 0 && sellPrice.id > 0 && sellPrice.count > 0) { _btnAccess.gameObject.SetActive(true); _tmpAccess.text = "出售"; } else { ShowAccess(null); } } else { ShowAccess(null); } } else if (propItem.isBeautyProp) { ShowAccess(ItemProxy.Instance.GetStaticItem(4)); } else if (propItem.isGem) { ShowAccess(ItemProxy.Instance.GetStaticItem(1)); } else if (propItem.id == Item.Id.kStone) { ShowAccess(ItemProxy.Instance.GetStaticItem(3)); } else { ShowAccess(null); } } } /// /// /// void ShowAccess(ItemAccess access) { if (access != null) { _btnAccess.gameObject.SetActive(true); _tmpAccess.text = access.name; } else { _btnAccess.gameObject.SetActive(false); } } private void OnAccessBtnClick() { if (this.data is ItemProp propItem) { if (propItem.isBeautyProp) { PostNotification(GlobalDefine.EVENT_MAIN_WINDOW_PAGE, null, "4"); } else if (propItem.isGem) { PostNotification(GlobalDefine.EVENT_MAIN_WINDOW_PAGE, null, "0"); } else if (propItem.id == Item.Id.kStone) { CloseWindow(); OpenWindow(); } else if (propItem.isProp && GlobalVar.BagPageShow) { var propEntity = ItemProxy.Instance.GetProp(propItem.id); if (propEntity.count <= 0) return; var sellPrice = propItem.sellPriceInfo; if (sellPrice.id > 0 && sellPrice.count > 0) { int moneyCount = sellPrice.count * propEntity.count; propEntity.count = 0; MoneyProxy.Instance.AddMoney(sellPrice.id, moneyCount); PostNotification(GlobalDefine.EVENT_MONEY_CHANGED, sellPrice.id, "prop_sell"); PostNotification(GlobalDefine.EVENT_PROP_CHANGED, propItem, "prop_sell"); var sellPropItem = sellPrice.propItem; if (sellPropItem != null) ToastBox.ShowText($"获得{sellPropItem.name} x{moneyCount}"); } } } OnCloseBtnClick(); } private void OnSellBtnClick() { if (this.data is ItemProp propItem) { if (propItem.isProp && GlobalVar.BagPageShow) { var sellPrice = propItem.sellPriceInfo; if (sellPrice.id > 0 && sellPrice.count > 0) { var propEntity = ItemProxy.Instance.GetProp(propItem.id); MoneyProxy.Instance.AddMoney(sellPrice.id, sellPrice.count * propEntity.count); propEntity.count = 0; } } } } private void OnCloseBtnClick() { CloseWindow(this); SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND); } #endregion } }