123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- using System;
- using System.Collections.Generic;
- using UI.CommonGame;
- namespace GFGGame
- {
- public class BuyTipsView : BaseWindow
- {
- private UI_BuyTipsUI _ui;
- private int _itemId;
- private int _costId;
- private int _count;
- private int _costCount;
- private Action _onSuccess;
- public override void Dispose()
- {
- base.Dispose();
- }
- protected override void OnInit()
- {
- base.OnInit();
- _ui = UI_BuyTipsUI.Create();
- this.viewCom = _ui.target;
- this.viewCom.Center();
- this.modal = true;
- viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
- _ui.m_btnSure.onClick.Add(OnClickBtnSure);
- _ui.m_btnCancel.onClick.Add(OnClickBtnCancel);
- }
- public void SetParams(int itemId, int count, Action onSuccess = null)
- {
- _itemId = itemId;
- _count = count;
- // _costId = costId;
- // _costCount = costCount;
- _onSuccess = onSuccess;
- }
- protected override void OnShown()
- {
- base.OnShown();
- UpdateView();
- }
- private void UpdateView()
- {
- ItemExchangeCfgArray.Instance.GetMoneyIdAndNum(_itemId, ItemDataManager.GetItemExchangeTimes(_itemId), _count, out _costId, out _costCount, out int buyNum);
- ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemId);
- _ui.m_txtNeed.text = string.Format("还需要购买{0}个", _count);
- _ui.m_loaNeed.url = ResPathUtil.GetCommonGameResPath(itemCfg.res);
- ItemCfg costCfg = ItemCfgArray.Instance.GetCfg(_costId);
- _ui.m_txtCost.text = string.Format("是否花费{0}{1}购买?", _costCount, costCfg.name);
- }
- private async void OnClickBtnSure()
- {
- bool result = await ItemExchangeSProxy.ItemExchange(_itemId, _count);
- if (result)
- {
- ItemData itemData = new ItemData();
- itemData.id = _itemId;
- itemData.num = _count;
- ViewManager.Show<RewardView>(itemData);
- if (_onSuccess != null)
- {
- _onSuccess();
- }
- }
- this.Hide();
- }
- private void OnClickBtnCancel()
- {
- this.Hide();
- }
- }
- }
|