RushSaleGiftBoxView.cs 17 KB

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