BuyTipsView.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 Action _onSuccess;
  14. public override void Dispose()
  15. {
  16. base.Dispose();
  17. }
  18. protected override void OnInit()
  19. {
  20. base.OnInit();
  21. _ui = UI_BuyTipsUI.Create();
  22. this.viewCom = _ui.target;
  23. this.viewCom.Center();
  24. this.modal = true;
  25. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  26. _ui.m_btnSure.onClick.Add(OnClickBtnSure);
  27. _ui.m_btnCancel.onClick.Add(OnClickBtnCancel);
  28. }
  29. public void SetParams(int itemId, int count, int costId, int costCount, Action onSuccess = null)
  30. {
  31. _itemId = itemId;
  32. _count = count;
  33. _costId = costId;
  34. _costCount = costCount;
  35. _onSuccess = onSuccess;
  36. }
  37. protected override void OnShown()
  38. {
  39. base.OnShown();
  40. UpdateView();
  41. }
  42. private void UpdateView()
  43. {
  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 void OnClickBtnSure()
  51. {
  52. CurrencyRatioCfg currencyRatioCfg = ItemUtil.GetCurrencyRatioCfgById(_itemId);
  53. int count = ItemUtil.GetItemExChangeCount(_itemId, _costCount);
  54. ItemUtil.AddItemUseCost(_itemId, count, _costId, _costCount);
  55. if (_onSuccess != null)
  56. {
  57. _onSuccess();
  58. }
  59. ItemData itemData = new ItemData();
  60. itemData.id = _itemId;
  61. itemData.num = count;
  62. ViewManager.Show<RewardView>(new List<ItemData> { itemData });
  63. this.Hide();
  64. }
  65. private void OnClickBtnCancel()
  66. {
  67. this.Hide();
  68. }
  69. }
  70. }