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 long _count; private int _costCount; private bool _result = false; private Action _onSuccess; private bool _showCheck = false; public override void Dispose() { if (_ui != null) { _ui.Dispose(); _ui = null; } BuyTipsController.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.target.onClick.Add(OnClickBtnSure); _ui.m_btnCancel.target.onClick.Add(OnClickBtnCancel); _ui.m_btnCancel.target.onClick.Add(OnClickBtnCancel); _ui.m_btnCheck.onClick.Add(OnBtnCheckClick); } public void SetParams(int itemId, long count, Action onSuccess = null, bool showCheck = false) { _itemId = itemId; _count = count; _onSuccess = onSuccess; _showCheck = showCheck; } protected override void OnShown() { base.OnShown(); UpdateView(); } private void UpdateView() { ItemExchangeCfgArray.Instance.GetMoneyIdAndNum(_itemId, ItemDataManager.GetItemExchangeTimes(_itemId), (int)_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); if (_showCheck) _ui.m_checkType.selectedIndex = 1; else _ui.m_checkType.selectedIndex = 0; } private async void OnClickBtnSure() { _result = await ItemExchangeSProxy.ItemExchange(_itemId, _count); if (_result) { BonusController.TryShowBonusList(ItemUtil.CreateItemDataList(_itemId, _count), _onSuccess); } this.Hide(); } private void OnClickBtnCancel() { this.Hide(); } private void OnBtnCheckClick() { LuckyBoxDataManager.Instance.CHECK_TIPS_OPEN = _ui.m_btnCheck.selected; } } }