BuyTipsView.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 int _count;
  12. private int _costCount;
  13. private bool _result = false;
  14. private Action _onSuccess;
  15. public override void Dispose()
  16. {
  17. if (_ui != null)
  18. {
  19. _ui.Dispose();
  20. _ui = null;
  21. }
  22. BuyTipsController.Dispose();
  23. base.Dispose();
  24. }
  25. protected override void OnInit()
  26. {
  27. base.OnInit();
  28. _ui = UI_BuyTipsUI.Create();
  29. this.viewCom = _ui.target;
  30. this.viewCom.Center();
  31. this.modal = true;
  32. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  33. _ui.m_btnSure.onClick.Add(OnClickBtnSure);
  34. _ui.m_btnCancel.onClick.Add(OnClickBtnCancel);
  35. }
  36. public void SetParams(int itemId, int count, Action onSuccess = null)
  37. {
  38. _itemId = itemId;
  39. _count = count;
  40. _onSuccess = onSuccess;
  41. }
  42. protected override void OnShown()
  43. {
  44. base.OnShown();
  45. UpdateView();
  46. }
  47. private void UpdateView()
  48. {
  49. ItemExchangeCfgArray.Instance.GetMoneyIdAndNum(_itemId, ItemDataManager.GetItemExchangeTimes(_itemId), _count, out _costId, out _costCount, out int buyNum);
  50. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemId);
  51. _ui.m_txtNeed.text = string.Format("还需要购买{0}个", _count);
  52. _ui.m_loaNeed.url = ResPathUtil.GetCommonGameResPath(itemCfg.res);
  53. ItemCfg costCfg = ItemCfgArray.Instance.GetCfg(_costId);
  54. _ui.m_txtCost.text = string.Format("是否花费{0}{1}购买?", _costCount, costCfg.name);
  55. }
  56. private async void OnClickBtnSure()
  57. {
  58. _result = await ItemExchangeSProxy.ItemExchange(_itemId, _count);
  59. if (_result)
  60. {
  61. BonusController.TryShowBonusList(ItemUtil.CreateItemDataList(_itemId, _count), _onSuccess);
  62. }
  63. this.Hide();
  64. }
  65. private void OnClickBtnCancel()
  66. {
  67. this.Hide();
  68. }
  69. }
  70. }