RushSaleGiftBoxView.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. protected override void OnInit()
  19. {
  20. base.OnInit();
  21. packageName = UI_EnduringGiftBoxUI.PACKAGE_NAME;
  22. _ui = UI_RushSaleGiftBoxUI.Create();
  23. this.viewCom = _ui.target;
  24. this.viewCom.Center();
  25. this.modal = true;
  26. viewAnimationType = EnumViewAnimationType.None;
  27. _ui.m_btnUp.onClick.Add(OnBtnPreviousClick);
  28. _ui.m_btnNext.onClick.Add(OnBtnNextClick);
  29. _ui.m_btnBack.onClick.Add(OnBtnCancelClick);
  30. _ui.m_btnBuyPink.target.onClick.Add(OnBtnBuyClick);
  31. }
  32. public override void Dispose()
  33. {
  34. if (_ui != null)
  35. {
  36. _ui.Dispose();
  37. _ui = null;
  38. }
  39. base.Dispose();
  40. }
  41. protected override void OnShown()
  42. {
  43. base.OnShown();
  44. AddEffect();
  45. InitPageInex();
  46. UpdateView(ListUtil.NavigateType.None);
  47. }
  48. protected override void AddEventListener()
  49. {
  50. base.AddEventListener();
  51. }
  52. protected override void RemoveEventListener()
  53. {
  54. base.RemoveEventListener();
  55. }
  56. private void AddEffect()
  57. {
  58. }
  59. //实例化索引
  60. private void InitPageInex()
  61. {
  62. if (_type == ConstActivityType.ActLimitGiftYxByLevel)
  63. {
  64. //4
  65. var data4 = LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData4
  66. .FirstOrDefault(a => a.IndexType == 1);
  67. _pageIndex = data4 == null ? 0 : LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData4.IndexOf(data4);
  68. }
  69. else if (_type == ConstActivityType.ActLimitGiftYxByTime)
  70. {
  71. //5
  72. var data5 = LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData5
  73. .FirstOrDefault(a => a.IndexType == 1);
  74. _pageIndex = data5 == null ? 0 : LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData4.IndexOf(data5);
  75. }
  76. }
  77. private void UpdateView(ListUtil.NavigateType type)
  78. {
  79. //筛选一条数据用来界面渲染
  80. var list = _type == ConstActivityType.ActLimitGiftYxByLevel
  81. ? LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData4
  82. : LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData5;
  83. var data = ListUtil.Navigate(list, type, _pageIndex, out int newIndex);
  84. _pageIndex = newIndex;
  85. var shopCfg = ShopCfgArray.Instance.GetCfg(data.ShopCfgId);
  86. var boxItemCfg = ItemCfgArray.Instance.GetCfg(shopCfg.itemId);
  87. var remainBuyNum = shopCfg.maxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(shopCfg.id);
  88. string mTxtUrc = string.Empty;
  89. if (shopCfg.refreshType == RefreshType.DAY)
  90. {
  91. mTxtUrc = $"今日限购{remainBuyNum}/{shopCfg.maxBuyNum}";
  92. }
  93. else if (shopCfg.refreshType == RefreshType.WEEK)
  94. {
  95. mTxtUrc = $"本周限购{remainBuyNum}/{shopCfg.maxBuyNum}";
  96. }
  97. else if (shopCfg.refreshType == RefreshType.MONTH)
  98. {
  99. mTxtUrc = $"本月限购{remainBuyNum}/{shopCfg.maxBuyNum}";
  100. }
  101. if (remainBuyNum == 0)
  102. {
  103. //已售完
  104. _ui.m_btnBuyPink.m_bagGrey.visible = true;
  105. _ui.m_btnBuyPink.m_bagPink.visible = false;
  106. }
  107. else
  108. {
  109. //未售完
  110. _ui.m_btnBuyPink.m_bagGrey.visible = false;
  111. _ui.m_btnBuyPink.m_bagPink.visible = true;
  112. }
  113. string mTxtNewPrice;
  114. _ui.m_btnBuyPink.m_loaIcon.visible = false;
  115. _ui.m_btnBuyPink.m_txtOldPrice.text = shopCfg.originalPrice.ToString();
  116. if (shopCfg.costType == CostType.ITEM)
  117. {
  118. //货币
  119. ItemCfg costCfg = ItemCfgArray.Instance.GetCfg(shopCfg.costId);
  120. mTxtNewPrice = shopCfg.price.ToString();
  121. _ui.m_btnBuyPink.m_loaIcon.visible = true;
  122. _ui.m_btnBuyPink.m_loaIcon.url = ResPathUtil.GetIconPath(costCfg);
  123. }
  124. else if (shopCfg.costType == CostType.RMB)
  125. {
  126. //人民币
  127. mTxtNewPrice = $"{shopCfg.price}元";
  128. _ui.m_btnBuyPink.m_txtNewPrice.align = AlignType.Left;
  129. _ui.m_btnBuyPink.m_txtNewPrice.x = 90;
  130. }
  131. else
  132. {
  133. //免费
  134. mTxtNewPrice = $"免费";
  135. _ui.m_btnBuyPink.m_txtOldPrice.text = "";
  136. _ui.m_btnBuyPink.m_txtNewPrice.align = AlignType.Left;
  137. _ui.m_btnBuyPink.m_txtNewPrice.x = 90;
  138. }
  139. _ui.m_txtBoxItemName.text = shopCfg.itemName;
  140. //这个B时间需要在一个地方统一处理,然后广播事件,不然可能会存在不同步的问题,最后做
  141. _ui.m_txtBoxResidueTime.text = TimeUtil.GetTimeLeft(TimeInfo.Instance.ServerNow(), data.EndTime);
  142. _ui.m_txtUrc.text = mTxtUrc;
  143. _ui.m_comDiscount.m_txtDiscountNum.text =
  144. NumberUtil.CalculateDiscount(shopCfg.originalPrice, shopCfg.price);
  145. _ui.m_txtLrc.text = $"可获得{shopCfg.price * 10}充值经验";
  146. _ui.m_btnBuyPink.m_txtNewPrice.text = mTxtNewPrice;
  147. _ui.m_btnBuyPink.target.data = shopCfg;
  148. _ui.m_list.data = boxItemCfg;
  149. _ui.m_list.itemRenderer = ListItemRender;
  150. _ui.m_list.numItems = boxItemCfg.itemsArr.Length;
  151. _ui.m_list.visible = true;
  152. }
  153. private void ListItemRender(int index, GObject obj)
  154. {
  155. UI_ComRsGifBoxIconItem uiItem = UI_ComRsGifBoxIconItem.Proxy(obj);
  156. var boxItemCfg = uiItem.target.parent.data as ItemCfg;
  157. var itemKv = boxItemCfg.itemsArr[index];
  158. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemKv[0]);
  159. uiItem.m_txtItemName.text = itemCfg.name;
  160. uiItem.m_comRewardIconItem.m_bagBlue.visible = false;
  161. uiItem.m_comRewardIconItem.m_bagBlueEx.visible = false;
  162. uiItem.m_comRewardIconItem.m_num.text = itemKv[1].ToString();
  163. uiItem.m_comRewardIconItem.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  164. }
  165. //上一条
  166. private void OnBtnPreviousClick()
  167. {
  168. UpdateView(ListUtil.NavigateType.Previous);
  169. }
  170. //下一条
  171. private void OnBtnNextClick()
  172. {
  173. UpdateView(ListUtil.NavigateType.Next);
  174. }
  175. //购买按钮点击事件
  176. private void OnBtnBuyClick(EventContext context)
  177. {
  178. GObject sender = context.sender as GObject;
  179. //GObject obj = sender.parent;
  180. ShopCfg cfg = sender.data as ShopCfg;
  181. bool isSellOut = cfg.maxBuyNum > 0 &&
  182. cfg.maxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(cfg.id) <= 0;
  183. if (isSellOut)
  184. {
  185. PromptController.Instance.ShowFloatTextPrompt("已售罄");
  186. return;
  187. }
  188. if (!ShopDataManager.Instance.GetShopGoodsStateById(cfg.id))
  189. {
  190. PromptController.Instance.ShowFloatTextPrompt(ShopDataManager.Instance.GetShopGoodsStateTips(cfg.id));
  191. return;
  192. }
  193. if (cfg.costType == CostType.FREE)
  194. {
  195. ShopSProxy.ReqShopBuy(cfg.id, 1).Coroutine();
  196. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.SHANG_CHENG, 2);
  197. }
  198. else
  199. {
  200. ViewManager.Show<ItemExchangeView>(cfg.id);
  201. }
  202. }
  203. protected override void OnHide()
  204. {
  205. this.RemoveEventListener();
  206. Dispose();
  207. base.Hide();
  208. }
  209. private void OnBtnCancelClick()
  210. {
  211. this.Hide();
  212. }
  213. }
  214. }