LuckyBoxView.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  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. isReturnView = true;
  64. _dressUpObjUIXiHe = new DressUpObjUI("SceneDressUp");
  65. _dressUpObjUIChangXi = new DressUpObjUI("SceneDressUp");
  66. // _ui.m_txtRemainTimes.visible = false;
  67. _valueBarController = new ValueBarController(_ui.m_valueBar);
  68. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  69. // _ui.m_btnHome.onClick.Add(OnClickBtnHome);
  70. _ui.m_btnLeft.onClick.Add(OnBtnLeftClick);
  71. _ui.m_btnRight.onClick.Add(OnBtnRightClick);
  72. // _ui.m_listBg.SetVirtual();
  73. _ui.m_listBg.itemRenderer = RenderListBgItem;
  74. // _ui.m_listBg.itemProvider = GetListItemResource;
  75. _ui.m_listBg.scrollPane.onScrollEnd.Add(OnListBgScroll);
  76. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("zx_bg");
  77. }
  78. protected override void AddEventListener()
  79. {
  80. base.AddEventListener();
  81. EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateListItemData);
  82. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateListItemData);
  83. EventAgent.AddEventListener(ConstMessage.LUCKY_BOX_FREE_TIME_CHANGED, UpdateFreeInfo);
  84. EventAgent.AddEventListener(ConstMessage.LUCKY_BOX_ACTIVITY_REWARD, UpdateBtnReward);
  85. EventAgent.AddEventListener(ConstMessage.ACTIVITY_LUCKY_BOX, UpdateBtnReward);
  86. }
  87. protected override void OnShown()
  88. {
  89. base.OnShown();
  90. Debug.Log("OnShown:LuckyBoxView");
  91. LuckyBoxDataManager.Instance.luckyBoxIds.Clear();
  92. LuckyBoxDataManager.Instance.luckyBoxIds.Add(LuckyBoxDataManager.BOX_ID_2);
  93. LuckyBoxDataManager.Instance.luckyBoxIds.Add(LuckyBoxDataManager.BOX_ID_3);
  94. _activeBoxId = 0;
  95. int activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitTsy);
  96. if (activityId > 0)
  97. GetWishingPoolInfo(activityId);
  98. if (LuckyBoxDataManager.Instance.RotatingId > 0)
  99. {
  100. RotatingLuckyBoxCfg rotatingLuckyBox = RotatingLuckyBoxCfgArray.Instance.GetCfg(LuckyBoxDataManager.Instance.RotatingId);
  101. _activeBoxId = rotatingLuckyBox.luckyBoxId;
  102. LuckyBoxDataManager.Instance.endTime = TimeUtil.GetTimestamp(rotatingLuckyBox.endTime);
  103. LuckyBoxDataManager.Instance.luckyBoxIds.Insert(0, _activeBoxId);
  104. }
  105. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[1];
  106. if (this.viewData != null)
  107. {
  108. boxId = (int)this.viewData;
  109. }
  110. if (GuideDataManager.IsGuideFinish(ConstGuideId.LUCKY_BOX) <= 0) boxId = LuckyBoxDataManager.BOX_ID_2;
  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. }
  172. private void OnBtnRightClick()
  173. {
  174. int index = _curIndex + 1;
  175. // if (index >= LuckyBoxDataManager.Instance.luckyBoxIds.Count) return;
  176. index = Mathf.Min(_ui.m_listBg.numItems - 1, index);
  177. _ui.m_listBg.ScrollToView(index, true);
  178. }
  179. private void OnListBgScroll()
  180. {
  181. if (_lcukyBoxCtrl.ContainsKey(LuckyBoxDataManager.Instance.currentBoxId)) _lcukyBoxCtrl[LuckyBoxDataManager.Instance.currentBoxId].OnHide();
  182. _curIndex = _ui.m_listBg.GetFirstChildInView();
  183. LuckyBoxDataManager.Instance.currentBoxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];
  184. if (LuckyBoxDataManager.Instance.currentBoxId == LuckyBoxDataManager.BOX_ID_3)
  185. {
  186. _valueBarController.Controller(3);
  187. }
  188. else
  189. {
  190. _valueBarController.Controller(4);
  191. }
  192. _valueBarController.UpdateCJ();
  193. UpdateListItem();
  194. _ui.m_btnLeft.grayed = _curIndex <= 0;
  195. _ui.m_btnRight.grayed = _curIndex >= _ui.m_listBg.numItems - 1;
  196. LuckyBoxDataManager.Instance.luckyBoxIndex = _curIndex;
  197. }
  198. List<GObject> _listActivityBtnObj = new List<GObject>();
  199. private void UpdateListItem()
  200. {
  201. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];
  202. LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  203. LuckyBoxDataManager.Instance.InitData(boxId);
  204. GObject obj = _ui.m_listBg.GetChildAt(_curIndex);
  205. UI_ComBox1 comBox = UI_ComBox1.Proxy(obj);
  206. _listActivityBtnObj.Add(obj);
  207. int activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitTsy);
  208. if (activityId > 0 && boxId == LuckyBoxDataManager.BOX_ID_2)
  209. {
  210. comBox.m_showActivityType.selectedIndex = 1;
  211. UpGiftBox(comBox);
  212. if (comBox.m_btnRule.data == null)
  213. {
  214. comBox.m_btnRule.onClick.Add(RuleController.ShowRuleView);
  215. comBox.m_btnRule.data = 300024;
  216. }
  217. }
  218. else
  219. comBox.m_showActivityType.selectedIndex = 0;
  220. if (!_lcukyBoxCtrl.ContainsKey(boxId))
  221. {
  222. _lcukyBoxCtrl.Add(boxId, new LuckyBoxController(comBox.m_comModel.target));
  223. }
  224. _lcukyBoxCtrl[LuckyBoxDataManager.Instance.currentBoxId].OnShown(LuckyBoxDataManager.Instance.currentBoxId);
  225. comBox.m_comLuckBoxBtn.m_imgSpecial.visible = boxId != LuckyBoxDataManager.BOX_ID_3;
  226. //GGraph holder = comBox.m_comLuckBoxBtn.m_btnBuyTen.GetChild("holder").asGraph;
  227. //holder.visible = boxId != LuckyBoxDataManager.BOX_ID_3;
  228. comBox.m_comLuckBoxBtn.m_holder.visible = boxId != LuckyBoxDataManager.BOX_ID_3;
  229. //_effectUI1 = EffectUIPool.CreateEffectUI(holder, "ui_LuckyBox", "Button_Glow");
  230. _effectUI2 = EffectUIPool.CreateEffectUI(comBox.m_comLuckBoxBtn.m_holder, "ui_LuckyBox", "but_text_dc");
  231. comBox.m_comLuckBoxBtn.m_comCostOne.m_txtCost.text = cfg.costNum.ToString();
  232. comBox.m_comLuckBoxBtn.m_comCostOne.m_loaCost.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(cfg.costID).res);
  233. comBox.m_comLuckBoxBtn.m_comCostTen.m_txtCost.text = cfg.costNumTen.ToString();
  234. comBox.m_comLuckBoxBtn.m_comCostTen.m_loaCost.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(cfg.costID).res);
  235. if (comBox.m_comLuckBoxBtn.m_btnBuyOne.data == null)
  236. {
  237. comBox.m_comLuckBoxBtn.m_btnBuyOne.onClick.Add(OnClickBtnBuyOne);
  238. }
  239. comBox.m_comLuckBoxBtn.m_btnBuyOne.data = boxId;
  240. if (comBox.m_comLuckBoxBtn.m_btnBuyTen.data == null)
  241. {
  242. comBox.m_comLuckBoxBtn.m_btnBuyTen.onClick.Add(OnClickBtnBuyTen);
  243. }
  244. comBox.m_comLuckBoxBtn.m_btnBuyTen.data = boxId;
  245. if (comBox.m_btnPreview.data == null)
  246. {
  247. comBox.m_btnPreview.onClick.Add(OnClickBtnPreview);
  248. }
  249. comBox.m_btnPreview.data = boxId;
  250. if (comBox.m_btnReward.data == null)
  251. {
  252. comBox.m_btnReward.onClick.Add(OnClikcBtnReward);
  253. comBox.m_btnShop.onClick.Add(OnClikcBtnShop);
  254. comBox.m_btnGiftBag.onClick.Add(OnClikcBtnGiftBag);
  255. }
  256. comBox.m_btnReward.data = boxId;
  257. obj.data = boxId;
  258. comBox.m_grpTime.visible = (boxId == _activeBoxId);
  259. if (boxId == _activeBoxId)
  260. {
  261. long endTime = LuckyBoxDataManager.Instance.endTime;
  262. long curTime = TimeHelper.ServerNow();
  263. // TimeUtil.FormattingTime(curTime, endTime, out int num, out string str);
  264. long time = endTime - curTime;
  265. string strTime = time > TimeUtil.SECOND_PER_DAY * 100 ? TimeUtil.FormattingTimeTo_DDHHmm(time) : TimeUtil.FormattingTimeTo_HHmmss(time);
  266. comBox.m_txtTime.text = string.Format("活动时间:剩余{0}", strTime);
  267. comBox.m_loaTitle.url = "ui://LuckyBox/zx_title_1";
  268. }
  269. else
  270. {
  271. comBox.m_loaTitle.url = string.Format("ui://LuckyBox/zx_title_{0}", boxId);
  272. }
  273. UI_ComBox1.ProxyEnd();
  274. UpdateListItemData();
  275. UpdateFreeInfo();
  276. }
  277. private void UpdateBtnReward()
  278. {
  279. if (_curIndex == 1) {
  280. GObject obj = _ui.m_listBg.GetChildAt(_curIndex);
  281. UI_ComBox1 comBox = UI_ComBox1.Proxy(obj);
  282. RedDotController.Instance.SetComRedDot(comBox.m_btnReward, RedDotDataManager.Instance.GetActLuckyBoxRewardRed(ConstLimitTimeActivityType.ActLimitTsy));
  283. comBox.m_txtCount.SetVar("value", ActivityDataManager.Instance.lastTsyDrawCount.ToString()).FlushVars();
  284. }
  285. }
  286. private void OnClikcBtnReward()
  287. {
  288. ViewManager.Show<ActivityThemeLuckyBoxBonusView>(ConstLimitTimeActivityType.ActLimitTsy);
  289. }
  290. private void OnClikcBtnShop()
  291. {
  292. ViewManager.Show<StoreView>(new object[] { ConstStoreTabId.STORE_GIFT_BAG, ConstStoreSubId.STORE_GIFT_BAG_ACTIVITY }, new object[] { typeof(LuckyBoxView).FullName });
  293. }
  294. //刷新摘星活动期间的数据
  295. private void UpGiftBox(UI_ComBox1 comBox)
  296. {
  297. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];
  298. LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  299. comBox.m_txtCount.SetVar("value", ActivityDataManager.Instance.lastTsyDrawCount.ToString()).FlushVars();
  300. comBox.m_txtCount.SetVar("name", cfg.name).FlushVars();
  301. var activityInfoByTypeList = ActivityGlobalDataManager.Instance.GetActivityInfoByType(ActivityType.XSLB3);
  302. var list = activityInfoByTypeList.Where(a => a.EndTime > TimeInfo.Instance.ServerNow()).ToList();
  303. if (list.Count == 0)
  304. {
  305. comBox.m_comBagTime.target.visible = false;
  306. comBox.m_btnGiftBag.visible = false;
  307. }
  308. else
  309. {
  310. bool isSoldOut = true;
  311. foreach (var activityInfo in list)
  312. {
  313. ActivityOpenCfg activityOpenCfg = ActivityOpenCfgArray.Instance.GetCfg(activityInfo.ActivityId);
  314. var paramsArr = activityOpenCfg.paramsArr;
  315. foreach (var shopCfgId in paramsArr)
  316. {
  317. var shopCfg = ShopCfgArray.Instance.GetCfg(shopCfgId);
  318. var remainBuyNum = shopCfg.maxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(shopCfgId);
  319. //只要有一个商品还能购买,就不是售罄
  320. if (remainBuyNum > 0)
  321. {
  322. isSoldOut = false;
  323. break;
  324. }
  325. }
  326. }
  327. if (isSoldOut)
  328. {
  329. comBox.m_comBagTime.target.visible = false;
  330. comBox.m_btnGiftBag.visible = false;
  331. }
  332. else
  333. {
  334. comBox.m_comBagTime.m_txtGiftBagTime.text = TimeUtil.GetTimeLeft(TimeInfo.Instance.ServerNow(), list[0].EndTime);
  335. comBox.m_comBagTime.target.visible = true;
  336. comBox.m_btnGiftBag.visible = true;
  337. }
  338. }
  339. UpdateBtnReward();
  340. }
  341. //限时礼包按钮点击执行方法
  342. private void OnClikcBtnGiftBag()
  343. {
  344. var activityInfoByTypeList =
  345. ActivityGlobalDataManager.Instance.GetActivityInfoByType(ActivityType.XSLB3);
  346. var list = activityInfoByTypeList
  347. .Where(a => a.EndTime > TimeInfo.Instance.ServerNow()).ToList();
  348. if (list.Count == 0)
  349. {
  350. PromptController.Instance.ShowFloatTextPrompt("活动已结束");
  351. }
  352. else
  353. {
  354. ViewManager.Show<RushSaleGiftBoxView>(new object[] { ActivityType.XSLB3, this.viewData });
  355. }
  356. }
  357. private void UpdateListItemData()
  358. {
  359. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];
  360. LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  361. GObject obj = _ui.m_listBg.GetChildAt(_curIndex);
  362. UI_ComBox1 comBox = UI_ComBox1.Proxy(obj);
  363. LuckyBoxDataManager.Instance.GetOwnedCount(boxId, out int count, out int totalCount);
  364. comBox.m_txtOwned.SetVar("v1", "" + count).FlushVars();
  365. comBox.m_txtOwned.SetVar("v2", "" + totalCount).FlushVars();
  366. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(cfg.numericType);
  367. comBox.m_comLuckBoxBtn.m_txtRemainTimes.text = string.Format("今日剩余次数:{0}", cfg.maxCount - boughtCount);
  368. UI_ComBox1.ProxyEnd();
  369. }
  370. private void CheckTime(object param = null)
  371. {
  372. if (LuckyBoxDataManager.Instance.currentBoxId == _activeBoxId)
  373. {
  374. if (LuckyBoxDataManager.Instance.currentBoxId != _activeBoxId) return;
  375. long endTime = LuckyBoxDataManager.Instance.endTime;
  376. long curTime = TimeHelper.ServerNow();
  377. TimeUtil.FormattingTime(curTime, endTime, out int num, out string str);
  378. GObject item = _ui.m_listBg.GetChildAt(0);
  379. if (item == null) return;
  380. GObject textField = item.asCom.GetChild("txtTime");
  381. if (textField == null) return;
  382. long time = endTime - curTime;
  383. string strTime = time > TimeUtil.SECOND_PER_DAY * 100 ? TimeUtil.FormattingTimeTo_DDHHmm(time) : TimeUtil.FormattingTimeTo_HHmmss(time);
  384. textField.asTextField.text = string.Format("活动时间:剩余{0}", strTime);
  385. }
  386. else if(LuckyBoxDataManager.Instance.currentBoxId == LuckyBoxDataManager.BOX_ID_2)
  387. {
  388. GObject item = _ui.m_listBg.GetChildAt(1);
  389. if (item == null) return;
  390. GObject textField = item.asCom.GetChild("txtTsyTime");
  391. if (textField == null) return;
  392. int activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitTsy);
  393. var activityCfg = ActivityOpenCfgArray.Instance.GetCfg(activityId);
  394. long endTime = TimeUtil.DateTimeToTimestamp(activityCfg.endTime);
  395. long curTime = TimeHelper.ServerNow();
  396. if (endTime < curTime)
  397. {
  398. PromptController.Instance.ShowFloatTextPrompt("活动已结束");
  399. Timers.inst.Remove(UpdateTime);
  400. OnClickBtnBack();
  401. return;
  402. }
  403. TimeUtil.FormattingTime(curTime, endTime, out int num, out string str);
  404. textField.asTextField.text = "概率提升剩余: " + TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);
  405. //=====限时礼包倒计时
  406. //UpGiftBox();
  407. //EventAgent.DispatchEvent(ConstMessage.LUCKY_BOX_TIME);
  408. //=====限时礼包倒计时END
  409. }
  410. }
  411. private void UpdateTime(object param = null)
  412. {
  413. }
  414. private void updateBoxEffect()
  415. {
  416. if (isActiveBoxOpen)
  417. {
  418. }
  419. }
  420. private void OnClickBtnPreview(EventContext context)
  421. {
  422. GObject obj = context.sender as GObject;
  423. int boxId = (int)obj.data;
  424. ViewManager.Show<LuckyBoxPreShowView>(boxId);
  425. }
  426. private void OnClickBtnBuyOne(EventContext context)
  427. {
  428. GObject obj = context.sender as GObject;
  429. int boxId = (int)obj.data;
  430. LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  431. long freeTime = LuckyBoxDataManager.Instance.GetFreeTime(boxId);
  432. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(luckyBoxCfg.numericType);
  433. if (boughtCount + LuckyBoxDataManager.ONCE_TIME > luckyBoxCfg.maxCount)
  434. {
  435. PromptController.Instance.ShowFloatTextPrompt("抽奖次数不足");
  436. return;
  437. }
  438. LuckyBoxDataManager.Instance.CheckItemEnough(boxId, LuckyBoxDataManager.ONCE_TIME, async () =>
  439. {
  440. int activityId = 0;
  441. if (boxId == LuckyBoxDataManager.BOX_ID_2) {
  442. activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitTsy);
  443. }
  444. bool freeType = (freeTime > 0 && freeTime < TimeHelper.ServerNow());
  445. bool result = await LuckyBoxSProxy.ReqGetBonus(boxId, LuckyBoxDataManager.ONCE_TIME, freeType, activityId);
  446. if (result)
  447. {
  448. ViewManager.Show<LuckyBoxStarView>(null, new object[] { typeof(LuckyBoxView).FullName, boxId });
  449. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 2);
  450. }
  451. });
  452. }
  453. private void OnClickBtnBuyTen(EventContext context)
  454. {
  455. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.LUCKY_BOX);
  456. if (GuideDataManager.IsGuideFinish(ConstGuideId.LUCKY_BOX) <= 0 && (GuideDataManager.currentGuideId == 0 || GuideDataManager.currentGuideIdIndex != 2))
  457. {
  458. //防止点击太快,在引导开启前就被点击到,导致引导卡死
  459. return;
  460. }
  461. GObject obj = context.sender as GObject;
  462. int boxId = (int)obj.data;
  463. LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  464. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(luckyBoxCfg.numericType);
  465. if (boughtCount + LuckyBoxDataManager.TEN_TIME > luckyBoxCfg.maxCount)
  466. {
  467. PromptController.Instance.ShowFloatTextPrompt("抽奖次数不足");
  468. return;
  469. }
  470. LuckyBoxDataManager.Instance.CheckItemEnough(boxId, LuckyBoxDataManager.TEN_TIME, async () =>
  471. {
  472. int activityId = 0;
  473. if (boxId == LuckyBoxDataManager.BOX_ID_2)
  474. {
  475. activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitTsy);
  476. }
  477. bool result = await LuckyBoxSProxy.ReqGetBonus(boxId, LuckyBoxDataManager.TEN_TIME,false, activityId);
  478. if (result)
  479. {
  480. ViewManager.Show<LuckyBoxStarView>(null, new object[] { typeof(LuckyBoxView).FullName, boxId });
  481. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 2);
  482. }
  483. });
  484. }
  485. protected override void OnHide()
  486. {
  487. base.OnHide();
  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. }