BuyConfirmView.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using System;
  2. using UI.CommonGame;
  3. namespace GFGGame
  4. {
  5. public class BuyConfirmView : BaseWindow
  6. {
  7. private UI_BuyConfirmUI _ui;
  8. private int _itemId;
  9. private int _count;//本次购买次数
  10. private int _buyTimes;//已购次数
  11. private Action _onSuccess;
  12. private int _times = 0;
  13. private int _maxTimes = 0;
  14. private string _message = "";
  15. public override void Dispose()
  16. {
  17. base.Dispose();
  18. }
  19. protected override void OnInit()
  20. {
  21. base.OnInit();
  22. _ui = UI_BuyConfirmUI.Create();
  23. this.viewCom = _ui.target;
  24. this.viewCom.Center();
  25. this.modal = true;
  26. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  27. _ui.m_btnSure.onClick.Add(OnClickBtnSure);
  28. _ui.m_btnCancel.onClick.Add(OnClickBtnCancel);
  29. }
  30. public void SetParams(int itemId, int count, int buyTimes, Action onSuccess, int times = 0, int maxTimes = 0, string message = "")
  31. {
  32. _itemId = itemId;
  33. _count = count;
  34. _buyTimes = buyTimes;
  35. _times = times;
  36. _maxTimes = maxTimes;
  37. _onSuccess = onSuccess;
  38. _message = message;
  39. }
  40. protected override void OnShown()
  41. {
  42. base.OnShown();
  43. UpdateView();
  44. }
  45. private void UpdateView()
  46. {
  47. ItemExchangeCfgArray.Instance.GetMoneyIdAndNum(_itemId, _buyTimes, _buyTimes + _count, out int costId, out int coustNum, out int buyNum);
  48. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemId);
  49. ItemCfg costCfg = ItemCfgArray.Instance.GetCfg(costId);
  50. _ui.m_txtNeed.text = string.Format("是否花费{0}{1} 购买{2}{3}", coustNum, costCfg.name, buyNum, itemCfg.name);
  51. _ui.m_txtNum.text = "";
  52. if (_message != "")
  53. {
  54. _ui.m_txtNum.text = _message;
  55. }
  56. else if (_maxTimes != 0)
  57. {
  58. _ui.m_txtNum.text = string.Format("今日剩余购买次数{0}/{1}", _buyTimes, _maxTimes);
  59. }
  60. }
  61. private async void OnClickBtnSure()
  62. {
  63. if ((_buyTimes + _count) <= 0 && _maxTimes != 0)
  64. {
  65. PromptController.Instance.ShowFloatTextPrompt("购买次数不足!");
  66. return;
  67. }
  68. ItemExchangeCfgArray.Instance.GetMoneyIdAndNum(_itemId, _buyTimes, _buyTimes + _count, out int costId, out int coustNum, out int buyNum);
  69. if (ItemDataManager.GetItemNum(costId) < coustNum)
  70. {
  71. ItemCfg costCfg = ItemCfgArray.Instance.GetCfg(costId);
  72. if (_itemId == ConstItemID.GOLD)
  73. {
  74. PromptController.Instance.ShowFloatTextPrompt("鲛绡不足,请前往商城选购");
  75. }
  76. else
  77. {
  78. // PromptController.Instance.ShowFloatTextPrompt(costCfg.name + "不足!");
  79. Alert.Show(costCfg.name + "不足,是否前往购买?").SetLeftButton(true).SetRightButton(true, "确认", (AlertWindow.AlertCallback)((object data) =>
  80. {
  81. int costNeedCount = coustNum - ItemDataManager.GetItemNum(costId);
  82. ItemExchangeCfg currencyRatioCfg = ItemUtil.GetCurrencyRatioCfgById(costId);
  83. BuyItemConteoller.Show(costId, (int)currencyRatioCfg.costId, (int)currencyRatioCfg.num, (int)currencyRatioCfg.costNum, costNeedCount, ConstBuyType.TYPE_ITEM, 0, null, true, true, GameConst.MAX_COUNT_TO_BUY_DIAMOND_RED);
  84. }));
  85. OnClickBtnCancel();
  86. }
  87. return;
  88. }
  89. bool result = await ItemExchangeSProxy.ItemExchange(_itemId, _buyTimes);
  90. if (result && _onSuccess != null)
  91. {
  92. _onSuccess();
  93. }
  94. PromptController.Instance.ShowFloatTextPrompt("购买成功!", MessageType.SUCCESS);
  95. this.Hide();
  96. }
  97. private void OnClickBtnCancel()
  98. {
  99. this.Hide();
  100. }
  101. }
  102. }