ActivityStoryChapterView.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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 ActivityStoryChapterView : BaseWindow
  11. {
  12. private UI_ActivityStoryChapterUI _ui;
  13. private int _chapterID;
  14. private int _activityID;
  15. private ActivityOpenCfg _activityCfg;
  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. //当前章节索引
  27. private int newIndex;
  28. //y轴移动索引
  29. private float indexY;
  30. private GameObject gamey;
  31. //特效类型数组,这里后面可以二维数组,放向左和向右的
  32. private string[] effArray = new string[2] { "ZJ_JuQing", "ZJ_ZD" };
  33. private int currentDifficulty;
  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_ActivityStoryChapterUI.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_chapter.m_compChapterScroll.m_imgBegin.onClick.Add(OnClickNext);
  80. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("zxian_bg3");
  81. _effFirst = new GComponent();
  82. _effFirst = UIPackage.CreateObject(UI_MainUI.PACKAGE_NAME, "ComEff").asCom;
  83. _effectUI3 = EffectUIPool.CreateEffectUI(_ui.m_bgEffect, "ui_zj", "ZX_BG_TX");
  84. _effectUI4 = EffectUIPool.CreateEffectUI(_ui.m_chapter.m_compChapterScroll.m_nextEffect, "ui_zj", "ZX_Next_Boat");
  85. }
  86. protected override void OnShown()
  87. {
  88. base.OnShown();
  89. GRoot.inst.touchable = false;
  90. SuitFosterProxy.SendGetSuitInfos().Coroutine();
  91. MusicManager.Instance.PlayCroutine(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT));
  92. _activityID = (int)viewData;
  93. _activityCfg = ActivityOpenCfgArray.Instance.GetCfg(_activityID);
  94. _chapterID = _activityCfg.params3Arr[0];
  95. _ui.m_activityID.selectedPage = _activityID.ToString();
  96. _valueBarController.OnShown();
  97. _ui.m_t0.SetHook("canHit", () => { GRoot.inst.touchable = true; });
  98. _ui.m_t0.Play();
  99. UpdateView();
  100. UpdateTime();
  101. Timers.inst.Add(1, 0, UpdateTime);
  102. }
  103. protected override void OnHide()
  104. {
  105. base.OnHide();
  106. _unPasslevelItem = null;
  107. _endLevelItem = null;
  108. // _ui.m_chapter.RemoveChildren(0, 0, true);
  109. GRoot.inst.touchable = true;
  110. _valueBarController.OnHide();
  111. Timers.inst.Remove(SetContainerY);
  112. Timers.inst.Remove(UpdateTime);
  113. }
  114. protected override void RemoveEventListener()
  115. {
  116. base.RemoveEventListener();
  117. }
  118. private void OnClickBtnBack()
  119. {
  120. ViewManager.GoBackFrom(typeof(StoryChapterView).FullName);
  121. //GameController.GoBackToMainView();
  122. }
  123. private void UpdateView()
  124. {
  125. //由于这里会切换特效,所以切换界面时进行清空
  126. EffectUIPool.Recycle(_effectUI2);
  127. _effectUI2 = null;
  128. if (_effFirst != null)
  129. {
  130. _effFirst.RemoveFromParent();
  131. }
  132. StoryChapterCfg chapterCfg = StoryChapterCfgArray.Instance.GetCfg(_chapterID);
  133. newIndex = StoryUtil.GetChapterOrder(chapterCfg.id);
  134. indexY = 111.0f * Mathf.Max(0, (float)StoryLevelCfgArray.Instance.GetCfgsBytypeAndsubTypeAndchapterId(chapterCfg.type, chapterCfg.subType, chapterCfg.id).Count - 5);
  135. gamey = GameObject.Find("Stage/GRoot/Window - StoryChapterUI/ContentPane/CompChapter/Container/Container");
  136. _ui.m_chapter.m_compChapterScroll.m_imgBegin.visible = false;
  137. _ui.m_chapter.m_compChapterScroll.m_nextEffect.visible = false;
  138. Timers.inst.StartCoroutine(InitChapter());
  139. //Timers.inst.Add(0.2f, 1, SetContainerY);
  140. _ui.m_chapter.m_compChapterScroll.target.y = 1;
  141. //招财进宝活动
  142. if (chapterCfg.subType == 2)
  143. {
  144. UI_ComponentValueBar valueBar = UI_ComponentValueBar.Proxy(_ui.m_valueBar);
  145. valueBar.m_c1.selectedIndex = 12;
  146. UI_ComponentValueBar.ProxyEnd();
  147. _valueBarController.UpdateList(new List<int>() { ConstItemID.DIAMOND_PURPLE, ConstItemID.DIAMOND_RED });
  148. long timeActivity = ActivityGlobalDataManager.Instance.GetActivityInfoOneByType(17).EndTime - TimeHelper.ServerNow();
  149. }
  150. else
  151. {
  152. UI_ComponentValueBar valueBar = UI_ComponentValueBar.Proxy(_ui.m_valueBar);
  153. valueBar.m_c1.selectedIndex = 1;
  154. UI_ComponentValueBar.ProxyEnd();
  155. }
  156. }
  157. private void OnClickNext()
  158. {
  159. StoryChapterCfg chapterSuitCfg = StoryChapterCfgArray.Instance.GetCfg(_chapterID);
  160. if (MainStoryDataManager.CheckChapterUnlock(_chapterID + 1) && StoryController.CheckSuitGot(chapterSuitCfg.suitId))
  161. {
  162. Timers.inst.Remove(SetContainerY);
  163. _chapterID += 1;
  164. MainStoryDataManager.currentChapterCfgId = _chapterID;
  165. //ViewManager.Show<StoryChapterView>(new object[] { (_chapterID+1), currentDifficulty });
  166. UpdateView();
  167. }
  168. else
  169. {
  170. StoryChapterCfg chapterCfg = StoryChapterCfgArray.Instance.GetCfg(_chapterID + 1);
  171. if (!StoryController.CheckSuitGot(chapterSuitCfg.suitId))
  172. {
  173. PromptController.Instance.ShowFloatTextPrompt("需集齐所需套装");
  174. }
  175. else if (GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl) < chapterCfg.lvl)
  176. {
  177. PromptController.Instance.ShowFloatTextPrompt(string.Format("角色等级达到{0}级开启", chapterCfg.lvl));
  178. }
  179. }
  180. }
  181. private IEnumerator InitChapter()
  182. {
  183. ActivityFightCfg chapterCfg = ActivityFightCfgArray.Instance.GetCfg(_chapterID);
  184. var list = StoryLevelCfgArray.Instance.GetCfgsBytypeAndsubTypeAndchapterId(chapterCfg.type, chapterCfg.subType, chapterCfg.id);
  185. int endLevel = 0;
  186. int UnlockCount = 0;
  187. _compChapter = _ui.m_chapter.m_compChapterScroll.target;
  188. float starPosY = _ui.m_chapter.m_compChapterScroll.m_imgBegin.y;
  189. int lineGap = 4500 / list.Count;
  190. StoryLevelCfg lastLevelCfg = list[list.Count - 1];
  191. //根据困难程度选择显示图片
  192. currentDifficulty = chapterCfg.subType;
  193. if (currentDifficulty == 1)
  194. {
  195. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("zhangjie_bg");
  196. }
  197. else
  198. {
  199. currentDifficulty = 0;
  200. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("bg_zhuxian");
  201. }
  202. //_comEff.visible = false;
  203. //_effFirst.visible = false;
  204. for (int i = 0; i < 20; i++)
  205. {
  206. GObject obj = _ui.m_chapter.m_compChapterScroll.target.GetChild("g" + (19 - i + 1));
  207. obj.SetPosition(obj.x, starPosY - lineGap * i - 300, 0); ;
  208. StoryLevelCfg levelCfg = i < list.Count ? list[i] : null;
  209. UI_CompStoryLevelItem levelItem = UI_CompStoryLevelItem.Proxy(obj);
  210. levelItem.m_fightBg.visible = true;
  211. levelItem.m_loaDialogBg.visible = true;
  212. if (levelCfg != null && MainStoryDataManager.CheckLevelUnlock(levelCfg.id))
  213. {
  214. UnlockCount++;
  215. levelItem.target.data = levelCfg.id;
  216. levelItem.target.visible = true;
  217. levelItem.target.onClick.Clear();
  218. levelItem.target.onClick.Add(OnClickLevelItem);
  219. string showId = StoryUtil.GetChapterOrder(_chapterID) + "-" + levelCfg.order;
  220. levelItem.m_txtDialogOrder.text = showId;
  221. levelItem.m_txtFightOrder.text = showId;
  222. levelItem.m_activityID.selectedPage = _activityID.ToString();
  223. levelItem.m_c1.selectedIndex = 1;
  224. int score = InstanceZonesDataManager.GetScoreHighest(levelCfg.id);
  225. if (score <= 0)
  226. {
  227. levelItem.m_flower.target.visible = false;
  228. }
  229. else
  230. {
  231. levelItem.m_flower.target.visible = true;
  232. int starCount = InstanceZonesDataManager.GetStarCountHistory(levelCfg.id);
  233. StoryUtil.UpdateStar(starCount, levelItem.m_flower.target, Mathf.Max(0, currentDifficulty));
  234. }
  235. //根据困难程度选择显示图片
  236. if (currentDifficulty == 1)
  237. {
  238. levelItem.m_loaDialogBg.url = "ui://Main/zxian_btn_jq_jy";
  239. levelItem.m_fightBg.url = "ui://Main/zxian_btn_zd_jy";
  240. levelItem.m_txtFightOrder.text = string.Format("{0}", StringUtil.GetColorText(showId.ToString(), "#E3F8FF"));
  241. levelItem.m_fightIconA.alpha = 0;
  242. levelItem.m_fightIconB.alpha = 0;
  243. }
  244. else
  245. {
  246. levelItem.m_loaDialogBg.url = "ui://Main/zxian_btn_jq";
  247. levelItem.m_fightBg.url = "ui://Main/zxian_btn_zd";
  248. levelItem.m_txtFightOrder.text = string.Format("{0}", StringUtil.GetColorText(showId.ToString(), "#FFEABF"));
  249. levelItem.m_fightIconA.alpha = 0;
  250. levelItem.m_fightIconB.alpha = 0;
  251. }
  252. levelItem.m_holder.visible = !InstanceZonesDataManager.CheckLevelPass(levelCfg.id);
  253. if (!InstanceZonesDataManager.CheckLevelPass(levelCfg.id))
  254. {
  255. //设置为解锁关卡
  256. MainStoryDataManager.currentLevelCfgId = levelCfg.id;
  257. _unPasslevelItem = levelItem.target;
  258. //levelItem.target.AddChild(_comEff);
  259. //_comEff.visible = true;
  260. //设置解锁特效
  261. string effName;
  262. if (currentDifficulty == 1)
  263. {
  264. effName = effArray[levelItem.m_c1.selectedIndex] + "_Bule";
  265. }
  266. else
  267. {
  268. effName = effArray[levelItem.m_c1.selectedIndex];
  269. }
  270. if (levelItem.m_c1.selectedIndex == 0)
  271. {
  272. if (levelItem.m_c2.selectedIndex == 0)
  273. {
  274. _effectUI2 = EffectUIPool.CreateEffectUI(_effFirst.GetChild("effect_jq_left").asGraph, "ui_zj", effName);
  275. _effFirst.GetChild("effect_jq_left").rotationY = 180;
  276. }
  277. else
  278. {
  279. _effectUI2 = EffectUIPool.CreateEffectUI(_effFirst.GetChild("effect_jq").asGraph, "ui_zj", effName);
  280. _effFirst.GetChild("effect_jq").rotationY = 0;
  281. }
  282. }
  283. else
  284. {
  285. _effectUI2 = EffectUIPool.CreateEffectUI(_effFirst.GetChild("effect_zd").asGraph, "ui_zj", effName);
  286. if (levelItem.m_c2.selectedIndex == 0)
  287. {
  288. _effFirst.GetChild("effect_zd").rotationY = 0;
  289. }
  290. else
  291. {
  292. _effFirst.GetChild("effect_zd").rotationY = 180;
  293. }
  294. }
  295. levelItem.target.AddChild(_effFirst);
  296. levelItem.m_fightBg.visible = false;
  297. levelItem.m_loaDialogBg.visible = false;
  298. levelItem.m_t0.Play();
  299. _effFirst.visible = true;
  300. //Timers.inst.Add(1.7f, 1, HideEffect, obj);
  301. }
  302. if (levelCfg.order > endLevel)
  303. {
  304. endLevel = levelCfg.order;
  305. _endLevelItem = levelItem.target;
  306. }
  307. }
  308. else
  309. {
  310. levelItem.target.visible = false;
  311. }
  312. UI_CompStoryLevelItem.ProxyEnd();
  313. }
  314. yield return new WaitForEndOfFrame();
  315. _ui.m_chapter.m_compChapterScroll.target.y = 0; //Mathf.Max(0, _ui.m_chapter.target.height - _ui.m_chapter.m_compChapterScroll.target.height);
  316. if (gamey != null)
  317. gamey.transform.position = new Vector3(0, indexY, 0);
  318. }
  319. private void SetContainerY(object param = null)
  320. {
  321. _ui.m_chapter.m_compChapterScroll.target.y = 1; //Mathf.Max(0, _ui.m_chapter.target.height - _ui.m_chapter.m_compChapterScroll.target.height - 1);
  322. }
  323. private void HideEffect(object param = null)
  324. {
  325. //_effFirst.visible = false;
  326. }
  327. private void OnClickLevelItem(EventContext context)
  328. {
  329. UI_CompStoryLevelItem levelItem = UI_CompStoryLevelItem.Proxy(context.sender as GObject);
  330. int levelCfgId = (int)levelItem.target.data;
  331. UI_CompStoryLevelItem.ProxyEnd();
  332. StoryController.ShowLevelView(levelCfgId);
  333. TryCompleteGuide();
  334. }
  335. private void UpdateTime(object param = null)
  336. {
  337. long endTime = TimeUtil.DateTimeToTimestamp(_activityCfg.endTime);
  338. long curTime = TimeHelper.ServerNow();
  339. if (endTime < curTime)
  340. {
  341. Timers.inst.Remove(UpdateTime);
  342. return;
  343. }
  344. TimeUtil.FormattingTime(curTime, endTime, out int num, out string str);
  345. string timeStr = TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);
  346. _ui.m_txtTime.text = timeStr;
  347. }
  348. }
  349. }