ActivityGetYuanXiaoEntryView.cs 10 KB

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