ActivityZCJBChapterView.cs 16 KB

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