RushSaleGiftBoxView.cs 16 KB

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