ActivityStoryChapterView.cs 16 KB

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