// *********************************************************************** // Assembly : Game // Author : Kimch // Created : 2020-12-07 // Description : // Last Modified By : // Last Modified On : // *********************************************************************** // // // *********************************************************************** using TMPro; using UnityEngine; using UnityEngine.UI; namespace G.UI { partial class BoxShopPanel { /// /// 每日礼包 /// public class ExchangeWidget : KUIWidget { #region Field #pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null [KUIFlag] GameObject __goProp; [KUIFlag] Button _btnGet; [KUIFlag] GameObject __goPrice; [KUIFlag] GameObject __goFree; [KUIFlag] GameObject _goExchanged; #pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null private PropWidget _propWidget; private CostWidget _costWidget; private SmartCostWidget _smartCostWidget; #endregion #region Method public override void Refresh() { if (this.data is BoxShopProxy.ExchangeInfo exchangeInfo) { _goExchanged.SetActive(exchangeInfo.exchanged); _propWidget.SetItem(exchangeInfo.prop); if (exchangeInfo.price.id == Item.Id.kAds) { __goFree.SetActive(true); _smartCostWidget.SetAdTicket(MoneyProxy.Instance.GetMoney(Item.Id.kAdTicket)); __goPrice.SetActive(false); } else { __goFree.SetActive(false); __goPrice.SetActive(true); _costWidget.SetPrice(exchangeInfo.price); } } } private void OnGetBtnClick() { if (this.data is BoxShopProxy.ExchangeInfo exchangeInfo) { BoxShopProxy.Instance.Exchange(exchangeInfo.id, (error, message) => { if (error == 0) { Refresh(); } else if (error == ErrorCode.MONEY_NOT_ENOUGH) { int moneyId = exchangeInfo.price.id; if (moneyId == Item.Id.kGem && KPlatform.Instance.QueryPay()) KUIWindow.OpenWindow(); else AdMoneyBox.ShowAdMoney(moneyId, true); } else { ToastBox.ShowText(message); } }); } SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND); } #endregion #region Unity /// /// /// private void Awake() { SetViewData(); _propWidget = __goProp.AddComponent(); _costWidget = __goPrice.AddComponent(); _smartCostWidget = __goFree.AddComponent(); _btnGet.onClick.AddListener(this.OnGetBtnClick); } #endregion } } }