ActivityZCJBChapterView.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. using FairyGUI;
  2. using UI.CommonGame;
  3. using UI.Main;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using System.Collections;
  7. using Assets.Game.HotUpdate.Data;
  8. using ET;
  9. namespace GFGGame
  10. {
  11. public class ActivityZCJBChapterView : BaseWindow
  12. {
  13. private UI_StoryChapterUI _ui;
  14. private int _chapterID;
  15. private GComponent _compChapter;
  16. private ValueBarController _valueBarController;
  17. private GObject _unPasslevelItem;
  18. private GObject _endLevelItem;
  19. private EffectUI _effectUI1;
  20. private EffectUI _effectUI2;
  21. private EffectUI _effectUI3;
  22. private EffectUI _effectUI4;
  23. private GComponent _comEff;
  24. private GComponent _effFirst;
  25. //y轴移动索引
  26. private float indexY;
  27. private GameObject gamey;
  28. //特效类型数组,这里后面可以二维数组,放向左和向右的
  29. private string[] effArray = new string[2] { "ZJ_JuQing", "ZJ_ZD" };
  30. private int currentDifficulty;
  31. public override void Dispose()
  32. {
  33. EffectUIPool.Recycle(_effectUI1);
  34. _effectUI1 = null;
  35. EffectUIPool.Recycle(_effectUI2);
  36. _effectUI2 = null;
  37. EffectUIPool.Recycle(_effectUI3);
  38. _effectUI3 = null;
  39. EffectUIPool.Recycle(_effectUI4);
  40. _effectUI4 = null;
  41. if (_comEff != null)
  42. {
  43. _comEff.RemoveFromParent();
  44. _comEff.Dispose();
  45. }
  46. if (_effFirst != null)
  47. {
  48. _effFirst.RemoveFromParent();
  49. _effFirst.Dispose();
  50. }
  51. if (_valueBarController != null)
  52. {
  53. _valueBarController.Dispose();
  54. _valueBarController = null;
  55. }
  56. if (_ui != null)
  57. {
  58. _ui.Dispose();
  59. _ui = null;
  60. }
  61. base.Dispose();
  62. }
  63. protected override void Init()
  64. {
  65. base.Init();
  66. _ui = UI_StoryChapterUI.Create();
  67. viewCom = _ui.target;
  68. isfullScreen = true;
  69. isReturnView = true;
  70. }
  71. protected override void OnInit()
  72. {
  73. base.OnInit();
  74. _valueBarController = new ValueBarController(_ui.m_valueBar);
  75. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  76. _ui.m_btnHome.onClick.Add(OnClickBtnHome);
  77. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("ksxy_gq_bj");
  78. //_comEff = new GComponent();
  79. //_comEff = UIPackage.CreateObject(UI_MainUI.PACKAGE_NAME, "ComEff").asCom;
  80. //_effectUI1 = EffectUIPool.CreateEffectUI(_comEff.GetChild("holder").asGraph, "ui_gk", "ui_gk_sg");
  81. _effFirst = new GComponent();
  82. _effFirst = UIPackage.CreateObject(UI_MainUI.PACKAGE_NAME, "ComEff").asCom;
  83. _effectUI3 = EffectUIPool.CreateEffectUI(_ui.m_bgEffect, "ui_zj", "ZX_BG_TX");
  84. _effectUI4 = EffectUIPool.CreateEffectUI(_ui.m_chapter.m_compChapterScroll.m_nextEffect, "ui_zj", "ZX_Next_Boat");
  85. }
  86. protected override void AddEventListener()
  87. {
  88. }
  89. protected override void OnShown()
  90. {
  91. base.OnShown();
  92. GRoot.inst.touchable = false;
  93. SuitFosterProxy.SendGetSuitInfos().Coroutine();
  94. MusicManager.Instance.PlayCroutine(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT));
  95. if ((this.viewData as object[]) != null)
  96. {
  97. _chapterID = (int)(this.viewData as object[])[0];
  98. currentDifficulty = (int)(this.viewData as object[])[1];
  99. }
  100. else
  101. {
  102. _chapterID = (int)this.viewData;
  103. }
  104. MainStoryDataManager.currentChapterCfgId = _chapterID;
  105. //由于这里会切换特效,所以切换界面时进行清空
  106. EffectUIPool.Recycle(_effectUI2);
  107. _effectUI2 = null;
  108. if (_effFirst != null)
  109. {
  110. _effFirst.RemoveFromParent();
  111. }
  112. ActivityFightCfg chapterCfg = ActivityFightCfgArray.Instance.GetCfg(_chapterID);
  113. indexY = 111.0f * Mathf.Max(0, (float)StoryLevelCfgArray.Instance.GetCfgsBytypeAndsubTypeAndchapterId(chapterCfg.type, chapterCfg.subType, chapterCfg.id).Count - 5);
  114. gamey = GameObject.Find("Stage/GRoot/Window - StoryChapterUI/ContentPane/CompChapter/Container/Container");
  115. _ui.m_chapter.m_compChapterScroll.m_imgBegin.visible = false;
  116. _ui.m_chapter.m_compChapterScroll.m_nextEffect.visible = false;
  117. _ui.m_targetSuit.visible = false;
  118. Timers.inst.StartCoroutine(InitChapter());
  119. //Timers.inst.Add(0.2f, 1, SetContainerY);
  120. _ui.m_chapter.m_compChapterScroll.target.y = 1;
  121. _valueBarController.OnShown();
  122. UI_ComponentValueBar valueBar = UI_ComponentValueBar.Proxy(_ui.m_valueBar);
  123. valueBar.m_c1.selectedIndex = 12;
  124. UI_ComponentValueBar.ProxyEnd();
  125. _valueBarController.UpdateList(new List<int>() { ActivityDressCfgArray.Instance.dataArray[0].comsumeArr[0][0], ConstItemID.DIAMOND_PURPLE, ConstItemID.DIAMOND_RED });
  126. _ui.m_selectChapter.visible = false;
  127. _ui.m_switchChapter.target.visible = false;
  128. _ui.m_bonusBox.visible = false;
  129. _ui.m_ActivityZCJB.visible = true;
  130. ActivityOpenCfg _activityCfg = ActivityOpenCfgArray.Instance.GetCfg(5006);
  131. long endTime = TimeUtil.DateTimeToTimestamp(_activityCfg.endTime);
  132. long curTime = TimeHelper.ServerNow();
  133. TimeUtil.FormattingTime(curTime, endTime, out int num, out string str);
  134. _ui.m_ZCJBTimeText.text = "剩余时间:" + TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);
  135. Timers.inst.Add(1, 0, UpdateActivityTime);
  136. //
  137. _ui.m_t0.SetHook("canHit", () => { GRoot.inst.touchable = true; });
  138. _ui.m_t0.Play();
  139. }
  140. protected override void OnHide()
  141. {
  142. base.OnHide();
  143. _unPasslevelItem = null;
  144. _endLevelItem = null;
  145. // _ui.m_chapter.RemoveChildren(0, 0, true);
  146. GRoot.inst.touchable = true;
  147. _valueBarController.OnHide();
  148. Timers.inst.Remove(SetContainerY);
  149. Timers.inst.Remove(UpdateActivityTime);
  150. }
  151. protected override void RemoveEventListener()
  152. {
  153. base.RemoveEventListener();
  154. }
  155. private void OnClickBtnBack()
  156. {
  157. ViewManager.GoBackFrom(typeof(ActivityZCJBChapterView).FullName);
  158. //GameController.GoBackToMainView();
  159. }
  160. private void OnClickBtnHome()
  161. {
  162. GameController.GoBackToMainView();
  163. }
  164. private IEnumerator InitChapter()
  165. {
  166. ActivityFightCfg chapterCfg = ActivityFightCfgArray.Instance.GetCfg(_chapterID);
  167. var list = StoryLevelCfgArray.Instance.GetCfgsBytypeAndsubTypeAndchapterId(chapterCfg.type, chapterCfg.subType, chapterCfg.id);
  168. int endLevel = 0;
  169. int UnlockCount = 0;
  170. _compChapter = _ui.m_chapter.m_compChapterScroll.target;
  171. float starPosY = _ui.m_chapter.m_compChapterScroll.m_imgBegin.y;
  172. int lineGap = 4500 / list.Count;
  173. StoryLevelCfg lastLevelCfg = list[list.Count - 1];
  174. //根据困难程度选择显示图片
  175. currentDifficulty = chapterCfg.type;
  176. if (currentDifficulty == 1)
  177. {
  178. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("ksxy_gq_bj");
  179. }
  180. else
  181. {
  182. currentDifficulty = 0;
  183. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("ksxy_gq_bj");
  184. }
  185. //_comEff.visible = false;
  186. //_effFirst.visible = false;
  187. for (int i = 0; i < 20; i++)
  188. {
  189. GObject obj = _ui.m_chapter.m_compChapterScroll.target.GetChild("g" + (19 - i + 1));
  190. obj.SetPosition(obj.x, starPosY - lineGap * i - 300, 0);
  191. StoryLevelCfg levelCfg = i < list.Count ? list[i] : null;
  192. UI_CompStoryLevelItem levelItem = UI_CompStoryLevelItem.Proxy(obj);
  193. levelItem.m_fightBg.visible = true;
  194. levelItem.m_loaDialogBg.visible = true;
  195. if(levelCfg == null)
  196. {
  197. levelItem.target.visible = false;
  198. continue;
  199. }
  200. if (i == 0 || InstanceZonesDataManager.CheckLevelPass(levelCfg.id - 1))
  201. {
  202. UnlockCount++;
  203. levelItem.target.data = levelCfg;
  204. levelItem.target.visible = true;
  205. levelItem.target.onClick.Clear();
  206. levelItem.target.onClick.Add(OnListItemClick);
  207. string showId = "0-"+ (i+1);
  208. levelItem.m_txtFightOrder.text = showId;
  209. if (levelCfg.fightID.Length > 0)
  210. {
  211. levelItem.m_c1.selectedIndex = 1;
  212. int score = InstanceZonesDataManager.GetScoreHighest(levelCfg.id);
  213. if (score <= 0)
  214. {
  215. levelItem.m_flower.target.visible = false;
  216. }
  217. else
  218. {
  219. levelItem.m_flower.target.visible = true;
  220. int starCount = InstanceZonesDataManager.GetStarCountHistory(levelCfg.id);
  221. StoryUtil.UpdateStar(starCount, levelItem.m_flower.target, Mathf.Max(0, currentDifficulty));
  222. }
  223. }
  224. else
  225. {
  226. levelItem.m_c1.selectedIndex = 0;
  227. levelItem.m_flower.target.visible = false;
  228. levelItem.m_txtName.text = levelCfg.name;
  229. levelItem.m_comDialogBg.m_c1.selectedIndex = Random.Range(0, 10);
  230. }
  231. //根据困难程度选择显示图片
  232. if (currentDifficulty == 1)
  233. {
  234. levelItem.m_loaDialogBg.url = "ui://Main/zxian_btn_jq_jy";
  235. levelItem.m_fightBg.url = "ui://Main/zxian_btn_zd_jy";
  236. levelItem.m_txtFightOrder.text = string.Format("{0}", StringUtil.GetColorText(showId.ToString(), "#E3F8FF"));
  237. levelItem.m_fightIconA.alpha = 0;
  238. levelItem.m_fightIconB.alpha = 0;
  239. _ui.m_txtBg.url = "ui://Main/zxian_chapter_dec_jy";
  240. _ui.m_txtChapter.strokeColor = new Color(0.592f, 0.773f, 0.961f, 1.000f);
  241. }
  242. else
  243. {
  244. levelItem.m_loaDialogBg.url = "ui://Main/zxian_btn_jq";
  245. levelItem.m_fightBg.url = "ui://Main/zxian_btn_zd";
  246. levelItem.m_txtFightOrder.text = string.Format("{0}", StringUtil.GetColorText(showId.ToString(), "#FFEABF"));
  247. levelItem.m_fightIconA.alpha = 0;
  248. levelItem.m_fightIconB.alpha = 0;
  249. _ui.m_txtBg.url = "ui://Main/zxian_chapter_dec";
  250. _ui.m_txtChapter.strokeColor = new Color(1.000f, 0.686f, 0.318f, 1.000f);
  251. }
  252. levelItem.m_holder.visible = !InstanceZonesDataManager.CheckLevelPass(levelCfg.id);
  253. if (!InstanceZonesDataManager.CheckLevelPass(levelCfg.id))
  254. {
  255. //设置为解锁关卡
  256. MainStoryDataManager.currentLevelCfgId = levelCfg.id;
  257. _unPasslevelItem = levelItem.target;
  258. //levelItem.target.AddChild(_comEff);
  259. //_comEff.visible = true;
  260. //设置解锁特效
  261. string effName;
  262. if (currentDifficulty == 1)
  263. {
  264. effName = effArray[levelItem.m_c1.selectedIndex] + "_Bule";
  265. }
  266. else
  267. {
  268. effName = effArray[levelItem.m_c1.selectedIndex];
  269. }
  270. if (levelItem.m_c1.selectedIndex == 0)
  271. {
  272. if (levelItem.m_c2.selectedIndex == 0)
  273. {
  274. _effectUI2 = EffectUIPool.CreateEffectUI(_effFirst.GetChild("effect_jq_left").asGraph, "ui_zj", effName);
  275. _effFirst.GetChild("effect_jq_left").rotationY = 180;
  276. }
  277. else
  278. {
  279. _effectUI2 = EffectUIPool.CreateEffectUI(_effFirst.GetChild("effect_jq").asGraph, "ui_zj", effName);
  280. _effFirst.GetChild("effect_jq").rotationY = 0;
  281. }
  282. }
  283. else
  284. {
  285. _effectUI2 = EffectUIPool.CreateEffectUI(_effFirst.GetChild("effect_zd").asGraph, "ui_zj", effName);
  286. if (levelItem.m_c2.selectedIndex == 0)
  287. {
  288. _effFirst.GetChild("effect_zd").rotationY = 0;
  289. }
  290. else
  291. {
  292. _effFirst.GetChild("effect_zd").rotationY = 180;
  293. }
  294. }
  295. levelItem.target.AddChild(_effFirst);
  296. levelItem.m_fightBg.visible = false;
  297. levelItem.m_loaDialogBg.visible = false;
  298. levelItem.m_t0.Play();
  299. _effFirst.visible = true;
  300. //Timers.inst.Add(1.7f, 1, HideEffect, obj);
  301. }
  302. if (levelCfg.order > endLevel)
  303. {
  304. endLevel = levelCfg.order;
  305. _endLevelItem = levelItem.target;
  306. }
  307. }
  308. else
  309. {
  310. levelItem.target.visible = false;
  311. }
  312. UI_CompStoryLevelItem.ProxyEnd();
  313. }
  314. yield return new WaitForEndOfFrame();
  315. _ui.m_chapter.m_compChapterScroll.target.y = 0; //Mathf.Max(0, _ui.m_chapter.target.height - _ui.m_chapter.m_compChapterScroll.target.height);
  316. if (gamey != null)
  317. gamey.transform.position = new Vector3(0, indexY, 0);
  318. }
  319. private void SetContainerY(object param = null)
  320. {
  321. _ui.m_chapter.m_compChapterScroll.target.y = 1; //Mathf.Max(0, _ui.m_chapter.target.height - _ui.m_chapter.m_compChapterScroll.target.height - 1);
  322. }
  323. private void HideEffect(object param = null)
  324. {
  325. //_effFirst.visible = false;
  326. }
  327. private void OnListItemClick(EventContext context)
  328. {
  329. GObject obj = context.sender as GObject;
  330. StoryLevelCfg storyLevelCfg = (StoryLevelCfg)obj.data;
  331. MainStoryDataManager.currentLevelCfgId = storyLevelCfg.id;
  332. InstanceZonesController.ShowLevelView(storyLevelCfg.id, StudioDataManager.Instance.OnFinishZCJBStoryLevel);
  333. }
  334. private void OnClickLevelItem(EventContext context)
  335. {
  336. UI_CompStoryLevelItem levelItem = UI_CompStoryLevelItem.Proxy(context.sender as GObject);
  337. int levelCfgId = (int)levelItem.target.data;
  338. UI_CompStoryLevelItem.ProxyEnd();
  339. StoryController.ShowLevelView(levelCfgId);
  340. }
  341. private void UpdateActivityTime(object param = null)
  342. {
  343. ActivityOpenCfg _activityCfg = ActivityOpenCfgArray.Instance.GetCfg(5006);
  344. long endTime = TimeUtil.DateTimeToTimestamp(_activityCfg.endTime);
  345. long curTime = TimeHelper.ServerNow();
  346. if (endTime < curTime)
  347. {
  348. PromptController.Instance.ShowFloatTextPrompt("活动已结束");
  349. Timers.inst.Remove(UpdateActivityTime);
  350. GameController.GoBackToMainView();
  351. return;
  352. }
  353. long timeActivity = ActivityGlobalDataManager.Instance.GetActivityInfoOneByType(17).EndTime - TimeHelper.ServerNow();
  354. _ui.m_ZCJBTimeText.text = "剩余时间:" + (timeActivity > TimeUtil.SECOND_PER_DAY * 1000 ? TimeUtil.FormattingTimeTo_DDHHmm(timeActivity) : TimeUtil.FormattingTimeTo_HHmmss(timeActivity));
  355. }
  356. }
  357. }