LuckyBoxView.cs 34 KB

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