StoryChapterView.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. using FairyGUI;
  2. using UI.CommonGame;
  3. using UI.Main;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using System.Collections;
  7. namespace GFGGame
  8. {
  9. public class StoryChapterView : BaseView
  10. {
  11. private UI_StoryChapterUI _ui;
  12. private int _chapterID;
  13. private GComponent _compChapter;
  14. private ValueBarController _valueBarController;
  15. private GObject _unPasslevelItem;
  16. private GObject _endLevelItem;
  17. private EffectUI _effectUI1;
  18. private GComponent _comEff;
  19. public override void Dispose()
  20. {
  21. if (_comEff != null)
  22. {
  23. _comEff.RemoveFromParent();
  24. _comEff.Dispose();
  25. }
  26. if (_valueBarController != null)
  27. {
  28. _valueBarController.Dispose();
  29. _valueBarController = null;
  30. }
  31. EffectUIPool.Recycle(_effectUI1);
  32. _effectUI1 = null;
  33. if (_ui != null)
  34. {
  35. _ui.Dispose();
  36. _ui = null;
  37. }
  38. base.Dispose();
  39. }
  40. protected override void Init()
  41. {
  42. base.Init();
  43. _ui = UI_StoryChapterUI.Create();
  44. viewCom = _ui.target;
  45. isfullScreen = true;
  46. }
  47. protected override void OnInit()
  48. {
  49. base.OnInit();
  50. _valueBarController = new ValueBarController(_ui.m_valueBar);
  51. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  52. _ui.m_btnHome.onClick.Add(OnClickBtnHome);
  53. _ui.m_bonusBox1.target.onClick.Add(() =>
  54. {
  55. OnClickBonusBox(_ui.m_bonusBox1, 0);
  56. });
  57. _ui.m_bonusBox2.target.onClick.Add(() =>
  58. {
  59. OnClickBonusBox(_ui.m_bonusBox2, 1);
  60. });
  61. _ui.m_bonusBox3.target.onClick.Add(() =>
  62. {
  63. OnClickBonusBox(_ui.m_bonusBox3, 2);
  64. });
  65. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("zxian_bg3");
  66. _comEff = new GComponent();
  67. _comEff = UIPackage.CreateObject(UI_MainUI.PACKAGE_NAME, "ComEff").asCom;
  68. _effectUI1 = EffectUIPool.CreateEffectUI(_comEff.GetChild("holder").asGraph, "ui_gk", "ui_gk_sg");
  69. }
  70. protected override void AddEventListener()
  71. {
  72. EventAgent.AddEventListener(ConstMessage.NOTICE_MAINSTORY_BOXBONUS_STATE, UpdateBonusBox);
  73. }
  74. protected override void OnShown()
  75. {
  76. base.OnShown();
  77. _ui.target.touchable = false;
  78. MusicManager.Instance.Play(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT));
  79. _chapterID = (int)viewData;
  80. MainStoryDataManager.currentChapterCfgId = _chapterID;
  81. Timers.inst.StartCoroutine(InitChapter());
  82. _valueBarController.OnShown();
  83. _ui.target.touchable = true;
  84. Timers.inst.AddUpdate(CheckGuide);
  85. }
  86. protected override void OnHide()
  87. {
  88. base.OnHide();
  89. _unPasslevelItem = null;
  90. _endLevelItem = null;
  91. // _ui.m_chapter.RemoveChildren(0, 0, true);
  92. _valueBarController.OnHide();
  93. Timers.inst.Remove(CheckGuide);
  94. }
  95. protected override void RemoveEventListener()
  96. {
  97. base.RemoveEventListener();
  98. EventAgent.RemoveEventListener(ConstMessage.NOTICE_MAINSTORY_BOXBONUS_STATE, UpdateBonusBox);
  99. }
  100. private void OnClickBtnBack()
  101. {
  102. ViewManager.GoBackFrom(ViewName.STORY_CHAPTER_VIEW);
  103. }
  104. private void OnClickBtnHome()
  105. {
  106. GameController.GoBackToMainView();
  107. }
  108. private IEnumerator InitChapter()
  109. {
  110. StoryChapterCfg chapterCfg = StoryChapterCfgArray.Instance.GetCfg(_chapterID);
  111. _ui.m_txtChapterName0.text = chapterCfg.name.Length > 0 ? chapterCfg.name[0].ToString() : "";
  112. _ui.m_txtChapterName1.text = chapterCfg.name.Length > 1 ? chapterCfg.name[1].ToString() : "";
  113. _ui.m_txtChapterName2.text = chapterCfg.name.Length > 2 ? chapterCfg.name[2].ToString() : "";
  114. _ui.m_txtChapterName3.text = chapterCfg.name.Length > 3 ? chapterCfg.name[3].ToString() : "";
  115. _ui.m_txtChapterName4.text = chapterCfg.name.Length > 4 ? chapterCfg.name[4].ToString() : "";
  116. int order = StoryUtil.GetChapterOrder(chapterCfg.id);
  117. _ui.m_txtChapter.text = order < 10 ? "0" + order : order.ToString();
  118. int starCountChapter = InstanceZonesDataManager.GetChapterStarCount(_chapterID, chapterCfg.type, chapterCfg.subType);
  119. _ui.m_txtStarCount.text = "" + starCountChapter + "/" + chapterCfg.bonusStar3;
  120. UpdateBonusBoxName(_ui.m_bonusBox1, "" + chapterCfg.bonusStar1);
  121. UpdateBonusBoxName(_ui.m_bonusBox2, "" + chapterCfg.bonusStar2);
  122. UpdateBonusBoxName(_ui.m_bonusBox3, "" + chapterCfg.bonusStar3);
  123. UpdateBonusBox();
  124. var list = StoryLevelCfgArray.Instance.GetCfgsBytypeAndsubTypeAndchapterId(chapterCfg.type, chapterCfg.subType, chapterCfg.id);
  125. int endLevel = 0;
  126. int UnlockCount = 0;
  127. _compChapter = _ui.m_chapter.m_compChapterScroll.target;
  128. float starPosY = _ui.m_chapter.m_compChapterScroll.m_imgBegin.y;
  129. int lineGap = 4500 / list.Count;
  130. for (int i = 0; i < 20; i++)
  131. {
  132. GObject obj = _ui.m_chapter.m_compChapterScroll.target.GetChild("g" + (i + 1));
  133. obj.SetPosition(obj.x, starPosY - lineGap * i - 300, 0); ;
  134. StoryLevelCfg levelCfg = i < list.Count ? list[i] : null;
  135. UI_CompStoryLevelItem levelItem = UI_CompStoryLevelItem.Proxy(obj);
  136. if (levelCfg != null && MainStoryDataManager.CheckLevelUnlock(levelCfg.id))
  137. {
  138. UnlockCount++;
  139. levelItem.target.data = levelCfg.id;
  140. levelItem.target.visible = true;
  141. levelItem.target.onClick.Clear();
  142. levelItem.target.onClick.Add(OnClickLevelItem);
  143. string showId = StoryUtil.GetChapterOrder(_chapterID) + "-" + levelCfg.order;
  144. levelItem.m_txtDialogOrder.text = showId;
  145. levelItem.m_txtFightOrder.text = showId;
  146. if (levelCfg.fightID.Length > 0)
  147. {
  148. levelItem.m_c1.selectedIndex = 1;
  149. int score = InstanceZonesDataManager.GetScoreHighest(levelCfg.id);
  150. if (score <= 0)
  151. {
  152. levelItem.m_flower.target.visible = false;
  153. }
  154. else
  155. {
  156. levelItem.m_flower.target.visible = true;
  157. int starCount = InstanceZonesDataManager.GetStarCountHistory(levelCfg.id);
  158. StoryUtil.UpdateStar(starCount, levelItem.m_flower.target);
  159. }
  160. }
  161. else
  162. {
  163. levelItem.m_c1.selectedIndex = 0;
  164. levelItem.m_flower.target.visible = false;
  165. levelItem.m_txtName.text = levelCfg.name;
  166. levelItem.m_comDialogBg.m_loabg.url = ResPathUtil.GetBgImgPath(chapterCfg.bgRes);
  167. levelItem.m_comDialogBg.m_loaIcon.url = ResPathUtil.GetChapterGuideIconPath(chapterCfg.bgRes);
  168. levelItem.m_comDialogBg.m_c1.selectedIndex = Random.Range(0, 10);
  169. }
  170. levelItem.m_holder.visible = !InstanceZonesDataManager.CheckLevelPass(levelCfg.id);
  171. if (!InstanceZonesDataManager.CheckLevelPass(levelCfg.id))
  172. {
  173. //设置为解锁关卡
  174. MainStoryDataManager.currentLevelCfgId = levelCfg.id;
  175. _unPasslevelItem = levelItem.target;
  176. levelItem.target.AddChild(_comEff);
  177. }
  178. if (levelCfg.order > endLevel)
  179. {
  180. endLevel = levelCfg.order;
  181. _endLevelItem = levelItem.target;
  182. }
  183. }
  184. else
  185. {
  186. levelItem.target.visible = false;
  187. }
  188. UI_CompStoryLevelItem.ProxyEnd();
  189. }
  190. yield return new WaitForEndOfFrame();
  191. _ui.m_chapter.m_compChapterScroll.target.y = Mathf.Max(0, _ui.m_chapter.target.height - _ui.m_chapter.m_compChapterScroll.target.height);
  192. }
  193. private void OnClickLevelItem(EventContext context)
  194. {
  195. UI_CompStoryLevelItem levelItem = UI_CompStoryLevelItem.Proxy(context.sender as GObject);
  196. int levelCfgId = (int)levelItem.target.data;
  197. UI_CompStoryLevelItem.ProxyEnd();
  198. StoryController.ShowLevelView(levelCfgId);
  199. TryCompleteGuide();
  200. }
  201. private void UpdateBonusBoxName(UI_CompBonusBox bonusBox, string name)
  202. {
  203. bonusBox.m_txtName.text = name;
  204. }
  205. private void UpdateBonusBox()
  206. {
  207. UpdateBonusBoxStatus(_ui.m_bonusBox1, 0);
  208. UpdateBonusBoxStatus(_ui.m_bonusBox2, 1);
  209. UpdateBonusBoxStatus(_ui.m_bonusBox3, 2);
  210. }
  211. private void UpdateBonusBoxStatus(UI_CompBonusBox bonusBox, int index)
  212. {
  213. int status = MainStoryDataManager.GetChapterBonusStatus(MainStoryDataManager.currentChapterCfgId, index);
  214. bonusBox.m_iconActive.visible = status == ConstBonusStatus.CAN_GET;
  215. // bonusBox.m_ComRewardEffect.visible = status == ConstBonusStatus.CAN_GET;
  216. if (status == ConstBonusStatus.GOT)
  217. {
  218. bonusBox.m_icon.url = "ui://Main/zxian_gift_get";
  219. }
  220. else
  221. {
  222. bonusBox.m_icon.url = "ui://Main/zxian_gift_unget";
  223. }
  224. bonusBox.target.data = status;
  225. }
  226. private async void OnClickBonusBox(UI_CompBonusBox bonusBox, int index)
  227. {
  228. int status = (int)bonusBox.target.data;
  229. if (status == ConstBonusStatus.CAN_GET)
  230. {
  231. bool got = await MainStorySProxy.GetMainStoryBoxBonus(MainStoryDataManager.currentChapterCfgId, index);
  232. if (got)
  233. {
  234. List<ItemData> bonusList = MainStoryDataManager.GetChapterBonus(MainStoryDataManager.currentChapterCfgId, index);
  235. if (bonusList != null && bonusList.Count > 0)
  236. {
  237. BonusController.TryShowBonusList(bonusList);
  238. }
  239. UpdateBonusBoxStatus(bonusBox, index);
  240. }
  241. }
  242. // else if (status == ConstBonusStatus.GOT)
  243. // {
  244. // PromptController.Instance.ShowFloatTextPrompt("这个宝箱已经被领取过了");
  245. // }
  246. else
  247. {
  248. List<ItemData> rewards = StoryBonusDataCache.GetChapterBonusList(_chapterID, index);
  249. int star = StoryBonusDataCache.GetChapterBonusStar(_chapterID, index);
  250. ViewManager.Show<RewardPreView>(new object[] { rewards, "宝箱奖励", string.Format("本章达成{0}星可领取", star) });
  251. // PromptController.Instance.ShowFloatTextPrompt("关卡总分不足,继续加油吧。");
  252. }
  253. }
  254. private void CheckGuide(object param)
  255. {
  256. if (GuideDataManager.IsGuideFinish(ConstGuideId.START_FIGHT) <= 0
  257. || GuideDataManager.IsGuideFinish(ConstGuideId.FREEDOM_DRESS) <= 0
  258. || GuideDataManager.IsGuideFinish(ConstGuideId.ENTER_CHAPTER) <= 0
  259. || GuideDataManager.IsGuideFinish(ConstGuideId.BUY_CLOTHING) <= 0
  260. || GuideDataManager.IsGuideFinish(ConstGuideId.UP_CARD_LV) <= 0
  261. || GuideDataManager.IsGuideFinish(ConstGuideId.ENTER_CHAPTER_1) <= 0
  262. || GuideDataManager.IsGuideFinish(ConstGuideId.ENTER_CHAPTER_2) <= 0
  263. || GuideDataManager.IsGuideFinish(ConstGuideId.ENTER_CHAPTER_3) <= 0
  264. || GuideDataManager.IsGuideFinish(ConstGuideId.ENTER_CHAPTER_4) <= 0
  265. || GuideDataManager.IsGuideFinish(ConstGuideId.ENTER_CHAPTER_5) <= 0
  266. || GuideDataManager.IsGuideFinish(ConstGuideId.UP_CARD_STAR) <= 0
  267. || GuideDataManager.IsGuideFinish(ConstGuideId.ARENA_OPEN) <= 0
  268. || GuideDataManager.IsGuideFinish(ConstGuideId.CLOTHING_DECOMPOSE) <= 0)
  269. {
  270. UpdateToCheckGuide(null);
  271. }
  272. else
  273. {
  274. Timers.inst.Remove(CheckGuide);
  275. }
  276. }
  277. protected override void UpdateToCheckGuide(object param)
  278. {
  279. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  280. GComponent unPasslevelCom = _unPasslevelItem == null ? null : _unPasslevelItem.asCom;
  281. bool isGuide0 = GuideController.TryGuide(unPasslevelCom, ConstGuideId.START_FIGHT, 1, "尝试换上一套衣服吧。");
  282. bool isGuide1 = GuideController.TryGuide(_ui.m_btnHome, ConstGuideId.FREEDOM_DRESS, 1, "获得的服饰随时可以查看和试穿。");
  283. bool isGuide2 = GuideController.TryGuide(unPasslevelCom, ConstGuideId.ENTER_CHAPTER, 5, "来继续我们的旅程吧。");
  284. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER, 5);
  285. bool isGuide3 = GuideController.TryGuide(unPasslevelCom, ConstGuideId.ENTER_CHAPTER_1, 4, "来继续我们的旅程吧。");
  286. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_1, 4);
  287. bool isGuide4 = GuideController.TryGuide(unPasslevelCom, ConstGuideId.BUY_CLOTHING, 1, "衣服被弄脏了,到机场更衣室换身衣服吧。");
  288. bool isGuide5 = GuideController.TryGuide(_ui.m_btnHome, ConstGuideId.UP_CARD_LV, 1, "点击返回主界面。");
  289. bool isGuide6 = GuideController.TryGuide(_ui.m_btnHome, ConstGuideId.CLOTHING_DECOMPOSE, 1, "点击返回主界面。");
  290. bool isGuide7 = GuideController.TryGuide(unPasslevelCom, ConstGuideId.ENTER_CHAPTER_2, 4, "来继续我们的旅程吧。");
  291. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_2, 4);
  292. bool isGuide8 = GuideController.TryGuide(unPasslevelCom, ConstGuideId.ENTER_CHAPTER_3, 3, "来继续我们的旅程吧。");
  293. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_3, 3);
  294. bool isGuide10 = GuideController.TryGuide(unPasslevelCom, ConstGuideId.ENTER_CHAPTER_4, 4, "来继续我们的旅程吧。");
  295. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_4, 4);
  296. bool isGuide11 = GuideController.TryGuide(unPasslevelCom, ConstGuideId.ENTER_CHAPTER_5, 4, "来继续我们的旅程吧。");
  297. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_5, 4);
  298. bool isGuide9 = GuideController.TryGuide(_ui.m_btnHome, ConstGuideId.UP_CARD_STAR, 1, "点击返回主界面。");
  299. bool isGuide12 = GuideController.TryGuide(_ui.m_btnHome, ConstGuideId.ARENA_OPEN, 1, "点击返回主界面。");
  300. _ui.m_chapter.target.scrollPane.touchEffect = !isGuide0 && !isGuide1 && !isGuide2 && !isGuide3 && !isGuide4 && !isGuide5 && !isGuide6 && !isGuide7 && !isGuide8 && !isGuide9 && !isGuide10;
  301. }
  302. protected override void TryCompleteGuide()
  303. {
  304. base.TryCompleteGuide();
  305. // GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.ENTER_CHAPTER);
  306. GuideController.TryCompleteGuideIndex(ConstGuideId.ENTER_CHAPTER, 5);
  307. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER, 5);
  308. // GuideCfg cfg1 = GuideCfgArray.Instance.GetCfg(ConstGuideId.ENTER_CHAPTER_1);
  309. GuideController.TryCompleteGuideIndex(ConstGuideId.ENTER_CHAPTER_1, 4);
  310. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_1, 4);
  311. // GuideCfg cfg2 = GuideCfgArray.Instance.GetCfg(ConstGuideId.ENTER_CHAPTER_2);
  312. GuideController.TryCompleteGuideIndex(ConstGuideId.ENTER_CHAPTER_2, 4);
  313. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_2, 4);
  314. // GuideCfg cfg3 = GuideCfgArray.Instance.GetCfg(ConstGuideId.ENTER_CHAPTER_3);
  315. GuideController.TryCompleteGuideIndex(ConstGuideId.ENTER_CHAPTER_3, 3);
  316. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_3, 3);
  317. // GuideCfg cfg4 = GuideCfgArray.Instance.GetCfg(ConstGuideId.ENTER_CHAPTER_4);
  318. GuideController.TryCompleteGuideIndex(ConstGuideId.ENTER_CHAPTER_4, 4);
  319. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_4, 4);
  320. // GuideCfg cfg5 = GuideCfgArray.Instance.GetCfg(ConstGuideId.ENTER_CHAPTER_5);
  321. GuideController.TryCompleteGuideIndex(ConstGuideId.ENTER_CHAPTER_5, 4);
  322. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_5, 4);
  323. }
  324. }
  325. }