RushSaleGiftBoxView.cs 16 KB

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