ActivityZCJBChapterView.cs 17 KB

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