EnduringGiftBoxView.cs 21 KB

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