ActivityGetYuanXiaoEntryView.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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 ValueBarController _valueBarController;
  14. private Dictionary<string, EffectUI> _effectUIDic = new Dictionary<string, EffectUI>();
  15. private int _curLevel;
  16. public override void Dispose()
  17. {
  18. // Clear Effect
  19. foreach (var v in _effectUIDic)
  20. {
  21. EffectUIPool.Recycle(v.Value);
  22. }
  23. _effectUIDic.Clear();
  24. if (_valueBarController != null)
  25. {
  26. _valueBarController.Dispose();
  27. _valueBarController = null;
  28. }
  29. if (_ui != null)
  30. {
  31. _ui.Dispose();
  32. }
  33. _ui = null;
  34. base.Dispose();
  35. }
  36. protected override void OnInit()
  37. {
  38. base.OnInit();
  39. packageName = UI_ActivityGetYuanXiaoEntryUI.PACKAGE_NAME;
  40. _ui = UI_ActivityGetYuanXiaoEntryUI.Create();
  41. viewCom = _ui.target;
  42. isReturnView = true;
  43. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("hd_yx_bg");
  44. _valueBarController = new ValueBarController(_ui.m_valueBar);
  45. _ui.m_list.itemRenderer = ListRenderer;
  46. _ui.m_btnStart.onClick.Add(OnBtnStartClick);
  47. _ui.m_btnTask.onClick.Add(OnBtnTaskClick);
  48. _ui.m_btnShop.onClick.Add(OnBtnShopClick);
  49. _ui.m_btnBack.onClick.Add(OnBtnBackClick);
  50. AddEffect();
  51. }
  52. protected async override void OnShown()
  53. {
  54. base.OnShown();
  55. _valueBarController.OnShown();
  56. _valueBarController.UpdateList(new List<int>() { ConstItemID .YUANXIAO_REWARD, ConstItemID.YUANXIAO_GAME_CONSUME});
  57. _ui.m_list.visible = false;
  58. var result = await ActivityGetYuanXiaoProxy.ReqGetActivityGameInfos();
  59. if (!isShowing)
  60. {
  61. return;
  62. }
  63. if (!result)
  64. {
  65. OnBtnBackClick();
  66. return;
  67. }
  68. _ui.m_list.visible = true;
  69. _ui.m_listShow.Play();
  70. _curLevel = ActivityGetYuanXiaoDataManager.Instance.GetCurLevel();
  71. _ui.m_list.numItems = ActivityGetYuanXiaoDataManager.Instance.gameinfoList.Count;
  72. _ui.m_list.selectedIndex = Mathf.Min(_curLevel, ActivityGetYuanXiaoDataManager.Instance.gameinfoList.Count - 1);
  73. AutoLocationCurLevel();
  74. UpdateRedDots();
  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. PickUpGame pickUpGame = PickUpGameArray.Instance.dataArray[index];
  102. level.m_spendIcon.url = ResPathUtil.GetIconPath(ItemCfgArray.Instance.GetCfg(pickUpGame.comsumePassArr[0][0]).res, "png");
  103. level.m_iconLevel.url = string.Format("ui://ActivityGetYuanXiao/yx_xg_{0}", index % 4 + 1);
  104. level.m_num.text = pickUpGame.comsumePassArr[0][1].ToString();
  105. int stateIndex = 0;
  106. if (index > _curLevel)
  107. {
  108. stateIndex = 1;
  109. }
  110. else if(index < _curLevel)
  111. {
  112. stateIndex = 2;
  113. }
  114. level.m_c1.selectedIndex = stateIndex;
  115. UI_level.ProxyEnd();
  116. }
  117. private void OnBtnStartClick()
  118. {
  119. if (_ui.m_list.selectedIndex > _curLevel)
  120. {
  121. PromptController.Instance.ShowFloatTextPrompt("请先通关前置关卡");
  122. return;
  123. }
  124. if (_ui.m_list.selectedIndex < _curLevel)
  125. {
  126. PromptController.Instance.ShowFloatTextPrompt("关卡已通过");
  127. return;
  128. }
  129. if (ActivityGetYuanXiaoDataManager.Instance.HaveNewLevelCanPlay() == false)
  130. {
  131. PromptController.Instance.ShowFloatTextPrompt("游园门票不足,请查看任务列表");
  132. return;
  133. }
  134. PickUpGame cfg = PickUpGameArray.Instance.dataArray[_ui.m_list.selectedIndex];
  135. ViewManager.Show<ActivityGetYuanXiaoTargetView>(cfg);
  136. }
  137. private async void StartGame()
  138. {
  139. int activityID = ActivityDataManager.Instance.GetCurOpenActiveByType(ActivityType.YuanXiao);
  140. if (activityID == 0)
  141. {
  142. return;
  143. }
  144. PickUpGame cfg = PickUpGameArray.Instance.dataArray[_ui.m_list.selectedIndex];
  145. var result = await MiniGameProxy.ReqMiniGameStart(cfg.id, cfg.type, activityID);
  146. if (!result || !isShowing) return;
  147. ViewManager.Show<ActivityGetYuanXiaoView>(new object[] { cfg, activityID });
  148. }
  149. private void OnBtnShopClick()
  150. {
  151. ViewManager.Show<StoreView>(new object[] { ConstStoreTabId.STORE_EXCHANGE, ConstStoreSubId.STORE_ACTIVITY_EXCHANGE });
  152. }
  153. private void OnBtnTaskClick()
  154. {
  155. int activityID = ActivityDataManager.Instance.GetCurOpenActiveByType(ActivityType.YuanXiao);
  156. if (activityID == 0)
  157. {
  158. return;
  159. }
  160. ViewManager.Show<ActivityGetYuanXiaoTaskView>();
  161. }
  162. private void UpdateRedDots()
  163. {
  164. bool canPlay = ActivityGetYuanXiaoDataManager.Instance.HaveNewLevelCanPlay();
  165. for (int i = 0; i < _ui.m_list.numChildren; i++)
  166. {
  167. if (i == _curLevel)
  168. {
  169. RedDotController.Instance.SetComRedDot(_ui.m_list.GetChildAt(i).asCom, canPlay, "", -21, 29);
  170. }
  171. else
  172. {
  173. RedDotController.Instance.SetComRedDot(_ui.m_list.GetChildAt(i).asCom, false);
  174. }
  175. }
  176. RedDotController.Instance.SetComRedDot(_ui.m_btnTask,
  177. TaskDataManager.Instance.CheckTaskRewardCanGet(TaskFuncType.YuanXiaoActivity), "", -25, 20);
  178. }
  179. private void AddEffect()
  180. {
  181. _effectUIDic.Add("YXJ_bg_tx", EffectUIPool.CreateEffectUI(_ui.m_bgEffect, "ui_Activity", "YXJ_bg_tx"));
  182. _effectUIDic.Add("YXJ_Button", EffectUIPool.CreateEffectUI(_ui.m_startBtnEffect, "ui_Activity", "YXJ_Button"));
  183. _effectUIDic.Add("YXJ_Middle", EffectUIPool.CreateEffectUI(_ui.m_yuanXiaoEffect, "ui_Activity", "YXJ_Middle"));
  184. _effectUIDic.Add("YXJ_Text", EffectUIPool.CreateEffectUI(_ui.m_titleTextEffect, "ui_Activity", "YXJ_Text"));
  185. _effectUIDic.Add("YXJ_Open_Down", EffectUIPool.CreateEffectUI(_ui.m_cloudEffect, "ui_Activity", "YXJ_Open_Down"));
  186. _effectUIDic.Add("YXJ_Open_Up", EffectUIPool.CreateEffectUI(_ui.m_leafEffect, "ui_Activity", "YXJ_Open_Up"));
  187. _effectUIDic.Add("RedPack_doubao_Loop_R", EffectUIPool.CreateEffectUI(_ui.m_doubaoEffect, "ui_Activity", "RedPack_doubao_Loop_R"));
  188. }
  189. private void AutoLocationCurLevel()
  190. {
  191. _ui.m_list.ScrollToView(Mathf.Min(_curLevel, ActivityGetYuanXiaoDataManager.Instance.gameinfoList.Count - 1));
  192. }
  193. private void UpdateTime(object param)
  194. {
  195. long curTime = TimeHelper.ServerNow();
  196. int activityID = ActivityDataManager.Instance.GetCurOpenActiveByType(ActivityType.YuanXiao);
  197. if (activityID == 0)
  198. {
  199. OnBtnBackClick();
  200. return;
  201. }
  202. var activityInfo = ActivityGlobalDataManager.Instance.GetActivityInfo(activityID);
  203. if (activityInfo != null)
  204. {
  205. long endTime = activityInfo.EndTime;
  206. _ui.m_txtTime.text = TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);
  207. }
  208. }
  209. private void OnBtnBackClick()
  210. {
  211. ViewManager.Show<MainUIView>(null, true);
  212. ViewManager.DeleteViewStackCountDown("MainUIView");
  213. }
  214. }
  215. }