RushSaleGiftBoxView.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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_RushSaleGiftBoxUI.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_txtLrc.text = string.Empty;
  115. _ui.m_btnBuyPink.m_loaIcon.visible = false;
  116. _ui.m_btnBuyPink.m_txtOldPrice.text = shopCfg.originalPrice.ToString();
  117. if (shopCfg.costType == CostType.ITEM)
  118. {
  119. //货币
  120. ItemCfg costCfg = ItemCfgArray.Instance.GetCfg(shopCfg.costId);
  121. mTxtNewPrice = shopCfg.price.ToString();
  122. _ui.m_btnBuyPink.m_loaIcon.visible = true;
  123. _ui.m_btnBuyPink.m_loaIcon.url = ResPathUtil.GetIconPath(costCfg);
  124. }
  125. else if (shopCfg.costType == CostType.RMB)
  126. {
  127. //人民币
  128. mTxtNewPrice = $"{shopCfg.price}元";
  129. _ui.m_btnBuyPink.m_txtNewPrice.align = AlignType.Left;
  130. _ui.m_btnBuyPink.m_txtNewPrice.x = 90;
  131. _ui.m_txtLrc.text = $"可获得{shopCfg.price * 10}充值经验";
  132. }
  133. else
  134. {
  135. //免费
  136. mTxtNewPrice = $"免费";
  137. _ui.m_btnBuyPink.m_txtOldPrice.text = "";
  138. _ui.m_btnBuyPink.m_txtNewPrice.align = AlignType.Left;
  139. _ui.m_btnBuyPink.m_txtNewPrice.x = 90;
  140. }
  141. _ui.m_txtBoxItemName.text = shopCfg.itemName;
  142. //这个B时间需要在一个地方统一处理,然后广播事件,不然可能会存在不同步的问题,最后做
  143. _ui.m_txtBoxResidueTime.text = TimeUtil.GetTimeLeft(TimeInfo.Instance.ServerNow(), data.EndTime);
  144. _ui.m_txtUrc.text = mTxtUrc;
  145. _ui.m_comDiscount.m_txtDiscountNum.text =
  146. NumberUtil.CalculateDiscount(shopCfg.originalPrice, shopCfg.price);
  147. _ui.m_btnBuyPink.m_txtNewPrice.text = mTxtNewPrice;
  148. _ui.m_btnBuyPink.target.data = shopCfg;
  149. _ui.m_list.data = boxItemCfg;
  150. _ui.m_list.itemRenderer = ListItemRender;
  151. _ui.m_list.numItems = boxItemCfg.itemsArr.Length;
  152. _ui.m_list.visible = true;
  153. }
  154. private void ListItemRender(int index, GObject obj)
  155. {
  156. UI_ComRsGifBoxIconItem uiItem = UI_ComRsGifBoxIconItem.Proxy(obj);
  157. var boxItemCfg = uiItem.target.parent.data as ItemCfg;
  158. var itemKv = boxItemCfg.itemsArr[index];
  159. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemKv[0]);
  160. uiItem.m_txtItemName.text = itemCfg.name;
  161. uiItem.m_comRewardIconItem.m_bagBlue.visible = false;
  162. uiItem.m_comRewardIconItem.m_bagBlueEx.visible = false;
  163. uiItem.m_comRewardIconItem.m_num.text = itemKv[1].ToString();
  164. uiItem.m_comRewardIconItem.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  165. }
  166. //上一条
  167. private void OnBtnPreviousClick()
  168. {
  169. UpdateView(ListUtil.NavigateType.Previous);
  170. }
  171. //下一条
  172. private void OnBtnNextClick()
  173. {
  174. UpdateView(ListUtil.NavigateType.Next);
  175. }
  176. //购买按钮点击事件
  177. private void OnBtnBuyClick(EventContext context)
  178. {
  179. GObject sender = context.sender as GObject;
  180. //GObject obj = sender.parent;
  181. ShopCfg cfg = sender.data as ShopCfg;
  182. bool isSellOut = cfg.maxBuyNum > 0 &&
  183. cfg.maxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(cfg.id) <= 0;
  184. if (isSellOut)
  185. {
  186. PromptController.Instance.ShowFloatTextPrompt("已售罄");
  187. return;
  188. }
  189. if (!ShopDataManager.Instance.GetShopGoodsStateById(cfg.id))
  190. {
  191. PromptController.Instance.ShowFloatTextPrompt(ShopDataManager.Instance.GetShopGoodsStateTips(cfg.id));
  192. return;
  193. }
  194. if (cfg.costType == CostType.FREE)
  195. {
  196. ShopSProxy.ReqShopBuy(cfg.id, 1).Coroutine();
  197. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.SHANG_CHENG, 2);
  198. }
  199. else
  200. {
  201. ViewManager.Show<ItemExchangeView>(cfg.id);
  202. }
  203. }
  204. protected override void OnHide()
  205. {
  206. this.RemoveEventListener();
  207. Dispose();
  208. base.Hide();
  209. }
  210. private void OnBtnCancelClick()
  211. {
  212. this.Hide();
  213. }
  214. }
  215. }