EnduringGiftBoxView.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  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. using UnityEngine;
  10. namespace GFGGame
  11. {
  12. public class EnduringGiftBoxView : BaseWindow
  13. {
  14. private UI_EnduringGiftBoxUI _ui;
  15. private int _itemId; //道具id,该页面目前只给:体力,金币使用
  16. private int _count; //本次购买次数
  17. private int _buyTimes = 0; //已购次数
  18. private int _type = 0; //0从别的地方跳转过来. 1从点击TOP菜单栏icon跳转过来
  19. private Action _onSuccess;
  20. private int _maxTimes = 0;
  21. private string _message = "";
  22. private List<ShopCfg> _shopCfgList = new List<ShopCfg>();
  23. private EffectUI _effectUI1;
  24. private EffectUI _effectUI2;
  25. private EffectUI _effectUI3;
  26. private EffectUI _effectUI4;
  27. protected override void OnInit()
  28. {
  29. base.OnInit();
  30. packageName = UI_EnduringGiftBoxUI.PACKAGE_NAME;
  31. _ui = UI_EnduringGiftBoxUI.Create();
  32. this.viewCom = _ui.target;
  33. this.viewCom.Center();
  34. this.modal = true;
  35. viewAnimationType = EnumViewAnimationType.None;
  36. _ui.m_btnSure.onClick.Add(OnClickBtnSure);
  37. _ui.m_btnCancel.onClick.Add(OnClickBtnCancel);
  38. _ui.m_btnBack.onClick.Add(OnClickBtnCancel);
  39. }
  40. public override void Dispose()
  41. {
  42. if (_ui != null)
  43. {
  44. _ui.Dispose();
  45. _ui = null;
  46. }
  47. EnduringGiftBoxController.Dispose();
  48. base.Dispose();
  49. }
  50. protected override void OnShown()
  51. {
  52. base.OnShown();
  53. AddEffect(() =>
  54. {
  55. // 确保所有特效加载完成后再播放动画
  56. if (_effectUI1 != null && _effectUI1.IsLoaded &&
  57. _effectUI2 != null && _effectUI2.IsLoaded &&
  58. _effectUI3 != null && _effectUI3.IsLoaded &&
  59. _effectUI4 != null && _effectUI4.IsLoaded)
  60. {
  61. _ui.m_t1.Play();
  62. _ui.m_t2.Play();
  63. _ui.m_t3.Play(CheckGuide);
  64. }
  65. UpdateView();
  66. });
  67. UpdateView();
  68. }
  69. protected override void AddEventListener()
  70. {
  71. base.AddEventListener();
  72. EventAgent.AddEventListener(ConstMessage.CONTINUOUS_REBATE_GIFT_SHOP_BUY, UpDayRebateAndView);
  73. EventAgent.AddEventListener(ConstMessage.CONTINUOUS_REBATE_GIFT, UpdateView);
  74. }
  75. protected override void RemoveEventListener()
  76. {
  77. EventAgent.RemoveEventListener(ConstMessage.CONTINUOUS_REBATE_GIFT_SHOP_BUY, UpDayRebateAndView);
  78. EventAgent.RemoveEventListener(ConstMessage.CONTINUOUS_REBATE_GIFT, UpdateView);
  79. base.RemoveEventListener();
  80. }
  81. private void AddEffect(Action onComplete)
  82. {
  83. int effectsToLoad = 4;
  84. int loadedCount = 0;
  85. bool hasError = false;
  86. Action effectLoaded = () =>
  87. {
  88. loadedCount++;
  89. if (loadedCount == effectsToLoad)
  90. {
  91. if (hasError)
  92. {
  93. // 处理加载失败的情况
  94. PromptController.Instance.ShowFloatTextPrompt("部分特效加载失败");
  95. }
  96. onComplete?.Invoke();
  97. }
  98. };
  99. // 小人
  100. if (_itemId == ConstItemID.POWER)
  101. {
  102. EffectUIPool.CreateEffectUI(_ui.m_holderBaby, "ui_Activity", "Activity_people02",
  103. scale: 100, onComplete: (effect) =>
  104. {
  105. if (effect != null)
  106. {
  107. _effectUI1 = effect;
  108. }
  109. else
  110. {
  111. hasError = true;
  112. }
  113. effectLoaded();
  114. });
  115. }
  116. else
  117. {
  118. EffectUIPool.CreateEffectUI(_ui.m_holderBaby, "ui_Activity", "Activity_people01",
  119. scale: 100, onComplete: (effect) =>
  120. {
  121. if (effect != null)
  122. {
  123. _effectUI1 = effect;
  124. }
  125. else
  126. {
  127. hasError = true;
  128. }
  129. effectLoaded();
  130. });
  131. }
  132. // 爆发,大泡泡
  133. EffectUIPool.CreateEffectUI(_ui.m_holderPaoMax, "ui_Activity", "Activity_baofa",
  134. scale: 100, onComplete: (effect) =>
  135. {
  136. if (effect != null)
  137. {
  138. _effectUI2 = effect;
  139. }
  140. else
  141. {
  142. hasError = true;
  143. }
  144. effectLoaded();
  145. });
  146. // 持续的小泡泡
  147. EffectUIPool.CreateEffectUI(_ui.m_holderPaoMin, "ui_Activity", "Activity_chixu",
  148. scale: 100, onComplete: (effect) =>
  149. {
  150. if (effect != null)
  151. {
  152. _effectUI3 = effect;
  153. }
  154. else
  155. {
  156. hasError = true;
  157. }
  158. effectLoaded();
  159. });
  160. // 爆发时候的发光
  161. EffectUIPool.CreateEffectUI(_ui.m_holderFg, "ui_Activity", "Activity_glow",
  162. scale: 100, onComplete: (effect) =>
  163. {
  164. if (effect != null)
  165. {
  166. _effectUI4 = effect;
  167. }
  168. else
  169. {
  170. hasError = true;
  171. }
  172. effectLoaded();
  173. });
  174. }
  175. public void SetParams(int itemId, int count, Action onSuccess, string message = "", int type = 0)
  176. {
  177. _itemId = itemId;
  178. _count = count;
  179. _onSuccess = onSuccess;
  180. _message = message;
  181. _type = type;
  182. }
  183. private void UpdateView()
  184. {
  185. _buyTimes = ItemDataManager.GetItemExchangeTimes(_itemId);
  186. ItemExchangeCfgArray.Instance.GetMoneyIdAndNum(_itemId, _buyTimes, _count, out int costId, out int coustNum,
  187. out int buyNum);
  188. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(_itemId);
  189. ItemCfg costCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(costId);
  190. _ui.m_txtNeed.text = string.Format("是否花费{0}{1} 购买{2}{3}", coustNum, costCfg.Name, buyNum, itemCfg.Name);
  191. _maxTimes = CommonDataManager.Tables.TblItemExchangeCfg.GetOrDefault(_itemId).MaxLimit;
  192. string showTxt = string.Empty;
  193. _shopCfgList.Clear();
  194. //常驻礼包
  195. if (_itemId == ConstItemID.POWER)
  196. {
  197. //体力礼包
  198. _shopCfgList = CommonDataManager.Tables.TblShopCfg.DataList
  199. .Where(a => a.Menu1 == ConstStoreTabId.ENDURING_GIFT_BOX &&
  200. a.Menu2 == ConstStoreSubId.ENDURING_GIFT_BOX_POWER).OrderBy(a => a.RefreshType)
  201. .ToList();
  202. _ui.m_txtNeed.align = AlignType.Center;
  203. int maxLimit = CommonDataManager.Tables.TblItemExchangeCfg.GetOrDefault(ConstItemID.POWER).MaxLimit;
  204. int lastBuyCount = maxLimit - ItemDataManager.GetItemExchangeTimes(ConstItemID.POWER);
  205. showTxt = string.Format("每5分钟回复1点体力\n今日剩余购买次数{0}/{1}次", lastBuyCount, maxLimit);
  206. }
  207. else
  208. {
  209. //金币礼包
  210. _shopCfgList = CommonDataManager.Tables.TblShopCfg.DataList
  211. .Where(a => a.Menu1 == ConstStoreTabId.ENDURING_GIFT_BOX &&
  212. a.Menu2 == ConstStoreSubId.ENDURING_GIFT_BOX_GOLD).OrderBy(a => a.RefreshType).ToList();
  213. _ui.m_txtNeed.align = AlignType.Right;
  214. if (_maxTimes != 0)
  215. {
  216. showTxt = string.Format("今日剩余购买次数{0}/{1}", _maxTimes - _buyTimes, _maxTimes);
  217. }
  218. }
  219. _ui.m_txtNum.text = showTxt;
  220. _ui.m_txtPromptExt.text = string.Format("除了上述购买{0}的途径,我们还提供了更多的优惠礼包选择", itemCfg.Name);
  221. _ui.m_list.itemRenderer = ListItemRender;
  222. _ui.m_list.numItems = _shopCfgList.Count;
  223. _ui.m_list.visible = true;
  224. }
  225. // ReSharper disable Unity.PerformanceAnalysis
  226. private void ListItemRender(int index, GObject obj)
  227. {
  228. ShopCfg shopCfg = _shopCfgList[index];
  229. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(shopCfg.ItemId); //购买的物品-礼包
  230. UI_ComCurSupplyItem item = UI_ComCurSupplyItem.Proxy(obj);
  231. item.target.data = shopCfg;
  232. //返利包
  233. item.m_txtTitle.text = itemCfg.Name;
  234. item.m_txtWeekPrompt.visible = false;
  235. item.m_btnIcoWeekPromptTag.visible = false;
  236. if (itemCfg.Param2.Count != 0)
  237. {
  238. item.m_txtWeekPrompt.visible = true;
  239. item.m_btnIcoWeekPromptTag.visible = true;
  240. item.m_txtWeekPrompt.text = string.Format("连续{0}天每日获得", itemCfg.Param2[0]);
  241. }
  242. int numItems;
  243. var childItemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(shopCfg.ItemId);
  244. var remainBuyNum = shopCfg.MaxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(shopCfg.Id);
  245. item.m_comLeftGiftBox.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  246. item.m_btnBuy.m_txtOldPrice.text = $"{shopCfg.OriginalPrice}";
  247. item.m_btnBuy.m_loaIcon.visible = false;
  248. string mTxtOldPrice = string.Empty;
  249. if (shopCfg.CostTypeReal == CostType.ITEM)
  250. {
  251. //货币
  252. ItemCfg costCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(shopCfg.CostIdReal);
  253. item.m_btnBuy.m_loaIcon.visible = true;
  254. item.m_btnBuy.m_loaIcon.url = ResPathUtil.GetIconPath(costCfg);
  255. }
  256. else if (shopCfg.CostTypeReal == CostType.RMB)
  257. {
  258. //人民币
  259. mTxtOldPrice = "元";
  260. }
  261. else
  262. {
  263. //免费
  264. mTxtOldPrice = $"免费";
  265. item.m_btnBuy.m_txtOldPrice.text = "";
  266. item.m_btnBuy.m_txtNewPrice.align = AlignType.Left;
  267. item.m_btnBuy.m_txtNewPrice.x = 90;
  268. }
  269. item.m_btnBuy.m_txtNewPrice.text = $"{shopCfg.Price + mTxtOldPrice}";
  270. item.m_comLeftGiftBox.target.data = itemCfg;
  271. item.m_comLeftGiftBox.target.onClick.Add(OnListSelectorItemClick);
  272. if (shopCfg.OriginalPrice != shopCfg.Price)
  273. {
  274. var roundedNumStr = NumberUtil.CalculateDiscount(shopCfg.OriginalPrice, shopCfg.Price);
  275. item.m_comLeftGiftBox.m_comDiscount.target.visible = true;
  276. item.m_comLeftGiftBox.m_comDiscount.m_txtDiscountNum.text = $"{roundedNumStr}折"; //之后再计算赋值
  277. }
  278. else
  279. {
  280. item.m_comLeftGiftBox.m_comDiscount.target.visible = false;
  281. }
  282. if (shopCfg.RefreshType == RefreshType.DAY) //也可以换成人民币来做条件
  283. {
  284. //日刷
  285. item.m_comLeftGiftBox.m_comGouMaiGetText.target.visible = false;
  286. item.m_txtUrc.text = string.Format("今日剩余{0}/{1}", remainBuyNum, shopCfg.MaxBuyNum);
  287. item.m_txtLrc.text = string.Format("可获得{0}会员积分", shopCfg.Price * 10);
  288. item.m_txtWeekPrompt.visible = false;
  289. item.m_btnIcoWeekPromptTag.visible = false;
  290. numItems = childItemCfg.Items.Count;
  291. if (remainBuyNum == 0)
  292. {
  293. //已售完
  294. item.m_btnBuy.target.visible = true;
  295. item.m_btnCurReceive.target.visible = false;
  296. item.m_btnBuy.m_bagYellow.visible = false;
  297. item.m_btnBuy.m_bagGrey.visible = true;
  298. }
  299. else
  300. {
  301. //未售完
  302. item.m_btnBuy.target.visible = true;
  303. item.m_btnCurReceive.target.visible = false;
  304. item.m_btnBuy.m_bagYellow.visible = true;
  305. item.m_btnBuy.m_bagGrey.visible = false;
  306. }
  307. }
  308. else
  309. {
  310. //周刷
  311. var weekGiftBoxState = EnduringGiftBoxDataManager.Instance.DayIsRebateGiftBox(shopCfg.ItemId);
  312. item.m_comLeftGiftBox.m_comGouMaiGetText.target.visible = true;
  313. var itemArr = itemCfg.Items[0];
  314. ItemCfg getItemCfg =
  315. CommonDataManager.Tables.TblItemCfg.GetOrDefault(itemArr.ItemId); //及时获得的物品,读取第一个显示ICON
  316. item.m_comLeftGiftBox.m_comGouMaiGetText.m_loaIcon.url = ResPathUtil.GetIconPath(getItemCfg);
  317. item.m_comLeftGiftBox.m_comGouMaiGetText.m_txtGetGold.text = itemArr.Count.ToString();
  318. item.m_txtUrc.text = string.Format("每周限购{0}/{1}", remainBuyNum, shopCfg.MaxBuyNum);
  319. int rebateDay = EnduringGiftBoxDataManager.Instance.GetItemRebateDay(itemCfg.Id);
  320. string mTxtLrc = string.Empty;
  321. if (rebateDay != 0)
  322. {
  323. mTxtLrc = string.Format("剩余{0}天", rebateDay);
  324. }
  325. item.m_txtLrc.text = mTxtLrc;
  326. item.m_txtWeekPrompt.visible = true;
  327. item.m_txtWeekPrompt.text =
  328. string.Format("连续{0}天每日获得",
  329. itemCfg.Param2[0] + 1); //NumberUtil.GetChiniseNumberText(itemCfg.param2Arr[0])
  330. item.m_btnIcoWeekPromptTag.visible = true;
  331. numItems = childItemCfg.Param1.Count;
  332. //领取加红点
  333. RedDotController.Instance.SetComRedDot(item.m_btnCurReceive.target, weekGiftBoxState);
  334. //是否需要领取
  335. if (weekGiftBoxState)
  336. {
  337. item.m_btnBuy.target.visible = false;
  338. item.m_btnCurReceive.target.visible = true;
  339. item.m_btnCurReceive.m_receive.visible = true;
  340. item.m_btnCurReceive.m_received.visible = false;
  341. item.m_btnCurReceive.m_txtRec.text = "领取";
  342. }
  343. else
  344. {
  345. //是否能购买
  346. if (remainBuyNum == 0)
  347. {
  348. //已经领取
  349. if (EnduringGiftBoxDataManager.Instance.DayRebateItemIds.Contains(shopCfg.ItemId))
  350. {
  351. item.m_btnBuy.target.visible = false;
  352. item.m_btnCurReceive.target.visible = true;
  353. item.m_btnCurReceive.m_receive.visible = false;
  354. item.m_btnCurReceive.m_received.visible = true;
  355. item.m_btnCurReceive.m_txtRec.text = "已领取";
  356. }
  357. else
  358. {
  359. item.m_btnCurReceive.target.visible = false;
  360. item.m_btnBuy.target.visible = true;
  361. item.m_btnBuy.m_bagGrey.visible = true;
  362. item.m_btnBuy.m_bagYellow.visible = false;
  363. }
  364. }
  365. else
  366. {
  367. //未售完
  368. item.m_btnBuy.target.visible = true;
  369. item.m_btnBuy.m_bagGrey.visible = false;
  370. item.m_btnBuy.m_bagYellow.visible = true;
  371. item.m_btnCurReceive.target.visible = false;
  372. }
  373. }
  374. }
  375. item.m_btnIcoWeekPromptTag.onClick.Add(RuleController.ShowRuleView);
  376. item.m_btnIcoWeekPromptTag.data = 300013;
  377. //领取按钮点击事件
  378. item.m_btnCurReceive.target.onClick.Add(OnBtnCurReceiveClick);
  379. //购买按钮点击事件
  380. item.m_btnBuy.target.onClick.Add(OnBtnBuyClick);
  381. item.m_list.data = shopCfg;
  382. item.m_list.itemRenderer = ChildListItemRender;
  383. //item.m_list.onClickItem.Add(OnListSelectorItemClick);
  384. item.m_list.numItems = numItems;
  385. UI_ComCurSupplyItem.ProxyEnd();
  386. }
  387. //领取按钮点击事件
  388. // ReSharper disable Unity.PerformanceAnalysis
  389. private void OnBtnCurReceiveClick(EventContext context)
  390. {
  391. GObject sender = context.sender as GObject;
  392. GObject obj = sender.parent;
  393. ShopCfg cfg = obj.data as ShopCfg;
  394. bool isSellOut = EnduringGiftBoxDataManager.Instance.DayIsRebateGiftBox(cfg.ItemId);
  395. if (isSellOut)
  396. {
  397. EnduringGiftBoxSProxy.ReqGetGiftBagRebate(cfg.Id).Coroutine();
  398. }
  399. else
  400. {
  401. PromptController.Instance.ShowFloatTextPrompt("无法领取");
  402. }
  403. }
  404. //购买按钮点击事件
  405. // ReSharper disable Unity.PerformanceAnalysis
  406. private void OnBtnBuyClick(EventContext context)
  407. {
  408. if (_itemId == ConstItemID.POWER && GuideDataManager.IsGuideFinish(ConstGuideId.BUY_POWER) <= 0)
  409. {
  410. GuideController.TryCompleteGuideIndex(ConstGuideId.BUY_POWER, 1);
  411. GuideController.TryCompleteGuide(ConstGuideId.BUY_POWER, 1);
  412. }
  413. GObject sender = context.sender as GObject;
  414. GObject obj = sender.parent;
  415. ShopCfg cfg = obj.data as ShopCfg;
  416. bool isSellOut = cfg.MaxBuyNum > 0 &&
  417. cfg.MaxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(cfg.Id) <= 0;
  418. if (isSellOut)
  419. {
  420. PromptController.Instance.ShowFloatTextPrompt("已售罄");
  421. return;
  422. }
  423. if (!ShopDataManager.Instance.GetShopGoodsStateById(cfg.Id))
  424. {
  425. PromptController.Instance.ShowFloatTextPrompt(ShopDataManager.Instance.GetShopGoodsStateTips(cfg.Id));
  426. return;
  427. }
  428. if (cfg.CostTypeReal == CostType.FREE)
  429. {
  430. ShopSProxy.ReqShopBuy(cfg.Id, 1).Coroutine();
  431. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.SHANG_CHENG, 2);
  432. }
  433. else
  434. {
  435. ViewManager.Show<ItemExchangeView>(cfg.Id);
  436. }
  437. }
  438. // ReSharper disable Unity.PerformanceAnalysis
  439. private void ChildListItemRender(int index, GObject obj)
  440. {
  441. UI_ComItem uiItemChild = UI_ComItem.Proxy(obj);
  442. var shopCfg = uiItemChild.target.parent.data as ShopCfg;
  443. var itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(shopCfg.ItemId);
  444. // uiItemChild.m_showRreceives.visible = false;
  445. //var curGiftBoxState = EnduringGiftBoxDataManager.GiftBoxStateDic[shopCfg.id];
  446. List<ItemParamProto> result;
  447. if (shopCfg.RefreshType == RefreshType.DAY)
  448. {
  449. result = itemCfg.Items.ToGfgGameItemParam();
  450. // uiItemChild.m_bagYellow.visible = false;
  451. // uiItemChild.m_bagBlue.visible = true;
  452. // uiItemChild.m_bagYellowEx.visible = false;
  453. // uiItemChild.m_bagBlueEx.visible = true;
  454. }
  455. else
  456. {
  457. //周刷
  458. result = itemCfg.Param1.ToGfgGameItemParam();
  459. // uiItemChild.m_bagYellow.visible = true;
  460. // uiItemChild.m_bagBlue.visible = false;
  461. // uiItemChild.m_bagYellowEx.visible = true;
  462. // uiItemChild.m_bagBlueEx.visible = false;
  463. }
  464. // if (curGiftBoxState == EnduringGiftBoxBuyStatus.YesGet)
  465. // {
  466. // uiItemChild.m_showRreceives.visible = true;
  467. // }
  468. // else if (curGiftBoxState == EnduringGiftBoxBuyStatus.NoGet)
  469. // {
  470. // uiItemChild.m_showRreceives.visible = false;
  471. // }
  472. var itemArr = result[index];
  473. var itemCfgChild = CommonDataManager.Tables.TblItemCfg.GetOrDefault(itemArr.ItemId);
  474. uiItemChild.target.data = itemCfgChild;
  475. uiItemChild.target.onClick.Add(OnListSelectorItemClick);
  476. uiItemChild.m_txtCount.text = itemArr.Count.ToString();
  477. uiItemChild.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfgChild);
  478. uiItemChild.m_QualityType.selectedIndex = itemCfgChild.Rarity - 1;
  479. UI_ComItem.ProxyEnd();
  480. }
  481. //弹出物品详细描述框
  482. private void OnListSelectorItemClick(EventContext context)
  483. {
  484. GObject item = context.sender as GObject;
  485. ItemCfg itemCfg = item.data as ItemCfg;
  486. GoodsItemTipsController.ShowItemTips(itemCfg.Id);
  487. }
  488. // ReSharper disable Unity.PerformanceAnalysis
  489. // ReSharper disable Unity.PerformanceAnalysis
  490. private async void OnClickBtnSure()
  491. {
  492. if (_maxTimes > 0 && (_buyTimes + _count) > _maxTimes)
  493. {
  494. PromptController.Instance.ShowFloatTextPrompt("购买次数不足");
  495. return;
  496. }
  497. ItemExchangeCfgArray.Instance.GetMoneyIdAndNum(_itemId, _buyTimes, _count, out int costId, out int coustNum,
  498. out int buyNum);
  499. Debug.Log(costId + "数量:" + ItemDataManager.GetItemNum(costId));
  500. if (ItemDataManager.GetItemNum(costId) < coustNum)
  501. {
  502. ItemCfg costCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(costId);
  503. if (_itemId == ConstItemID.DIAMOND_PURPLE)
  504. {
  505. PromptController.Instance.ShowFloatTextPrompt(string.Format("{0}不足,请前往商城选购", costCfg.Name));
  506. }
  507. else
  508. {
  509. AlertUI.Show(costCfg.Name + "不足,是否前往购买?").SetLeftButton(true).SetRightButton(true, "确认",
  510. (AlertWindow.AlertCallback)((object data) =>
  511. {
  512. long costNeedCount = coustNum - ItemDataManager.GetItemNum(costId);
  513. BuyItemConteoller.Show(costId, costNeedCount, ConstBuyType.TYPE_ITEM, null, true, true,
  514. GameConst.MAX_COUNT_TO_BUY_DIAMOND_RED);
  515. }));
  516. OnClickBtnCancel();
  517. }
  518. return;
  519. }
  520. bool result = await ItemExchangeSProxy.ItemExchange(_itemId, _count);
  521. if (result)
  522. {
  523. PromptController.Instance.ShowFloatTextPrompt("购买成功", MessageType.SUCCESS);
  524. if (_onSuccess != null)
  525. {
  526. _onSuccess();
  527. }
  528. }
  529. UpdateView();
  530. //判断一下是不是从主要界面进来的
  531. if (_type == 0)
  532. {
  533. this.Hide();
  534. }
  535. }
  536. //购买连续礼包之后,更新数据+更新界面
  537. // ReSharper disable Unity.PerformanceAnalysis
  538. private void UpDayRebateAndView(EventContext context)
  539. {
  540. ShopCfg shopCfg = context.data as ShopCfg;
  541. var itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(shopCfg.ItemId);
  542. if (itemCfg.ItemType == ConstItemType.USEABLE &&
  543. itemCfg.FunType == ConstItemFuncType.CONTINUOUS_REWARD_GIFT)
  544. {
  545. int dayNum = EnduringGiftBoxDataManager.Instance.GetItemRebateDay(itemCfg.Id);
  546. int totalDayNum = dayNum + itemCfg.Param2[0];
  547. EnduringGiftBoxDataManager.Instance.UpDayAllRebateItemDic(itemCfg.Id, totalDayNum);
  548. EnduringGiftBoxDataManager.Instance.AddDayRebateItemIds(itemCfg.Id);
  549. }
  550. UpdateView();
  551. }
  552. protected override void OnHide()
  553. {
  554. EffectUIPool.Recycle(_effectUI1);
  555. _effectUI1 = null;
  556. EffectUIPool.Recycle(_effectUI2);
  557. _effectUI2 = null;
  558. EffectUIPool.Recycle(_effectUI3);
  559. _effectUI3 = null;
  560. EffectUIPool.Recycle(_effectUI4);
  561. _effectUI4 = null;
  562. this.RemoveEventListener();
  563. base.Hide();
  564. _onSuccess = null;
  565. Timers.inst.Remove(CheckGuide);
  566. }
  567. private void OnClickBtnCancel()
  568. {
  569. // Dispose();
  570. this.Hide();
  571. }
  572. private void CheckGuide()
  573. {
  574. Timers.inst.AddUpdate(CheckGuide);
  575. }
  576. private void CheckGuide(object param)
  577. {
  578. if (GuideDataManager.IsGuideFinish(ConstGuideId.BUY_POWER) <= 0)
  579. {
  580. UpdateToCheckGuide(null);
  581. }
  582. else
  583. {
  584. Timers.inst.Remove(CheckGuide);
  585. }
  586. }
  587. protected override void UpdateToCheckGuide(object param)
  588. {
  589. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  590. if (_itemId == ConstItemID.POWER)
  591. {
  592. GuideController.TryGuide(_ui.m_list.GetChildAt(1).asCom.GetChild("btnCurReceive").asButton,
  593. ConstGuideId.BUY_POWER, 1, "这里可以购买体力超值返利包,每天都能领体力哦~");
  594. }
  595. }
  596. }
  597. }