LuckyBoxView.cs 28 KB

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