GiftBagBuyView.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. _ui.m_txtRefreshTime.text = RechargeDataManager.Instance.GetRefreshTime(cfg.id);
  56. _ui.m_grpRefreshTime.visible = RechargeDataManager.Instance.GetRefreshTime(cfg.id) != "";
  57. _ui.m_txtOriginalPrice.text = cfg.originalPrice.ToString();
  58. if (cfg.price > 0 && cfg.costType != CostType.FREE)
  59. {
  60. _ui.m_grpOriginalPrice.visible = cfg.originalPrice > 0;
  61. _ui.m_grpIcon.visible = true;
  62. _ui.m_txtPrice.text = cfg.price.ToString();
  63. if (cfg.costType == CostType.RMB)
  64. {
  65. _ui.m_loaPriceIcon.visible = false;
  66. _ui.m_txtIcon.visible = true;
  67. _ui.m_txtIcon.text = "¥";
  68. }
  69. else
  70. {
  71. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(cfg.costId);
  72. _ui.m_loaPriceIcon.url = ResPathUtil.GetIconPath(itemCfg);
  73. _ui.m_loaPriceIcon.visible = true;
  74. _ui.m_txtIcon.visible = false;
  75. }
  76. }
  77. else
  78. {
  79. _ui.m_grpIcon.visible = false;
  80. _ui.m_grpOriginalPrice.visible = false;
  81. _ui.m_txtPrice.text = "免费";
  82. }
  83. }
  84. private void ListItemRender(int index, GObject item)
  85. {
  86. GiftBagCfg cfg = GiftBagCfgArray.Instance.GetCfg(_giftId);
  87. ItemData itemData = ItemUtil.createItemData(cfg.itemsArr[index]);
  88. if (item.data == null)
  89. {
  90. item.data = new ItemView(item as GComponent);
  91. }
  92. (item.data as ItemView).SetData(itemData);
  93. }
  94. private void OnBtnBuyClick()
  95. {
  96. GiftBagCfg cfg = GiftBagCfgArray.Instance.GetCfg(_giftId);
  97. if (cfg.costType == CostType.MONEY || cfg.costType == CostType.ITEM)
  98. {
  99. int hasNum = ItemDataManager.GetItemNum(cfg.costId);
  100. if (hasNum < cfg.price)
  101. {
  102. PromptController.Instance.ShowFloatTextPrompt("道具不足");
  103. return;
  104. }
  105. }
  106. if (cfg.costType == CostType.RMB)
  107. {
  108. }
  109. else
  110. {
  111. RechargeSProxy.ReqBuyGiftBag(_giftId).Coroutine();
  112. this.Hide();
  113. }
  114. }
  115. }
  116. }