BuyTipsView.cs 2.2 KB

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