LuckyBoxView.cs 33 KB

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