ActivityZCJBChapterView.cs 19 KB

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