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. 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. comBox.m_showActivityType.selectedIndex = 1;
  209. UpGiftBox(comBox);
  210. if (comBox.m_btnRule.data == null)
  211. {
  212. comBox.m_btnRule.onClick.Add(RuleController.ShowRuleView);
  213. comBox.m_btnRule.data = 300024;
  214. }
  215. }
  216. else
  217. comBox.m_showActivityType.selectedIndex = 0;
  218. if (!_lcukyBoxCtrl.ContainsKey(boxId))
  219. {
  220. _lcukyBoxCtrl.Add(boxId, new LuckyBoxController(comBox.m_comModel.target));
  221. }
  222. _lcukyBoxCtrl[LuckyBoxDataManager.Instance.currentBoxId].OnShown(LuckyBoxDataManager.Instance.currentBoxId);
  223. comBox.m_comLuckBoxBtn.m_imgSpecial.visible = boxId != LuckyBoxDataManager.BOX_ID_3;
  224. //GGraph holder = comBox.m_comLuckBoxBtn.m_btnBuyTen.GetChild("holder").asGraph;
  225. //holder.visible = boxId != LuckyBoxDataManager.BOX_ID_3;
  226. comBox.m_comLuckBoxBtn.m_holder.visible = boxId != LuckyBoxDataManager.BOX_ID_3;
  227. //_effectUI1 = EffectUIPool.CreateEffectUI(holder, "ui_LuckyBox", "Button_Glow");
  228. _effectUI2 = EffectUIPool.CreateEffectUI(comBox.m_comLuckBoxBtn.m_holder, "ui_LuckyBox", "but_text_dc");
  229. comBox.m_comLuckBoxBtn.m_comCostOne.m_txtCost.text = cfg.costNum.ToString();
  230. comBox.m_comLuckBoxBtn.m_comCostOne.m_loaCost.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(cfg.costID).res);
  231. comBox.m_comLuckBoxBtn.m_comCostTen.m_txtCost.text = cfg.costNumTen.ToString();
  232. comBox.m_comLuckBoxBtn.m_comCostTen.m_loaCost.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(cfg.costID).res);
  233. if (comBox.m_comLuckBoxBtn.m_btnBuyOne.data == null)
  234. {
  235. comBox.m_comLuckBoxBtn.m_btnBuyOne.onClick.Add(OnClickBtnBuyOne);
  236. }
  237. comBox.m_comLuckBoxBtn.m_btnBuyOne.data = boxId;
  238. if (comBox.m_comLuckBoxBtn.m_btnBuyTen.data == null)
  239. {
  240. comBox.m_comLuckBoxBtn.m_btnBuyTen.onClick.Add(OnClickBtnBuyTen);
  241. }
  242. comBox.m_comLuckBoxBtn.m_btnBuyTen.data = boxId;
  243. if (comBox.m_btnPreview.data == null)
  244. {
  245. comBox.m_btnPreview.onClick.Add(OnClickBtnPreview);
  246. }
  247. comBox.m_btnPreview.data = boxId;
  248. if (comBox.m_btnReward.data == null)
  249. {
  250. comBox.m_btnReward.onClick.Add(OnClikcBtnReward);
  251. comBox.m_btnShop.onClick.Add(OnClikcBtnShop);
  252. comBox.m_btnGiftBag.onClick.Add(OnClikcBtnGiftBag);
  253. }
  254. comBox.m_btnReward.data = boxId;
  255. obj.data = boxId;
  256. comBox.m_grpTime.visible = (boxId == _activeBoxId);
  257. if (boxId == _activeBoxId)
  258. {
  259. long endTime = LuckyBoxDataManager.Instance.endTime;
  260. long curTime = TimeHelper.ServerNow();
  261. // TimeUtil.FormattingTime(curTime, endTime, out int num, out string str);
  262. long time = endTime - curTime;
  263. string strTime = time > TimeUtil.SECOND_PER_DAY * 100 ? TimeUtil.FormattingTimeTo_DDHHmm(time) : TimeUtil.FormattingTimeTo_HHmmss(time);
  264. comBox.m_txtTime.text = string.Format("活动时间:剩余{0}", strTime);
  265. comBox.m_loaTitle.url = "ui://LuckyBox/zx_title_1";
  266. }
  267. else
  268. {
  269. comBox.m_loaTitle.url = string.Format("ui://LuckyBox/zx_title_{0}", boxId);
  270. }
  271. UI_ComBox1.ProxyEnd();
  272. UpdateListItemData();
  273. UpdateFreeInfo();
  274. }
  275. private void UpdateBtnReward()
  276. {
  277. if (_curIndex == 1) {
  278. GObject obj = _ui.m_listBg.GetChildAt(_curIndex);
  279. UI_ComBox1 comBox = UI_ComBox1.Proxy(obj);
  280. RedDotController.Instance.SetComRedDot(comBox.m_btnReward, RedDotDataManager.Instance.GetActLuckyBoxRewardRed(ConstLimitTimeActivityType.ActLimitTsy));
  281. comBox.m_txtCount.SetVar("value", ActivityDataManager.Instance.lastTsyDrawCount.ToString()).FlushVars();
  282. }
  283. }
  284. private void OnClikcBtnReward()
  285. {
  286. ViewManager.Show<ActivityThemeLuckyBoxBonusView>(ConstLimitTimeActivityType.ActLimitTsy);
  287. }
  288. private void OnClikcBtnShop()
  289. {
  290. ViewManager.Show<StoreView>(new object[] { ConstStoreTabId.STORE_GIFT_BAG, ConstStoreSubId.STORE_GIFT_BAG_ACTIVITY }, new object[] { typeof(LuckyBoxView).FullName });
  291. }
  292. //刷新摘星活动期间的数据
  293. private void UpGiftBox(UI_ComBox1 comBox)
  294. {
  295. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];
  296. LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  297. comBox.m_txtCount.SetVar("value", ActivityDataManager.Instance.lastTsyDrawCount.ToString()).FlushVars();
  298. comBox.m_txtCount.SetVar("name", cfg.name).FlushVars();
  299. var activityInfoByTypeList = ActivityGlobalDataManager.Instance.GetActivityInfoByType(ActivityType.XSLB3);
  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 result = false;
  443. if (freeTime > 0 && freeTime < TimeHelper.ServerNow())
  444. result = await LuckyBoxSProxy.ReqGetBonus(boxId, LuckyBoxDataManager.ONCE_TIME, true, activityId);
  445. else
  446. result = await LuckyBoxSProxy.ReqGetBonus(boxId, LuckyBoxDataManager.ONCE_TIME,false, activityId);
  447. if (result)
  448. {
  449. ViewManager.Show<LuckyBoxStarView>(null, new object[] { typeof(LuckyBoxView).FullName, boxId });
  450. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 2);
  451. }
  452. });
  453. }
  454. private void OnClickBtnBuyTen(EventContext context)
  455. {
  456. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.LUCKY_BOX);
  457. if (GuideDataManager.IsGuideFinish(ConstGuideId.LUCKY_BOX) <= 0 && (GuideDataManager.currentGuideId == 0 || GuideDataManager.currentGuideIdIndex != 2))
  458. {
  459. //防止点击太快,在引导开启前就被点击到,导致引导卡死
  460. return;
  461. }
  462. GObject obj = context.sender as GObject;
  463. int boxId = (int)obj.data;
  464. LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  465. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(luckyBoxCfg.numericType);
  466. if (boughtCount + LuckyBoxDataManager.TEN_TIME > luckyBoxCfg.maxCount)
  467. {
  468. PromptController.Instance.ShowFloatTextPrompt("抽奖次数不足");
  469. return;
  470. }
  471. LuckyBoxDataManager.Instance.CheckItemEnough(boxId, LuckyBoxDataManager.TEN_TIME, async () =>
  472. {
  473. int activityId = 0;
  474. if (boxId == LuckyBoxDataManager.BOX_ID_2)
  475. {
  476. activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitTsy);
  477. }
  478. bool result = await LuckyBoxSProxy.ReqGetBonus(boxId, LuckyBoxDataManager.TEN_TIME,false, activityId);
  479. if (result)
  480. {
  481. ViewManager.Show<LuckyBoxStarView>(null, new object[] { typeof(LuckyBoxView).FullName, boxId });
  482. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 2);
  483. }
  484. });
  485. }
  486. protected override void OnHide()
  487. {
  488. base.OnHide();
  489. _valueBarController.OnHide();
  490. foreach (int key in _lcukyBoxCtrl.Keys)
  491. {
  492. _lcukyBoxCtrl[key].OnHide();
  493. }
  494. Timers.inst.Remove(OnTimerUpdate);
  495. Timers.inst.Remove(CheckTime);
  496. // Timers.inst.Remove(UpdateBg);
  497. Timers.inst.Remove(CheckGuide);
  498. // Timers.inst.Remove(UpdateTime);
  499. Debug.Log("OnHide: LuckyBoxView");
  500. }
  501. protected override void RemoveEventListener()
  502. {
  503. base.RemoveEventListener();
  504. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateListItemData);
  505. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateListItemData);
  506. EventAgent.RemoveEventListener(ConstMessage.LUCKY_BOX_FREE_TIME_CHANGED, UpdateFreeInfo);
  507. EventAgent.RemoveEventListener(ConstMessage.LUCKY_BOX_ACTIVITY_REWARD, UpdateBtnReward);
  508. EventAgent.RemoveEventListener(ConstMessage.ACTIVITY_LUCKY_BOX, UpdateBtnReward);
  509. }
  510. private void OnClickBtnBack()
  511. {
  512. Reset();
  513. 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. }