ActivityZCJBChapterView.cs 18 KB

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