BuyTipsView.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. BuyTipsController.Dispose();
  18. base.Dispose();
  19. }
  20. protected override void OnInit()
  21. {
  22. base.OnInit();
  23. _ui = UI_BuyTipsUI.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, Action onSuccess = null)
  32. {
  33. _itemId = itemId;
  34. _count = count;
  35. _onSuccess = onSuccess;
  36. }
  37. protected override void OnShown()
  38. {
  39. base.OnShown();
  40. UpdateView();
  41. }
  42. private void UpdateView()
  43. {
  44. ItemExchangeCfgArray.Instance.GetMoneyIdAndNum(_itemId, ItemDataManager.GetItemExchangeTimes(_itemId), _count, out _costId, out _costCount, out int buyNum);
  45. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemId);
  46. _ui.m_txtNeed.text = string.Format("还需要购买{0}个", _count);
  47. _ui.m_loaNeed.url = ResPathUtil.GetCommonGameResPath(itemCfg.res);
  48. ItemCfg costCfg = ItemCfgArray.Instance.GetCfg(_costId);
  49. _ui.m_txtCost.text = string.Format("是否花费{0}{1}购买?", _costCount, costCfg.name);
  50. }
  51. private async void OnClickBtnSure()
  52. {
  53. _result = await ItemExchangeSProxy.ItemExchange(_itemId, _count);
  54. if (_result)
  55. {
  56. BonusController.TryShowBonusList(ItemUtil.CreateItemDataList(_itemId, _count), _onSuccess);
  57. }
  58. this.Hide();
  59. }
  60. private void OnClickBtnCancel()
  61. {
  62. this.Hide();
  63. }
  64. }
  65. }