WeeklyGiftTipsView.cs 5.7 KB

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