BuyConfirmView.cs 4.2 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 _costId;
  10. private int _count;
  11. private int _costCount;
  12. private Action _onSuccess;
  13. private int _times = 0;
  14. private int _maxTimes = 0;
  15. private string _message = "";
  16. public override void Dispose()
  17. {
  18. base.Dispose();
  19. }
  20. protected override void OnInit()
  21. {
  22. base.OnInit();
  23. _ui = UI_BuyConfirmUI.Create();
  24. this.viewCom = _ui.target;
  25. this.viewCom.Center();
  26. this.modal = true;
  27. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  28. _ui.m_btnSure.onClick.Add(OnClickBtnSure);
  29. _ui.m_btnCancel.onClick.Add(OnClickBtnCancel);
  30. }
  31. public void SetParams(int itemId, int count, int costId, int costCount, Action onSuccess, int times = 0, int maxTimes = 0, string message = "")
  32. {
  33. _itemId = itemId;
  34. _count = count;
  35. _costId = costId;
  36. _costCount = costCount;
  37. _times = times;
  38. _maxTimes = maxTimes;
  39. _onSuccess = onSuccess;
  40. _message = message;
  41. }
  42. protected override void OnShown()
  43. {
  44. base.OnShown();
  45. UpdateView();
  46. }
  47. private void UpdateView()
  48. {
  49. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemId);
  50. ItemCfg costCfg = ItemCfgArray.Instance.GetCfg(_costId);
  51. _ui.m_txtNeed.text = string.Format("是否花费{0}{1} 购买{2}{3}", _costCount, costCfg.name, _count, itemCfg.name);
  52. _ui.m_txtNum.text = "";
  53. if (_message != "")
  54. {
  55. _ui.m_txtNum.text = _message;
  56. }
  57. else if (_maxTimes != 0)
  58. {
  59. _ui.m_txtNum.text = string.Format("今日剩余购买次数{0}/{1}", _times, _maxTimes);
  60. }
  61. }
  62. private void OnClickBtnSure()
  63. {
  64. if (_times <= 0 && _maxTimes != 0)
  65. {
  66. PromptController.Instance.ShowFloatTextPrompt("购买次数不足!");
  67. return;
  68. }
  69. if (ItemDataManager.GetItemNum(_costId) < _costCount)
  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 = _costCount - ItemDataManager.GetItemNum(_costId);
  82. ItemExchangeCfg currencyRatioCfg = ItemUtil.GetCurrencyRatioCfgById(_costId);
  83. BuyItemConteoller.Show(_costId, (int)currencyRatioCfg.costId, (int)currencyRatioCfg.num, (int)currencyRatioCfg.costNum, costNeedCount, null, true, true, GameConst.MAX_COUNT_TO_BUY_DIAMOND_RED);
  84. }));
  85. OnClickBtnCancel();
  86. }
  87. return;
  88. }
  89. ItemExchangeCfg currencyRatioCfg = ItemUtil.GetCurrencyRatioCfgById(_itemId);
  90. // int count = (int)Math.Ceiling((decimal)_costCount / currencyRatioCfg.costNum * currencyRatioCfg.num);
  91. int count = ItemUtil.GetItemExChangeCount(_itemId, _costCount);
  92. ItemUtil.AddItemUseCost(_itemId, count, _costId, _costCount);
  93. if (_onSuccess != null)
  94. {
  95. _onSuccess();
  96. }
  97. PromptController.Instance.ShowFloatTextPrompt("购买成功!", MessageType.SUCCESS);
  98. this.Hide();
  99. }
  100. private void OnClickBtnCancel()
  101. {
  102. this.Hide();
  103. }
  104. }
  105. }