WeeklyGiftTipsView.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. using FairyGUI;
  2. using UI.ActivityMain;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using ET;
  6. using static GFGGame.ShopSProxy;
  7. using UI.CommonGame;
  8. using System.Text.RegularExpressions;
  9. namespace GFGGame
  10. {
  11. class WeeklyGiftTipsView : BaseWindow
  12. {
  13. private UI_WeeklyGiftTipsUI _ui;
  14. private int giftShopId = 0;
  15. private EffectUI _effectUI1;
  16. private EffectUI _effectUI2;
  17. public override void Dispose()
  18. {
  19. EffectUIPool.Recycle(_effectUI1);
  20. _effectUI1 = null;
  21. EffectUIPool.Recycle(_effectUI2);
  22. _effectUI2 = null;
  23. if (_ui != null)
  24. {
  25. _ui.Dispose();
  26. _ui = null;
  27. }
  28. base.Dispose();
  29. }
  30. protected override void OnInit()
  31. {
  32. base.OnInit();
  33. packageName = UI_WeeklyGiftTipsUI.PACKAGE_NAME;
  34. _ui = UI_WeeklyGiftTipsUI.Create();
  35. this.viewCom = _ui.target;
  36. modal = true;
  37. this.viewCom.Center();
  38. //邊框左上角特效
  39. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holderLeftTop, "ui_Activity", "Com_window_L_up");
  40. //邊框右下角特效
  41. _effectUI2 = EffectUIPool.CreateEffectUI(_ui.m_holderRightDowm, "ui_Activity", "Com_window_R_Down");
  42. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  43. _ui.m_rewardList.itemRenderer = ListItemRender;
  44. _ui.m_rewardList.onClickItem.Add(OnListSelectorItemClick);
  45. _ui.m_backBtn.onClick.Add(OnClickChange);
  46. _ui.m_buyBtn.onClick.Add(OnClickBuy);
  47. }
  48. protected override void OnShown()
  49. {
  50. base.OnShown();
  51. ActivityOpenCfg activityCfg = ActivityOpenCfgArray.Instance.GetCfg(ActivityDataManager.Instance.GetCurOpenActiveByType(101));
  52. giftShopId = activityCfg.paramsArr[0];
  53. if (giftShopId != 0)
  54. {
  55. var shopCfg = ShopCfgArray.Instance.GetCfg(giftShopId);
  56. ItemCfg item = ItemCfgArray.Instance.GetCfg(shopCfg.itemId);
  57. _ui.m_rewardList.numItems = item.itemsArr.Length;
  58. }
  59. else
  60. {
  61. _ui.m_rewardList.numItems = 0;
  62. }
  63. string pattern = @"\[([^\[\]]+)\]"; // 正则表达式模式
  64. // 创建Regex对象
  65. Regex regex = new Regex(pattern);
  66. // 匹配文本中的所有结果
  67. MatchCollection matchesOpen = regex.Matches(activityCfg.openTime);
  68. MatchCollection matchesEnd = regex.Matches(activityCfg.endTime);
  69. string openTime = matchesOpen[0].Groups[1].Value +"." + matchesOpen[1].Groups[1].Value + "." + matchesOpen[2].Groups[1].Value;
  70. string endTime = matchesEnd[0].Groups[1].Value + "." + matchesEnd[1].Groups[1].Value + "." + matchesEnd[2].Groups[1].Value;
  71. _ui.m_timeText.text = string.Format("本期特供时间:{0}-{1}", openTime, endTime);
  72. UpdateBtn();
  73. }
  74. protected override void OnHide()
  75. {
  76. base.OnHide();
  77. }
  78. protected override void AddEventListener()
  79. {
  80. base.AddEventListener();
  81. EventAgent.AddEventListener(ConstMessage.SHOP_BUY, UpdateBtn);
  82. }
  83. protected override void RemoveEventListener()
  84. {
  85. base.RemoveEventListener();
  86. EventAgent.RemoveEventListener(ConstMessage.SHOP_BUY, UpdateBtn);
  87. }
  88. private void OnClickChange()
  89. {
  90. this.Hide();
  91. }
  92. private void ListItemRender(int index, GObject obj)
  93. {
  94. UI_ComItem uiItemChild = UI_ComItem.Proxy(obj);
  95. var shopCfg = ShopCfgArray.Instance.GetCfg(giftShopId);
  96. var itemCfg = ItemCfgArray.Instance.GetCfg(shopCfg.itemId);
  97. int[][] result;
  98. result = itemCfg.itemsArr;
  99. var itemArr = result[index];
  100. var itemCfgChild = ItemCfgArray.Instance.GetCfg(itemArr[0]);
  101. uiItemChild.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfgChild);
  102. uiItemChild.m_txtCount.text = itemArr[1].ToString();
  103. uiItemChild.target.data = itemCfgChild;
  104. uiItemChild.m_QualityType.selectedIndex = itemCfgChild.rarity - 1;
  105. UI_ComItem.ProxyEnd();
  106. }
  107. //弹出物品详细描述框
  108. private void OnListSelectorItemClick(EventContext context)
  109. {
  110. GComponent item = context.data as GComponent;
  111. ItemCfg itemCfg = item.data as ItemCfg;
  112. GoodsItemTipsController.ShowItemTips(itemCfg.id);
  113. }
  114. private async void OnClickBuy()
  115. {
  116. if(giftShopId == 0)
  117. {
  118. return;
  119. }
  120. await ReqShopBuy(giftShopId);
  121. }
  122. private void UpdateBtn()
  123. {
  124. ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(giftShopId);
  125. var remainBuyNum = shopCfg.maxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(shopCfg.id);
  126. if (remainBuyNum == 0)
  127. {
  128. //已售完
  129. _ui.m_buyBtn.visible = false;
  130. }
  131. else
  132. {
  133. //未售完
  134. _ui.m_buyBtn.visible = true;
  135. }
  136. _ui.m_descText.text = string.Format("已购买次数:{0}/{1}", ShopDataManager.Instance.GetGoodsBuyNumById(shopCfg.id) ,shopCfg.maxBuyNum);
  137. }
  138. }
  139. }