EnduringGiftBoxView.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  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. public class EnduringGiftBoxView : BaseWindow
  11. {
  12. private UI_EnduringGiftBoxUI _ui;
  13. private int _itemId; //道具id,该页面目前只给:体力,金币使用
  14. private int _count; //本次购买次数
  15. private int _buyTimes = 0; //已购次数
  16. private Action _onSuccess;
  17. private int _maxTimes = 0;
  18. private string _message = "";
  19. private List<ShopCfg> _shopCfgList = new List<ShopCfg>();
  20. private GameObject _gameObject1;
  21. private GameObject _gameObject2;
  22. private GameObject _gameObject3;
  23. private GameObject _gameObject4;
  24. private GoWrapper _wrapper1;
  25. private GoWrapper _wrapper2;
  26. private GoWrapper _wrapper3;
  27. private GoWrapper _wrapper4;
  28. protected override void OnInit()
  29. {
  30. base.OnInit();
  31. packageName = UI_EnduringGiftBoxUI.PACKAGE_NAME;
  32. _ui = UI_EnduringGiftBoxUI.Create();
  33. this.viewCom = _ui.target;
  34. this.viewCom.Center();
  35. this.modal = true;
  36. viewAnimationType = EnumViewAnimationType.None;
  37. _ui.m_btnSure.onClick.Add(OnClickBtnSure);
  38. _ui.m_btnCancel.onClick.Add(OnClickBtnCancel);
  39. _ui.m_btnBack.onClick.Add(OnClickBtnCancel);
  40. }
  41. public override void Dispose()
  42. {
  43. SceneController.DestroyObjectFromView(_gameObject1, _wrapper1);
  44. SceneController.DestroyObjectFromView(_gameObject2, _wrapper2);
  45. SceneController.DestroyObjectFromView(_gameObject3, _wrapper3);
  46. SceneController.DestroyObjectFromView(_gameObject4, _wrapper4);
  47. if (_ui != null)
  48. {
  49. _ui.Dispose();
  50. _ui = null;
  51. }
  52. EnduringGiftBoxController.Dispose();
  53. base.Dispose();
  54. }
  55. protected override void OnShown()
  56. {
  57. base.OnShown();
  58. AddEffect();
  59. _ui.m_t1.Play();
  60. _ui.m_t2.Play();
  61. UpdateView();
  62. }
  63. protected override void AddEventListener()
  64. {
  65. base.AddEventListener();
  66. EventAgent.AddEventListener(ConstMessage.CONTINUOUS_REBATE_GIFT_SHOP_BUY, UpDayRebateAndView);
  67. EventAgent.AddEventListener(ConstMessage.CONTINUOUS_REBATE_GIFT, UpdateView);
  68. // EventAgent.AddEventListener(ConstMessage.SHOP_BUY, UpdateView);
  69. }
  70. protected override void RemoveEventListener()
  71. {
  72. base.RemoveEventListener();
  73. EventAgent.RemoveEventListener(ConstMessage.CONTINUOUS_REBATE_GIFT, UpdateView);
  74. EventAgent.RemoveEventListener(ConstMessage.CONTINUOUS_REBATE_GIFT_SHOP_BUY, UpdateView);
  75. }
  76. private void AddEffect()
  77. {
  78. string resPath3;
  79. if (_itemId == ConstItemID.POWER)
  80. {
  81. resPath3 = ResPathUtil.GetViewEffectPath("ui_Activity", "Activity_people02");
  82. }
  83. else
  84. {
  85. resPath3 = ResPathUtil.GetViewEffectPath("ui_Activity", "Activity_people01");
  86. }
  87. //小人
  88. SceneController.AddObjectToView(null, null, _ui.m_holderBaby, resPath3,
  89. out _gameObject3, out _wrapper3);
  90. //爆发,大泡泡
  91. string resPath1 = ResPathUtil.GetViewEffectPath("ui_Activity", "Activity_baofa");
  92. SceneController.AddObjectToView(null, null, _ui.m_holderPaoMax, resPath1,
  93. out _gameObject1, out _wrapper1);
  94. //持续的小泡泡
  95. string resPath2 = ResPathUtil.GetViewEffectPath("ui_Activity", "Activity_chixu");
  96. SceneController.AddObjectToView(null, null, _ui.m_holderPaoMin, resPath2,
  97. out _gameObject2, out _wrapper2);
  98. //爆发时候的发光
  99. string resPath4 = ResPathUtil.GetViewEffectPath("ui_Activity", "Activity_glow");
  100. SceneController.AddObjectToView(null, null, _ui.m_holderFg, resPath4,
  101. out _gameObject4, out _wrapper4);
  102. }
  103. public void SetParams(int itemId, int count, Action onSuccess, string message = "")
  104. {
  105. _itemId = itemId;
  106. _count = count;
  107. _onSuccess = onSuccess;
  108. _message = message;
  109. }
  110. private void UpdateView()
  111. {
  112. _buyTimes = ItemDataManager.GetItemExchangeTimes(_itemId);
  113. ItemExchangeCfgArray.Instance.GetMoneyIdAndNum(_itemId, _buyTimes, _count, out int costId, out int coustNum,
  114. out int buyNum);
  115. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemId);
  116. ItemCfg costCfg = ItemCfgArray.Instance.GetCfg(costId);
  117. _ui.m_txtNeed.text = string.Format("是否花费{0}{1} 购买{2}{3}", coustNum, costCfg.name, buyNum, itemCfg.name);
  118. _ui.m_txtNum.text = "";
  119. _maxTimes = ItemExchangeCfgArray.Instance.GetCfg(_itemId).maxLimit;
  120. if (_maxTimes != 0)
  121. {
  122. _ui.m_txtNum.text = string.Format("今日剩余购买次数{0}/{1}", _maxTimes - _buyTimes, _maxTimes);
  123. }
  124. if (_message != "")
  125. {
  126. _ui.m_txtNum.text = _message;
  127. }
  128. _shopCfgList.Clear();
  129. //常驻礼包
  130. if (_itemId == ConstItemID.POWER)
  131. {
  132. //体力礼包
  133. _shopCfgList = ShopCfgArray.Instance
  134. .GetCfgsBymenu1Andmenu2(ConstStoreTabId.ENDURING_GIFT_BOX, ConstStoreSubId.ENDURING_GIFT_BOX_POWER)
  135. .OrderBy(a => a.refreshType).ToList();
  136. }
  137. else
  138. {
  139. //金币礼包
  140. _shopCfgList = ShopCfgArray.Instance
  141. .GetCfgsBymenu1Andmenu2(ConstStoreTabId.ENDURING_GIFT_BOX, ConstStoreSubId.ENDURING_GIFT_BOX_GOLD)
  142. .OrderBy(a => a.refreshType).ToList();
  143. }
  144. _ui.m_txtPromptExt.text = string.Format("除了上述购买{0}的途径,我们还提供了更多的优惠礼包选择", itemCfg.name);
  145. _ui.m_list.itemRenderer = ListItemRender;
  146. _ui.m_list.numItems = _shopCfgList.Count;
  147. _ui.m_list.visible = true;
  148. }
  149. private void ListItemRender(int index, GObject obj)
  150. {
  151. ShopCfg shopCfg = _shopCfgList[index];
  152. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(shopCfg.itemId); //购买的物品-礼包
  153. UI_ComCurSupplyItem item = UI_ComCurSupplyItem.Proxy(obj);
  154. item.target.data = shopCfg;
  155. //返利包
  156. item.m_txtTitle.text = itemCfg.name;
  157. item.m_txtWeekPrompt.visible = false;
  158. item.m_icoWeekPromptTag.visible = false;
  159. if (itemCfg.param2Arr.Length != 0)
  160. {
  161. item.m_txtWeekPrompt.visible = true;
  162. item.m_icoWeekPromptTag.visible = true;
  163. item.m_txtWeekPrompt.text = string.Format("连续{0}天每日获得", itemCfg.param2Arr[0]);
  164. }
  165. int numItems;
  166. var childItemCfg = ItemCfgArray.Instance.GetCfg(shopCfg.itemId);
  167. var remainBuyNum = shopCfg.maxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(shopCfg.id);
  168. item.m_comLeftGiftBox.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  169. item.m_btnBuy.m_txtOldPrice.text = $"{shopCfg.originalPrice}";
  170. item.m_btnBuy.m_txtNewPrice.text = $"{shopCfg.price}元";
  171. item.m_comLeftGiftBox.target.data = itemCfg;
  172. item.m_comLeftGiftBox.m_loaIcon.onClick.Add(OnListSelectorItemClick);
  173. if (shopCfg.refreshType == RefreshType.DAY) //也可以换成人民币来做条件
  174. {
  175. //日刷
  176. item.m_comLeftGiftBox.m_comDiscount.target.visible = true;
  177. item.m_comLeftGiftBox.m_comDiscount.m_txtDiscountNum.text = "1.5折"; //之后再计算赋值
  178. item.m_comLeftGiftBox.m_comGouMaiGetText.target.visible = false;
  179. item.m_txtUrc.text = string.Format("今日剩余{0}/{1}", remainBuyNum, shopCfg.maxBuyNum);
  180. item.m_txtLrc.text = string.Format("可获得{0}会员积分", shopCfg.price * 10);
  181. item.m_txtWeekPrompt.visible = false;
  182. item.m_icoWeekPromptTag.visible = false;
  183. numItems = childItemCfg.itemsArr.Length;
  184. if (remainBuyNum == 0)
  185. {
  186. //已售完
  187. item.m_btnBuy.target.visible = true;
  188. item.m_btnCurReceive.target.visible = false;
  189. item.m_btnBuy.m_bagYellow.visible = false;
  190. item.m_btnBuy.m_bagGrey.visible = true;
  191. }
  192. else
  193. {
  194. //未售完
  195. item.m_btnBuy.target.visible = true;
  196. item.m_btnCurReceive.target.visible = false;
  197. item.m_btnBuy.m_bagYellow.visible = true;
  198. item.m_btnBuy.m_bagGrey.visible = false;
  199. }
  200. }
  201. else
  202. {
  203. //周刷
  204. var weekGiftBoxState = EnduringGiftBoxDataManager.Instance.DayIsRebateGiftBox(shopCfg.itemId);
  205. item.m_comLeftGiftBox.m_comDiscount.target.visible = false;
  206. item.m_comLeftGiftBox.m_comGouMaiGetText.target.visible = true;
  207. var itemArr = itemCfg.itemsArr[0];
  208. ItemCfg getItemCfg = ItemCfgArray.Instance.GetCfg(itemArr[0]); //及时获得的物品,读取第一个显示ICON
  209. item.m_comLeftGiftBox.m_comGouMaiGetText.m_loaIcon.url = ResPathUtil.GetIconPath(getItemCfg);
  210. item.m_comLeftGiftBox.m_comGouMaiGetText.m_txtGetGold.text = itemArr[1].ToString();
  211. item.m_txtUrc.text = string.Format("每周限购{0}/{1}", remainBuyNum, shopCfg.maxBuyNum);
  212. item.m_txtLrc.text = string.Format("剩余{0}天", "");
  213. item.m_txtWeekPrompt.visible = true;
  214. item.m_txtWeekPrompt.text =
  215. string.Format("连续{0}天每日获得", NumberUtil.GetChiniseNumberText(itemCfg.param2Arr[0]));
  216. item.m_icoWeekPromptTag.visible = true;
  217. numItems = childItemCfg.param1Arr.Length;
  218. //是否需要领取
  219. if (weekGiftBoxState)
  220. {
  221. item.m_btnBuy.target.visible = false;
  222. item.m_btnCurReceive.target.visible = true;
  223. item.m_btnCurReceive.m_receive.visible = true;
  224. item.m_btnCurReceive.m_received.visible = false;
  225. item.m_btnCurReceive.m_txtRec.text = "领取";
  226. }
  227. else
  228. {
  229. //是否能购买
  230. if (remainBuyNum == 0)
  231. {
  232. //已经领取
  233. if (EnduringGiftBoxDataManager.Instance.DayRebateItemIds.Contains(shopCfg.itemId))
  234. {
  235. item.m_btnBuy.target.visible = false;
  236. item.m_btnCurReceive.target.visible = true;
  237. item.m_btnCurReceive.m_receive.visible = false;
  238. item.m_btnCurReceive.m_received.visible = true;
  239. item.m_btnCurReceive.m_txtRec.text = "已领取";
  240. }
  241. else
  242. {
  243. item.m_btnCurReceive.target.visible = false;
  244. item.m_btnBuy.target.visible = true;
  245. item.m_btnBuy.m_bagGrey.visible = true;
  246. item.m_btnBuy.m_bagYellow.visible = false;
  247. }
  248. }
  249. else
  250. {
  251. //未售完
  252. item.m_btnBuy.target.visible = true;
  253. item.m_btnBuy.m_bagGrey.visible = false;
  254. item.m_btnBuy.m_bagYellow.visible = true;
  255. item.m_btnCurReceive.target.visible = false;
  256. }
  257. }
  258. }
  259. //领取按钮点击事件
  260. item.m_btnCurReceive.target.onClick.Add(OnBtnCurReceiveClick);
  261. //购买按钮点击事件
  262. item.m_btnBuy.target.onClick.Add(OnBtnBuyClick);
  263. item.m_list.data = shopCfg;
  264. item.m_list.itemRenderer = ChildListItemRender;
  265. item.m_list.numItems = numItems;
  266. }
  267. //领取按钮点击事件
  268. private void OnBtnCurReceiveClick(EventContext context)
  269. {
  270. GObject sender = context.sender as GObject;
  271. GObject obj = sender.parent;
  272. ShopCfg cfg = obj.data as ShopCfg;
  273. bool isSellOut = EnduringGiftBoxDataManager.Instance.DayIsRebateGiftBox(cfg.itemId);
  274. if (isSellOut)
  275. {
  276. EnduringGiftBoxSProxy.ReqGetGiftBagRebate(cfg.id).Coroutine();
  277. }
  278. else
  279. {
  280. PromptController.Instance.ShowFloatTextPrompt("无法领取");
  281. }
  282. }
  283. //购买按钮点击事件
  284. private void OnBtnBuyClick(EventContext context)
  285. {
  286. GObject sender = context.sender as GObject;
  287. GObject obj = sender.parent;
  288. ShopCfg cfg = obj.data as ShopCfg;
  289. bool isSellOut = cfg.maxBuyNum > 0 &&
  290. cfg.maxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(cfg.id) <= 0;
  291. if (isSellOut)
  292. {
  293. PromptController.Instance.ShowFloatTextPrompt("已售罄");
  294. return;
  295. }
  296. if (!ShopDataManager.Instance.GetShopGoodsStateById(cfg.id))
  297. {
  298. PromptController.Instance.ShowFloatTextPrompt(ShopDataManager.Instance.GetShopGoodsStateTips(cfg.id));
  299. return;
  300. }
  301. if (cfg.costType == CostType.FREE)
  302. {
  303. ShopSProxy.ReqShopBuy(cfg.id, 1).Coroutine();
  304. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.SHANG_CHENG, 2);
  305. }
  306. else
  307. {
  308. ViewManager.Show<ItemExchangeView>(cfg.id);
  309. }
  310. }
  311. private void ChildListItemRender(int index, GObject obj)
  312. {
  313. UI_ComRewardIconItem uiItemChild = UI_ComRewardIconItem.Proxy(obj);
  314. var shopCfg = uiItemChild.target.parent.data as ShopCfg;
  315. var itemCfg = ItemCfgArray.Instance.GetCfg(shopCfg.itemId);
  316. // uiItemChild.m_showRreceives.visible = false;
  317. //var curGiftBoxState = EnduringGiftBoxDataManager.GiftBoxStateDic[shopCfg.id];
  318. int[][] result;
  319. if (shopCfg.refreshType == RefreshType.DAY)
  320. {
  321. result = itemCfg.itemsArr;
  322. uiItemChild.m_bagYellow.visible = false;
  323. uiItemChild.m_bagBlue.visible = true;
  324. uiItemChild.m_bagYellowEx.visible = false;
  325. uiItemChild.m_bagBlueEx.visible = true;
  326. }
  327. else
  328. {
  329. //周刷
  330. result = itemCfg.param1Arr;
  331. uiItemChild.m_bagYellow.visible = true;
  332. uiItemChild.m_bagBlue.visible = false;
  333. uiItemChild.m_bagYellowEx.visible = true;
  334. uiItemChild.m_bagBlueEx.visible = false;
  335. }
  336. // if (curGiftBoxState == EnduringGiftBoxBuyStatus.YesGet)
  337. // {
  338. // uiItemChild.m_showRreceives.visible = true;
  339. // }
  340. // else if (curGiftBoxState == EnduringGiftBoxBuyStatus.NoGet)
  341. // {
  342. // uiItemChild.m_showRreceives.visible = false;
  343. // }
  344. var itemArr = result[index];
  345. var itemCfgChild = ItemCfgArray.Instance.GetCfg(itemArr[0]);
  346. uiItemChild.m_loaIcon.onClick.Add(OnListSelectorItemClick);
  347. uiItemChild.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfgChild);
  348. uiItemChild.m_num.text = itemArr[1].ToString();
  349. uiItemChild.target.data = itemCfgChild;
  350. UI_ComRewardIconItem.ProxyEnd();
  351. }
  352. //弹出物品详细描述框
  353. private void OnListSelectorItemClick(EventContext context)
  354. {
  355. GObject sender = context.sender as GObject;
  356. GObject obj = sender.parent;
  357. ItemCfg itemCfg = obj.data as ItemCfg;
  358. GoodsItemTipsController.ShowItemTips(itemCfg.id);
  359. }
  360. private async void OnClickBtnSure()
  361. {
  362. if (_maxTimes > 0 && (_buyTimes + _count) > _maxTimes)
  363. {
  364. PromptController.Instance.ShowFloatTextPrompt("购买次数不足");
  365. return;
  366. }
  367. ItemExchangeCfgArray.Instance.GetMoneyIdAndNum(_itemId, _buyTimes, _count, out int costId, out int coustNum,
  368. out int buyNum);
  369. Debug.Log(costId + "数量:" + ItemDataManager.GetItemNum(costId));
  370. if (ItemDataManager.GetItemNum(costId) < coustNum)
  371. {
  372. ItemCfg costCfg = ItemCfgArray.Instance.GetCfg(costId);
  373. if (_itemId == ConstItemID.DIAMOND_PURPLE)
  374. {
  375. PromptController.Instance.ShowFloatTextPrompt(string.Format("{0}不足,请前往商城选购", costCfg.name));
  376. }
  377. else
  378. {
  379. AlertUI.Show(costCfg.name + "不足,是否前往购买?").SetLeftButton(true).SetRightButton(true, "确认",
  380. (AlertWindow.AlertCallback)((object data) =>
  381. {
  382. long costNeedCount = coustNum - ItemDataManager.GetItemNum(costId);
  383. BuyItemConteoller.Show(costId, costNeedCount, ConstBuyType.TYPE_ITEM, null, true, true,
  384. GameConst.MAX_COUNT_TO_BUY_DIAMOND_RED);
  385. }));
  386. OnClickBtnCancel();
  387. }
  388. return;
  389. }
  390. bool result = await ItemExchangeSProxy.ItemExchange(_itemId, _count);
  391. if (result)
  392. {
  393. PromptController.Instance.ShowFloatTextPrompt("购买成功", MessageType.SUCCESS);
  394. if (_onSuccess != null)
  395. {
  396. _onSuccess();
  397. }
  398. }
  399. this.Hide();
  400. }
  401. private void UpDayRebateAndView(EventContext context)
  402. {
  403. ShopCfg shopCfg = context.data as ShopCfg;
  404. var itemCfg = ItemCfgArray.Instance.GetCfg(shopCfg.itemId);
  405. if (itemCfg.itemType == ConstItemType.GIFT_BAG &&
  406. itemCfg.subType == ConstItemSubType.CONTINUOUS_REWARD_GIFT)
  407. {
  408. EnduringGiftBoxDataManager.Instance.AddDayAllRebateItemIds(itemCfg.id);
  409. EnduringGiftBoxDataManager.Instance.AddDayRebateItemIds(itemCfg.id);
  410. }
  411. UpdateView();
  412. }
  413. protected override void OnHide()
  414. {
  415. Dispose();
  416. base.Hide();
  417. _onSuccess = null;
  418. }
  419. private void OnClickBtnCancel()
  420. {
  421. // Dispose();
  422. this.Hide();
  423. }
  424. }
  425. }