LuckyBoxView.cs 28 KB

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