LuckyBoxView.cs 28 KB

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