LuckyBoxView.cs 28 KB

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