LuckyBoxView.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. using FairyGUI;
  2. using UI.LuckyBox;
  3. using UI.CommonGame;
  4. using System;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using ET;
  8. using System.Linq;
  9. namespace GFGGame
  10. {
  11. public class LuckyBoxView : BaseView
  12. {
  13. private UI_LuckyBoxUI _ui;
  14. private ValueBarController _valueBarController;
  15. private Dictionary<int, LuckyBoxController> _lcukyBoxCtrl = new Dictionary<int, LuckyBoxController>();
  16. private EffectUI _effectUI1;
  17. private EffectUI _effectUI2;
  18. private DressUpObjUI _dressUpObjUIXiHe;
  19. private DressUpObjUI _dressUpObjUIChangXi;
  20. private bool isActiveBoxOpen = false;
  21. private int _activeBoxId = 0;
  22. private int _curIndex = 0;
  23. public override void Dispose()
  24. {
  25. if (_valueBarController != null)
  26. {
  27. _valueBarController.Dispose();
  28. _valueBarController = null;
  29. }
  30. foreach (int key in _lcukyBoxCtrl.Keys)
  31. {
  32. _lcukyBoxCtrl[key].Dispose();
  33. }
  34. _lcukyBoxCtrl.Clear();
  35. if (_dressUpObjUIXiHe != null)
  36. {
  37. _dressUpObjUIXiHe.Dispose();
  38. _dressUpObjUIXiHe = null;
  39. }
  40. if (_dressUpObjUIChangXi != null)
  41. {
  42. _dressUpObjUIChangXi.Dispose();
  43. _dressUpObjUIChangXi = null;
  44. }
  45. EffectUIPool.Recycle(_effectUI1);
  46. _effectUI1 = null;
  47. EffectUIPool.Recycle(_effectUI2);
  48. _effectUI2 = null;
  49. if (_ui != null)
  50. {
  51. _ui.Dispose();
  52. _ui = null;
  53. }
  54. base.Dispose();
  55. }
  56. protected override void OnInit()
  57. {
  58. base.OnInit();
  59. packageName = UI_LuckyBoxUI.PACKAGE_NAME;
  60. _ui = UI_LuckyBoxUI.Create();
  61. this.viewCom = _ui.target;
  62. isfullScreen = true;
  63. _dressUpObjUIXiHe = new DressUpObjUI("SceneDressUp");
  64. _dressUpObjUIChangXi = new DressUpObjUI("SceneDressUp");
  65. // _ui.m_txtRemainTimes.visible = false;
  66. _valueBarController = new ValueBarController(_ui.m_valueBar);
  67. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  68. // _ui.m_btnHome.onClick.Add(OnClickBtnHome);
  69. _ui.m_btnLeft.onClick.Add(OnBtnLeftClick);
  70. _ui.m_btnRight.onClick.Add(OnBtnRightClick);
  71. // _ui.m_listBg.SetVirtual();
  72. _ui.m_listBg.itemRenderer = RenderListBgItem;
  73. // _ui.m_listBg.itemProvider = GetListItemResource;
  74. _ui.m_listBg.scrollPane.onScrollEnd.Add(OnListBgScroll);
  75. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("zx_bg");
  76. }
  77. protected override void AddEventListener()
  78. {
  79. base.AddEventListener();
  80. EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateListItemData);
  81. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateListItemData);
  82. EventAgent.AddEventListener(ConstMessage.LUCKY_BOX_FREE_TIME_CHANGED, UpdateFreeInfo);
  83. EventAgent.AddEventListener(ConstMessage.LUCKY_BOX_ACTIVITY_REWARD, UpdateBtnReward);
  84. 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. int activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitTsy);
  95. if (activityId > 0)
  96. GetWishingPoolInfo(activityId);
  97. if (LuckyBoxDataManager.Instance.RotatingId > 0)
  98. {
  99. RotatingLuckyBoxCfg rotatingLuckyBox = RotatingLuckyBoxCfgArray.Instance.GetCfg(LuckyBoxDataManager.Instance.RotatingId);
  100. _activeBoxId = rotatingLuckyBox.luckyBoxId;
  101. LuckyBoxDataManager.Instance.endTime = TimeUtil.GetTimestamp(rotatingLuckyBox.endTime);
  102. LuckyBoxDataManager.Instance.luckyBoxIds.Insert(0, _activeBoxId);
  103. }
  104. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[1];
  105. if (this.viewData != null)
  106. {
  107. boxId = (int)this.viewData;
  108. }
  109. if (GuideDataManager.IsGuideFinish(ConstGuideId.LUCKY_BOX) <= 0) boxId = LuckyBoxDataManager.BOX_ID_2;
  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. if (comBox.m_btnRule.data == null)
  212. {
  213. comBox.m_btnRule.onClick.Add(RuleController.ShowRuleView);
  214. comBox.m_btnRule.data = 300024;
  215. }
  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. //_effectUI1 = EffectUIPool.CreateEffectUI(holder, "ui_LuckyBox", "Button_Glow");
  229. _effectUI2 = EffectUIPool.CreateEffectUI(comBox.m_comLuckBoxBtn.m_holder, "ui_LuckyBox", "but_text_dc");
  230. comBox.m_comLuckBoxBtn.m_comCostOne.m_txtCost.text = cfg.costNum.ToString();
  231. comBox.m_comLuckBoxBtn.m_comCostOne.m_loaCost.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(cfg.costID).res);
  232. comBox.m_comLuckBoxBtn.m_comCostTen.m_txtCost.text = cfg.costNumTen.ToString();
  233. comBox.m_comLuckBoxBtn.m_comCostTen.m_loaCost.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(cfg.costID).res);
  234. if (comBox.m_comLuckBoxBtn.m_btnBuyOne.data == null)
  235. {
  236. comBox.m_comLuckBoxBtn.m_btnBuyOne.onClick.Add(OnClickBtnBuyOne);
  237. }
  238. comBox.m_comLuckBoxBtn.m_btnBuyOne.data = boxId;
  239. if (comBox.m_comLuckBoxBtn.m_btnBuyTen.data == null)
  240. {
  241. comBox.m_comLuckBoxBtn.m_btnBuyTen.onClick.Add(OnClickBtnBuyTen);
  242. }
  243. comBox.m_comLuckBoxBtn.m_btnBuyTen.data = boxId;
  244. if (comBox.m_btnPreview.data == null)
  245. {
  246. comBox.m_btnPreview.onClick.Add(OnClickBtnPreview);
  247. }
  248. comBox.m_btnPreview.data = boxId;
  249. if (comBox.m_btnReward.data == null)
  250. {
  251. comBox.m_btnReward.onClick.Add(OnClikcBtnReward);
  252. comBox.m_btnShop.onClick.Add(OnClikcBtnShop);
  253. comBox.m_btnGiftBag.onClick.Add(OnClikcBtnGiftBag);
  254. }
  255. comBox.m_btnReward.data = boxId;
  256. obj.data = boxId;
  257. comBox.m_grpTime.visible = (boxId == _activeBoxId);
  258. if (boxId == _activeBoxId)
  259. {
  260. long endTime = LuckyBoxDataManager.Instance.endTime;
  261. long curTime = TimeHelper.ServerNow();
  262. // TimeUtil.FormattingTime(curTime, endTime, out int num, out string str);
  263. long time = endTime - curTime;
  264. string strTime = time > TimeUtil.SECOND_PER_DAY * 100 ? TimeUtil.FormattingTimeTo_DDHHmm(time) : TimeUtil.FormattingTimeTo_HHmmss(time);
  265. comBox.m_txtTime.text = string.Format("活动时间:剩余{0}", strTime);
  266. comBox.m_loaTitle.url = "ui://LuckyBox/zx_title_1";
  267. }
  268. else
  269. {
  270. comBox.m_loaTitle.url = string.Format("ui://LuckyBox/zx_title_{0}", boxId);
  271. }
  272. UI_ComBox1.ProxyEnd();
  273. UpdateListItemData();
  274. UpdateFreeInfo();
  275. }
  276. private void UpdateBtnReward()
  277. {
  278. if (_curIndex == 1) {
  279. GObject obj = _ui.m_listBg.GetChildAt(_curIndex);
  280. UI_ComBox1 comBox = UI_ComBox1.Proxy(obj);
  281. RedDotController.Instance.SetComRedDot(comBox.m_btnReward, RedDotDataManager.Instance.GetActLuckyBoxRewardRed(ConstLimitTimeActivityType.ActLimitTsy));
  282. comBox.m_txtCount.SetVar("value", ActivityDataManager.Instance.lastTsyDrawCount.ToString()).FlushVars();
  283. }
  284. }
  285. private void OnClikcBtnReward()
  286. {
  287. ViewManager.Show<ActivityThemeLuckyBoxBonusView>(ConstLimitTimeActivityType.ActLimitTsy);
  288. }
  289. private void OnClikcBtnShop()
  290. {
  291. ViewManager.Show<StoreView>(new object[] { ConstStoreTabId.STORE_GIFT_BAG, ConstStoreSubId.STORE_GIFT_BAG_ACTIVITY }, new object[] { typeof(LuckyBoxView).FullName });
  292. }
  293. //刷新摘星活动期间的数据
  294. private void UpGiftBox(UI_ComBox1 comBox)
  295. {
  296. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];
  297. LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  298. comBox.m_txtCount.SetVar("value", ActivityDataManager.Instance.lastTsyDrawCount.ToString()).FlushVars();
  299. comBox.m_txtCount.SetVar("name", cfg.name).FlushVars();
  300. var activityInfoByTypeList = ActivityGlobalDataManager.Instance.GetActivityInfoByType(ActivityType.XSLB3);
  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. _valueBarController.OnHide();
  488. foreach (int key in _lcukyBoxCtrl.Keys)
  489. {
  490. _lcukyBoxCtrl[key].OnHide();
  491. }
  492. Timers.inst.Remove(OnTimerUpdate);
  493. Timers.inst.Remove(CheckTime);
  494. // Timers.inst.Remove(UpdateBg);
  495. Timers.inst.Remove(CheckGuide);
  496. // Timers.inst.Remove(UpdateTime);
  497. Debug.Log("OnHide: LuckyBoxView");
  498. }
  499. protected override void RemoveEventListener()
  500. {
  501. base.RemoveEventListener();
  502. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateListItemData);
  503. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateListItemData);
  504. EventAgent.RemoveEventListener(ConstMessage.LUCKY_BOX_FREE_TIME_CHANGED, UpdateFreeInfo);
  505. EventAgent.RemoveEventListener(ConstMessage.LUCKY_BOX_ACTIVITY_REWARD, UpdateBtnReward);
  506. EventAgent.RemoveEventListener(ConstMessage.ACTIVITY_LUCKY_BOX, UpdateBtnReward);
  507. }
  508. private void OnClickBtnBack()
  509. {
  510. Reset();
  511. ViewManager.GoBackFrom(typeof(LuckyBoxView).FullName);
  512. }
  513. private void OnClickBtnHome()
  514. {
  515. GameController.GoBackToMainView();
  516. }
  517. private void Reset()
  518. {
  519. LuckyBoxDataManager.Instance.currentBoxId = LuckyBoxDataManager.Instance.luckyBoxIds[0];
  520. }
  521. private void CheckGuide(object param)
  522. {
  523. if (GuideDataManager.IsGuideFinish(ConstGuideId.LUCKY_BOX) <= 0)
  524. {
  525. UpdateToCheckGuide(null);
  526. }
  527. else
  528. {
  529. Timers.inst.Remove(CheckGuide);
  530. }
  531. }
  532. protected override void UpdateToCheckGuide(object param)
  533. {
  534. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  535. GObject gObject = _ui.m_listBg.GetChildAt(_curIndex);
  536. if (gObject == null) return;
  537. GButton btnBuyTen = gObject.asCom.GetChild("comLuckBoxBtn").asCom.GetChild("btnBuyTen").asButton;
  538. GuideController.TryGuide(null, ConstGuideId.LUCKY_BOX, 1, "“摘星”里可以通过星辰的力量获得服饰。", -1, true, _ui.target.height - 600);
  539. GuideController.TryGuide(btnBuyTen, ConstGuideId.LUCKY_BOX, 2, "点击摘取十次。");
  540. }
  541. protected override void TryCompleteGuide()
  542. {
  543. base.TryCompleteGuide();
  544. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.LUCKY_BOX);
  545. GuideController.TryCompleteGuideIndex(ConstGuideId.LUCKY_BOX, 2);
  546. }
  547. private void UpdateFreeInfo()
  548. {
  549. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];
  550. LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  551. long freeTime = LuckyBoxDataManager.Instance.GetFreeTime(boxId);
  552. GObject obj = _ui.m_listBg.GetChildAt(_curIndex);
  553. UI_ComBox1 comBox = UI_ComBox1.Proxy(obj);
  554. if (freeTime > 0)
  555. {
  556. if (freeTime > TimeHelper.ServerNow())
  557. {
  558. comBox.m_comLuckBoxBtn.m_comCostOne.m_c1.selectedIndex = 0;
  559. comBox.m_comLuckBoxBtn.m_txtFreeTime.visible = true;
  560. }
  561. else
  562. {
  563. comBox.m_comLuckBoxBtn.m_comCostOne.m_c1.selectedIndex = 1;
  564. comBox.m_comLuckBoxBtn.m_txtFreeTime.visible = false;
  565. }
  566. }
  567. else
  568. {
  569. comBox.m_comLuckBoxBtn.m_comCostOne.m_c1.selectedIndex = 0;
  570. comBox.m_comLuckBoxBtn.m_txtFreeTime.visible = false;
  571. }
  572. RedDotController.Instance.SetComRedDot(comBox.m_comLuckBoxBtn.m_btnBuyOne, comBox.m_comLuckBoxBtn.m_comCostOne.m_c1.selectedIndex == 1);
  573. UI_ComBox1.ProxyEnd();
  574. }
  575. }
  576. }