ActivityZCJBChapterView.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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. Timers.inst.StartCoroutine(InitChapter());
  117. //Timers.inst.Add(0.2f, 1, SetContainerY);
  118. _ui.m_chapter.m_compChapterScroll.target.y = 1;
  119. _valueBarController.OnShown();
  120. UI_ComponentValueBar valueBar = UI_ComponentValueBar.Proxy(_ui.m_valueBar);
  121. valueBar.m_c1.selectedIndex = 12;
  122. UI_ComponentValueBar.ProxyEnd();
  123. _valueBarController.UpdateList(new List<int>() { 3000023, ConstItemID.DIAMOND_PURPLE, ConstItemID.DIAMOND_RED });
  124. _ui.m_selectChapter.visible = false;
  125. _ui.m_switchChapter.visible = false;
  126. _ui.m_bonusBox.visible = false;
  127. _ui.m_ActivityZCJB.visible = true;
  128. long timeActivity = ActivityGlobalDataManager.Instance.GetActivityInfoOneByType(17).EndTime - TimeHelper.ServerNow();
  129. _ui.m_ZCJBTimeText.text = "剩余时间:" + (timeActivity > TimeUtil.SECOND_PER_DAY * 1000 ? TimeUtil.FormattingTimeTo_DDHHmm(timeActivity) : TimeUtil.FormattingTimeTo_HHmmss(timeActivity));
  130. Timers.inst.Add(60.0f, 0, UpdateActivityTime);
  131. //
  132. _ui.m_t0.SetHook("canHit", () => { _ui.target.touchable = true; });
  133. _ui.m_t0.Play();
  134. }
  135. protected override void OnHide()
  136. {
  137. base.OnHide();
  138. _unPasslevelItem = null;
  139. _endLevelItem = null;
  140. // _ui.m_chapter.RemoveChildren(0, 0, true);
  141. GRoot.inst.touchable = true;
  142. _valueBarController.OnHide();
  143. Timers.inst.Remove(SetContainerY);
  144. Timers.inst.Remove(UpdateActivityTime);
  145. }
  146. protected override void RemoveEventListener()
  147. {
  148. base.RemoveEventListener();
  149. }
  150. private void OnClickBtnBack()
  151. {
  152. ViewManager.GoBackFrom(typeof(ActivityZCJBChapterView).FullName);
  153. //GameController.GoBackToMainView();
  154. }
  155. private void OnClickBtnHome()
  156. {
  157. GameController.GoBackToMainView();
  158. }
  159. private IEnumerator InitChapter()
  160. {
  161. ActivityFightCfg chapterCfg = ActivityFightCfgArray.Instance.GetCfg(_chapterID);
  162. var list = StoryLevelCfgArray.Instance.GetCfgsBytypeAndsubTypeAndchapterId(chapterCfg.type, chapterCfg.subType, chapterCfg.id);
  163. int endLevel = 0;
  164. int UnlockCount = 0;
  165. _compChapter = _ui.m_chapter.m_compChapterScroll.target;
  166. float starPosY = _ui.m_chapter.m_compChapterScroll.m_imgBegin.y;
  167. int lineGap = 4500 / list.Count;
  168. StoryLevelCfg lastLevelCfg = list[list.Count - 1];
  169. //根据困难程度选择显示图片
  170. currentDifficulty = chapterCfg.type;
  171. if (currentDifficulty == 1)
  172. {
  173. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("zcjb_gkbj");
  174. }
  175. else
  176. {
  177. currentDifficulty = 0;
  178. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("zcjb_gkbj");
  179. }
  180. //_comEff.visible = false;
  181. //_effFirst.visible = false;
  182. for (int i = 0; i < 20; i++)
  183. {
  184. GObject obj = _ui.m_chapter.m_compChapterScroll.target.GetChild("g" + (19 - i + 1));
  185. obj.SetPosition(obj.x, starPosY - lineGap * i - 300, 0); ;
  186. StoryLevelCfg levelCfg = i < list.Count ? list[i] : null;
  187. UI_CompStoryLevelItem levelItem = UI_CompStoryLevelItem.Proxy(obj);
  188. levelItem.m_fightBg.visible = true;
  189. levelItem.m_loaDialogBg.visible = true;
  190. if(levelCfg == null)
  191. {
  192. levelItem.target.visible = false;
  193. continue;
  194. }
  195. if (i == 0 || InstanceZonesDataManager.CheckLevelPass(levelCfg.id - 1))
  196. {
  197. UnlockCount++;
  198. levelItem.target.data = levelCfg;
  199. levelItem.target.visible = true;
  200. levelItem.target.onClick.Clear();
  201. levelItem.target.onClick.Add(OnListItemClick);
  202. string showId = "0-"+ (i+1);
  203. levelItem.m_txtFightOrder.text = showId;
  204. if (levelCfg.fightID.Length > 0)
  205. {
  206. levelItem.m_c1.selectedIndex = 1;
  207. int score = InstanceZonesDataManager.GetScoreHighest(levelCfg.id);
  208. if (score <= 0)
  209. {
  210. levelItem.m_flower.target.visible = false;
  211. }
  212. else
  213. {
  214. levelItem.m_flower.target.visible = true;
  215. int starCount = InstanceZonesDataManager.GetStarCountHistory(levelCfg.id);
  216. StoryUtil.UpdateStar(starCount, levelItem.m_flower.target, Mathf.Max(0, currentDifficulty));
  217. }
  218. }
  219. else
  220. {
  221. levelItem.m_c1.selectedIndex = 0;
  222. levelItem.m_flower.target.visible = false;
  223. levelItem.m_txtName.text = levelCfg.name;
  224. levelItem.m_comDialogBg.m_c1.selectedIndex = Random.Range(0, 10);
  225. }
  226. //根据困难程度选择显示图片
  227. if (currentDifficulty == 1)
  228. {
  229. levelItem.m_loaDialogBg.url = "ui://Main/zxian_btn_jq_jy";
  230. levelItem.m_fightBg.url = "ui://Main/zxian_btn_zd_jy";
  231. levelItem.m_txtFightOrder.text = string.Format("{0}", StringUtil.GetColorText(showId.ToString(), "#E3F8FF"));
  232. levelItem.m_fightIconA.alpha = 0;
  233. levelItem.m_fightIconB.alpha = 0;
  234. _ui.m_txtBg.url = "ui://Main/zxian_chapter_dec_jy";
  235. _ui.m_txtChapter.strokeColor = new Color(0.592f, 0.773f, 0.961f, 1.000f);
  236. }
  237. else
  238. {
  239. levelItem.m_loaDialogBg.url = "ui://Main/zxian_btn_jq";
  240. levelItem.m_fightBg.url = "ui://Main/zxian_btn_zd";
  241. levelItem.m_txtFightOrder.text = string.Format("{0}", StringUtil.GetColorText(showId.ToString(), "#FFEABF"));
  242. levelItem.m_fightIconA.alpha = 0;
  243. levelItem.m_fightIconB.alpha = 0;
  244. _ui.m_txtBg.url = "ui://Main/zxian_chapter_dec";
  245. _ui.m_txtChapter.strokeColor = new Color(1.000f, 0.686f, 0.318f, 1.000f);
  246. }
  247. levelItem.m_holder.visible = !InstanceZonesDataManager.CheckLevelPass(levelCfg.id);
  248. if (!InstanceZonesDataManager.CheckLevelPass(levelCfg.id))
  249. {
  250. //设置为解锁关卡
  251. MainStoryDataManager.currentLevelCfgId = levelCfg.id;
  252. _unPasslevelItem = levelItem.target;
  253. //levelItem.target.AddChild(_comEff);
  254. //_comEff.visible = true;
  255. //设置解锁特效
  256. string effName;
  257. if (currentDifficulty == 1)
  258. {
  259. effName = effArray[levelItem.m_c1.selectedIndex] + "_Bule";
  260. }
  261. else
  262. {
  263. effName = effArray[levelItem.m_c1.selectedIndex];
  264. }
  265. if (levelItem.m_c1.selectedIndex == 0)
  266. {
  267. if (levelItem.m_c2.selectedIndex == 0)
  268. {
  269. _effectUI2 = EffectUIPool.CreateEffectUI(_effFirst.GetChild("effect_jq_left").asGraph, "ui_zj", effName);
  270. _effFirst.GetChild("effect_jq_left").rotationY = 180;
  271. }
  272. else
  273. {
  274. _effectUI2 = EffectUIPool.CreateEffectUI(_effFirst.GetChild("effect_jq").asGraph, "ui_zj", effName);
  275. _effFirst.GetChild("effect_jq").rotationY = 0;
  276. }
  277. }
  278. else
  279. {
  280. _effectUI2 = EffectUIPool.CreateEffectUI(_effFirst.GetChild("effect_zd").asGraph, "ui_zj", effName);
  281. if (levelItem.m_c2.selectedIndex == 0)
  282. {
  283. _effFirst.GetChild("effect_zd").rotationY = 0;
  284. }
  285. else
  286. {
  287. _effFirst.GetChild("effect_zd").rotationY = 180;
  288. }
  289. }
  290. levelItem.target.AddChild(_effFirst);
  291. levelItem.m_fightBg.visible = false;
  292. levelItem.m_loaDialogBg.visible = false;
  293. levelItem.m_t0.Play();
  294. _effFirst.visible = true;
  295. //Timers.inst.Add(1.7f, 1, HideEffect, obj);
  296. }
  297. if (levelCfg.order > endLevel)
  298. {
  299. endLevel = levelCfg.order;
  300. _endLevelItem = levelItem.target;
  301. }
  302. }
  303. else
  304. {
  305. levelItem.target.visible = false;
  306. }
  307. UI_CompStoryLevelItem.ProxyEnd();
  308. }
  309. yield return new WaitForEndOfFrame();
  310. _ui.m_chapter.m_compChapterScroll.target.y = 0; //Mathf.Max(0, _ui.m_chapter.target.height - _ui.m_chapter.m_compChapterScroll.target.height);
  311. if (gamey != null)
  312. gamey.transform.position = new Vector3(0, indexY, 0);
  313. }
  314. private void SetContainerY(object param = null)
  315. {
  316. _ui.m_chapter.m_compChapterScroll.target.y = 1; //Mathf.Max(0, _ui.m_chapter.target.height - _ui.m_chapter.m_compChapterScroll.target.height - 1);
  317. }
  318. private void HideEffect(object param = null)
  319. {
  320. //_effFirst.visible = false;
  321. }
  322. private void OnListItemClick(EventContext context)
  323. {
  324. GObject obj = context.sender as GObject;
  325. StoryLevelCfg storyLevelCfg = (StoryLevelCfg)obj.data;
  326. MainStoryDataManager.currentLevelCfgId = storyLevelCfg.id;
  327. InstanceZonesController.ShowLevelView(storyLevelCfg.id, StudioDataManager.Instance.OnFinishZCJBStoryLevel);
  328. }
  329. private void OnClickLevelItem(EventContext context)
  330. {
  331. UI_CompStoryLevelItem levelItem = UI_CompStoryLevelItem.Proxy(context.sender as GObject);
  332. int levelCfgId = (int)levelItem.target.data;
  333. UI_CompStoryLevelItem.ProxyEnd();
  334. StoryController.ShowLevelView(levelCfgId);
  335. }
  336. private void UpdateActivityTime(object param = null)
  337. {
  338. long timeActivity = ActivityGlobalDataManager.Instance.GetActivityInfoOneByType(17).EndTime - TimeHelper.ServerNow();
  339. _ui.m_ZCJBTimeText.text = "剩余时间:" + (timeActivity > TimeUtil.SECOND_PER_DAY * 1000 ? TimeUtil.FormattingTimeTo_DDHHmm(timeActivity) : TimeUtil.FormattingTimeTo_HHmmss(timeActivity));
  340. }
  341. }
  342. }