BuyTipsView.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System;
  2. using System.Collections.Generic;
  3. using UI.CommonGame;
  4. namespace GFGGame
  5. {
  6. public class BuyTipsView : BaseWindow
  7. {
  8. private UI_BuyTipsUI _ui;
  9. private int _itemId;
  10. private int _costId;
  11. private long _count;
  12. private int _costCount;
  13. private bool _result = false;
  14. private Action _onSuccess;
  15. private bool _showCheck = false;
  16. public override void Dispose()
  17. {
  18. if (_ui != null)
  19. {
  20. _ui.Dispose();
  21. _ui = null;
  22. }
  23. BuyTipsController.Dispose();
  24. base.Dispose();
  25. }
  26. protected override void OnInit()
  27. {
  28. base.OnInit();
  29. _ui = UI_BuyTipsUI.Create();
  30. this.viewCom = _ui.target;
  31. this.viewCom.Center();
  32. this.modal = true;
  33. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  34. _ui.m_btnSure.target.onClick.Add(OnClickBtnSure);
  35. _ui.m_btnCancel.target.onClick.Add(OnClickBtnCancel);
  36. _ui.m_btnCancel.target.onClick.Add(OnClickBtnCancel);
  37. _ui.m_btnCheck.onClick.Add(OnBtnCheckClick);
  38. }
  39. public void SetParams(int itemId, long count, Action onSuccess = null, bool showCheck = false)
  40. {
  41. _itemId = itemId;
  42. _count = count;
  43. _onSuccess = onSuccess;
  44. _showCheck = showCheck;
  45. }
  46. protected override void OnShown()
  47. {
  48. base.OnShown();
  49. UpdateView();
  50. }
  51. private void UpdateView()
  52. {
  53. ItemExchangeCfgArray.Instance.GetMoneyIdAndNum(_itemId, ItemDataManager.GetItemExchangeTimes(_itemId), (int)_count, out _costId, out _costCount, out int buyNum);
  54. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemId);
  55. _ui.m_txtNeed.text = string.Format("还需要购买{0}个", _count);
  56. _ui.m_loaNeed.url = ResPathUtil.GetCommonGameResPath(itemCfg.res);
  57. ItemCfg costCfg = ItemCfgArray.Instance.GetCfg(_costId);
  58. _ui.m_txtCost.text = string.Format("是否花费{0}{1}购买?", _costCount, costCfg.name);
  59. if (_showCheck)
  60. _ui.m_checkType.selectedIndex = 1;
  61. else
  62. _ui.m_checkType.selectedIndex = 0;
  63. }
  64. private async void OnClickBtnSure()
  65. {
  66. _result = await ItemExchangeSProxy.ItemExchange(_itemId, _count);
  67. if (_result)
  68. {
  69. BonusController.TryShowBonusList(ItemUtil.CreateItemDataList(_itemId, _count), _onSuccess);
  70. }
  71. this.Hide();
  72. }
  73. private void OnClickBtnCancel()
  74. {
  75. this.Hide();
  76. }
  77. private void OnBtnCheckClick()
  78. {
  79. LuckyBoxDataManager.Instance.CHECK_TIPS_OPEN = _ui.m_btnCheck.selected;
  80. }
  81. }
  82. }