RushSaleGiftBoxView.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using ET;
  5. using FairyGUI;
  6. using UI.EnduringGiftBox;
  7. using UnityEngine;
  8. namespace GFGGame
  9. {
  10. //圆形样式的限时礼包
  11. // 4类型-圆形样式:等级条件的数据
  12. // 5类型-圆形样式:时间条件的数据
  13. public class RushSaleGiftBoxView : BaseWindow
  14. {
  15. private UI_RushSaleGiftBoxUI _ui;
  16. private int _type; //决定数据的类型 --等级条件的数据,时间条件的数据
  17. private int _pageIndex; //当前页码,需要显示的数据的索引
  18. private List<GGraph> _graphList = new List<GGraph>();
  19. private List<EffectUI> _effectUIList = new List<EffectUI>();
  20. private List<Transition> _transitionList = new List<Transition>();
  21. private EffectUI _effectUI1;
  22. private EffectUI _effectUI2;
  23. //private EffectUI _effectUI3;
  24. private EffectUI _effectUI4;
  25. private EffectUI _effectUI5;
  26. protected override void OnInit()
  27. {
  28. base.OnInit();
  29. packageName = UI_RushSaleGiftBoxUI.PACKAGE_NAME;
  30. _ui = UI_RushSaleGiftBoxUI.Create();
  31. this.viewCom = _ui.target;
  32. this.viewCom.Center();
  33. this.modal = true;
  34. viewAnimationType = EnumViewAnimationType.None;
  35. _ui.m_btnUp.onClick.Add(OnBtnPreviousClick);
  36. _ui.m_btnNext.onClick.Add(OnBtnNextClick);
  37. _ui.m_btnBack.onClick.Add(OnBtnCancelClick);
  38. _ui.m_btnBuyPink.target.onClick.Add(OnBtnBuyClick);
  39. }
  40. protected override void OnShown()
  41. {
  42. base.OnShown();
  43. _type = (int)(this.viewData as object[])[0]; //ConstActivityType
  44. AddEffect();
  45. _ui.m_t3.Play();
  46. LimitedTimeGiftBoxDataManager.Instance.UpLtgGbItemData4();
  47. LimitedTimeGiftBoxDataManager.Instance.UpLtgGbItemData5();
  48. InitPageInex();
  49. UpViewNone();
  50. }
  51. protected override void AddEventListener()
  52. {
  53. base.AddEventListener();
  54. EventAgent.AddEventListener(ConstMessage.ACTIVITY_REMOVE, UpViewNone);
  55. EventAgent.AddEventListener(ConstMessage.ACTIVITY_ADD, UpViewNone);
  56. EventAgent.AddEventListener(ConstMessage.SHOP_BUY, UpViewNone);
  57. EventAgent.AddEventListener(ConstMessage.LUCKY_BOX_TIME, UpTime);
  58. }
  59. protected override void RemoveEventListener()
  60. {
  61. EventAgent.RemoveEventListener(ConstMessage.ACTIVITY_REMOVE, UpViewNone);
  62. EventAgent.RemoveEventListener(ConstMessage.ACTIVITY_ADD, UpViewNone);
  63. EventAgent.RemoveEventListener(ConstMessage.SHOP_BUY, UpViewNone);
  64. EventAgent.RemoveEventListener(ConstMessage.LUCKY_BOX_TIME, UpTime);
  65. base.RemoveEventListener();
  66. }
  67. private void AddEffect()
  68. {
  69. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holderPaoBaby, "ui_Activity", "Limite_pepole");
  70. //_effectUI3 = EffectUIPool.CreateEffectUI(_ui.m_holderZheKouChiXu, "ui_Activity", "Limite_discount_chixu");
  71. Timers.inst.Add(0.8f, 1, (obj) =>
  72. {
  73. //防止手速超快关了又开开了又关导致的特效重复加载,因为这里是通过Timers延时加载的
  74. if (ViewManager.isViewOpen(nameof(RushSaleGiftBoxView)))
  75. {
  76. _effectUI4 = EffectUIPool.CreateEffectUI(_ui.m_holderZheKou, "ui_Activity", "Limite_discount_baofa");
  77. _effectUI2 = EffectUIPool.CreateEffectUI(_ui.m_holderBtnBy, "ui_Activity", "Limite_button");
  78. }
  79. }
  80. );
  81. _effectUI5 = EffectUIPool.CreateEffectUI(_ui.m_holderStar, "ui_Activity", "Limite_star");
  82. }
  83. //实例化索引
  84. private void InitPageInex()
  85. {
  86. if (_type == ActivityType.XSLB2)
  87. {
  88. //4
  89. var data4 = LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData4
  90. .FirstOrDefault(a => a.IndexType == 1);
  91. _pageIndex = data4 == null ? 0 : LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData4.IndexOf(data4);
  92. }
  93. else if (_type == ActivityType.XSLB3)
  94. {
  95. //5摘星里面的 每日特惠
  96. var data5 = LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData5
  97. .FirstOrDefault(a => a.IndexType == 1);
  98. _pageIndex = data5 == null ? 0 : LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData5.IndexOf(data5);
  99. if (!LimitedTimeGiftBoxDataManager.Instance.IsOpenMeiRiTeHui)
  100. {
  101. LimitedTimeGiftBoxDataManager.Instance.SetIsOpenMeiRiTeHui();
  102. }
  103. }
  104. }
  105. public void UpTime()
  106. {
  107. //筛选一条数据用来界面渲染
  108. var list = _type == ActivityType.XSLB2
  109. ? LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData4
  110. : LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData5;
  111. list = list.Where(a => a.EndTime > TimeInfo.Instance.ServerNow()).ToList();
  112. if (list.Count == 0)
  113. {
  114. PromptController.Instance.ShowFloatTextPrompt("活动已结束");
  115. this.Hide();
  116. return;
  117. }
  118. _ui.m_txtBoxResidueTime.text = TimeUtil.GetTimeLeft(TimeInfo.Instance.ServerNow(), list[0].EndTime);
  119. }
  120. private void UpdateView(ListUtil.NavigateType type)
  121. {
  122. var list = _type == ActivityType.XSLB2
  123. ? LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData4
  124. : LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData5;
  125. list = list.Where(a => a.EndTime > TimeInfo.Instance.ServerNow()).ToList();
  126. if (list.Count == 0)
  127. {
  128. PromptController.Instance.ShowFloatTextPrompt("活动已结束");
  129. this.Hide();
  130. return;
  131. }
  132. var data = ListUtil.Navigate(list, type, _pageIndex, out int newIndex);
  133. _pageIndex = newIndex;
  134. _ui.m_btnUp.visible = true;
  135. _ui.m_btnNext.visible = true;
  136. if (list.Count == 1)
  137. {
  138. _ui.m_btnUp.visible = false;
  139. _ui.m_btnNext.visible = false;
  140. }
  141. else
  142. {
  143. //翻页翻到了最后一条数据
  144. if (list.Count == _pageIndex + 1)
  145. {
  146. _ui.m_btnNext.visible = false;
  147. }
  148. if (_pageIndex == 0)
  149. {
  150. _ui.m_btnUp.visible = false;
  151. }
  152. }
  153. var shopCfg = ShopCfgArray.Instance.GetCfg(data.ShopCfgId);
  154. var boxItemCfg = ItemCfgArray.Instance.GetCfg(shopCfg.itemId);
  155. var remainBuyNum = shopCfg.maxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(shopCfg.id);
  156. string mTxtUrc = string.Empty;
  157. if (shopCfg.refreshType == RefreshType.DAY)
  158. {
  159. mTxtUrc = $"今日限购{remainBuyNum}/{shopCfg.maxBuyNum}";
  160. }
  161. else if (shopCfg.refreshType == RefreshType.WEEK)
  162. {
  163. mTxtUrc = $"本周限购{remainBuyNum}/{shopCfg.maxBuyNum}";
  164. }
  165. else if (shopCfg.refreshType == RefreshType.MONTH)
  166. {
  167. mTxtUrc = $"本月限购{remainBuyNum}/{shopCfg.maxBuyNum}";
  168. }
  169. string mTxtNewPrice;
  170. _ui.m_txtLrc.text = string.Empty;
  171. _ui.m_btnBuyPink.m_loaIcon.visible = false;
  172. _ui.m_btnBuyPink.m_txtOldPrice.text = shopCfg.originalPrice.ToString();
  173. if (shopCfg.costType == CostType.ITEM)
  174. {
  175. //货币
  176. ItemCfg costCfg = ItemCfgArray.Instance.GetCfg(shopCfg.costId);
  177. mTxtNewPrice = shopCfg.price.ToString();
  178. _ui.m_btnBuyPink.m_loaIcon.visible = true;
  179. _ui.m_btnBuyPink.m_loaIcon.url = ResPathUtil.GetIconPath(costCfg);
  180. //_ui.m_btnBuyPink.m_txtNewPrice.x = 166;
  181. }
  182. else if (shopCfg.costType == CostType.RMB)
  183. {
  184. //人民币
  185. mTxtNewPrice = $"{shopCfg.price}元";
  186. //_ui.m_btnBuyPink.m_txtNewPrice.align = AlignType.Left;
  187. //_ui.m_btnBuyPink.m_txtNewPrice.x = 166;
  188. _ui.m_txtLrc.text = $"可获得{shopCfg.price * 10}会员积分";
  189. }
  190. else
  191. {
  192. //免费
  193. mTxtNewPrice = $"免费";
  194. _ui.m_btnBuyPink.m_txtOldPrice.text = "";
  195. //_ui.m_btnBuyPink.m_txtNewPrice.align = AlignType.Left;
  196. // _ui.m_btnBuyPink.m_txtNewPrice.x = 166;
  197. }
  198. if (remainBuyNum == 0)
  199. {
  200. //已售完
  201. _ui.m_btnBuyPink.m_bagGrey.visible = true;
  202. _ui.m_btnBuyPink.m_bagPink.visible = false;
  203. _ui.m_btnBuyPink.m_txtSoldOut.visible = true;
  204. _ui.m_btnBuyPink.m_txtSoldOut.text = "已售罄";
  205. _ui.m_holderBtnBy.visible = false;
  206. _ui.m_btnBuyPink.m_loaIcon.visible = false;
  207. _ui.m_btnBuyPink.m_txtOldPrice.visible = false;
  208. _ui.m_btnBuyPink.m_txtNewPrice.visible = false;
  209. }
  210. else
  211. {
  212. //未售完
  213. _ui.m_btnBuyPink.m_bagGrey.visible = false;
  214. _ui.m_btnBuyPink.m_bagPink.visible = true;
  215. _ui.m_btnBuyPink.m_txtSoldOut.visible = false;
  216. _ui.m_btnBuyPink.m_txtSoldOut.text = "";
  217. // _ui.m_holderBtnBy.visible = true;
  218. _ui.m_btnBuyPink.m_loaIcon.visible = true;
  219. _ui.m_btnBuyPink.m_txtOldPrice.visible = true;
  220. _ui.m_btnBuyPink.m_txtNewPrice.visible = true;
  221. }
  222. _ui.m_txtBoxItemName.text = shopCfg.itemName;
  223. //这个B时间需要在一个地方统一处理,然后广播事件,不然可能会存在不同步的问题,最后做
  224. _ui.m_txtBoxResidueTime.text = TimeUtil.GetTimeLeft(TimeInfo.Instance.ServerNow(), data.EndTime);
  225. _ui.m_txtUrc.text = mTxtUrc;
  226. _ui.m_comDiscount.m_txtDiscountNum.text =
  227. NumberUtil.CalculateDiscount(shopCfg.originalPrice, shopCfg.price);
  228. _ui.m_btnBuyPink.m_txtNewPrice.text = mTxtNewPrice;
  229. _ui.m_btnBuyPink.target.data = shopCfg;
  230. _ui.m_list.data = boxItemCfg;
  231. _ui.m_list.itemRenderer = ListItemRender;
  232. _ui.m_list.numItems = boxItemCfg.itemsArr.Length;
  233. _ui.m_list.visible = true;
  234. }
  235. private void ListItemRender(int index, GObject obj)
  236. {
  237. UI_ComRsGifBoxIconItem uiItem = UI_ComRsGifBoxIconItem.Proxy(obj);
  238. var boxItemCfg = uiItem.target.parent.data as ItemCfg;
  239. var itemKv = boxItemCfg.itemsArr[index];
  240. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemKv[0]);
  241. uiItem.m_txtItemName.text = itemCfg.name;
  242. uiItem.target.data = itemCfg;
  243. uiItem.m_comRewardIconItem.m_bagBlue.visible = false;
  244. uiItem.m_comRewardIconItem.m_bagBlueEx.visible = false;
  245. uiItem.m_comRewardIconItem.m_num.text = itemKv[1].ToString();
  246. uiItem.m_comRewardIconItem.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  247. uiItem.m_comRewardIconItem.target.onClick.Add(OnListSelectorItemClick);
  248. if (!_graphList.Contains(uiItem.m_holderItem))
  249. {
  250. EffectUI _effectUI = EffectUIPool.CreateEffectUI(uiItem.m_holderItem, "ui_Activity", "Limite_kuang");
  251. _graphList.Add(uiItem.m_holderItem);
  252. _effectUIList.Add(_effectUI);
  253. }
  254. uiItem.m_t1.Play();
  255. UI_RushSaleGiftBoxUI.ProxyEnd();
  256. }
  257. private void UpViewNone()
  258. {
  259. UpdateView(ListUtil.NavigateType.None);
  260. }
  261. //上一条
  262. private void OnBtnPreviousClick()
  263. {
  264. UpdateView(ListUtil.NavigateType.Previous);
  265. }
  266. //下一条
  267. private void OnBtnNextClick()
  268. {
  269. UpdateView(ListUtil.NavigateType.Next);
  270. }
  271. //购买按钮点击事件
  272. private void OnBtnBuyClick(EventContext context)
  273. {
  274. GObject sender = context.sender as GObject;
  275. //GObject obj = sender.parent;
  276. ShopCfg cfg = sender.data as ShopCfg;
  277. bool isSellOut = cfg.maxBuyNum > 0 &&
  278. cfg.maxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(cfg.id) <= 0;
  279. if (isSellOut)
  280. {
  281. PromptController.Instance.ShowFloatTextPrompt("已售罄");
  282. return;
  283. }
  284. if (!ShopDataManager.Instance.GetShopGoodsStateById(cfg.id))
  285. {
  286. PromptController.Instance.ShowFloatTextPrompt(ShopDataManager.Instance.GetShopGoodsStateTips(cfg.id));
  287. return;
  288. }
  289. if (cfg.costType == CostType.FREE)
  290. {
  291. ShopSProxy.ReqShopBuy(cfg.id, 1).Coroutine();
  292. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.SHANG_CHENG, 2);
  293. }
  294. else
  295. {
  296. ViewManager.Show<ItemExchangeView>(cfg.id);
  297. }
  298. }
  299. private void DestroyObjectFromView()
  300. {
  301. for (int i = 0; i < _effectUIList.Count; i++) {
  302. if (_effectUIList[i] != null)
  303. {
  304. EffectUIPool.Recycle(_effectUIList[i]);
  305. _effectUIList[i] = null;
  306. }
  307. }
  308. _effectUIList.Clear();
  309. _graphList.Clear();
  310. }
  311. protected override void OnHide()
  312. {
  313. EffectUIPool.Recycle(_effectUI1);
  314. _effectUI1 = null;
  315. EffectUIPool.Recycle(_effectUI2);
  316. _effectUI2 = null;
  317. //EffectUIPool.Recycle(_effectUI3);
  318. //_effectUI3 = null;
  319. EffectUIPool.Recycle(_effectUI4);
  320. _effectUI4 = null;
  321. EffectUIPool.Recycle(_effectUI5);
  322. _effectUI5 = null;
  323. DestroyObjectFromView();
  324. this.RemoveEventListener();
  325. //Dispose();
  326. base.Hide();
  327. }
  328. private void OnBtnCancelClick()
  329. {
  330. this.Hide();
  331. }
  332. //弹出物品详细描述框
  333. private void OnListSelectorItemClick(EventContext context)
  334. {
  335. GObject sender = context.sender as GObject;
  336. GObject obj = sender.parent;
  337. ItemCfg itemCfg = obj.data as ItemCfg;
  338. GoodsItemTipsController.ShowItemTips(itemCfg.id);
  339. }
  340. }
  341. }