EnduringGiftBoxView.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  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. int rebateDay = EnduringGiftBoxDataManager.Instance.GetItemRebateDay(itemCfg.id);
  243. string mTxtLrc = string.Empty;
  244. if (rebateDay != 0)
  245. {
  246. mTxtLrc = string.Format("剩余{0}天", rebateDay);
  247. }
  248. item.m_txtLrc.text = mTxtLrc;
  249. item.m_txtWeekPrompt.visible = true;
  250. item.m_txtWeekPrompt.text =
  251. string.Format("连续{0}天每日获得",
  252. itemCfg.param2Arr[0] + 1); //NumberUtil.GetChiniseNumberText(itemCfg.param2Arr[0])
  253. item.m_icoWeekPromptTag.visible = true;
  254. numItems = childItemCfg.param1Arr.Length;
  255. //是否需要领取
  256. if (weekGiftBoxState)
  257. {
  258. item.m_btnBuy.target.visible = false;
  259. item.m_btnCurReceive.target.visible = true;
  260. item.m_btnCurReceive.m_receive.visible = true;
  261. item.m_btnCurReceive.m_received.visible = false;
  262. item.m_btnCurReceive.m_txtRec.text = "领取";
  263. }
  264. else
  265. {
  266. //是否能购买
  267. if (remainBuyNum == 0)
  268. {
  269. //已经领取
  270. if (EnduringGiftBoxDataManager.Instance.DayRebateItemIds.Contains(shopCfg.itemId))
  271. {
  272. item.m_btnBuy.target.visible = false;
  273. item.m_btnCurReceive.target.visible = true;
  274. item.m_btnCurReceive.m_receive.visible = false;
  275. item.m_btnCurReceive.m_received.visible = true;
  276. item.m_btnCurReceive.m_txtRec.text = "已领取";
  277. }
  278. else
  279. {
  280. item.m_btnCurReceive.target.visible = false;
  281. item.m_btnBuy.target.visible = true;
  282. item.m_btnBuy.m_bagGrey.visible = true;
  283. item.m_btnBuy.m_bagYellow.visible = false;
  284. }
  285. }
  286. else
  287. {
  288. //未售完
  289. item.m_btnBuy.target.visible = true;
  290. item.m_btnBuy.m_bagGrey.visible = false;
  291. item.m_btnBuy.m_bagYellow.visible = true;
  292. item.m_btnCurReceive.target.visible = false;
  293. }
  294. }
  295. }
  296. item.m_icoWeekPromptTag.onClick.Add(RuleController.ShowRuleView);
  297. item.m_icoWeekPromptTag.data = 300013;
  298. //领取按钮点击事件
  299. item.m_btnCurReceive.target.onClick.Add(OnBtnCurReceiveClick);
  300. //购买按钮点击事件
  301. item.m_btnBuy.target.onClick.Add(OnBtnBuyClick);
  302. item.m_list.data = shopCfg;
  303. item.m_list.itemRenderer = ChildListItemRender;
  304. item.m_list.numItems = numItems;
  305. }
  306. //领取按钮点击事件
  307. private void OnBtnCurReceiveClick(EventContext context)
  308. {
  309. GObject sender = context.sender as GObject;
  310. GObject obj = sender.parent;
  311. ShopCfg cfg = obj.data as ShopCfg;
  312. bool isSellOut = EnduringGiftBoxDataManager.Instance.DayIsRebateGiftBox(cfg.itemId);
  313. if (isSellOut)
  314. {
  315. EnduringGiftBoxSProxy.ReqGetGiftBagRebate(cfg.id).Coroutine();
  316. }
  317. else
  318. {
  319. PromptController.Instance.ShowFloatTextPrompt("无法领取");
  320. }
  321. }
  322. //购买按钮点击事件
  323. private void OnBtnBuyClick(EventContext context)
  324. {
  325. GObject sender = context.sender as GObject;
  326. GObject obj = sender.parent;
  327. ShopCfg cfg = obj.data as ShopCfg;
  328. bool isSellOut = cfg.maxBuyNum > 0 &&
  329. cfg.maxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(cfg.id) <= 0;
  330. if (isSellOut)
  331. {
  332. PromptController.Instance.ShowFloatTextPrompt("已售罄");
  333. return;
  334. }
  335. if (!ShopDataManager.Instance.GetShopGoodsStateById(cfg.id))
  336. {
  337. PromptController.Instance.ShowFloatTextPrompt(ShopDataManager.Instance.GetShopGoodsStateTips(cfg.id));
  338. return;
  339. }
  340. if (cfg.costType == CostType.FREE)
  341. {
  342. ShopSProxy.ReqShopBuy(cfg.id, 1).Coroutine();
  343. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.SHANG_CHENG, 2);
  344. }
  345. else
  346. {
  347. ViewManager.Show<ItemExchangeView>(cfg.id);
  348. }
  349. }
  350. private void ChildListItemRender(int index, GObject obj)
  351. {
  352. UI_ComRewardIconItem uiItemChild = UI_ComRewardIconItem.Proxy(obj);
  353. var shopCfg = uiItemChild.target.parent.data as ShopCfg;
  354. var itemCfg = ItemCfgArray.Instance.GetCfg(shopCfg.itemId);
  355. // uiItemChild.m_showRreceives.visible = false;
  356. //var curGiftBoxState = EnduringGiftBoxDataManager.GiftBoxStateDic[shopCfg.id];
  357. int[][] result;
  358. if (shopCfg.refreshType == RefreshType.DAY)
  359. {
  360. result = itemCfg.itemsArr;
  361. uiItemChild.m_bagYellow.visible = false;
  362. uiItemChild.m_bagBlue.visible = true;
  363. uiItemChild.m_bagYellowEx.visible = false;
  364. uiItemChild.m_bagBlueEx.visible = true;
  365. }
  366. else
  367. {
  368. //周刷
  369. result = itemCfg.param1Arr;
  370. uiItemChild.m_bagYellow.visible = true;
  371. uiItemChild.m_bagBlue.visible = false;
  372. uiItemChild.m_bagYellowEx.visible = true;
  373. uiItemChild.m_bagBlueEx.visible = false;
  374. }
  375. // if (curGiftBoxState == EnduringGiftBoxBuyStatus.YesGet)
  376. // {
  377. // uiItemChild.m_showRreceives.visible = true;
  378. // }
  379. // else if (curGiftBoxState == EnduringGiftBoxBuyStatus.NoGet)
  380. // {
  381. // uiItemChild.m_showRreceives.visible = false;
  382. // }
  383. var itemArr = result[index];
  384. var itemCfgChild = ItemCfgArray.Instance.GetCfg(itemArr[0]);
  385. uiItemChild.m_loaIcon.onClick.Add(OnListSelectorItemClick);
  386. uiItemChild.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfgChild);
  387. uiItemChild.m_num.text = itemArr[1].ToString();
  388. uiItemChild.target.data = itemCfgChild;
  389. UI_ComRewardIconItem.ProxyEnd();
  390. }
  391. //弹出物品详细描述框
  392. private void OnListSelectorItemClick(EventContext context)
  393. {
  394. GObject sender = context.sender as GObject;
  395. GObject obj = sender.parent;
  396. ItemCfg itemCfg = obj.data as ItemCfg;
  397. GoodsItemTipsController.ShowItemTips(itemCfg.id);
  398. }
  399. private async void OnClickBtnSure()
  400. {
  401. if (_maxTimes > 0 && (_buyTimes + _count) > _maxTimes)
  402. {
  403. PromptController.Instance.ShowFloatTextPrompt("购买次数不足");
  404. return;
  405. }
  406. ItemExchangeCfgArray.Instance.GetMoneyIdAndNum(_itemId, _buyTimes, _count, out int costId, out int coustNum,
  407. out int buyNum);
  408. Debug.Log(costId + "数量:" + ItemDataManager.GetItemNum(costId));
  409. if (ItemDataManager.GetItemNum(costId) < coustNum)
  410. {
  411. ItemCfg costCfg = ItemCfgArray.Instance.GetCfg(costId);
  412. if (_itemId == ConstItemID.DIAMOND_PURPLE)
  413. {
  414. PromptController.Instance.ShowFloatTextPrompt(string.Format("{0}不足,请前往商城选购", costCfg.name));
  415. }
  416. else
  417. {
  418. AlertUI.Show(costCfg.name + "不足,是否前往购买?").SetLeftButton(true).SetRightButton(true, "确认",
  419. (AlertWindow.AlertCallback)((object data) =>
  420. {
  421. long costNeedCount = coustNum - ItemDataManager.GetItemNum(costId);
  422. BuyItemConteoller.Show(costId, costNeedCount, ConstBuyType.TYPE_ITEM, null, true, true,
  423. GameConst.MAX_COUNT_TO_BUY_DIAMOND_RED);
  424. }));
  425. OnClickBtnCancel();
  426. }
  427. return;
  428. }
  429. bool result = await ItemExchangeSProxy.ItemExchange(_itemId, _count);
  430. if (result)
  431. {
  432. PromptController.Instance.ShowFloatTextPrompt("购买成功", MessageType.SUCCESS);
  433. if (_onSuccess != null)
  434. {
  435. _onSuccess();
  436. }
  437. }
  438. UpdateView();
  439. //this.Hide();
  440. }
  441. //购买连续礼包之后,更新数据+更新界面
  442. private void UpDayRebateAndView(EventContext context)
  443. {
  444. ShopCfg shopCfg = context.data as ShopCfg;
  445. var itemCfg = ItemCfgArray.Instance.GetCfg(shopCfg.itemId);
  446. if (itemCfg.itemType == ConstItemType.GIFT_BAG &&
  447. itemCfg.subType == ConstItemSubType.CONTINUOUS_REWARD_GIFT)
  448. {
  449. int dayNum = EnduringGiftBoxDataManager.Instance.GetItemRebateDay(itemCfg.id);
  450. int totalDayNum = dayNum + itemCfg.param2Arr[0];
  451. EnduringGiftBoxDataManager.Instance.UpDayAllRebateItemDic(itemCfg.id, totalDayNum);
  452. EnduringGiftBoxDataManager.Instance.AddDayRebateItemIds(itemCfg.id);
  453. }
  454. UpdateView();
  455. }
  456. protected override void OnHide()
  457. {
  458. this.RemoveEventListener();
  459. Dispose();
  460. base.Hide();
  461. _onSuccess = null;
  462. }
  463. private void OnClickBtnCancel()
  464. {
  465. // Dispose();
  466. this.Hide();
  467. }
  468. }
  469. }