ActivityZCJBChapterView.cs 17 KB

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