LuckyBoxView.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  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. }
  84. protected override void OnShown()
  85. {
  86. base.OnShown();
  87. Debug.Log("OnShown:LuckyBoxView");
  88. LuckyBoxDataManager.Instance.luckyBoxIds.Clear();
  89. LuckyBoxDataManager.Instance.luckyBoxIds.Add(LuckyBoxDataManager.BOX_ID_2);
  90. LuckyBoxDataManager.Instance.luckyBoxIds.Add(LuckyBoxDataManager.BOX_ID_3);
  91. _activeBoxId = 0;
  92. int activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitTsy);
  93. if (activityId > 0)
  94. GetWishingPoolInfo(activityId);
  95. if (LuckyBoxDataManager.Instance.RotatingId > 0)
  96. {
  97. RotatingLuckyBoxCfg rotatingLuckyBox = RotatingLuckyBoxCfgArray.Instance.GetCfg(LuckyBoxDataManager.Instance.RotatingId);
  98. _activeBoxId = rotatingLuckyBox.luckyBoxId;
  99. LuckyBoxDataManager.Instance.endTime = TimeUtil.GetTimestamp(rotatingLuckyBox.endTime);
  100. LuckyBoxDataManager.Instance.luckyBoxIds.Insert(0, _activeBoxId);
  101. }
  102. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[1];
  103. if (this.viewData != null)
  104. {
  105. boxId = (int)this.viewData;
  106. }
  107. if (GuideDataManager.IsGuideFinish(ConstGuideId.LUCKY_BOX) <= 0) boxId = LuckyBoxDataManager.BOX_ID_2;
  108. LuckyBoxDataManager.Instance.currentBoxId = boxId;
  109. if (_activeBoxId > 0 || boxId == LuckyBoxDataManager.BOX_ID_2) Timers.inst.Add(1, 0, CheckTime);
  110. _valueBarController.OnShown();
  111. _valueBarController.Controller(4);
  112. _curIndex = LuckyBoxDataManager.Instance.luckyBoxIds.IndexOf(boxId);
  113. _ui.m_listBg.numItems = LuckyBoxDataManager.Instance.luckyBoxIds.Count;
  114. _ui.m_listBg.ScrollToView(_curIndex);
  115. _ui.m_listBg.scrollPane.decelerationRate = 0.8f;
  116. LuckyBoxDataManager.Instance.luckyBoxIndex = _curIndex;
  117. OnListBgScroll();
  118. updateBoxEffect();
  119. Timers.inst.AddUpdate(CheckGuide);
  120. Timers.inst.Add(1f, 0, OnTimerUpdate, 1);
  121. }
  122. private async void GetWishingPoolInfo(int activityId)
  123. {
  124. bool result = await LuckyBoxSProxy.ReqGetWishingPoolInfo();
  125. if (result)
  126. {
  127. int index = LuckyBoxDataManager.Instance.KsActivityId.IndexOf(activityId);
  128. if (index < 0 || !LuckyBoxDataManager.Instance.VsStatus[index])
  129. ViewManager.Show<LuckyBoxWishView>(ConstLimitTimeActivityType.ActLimitTsy);
  130. }
  131. }
  132. private void OnTimerUpdate(object param)
  133. {
  134. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];
  135. long freeTime = LuckyBoxDataManager.Instance.GetFreeTime(boxId);
  136. GObject obj = _ui.m_listBg.GetChildAt(_curIndex);
  137. UI_ComBox1 comBox = UI_ComBox1.Proxy(obj);
  138. if (freeTime > 0)
  139. {
  140. long timeDifference = freeTime - TimeHelper.ServerNow();
  141. if (timeDifference> 0)
  142. {
  143. comBox.m_comLuckBoxBtn.m_comCostOne.m_c1.selectedIndex = 0;
  144. comBox.m_comLuckBoxBtn.m_txtFreeTime.visible = true;
  145. string strFreeTime = TimeUtil.FormattingTimeTo_HHmmss(timeDifference);
  146. comBox.m_comLuckBoxBtn.m_txtFreeTime.text = string.Format("{0}后免费", strFreeTime);
  147. }
  148. else
  149. {
  150. comBox.m_comLuckBoxBtn.m_comCostOne.m_c1.selectedIndex = 1;
  151. comBox.m_comLuckBoxBtn.m_txtFreeTime.visible = false;
  152. }
  153. }
  154. UI_ComBox1.ProxyEnd();
  155. }
  156. private void RenderListBgItem(int index, GObject obj)
  157. {
  158. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[index];
  159. }
  160. private void OnBtnLeftClick()
  161. {
  162. int index = _curIndex - 1;
  163. if (index < 0) return;
  164. _ui.m_listBg.ScrollToView(index, true);
  165. }
  166. private void OnBtnRightClick()
  167. {
  168. int index = _curIndex + 1;
  169. // if (index >= LuckyBoxDataManager.Instance.luckyBoxIds.Count) return;
  170. index = Mathf.Min(_ui.m_listBg.numItems - 1, index);
  171. _ui.m_listBg.ScrollToView(index, true);
  172. }
  173. private void OnListBgScroll()
  174. {
  175. if (_lcukyBoxCtrl.ContainsKey(LuckyBoxDataManager.Instance.currentBoxId)) _lcukyBoxCtrl[LuckyBoxDataManager.Instance.currentBoxId].OnHide();
  176. _curIndex = _ui.m_listBg.GetFirstChildInView();
  177. LuckyBoxDataManager.Instance.currentBoxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];
  178. if (LuckyBoxDataManager.Instance.currentBoxId == LuckyBoxDataManager.BOX_ID_3)
  179. {
  180. _valueBarController.Controller(3);
  181. }
  182. else
  183. {
  184. _valueBarController.Controller(4);
  185. }
  186. _valueBarController.UpdateCJ();
  187. UpdateListItem();
  188. _ui.m_btnLeft.grayed = _curIndex <= 0;
  189. _ui.m_btnRight.grayed = _curIndex >= _ui.m_listBg.numItems - 1;
  190. LuckyBoxDataManager.Instance.luckyBoxIndex = _curIndex;
  191. }
  192. private void UpdateListItem()
  193. {
  194. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];
  195. LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  196. LuckyBoxDataManager.Instance.InitData(boxId);
  197. GObject obj = _ui.m_listBg.GetChildAt(_curIndex);
  198. UI_ComBox1 comBox = UI_ComBox1.Proxy(obj);
  199. int activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitTsy);
  200. if (activityId > 0 && boxId == LuckyBoxDataManager.BOX_ID_2) {
  201. comBox.m_showActivityType.selectedIndex = 1;
  202. UpGiftBox(comBox);
  203. }
  204. else
  205. comBox.m_showActivityType.selectedIndex = 0;
  206. if (!_lcukyBoxCtrl.ContainsKey(boxId))
  207. {
  208. _lcukyBoxCtrl.Add(boxId, new LuckyBoxController(comBox.m_comModel.target));
  209. }
  210. _lcukyBoxCtrl[LuckyBoxDataManager.Instance.currentBoxId].OnShown(LuckyBoxDataManager.Instance.currentBoxId);
  211. comBox.m_comLuckBoxBtn.m_imgSpecial.visible = boxId != LuckyBoxDataManager.BOX_ID_3;
  212. //GGraph holder = comBox.m_comLuckBoxBtn.m_btnBuyTen.GetChild("holder").asGraph;
  213. //holder.visible = boxId != LuckyBoxDataManager.BOX_ID_3;
  214. comBox.m_comLuckBoxBtn.m_holder.visible = boxId != LuckyBoxDataManager.BOX_ID_3;
  215. //_effectUI1 = EffectUIPool.CreateEffectUI(holder, "ui_LuckyBox", "Button_Glow");
  216. _effectUI2 = EffectUIPool.CreateEffectUI(comBox.m_comLuckBoxBtn.m_holder, "ui_LuckyBox", "but_text_dc");
  217. comBox.m_comLuckBoxBtn.m_comCostOne.m_txtCost.text = cfg.costNum.ToString();
  218. comBox.m_comLuckBoxBtn.m_comCostOne.m_loaCost.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(cfg.costID).res);
  219. comBox.m_comLuckBoxBtn.m_comCostTen.m_txtCost.text = cfg.costNumTen.ToString();
  220. comBox.m_comLuckBoxBtn.m_comCostTen.m_loaCost.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(cfg.costID).res);
  221. if (comBox.m_comLuckBoxBtn.m_btnBuyOne.data == null)
  222. {
  223. comBox.m_comLuckBoxBtn.m_btnBuyOne.onClick.Add(OnClickBtnBuyOne);
  224. }
  225. comBox.m_comLuckBoxBtn.m_btnBuyOne.data = boxId;
  226. if (comBox.m_comLuckBoxBtn.m_btnBuyTen.data == null)
  227. {
  228. comBox.m_comLuckBoxBtn.m_btnBuyTen.onClick.Add(OnClickBtnBuyTen);
  229. }
  230. comBox.m_comLuckBoxBtn.m_btnBuyTen.data = boxId;
  231. if (comBox.m_btnPreview.data == null)
  232. {
  233. comBox.m_btnPreview.onClick.Add(OnClickBtnPreview);
  234. }
  235. comBox.m_btnPreview.data = boxId;
  236. if (comBox.m_btnReward.data == null)
  237. {
  238. comBox.m_btnReward.onClick.Add(OnClikcBtnReward);
  239. comBox.m_btnShop.onClick.Add(OnClikcBtnShop);
  240. comBox.m_btnGiftBag.onClick.Add(OnClikcBtnGiftBag);
  241. }
  242. comBox.m_btnReward.data = boxId;
  243. obj.data = boxId;
  244. comBox.m_grpTime.visible = (boxId == _activeBoxId);
  245. if (boxId == _activeBoxId)
  246. {
  247. long endTime = LuckyBoxDataManager.Instance.endTime;
  248. long curTime = TimeHelper.ServerNow();
  249. // TimeUtil.FormattingTime(curTime, endTime, out int num, out string str);
  250. long time = endTime - curTime;
  251. string strTime = time > TimeUtil.SECOND_PER_DAY * 100 ? TimeUtil.FormattingTimeTo_DDHHmm(time) : TimeUtil.FormattingTimeTo_HHmmss(time);
  252. comBox.m_txtTime.text = string.Format("活动时间:剩余{0}", strTime);
  253. comBox.m_loaTitle.url = "ui://LuckyBox/zx_title_1";
  254. }
  255. else
  256. {
  257. comBox.m_loaTitle.url = string.Format("ui://LuckyBox/zx_title_{0}", boxId);
  258. }
  259. UI_ComBox1.ProxyEnd();
  260. UpdateListItemData();
  261. UpdateFreeInfo();
  262. RedDotController.Instance.SetComRedDot(comBox.m_btnReward, RedDotDataManager.Instance.GetActLuckyBoxRewardRed(ConstLimitTimeActivityType.ActLimitTsy));
  263. }
  264. private void OnClikcBtnReward()
  265. {
  266. ViewManager.Show<ActivityThemeLuckyBoxBonusView>(ConstLimitTimeActivityType.ActLimitTsy);
  267. }
  268. private void OnClikcBtnShop()
  269. {
  270. ViewManager.Show<StoreView>(new object[] { ConstStoreTabId.STORE_GIFT_BAG, ConstStoreSubId.STORE_GIFT_BAG_ACTIVITY }, new object[] { typeof(LuckyBoxView).FullName });
  271. }
  272. //刷新摘星活动期间的数据
  273. private void UpGiftBox(UI_ComBox1 comBox)
  274. {
  275. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];
  276. LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  277. comBox.m_txtCount.SetVar("value", ActivityDataManager.Instance.lastTsyDrawCount.ToString()).FlushVars();
  278. comBox.m_txtCount.SetVar("name", cfg.name).FlushVars();
  279. var activityInfoByTypeList = ActivityGlobalDataManager.Instance.GetActivityInfoByType(ActivityType.XSLB3);
  280. var list = activityInfoByTypeList.Where(a => a.EndTime > TimeInfo.Instance.ServerNow()).ToList();
  281. if (list.Count == 0)
  282. {
  283. comBox.m_comBagTime.target.visible = false;
  284. comBox.m_btnGiftBag.visible = false;
  285. }
  286. else
  287. {
  288. bool isSoldOut = true;
  289. foreach (var activityInfo in list)
  290. {
  291. ActivityOpenCfg activityOpenCfg = ActivityOpenCfgArray.Instance.GetCfg(activityInfo.ActivityId);
  292. var paramsArr = activityOpenCfg.paramsArr;
  293. foreach (var shopCfgId in paramsArr)
  294. {
  295. var shopCfg = ShopCfgArray.Instance.GetCfg(shopCfgId);
  296. var remainBuyNum = shopCfg.maxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(shopCfgId);
  297. //只要有一个商品还能购买,就不是售罄
  298. if (remainBuyNum > 0)
  299. {
  300. isSoldOut = false;
  301. break;
  302. }
  303. }
  304. }
  305. if (isSoldOut)
  306. {
  307. comBox.m_comBagTime.target.visible = false;
  308. comBox.m_btnGiftBag.visible = false;
  309. }
  310. else
  311. {
  312. comBox.m_comBagTime.m_txtGiftBagTime.text = TimeUtil.GetTimeLeft(TimeInfo.Instance.ServerNow(), list[0].EndTime);
  313. comBox.m_comBagTime.target.visible = true;
  314. comBox.m_btnGiftBag.visible = true;
  315. }
  316. }
  317. }
  318. //限时礼包按钮点击执行方法
  319. private void OnClikcBtnGiftBag()
  320. {
  321. var activityInfoByTypeList =
  322. ActivityGlobalDataManager.Instance.GetActivityInfoByType(ActivityType.XSLB3);
  323. var list = activityInfoByTypeList
  324. .Where(a => a.EndTime > TimeInfo.Instance.ServerNow()).ToList();
  325. if (list.Count == 0)
  326. {
  327. PromptController.Instance.ShowFloatTextPrompt("活动已结束");
  328. }
  329. else
  330. {
  331. ViewManager.Show<RushSaleGiftBoxView>(new object[] { ActivityType.XSLB3, this.viewData });
  332. }
  333. }
  334. private void UpdateListItemData()
  335. {
  336. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];
  337. LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  338. GObject obj = _ui.m_listBg.GetChildAt(_curIndex);
  339. UI_ComBox1 comBox = UI_ComBox1.Proxy(obj);
  340. LuckyBoxDataManager.Instance.GetOwnedCount(boxId, out int count, out int totalCount);
  341. comBox.m_txtOwned.SetVar("v1", "" + count).FlushVars();
  342. comBox.m_txtOwned.SetVar("v2", "" + totalCount).FlushVars();
  343. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(cfg.numericType);
  344. comBox.m_comLuckBoxBtn.m_txtRemainTimes.text = string.Format("今日剩余次数:{0}", cfg.maxCount - boughtCount);
  345. UI_ComBox1.ProxyEnd();
  346. }
  347. private void CheckTime(object param = null)
  348. {
  349. if (LuckyBoxDataManager.Instance.currentBoxId == _activeBoxId)
  350. {
  351. if (LuckyBoxDataManager.Instance.currentBoxId != _activeBoxId) return;
  352. long endTime = LuckyBoxDataManager.Instance.endTime;
  353. long curTime = TimeHelper.ServerNow();
  354. TimeUtil.FormattingTime(curTime, endTime, out int num, out string str);
  355. GObject item = _ui.m_listBg.GetChildAt(0);
  356. if (item == null) return;
  357. GObject textField = item.asCom.GetChild("txtTime");
  358. if (textField == null) return;
  359. long time = endTime - curTime;
  360. string strTime = time > TimeUtil.SECOND_PER_DAY * 100 ? TimeUtil.FormattingTimeTo_DDHHmm(time) : TimeUtil.FormattingTimeTo_HHmmss(time);
  361. textField.asTextField.text = string.Format("活动时间:剩余{0}", strTime);
  362. }
  363. else if(LuckyBoxDataManager.Instance.currentBoxId == LuckyBoxDataManager.BOX_ID_2)
  364. {
  365. GObject item = _ui.m_listBg.GetChildAt(1);
  366. if (item == null) return;
  367. GObject textField = item.asCom.GetChild("txtTsyTime");
  368. if (textField == null) return;
  369. int activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitTsy);
  370. var activityCfg = ActivityOpenCfgArray.Instance.GetCfg(activityId);
  371. long endTime = TimeUtil.DateTimeToTimestamp(activityCfg.endTime);
  372. long curTime = TimeHelper.ServerNow();
  373. if (endTime < curTime)
  374. {
  375. PromptController.Instance.ShowFloatTextPrompt("活动已结束");
  376. Timers.inst.Remove(UpdateTime);
  377. OnClickBtnBack();
  378. return;
  379. }
  380. TimeUtil.FormattingTime(curTime, endTime, out int num, out string str);
  381. textField.asTextField.text = "概率提升剩余: " + TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);
  382. //=====限时礼包倒计时
  383. //UpGiftBox();
  384. //EventAgent.DispatchEvent(ConstMessage.LUCKY_BOX_TIME);
  385. //=====限时礼包倒计时END
  386. }
  387. }
  388. private void UpdateTime(object param = null)
  389. {
  390. }
  391. private void updateBoxEffect()
  392. {
  393. if (isActiveBoxOpen)
  394. {
  395. }
  396. }
  397. private void OnClickBtnPreview(EventContext context)
  398. {
  399. GObject obj = context.sender as GObject;
  400. int boxId = (int)obj.data;
  401. ViewManager.Show<LuckyBoxPreShowView>(boxId);
  402. }
  403. private void OnClickBtnBuyOne(EventContext context)
  404. {
  405. GObject obj = context.sender as GObject;
  406. int boxId = (int)obj.data;
  407. LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  408. long freeTime = LuckyBoxDataManager.Instance.GetFreeTime(boxId);
  409. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(luckyBoxCfg.numericType);
  410. if (boughtCount + LuckyBoxDataManager.ONCE_TIME > luckyBoxCfg.maxCount)
  411. {
  412. PromptController.Instance.ShowFloatTextPrompt("抽奖次数不足");
  413. return;
  414. }
  415. LuckyBoxDataManager.Instance.CheckItemEnough(boxId, LuckyBoxDataManager.ONCE_TIME, async () =>
  416. {
  417. int activityId = 0;
  418. if (boxId == LuckyBoxDataManager.BOX_ID_2) {
  419. activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitTsy);
  420. }
  421. bool result = false;
  422. if (freeTime > 0 && freeTime < TimeHelper.ServerNow())
  423. result = await LuckyBoxSProxy.ReqGetBonus(boxId, LuckyBoxDataManager.ONCE_TIME, true, activityId);
  424. else
  425. result = await LuckyBoxSProxy.ReqGetBonus(boxId, LuckyBoxDataManager.ONCE_TIME,false, activityId);
  426. if (result)
  427. {
  428. ViewManager.Show<LuckyBoxStarView>(null, new object[] { typeof(LuckyBoxView).FullName, boxId });
  429. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 2);
  430. }
  431. });
  432. }
  433. private void OnClickBtnBuyTen(EventContext context)
  434. {
  435. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.LUCKY_BOX);
  436. if (GuideDataManager.IsGuideFinish(ConstGuideId.LUCKY_BOX) <= 0 && (GuideDataManager.currentGuideId == 0 || GuideDataManager.currentGuideIdIndex != 2))
  437. {
  438. //防止点击太快,在引导开启前就被点击到,导致引导卡死
  439. return;
  440. }
  441. GObject obj = context.sender as GObject;
  442. int boxId = (int)obj.data;
  443. LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  444. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(luckyBoxCfg.numericType);
  445. if (boughtCount + LuckyBoxDataManager.TEN_TIME > luckyBoxCfg.maxCount)
  446. {
  447. PromptController.Instance.ShowFloatTextPrompt("抽奖次数不足");
  448. return;
  449. }
  450. LuckyBoxDataManager.Instance.CheckItemEnough(boxId, LuckyBoxDataManager.TEN_TIME, async () =>
  451. {
  452. int activityId = 0;
  453. if (boxId == LuckyBoxDataManager.BOX_ID_2)
  454. {
  455. activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitTsy);
  456. }
  457. bool result = await LuckyBoxSProxy.ReqGetBonus(boxId, LuckyBoxDataManager.TEN_TIME,false, activityId);
  458. if (result)
  459. {
  460. ViewManager.Show<LuckyBoxStarView>(null, new object[] { typeof(LuckyBoxView).FullName, boxId });
  461. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 2);
  462. }
  463. });
  464. }
  465. protected override void OnHide()
  466. {
  467. base.OnHide();
  468. _valueBarController.OnHide();
  469. foreach (int key in _lcukyBoxCtrl.Keys)
  470. {
  471. _lcukyBoxCtrl[key].OnHide();
  472. }
  473. Timers.inst.Remove(OnTimerUpdate);
  474. Timers.inst.Remove(CheckTime);
  475. // Timers.inst.Remove(UpdateBg);
  476. Timers.inst.Remove(CheckGuide);
  477. // Timers.inst.Remove(UpdateTime);
  478. Debug.Log("OnHide: LuckyBoxView");
  479. }
  480. protected override void RemoveEventListener()
  481. {
  482. base.RemoveEventListener();
  483. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateListItemData);
  484. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateListItemData);
  485. EventAgent.RemoveEventListener(ConstMessage.LUCKY_BOX_FREE_TIME_CHANGED, UpdateFreeInfo);
  486. }
  487. private void OnClickBtnBack()
  488. {
  489. Reset();
  490. ViewManager.GoBackFrom(typeof(LuckyBoxView).FullName);
  491. }
  492. private void OnClickBtnHome()
  493. {
  494. GameController.GoBackToMainView();
  495. }
  496. private void Reset()
  497. {
  498. LuckyBoxDataManager.Instance.currentBoxId = LuckyBoxDataManager.Instance.luckyBoxIds[0];
  499. }
  500. private void CheckGuide(object param)
  501. {
  502. if (GuideDataManager.IsGuideFinish(ConstGuideId.LUCKY_BOX) <= 0)
  503. {
  504. UpdateToCheckGuide(null);
  505. }
  506. else
  507. {
  508. Timers.inst.Remove(CheckGuide);
  509. }
  510. }
  511. protected override void UpdateToCheckGuide(object param)
  512. {
  513. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  514. GObject gObject = _ui.m_listBg.GetChildAt(_curIndex);
  515. if (gObject == null) return;
  516. GButton btnBuyTen = gObject.asCom.GetChild("comLuckBoxBtn").asCom.GetChild("btnBuyTen").asButton;
  517. GuideController.TryGuide(null, ConstGuideId.LUCKY_BOX, 1, "“摘星”里可以通过星辰的力量获得服饰。", -1, true, _ui.target.height - 600);
  518. GuideController.TryGuide(btnBuyTen, ConstGuideId.LUCKY_BOX, 2, "点击摘取十次。");
  519. }
  520. protected override void TryCompleteGuide()
  521. {
  522. base.TryCompleteGuide();
  523. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.LUCKY_BOX);
  524. GuideController.TryCompleteGuideIndex(ConstGuideId.LUCKY_BOX, 2);
  525. }
  526. private void UpdateFreeInfo()
  527. {
  528. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];
  529. LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  530. long freeTime = LuckyBoxDataManager.Instance.GetFreeTime(boxId);
  531. GObject obj = _ui.m_listBg.GetChildAt(_curIndex);
  532. UI_ComBox1 comBox = UI_ComBox1.Proxy(obj);
  533. if (freeTime > 0)
  534. {
  535. if (freeTime > TimeHelper.ServerNow())
  536. {
  537. comBox.m_comLuckBoxBtn.m_comCostOne.m_c1.selectedIndex = 0;
  538. comBox.m_comLuckBoxBtn.m_txtFreeTime.visible = true;
  539. }
  540. else
  541. {
  542. comBox.m_comLuckBoxBtn.m_comCostOne.m_c1.selectedIndex = 1;
  543. comBox.m_comLuckBoxBtn.m_txtFreeTime.visible = false;
  544. }
  545. }
  546. else
  547. {
  548. comBox.m_comLuckBoxBtn.m_comCostOne.m_c1.selectedIndex = 0;
  549. comBox.m_comLuckBoxBtn.m_txtFreeTime.visible = false;
  550. }
  551. }
  552. }
  553. }