RushSaleGiftBoxView.cs 16 KB

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