ActivityStoryChapterView.cs 18 KB

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