SpecialOfferGiftBoxView.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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. //列表样式的限时礼包--3类型-列表样式:等级条件的数据
  11. public class SpecialOfferGiftBoxView : BaseWindow
  12. {
  13. private UI_SpecialOfferGiftBoxUI _ui;
  14. private int _pageIndex; //当前页码,需要显示的数据的索引
  15. private List<GGraph> _graphList = new List<GGraph>();
  16. private List<GameObject> _gameObjectList = new List<GameObject>();
  17. private List<GoWrapper> _wrapperList = new List<GoWrapper>();
  18. private GameObject _gameObject1;
  19. private GameObject _gameObject2;
  20. private GameObject _gameObject3;
  21. private GoWrapper _wrapper1;
  22. private GoWrapper _wrapper2;
  23. private GoWrapper _wrapper3;
  24. protected override void OnInit()
  25. {
  26. base.OnInit();
  27. packageName = UI_SpecialOfferGiftBoxUI.PACKAGE_NAME;
  28. _ui = UI_SpecialOfferGiftBoxUI.Create();
  29. this.viewCom = _ui.target;
  30. this.viewCom.Center();
  31. this.modal = true;
  32. viewAnimationType = EnumViewAnimationType.None;
  33. _ui.m_back.onClick.Add(OnBtnCancelClick);
  34. _ui.m_btnUp.onClick.Add(OnBtnPreviousClick);
  35. _ui.m_btnNext.onClick.Add(OnBtnNextClick);
  36. }
  37. public override void Dispose()
  38. {
  39. if (_ui != null)
  40. {
  41. _ui.Dispose();
  42. _ui = null;
  43. }
  44. base.Dispose();
  45. }
  46. protected override void OnShown()
  47. {
  48. base.OnShown();
  49. _ui.m_t0.Play();
  50. AddEffect();
  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. }
  61. protected override void RemoveEventListener()
  62. {
  63. EventAgent.RemoveEventListener(ConstMessage.ACTIVITY_REMOVE, UpViewNone);
  64. EventAgent.RemoveEventListener(ConstMessage.ACTIVITY_ADD, UpViewNone);
  65. EventAgent.RemoveEventListener(ConstMessage.SHOP_BUY, UpViewNone);
  66. base.RemoveEventListener();
  67. }
  68. private void AddEffect()
  69. {
  70. string resPath1 = ResPathUtil.GetViewEffectPath("ui_Activity", "Prefer_person");
  71. SceneController.AddObjectToView(null, null, _ui.m_holderBaby, resPath1,
  72. out _gameObject1, out _wrapper1);
  73. string resPath2 = ResPathUtil.GetViewEffectPath("ui_Activity", "Prefer_chixu_tx");
  74. SceneController.AddObjectToView(null, null, _ui.m_holderChiXuTx, resPath2,
  75. out _gameObject2, out _wrapper2);
  76. string resPath3 = ResPathUtil.GetViewEffectPath("ui_Activity", "Prefer_one_tx");
  77. SceneController.AddObjectToView(null, null, _ui.m_holderOneTx, resPath3,
  78. out _gameObject3, out _wrapper3);
  79. }
  80. public void UpTime()
  81. {
  82. //筛选一条数据用来界面渲染
  83. var list = LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData3;
  84. list = list.Where(a => a.EndTime > TimeInfo.Instance.ServerNow()).ToList();
  85. if (list.Count == 0)
  86. {
  87. PromptController.Instance.ShowFloatTextPrompt("活动已结束");
  88. this.Hide();
  89. return;
  90. }
  91. _ui.m_txtBoxResidueTime.text = TimeUtil.GetTimeLeft(TimeInfo.Instance.ServerNow(), list[0].EndTime);
  92. }
  93. //实例化索引
  94. private void InitPageInex()
  95. {
  96. _pageIndex = 0;
  97. }
  98. private void UpdateView(ListUtil.NavigateType type)
  99. {
  100. //筛选一条数据用来界面渲染
  101. var list = LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData3;
  102. list = list.Where(a => a.EndTime > TimeInfo.Instance.ServerNow()).ToList();
  103. if (list.Count == 0)
  104. {
  105. PromptController.Instance.ShowFloatTextPrompt("活动已结束");
  106. this.Hide();
  107. return;
  108. }
  109. var data = ListUtil.Navigate(list, type, _pageIndex, out int newIndex);
  110. _pageIndex = newIndex;
  111. _ui.m_btnUp.visible = true;
  112. _ui.m_btnNext.visible = true;
  113. if (list.Count == 1)
  114. {
  115. _ui.m_btnUp.visible = false;
  116. _ui.m_btnNext.visible = false;
  117. }
  118. else
  119. {
  120. //翻页翻到了最后一条数据
  121. if (list.Count == _pageIndex + 1)
  122. {
  123. _ui.m_btnNext.visible = false;
  124. }
  125. if (_pageIndex == 0)
  126. {
  127. _ui.m_btnUp.visible = false;
  128. }
  129. }
  130. _ui.m_txtBoxResidueTime.text = TimeUtil.GetTimeLeft(TimeInfo.Instance.ServerNow(), data.EndTime);
  131. _ui.m_list.data = data.ShopCfgIds;
  132. _ui.m_list.itemRenderer = ListItemRender;
  133. _ui.m_list.numItems = data.ShopCfgIds.Count;
  134. _ui.m_list.visible = true;
  135. }
  136. private void ListItemRender(int index, GObject obj)
  137. {
  138. UI_ComSpecialOfferGiftBoxItem uiItem = UI_ComSpecialOfferGiftBoxItem.Proxy(obj);
  139. var shopCfgIds = uiItem.target.parent.data as List<int>;
  140. var shopCfgId = shopCfgIds[index];
  141. var shopCfg = ShopCfgArray.Instance.GetCfg(shopCfgId);
  142. var shopItemCfg = ItemCfgArray.Instance.GetCfg(shopCfg.itemId);
  143. var remainBuyNum = shopCfg.maxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(shopCfg.id);
  144. uiItem.m_txtGetJf.text = string.Empty;
  145. string mTxtUrc = string.Empty;
  146. string mTxtNewPrice;
  147. if (shopCfg.refreshType == RefreshType.DAY)
  148. {
  149. mTxtUrc = $"每日限购{remainBuyNum}/{shopCfg.maxBuyNum}";
  150. }
  151. else if (shopCfg.refreshType == RefreshType.WEEK)
  152. {
  153. mTxtUrc = $"每周限购{remainBuyNum}/{shopCfg.maxBuyNum}";
  154. }
  155. else if (shopCfg.refreshType == RefreshType.MONTH)
  156. {
  157. mTxtUrc = $"每月限购{remainBuyNum}/{shopCfg.maxBuyNum}";
  158. }
  159. else
  160. {
  161. mTxtUrc = $"永久限购{remainBuyNum}/{shopCfg.maxBuyNum}";
  162. }
  163. uiItem.m_btnBuy.m_txtOldPrice.text = shopCfg.originalPrice.ToString();
  164. if (shopCfg.costType == CostType.ITEM)
  165. {
  166. //货币
  167. ItemCfg costCfg = ItemCfgArray.Instance.GetCfg(shopCfg.costId);
  168. mTxtNewPrice = shopCfg.price.ToString();
  169. uiItem.m_btnBuy.m_loaIcon.visible = true;
  170. uiItem.m_btnBuy.m_txtNewPrice.x = 134;
  171. uiItem.m_btnBuy.m_txtOldPrice.x = 21;
  172. uiItem.m_btnBuy.m_loaIcon.url = ResPathUtil.GetIconPath(costCfg);
  173. }
  174. else if (shopCfg.costType == CostType.RMB)
  175. {
  176. //人民币
  177. mTxtNewPrice = $"{shopCfg.price}元";
  178. uiItem.m_btnBuy.m_txtNewPrice.align = AlignType.Left;
  179. uiItem.m_btnBuy.m_txtNewPrice.x = 125;
  180. uiItem.m_btnBuy.m_txtOldPrice.x = 30;
  181. uiItem.m_txtGetJf.text = $"可获得{shopCfg.price * 10}会员积分";
  182. }
  183. else
  184. {
  185. //免费
  186. mTxtNewPrice = $"免费";
  187. uiItem.m_btnBuy.m_txtOldPrice.text = "";
  188. uiItem.m_btnBuy.m_txtNewPrice.align = AlignType.Left;
  189. uiItem.m_btnBuy.m_txtNewPrice.x = 125;
  190. uiItem.m_btnBuy.m_txtOldPrice.x = 30;
  191. }
  192. if (remainBuyNum == 0)
  193. {
  194. //已售完
  195. uiItem.m_btnBuy.m_bagGrey.visible = true;
  196. uiItem.m_btnBuy.m_txtSoldOut.text = "已售罄";
  197. uiItem.m_btnBuy.m_txtSoldOut.visible = true;
  198. uiItem.m_btnBuy.m_bagYellow.visible = false;
  199. uiItem.m_btnBuy.m_txtOldPrice.visible = false;
  200. uiItem.m_btnBuy.m_txtNewPrice.visible = false;
  201. uiItem.m_btnBuy.m_loaIcon.visible = false;
  202. uiItem.m_holderBtn.visible = false;
  203. }
  204. else
  205. {
  206. //未售完
  207. uiItem.m_btnBuy.m_txtSoldOut.text = "";
  208. uiItem.m_btnBuy.m_txtSoldOut.visible = false;
  209. uiItem.m_btnBuy.m_bagGrey.visible = false;
  210. uiItem.m_btnBuy.m_bagYellow.visible = true;
  211. uiItem.m_btnBuy.m_txtOldPrice.visible = true;
  212. uiItem.m_btnBuy.m_txtNewPrice.visible = true;
  213. uiItem.m_btnBuy.m_loaIcon.visible = true;
  214. uiItem.m_holderBtn.visible = true;
  215. }
  216. uiItem.m_comDiscount.m_txtDiscountNum.text =
  217. NumberUtil.CalculateDiscount(shopCfg.originalPrice, shopCfg.price);
  218. uiItem.target.data = shopCfg;
  219. uiItem.m_btnBuy.m_txtNewPrice.text = mTxtNewPrice;
  220. uiItem.m_txtUrc.text = mTxtUrc;
  221. uiItem.m_btnBuy.target.onClick.Add(OnBtnBuyClick);
  222. uiItem.m_txtBoxItemName.text = shopCfg.itemName;
  223. if (!_graphList.Contains(uiItem.m_holderZheKou))
  224. {
  225. string resPath = ResPathUtil.GetViewEffectPath("ui_Activity", "Prefer_but_zhekou");
  226. SceneController.AddObjectToView(null, null, uiItem.m_holderZheKou, resPath, out var gameObject,
  227. out var wrapper);
  228. _graphList.Add(uiItem.m_holderZheKou);
  229. _gameObjectList.Add(gameObject);
  230. _wrapperList.Add(wrapper);
  231. }
  232. if (!_graphList.Contains(uiItem.m_holderBtn))
  233. {
  234. string resPath = ResPathUtil.GetViewEffectPath("ui_Activity", "Prefer_button_buy");
  235. SceneController.AddObjectToView(null, null, uiItem.m_holderBtn, resPath, out var gameObject,
  236. out var wrapper);
  237. _graphList.Add(uiItem.m_holderBtn);
  238. _gameObjectList.Add(gameObject);
  239. _wrapperList.Add(wrapper);
  240. }
  241. uiItem.m_t0.Play();
  242. //子列表
  243. uiItem.m_list.itemRenderer = ChildListItemRender;
  244. uiItem.m_list.numItems = shopItemCfg.itemsArr.Length;
  245. uiItem.m_list.visible = true;
  246. }
  247. private void ChildListItemRender(int index, GObject obj)
  248. {
  249. UI_ComRewardIconItem uiItemChild = UI_ComRewardIconItem.Proxy(obj);
  250. var shopCfg = uiItemChild.target.parent.parent.data as ShopCfg;
  251. var itemCfg = ItemCfgArray.Instance.GetCfg(shopCfg.itemId);
  252. int[][] result;
  253. // if (shopCfg.refreshType == RefreshType.DAY)
  254. // {
  255. result = itemCfg.itemsArr;
  256. uiItemChild.m_bagYellow.visible = false;
  257. uiItemChild.m_bagBlue.visible = true;
  258. uiItemChild.m_bagYellowEx.visible = false;
  259. uiItemChild.m_bagBlueEx.visible = true;
  260. // }
  261. // else
  262. // {
  263. //周刷
  264. // result = itemCfg.param1Arr;
  265. // uiItemChild.m_bagYellow.visible = true;
  266. // uiItemChild.m_bagBlue.visible = false;
  267. // uiItemChild.m_bagYellowEx.visible = true;
  268. // uiItemChild.m_bagBlueEx.visible = false;
  269. // }
  270. var itemArr = result[index];
  271. var itemCfgChild = ItemCfgArray.Instance.GetCfg(itemArr[0]);
  272. uiItemChild.m_loaIcon.onClick.Add(OnListSelectorItemClick);
  273. uiItemChild.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfgChild);
  274. uiItemChild.m_num.text = itemArr[1].ToString();
  275. uiItemChild.target.data = itemCfgChild;
  276. if (!_graphList.Contains(uiItemChild.m_holderItem))
  277. {
  278. string resPath = ResPathUtil.GetViewEffectPath("ui_Activity", "Prefer_kuang");
  279. SceneController.AddObjectToView(null, null, uiItemChild.m_holderItem, resPath, out var gameObject,
  280. out var wrapper);
  281. _graphList.Add(uiItemChild.m_holderItem);
  282. _gameObjectList.Add(gameObject);
  283. _wrapperList.Add(wrapper);
  284. }
  285. uiItemChild.m_t0.Play();
  286. UI_ComRewardIconItem.ProxyEnd();
  287. }
  288. //弹出物品详细描述框
  289. private void OnListSelectorItemClick(EventContext context)
  290. {
  291. GObject sender = context.sender as GObject;
  292. GObject obj = sender.parent;
  293. ItemCfg itemCfg = obj.data as ItemCfg;
  294. GoodsItemTipsController.ShowItemTips(itemCfg.id);
  295. }
  296. private void UpViewNone()
  297. {
  298. LimitedTimeGiftBoxDataManager.Instance.UpLtgGbItemData3();
  299. UpdateView(ListUtil.NavigateType.None);
  300. }
  301. //上一条
  302. private void OnBtnPreviousClick()
  303. {
  304. UpdateView(ListUtil.NavigateType.Previous);
  305. }
  306. //下一条
  307. private void OnBtnNextClick()
  308. {
  309. UpdateView(ListUtil.NavigateType.Next);
  310. }
  311. //购买按钮点击事件
  312. private void OnBtnBuyClick(EventContext context)
  313. {
  314. GObject sender = context.sender as GObject;
  315. ShopCfg cfg = sender.parent.data as ShopCfg;
  316. bool isSellOut = cfg.maxBuyNum > 0 &&
  317. cfg.maxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(cfg.id) <= 0;
  318. if (isSellOut)
  319. {
  320. PromptController.Instance.ShowFloatTextPrompt("已售罄");
  321. return;
  322. }
  323. if (!ShopDataManager.Instance.GetShopGoodsStateById(cfg.id))
  324. {
  325. PromptController.Instance.ShowFloatTextPrompt(ShopDataManager.Instance.GetShopGoodsStateTips(cfg.id));
  326. return;
  327. }
  328. if (cfg.costType == CostType.FREE)
  329. {
  330. ShopSProxy.ReqShopBuy(cfg.id, 1).Coroutine();
  331. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.SHANG_CHENG, 2);
  332. }
  333. else
  334. {
  335. ViewManager.Show<ItemExchangeView>(cfg.id);
  336. }
  337. }
  338. private void DestroyObjectFromView()
  339. {
  340. foreach (var itemGameObject in _gameObjectList)
  341. {
  342. if (itemGameObject != null)
  343. {
  344. GameObject.DestroyImmediate(itemGameObject);
  345. }
  346. }
  347. _gameObjectList.Clear();
  348. foreach (var itemWrapper in _wrapperList)
  349. {
  350. if (itemWrapper != null)
  351. {
  352. itemWrapper.Dispose();
  353. }
  354. }
  355. _wrapperList.Clear();
  356. _graphList.Clear();
  357. }
  358. protected override void OnHide()
  359. {
  360. SceneController.DestroyObjectFromView(_gameObject1, _wrapper1);
  361. SceneController.DestroyObjectFromView(_gameObject2, _wrapper2);
  362. SceneController.DestroyObjectFromView(_gameObject3, _wrapper3);
  363. DestroyObjectFromView();
  364. this.RemoveEventListener();
  365. Dispose();
  366. base.Hide();
  367. }
  368. private void OnBtnCancelClick()
  369. {
  370. this.Hide();
  371. }
  372. }
  373. }