RushSaleGiftBoxView.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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. string resPath4 = ResPathUtil.GetViewEffectPath("ui_Activity", "Limite_discount_baofa");
  82. SceneController.AddObjectToView(null, null, _ui.m_holderZheKou, resPath4,
  83. out _gameObject4, out _wrapper4);
  84. string resPath2 = ResPathUtil.GetViewEffectPath("ui_Activity", "Limite_button");
  85. SceneController.AddObjectToView(null, null, _ui.m_holderBtnBy, resPath2,
  86. out _gameObject2, out _wrapper2);
  87. }
  88. );
  89. string resPath5 = ResPathUtil.GetViewEffectPath("ui_Activity", "Limite_star");
  90. SceneController.AddObjectToView(null, null, _ui.m_holderStar, resPath5,
  91. out _gameObject5, out _wrapper5);
  92. }
  93. //实例化索引
  94. private void InitPageInex()
  95. {
  96. if (_type == ActivityType.XSLB2)
  97. {
  98. //4
  99. var data4 = LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData4
  100. .FirstOrDefault(a => a.IndexType == 1);
  101. _pageIndex = data4 == null ? 0 : LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData4.IndexOf(data4);
  102. }
  103. else if (_type == ActivityType.XSLB3)
  104. {
  105. //5
  106. var data5 = LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData5
  107. .FirstOrDefault(a => a.IndexType == 1);
  108. _pageIndex = data5 == null ? 0 : LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData5.IndexOf(data5);
  109. }
  110. }
  111. public void UpTime()
  112. {
  113. //筛选一条数据用来界面渲染
  114. var list = _type == ActivityType.XSLB2
  115. ? LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData4
  116. : LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData5;
  117. list = list.Where(a => a.EndTime > TimeInfo.Instance.ServerNow()).ToList();
  118. if (list.Count == 0)
  119. {
  120. PromptController.Instance.ShowFloatTextPrompt("活动已结束");
  121. this.Hide();
  122. return;
  123. }
  124. _ui.m_txtBoxResidueTime.text = TimeUtil.GetTimeLeft(TimeInfo.Instance.ServerNow(), list[0].EndTime);
  125. }
  126. private void UpdateView(ListUtil.NavigateType type)
  127. {
  128. var list = _type == ActivityType.XSLB2
  129. ? LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData4
  130. : LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData5;
  131. list = list.Where(a => a.EndTime > TimeInfo.Instance.ServerNow()).ToList();
  132. if (list.Count == 0)
  133. {
  134. PromptController.Instance.ShowFloatTextPrompt("活动已结束");
  135. this.Hide();
  136. return;
  137. }
  138. var data = ListUtil.Navigate(list, type, _pageIndex, out int newIndex);
  139. _pageIndex = newIndex;
  140. _ui.m_btnUp.visible = true;
  141. _ui.m_btnNext.visible = true;
  142. if (list.Count == 1)
  143. {
  144. _ui.m_btnUp.visible = false;
  145. _ui.m_btnNext.visible = false;
  146. }
  147. else
  148. {
  149. //翻页翻到了最后一条数据
  150. if (list.Count == _pageIndex + 1)
  151. {
  152. _ui.m_btnNext.visible = false;
  153. }
  154. if (_pageIndex == 0)
  155. {
  156. _ui.m_btnUp.visible = false;
  157. }
  158. }
  159. var shopCfg = ShopCfgArray.Instance.GetCfg(data.ShopCfgId);
  160. var boxItemCfg = ItemCfgArray.Instance.GetCfg(shopCfg.itemId);
  161. var remainBuyNum = shopCfg.maxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(shopCfg.id);
  162. string mTxtUrc = string.Empty;
  163. if (shopCfg.refreshType == RefreshType.DAY)
  164. {
  165. mTxtUrc = $"今日限购{remainBuyNum}/{shopCfg.maxBuyNum}";
  166. }
  167. else if (shopCfg.refreshType == RefreshType.WEEK)
  168. {
  169. mTxtUrc = $"本周限购{remainBuyNum}/{shopCfg.maxBuyNum}";
  170. }
  171. else if (shopCfg.refreshType == RefreshType.MONTH)
  172. {
  173. mTxtUrc = $"本月限购{remainBuyNum}/{shopCfg.maxBuyNum}";
  174. }
  175. if (remainBuyNum == 0)
  176. {
  177. //已售完
  178. _ui.m_btnBuyPink.m_bagGrey.visible = true;
  179. _ui.m_btnBuyPink.m_bagPink.visible = false;
  180. }
  181. else
  182. {
  183. //未售完
  184. _ui.m_btnBuyPink.m_bagGrey.visible = false;
  185. _ui.m_btnBuyPink.m_bagPink.visible = true;
  186. }
  187. string mTxtNewPrice;
  188. _ui.m_txtLrc.text = string.Empty;
  189. _ui.m_btnBuyPink.m_loaIcon.visible = false;
  190. _ui.m_btnBuyPink.m_txtOldPrice.text = shopCfg.originalPrice.ToString();
  191. if (shopCfg.costType == CostType.ITEM)
  192. {
  193. //货币
  194. ItemCfg costCfg = ItemCfgArray.Instance.GetCfg(shopCfg.costId);
  195. mTxtNewPrice = shopCfg.price.ToString();
  196. _ui.m_btnBuyPink.m_loaIcon.visible = true;
  197. _ui.m_btnBuyPink.m_loaIcon.url = ResPathUtil.GetIconPath(costCfg);
  198. //_ui.m_btnBuyPink.m_txtNewPrice.x = 166;
  199. }
  200. else if (shopCfg.costType == CostType.RMB)
  201. {
  202. //人民币
  203. mTxtNewPrice = $"{shopCfg.price}元";
  204. //_ui.m_btnBuyPink.m_txtNewPrice.align = AlignType.Left;
  205. //_ui.m_btnBuyPink.m_txtNewPrice.x = 166;
  206. _ui.m_txtLrc.text = $"可获得{shopCfg.price * 10}会员积分";
  207. }
  208. else
  209. {
  210. //免费
  211. mTxtNewPrice = $"免费";
  212. _ui.m_btnBuyPink.m_txtOldPrice.text = "";
  213. //_ui.m_btnBuyPink.m_txtNewPrice.align = AlignType.Left;
  214. // _ui.m_btnBuyPink.m_txtNewPrice.x = 166;
  215. }
  216. _ui.m_txtBoxItemName.text = shopCfg.itemName;
  217. //这个B时间需要在一个地方统一处理,然后广播事件,不然可能会存在不同步的问题,最后做
  218. _ui.m_txtBoxResidueTime.text = TimeUtil.GetTimeLeft(TimeInfo.Instance.ServerNow(), data.EndTime);
  219. _ui.m_txtUrc.text = mTxtUrc;
  220. _ui.m_comDiscount.m_txtDiscountNum.text =
  221. NumberUtil.CalculateDiscount(shopCfg.originalPrice, shopCfg.price);
  222. _ui.m_btnBuyPink.m_txtNewPrice.text = mTxtNewPrice;
  223. _ui.m_btnBuyPink.target.data = shopCfg;
  224. _ui.m_list.data = boxItemCfg;
  225. _ui.m_list.itemRenderer = ListItemRender;
  226. _ui.m_list.numItems = boxItemCfg.itemsArr.Length;
  227. _ui.m_list.visible = true;
  228. }
  229. private void ListItemRender(int index, GObject obj)
  230. {
  231. UI_ComRsGifBoxIconItem uiItem = UI_ComRsGifBoxIconItem.Proxy(obj);
  232. var boxItemCfg = uiItem.target.parent.data as ItemCfg;
  233. var itemKv = boxItemCfg.itemsArr[index];
  234. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemKv[0]);
  235. uiItem.m_txtItemName.text = itemCfg.name;
  236. uiItem.target.data = itemCfg;
  237. uiItem.m_comRewardIconItem.m_bagBlue.visible = false;
  238. uiItem.m_comRewardIconItem.m_bagBlueEx.visible = false;
  239. uiItem.m_comRewardIconItem.m_num.text = itemKv[1].ToString();
  240. uiItem.m_comRewardIconItem.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  241. uiItem.m_comRewardIconItem.target.onClick.Add(OnListSelectorItemClick);
  242. if (!_graphList.Contains(uiItem.m_holderItem))
  243. {
  244. string resPath = ResPathUtil.GetViewEffectPath("ui_Activity", "Limite_kuang");
  245. SceneController.AddObjectToView(null, null, uiItem.m_holderItem, resPath, out var gameObject,
  246. out var wrapper);
  247. _graphList.Add(uiItem.m_holderItem);
  248. _gameObjectList.Add(gameObject);
  249. _wrapperList.Add(wrapper);
  250. }
  251. uiItem.m_t1.Play();
  252. UI_RushSaleGiftBoxUI.ProxyEnd();
  253. }
  254. private void UpViewNone()
  255. {
  256. UpdateView(ListUtil.NavigateType.None);
  257. }
  258. //上一条
  259. private void OnBtnPreviousClick()
  260. {
  261. UpdateView(ListUtil.NavigateType.Previous);
  262. }
  263. //下一条
  264. private void OnBtnNextClick()
  265. {
  266. UpdateView(ListUtil.NavigateType.Next);
  267. }
  268. //购买按钮点击事件
  269. private void OnBtnBuyClick(EventContext context)
  270. {
  271. GObject sender = context.sender as GObject;
  272. //GObject obj = sender.parent;
  273. ShopCfg cfg = sender.data as ShopCfg;
  274. bool isSellOut = cfg.maxBuyNum > 0 &&
  275. cfg.maxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(cfg.id) <= 0;
  276. if (isSellOut)
  277. {
  278. PromptController.Instance.ShowFloatTextPrompt("已售罄");
  279. return;
  280. }
  281. if (!ShopDataManager.Instance.GetShopGoodsStateById(cfg.id))
  282. {
  283. PromptController.Instance.ShowFloatTextPrompt(ShopDataManager.Instance.GetShopGoodsStateTips(cfg.id));
  284. return;
  285. }
  286. if (cfg.costType == CostType.FREE)
  287. {
  288. ShopSProxy.ReqShopBuy(cfg.id, 1).Coroutine();
  289. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.SHANG_CHENG, 2);
  290. }
  291. else
  292. {
  293. ViewManager.Show<ItemExchangeView>(cfg.id);
  294. }
  295. }
  296. private void DestroyObjectFromView()
  297. {
  298. foreach (var itemGameObject in _gameObjectList)
  299. {
  300. if (itemGameObject != null)
  301. {
  302. GameObject.DestroyImmediate(itemGameObject);
  303. }
  304. }
  305. _gameObjectList.Clear();
  306. foreach (var itemWrapper in _wrapperList)
  307. {
  308. if (itemWrapper != null)
  309. {
  310. itemWrapper.Dispose();
  311. }
  312. }
  313. // foreach (var transition in _transitionList)
  314. // {
  315. // if (transition != null)
  316. // {
  317. // transition.Stop(true, false);
  318. // transition.Dispose();
  319. // transition.PlayReverse();
  320. // }
  321. // }
  322. // _transitionList.Clear();
  323. _wrapperList.Clear();
  324. _graphList.Clear();
  325. }
  326. protected override void OnHide()
  327. {
  328. SceneController.DestroyObjectFromView(_gameObject1, _wrapper1);
  329. SceneController.DestroyObjectFromView(_gameObject2, _wrapper2);
  330. SceneController.DestroyObjectFromView(_gameObject3, _wrapper3);
  331. SceneController.DestroyObjectFromView(_gameObject4, _wrapper4);
  332. SceneController.DestroyObjectFromView(_gameObject5, _wrapper5);
  333. DestroyObjectFromView();
  334. this.RemoveEventListener();
  335. //Dispose();
  336. base.Hide();
  337. }
  338. private void OnBtnCancelClick()
  339. {
  340. this.Hide();
  341. }
  342. //弹出物品详细描述框
  343. private void OnListSelectorItemClick(EventContext context)
  344. {
  345. GObject sender = context.sender as GObject;
  346. GObject obj = sender.parent;
  347. ItemCfg itemCfg = obj.data as ItemCfg;
  348. GoodsItemTipsController.ShowItemTips(itemCfg.id);
  349. }
  350. }
  351. }