LuckyBoxView.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. using FairyGUI;
  2. using UI.LuckyBox;
  3. using UI.CommonGame;
  4. using System;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using ET;
  8. using System.Linq;
  9. namespace GFGGame
  10. {
  11. public class LuckyBoxView : BaseView
  12. {
  13. private UI_LuckyBoxUI _ui;
  14. private ValueBarController _valueBarController;
  15. private Dictionary<int, LuckyBoxController> _lcukyBoxCtrl = new Dictionary<int, LuckyBoxController>();
  16. private EffectUI _effectUI1;
  17. private EffectUI _effectUI2;
  18. private DressUpObjUI _dressUpObjUIXiHe;
  19. private DressUpObjUI _dressUpObjUIChangXi;
  20. private bool isActiveBoxOpen = false;
  21. private int _activeBoxId = 0;
  22. private int _curIndex = 0;
  23. public override void Dispose()
  24. {
  25. if (_valueBarController != null)
  26. {
  27. _valueBarController.Dispose();
  28. _valueBarController = null;
  29. }
  30. foreach (int key in _lcukyBoxCtrl.Keys)
  31. {
  32. _lcukyBoxCtrl[key].Dispose();
  33. }
  34. _lcukyBoxCtrl.Clear();
  35. if (_dressUpObjUIXiHe != null)
  36. {
  37. _dressUpObjUIXiHe.Dispose();
  38. _dressUpObjUIXiHe = null;
  39. }
  40. if (_dressUpObjUIChangXi != null)
  41. {
  42. _dressUpObjUIChangXi.Dispose();
  43. _dressUpObjUIChangXi = null;
  44. }
  45. EffectUIPool.Recycle(_effectUI1);
  46. _effectUI1 = null;
  47. EffectUIPool.Recycle(_effectUI2);
  48. _effectUI2 = null;
  49. if (_ui != null)
  50. {
  51. _ui.Dispose();
  52. _ui = null;
  53. }
  54. base.Dispose();
  55. }
  56. protected override void OnInit()
  57. {
  58. base.OnInit();
  59. packageName = UI_LuckyBoxUI.PACKAGE_NAME;
  60. _ui = UI_LuckyBoxUI.Create();
  61. this.viewCom = _ui.target;
  62. isfullScreen = true;
  63. _dressUpObjUIXiHe = new DressUpObjUI("SceneDressUp");
  64. _dressUpObjUIChangXi = new DressUpObjUI("SceneDressUp");
  65. // _ui.m_txtRemainTimes.visible = false;
  66. _valueBarController = new ValueBarController(_ui.m_valueBar);
  67. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  68. // _ui.m_btnHome.onClick.Add(OnClickBtnHome);
  69. _ui.m_btnLeft.onClick.Add(OnBtnLeftClick);
  70. _ui.m_btnRight.onClick.Add(OnBtnRightClick);
  71. // _ui.m_listBg.SetVirtual();
  72. _ui.m_listBg.itemRenderer = RenderListBgItem;
  73. // _ui.m_listBg.itemProvider = GetListItemResource;
  74. _ui.m_listBg.scrollPane.onScrollEnd.Add(OnListBgScroll);
  75. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("zx_bg");
  76. }
  77. protected override void AddEventListener()
  78. {
  79. base.AddEventListener();
  80. EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateListItemData);
  81. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateListItemData);
  82. EventAgent.AddEventListener(ConstMessage.LUCKY_BOX_FREE_TIME_CHANGED, UpdateFreeInfo);
  83. EventAgent.AddEventListener(ConstMessage.LUCKY_BOX_ACTIVITY_REWARD, UpdateBtnReward);
  84. }
  85. protected override void OnShown()
  86. {
  87. base.OnShown();
  88. Debug.Log("OnShown:LuckyBoxView");
  89. LuckyBoxDataManager.Instance.luckyBoxIds.Clear();
  90. LuckyBoxDataManager.Instance.luckyBoxIds.Add(LuckyBoxDataManager.BOX_ID_2);
  91. LuckyBoxDataManager.Instance.luckyBoxIds.Add(LuckyBoxDataManager.BOX_ID_3);
  92. _activeBoxId = 0;
  93. int activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitTsy);
  94. if (activityId > 0)
  95. GetWishingPoolInfo(activityId);
  96. if (LuckyBoxDataManager.Instance.RotatingId > 0)
  97. {
  98. RotatingLuckyBoxCfg rotatingLuckyBox = RotatingLuckyBoxCfgArray.Instance.GetCfg(LuckyBoxDataManager.Instance.RotatingId);
  99. _activeBoxId = rotatingLuckyBox.luckyBoxId;
  100. LuckyBoxDataManager.Instance.endTime = TimeUtil.GetTimestamp(rotatingLuckyBox.endTime);
  101. LuckyBoxDataManager.Instance.luckyBoxIds.Insert(0, _activeBoxId);
  102. }
  103. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[1];
  104. if (this.viewData != null)
  105. {
  106. boxId = (int)this.viewData;
  107. }
  108. if (GuideDataManager.IsGuideFinish(ConstGuideId.LUCKY_BOX) <= 0) boxId = LuckyBoxDataManager.BOX_ID_2;
  109. LuckyBoxDataManager.Instance.currentBoxId = boxId;
  110. if (_activeBoxId > 0 || boxId == LuckyBoxDataManager.BOX_ID_2) Timers.inst.Add(1, 0, CheckTime);
  111. _valueBarController.OnShown();
  112. _valueBarController.Controller(4);
  113. _curIndex = LuckyBoxDataManager.Instance.luckyBoxIds.IndexOf(boxId);
  114. _ui.m_listBg.numItems = LuckyBoxDataManager.Instance.luckyBoxIds.Count;
  115. _ui.m_listBg.ScrollToView(_curIndex);
  116. _ui.m_listBg.scrollPane.decelerationRate = 0.8f;
  117. LuckyBoxDataManager.Instance.luckyBoxIndex = _curIndex;
  118. OnListBgScroll();
  119. updateBoxEffect();
  120. Timers.inst.AddUpdate(CheckGuide);
  121. Timers.inst.Add(1f, 0, OnTimerUpdate, 1);
  122. }
  123. private async void GetWishingPoolInfo(int activityId)
  124. {
  125. bool result = await LuckyBoxSProxy.ReqGetWishingPoolInfo();
  126. if (result)
  127. {
  128. int index = LuckyBoxDataManager.Instance.KsActivityId.IndexOf(activityId);
  129. if (index < 0 || !LuckyBoxDataManager.Instance.VsStatus[index])
  130. ViewManager.Show<LuckyBoxWishView>(ConstLimitTimeActivityType.ActLimitTsy);
  131. }
  132. }
  133. private void OnTimerUpdate(object param)
  134. {
  135. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];
  136. long freeTime = LuckyBoxDataManager.Instance.GetFreeTime(boxId);
  137. GObject obj = _ui.m_listBg.GetChildAt(_curIndex);
  138. UI_ComBox1 comBox = UI_ComBox1.Proxy(obj);
  139. if (freeTime > 0)
  140. {
  141. long timeDifference = freeTime - TimeHelper.ServerNow();
  142. if (timeDifference> 0)
  143. {
  144. comBox.m_comLuckBoxBtn.m_comCostOne.m_c1.selectedIndex = 0;
  145. comBox.m_comLuckBoxBtn.m_txtFreeTime.visible = true;
  146. string strFreeTime = TimeUtil.FormattingTimeTo_HHmmss(timeDifference);
  147. comBox.m_comLuckBoxBtn.m_txtFreeTime.text = string.Format("{0}后免费", strFreeTime);
  148. }
  149. else
  150. {
  151. comBox.m_comLuckBoxBtn.m_comCostOne.m_c1.selectedIndex = 1;
  152. comBox.m_comLuckBoxBtn.m_txtFreeTime.visible = false;
  153. }
  154. }
  155. UI_ComBox1.ProxyEnd();
  156. }
  157. private void RenderListBgItem(int index, GObject obj)
  158. {
  159. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[index];
  160. }
  161. private void OnBtnLeftClick()
  162. {
  163. int index = _curIndex - 1;
  164. if (index < 0) return;
  165. _ui.m_listBg.ScrollToView(index, true);
  166. }
  167. private void OnBtnRightClick()
  168. {
  169. int index = _curIndex + 1;
  170. // if (index >= LuckyBoxDataManager.Instance.luckyBoxIds.Count) return;
  171. index = Mathf.Min(_ui.m_listBg.numItems - 1, index);
  172. _ui.m_listBg.ScrollToView(index, true);
  173. }
  174. private void OnListBgScroll()
  175. {
  176. if (_lcukyBoxCtrl.ContainsKey(LuckyBoxDataManager.Instance.currentBoxId)) _lcukyBoxCtrl[LuckyBoxDataManager.Instance.currentBoxId].OnHide();
  177. _curIndex = _ui.m_listBg.GetFirstChildInView();
  178. LuckyBoxDataManager.Instance.currentBoxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];
  179. if (LuckyBoxDataManager.Instance.currentBoxId == LuckyBoxDataManager.BOX_ID_3)
  180. {
  181. _valueBarController.Controller(3);
  182. }
  183. else
  184. {
  185. _valueBarController.Controller(4);
  186. }
  187. _valueBarController.UpdateCJ();
  188. UpdateListItem();
  189. _ui.m_btnLeft.grayed = _curIndex <= 0;
  190. _ui.m_btnRight.grayed = _curIndex >= _ui.m_listBg.numItems - 1;
  191. LuckyBoxDataManager.Instance.luckyBoxIndex = _curIndex;
  192. }
  193. List<GObject> _listActivityBtnObj = new List<GObject>();
  194. private void UpdateListItem()
  195. {
  196. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];
  197. LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  198. LuckyBoxDataManager.Instance.InitData(boxId);
  199. GObject obj = _ui.m_listBg.GetChildAt(_curIndex);
  200. UI_ComBox1 comBox = UI_ComBox1.Proxy(obj);
  201. _listActivityBtnObj.Add(obj);
  202. int activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitTsy);
  203. if (activityId > 0 && boxId == LuckyBoxDataManager.BOX_ID_2) {
  204. comBox.m_showActivityType.selectedIndex = 1;
  205. UpGiftBox(comBox);
  206. }
  207. else
  208. comBox.m_showActivityType.selectedIndex = 0;
  209. if (!_lcukyBoxCtrl.ContainsKey(boxId))
  210. {
  211. _lcukyBoxCtrl.Add(boxId, new LuckyBoxController(comBox.m_comModel.target));
  212. }
  213. _lcukyBoxCtrl[LuckyBoxDataManager.Instance.currentBoxId].OnShown(LuckyBoxDataManager.Instance.currentBoxId);
  214. comBox.m_comLuckBoxBtn.m_imgSpecial.visible = boxId != LuckyBoxDataManager.BOX_ID_3;
  215. //GGraph holder = comBox.m_comLuckBoxBtn.m_btnBuyTen.GetChild("holder").asGraph;
  216. //holder.visible = boxId != LuckyBoxDataManager.BOX_ID_3;
  217. comBox.m_comLuckBoxBtn.m_holder.visible = boxId != LuckyBoxDataManager.BOX_ID_3;
  218. //_effectUI1 = EffectUIPool.CreateEffectUI(holder, "ui_LuckyBox", "Button_Glow");
  219. _effectUI2 = EffectUIPool.CreateEffectUI(comBox.m_comLuckBoxBtn.m_holder, "ui_LuckyBox", "but_text_dc");
  220. comBox.m_comLuckBoxBtn.m_comCostOne.m_txtCost.text = cfg.costNum.ToString();
  221. comBox.m_comLuckBoxBtn.m_comCostOne.m_loaCost.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(cfg.costID).res);
  222. comBox.m_comLuckBoxBtn.m_comCostTen.m_txtCost.text = cfg.costNumTen.ToString();
  223. comBox.m_comLuckBoxBtn.m_comCostTen.m_loaCost.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(cfg.costID).res);
  224. if (comBox.m_comLuckBoxBtn.m_btnBuyOne.data == null)
  225. {
  226. comBox.m_comLuckBoxBtn.m_btnBuyOne.onClick.Add(OnClickBtnBuyOne);
  227. }
  228. comBox.m_comLuckBoxBtn.m_btnBuyOne.data = boxId;
  229. if (comBox.m_comLuckBoxBtn.m_btnBuyTen.data == null)
  230. {
  231. comBox.m_comLuckBoxBtn.m_btnBuyTen.onClick.Add(OnClickBtnBuyTen);
  232. }
  233. comBox.m_comLuckBoxBtn.m_btnBuyTen.data = boxId;
  234. if (comBox.m_btnPreview.data == null)
  235. {
  236. comBox.m_btnPreview.onClick.Add(OnClickBtnPreview);
  237. }
  238. comBox.m_btnPreview.data = boxId;
  239. if (comBox.m_btnReward.data == null)
  240. {
  241. comBox.m_btnReward.onClick.Add(OnClikcBtnReward);
  242. comBox.m_btnShop.onClick.Add(OnClikcBtnShop);
  243. comBox.m_btnGiftBag.onClick.Add(OnClikcBtnGiftBag);
  244. }
  245. comBox.m_btnReward.data = boxId;
  246. obj.data = boxId;
  247. comBox.m_grpTime.visible = (boxId == _activeBoxId);
  248. if (boxId == _activeBoxId)
  249. {
  250. long endTime = LuckyBoxDataManager.Instance.endTime;
  251. long curTime = TimeHelper.ServerNow();
  252. // TimeUtil.FormattingTime(curTime, endTime, out int num, out string str);
  253. long time = endTime - curTime;
  254. string strTime = time > TimeUtil.SECOND_PER_DAY * 100 ? TimeUtil.FormattingTimeTo_DDHHmm(time) : TimeUtil.FormattingTimeTo_HHmmss(time);
  255. comBox.m_txtTime.text = string.Format("活动时间:剩余{0}", strTime);
  256. comBox.m_loaTitle.url = "ui://LuckyBox/zx_title_1";
  257. }
  258. else
  259. {
  260. comBox.m_loaTitle.url = string.Format("ui://LuckyBox/zx_title_{0}", boxId);
  261. }
  262. UI_ComBox1.ProxyEnd();
  263. UpdateListItemData();
  264. UpdateFreeInfo();
  265. UpdateBtnReward();
  266. }
  267. private void UpdateBtnReward()
  268. {
  269. GObject obj = _ui.m_listBg.GetChildAt(1);
  270. UI_ComBox1 comBox = UI_ComBox1.Proxy(obj);
  271. RedDotController.Instance.SetComRedDot(comBox.m_btnReward, RedDotDataManager.Instance.GetActLuckyBoxRewardRed(ConstLimitTimeActivityType.ActLimitTsy));
  272. }
  273. private void OnClikcBtnReward()
  274. {
  275. ViewManager.Show<ActivityThemeLuckyBoxBonusView>(ConstLimitTimeActivityType.ActLimitTsy);
  276. }
  277. private void OnClikcBtnShop()
  278. {
  279. ViewManager.Show<StoreView>(new object[] { ConstStoreTabId.STORE_GIFT_BAG, ConstStoreSubId.STORE_GIFT_BAG_ACTIVITY }, new object[] { typeof(LuckyBoxView).FullName });
  280. }
  281. //刷新摘星活动期间的数据
  282. private void UpGiftBox(UI_ComBox1 comBox)
  283. {
  284. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];
  285. LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  286. comBox.m_txtCount.SetVar("value", ActivityDataManager.Instance.lastTsyDrawCount.ToString()).FlushVars();
  287. comBox.m_txtCount.SetVar("name", cfg.name).FlushVars();
  288. var activityInfoByTypeList = ActivityGlobalDataManager.Instance.GetActivityInfoByType(ActivityType.XSLB3);
  289. var list = activityInfoByTypeList.Where(a => a.EndTime > TimeInfo.Instance.ServerNow()).ToList();
  290. if (list.Count == 0)
  291. {
  292. comBox.m_comBagTime.target.visible = false;
  293. comBox.m_btnGiftBag.visible = false;
  294. }
  295. else
  296. {
  297. bool isSoldOut = true;
  298. foreach (var activityInfo in list)
  299. {
  300. ActivityOpenCfg activityOpenCfg = ActivityOpenCfgArray.Instance.GetCfg(activityInfo.ActivityId);
  301. var paramsArr = activityOpenCfg.paramsArr;
  302. foreach (var shopCfgId in paramsArr)
  303. {
  304. var shopCfg = ShopCfgArray.Instance.GetCfg(shopCfgId);
  305. var remainBuyNum = shopCfg.maxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(shopCfgId);
  306. //只要有一个商品还能购买,就不是售罄
  307. if (remainBuyNum > 0)
  308. {
  309. isSoldOut = false;
  310. break;
  311. }
  312. }
  313. }
  314. if (isSoldOut)
  315. {
  316. comBox.m_comBagTime.target.visible = false;
  317. comBox.m_btnGiftBag.visible = false;
  318. }
  319. else
  320. {
  321. comBox.m_comBagTime.m_txtGiftBagTime.text = TimeUtil.GetTimeLeft(TimeInfo.Instance.ServerNow(), list[0].EndTime);
  322. comBox.m_comBagTime.target.visible = true;
  323. comBox.m_btnGiftBag.visible = true;
  324. }
  325. }
  326. }
  327. //限时礼包按钮点击执行方法
  328. private void OnClikcBtnGiftBag()
  329. {
  330. var activityInfoByTypeList =
  331. ActivityGlobalDataManager.Instance.GetActivityInfoByType(ActivityType.XSLB3);
  332. var list = activityInfoByTypeList
  333. .Where(a => a.EndTime > TimeInfo.Instance.ServerNow()).ToList();
  334. if (list.Count == 0)
  335. {
  336. PromptController.Instance.ShowFloatTextPrompt("活动已结束");
  337. }
  338. else
  339. {
  340. ViewManager.Show<RushSaleGiftBoxView>(new object[] { ActivityType.XSLB3, this.viewData });
  341. }
  342. }
  343. private void UpdateListItemData()
  344. {
  345. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];
  346. LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  347. GObject obj = _ui.m_listBg.GetChildAt(_curIndex);
  348. UI_ComBox1 comBox = UI_ComBox1.Proxy(obj);
  349. LuckyBoxDataManager.Instance.GetOwnedCount(boxId, out int count, out int totalCount);
  350. comBox.m_txtOwned.SetVar("v1", "" + count).FlushVars();
  351. comBox.m_txtOwned.SetVar("v2", "" + totalCount).FlushVars();
  352. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(cfg.numericType);
  353. comBox.m_comLuckBoxBtn.m_txtRemainTimes.text = string.Format("今日剩余次数:{0}", cfg.maxCount - boughtCount);
  354. UI_ComBox1.ProxyEnd();
  355. }
  356. private void CheckTime(object param = null)
  357. {
  358. if (LuckyBoxDataManager.Instance.currentBoxId == _activeBoxId)
  359. {
  360. if (LuckyBoxDataManager.Instance.currentBoxId != _activeBoxId) return;
  361. long endTime = LuckyBoxDataManager.Instance.endTime;
  362. long curTime = TimeHelper.ServerNow();
  363. TimeUtil.FormattingTime(curTime, endTime, out int num, out string str);
  364. GObject item = _ui.m_listBg.GetChildAt(0);
  365. if (item == null) return;
  366. GObject textField = item.asCom.GetChild("txtTime");
  367. if (textField == null) return;
  368. long time = endTime - curTime;
  369. string strTime = time > TimeUtil.SECOND_PER_DAY * 100 ? TimeUtil.FormattingTimeTo_DDHHmm(time) : TimeUtil.FormattingTimeTo_HHmmss(time);
  370. textField.asTextField.text = string.Format("活动时间:剩余{0}", strTime);
  371. }
  372. else if(LuckyBoxDataManager.Instance.currentBoxId == LuckyBoxDataManager.BOX_ID_2)
  373. {
  374. GObject item = _ui.m_listBg.GetChildAt(1);
  375. if (item == null) return;
  376. GObject textField = item.asCom.GetChild("txtTsyTime");
  377. if (textField == null) return;
  378. int activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitTsy);
  379. var activityCfg = ActivityOpenCfgArray.Instance.GetCfg(activityId);
  380. long endTime = TimeUtil.DateTimeToTimestamp(activityCfg.endTime);
  381. long curTime = TimeHelper.ServerNow();
  382. if (endTime < curTime)
  383. {
  384. PromptController.Instance.ShowFloatTextPrompt("活动已结束");
  385. Timers.inst.Remove(UpdateTime);
  386. OnClickBtnBack();
  387. return;
  388. }
  389. TimeUtil.FormattingTime(curTime, endTime, out int num, out string str);
  390. textField.asTextField.text = "概率提升剩余: " + TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);
  391. //=====限时礼包倒计时
  392. //UpGiftBox();
  393. //EventAgent.DispatchEvent(ConstMessage.LUCKY_BOX_TIME);
  394. //=====限时礼包倒计时END
  395. }
  396. }
  397. private void UpdateTime(object param = null)
  398. {
  399. }
  400. private void updateBoxEffect()
  401. {
  402. if (isActiveBoxOpen)
  403. {
  404. }
  405. }
  406. private void OnClickBtnPreview(EventContext context)
  407. {
  408. GObject obj = context.sender as GObject;
  409. int boxId = (int)obj.data;
  410. ViewManager.Show<LuckyBoxPreShowView>(boxId);
  411. }
  412. private void OnClickBtnBuyOne(EventContext context)
  413. {
  414. GObject obj = context.sender as GObject;
  415. int boxId = (int)obj.data;
  416. LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  417. long freeTime = LuckyBoxDataManager.Instance.GetFreeTime(boxId);
  418. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(luckyBoxCfg.numericType);
  419. if (boughtCount + LuckyBoxDataManager.ONCE_TIME > luckyBoxCfg.maxCount)
  420. {
  421. PromptController.Instance.ShowFloatTextPrompt("抽奖次数不足");
  422. return;
  423. }
  424. LuckyBoxDataManager.Instance.CheckItemEnough(boxId, LuckyBoxDataManager.ONCE_TIME, async () =>
  425. {
  426. int activityId = 0;
  427. if (boxId == LuckyBoxDataManager.BOX_ID_2) {
  428. activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitTsy);
  429. }
  430. bool result = false;
  431. if (freeTime > 0 && freeTime < TimeHelper.ServerNow())
  432. result = await LuckyBoxSProxy.ReqGetBonus(boxId, LuckyBoxDataManager.ONCE_TIME, true, activityId);
  433. else
  434. result = await LuckyBoxSProxy.ReqGetBonus(boxId, LuckyBoxDataManager.ONCE_TIME,false, activityId);
  435. if (result)
  436. {
  437. ViewManager.Show<LuckyBoxStarView>(null, new object[] { typeof(LuckyBoxView).FullName, boxId });
  438. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 2);
  439. }
  440. });
  441. }
  442. private void OnClickBtnBuyTen(EventContext context)
  443. {
  444. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.LUCKY_BOX);
  445. if (GuideDataManager.IsGuideFinish(ConstGuideId.LUCKY_BOX) <= 0 && (GuideDataManager.currentGuideId == 0 || GuideDataManager.currentGuideIdIndex != 2))
  446. {
  447. //防止点击太快,在引导开启前就被点击到,导致引导卡死
  448. return;
  449. }
  450. GObject obj = context.sender as GObject;
  451. int boxId = (int)obj.data;
  452. LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  453. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(luckyBoxCfg.numericType);
  454. if (boughtCount + LuckyBoxDataManager.TEN_TIME > luckyBoxCfg.maxCount)
  455. {
  456. PromptController.Instance.ShowFloatTextPrompt("抽奖次数不足");
  457. return;
  458. }
  459. LuckyBoxDataManager.Instance.CheckItemEnough(boxId, LuckyBoxDataManager.TEN_TIME, async () =>
  460. {
  461. int activityId = 0;
  462. if (boxId == LuckyBoxDataManager.BOX_ID_2)
  463. {
  464. activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitTsy);
  465. }
  466. bool result = await LuckyBoxSProxy.ReqGetBonus(boxId, LuckyBoxDataManager.TEN_TIME,false, activityId);
  467. if (result)
  468. {
  469. ViewManager.Show<LuckyBoxStarView>(null, new object[] { typeof(LuckyBoxView).FullName, boxId });
  470. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 2);
  471. UpdateBtnReward();
  472. }
  473. });
  474. }
  475. protected override void OnHide()
  476. {
  477. base.OnHide();
  478. _valueBarController.OnHide();
  479. foreach (int key in _lcukyBoxCtrl.Keys)
  480. {
  481. _lcukyBoxCtrl[key].OnHide();
  482. }
  483. Timers.inst.Remove(OnTimerUpdate);
  484. Timers.inst.Remove(CheckTime);
  485. // Timers.inst.Remove(UpdateBg);
  486. Timers.inst.Remove(CheckGuide);
  487. // Timers.inst.Remove(UpdateTime);
  488. Debug.Log("OnHide: LuckyBoxView");
  489. }
  490. protected override void RemoveEventListener()
  491. {
  492. base.RemoveEventListener();
  493. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateListItemData);
  494. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateListItemData);
  495. EventAgent.RemoveEventListener(ConstMessage.LUCKY_BOX_FREE_TIME_CHANGED, UpdateFreeInfo);
  496. EventAgent.RemoveEventListener(ConstMessage.LUCKY_BOX_ACTIVITY_REWARD, UpdateBtnReward);
  497. }
  498. private void OnClickBtnBack()
  499. {
  500. Reset();
  501. ViewManager.GoBackFrom(typeof(LuckyBoxView).FullName);
  502. }
  503. private void OnClickBtnHome()
  504. {
  505. GameController.GoBackToMainView();
  506. }
  507. private void Reset()
  508. {
  509. LuckyBoxDataManager.Instance.currentBoxId = LuckyBoxDataManager.Instance.luckyBoxIds[0];
  510. }
  511. private void CheckGuide(object param)
  512. {
  513. if (GuideDataManager.IsGuideFinish(ConstGuideId.LUCKY_BOX) <= 0)
  514. {
  515. UpdateToCheckGuide(null);
  516. }
  517. else
  518. {
  519. Timers.inst.Remove(CheckGuide);
  520. }
  521. }
  522. protected override void UpdateToCheckGuide(object param)
  523. {
  524. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  525. GObject gObject = _ui.m_listBg.GetChildAt(_curIndex);
  526. if (gObject == null) return;
  527. GButton btnBuyTen = gObject.asCom.GetChild("comLuckBoxBtn").asCom.GetChild("btnBuyTen").asButton;
  528. GuideController.TryGuide(null, ConstGuideId.LUCKY_BOX, 1, "“摘星”里可以通过星辰的力量获得服饰。", -1, true, _ui.target.height - 600);
  529. GuideController.TryGuide(btnBuyTen, ConstGuideId.LUCKY_BOX, 2, "点击摘取十次。");
  530. }
  531. protected override void TryCompleteGuide()
  532. {
  533. base.TryCompleteGuide();
  534. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.LUCKY_BOX);
  535. GuideController.TryCompleteGuideIndex(ConstGuideId.LUCKY_BOX, 2);
  536. }
  537. private void UpdateFreeInfo()
  538. {
  539. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];
  540. LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  541. long freeTime = LuckyBoxDataManager.Instance.GetFreeTime(boxId);
  542. GObject obj = _ui.m_listBg.GetChildAt(_curIndex);
  543. UI_ComBox1 comBox = UI_ComBox1.Proxy(obj);
  544. if (freeTime > 0)
  545. {
  546. if (freeTime > TimeHelper.ServerNow())
  547. {
  548. comBox.m_comLuckBoxBtn.m_comCostOne.m_c1.selectedIndex = 0;
  549. comBox.m_comLuckBoxBtn.m_txtFreeTime.visible = true;
  550. }
  551. else
  552. {
  553. comBox.m_comLuckBoxBtn.m_comCostOne.m_c1.selectedIndex = 1;
  554. comBox.m_comLuckBoxBtn.m_txtFreeTime.visible = false;
  555. }
  556. }
  557. else
  558. {
  559. comBox.m_comLuckBoxBtn.m_comCostOne.m_c1.selectedIndex = 0;
  560. comBox.m_comLuckBoxBtn.m_txtFreeTime.visible = false;
  561. }
  562. }
  563. }
  564. }