EnduringGiftBoxView.cs 17 KB

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