EnduringGiftBoxView.cs 18 KB

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