LuckyBoxView.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  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. var activityInfoByTypeList = ActivityGlobalDataManager.Instance.GetActivityInfoByType(ActivityType.XSLB3);
  297. var list = activityInfoByTypeList.Where(a => a.EndTime > TimeInfo.Instance.ServerNow()).ToList();
  298. if (list.Count == 0)
  299. {
  300. comBox.m_comBagTime.target.visible = false;
  301. comBox.m_btnGiftBag.visible = false;
  302. }
  303. else
  304. {
  305. bool isSoldOut = true;
  306. foreach (var activityInfo in list)
  307. {
  308. ActivityOpenCfg activityOpenCfg = ActivityOpenCfgArray.Instance.GetCfg(activityInfo.ActivityId);
  309. var paramsArr = activityOpenCfg.paramsArr;
  310. foreach (var shopCfgId in paramsArr)
  311. {
  312. var shopCfg = ShopCfgArray.Instance.GetCfg(shopCfgId);
  313. var remainBuyNum = shopCfg.maxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(shopCfgId);
  314. //只要有一个商品还能购买,就不是售罄
  315. if (remainBuyNum > 0)
  316. {
  317. isSoldOut = false;
  318. break;
  319. }
  320. }
  321. }
  322. if (isSoldOut)
  323. {
  324. comBox.m_comBagTime.target.visible = false;
  325. comBox.m_btnGiftBag.visible = false;
  326. }
  327. else
  328. {
  329. comBox.m_comBagTime.m_txtGiftBagTime.text = TimeUtil.GetTimeLeft(TimeInfo.Instance.ServerNow(), list[0].EndTime);
  330. comBox.m_comBagTime.target.visible = true;
  331. comBox.m_btnGiftBag.visible = true;
  332. }
  333. }
  334. UpdateBtnReward();
  335. }
  336. //限时礼包按钮点击执行方法
  337. private void OnClikcBtnGiftBag()
  338. {
  339. var activityInfoByTypeList =
  340. ActivityGlobalDataManager.Instance.GetActivityInfoByType(ActivityType.XSLB3);
  341. var list = activityInfoByTypeList
  342. .Where(a => a.EndTime > TimeInfo.Instance.ServerNow()).ToList();
  343. if (list.Count == 0)
  344. {
  345. PromptController.Instance.ShowFloatTextPrompt("活动已结束");
  346. }
  347. else
  348. {
  349. ViewManager.Show<RushSaleGiftBoxView>(new object[] { ActivityType.XSLB3, this.viewData });
  350. }
  351. }
  352. private void UpdateListItemData()
  353. {
  354. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];
  355. LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  356. GObject obj = _ui.m_listBg.GetChildAt(_curIndex);
  357. UI_ComBox1 comBox = UI_ComBox1.Proxy(obj);
  358. LuckyBoxDataManager.Instance.GetOwnedCount(boxId, out int count, out int totalCount);
  359. comBox.m_txtOwned.SetVar("v1", "" + count).FlushVars();
  360. comBox.m_txtOwned.SetVar("v2", "" + totalCount).FlushVars();
  361. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(cfg.numericType);
  362. comBox.m_comLuckBoxBtn.m_txtRemainTimes.text = string.Format("今日剩余次数:{0}", cfg.maxCount - boughtCount);
  363. UI_ComBox1.ProxyEnd();
  364. }
  365. private void CheckTime(object param = null)
  366. {
  367. if (LuckyBoxDataManager.Instance.currentBoxId == _activeBoxId)
  368. {
  369. if (LuckyBoxDataManager.Instance.currentBoxId != _activeBoxId) return;
  370. long endTime = LuckyBoxDataManager.Instance.endTime;
  371. long curTime = TimeHelper.ServerNow();
  372. TimeUtil.FormattingTime(curTime, endTime, out int num, out string str);
  373. GObject item = _ui.m_listBg.GetChildAt(0);
  374. if (item == null) return;
  375. GObject textField = item.asCom.GetChild("txtTime");
  376. if (textField == null) return;
  377. long time = endTime - curTime;
  378. string strTime = time > TimeUtil.SECOND_PER_DAY * 100 ? TimeUtil.FormattingTimeTo_DDHHmm(time) : TimeUtil.FormattingTimeTo_HHmmss(time);
  379. textField.asTextField.text = string.Format("活动时间:剩余{0}", strTime);
  380. }
  381. else if(LuckyBoxDataManager.Instance.currentBoxId == LuckyBoxDataManager.BOX_ID_2)
  382. {
  383. GObject item = _ui.m_listBg.GetChildAt(1);
  384. if (item == null) return;
  385. GObject textField = item.asCom.GetChild("txtTsyTime");
  386. if (textField == null) return;
  387. int activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitTsy);
  388. var activityCfg = ActivityOpenCfgArray.Instance.GetCfg(activityId);
  389. long endTime = TimeUtil.DateTimeToTimestamp(activityCfg.endTime);
  390. long curTime = TimeHelper.ServerNow();
  391. if (endTime < curTime)
  392. {
  393. PromptController.Instance.ShowFloatTextPrompt("活动已结束");
  394. Timers.inst.Remove(UpdateTime);
  395. OnClickBtnBack();
  396. return;
  397. }
  398. TimeUtil.FormattingTime(curTime, endTime, out int num, out string str);
  399. textField.asTextField.text = "概率提升剩余: " + TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);
  400. //=====限时礼包倒计时
  401. //UpGiftBox();
  402. //EventAgent.DispatchEvent(ConstMessage.LUCKY_BOX_TIME);
  403. //=====限时礼包倒计时END
  404. }
  405. }
  406. private void UpdateTime(object param = null)
  407. {
  408. }
  409. private void updateBoxEffect()
  410. {
  411. if (isActiveBoxOpen)
  412. {
  413. }
  414. }
  415. private void OnClickBtnPreview(EventContext context)
  416. {
  417. GObject obj = context.sender as GObject;
  418. int boxId = (int)obj.data;
  419. ViewManager.Show<LuckyBoxPreShowView>(boxId);
  420. }
  421. private void OnClickBtnBuyOne(EventContext context)
  422. {
  423. GObject obj = context.sender as GObject;
  424. int boxId = (int)obj.data;
  425. LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  426. long freeTime = LuckyBoxDataManager.Instance.GetFreeTime(boxId);
  427. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(luckyBoxCfg.numericType);
  428. if (boughtCount + LuckyBoxDataManager.ONCE_TIME > luckyBoxCfg.maxCount)
  429. {
  430. PromptController.Instance.ShowFloatTextPrompt("抽奖次数不足");
  431. return;
  432. }
  433. LuckyBoxDataManager.Instance.CheckItemEnough(boxId, LuckyBoxDataManager.ONCE_TIME, async () =>
  434. {
  435. int activityId = 0;
  436. if (boxId == LuckyBoxDataManager.BOX_ID_2) {
  437. activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitTsy);
  438. }
  439. bool freeType = (freeTime > 0 && freeTime < TimeHelper.ServerNow());
  440. bool result = await LuckyBoxSProxy.ReqGetBonus(boxId, LuckyBoxDataManager.ONCE_TIME, freeType, activityId);
  441. if (result)
  442. {
  443. ViewManager.Show<LuckyBoxStarView>(null, new object[] { typeof(LuckyBoxView).FullName, boxId });
  444. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 2);
  445. }
  446. });
  447. }
  448. private void OnClickBtnBuyTen(EventContext context)
  449. {
  450. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.LUCKY_BOX);
  451. if (GuideDataManager.IsGuideFinish(ConstGuideId.LUCKY_BOX) <= 0 && (GuideDataManager.currentGuideId == 0 || GuideDataManager.currentGuideIdIndex != 2))
  452. {
  453. //防止点击太快,在引导开启前就被点击到,导致引导卡死
  454. return;
  455. }
  456. GObject obj = context.sender as GObject;
  457. int boxId = (int)obj.data;
  458. LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  459. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(luckyBoxCfg.numericType);
  460. if (boughtCount + LuckyBoxDataManager.TEN_TIME > luckyBoxCfg.maxCount)
  461. {
  462. PromptController.Instance.ShowFloatTextPrompt("抽奖次数不足");
  463. return;
  464. }
  465. LuckyBoxDataManager.Instance.CheckItemEnough(boxId, LuckyBoxDataManager.TEN_TIME, async () =>
  466. {
  467. int activityId = 0;
  468. if (boxId == LuckyBoxDataManager.BOX_ID_2)
  469. {
  470. activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitTsy);
  471. }
  472. bool result = await LuckyBoxSProxy.ReqGetBonus(boxId, LuckyBoxDataManager.TEN_TIME,false, activityId);
  473. if (result)
  474. {
  475. ViewManager.Show<LuckyBoxStarView>(null, new object[] { typeof(LuckyBoxView).FullName, boxId });
  476. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 2);
  477. }
  478. });
  479. }
  480. protected override void OnHide()
  481. {
  482. base.OnHide();
  483. _valueBarController.OnHide();
  484. foreach (int key in _lcukyBoxCtrl.Keys)
  485. {
  486. _lcukyBoxCtrl[key].OnHide();
  487. }
  488. Timers.inst.Remove(OnTimerUpdate);
  489. Timers.inst.Remove(CheckTime);
  490. // Timers.inst.Remove(UpdateBg);
  491. Timers.inst.Remove(CheckGuide);
  492. // Timers.inst.Remove(UpdateTime);
  493. Debug.Log("OnHide: LuckyBoxView");
  494. }
  495. protected override void RemoveEventListener()
  496. {
  497. base.RemoveEventListener();
  498. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateListItemData);
  499. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateListItemData);
  500. EventAgent.RemoveEventListener(ConstMessage.LUCKY_BOX_FREE_TIME_CHANGED, UpdateFreeInfo);
  501. EventAgent.RemoveEventListener(ConstMessage.LUCKY_BOX_ACTIVITY_REWARD, UpdateBtnReward);
  502. EventAgent.RemoveEventListener(ConstMessage.ACTIVITY_LUCKY_BOX, UpdateBtnReward);
  503. }
  504. private void OnClickBtnBack()
  505. {
  506. Reset();
  507. //this.Hide();
  508. ViewManager.GoBackFrom(typeof(LuckyBoxView).FullName);
  509. }
  510. private void OnClickBtnHome()
  511. {
  512. GameController.GoBackToMainView();
  513. }
  514. private void Reset()
  515. {
  516. LuckyBoxDataManager.Instance.currentBoxId = LuckyBoxDataManager.Instance.luckyBoxIds[0];
  517. }
  518. private void CheckGuide(object param)
  519. {
  520. if (GuideDataManager.IsGuideFinish(ConstGuideId.LUCKY_BOX) <= 0)
  521. {
  522. UpdateToCheckGuide(null);
  523. }
  524. else
  525. {
  526. Timers.inst.Remove(CheckGuide);
  527. }
  528. }
  529. protected override void UpdateToCheckGuide(object param)
  530. {
  531. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  532. GObject gObject = _ui.m_listBg.GetChildAt(_curIndex);
  533. if (gObject == null) return;
  534. GButton btnBuyTen = gObject.asCom.GetChild("comLuckBoxBtn").asCom.GetChild("btnBuyTen").asButton;
  535. GuideController.TryGuide(null, ConstGuideId.LUCKY_BOX, 1, "“摘星”里可以通过星辰的力量获得服饰。", -1, true, _ui.target.height - 600);
  536. GuideController.TryGuide(btnBuyTen, ConstGuideId.LUCKY_BOX, 2, "点击摘取十次。");
  537. }
  538. protected override void TryCompleteGuide()
  539. {
  540. base.TryCompleteGuide();
  541. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.LUCKY_BOX);
  542. GuideController.TryCompleteGuideIndex(ConstGuideId.LUCKY_BOX, 2);
  543. }
  544. private void UpdateFreeInfo()
  545. {
  546. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];
  547. LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  548. long freeTime = LuckyBoxDataManager.Instance.GetFreeTime(boxId);
  549. GObject obj = _ui.m_listBg.GetChildAt(_curIndex);
  550. UI_ComBox1 comBox = UI_ComBox1.Proxy(obj);
  551. if (freeTime > 0)
  552. {
  553. if (freeTime > TimeHelper.ServerNow())
  554. {
  555. comBox.m_comLuckBoxBtn.m_comCostOne.m_c1.selectedIndex = 0;
  556. comBox.m_comLuckBoxBtn.m_txtFreeTime.visible = true;
  557. }
  558. else
  559. {
  560. comBox.m_comLuckBoxBtn.m_comCostOne.m_c1.selectedIndex = 1;
  561. comBox.m_comLuckBoxBtn.m_txtFreeTime.visible = false;
  562. }
  563. }
  564. else
  565. {
  566. comBox.m_comLuckBoxBtn.m_comCostOne.m_c1.selectedIndex = 0;
  567. comBox.m_comLuckBoxBtn.m_txtFreeTime.visible = false;
  568. }
  569. RedDotController.Instance.SetComRedDot(comBox.m_comLuckBoxBtn.m_btnBuyOne, comBox.m_comLuckBoxBtn.m_comCostOne.m_c1.selectedIndex == 1);
  570. UI_ComBox1.ProxyEnd();
  571. }
  572. }
  573. }