WeeklyGiftTipsView.cs 6.0 KB

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