SpecialOfferGiftBoxView.cs 15 KB

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