GiftBagBuyView.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using System.Threading.Tasks;
  2. using FairyGUI;
  3. using UI.RechargeStore;
  4. namespace GFGGame
  5. {
  6. public class GiftBagBuyView : BaseWindow
  7. {
  8. private UI_GiftBagBuyUI _ui;
  9. private int _giftId;
  10. public override void Dispose()
  11. {
  12. if (_ui != null)
  13. {
  14. _ui.Dispose();
  15. }
  16. _ui = null;
  17. base.Dispose();
  18. }
  19. protected override void OnHide()
  20. {
  21. base.OnHide();
  22. }
  23. protected override void OnInit()
  24. {
  25. base.OnInit();
  26. packageName = UI_GiftBagBuyUI.PACKAGE_NAME;
  27. _ui = UI_GiftBagBuyUI.Create();
  28. this.viewCom = _ui.target;
  29. this.viewCom.Center();
  30. this.modal = true;
  31. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  32. _ui.m_btnBuy.onClick.Add(OnBtnBuyClick);
  33. _ui.m_list.itemRenderer = ListItemRender;
  34. }
  35. protected override void OnShown()
  36. {
  37. base.OnShown();
  38. _giftId = (int)this.viewData;
  39. GiftBagCfg cfg = GiftBagCfgArray.Instance.GetCfg(_giftId);
  40. _ui.m_txtName.text = cfg.name;
  41. _ui.m_loaIcon.url = string.Format("ui://RechargeStore/{0}", cfg.res);
  42. _ui.m_list.numItems = cfg.itemsArr.Length;
  43. _ui.m_c1.selectedIndex = RechargeDataManager.Instance.GetGiftStateById(_giftId) ? 0 : 1;
  44. if (cfg.lockType == LockType.STORY_LV)
  45. {
  46. StoryLevelCfg storyLevelCfg = StoryLevelCfgArray.Instance.GetCfg(cfg.storyLevelId);
  47. _ui.m_txtLock.text = string.Format("通关{0}-{1}解锁", StoryUtil.GetChapterOrder(storyLevelCfg.chapterId), storyLevelCfg.order);
  48. }
  49. else if (cfg.lockType == LockType.ROLE_LV)
  50. {
  51. _ui.m_txtLock.text = string.Format("角色达到{0}级解锁", cfg.lv);
  52. }
  53. int buyNum = RechargeDataManager.Instance.GetGiftBuyNumById(cfg.id);
  54. _ui.m_txtLimit.text = string.Format("每{0}限购({1}/{2})", RechargeDataManager.Instance.refreshType[cfg.refreshType], StringUtil.GetColorText(buyNum.ToString(), "#DA8870"), cfg.maxBuyNum);
  55. if (cfg.refreshType == RefreshType.NONE) _ui.m_txtLimit.text = "永久限购";
  56. _ui.m_txtEndTime.text = RechargeDataManager.Instance.GetEndTime(cfg.id);
  57. _ui.m_grpEndTime.visible = cfg.endTime != "";
  58. _ui.m_txtOriginalPrice.text = cfg.originalPrice.ToString();
  59. if (cfg.price > 0 && cfg.costType != CostType.FREE)
  60. {
  61. _ui.m_grpOriginalPrice.visible = cfg.originalPrice > 0;
  62. _ui.m_grpIcon.visible = true;
  63. _ui.m_txtPrice.text = cfg.price.ToString();
  64. if (cfg.costType == CostType.RMB)
  65. {
  66. _ui.m_loaPriceIcon.visible = false;
  67. _ui.m_txtIcon.visible = true;
  68. _ui.m_txtIcon.text = "¥";
  69. }
  70. else
  71. {
  72. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(cfg.costId);
  73. _ui.m_loaPriceIcon.url = ResPathUtil.GetIconPath(itemCfg);
  74. _ui.m_loaPriceIcon.visible = true;
  75. _ui.m_txtIcon.visible = false;
  76. }
  77. }
  78. else
  79. {
  80. _ui.m_grpIcon.visible = false;
  81. _ui.m_grpOriginalPrice.visible = false;
  82. _ui.m_txtPrice.text = "免费";
  83. }
  84. }
  85. private void ListItemRender(int index, GObject item)
  86. {
  87. GiftBagCfg cfg = GiftBagCfgArray.Instance.GetCfg(_giftId);
  88. ItemData itemData = ItemUtil.createItemData(cfg.itemsArr[index]);
  89. if (item.data == null)
  90. {
  91. item.data = new ItemView(item as GComponent);
  92. }
  93. (item.data as ItemView).SetData(itemData);
  94. }
  95. private async void OnBtnBuyClick()
  96. {
  97. GiftBagCfg cfg = GiftBagCfgArray.Instance.GetCfg(_giftId);
  98. if (cfg.costType == CostType.MONEY || cfg.costType == CostType.ITEM)
  99. {
  100. int hasNum = ItemDataManager.GetItemNum(cfg.costId);
  101. if (hasNum < cfg.price)
  102. {
  103. PromptController.Instance.ShowFloatTextPrompt("道具不足");
  104. return;
  105. }
  106. }
  107. bool result = await RechargeSProxy.ReqBuyGiftBag(_giftId);
  108. if (result && cfg.costType == CostType.RMB)
  109. {
  110. PromptController.Instance.ShowFloatTextPrompt("虚拟充值购买成功");
  111. }
  112. // if (cfg.costType == CostType.RMB)
  113. // {
  114. // }
  115. // else
  116. // {
  117. // RechargeSProxy.ReqBuyGiftBag(_giftId).Coroutine();
  118. this.Hide();
  119. // }
  120. }
  121. }
  122. }