123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- using System;
- using UI.CommonGame;
- namespace GFGGame
- {
- public class BuyConfirmView : BaseWindow
- {
- private UI_BuyConfirmUI _ui;
- private int _itemId;
- private int _costId;
- private int _count;
- private int _costCount;
- private Action _onSuccess;
- private int _times = 0;
- private int _maxTimes = 0;
- private string _message = "";
- public override void Dispose()
- {
- base.Dispose();
- }
- protected override void OnInit()
- {
- base.OnInit();
- _ui = UI_BuyConfirmUI.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, int costId, int costCount, Action onSuccess, int times = 0, int maxTimes = 0, string message = "")
- {
- _itemId = itemId;
- _count = count;
- _costId = costId;
- _costCount = costCount;
- _times = times;
- _maxTimes = maxTimes;
- _onSuccess = onSuccess;
- _message = message;
- }
- protected override void OnShown()
- {
- base.OnShown();
- UpdateView();
- }
- private void UpdateView()
- {
- ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemId);
- ItemCfg costCfg = ItemCfgArray.Instance.GetCfg(_costId);
- _ui.m_txtNeed.text = string.Format("是否花费{0}{1} 购买{2}{3}", _costCount, costCfg.name, _count, itemCfg.name);
- _ui.m_txtNum.text = "";
- if (_message != "")
- {
- _ui.m_txtNum.text = _message;
- }
- else if (_maxTimes != 0)
- {
- _ui.m_txtNum.text = string.Format("今日剩余购买次数{0}/{1}", _times, _maxTimes);
- }
- }
- private void OnClickBtnSure()
- {
- if (_times <= 0 && _maxTimes != 0)
- {
- PromptController.Instance.ShowFloatTextPrompt("购买次数不足!");
- return;
- }
- if (ItemDataManager.GetItemNum(_costId) < _costCount)
- {
- ItemCfg costCfg = ItemCfgArray.Instance.GetCfg(_costId);
- if (_itemId == ConstItemID.GOLD)
- {
- PromptController.Instance.ShowFloatTextPrompt("鲛绡不足,请前往商城选购");
- }
- else
- {
- // PromptController.Instance.ShowFloatTextPrompt(costCfg.name + "不足!");
- Alert.Show(costCfg.name + "不足,是否前往购买?").SetLeftButton(true).SetRightButton(true, "确认", (AlertWindow.AlertCallback)((object data) =>
- {
- int costNeedCount = _costCount - ItemDataManager.GetItemNum(_costId);
- ItemExchangeCfg currencyRatioCfg = ItemUtil.GetCurrencyRatioCfgById(_costId);
- BuyItemConteoller.Show(_costId, (int)currencyRatioCfg.costId, (int)currencyRatioCfg.num, (int)currencyRatioCfg.costNum, costNeedCount, null, true, true, GameConst.MAX_COUNT_TO_BUY_DIAMOND_RED);
- }));
- OnClickBtnCancel();
- }
- return;
- }
- ItemExchangeCfg currencyRatioCfg = ItemUtil.GetCurrencyRatioCfgById(_itemId);
- // int count = (int)Math.Ceiling((decimal)_costCount / currencyRatioCfg.costNum * currencyRatioCfg.num);
- int count = ItemUtil.GetItemExChangeCount(_itemId, _costCount);
- ItemUtil.AddItemUseCost(_itemId, count, _costId, _costCount);
- if (_onSuccess != null)
- {
- _onSuccess();
- }
- PromptController.Instance.ShowFloatTextPrompt("购买成功!", MessageType.SUCCESS);
- this.Hide();
- }
- private void OnClickBtnCancel()
- {
- this.Hide();
- }
- }
- }
|