ActivityGetYuanXiaoEntryView.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. using System.Collections;
  2. using UnityEngine;
  3. using UI.ActivityGetYuanXiao;
  4. using FairyGUI;
  5. using System.Collections.Generic;
  6. using System.Threading.Tasks;
  7. using cfg.GfgCfg;
  8. using ET;
  9. namespace GFGGame
  10. {
  11. public class ActivityGetYuanXiaoEntryView : BaseView
  12. {
  13. private UI_ActivityGetYuanXiaoEntryUI _ui;
  14. private int index;
  15. private ValueBarController _valueBarController;
  16. private Dictionary<string, EffectUI> _effectUIDic = new Dictionary<string, EffectUI>();
  17. private int _curLevel;
  18. public override void Dispose()
  19. {
  20. // Clear Effect
  21. foreach (var v in _effectUIDic)
  22. {
  23. EffectUIPool.Recycle(v.Value);
  24. }
  25. _effectUIDic.Clear();
  26. if (_valueBarController != null)
  27. {
  28. _valueBarController.Dispose();
  29. _valueBarController = null;
  30. }
  31. if (_ui != null)
  32. {
  33. _ui.Dispose();
  34. }
  35. _ui = null;
  36. base.Dispose();
  37. }
  38. protected override void OnInit()
  39. {
  40. base.OnInit();
  41. packageName = UI_ActivityGetYuanXiaoEntryUI.PACKAGE_NAME;
  42. _ui = UI_ActivityGetYuanXiaoEntryUI.Create();
  43. viewCom = _ui.target;
  44. isReturnView = true;
  45. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("xyx_clfg_bg");
  46. _valueBarController = new ValueBarController(_ui.m_valueBar);
  47. _ui.m_list.itemRenderer = ListRenderer;
  48. _ui.m_btnStart.onClick.Add(OnBtnStartClick);
  49. _ui.m_btnTask.onClick.Add(OnBtnTaskClick);
  50. _ui.m_btnShop.onClick.Add(OnBtnShopClick);
  51. _ui.m_btnBack.onClick.Add(OnBtnBackClick);
  52. AddEffect();
  53. }
  54. protected async override void OnShown()
  55. {
  56. base.OnShown();
  57. InitUI();
  58. var result = await ActivityGetYuanXiaoProxy.ReqGetActivityGameInfos();
  59. if (!isShowing || !result)
  60. {
  61. return;
  62. }
  63. _ui.m_doubaoEffect.SetScale(1, 1);
  64. _ui.m_list.visible = true;
  65. _valueBarController.UpdateList(new List<int>()
  66. { ConstItemID.YUANXIAO_REWARD, ConstItemID.YUANXIAO_GAME_CONSUME });
  67. _ui.m_listShow.Play();
  68. _curLevel = ActivityGetYuanXiaoDataManager.Instance.GetCurLevel();
  69. _ui.m_list.numItems = ActivityGetYuanXiaoDataManager.Instance.gameinfoList.Count;
  70. _ui.m_list.selectedIndex =
  71. Mathf.Min(_curLevel, ActivityGetYuanXiaoDataManager.Instance.gameinfoList.Count - 1);
  72. AutoLocationCurLevel();
  73. UpdateRedDots();
  74. index = _ui.m_list.selectedIndex;
  75. UpdateTime(null);
  76. Timers.inst.Remove(UpdateTime);
  77. Timers.inst.Add(1, 0, UpdateTime);
  78. }
  79. protected override void OnHide()
  80. {
  81. base.OnHide();
  82. _valueBarController.OnHide();
  83. Timers.inst.Remove(UpdateTime);
  84. }
  85. protected override void AddEventListener()
  86. {
  87. base.AddEventListener();
  88. EventAgent.AddEventListener(ConstMessage.ACTIVITY_GETYUANXIAO_START, StartGame);
  89. EventAgent.AddEventListener(ConstMessage.RED_CHANGE, UpdateRedDots);
  90. }
  91. protected override void RemoveEventListener()
  92. {
  93. base.RemoveEventListener();
  94. EventAgent.RemoveEventListener(ConstMessage.ACTIVITY_GETYUANXIAO_START, StartGame);
  95. EventAgent.RemoveEventListener(ConstMessage.RED_CHANGE, UpdateRedDots);
  96. }
  97. private void ListRenderer(int index, GObject item)
  98. {
  99. item.data = index;
  100. UI_level level = UI_level.Proxy(item);
  101. PickUpGameCfg pickUpGame = CommonDataManager.Tables.TblPickUpGameCfg.DataList[index];
  102. level.m_spendIcon.url =
  103. ResPathUtil.GetIconPath(
  104. CommonDataManager.Tables.TblItemCfg.GetOrDefault(pickUpGame.ComsumePass[0].ItemId).Res, "png");
  105. level.m_iconLevel.url = string.Format("ui://ActivityGetYuanXiao/clfg_xg_{0}", index % 4 + 1);
  106. level.m_num.text = pickUpGame.ComsumePass[0].Count.ToString();
  107. int stateIndex = 0;
  108. if (index > _curLevel)
  109. {
  110. stateIndex = 1;
  111. }
  112. else if (index < _curLevel)
  113. {
  114. stateIndex = 2;
  115. }
  116. level.m_c1.selectedIndex = stateIndex;
  117. level.target.onClick.Add(OnBtnClick);
  118. UI_level.ProxyEnd();
  119. }
  120. private void OnBtnClick(EventContext context)
  121. {
  122. GObject gObject = context.sender as GObject;
  123. int id = (int)gObject.data;
  124. if (id != index)
  125. {
  126. index = id;
  127. return;
  128. }
  129. index = id;
  130. PickUpGameCfg cfg = CommonDataManager.Tables.TblPickUpGameCfg.DataList[id];
  131. ViewManager.Show<ActivityZLFGRewardTips>(cfg);
  132. }
  133. private void OnBtnStartClick()
  134. {
  135. int activityID = ActivityDataManager.Instance.GetCurOpenActiveByType(ActivityType.YuanXiao);
  136. if (activityID == 0)
  137. {
  138. PromptController.Instance.ShowFloatTextPrompt("活动已结束");
  139. return;
  140. }
  141. if (_ui.m_list.selectedIndex > _curLevel)
  142. {
  143. PromptController.Instance.ShowFloatTextPrompt("请先通关前置关卡");
  144. return;
  145. }
  146. if (_ui.m_list.selectedIndex < _curLevel)
  147. {
  148. PromptController.Instance.ShowFloatTextPrompt("关卡已通过");
  149. return;
  150. }
  151. if (ActivityGetYuanXiaoDataManager.Instance.HaveNewLevelCanPlay() == false)
  152. {
  153. PromptController.Instance.ShowFloatTextPrompt("游园门票不足,请查看任务列表");
  154. return;
  155. }
  156. PickUpGameCfg cfg = CommonDataManager.Tables.TblPickUpGameCfg.DataList[_ui.m_list.selectedIndex];
  157. ViewManager.Show<ActivityGetYuanXiaoTargetView>(cfg);
  158. }
  159. private async void StartGame()
  160. {
  161. int activityID = ActivityDataManager.Instance.GetCurOpenActiveByType(ActivityType.YuanXiao);
  162. PickUpGameCfg cfg = CommonDataManager.Tables.TblPickUpGameCfg.DataList[_ui.m_list.selectedIndex];
  163. var result = await MiniGameProxy.ReqMiniGameStart(cfg.Id, cfg.Type, activityID);
  164. if (!result || !isShowing) return;
  165. ViewManager.Show<ActivityGetYuanXiaoView>(new object[] { cfg, activityID });
  166. }
  167. private void OnBtnShopClick()
  168. {
  169. int activityID = ActivityDataManager.Instance.GetCurOpenActiveByType(ActivityType.YuanXiao);
  170. if (activityID == 0)
  171. {
  172. PromptController.Instance.ShowFloatTextPrompt("活动已结束");
  173. return;
  174. }
  175. ViewManager.Show<StoreView>(new object[]
  176. { ConstStoreTabId.STORE_EXCHANGE, ConstStoreSubId.STORE_ACTIVITY_EXCHANGE });
  177. }
  178. private void OnBtnTaskClick()
  179. {
  180. int activityID = ActivityDataManager.Instance.GetCurOpenActiveByType(ActivityType.YuanXiao);
  181. if (activityID == 0)
  182. {
  183. PromptController.Instance.ShowFloatTextPrompt("活动已结束");
  184. return;
  185. }
  186. ViewManager.Show<ActivityGetYuanXiaoTaskView>();
  187. }
  188. private void UpdateRedDots()
  189. {
  190. bool canPlay = ActivityGetYuanXiaoDataManager.Instance.HaveNewLevelCanPlay();
  191. for (int i = 0; i < _ui.m_list.numChildren; i++)
  192. {
  193. if (i == _curLevel)
  194. {
  195. RedDotController.Instance.SetComRedDot(_ui.m_list.GetChildAt(i).asCom, canPlay, "", -21, 29);
  196. }
  197. else
  198. {
  199. RedDotController.Instance.SetComRedDot(_ui.m_list.GetChildAt(i).asCom, false);
  200. }
  201. }
  202. RedDotController.Instance.SetComRedDot(_ui.m_btnTask,
  203. ActivityGetYuanXiaoDataManager.Instance.ShowTaskRedDots(TaskFuncType.YuanXiaoActivity), "", -25, 20);
  204. }
  205. private void AddEffect()
  206. {
  207. EffectUIPool.CreateEffectUI(_ui.m_bgEffect, "ui_Activity", "CLFG_BG_TX/CLFG_BG_TX",
  208. onComplete: (effect) =>
  209. {
  210. if (effect != null)
  211. {
  212. _effectUIDic.Add("YXJ_bg_tx", effect);
  213. }
  214. });
  215. EffectUIPool.CreateEffectUI(_ui.m_startBtnEffect, "ui_Activity",
  216. "CLFG_Start_Button/CLFG_Start_Button",
  217. onComplete: (effect) =>
  218. {
  219. if (effect != null)
  220. {
  221. _effectUIDic.Add("YXJ_Button", effect);
  222. }
  223. });
  224. EffectUIPool.CreateEffectUI(_ui.m_titleTextEffect, "ui_Activity", "CLFG_Text/CLFG_Text",
  225. onComplete: (effect) =>
  226. {
  227. if (effect != null)
  228. {
  229. _effectUIDic.Add("YXJ_Text", effect);
  230. }
  231. });
  232. EffectUIPool.CreateEffectUI(_ui.m_cloudEffect, "ui_Activity", "YXJ_Open_Down",
  233. onComplete: (effect) =>
  234. {
  235. if (effect != null)
  236. {
  237. _effectUIDic.Add("YXJ_Open_Down", effect);
  238. }
  239. });
  240. EffectUIPool.CreateEffectUI(_ui.m_doubaoEffect, "ui_Activity", "CLFG_Mid_Anma/CLFG_Mid_Anma",
  241. onComplete: (effect) =>
  242. {
  243. if (effect != null)
  244. {
  245. _effectUIDic.Add("RedPack_doubao_Loop_R", effect);
  246. }
  247. });
  248. }
  249. private void AutoLocationCurLevel()
  250. {
  251. _ui.m_list.ScrollToView(
  252. Mathf.Min(_curLevel, ActivityGetYuanXiaoDataManager.Instance.gameinfoList.Count - 1));
  253. }
  254. private void UpdateTime(object param)
  255. {
  256. long curTime = TimeHelper.ServerNow();
  257. int activityID = ActivityDataManager.Instance.GetCurOpenActiveByType(ActivityType.YuanXiao);
  258. var activityInfo = ActivityGlobalDataManager.Instance.GetActivityInfo(activityID);
  259. if (activityInfo != null)
  260. {
  261. long endTime = activityInfo.EndTime;
  262. _ui.m_txtTime.text = TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);
  263. }
  264. else
  265. {
  266. //_ui.m_txtTime.text = "已结束";
  267. //InitUI();
  268. OnBtnBackClick();
  269. }
  270. }
  271. private void OnBtnBackClick()
  272. {
  273. ViewManager.Show<MainUIView>(null, true);
  274. ViewManager.DeleteViewStackCountDown("MainUIView");
  275. }
  276. private void InitUI()
  277. {
  278. _ui.m_list.visible = false;
  279. _valueBarController.OnShown();
  280. _valueBarController.UpdateList(new List<int>());
  281. }
  282. }
  283. }