ActivityZCJBChapterView.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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. _effectUI3 = EffectUIPool.CreateEffectUI(_ui.m_bgEffect, "ui_zj", "ZX_BG_TX");
  87. _effectUI4 =
  88. EffectUIPool.CreateEffectUI(_ui.m_chapter.m_compChapterScroll.m_nextEffect, "ui_zj", "ZX_Next_Boat");
  89. }
  90. protected override void AddEventListener()
  91. {
  92. }
  93. protected override void OnShown()
  94. {
  95. base.OnShown();
  96. GRoot.inst.touchable = false;
  97. SuitFosterProxy.SendGetSuitInfos().Coroutine();
  98. MusicManager.Instance.PlayCroutine(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT));
  99. if ((this.viewData as object[]) != null)
  100. {
  101. _chapterID = (int)(this.viewData as object[])[0];
  102. currentDifficulty = (int)(this.viewData as object[])[1];
  103. }
  104. else
  105. {
  106. _chapterID = (int)this.viewData;
  107. }
  108. MainStoryDataManager.currentChapterCfgId = _chapterID;
  109. activityID = ActivityDataManager.Instance.GetCurOpenActiveByType(17);
  110. //由于这里会切换特效,所以切换界面时进行清空
  111. EffectUIPool.Recycle(_effectUI2);
  112. _effectUI2 = null;
  113. if (_effFirst != null)
  114. {
  115. _effFirst.RemoveFromParent();
  116. }
  117. ActivityFightCfg chapterCfg = CommonDataManager.Tables.TblActivityFightCfg.GetOrDefault(_chapterID);
  118. indexY = 111.0f * Mathf.Max(0,
  119. (float)CommonDataManager.Tables.TblStoryLevelCfg.DataList.Where(a =>
  120. a.Type == chapterCfg.Type && a.SubType == chapterCfg.SubType &&
  121. a.ChapterId == chapterCfg.Id).ToList().Count -
  122. 5);
  123. gamey = GameObject.Find("Stage/GRoot/Window - StoryChapterUI/ContentPane/CompChapter/Container/Container");
  124. _ui.m_chapter.m_compChapterScroll.m_imgBegin.visible = false;
  125. _ui.m_chapter.m_compChapterScroll.m_nextEffect.visible = false;
  126. _ui.m_targetSuit.visible = false;
  127. Timers.inst.StartCoroutine(InitChapter());
  128. //Timers.inst.Add(0.2f, 1, SetContainerY);
  129. _ui.m_chapter.m_compChapterScroll.target.y = 1;
  130. _valueBarController.OnShown();
  131. UI_ComponentValueBar valueBar = UI_ComponentValueBar.Proxy(_ui.m_valueBar);
  132. valueBar.m_c1.selectedIndex = 12;
  133. UI_ComponentValueBar.ProxyEnd();
  134. _valueBarController.UpdateList(new List<int>()
  135. {
  136. CommonDataManager.Tables.TblActivityDressCfg.GetGroup1ByActivityId(activityID)[0].Comsume[0].ItemId,
  137. ConstItemID.DIAMOND_PURPLE, ConstItemID.DIAMOND_RED
  138. });
  139. _ui.m_selectChapter.visible = false;
  140. _ui.m_switchChapter.target.visible = false;
  141. _ui.m_bonusBox.visible = false;
  142. _ui.m_ActivityZCJB.visible = true;
  143. ActivityOpenCfg _activityCfg = CommonDataManager.Tables.TblActivityOpenCfg.GetOrDefault(activityID);
  144. long endTime = TimeUtil.DateTimeToTimestamp(_activityCfg.EndTime);
  145. long curTime = TimeHelper.ServerNow();
  146. TimeUtil.FormattingTime(curTime, endTime, out int num, out string str);
  147. _ui.m_ZCJBTimeText.text = "剩余时间:" + TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);
  148. Timers.inst.Add(1, 0, UpdateActivityTime);
  149. //
  150. _ui.m_t0.SetHook("canHit", () => { GRoot.inst.touchable = true; });
  151. _ui.m_t0.Play();
  152. }
  153. protected override void OnHide()
  154. {
  155. base.OnHide();
  156. _unPasslevelItem = null;
  157. _endLevelItem = null;
  158. // _ui.m_chapter.RemoveChildren(0, 0, true);
  159. GRoot.inst.touchable = true;
  160. _valueBarController.OnHide();
  161. Timers.inst.Remove(SetContainerY);
  162. Timers.inst.Remove(UpdateActivityTime);
  163. }
  164. protected override void RemoveEventListener()
  165. {
  166. base.RemoveEventListener();
  167. }
  168. private void OnClickBtnBack()
  169. {
  170. ViewManager.GoBackFrom(typeof(ActivityZCJBChapterView).FullName);
  171. //GameController.GoBackToMainView();
  172. }
  173. private void OnClickBtnHome()
  174. {
  175. GameController.GoBackToMainView();
  176. }
  177. private IEnumerator InitChapter()
  178. {
  179. ActivityFightCfg chapterCfg = CommonDataManager.Tables.TblActivityFightCfg.GetOrDefault(_chapterID);
  180. var list = CommonDataManager.Tables.TblStoryLevelCfg.DataList.Where(a =>
  181. a.Type == chapterCfg.Type && a.SubType == chapterCfg.SubType &&
  182. a.ChapterId == chapterCfg.Id).ToList();
  183. int endLevel = 0;
  184. int UnlockCount = 0;
  185. _compChapter = _ui.m_chapter.m_compChapterScroll.target;
  186. float starPosY = _ui.m_chapter.m_compChapterScroll.m_imgBegin.y;
  187. int lineGap = 4500 / list.Count;
  188. //根据困难程度选择显示图片
  189. currentDifficulty = chapterCfg.Type;
  190. if (currentDifficulty == 1)
  191. {
  192. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("yytz_gq_bj");
  193. }
  194. else
  195. {
  196. currentDifficulty = 0;
  197. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("yytz_gq_bj");
  198. }
  199. //_comEff.visible = false;
  200. //_effFirst.visible = false;
  201. for (int i = 0; i < 20; i++)
  202. {
  203. GObject obj = _ui.m_chapter.m_compChapterScroll.target.GetChild("g" + (19 - i + 1));
  204. obj.SetPosition(obj.x, starPosY - lineGap * i - 300, 0);
  205. StoryLevelCfg levelCfg = i < list.Count ? list[i] : null;
  206. UI_CompStoryLevelItem levelItem = UI_CompStoryLevelItem.Proxy(obj);
  207. levelItem.m_fightBg.visible = true;
  208. levelItem.m_loaDialogBg.visible = true;
  209. if (levelCfg == null)
  210. {
  211. levelItem.target.visible = false;
  212. continue;
  213. }
  214. if (i == 0 || InstanceZonesDataManager.CheckLevelPass(levelCfg.Id - 1))
  215. {
  216. UnlockCount++;
  217. levelItem.target.data = levelCfg;
  218. levelItem.target.visible = true;
  219. levelItem.target.onClick.Clear();
  220. levelItem.target.onClick.Add(OnListItemClick);
  221. string showId = "1-" + (i + 1);
  222. levelItem.m_txtFightOrder.text = showId;
  223. if (levelCfg.FightID.Length > 0)
  224. {
  225. levelItem.m_c1.selectedIndex = 1;
  226. int score = InstanceZonesDataManager.GetScoreHighest(levelCfg.Id);
  227. if (score <= 0)
  228. {
  229. levelItem.m_flower.target.visible = false;
  230. }
  231. else
  232. {
  233. levelItem.m_flower.target.visible = true;
  234. int starCount = InstanceZonesDataManager.GetStarCountHistory(levelCfg.Id);
  235. StoryUtil.UpdateStar(starCount, levelItem.m_flower.target, Mathf.Max(0, currentDifficulty));
  236. }
  237. }
  238. else
  239. {
  240. levelItem.m_c1.selectedIndex = 0;
  241. levelItem.m_flower.target.visible = false;
  242. levelItem.m_txtName.text = levelCfg.Name;
  243. levelItem.m_comDialogBg.m_loabg.url = ResPathUtil.GetBgImgPath("wxsg_zjBg");
  244. levelItem.m_comDialogBg.m_loaIcon.url = ResPathUtil.GetChapterGuideIconPath("wxsg_zjBg");
  245. levelItem.m_comDialogBg.m_c1.selectedIndex = Random.Range(0, 10);
  246. levelItem.m_txtDialogOrder.text = showId;
  247. }
  248. //根据困难程度选择显示图片
  249. if (currentDifficulty == 1)
  250. {
  251. levelItem.m_loaDialogBg.url = "ui://Main/zxian_btn_jq_jy";
  252. levelItem.m_fightBg.url = "ui://Main/zxian_btn_zd_jy";
  253. levelItem.m_txtFightOrder.text =
  254. string.Format("{0}", StringUtil.GetColorText(showId.ToString(), "#E3F8FF"));
  255. levelItem.m_fightIconA.alpha = 0;
  256. levelItem.m_fightIconB.alpha = 0;
  257. _ui.m_txtBg.url = "ui://Main/zxian_chapter_dec_jy";
  258. _ui.m_txtChapter.strokeColor = new Color(0.592f, 0.773f, 0.961f, 1.000f);
  259. }
  260. else
  261. {
  262. levelItem.m_loaDialogBg.url = "ui://Main/zxian_btn_jq";
  263. levelItem.m_fightBg.url = "ui://Main/zxian_btn_zd";
  264. levelItem.m_txtFightOrder.text =
  265. string.Format("{0}", StringUtil.GetColorText(showId.ToString(), "#FFEABF"));
  266. levelItem.m_fightIconA.alpha = 0;
  267. levelItem.m_fightIconB.alpha = 0;
  268. _ui.m_txtBg.url = "ui://Main/zxian_chapter_dec";
  269. _ui.m_txtChapter.strokeColor = new Color(1.000f, 0.686f, 0.318f, 1.000f);
  270. }
  271. levelItem.m_holder.visible = !InstanceZonesDataManager.CheckLevelPass(levelCfg.Id);
  272. if (!InstanceZonesDataManager.CheckLevelPass(levelCfg.Id))
  273. {
  274. //设置为解锁关卡
  275. MainStoryDataManager.currentLevelCfgId = levelCfg.Id;
  276. _unPasslevelItem = levelItem.target;
  277. //levelItem.target.AddChild(_comEff);
  278. //_comEff.visible = true;
  279. //设置解锁特效
  280. string effName;
  281. if (currentDifficulty == 1)
  282. {
  283. effName = effArray[levelItem.m_c1.selectedIndex] + "_Bule";
  284. }
  285. else
  286. {
  287. effName = effArray[levelItem.m_c1.selectedIndex];
  288. }
  289. if (levelItem.m_c1.selectedIndex == 0)
  290. {
  291. if (levelItem.m_c2.selectedIndex == 0)
  292. {
  293. _effectUI2 = EffectUIPool.CreateEffectUI(_effFirst.GetChild("effect_jq_left").asGraph,
  294. "ui_zj", effName);
  295. _effFirst.GetChild("effect_jq_left").rotationY = 180;
  296. }
  297. else
  298. {
  299. _effectUI2 = EffectUIPool.CreateEffectUI(_effFirst.GetChild("effect_jq").asGraph,
  300. "ui_zj", effName);
  301. _effFirst.GetChild("effect_jq").rotationY = 0;
  302. }
  303. }
  304. else
  305. {
  306. _effectUI2 = EffectUIPool.CreateEffectUI(_effFirst.GetChild("effect_zd").asGraph, "ui_zj",
  307. effName);
  308. if (levelItem.m_c2.selectedIndex == 0)
  309. {
  310. _effFirst.GetChild("effect_zd").rotationY = 0;
  311. }
  312. else
  313. {
  314. _effFirst.GetChild("effect_zd").rotationY = 180;
  315. }
  316. }
  317. levelItem.target.AddChild(_effFirst);
  318. levelItem.m_fightBg.visible = false;
  319. levelItem.m_loaDialogBg.visible = false;
  320. levelItem.m_t0.Play();
  321. _effFirst.visible = true;
  322. //Timers.inst.Add(1.7f, 1, HideEffect, obj);
  323. }
  324. if (levelCfg.Order > endLevel)
  325. {
  326. endLevel = levelCfg.Order;
  327. _endLevelItem = levelItem.target;
  328. }
  329. }
  330. else
  331. {
  332. levelItem.target.visible = false;
  333. }
  334. UI_CompStoryLevelItem.ProxyEnd();
  335. }
  336. yield return new WaitForEndOfFrame();
  337. _ui.m_chapter.m_compChapterScroll.target.y =
  338. 0; //Mathf.Max(0, _ui.m_chapter.target.height - _ui.m_chapter.m_compChapterScroll.target.height);
  339. if (gamey != null)
  340. gamey.transform.position = new Vector3(0, indexY, 0);
  341. }
  342. private void SetContainerY(object param = null)
  343. {
  344. _ui.m_chapter.m_compChapterScroll.target.y =
  345. 1; //Mathf.Max(0, _ui.m_chapter.target.height - _ui.m_chapter.m_compChapterScroll.target.height - 1);
  346. }
  347. private void HideEffect(object param = null)
  348. {
  349. //_effFirst.visible = false;
  350. }
  351. private void OnListItemClick(EventContext context)
  352. {
  353. GObject obj = context.sender as GObject;
  354. StoryLevelCfg storyLevelCfg = (StoryLevelCfg)obj.data;
  355. MainStoryDataManager.currentLevelCfgId = storyLevelCfg.Id;
  356. InstanceZonesController.ShowLevelView(storyLevelCfg.Id, StudioDataManager.Instance.OnFinishZCJBStoryLevel);
  357. }
  358. private void OnClickLevelItem(EventContext context)
  359. {
  360. UI_CompStoryLevelItem levelItem = UI_CompStoryLevelItem.Proxy(context.sender as GObject);
  361. int levelCfgId = (int)levelItem.target.data;
  362. UI_CompStoryLevelItem.ProxyEnd();
  363. StoryController.ShowLevelView(levelCfgId);
  364. }
  365. private void UpdateActivityTime(object param = null)
  366. {
  367. ActivityOpenCfg _activityCfg = CommonDataManager.Tables.TblActivityOpenCfg.GetOrDefault(activityID);
  368. long endTime = TimeUtil.DateTimeToTimestamp(_activityCfg.EndTime);
  369. long curTime = TimeHelper.ServerNow();
  370. if (endTime < curTime)
  371. {
  372. PromptController.Instance.ShowFloatTextPrompt("活动已结束");
  373. Timers.inst.Remove(UpdateActivityTime);
  374. GameController.GoBackToMainView();
  375. return;
  376. }
  377. long timeActivity = ActivityGlobalDataManager.Instance.GetActivityInfoOneByType(17).EndTime -
  378. TimeHelper.ServerNow();
  379. _ui.m_ZCJBTimeText.text = "剩余时间:" + (timeActivity > TimeUtil.SECOND_PER_DAY * 1000
  380. ? TimeUtil.FormattingTimeTo_DDHHmm(timeActivity)
  381. : TimeUtil.FormattingTimeTo_HHmmss(timeActivity));
  382. }
  383. }
  384. }