LuckyBoxView.cs 34 KB

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