LuckyBoxView.cs 27 KB

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