ActivityStoryChapterView.cs 16 KB

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