LuckyBoxView.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874
  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. using cfg.GfgCfg;
  10. namespace GFGGame
  11. {
  12. public class LuckyBoxView : BaseWindow
  13. {
  14. private UI_LuckyBoxUI _ui;
  15. private ValueBarController _valueBarController;
  16. private Dictionary<int, LuckyBoxController> _luckyBoxCtrl = new Dictionary<int, LuckyBoxController>();
  17. private Dictionary<string, EffectUI> _effectUIDic = new Dictionary<string, EffectUI>();
  18. private DressUpObjUI _dressUpObjUIXiHe;
  19. private DressUpObjUI _dressUpObjUIChangXi;
  20. private string activityEndTime = "[2024][2][2][00:00]";
  21. Dictionary<int, GObject> _listActivityBtnObj = new Dictionary<int, GObject>();
  22. private Dictionary<string, GGraph> effectNameDic = new Dictionary<string, GGraph>() { };
  23. private int _activeBoxId = 0;
  24. private int _curIndex = 0;
  25. private int _activityId = 0;
  26. private bool scrollTouch = true; //左右箭头点击等滑动完成后才可以再次点击
  27. private EffectUI _effectUI1;
  28. private EffectUI _effectUI2;
  29. private EffectUI _effectUI3;
  30. private EffectUI _effectUI4;
  31. public override void Dispose()
  32. {
  33. // Clear Effect
  34. foreach (var v in _effectUIDic)
  35. {
  36. EffectUIPool.Recycle(v.Value);
  37. }
  38. EffectUIPool.Recycle(_effectUI1);
  39. _effectUI1 = null;
  40. EffectUIPool.Recycle(_effectUI2);
  41. _effectUI2 = null;
  42. EffectUIPool.Recycle(_effectUI3);
  43. _effectUI3 = null;
  44. EffectUIPool.Recycle(_effectUI4);
  45. _effectUI4 = null;
  46. _effectUIDic.Clear();
  47. if (_valueBarController != null)
  48. {
  49. _valueBarController.Dispose();
  50. _valueBarController = null;
  51. }
  52. foreach (int key in _luckyBoxCtrl.Keys)
  53. {
  54. _luckyBoxCtrl[key].Dispose();
  55. }
  56. _luckyBoxCtrl.Clear();
  57. if (_dressUpObjUIXiHe != null)
  58. {
  59. _dressUpObjUIXiHe.Dispose();
  60. _dressUpObjUIXiHe = null;
  61. }
  62. if (_dressUpObjUIChangXi != null)
  63. {
  64. _dressUpObjUIChangXi.Dispose();
  65. _dressUpObjUIChangXi = null;
  66. }
  67. if (_ui != null)
  68. {
  69. _ui.Dispose();
  70. _ui = null;
  71. }
  72. base.Dispose();
  73. }
  74. protected override void OnInit()
  75. {
  76. base.OnInit();
  77. packageName = UI_LuckyBoxUI.PACKAGE_NAME;
  78. _ui = UI_LuckyBoxUI.Create();
  79. this.viewCom = _ui.target;
  80. isfullScreen = true;
  81. isReturnView = true;
  82. _dressUpObjUIXiHe = new DressUpObjUI("SceneDressUp");
  83. _dressUpObjUIChangXi = new DressUpObjUI("SceneDressUp");
  84. _valueBarController = new ValueBarController(_ui.m_valueBar);
  85. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  86. _ui.m_btnLeft.onClick.Add(OnBtnLeftClick);
  87. _ui.m_btnRight.onClick.Add(OnBtnRightClick);
  88. _ui.m_listBg.itemRenderer = RenderListBgItem;
  89. _ui.m_listBg.SetVirtualAndLoop(); //虚拟循环列表
  90. _ui.m_listBg.scrollPane.onScrollEnd.Add(OnScrollEnd);
  91. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("zx_bg");
  92. effectNameDic.Add("zx_zwy_ll", _ui.m_effectZWH);
  93. effectNameDic.Add("zx_twy_cx", _ui.m_effectTWH);
  94. effectNameDic.Add("zx_twy_xh", _ui.m_effectTWH2);
  95. effectNameDic.Add("zx_zwy_yjzh", _ui.m_effectZWH2);
  96. EffectUIPool.CreateEffectUI(_ui.m_effectTWH, "ui_LuckyBox", "CK_TWH_01",
  97. onComplete: (effect) =>
  98. {
  99. if (effect != null)
  100. {
  101. _effectUI1 = effect;
  102. }
  103. });
  104. EffectUIPool.CreateEffectUI(_ui.m_effectZWH, "ui_LuckyBox", "CK_ZWH_01",
  105. onComplete: (effect) =>
  106. {
  107. if (effect != null)
  108. {
  109. _effectUI2 = effect;
  110. }
  111. });
  112. EffectUIPool.CreateEffectUI(_ui.m_effectTWH2, "ui_LuckyBox", "CK_TWH_02",
  113. onComplete: (effect) =>
  114. {
  115. if (effect != null)
  116. {
  117. _effectUI1 = effect;
  118. }
  119. });
  120. EffectUIPool.CreateEffectUI(_ui.m_effectZWH2, "ui_LuckyBox", "CK_ZWH_02",
  121. onComplete: (effect) =>
  122. {
  123. if (effect != null)
  124. {
  125. _effectUI2 = effect;
  126. }
  127. });
  128. AdaptScreen();
  129. }
  130. protected override void AddEventListener()
  131. {
  132. base.AddEventListener();
  133. EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateListItemData);
  134. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateListItemData);
  135. EventAgent.AddEventListener(ConstMessage.LUCKY_BOX_FREE_TIME_CHANGED, UpdateFreeInfo);
  136. EventAgent.AddEventListener(ConstMessage.LUCKY_BOX_ACTIVITY_REWARD, UpdateBtnReward);
  137. EventAgent.AddEventListener(ConstMessage.ACTIVITY_LUCKY_BOX, UpdateBtnReward);
  138. EventAgent.AddEventListener(ConstMessage.LUCKY_EFFECT_UPDATE, UpdateEffectVisible);
  139. }
  140. protected override void OnShown()
  141. {
  142. base.OnShown();
  143. Debug.Log("OnShown:LuckyBoxView");
  144. //防止引导检测之前触发点击事件
  145. GRoot.inst.touchable = false;
  146. _valueBarController.OnShown();
  147. _valueBarController.Controller(4);
  148. LuckyBoxDataManager.Instance.luckyBoxIds.Clear();
  149. LuckyBoxDataManager.Instance.luckyBoxIds.Add(LuckyBoxDataManager.BOX_ID_2);
  150. LuckyBoxDataManager.Instance.luckyBoxIds.Add(LuckyBoxDataManager.BOX_ID_3);
  151. _activeBoxId = 0;
  152. _activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitTsy);
  153. //第一个活动可能为轮换活动
  154. if (LuckyBoxDataManager.Instance.RotatingId > 0)
  155. {
  156. RotatingLuckyBoxCfg rotatingLuckyBox =
  157. CommonDataManager.Tables.TblRotatingLuckyBoxCfg.GetOrDefault(
  158. LuckyBoxDataManager.Instance.RotatingId);
  159. _activeBoxId = rotatingLuckyBox.LuckyBoxId;
  160. LuckyBoxDataManager.Instance.endTime = TimeUtil.GetTimestamp(rotatingLuckyBox.EndTime);
  161. LuckyBoxDataManager.Instance.luckyBoxIds.Insert(0, _activeBoxId);
  162. }
  163. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[0]; //默认跳转进来是第一个活动
  164. if (this.viewData != null)
  165. {
  166. int index = (int)this.viewData; //传入的值为第几个活动,不是活动id
  167. boxId = LuckyBoxDataManager.Instance.luckyBoxIds[index - 1]; //是1的时候,就使用轮换活动,不是1就是传入的固定活动
  168. }
  169. //新手引导选中第一个活动
  170. if (GuideDataManager.IsGuideFinish(ConstGuideId.LUCKY_BOX) <= 0)
  171. boxId = LuckyBoxDataManager.Instance.luckyBoxIds[0];
  172. //第二个活动会有许愿活动出现
  173. if (_activityId > 0 && boxId == LuckyBoxDataManager.BOX_ID_2)
  174. GetWishingPoolInfo(_activityId);
  175. LuckyBoxDataManager.Instance.currentBoxId = boxId;
  176. _curIndex = LuckyBoxDataManager.Instance.luckyBoxIds.IndexOf(boxId);
  177. LuckyBoxDataManager.Instance.luckyBoxIndex = _curIndex;
  178. _listActivityBtnObj.Clear();
  179. _ui.m_listBg.numItems = LuckyBoxDataManager.Instance.luckyBoxIds.Count;
  180. _ui.m_listBg.ScrollToView(_curIndex);
  181. _ui.m_listBg.scrollPane.decelerationRate = 0.8f;
  182. OnListBgScroll();
  183. bool actLimitTsyOpen = LuckyBoxDataManager.Instance.GetActLimitTsyOpen();
  184. //时间倒计时
  185. if (_activeBoxId > 0)
  186. Timers.inst.Add(1, 0, CheckTime);
  187. //第二个活动的倒计时
  188. if (actLimitTsyOpen) // && LuckyBoxDataManager.Instance.currentBoxId == LuckyBoxDataManager.BOX_ID_2
  189. Timers.inst.Add(1, 0, UpdateTime);
  190. //第二个活动的模拟活动倒计时
  191. if (!actLimitTsyOpen && boxId == LuckyBoxDataManager.BOX_ID_2)
  192. Timers.inst.Add(1, 0, UpdateImitateTime);
  193. Timers.inst.AddUpdate(CheckGuide);
  194. }
  195. private void RenderListBgItem(int index, GObject obj)
  196. {
  197. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[index];
  198. UI_ComBox1 comBox = UI_ComBox1.Proxy(obj);
  199. LuckyBoxCfg cfg = CommonDataManager.Tables.TblLuckyBoxCfg.GetOrDefault(boxId);
  200. LuckyBoxDataManager.Instance.InitData(boxId);
  201. if (!_listActivityBtnObj.ContainsKey(boxId))
  202. _listActivityBtnObj.Add(boxId, obj);
  203. else
  204. _listActivityBtnObj[boxId] = obj;
  205. comBox.m_ImgUp.visible = index == 0;
  206. int activityId =
  207. 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 if (boxId == LuckyBoxDataManager.BOX_ID_2)
  214. {
  215. long endTime = TimeUtil.DateTimeToTimestamp(activityEndTime);
  216. if (endTime < TimeHelper.ServerNow())
  217. comBox.m_showActivityType.selectedIndex = 0;
  218. else
  219. {
  220. comBox.m_showActivityType.selectedIndex = 2;
  221. long curTime = TimeHelper.ServerNow();
  222. if (endTime >= curTime)
  223. comBox.m_txtHasTime.text = "剩余时间: " + TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);
  224. }
  225. }
  226. else
  227. comBox.m_showActivityType.selectedIndex = 0;
  228. if (cfg.CostNumfifty > 0)
  229. comBox.m_comLuckBoxBtn.m_btnNumberType.selectedIndex = 1;
  230. else
  231. comBox.m_comLuckBoxBtn.m_btnNumberType.selectedIndex = 0;
  232. if (_luckyBoxCtrl.ContainsKey(boxId))
  233. {
  234. _luckyBoxCtrl[boxId].OnHide();
  235. _luckyBoxCtrl[boxId].Dispose();
  236. _luckyBoxCtrl.Remove(boxId);
  237. }
  238. _luckyBoxCtrl.Add(boxId, new LuckyBoxController(comBox.m_comModel.target));
  239. //comBox.m_comLuckBoxBtn.m_holder.visible = boxId != LuckyBoxDataManager.BOX_ID_3;
  240. comBox.m_comLuckBoxBtn.m_comCostOne.m_txtCost.text = cfg.CostNum.ToString();
  241. comBox.m_comLuckBoxBtn.m_comCostOne.m_loaCost.url =
  242. ResPathUtil.GetCommonGameResPath(CommonDataManager.Tables.TblItemCfg.GetOrDefault(cfg.CostID).Res);
  243. comBox.m_comLuckBoxBtn.m_comCostTen.m_txtCost.text = cfg.CostNumTen.ToString();
  244. comBox.m_comLuckBoxBtn.m_comCostTen.m_loaCost.url =
  245. ResPathUtil.GetCommonGameResPath(CommonDataManager.Tables.TblItemCfg.GetOrDefault(cfg.CostID).Res);
  246. comBox.m_comLuckBoxBtn.m_comCostFifty.m_txtCost.text = cfg.CostNumfifty.ToString();
  247. comBox.m_comLuckBoxBtn.m_comCostFifty.m_loaCost.url =
  248. ResPathUtil.GetCommonGameResPath(CommonDataManager.Tables.TblItemCfg.GetOrDefault(cfg.CostID).Res);
  249. if (comBox.m_comLuckBoxBtn.m_btnBuyOne.data == null)
  250. comBox.m_comLuckBoxBtn.m_btnBuyOne.onClick.Add(OnClickBtnBuyOne);
  251. comBox.m_comLuckBoxBtn.m_btnBuyOne.data = boxId;
  252. if (comBox.m_comLuckBoxBtn.m_btnBuyTen.data == null)
  253. {
  254. if (boxId != LuckyBoxDataManager.BOX_ID_3)
  255. {
  256. if (!_effectUIDic.ContainsKey("Button_Text_DianCang" + boxId))
  257. {
  258. EffectUIPool.CreateEffectUI(comBox.m_comLuckBoxBtn.m_Special_eff, "ui_LuckyBox",
  259. "Button_Text_DianCang",
  260. onComplete: (effect) =>
  261. {
  262. if (effect != null)
  263. {
  264. _effectUIDic.Add("Button_Text_DianCang" + boxId, effect);
  265. }
  266. });
  267. }
  268. if (!_effectUIDic.ContainsKey("Button_public" + boxId))
  269. {
  270. EffectUIPool.CreateEffectUI(comBox.m_comLuckBoxBtn.m_btnBuyTen_eff, "ui_LuckyBox",
  271. "Button_public",
  272. onComplete: (effect) =>
  273. {
  274. if (effect != null)
  275. {
  276. _effectUIDic.Add("Button_public" + boxId, effect);
  277. }
  278. });
  279. }
  280. }
  281. comBox.m_comLuckBoxBtn.m_btnBuyTen.onClick.Add(OnClickBtnBuyTen);
  282. }
  283. comBox.m_comLuckBoxBtn.m_btnBuyTen.data = boxId;
  284. if (comBox.m_comLuckBoxBtn.m_btnBuyFifty.data == null)
  285. comBox.m_comLuckBoxBtn.m_btnBuyFifty.onClick.Add(OnClickBtnBuyFifty);
  286. comBox.m_comLuckBoxBtn.m_btnBuyFifty.data = boxId;
  287. if (comBox.m_btnPreview.data == null)
  288. comBox.m_btnPreview.onClick.Add(OnClickBtnPreview);
  289. comBox.m_btnPreview.data = boxId;
  290. if (comBox.m_btnReward.target.data == null)
  291. {
  292. comBox.m_btnReward.target.onClick.Add(OnClikcBtnReward);
  293. comBox.m_btnShop.target.onClick.Add(OnClikcBtnShop);
  294. comBox.m_btnGiftBag.target.onClick.Add(OnClikcBtnGiftBag);
  295. }
  296. comBox.m_btnReward.target.data = boxId;
  297. obj.data = boxId;
  298. comBox.m_grpTime.visible = (boxId == _activeBoxId);
  299. if (boxId == _activeBoxId)
  300. {
  301. long endTime = LuckyBoxDataManager.Instance.endTime;
  302. long curTime = TimeHelper.ServerNow();
  303. long time = endTime - curTime;
  304. string strTime = time > TimeUtil.SECOND_PER_DAY * 100
  305. ? TimeUtil.FormattingTimeTo_DDHHmm(time)
  306. : TimeUtil.FormattingTimeTo_HHmmss(time);
  307. comBox.m_txtTime.text = string.Format("轮换倒计时:{0}", strTime);
  308. }
  309. UI_ComBox1.ProxyEnd();
  310. }
  311. private async void GetWishingPoolInfo(int activityId)
  312. {
  313. bool result = await LuckyBoxSProxy.ReqGetWishingPoolInfo();
  314. if (result)
  315. {
  316. int index = LuckyBoxDataManager.Instance.KsActivityId.IndexOf(activityId);
  317. if (index < 0 || !LuckyBoxDataManager.Instance.VsStatus[index])
  318. ViewManager.Show<LuckyBoxWishView>(ConstLimitTimeActivityType.ActLimitTsy);
  319. }
  320. }
  321. private void OnBtnLeftClick()
  322. {
  323. if (!scrollTouch) return;
  324. scrollTouch = false;
  325. int index = _curIndex - 1;
  326. _ui.m_listBg.ScrollToView(index, true);
  327. if (_activityId > 0 && index + 1 == LuckyBoxDataManager.BOX_ID_2)
  328. GetWishingPoolInfo(_activityId);
  329. }
  330. private void OnBtnRightClick()
  331. {
  332. if (!scrollTouch) return;
  333. scrollTouch = false;
  334. int index = _curIndex + 1;
  335. _ui.m_listBg.ScrollToView(index, true);
  336. if (_activityId > 0 && index + 1 == LuckyBoxDataManager.BOX_ID_2)
  337. GetWishingPoolInfo(_activityId);
  338. }
  339. private void OnScrollEnd()
  340. {
  341. scrollTouch = true;
  342. // 未更新滚动位置的时候,不更新,防止不停的播放渐入动画
  343. int index = _ui.m_listBg.GetFirstChildInView();
  344. if (index == _curIndex)
  345. {
  346. return;
  347. }
  348. OnListBgScroll();
  349. }
  350. private void OnListBgScroll()
  351. {
  352. LuckyBoxController valueBox;
  353. _luckyBoxCtrl.TryGetValue(LuckyBoxDataManager.Instance.currentBoxId, out valueBox);
  354. if (valueBox != null)
  355. _luckyBoxCtrl[LuckyBoxDataManager.Instance.currentBoxId].OnHide();
  356. _curIndex = _ui.m_listBg.GetFirstChildInView();
  357. LuckyBoxDataManager.Instance.currentBoxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];
  358. if (LuckyBoxDataManager.Instance.currentBoxId == LuckyBoxDataManager.BOX_ID_3)
  359. {
  360. _valueBarController.Controller(3);
  361. }
  362. else
  363. {
  364. _valueBarController.Controller(4);
  365. }
  366. _valueBarController.UpdateCJ();
  367. _luckyBoxCtrl[LuckyBoxDataManager.Instance.currentBoxId].OnShown(LuckyBoxDataManager.Instance.currentBoxId);
  368. LuckyBoxDataManager.Instance.luckyBoxIndex = _curIndex;
  369. UpdateFreeInfo();
  370. UpdateListItemData();
  371. UpdateEffect();
  372. }
  373. private void UpdateEffect()
  374. {
  375. //LuckyBoxCfg luckybox = LuckyBoxCfgArray.Instance.GetCfg(LuckyBoxDataManager.Instance.currentBoxId);
  376. //if(luckybox.name == "紫薇垣")
  377. //{
  378. // _ui.m_effectZWH.visible = true;
  379. // _ui.m_effectTWH.visible = false;
  380. //}
  381. //else if (luckybox.name == "太微垣")
  382. //{
  383. // _ui.m_effectZWH.visible = false;
  384. // _ui.m_effectTWH.visible = true;
  385. //}
  386. //else
  387. //{
  388. // _ui.m_effectZWH.visible = false;
  389. // _ui.m_effectTWH.visible = false;
  390. //}
  391. }
  392. private void UpdateBtnReward()
  393. {
  394. if (_curIndex == 1)
  395. {
  396. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];
  397. GObject obj = _listActivityBtnObj[boxId];
  398. UI_ComBox1 comBox = UI_ComBox1.Proxy(obj);
  399. RedDotController.Instance.SetComRedDot(comBox.m_btnReward.target,
  400. RedDotDataManager.Instance.GetActLuckyBoxRewardRed(ConstLimitTimeActivityType.ActLimitTsy), "", -21,
  401. 18);
  402. comBox.m_txtCount.SetVar("value", ActivityDataManager.Instance.lastTsyDrawCount.ToString()).FlushVars();
  403. UI_ComBox1.ProxyEnd();
  404. }
  405. }
  406. private void OnClikcBtnReward()
  407. {
  408. ViewManager.Show<ActivityThemeLuckyBoxBonusView>(ConstLimitTimeActivityType.ActLimitTsy);
  409. }
  410. private void OnClikcBtnShop()
  411. {
  412. //ViewManager.Show<StoreView>(new object[] { ConstStoreTabId.STORE_GIFT_BAG, ConstStoreSubId.STORE_GIFT_BAG_TSY });
  413. }
  414. //刷新摘星活动期间的数据
  415. private void UpGiftBox(UI_ComBox1 comBox)
  416. {
  417. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];
  418. LuckyBoxCfg cfg = CommonDataManager.Tables.TblLuckyBoxCfg.GetOrDefault(boxId);
  419. comBox.m_txtCount.SetVar("value", ActivityDataManager.Instance.lastTsyDrawCount.ToString()).FlushVars();
  420. comBox.m_txtCount.SetVar("name", cfg.Name).FlushVars();
  421. int activityId =
  422. ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitTsy);
  423. var activityInfoByTypeList =
  424. ActivityGlobalDataManager.Instance.GetActivityInfoByTypeAndID(ActivityType.XSLB3, activityId);
  425. var list = activityInfoByTypeList.Where(a => a.EndTime > TimeInfo.Instance.ServerNow()).ToList();
  426. if (list.Count == 0)
  427. {
  428. comBox.m_comBagTime.target.visible = false;
  429. comBox.m_btnGiftBag.target.visible = false;
  430. }
  431. else
  432. {
  433. bool isSoldOut = true;
  434. foreach (var activityInfo in list)
  435. {
  436. ActivityOpenCfg activityOpenCfg =
  437. CommonDataManager.Tables.TblActivityOpenCfg.GetOrDefault(activityInfo.ActivityId);
  438. var paramsArr = activityOpenCfg.Params1;
  439. foreach (var shopCfgId in paramsArr)
  440. {
  441. var shopCfg = CommonDataManager.Tables.TblShopCfg.GetOrDefault(shopCfgId);
  442. var remainBuyNum = shopCfg.MaxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(shopCfgId);
  443. //只要有一个商品还能购买,就不是售罄
  444. if (remainBuyNum > 0)
  445. {
  446. isSoldOut = false;
  447. break;
  448. }
  449. }
  450. }
  451. if (isSoldOut)
  452. {
  453. comBox.m_comBagTime.target.visible = false;
  454. comBox.m_btnGiftBag.target.visible = false;
  455. }
  456. else
  457. {
  458. comBox.m_comBagTime.m_txtGiftBagTime.text =
  459. TimeUtil.GetTimeLeft(TimeInfo.Instance.ServerNow(), list[0].EndTime);
  460. comBox.m_comBagTime.target.visible = true;
  461. comBox.m_btnGiftBag.target.visible = true;
  462. }
  463. }
  464. UpdateBtnReward();
  465. }
  466. //限时礼包按钮点击执行方法
  467. private void OnClikcBtnGiftBag()
  468. {
  469. var activityInfoByTypeList =
  470. ActivityGlobalDataManager.Instance.GetActivityInfoByType(ActivityType.XSLB3);
  471. var list = activityInfoByTypeList
  472. .Where(a => a.EndTime > TimeInfo.Instance.ServerNow()).ToList();
  473. if (list.Count == 0)
  474. PromptController.Instance.ShowFloatTextPrompt("活动已结束");
  475. else
  476. ViewManager.Show<RushSaleGiftBoxView>(new object[] { ActivityType.XSLB3, this.viewData });
  477. }
  478. private void UpdateListItemData()
  479. {
  480. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];
  481. LuckyBoxCfg cfg = CommonDataManager.Tables.TblLuckyBoxCfg.GetOrDefault(boxId);
  482. GObject obj = _listActivityBtnObj[boxId];
  483. UI_ComBox1 comBox = UI_ComBox1.Proxy(obj);
  484. LuckyBoxDataManager.Instance.GetOwnedCount(boxId, out int count, out int totalCount);
  485. comBox.m_txtOwned.SetVar("v1", "" + count).FlushVars();
  486. comBox.m_txtOwned.SetVar("v2", "" + totalCount).FlushVars();
  487. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(cfg.NumericType);
  488. comBox.m_comLuckBoxBtn.m_txtRemainTimes.text = string.Format("今日剩余次数:{0}", cfg.MaxCount - boughtCount);
  489. UI_ComBox1.ProxyEnd();
  490. }
  491. private void CheckTime(object param = null)
  492. {
  493. if (LuckyBoxDataManager.Instance.currentBoxId != _activeBoxId) return;
  494. long endTime = LuckyBoxDataManager.Instance.endTime;
  495. long curTime = TimeHelper.ServerNow();
  496. TimeUtil.FormattingTime(curTime, endTime, out int num, out string str);
  497. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[0];
  498. GObject item = _listActivityBtnObj[boxId];
  499. if (item == null) return;
  500. GObject textField = item.asCom.GetChild("txtTime");
  501. if (textField == null) return;
  502. long time = endTime - curTime;
  503. string strTime = time > TimeUtil.SECOND_PER_DAY * 100
  504. ? TimeUtil.FormattingTimeTo_DDHHmm(time)
  505. : TimeUtil.FormattingTimeTo_HHmmss(time);
  506. textField.asTextField.text = string.Format("轮换倒计时:{0}", strTime);
  507. }
  508. private void UpdateImitateTime(object param = null)
  509. {
  510. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[1];
  511. GObject item = _listActivityBtnObj[boxId];
  512. GObject textField = item.asCom.GetChild("txtHasTime");
  513. if (textField == null) return;
  514. long curTime = TimeHelper.ServerNow();
  515. long endTime = TimeUtil.DateTimeToTimestamp(activityEndTime);
  516. if (endTime < curTime)
  517. {
  518. Timers.inst.Remove(UpdateImitateTime);
  519. endTime = curTime;
  520. }
  521. textField.asTextField.text = "剩余时间: " + TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);
  522. }
  523. private void UpdateTime(object param = null)
  524. {
  525. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[1];
  526. GObject item = _listActivityBtnObj[boxId];
  527. if (item == null) return;
  528. GObject textField = item.asCom.GetChild("txtTsyTime");
  529. if (textField == null) return;
  530. int activityId =
  531. ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitTsy);
  532. var activityCfg = CommonDataManager.Tables.TblActivityOpenCfg.GetOrDefault(activityId);
  533. long endTime = 0;
  534. if (activityCfg != null)
  535. endTime = TimeUtil.DateTimeToTimestamp(activityCfg.EndTime);
  536. long curTime = TimeHelper.ServerNow();
  537. if (endTime < curTime)
  538. {
  539. PromptController.Instance.ShowFloatTextPrompt("活动已结束");
  540. Timers.inst.Remove(UpdateTime);
  541. endTime = curTime;
  542. }
  543. TimeUtil.FormattingTime(curTime, endTime, out int num, out string str);
  544. textField.asTextField.text = "概率提升剩余: " + TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);
  545. //=====限时礼包倒计时
  546. //UpGiftBox();
  547. //EventAgent.DispatchEvent(ConstMessage.LUCKY_BOX_TIME);
  548. //=====限时礼包倒计时END
  549. }
  550. private void OnClickBtnPreview(EventContext context)
  551. {
  552. GObject obj = context.sender as GObject;
  553. int boxId = (int)obj.data;
  554. ViewManager.Show<LuckyBoxPreShowView>(boxId);
  555. }
  556. private void OnClickBtnBuyOne(EventContext context)
  557. {
  558. GetSuitItemController.showSingle = true;
  559. GObject obj = context.sender as GObject;
  560. int boxId = (int)obj.data;
  561. LuckyBoxCfg luckyBoxCfg = CommonDataManager.Tables.TblLuckyBoxCfg.GetOrDefault(boxId);
  562. long freeTime = LuckyBoxDataManager.Instance.GetFreeTime(boxId);
  563. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(luckyBoxCfg.NumericType);
  564. if (boughtCount + LuckyBoxDataManager.ONCE_TIME > luckyBoxCfg.MaxCount)
  565. {
  566. PromptController.Instance.ShowFloatTextPrompt("抽奖次数不足");
  567. return;
  568. }
  569. LuckyBoxDataManager.Instance.CheckItemEnough(boxId, LuckyBoxDataManager.ONCE_TIME, async () =>
  570. {
  571. int activityId = 0;
  572. if (boxId == LuckyBoxDataManager.BOX_ID_2)
  573. {
  574. activityId =
  575. ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitTsy);
  576. }
  577. bool freeType = (freeTime > 0 && freeTime < TimeHelper.ServerNow());
  578. bool result =
  579. await LuckyBoxSProxy.ReqGetBonus(boxId, LuckyBoxDataManager.ONCE_TIME, freeType, activityId);
  580. if (result)
  581. {
  582. ViewManager.Show<LuckyBoxStarView>();
  583. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 2);
  584. GetSuitItemController.showSingle = false;
  585. }
  586. });
  587. }
  588. private void OnClickBtnBuyTen(EventContext context)
  589. {
  590. GetSuitItemController.showSingle = true;
  591. GuideCfg cfg = CommonDataManager.Tables.TblGuideCfg.GetOrDefault(ConstGuideId.LUCKY_BOX);
  592. if (GuideDataManager.IsGuideFinish(ConstGuideId.LUCKY_BOX) <= 0
  593. && (GuideDataManager.currentGuideId == 0
  594. || (GuideDataManager.currentGuideId == cfg.Id && GuideDataManager.currentGuideIdIndex != 2)))
  595. {
  596. //防止点击太快,在引导开启前就被点击到,导致引导卡死
  597. return;
  598. }
  599. GObject obj = context.sender as GObject;
  600. int boxId = (int)obj.data;
  601. LuckyBoxCfg luckyBoxCfg = CommonDataManager.Tables.TblLuckyBoxCfg.GetOrDefault(boxId);
  602. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(luckyBoxCfg.NumericType);
  603. if (boughtCount + LuckyBoxDataManager.TEN_TIME > luckyBoxCfg.MaxCount)
  604. {
  605. PromptController.Instance.ShowFloatTextPrompt("抽奖次数不足");
  606. return;
  607. }
  608. LuckyBoxDataManager.Instance.CheckItemEnough(boxId, LuckyBoxDataManager.TEN_TIME, async () =>
  609. {
  610. int activityId = 0;
  611. if (boxId == LuckyBoxDataManager.BOX_ID_2)
  612. {
  613. activityId =
  614. ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitTsy);
  615. }
  616. bool result = await LuckyBoxSProxy.ReqGetBonus(boxId, LuckyBoxDataManager.TEN_TIME, false, activityId);
  617. if (result)
  618. {
  619. ViewManager.Show<LuckyBoxStarView>();
  620. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 2);
  621. GetSuitItemController.showSingle = false;
  622. }
  623. });
  624. }
  625. private void OnClickBtnBuyFifty(EventContext context)
  626. {
  627. GetSuitItemController.showSingle = true;
  628. GObject obj = context.sender as GObject;
  629. int boxId = (int)obj.data;
  630. LuckyBoxCfg luckyBoxCfg = CommonDataManager.Tables.TblLuckyBoxCfg.GetOrDefault(boxId);
  631. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(luckyBoxCfg.NumericType);
  632. if (boughtCount + LuckyBoxDataManager.FIFTY_TIME > luckyBoxCfg.MaxCount)
  633. {
  634. PromptController.Instance.ShowFloatTextPrompt("抽奖次数不足");
  635. return;
  636. }
  637. LuckyBoxDataManager.Instance.CheckItemEnough(boxId, LuckyBoxDataManager.FIFTY_TIME, async () =>
  638. {
  639. bool result = await LuckyBoxSProxy.ReqGetBonus(boxId, LuckyBoxDataManager.FIFTY_TIME, false, 0);
  640. if (result)
  641. {
  642. BonusController.TryShowBonusList(LuckyBoxDataManager.Instance.RewardList);
  643. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 3);
  644. GetSuitItemController.showSingle = false;
  645. }
  646. });
  647. }
  648. protected override void OnHide()
  649. {
  650. base.OnHide();
  651. GRoot.inst.touchable = true;
  652. _valueBarController.OnHide();
  653. foreach (int key in _luckyBoxCtrl.Keys)
  654. {
  655. _luckyBoxCtrl[key].OnHide();
  656. }
  657. Timers.inst.Remove(CheckTime);
  658. Timers.inst.Remove(UpdateTime);
  659. Timers.inst.Remove(UpdateImitateTime);
  660. Timers.inst.Remove(CheckGuide);
  661. Debug.Log("OnHide: LuckyBoxView");
  662. }
  663. protected override void RemoveEventListener()
  664. {
  665. base.RemoveEventListener();
  666. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateListItemData);
  667. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateListItemData);
  668. EventAgent.RemoveEventListener(ConstMessage.LUCKY_BOX_FREE_TIME_CHANGED, UpdateFreeInfo);
  669. EventAgent.RemoveEventListener(ConstMessage.LUCKY_BOX_ACTIVITY_REWARD, UpdateBtnReward);
  670. EventAgent.RemoveEventListener(ConstMessage.ACTIVITY_LUCKY_BOX, UpdateBtnReward);
  671. EventAgent.RemoveEventListener(ConstMessage.LUCKY_EFFECT_UPDATE, UpdateEffectVisible);
  672. }
  673. private void OnClickBtnBack()
  674. {
  675. Reset();
  676. ViewManager.GoBackFrom(typeof(LuckyBoxView).FullName);
  677. }
  678. private void Reset()
  679. {
  680. LuckyBoxDataManager.Instance.currentBoxId = LuckyBoxDataManager.Instance.luckyBoxIds[0];
  681. }
  682. private void CheckGuide(object param)
  683. {
  684. GRoot.inst.touchable = true;
  685. if (GuideDataManager.IsGuideFinish(ConstGuideId.LUCKY_BOX) <= 0)
  686. UpdateToCheckGuide(null);
  687. else
  688. Timers.inst.Remove(CheckGuide);
  689. }
  690. protected override void UpdateToCheckGuide(object param)
  691. {
  692. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  693. if (_curIndex > 0) return;
  694. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];
  695. GObject gObject = _listActivityBtnObj[boxId];
  696. if (gObject == null) return;
  697. GButton btnBuyTen = gObject.asCom.GetChild("comLuckBoxBtn").asCom.GetChild("btnBuyTen").asButton;
  698. GuideController.TryGuide(null, ConstGuideId.LUCKY_BOX, 1, "“摘星”里可以通过星辰的力量获得服饰。", -1, true,
  699. _ui.target.height - 600);
  700. GuideController.TryGuide(btnBuyTen, ConstGuideId.LUCKY_BOX, 2, "点击摘取十次。");
  701. GuideController.TryCompleteGuide(ConstGuideId.LUCKY_BOX, 2);
  702. }
  703. protected override void TryCompleteGuide()
  704. {
  705. base.TryCompleteGuide();
  706. // GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.LUCKY_BOX);
  707. GuideController.TryCompleteGuideIndex(ConstGuideId.LUCKY_BOX, 2);
  708. }
  709. private void UpdateFreeInfo()
  710. {
  711. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[_curIndex];
  712. long freeTime = LuckyBoxDataManager.Instance.GetFreeTime(boxId);
  713. GObject obj = _listActivityBtnObj[boxId];
  714. UI_ComBox1 comBox = UI_ComBox1.Proxy(obj);
  715. if (freeTime > 0)
  716. {
  717. long timeDifference = freeTime - TimeHelper.ServerNow();
  718. if (freeTime > TimeHelper.ServerNow())
  719. {
  720. comBox.m_comLuckBoxBtn.m_comCostOne.m_c1.selectedIndex = 0;
  721. comBox.m_comLuckBoxBtn.m_txtFreeTime.visible = true;
  722. string strFreeTime = TimeUtil.FormattingTimeTo_DDHHmm(timeDifference);
  723. comBox.m_comLuckBoxBtn.m_txtFreeTime.text = string.Format("{0}后免费", strFreeTime);
  724. }
  725. else
  726. {
  727. comBox.m_comLuckBoxBtn.m_comCostOne.m_c1.selectedIndex = 1;
  728. comBox.m_comLuckBoxBtn.m_txtFreeTime.visible = false;
  729. }
  730. }
  731. else
  732. {
  733. comBox.m_comLuckBoxBtn.m_comCostOne.m_c1.selectedIndex = 0;
  734. comBox.m_comLuckBoxBtn.m_txtFreeTime.visible = false;
  735. }
  736. RedDotController.Instance.SetComRedDot(comBox.m_comLuckBoxBtn.m_btnBuyOne,
  737. comBox.m_comLuckBoxBtn.m_comCostOne.m_c1.selectedIndex == 1, "", -29, 9);
  738. RedDotController.Instance.SetComRedDot(_ui.m_btnLeft, LuckyBoxDataManager.Instance.RedBtnLeft(_curIndex));
  739. RedDotController.Instance.SetComRedDot(_ui.m_btnRight, LuckyBoxDataManager.Instance.RedBtnRight(_curIndex),
  740. "", -60, 70);
  741. UI_ComBox1.ProxyEnd();
  742. }
  743. private void AdaptScreen()
  744. {
  745. float offsetY = _ui.m_grpTop.y + ViewGlobal.GetRealTopOffset();
  746. _ui.m_grpTop.SetXY(_ui.m_grpTop.x, offsetY);
  747. }
  748. private void UpdateEffectVisible(EventContext eventContext)
  749. {
  750. var resStr = (string)eventContext.data;
  751. foreach (var item in effectNameDic)
  752. {
  753. if (item.Key == resStr)
  754. {
  755. item.Value.visible = true;
  756. }
  757. else
  758. {
  759. item.Value.visible = false;
  760. }
  761. }
  762. }
  763. }
  764. }