StoryChapterView.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  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 GameObject _gameObject;
  18. private GoWrapper _wrapper;
  19. private GComponent _comEff;
  20. public override void Dispose()
  21. {
  22. if (_comEff != null)
  23. {
  24. _comEff.RemoveFromParent();
  25. _comEff.Dispose();
  26. }
  27. if (_valueBarController != null)
  28. {
  29. _valueBarController.Dispose();
  30. _valueBarController = null;
  31. }
  32. SceneController.DestroyObjectFromView(_gameObject, _wrapper);
  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. string resPath = ResPathUtil.GetViewEffectPath("ui_gk", "ui_gk_sg");
  69. SceneController.AddObjectToView(_gameObject, _wrapper, _comEff.GetChild("holder").asGraph, resPath, out _gameObject, out _wrapper);
  70. }
  71. protected override void AddEventListener()
  72. {
  73. EventAgent.AddEventListener(ConstMessage.NOTICE_MAINSTORY_BOXBONUS_STATE, UpdateBonusBox);
  74. }
  75. protected override void OnShown()
  76. {
  77. base.OnShown();
  78. _ui.target.touchable = false;
  79. MusicManager.Instance.Play(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT));
  80. _chapterID = (int)viewData;
  81. MainStoryDataManager.currentChapterCfgId = _chapterID;
  82. Timers.inst.StartCoroutine(InitChapter());
  83. _valueBarController.OnShown();
  84. _ui.target.touchable = true;
  85. Timers.inst.AddUpdate(CheckGuide);
  86. }
  87. protected override void OnHide()
  88. {
  89. base.OnHide();
  90. _unPasslevelItem = null;
  91. _endLevelItem = null;
  92. // _ui.m_chapter.RemoveChildren(0, 0, true);
  93. _valueBarController.OnHide();
  94. Timers.inst.Remove(CheckGuide);
  95. }
  96. protected override void RemoveEventListener()
  97. {
  98. base.RemoveEventListener();
  99. EventAgent.RemoveEventListener(ConstMessage.NOTICE_MAINSTORY_BOXBONUS_STATE, UpdateBonusBox);
  100. }
  101. private void OnClickBtnBack()
  102. {
  103. ViewManager.GoBackFrom(ViewName.STORY_CHAPTER_VIEW);
  104. }
  105. private void OnClickBtnHome()
  106. {
  107. GameController.GoBackToMainView();
  108. }
  109. private IEnumerator InitChapter()
  110. {
  111. Debug.Log("InitChapter 000");
  112. StoryChapterCfg chapterCfg = StoryChapterCfgArray.Instance.GetCfg(_chapterID);
  113. Debug.Log("InitChapter 002");
  114. _ui.m_txtChapterName0.text = chapterCfg.name.Length > 0 ? chapterCfg.name[0].ToString() : "";
  115. _ui.m_txtChapterName1.text = chapterCfg.name.Length > 1 ? chapterCfg.name[1].ToString() : "";
  116. _ui.m_txtChapterName2.text = chapterCfg.name.Length > 2 ? chapterCfg.name[2].ToString() : "";
  117. _ui.m_txtChapterName3.text = chapterCfg.name.Length > 3 ? chapterCfg.name[3].ToString() : "";
  118. _ui.m_txtChapterName4.text = chapterCfg.name.Length > 4 ? chapterCfg.name[4].ToString() : "";
  119. int order = StoryUtil.GetChapterOrder(chapterCfg.id);
  120. _ui.m_txtChapter.text = order < 10 ? "0" + order : order.ToString();
  121. int starCountChapter = InstanceZonesDataManager.GetChapterStarCount(_chapterID, chapterCfg.type, chapterCfg.subType);
  122. _ui.m_txtStarCount.text = "" + starCountChapter + "/" + chapterCfg.bonusStar3;
  123. UpdateBonusBoxName(_ui.m_bonusBox1, "" + chapterCfg.bonusStar1);
  124. UpdateBonusBoxName(_ui.m_bonusBox2, "" + chapterCfg.bonusStar2);
  125. UpdateBonusBoxName(_ui.m_bonusBox3, "" + chapterCfg.bonusStar3);
  126. UpdateBonusBox();
  127. Debug.Log("InitChapter 003");
  128. var list = StoryLevelCfgArray.Instance.GetCfgsBytypeAndsubTypeAndchapterId(chapterCfg.type, chapterCfg.subType, chapterCfg.id);
  129. Debug.Log("InitChapter_ 004");
  130. int endLevel = 0;
  131. int UnlockCount = 0;
  132. Debug.Log("InitChapter_ 005");
  133. _compChapter = _ui.m_chapter.m_compChapterScroll.target;
  134. Debug.Log("InitChapter_ 006");
  135. float starPosY = _ui.m_chapter.m_compChapterScroll.m_imgBegin.y;
  136. Debug.Log("InitChapter_ 007");
  137. int lineGap = 4500 / list.Count;
  138. for (int i = 0; i < 20; i++)
  139. {
  140. Debug.Log("InitChapter_ 008 _:" + i);
  141. GObject obj = _ui.m_chapter.m_compChapterScroll.target.GetChild("g" + (i + 1));
  142. Debug.Log("InitChapter_ 009 _:" + obj);
  143. obj.SetPosition(obj.x, starPosY - lineGap * i - 300, 0); ;
  144. Debug.Log("InitChapter_ 010 _:" + list.Count);
  145. StoryLevelCfg levelCfg = i < list.Count ? list[i] : null;
  146. Debug.Log("InitChapter_ 011 _:");
  147. UI_CompStoryLevelItem levelItem = UI_CompStoryLevelItem.Proxy(obj);
  148. Debug.Log("InitChapter_ 012 _:" + levelItem);
  149. if (levelCfg != null && MainStoryDataManager.CheckLevelUnlock(levelCfg.id))
  150. {
  151. Debug.Log("InitChapter_ 013 _:" + levelCfg.id);
  152. UnlockCount++;
  153. Debug.Log("InitChapter_ 014 _:");
  154. levelItem.target.data = levelCfg.id;
  155. levelItem.target.visible = true;
  156. levelItem.target.onClick.Clear();
  157. levelItem.target.onClick.Add(OnClickLevelItem);
  158. Debug.Log("InitChapter_ 015 _:" + levelCfg.order);
  159. string showId = StoryUtil.GetChapterOrder(_chapterID) + "-" + levelCfg.order;
  160. Debug.Log("InitChapter_ 016 _:");
  161. levelItem.m_txtDialogOrder.text = showId;
  162. levelItem.m_txtFightOrder.text = showId;
  163. if (levelCfg.fightID.Length > 0)
  164. {
  165. Debug.Log("InitChapter_ 017 _:" + levelCfg.fightID);
  166. levelItem.m_c1.selectedIndex = 1;
  167. int score = InstanceZonesDataManager.GetScoreHighest(levelCfg.id);
  168. if (score <= 0)
  169. {
  170. levelItem.m_flower.target.visible = false;
  171. }
  172. else
  173. {
  174. levelItem.m_flower.target.visible = true;
  175. Debug.Log("InitChapter_ 018 _:");
  176. int starCount = InstanceZonesDataManager.GetStarCountHistory(levelCfg.id);
  177. Debug.Log("InitChapter_ 019 _:");
  178. StoryUtil.UpdateStar(starCount, levelItem.m_flower.target);
  179. Debug.Log("InitChapter_ 020 _:");
  180. }
  181. }
  182. else
  183. {
  184. Debug.Log("InitChapter_ 021 _:");
  185. levelItem.m_c1.selectedIndex = 0;
  186. levelItem.m_flower.target.visible = false;
  187. levelItem.m_txtName.text = levelCfg.name;
  188. Debug.Log("InitChapter_ 022 _:");
  189. levelItem.m_comDialogBg.m_loabg.url = ResPathUtil.GetBgImgPath(chapterCfg.bgRes);
  190. levelItem.m_comDialogBg.m_loaIcon.url = ResPathUtil.GetChapterGuideIconPath(chapterCfg.bgRes);
  191. levelItem.m_comDialogBg.m_c1.selectedIndex = Random.Range(0, 10);
  192. Debug.Log("InitChapter_ 023 _:" + UnlockCount);
  193. }
  194. Debug.Log("InitChapter_ 024 _:" + levelCfg.id);
  195. Debug.Log("InitChapter_ 025 _:" + levelItem.m_holder);
  196. levelItem.m_holder.visible = !InstanceZonesDataManager.CheckLevelPass(levelCfg.id);
  197. Debug.Log("InitChapter_ 026 _:" + UnlockCount);
  198. if (!InstanceZonesDataManager.CheckLevelPass(levelCfg.id))
  199. {
  200. Debug.Log("InitChapter_ 027 _:" + UnlockCount);
  201. //设置为解锁关卡
  202. MainStoryDataManager.currentLevelCfgId = levelCfg.id;
  203. _unPasslevelItem = levelItem.target;
  204. Debug.Log("InitChapter_ 028 _:" + UnlockCount);
  205. // string resPath = ResPathUtil.GetViewEffectPath("ui_gk", "ui_gk_sg");
  206. // SceneController.AddObjectToView(_gameObject, _wrapper, levelItem.m_holder, resPath, out _gameObject, out _wrapper);
  207. Debug.Log("InitChapter_ 029 _:" + UnlockCount);
  208. levelItem.target.AddChild(_comEff);
  209. }
  210. if (levelCfg.order > endLevel)
  211. {
  212. Debug.Log("InitChapter_ 030 _:" + UnlockCount);
  213. endLevel = levelCfg.order;
  214. _endLevelItem = levelItem.target;
  215. Debug.Log("InitChapter_ 031 _:" + UnlockCount);
  216. }
  217. }
  218. else
  219. {
  220. Debug.Log("InitChapter_ 032 _:" + UnlockCount);
  221. levelItem.target.visible = false;
  222. Debug.Log("InitChapter_ 033 _:" + UnlockCount);
  223. }
  224. Debug.Log("InitChapter_ 034 _:" + UnlockCount);
  225. UI_CompStoryLevelItem.ProxyEnd();
  226. }
  227. Debug.Log("InitChapter 035");
  228. yield return new WaitForEndOfFrame();
  229. Debug.Log("InitChapter 036");
  230. _ui.m_chapter.m_compChapterScroll.target.y = Mathf.Max(0, _ui.m_chapter.target.height - _ui.m_chapter.m_compChapterScroll.target.height);
  231. }
  232. private void OnClickLevelItem(EventContext context)
  233. {
  234. UI_CompStoryLevelItem levelItem = UI_CompStoryLevelItem.Proxy(context.sender as GObject);
  235. int levelCfgId = (int)levelItem.target.data;
  236. UI_CompStoryLevelItem.ProxyEnd();
  237. StoryController.ShowLevelView(levelCfgId);
  238. TryCompleteGuide();
  239. }
  240. private void UpdateBonusBoxName(UI_CompBonusBox bonusBox, string name)
  241. {
  242. bonusBox.m_txtName.text = name;
  243. }
  244. private void UpdateBonusBox()
  245. {
  246. UpdateBonusBoxStatus(_ui.m_bonusBox1, 0);
  247. UpdateBonusBoxStatus(_ui.m_bonusBox2, 1);
  248. UpdateBonusBoxStatus(_ui.m_bonusBox3, 2);
  249. }
  250. private void UpdateBonusBoxStatus(UI_CompBonusBox bonusBox, int index)
  251. {
  252. int status = MainStoryDataManager.GetChapterBonusStatus(MainStoryDataManager.currentChapterCfgId, index);
  253. bonusBox.m_iconActive.visible = status == ConstBonusStatus.CAN_GET;
  254. // bonusBox.m_ComRewardEffect.visible = status == ConstBonusStatus.CAN_GET;
  255. if (status == ConstBonusStatus.GOT)
  256. {
  257. bonusBox.m_icon.url = "ui://Main/zxian_gift_get";
  258. }
  259. else
  260. {
  261. bonusBox.m_icon.url = "ui://Main/zxian_gift_unget";
  262. }
  263. bonusBox.target.data = status;
  264. }
  265. private async void OnClickBonusBox(UI_CompBonusBox bonusBox, int index)
  266. {
  267. int status = (int)bonusBox.target.data;
  268. if (status == ConstBonusStatus.CAN_GET)
  269. {
  270. bool got = await MainStorySProxy.GetMainStoryBoxBonus(MainStoryDataManager.currentChapterCfgId, index);
  271. if (got)
  272. {
  273. List<ItemData> bonusList = MainStoryDataManager.GetChapterBonus(MainStoryDataManager.currentChapterCfgId, index);
  274. if (bonusList != null && bonusList.Count > 0)
  275. {
  276. BonusController.TryShowBonusList(bonusList);
  277. }
  278. UpdateBonusBoxStatus(bonusBox, index);
  279. }
  280. }
  281. // else if (status == ConstBonusStatus.GOT)
  282. // {
  283. // PromptController.Instance.ShowFloatTextPrompt("这个宝箱已经被领取过了");
  284. // }
  285. else
  286. {
  287. List<ItemData> rewards = StoryBonusDataCache.GetChapterBonusList(_chapterID, index);
  288. int star = StoryBonusDataCache.GetChapterBonusStar(_chapterID, index);
  289. ViewManager.Show<RewardPreView>(new object[] { rewards, "宝箱奖励", string.Format("本章达成{0}星可领取", star) });
  290. // PromptController.Instance.ShowFloatTextPrompt("关卡总分不足,继续加油吧。");
  291. }
  292. }
  293. private void CheckGuide(object param)
  294. {
  295. if (GuideDataManager.IsGuideFinish(ConstGuideId.START_FIGHT) <= 0
  296. || GuideDataManager.IsGuideFinish(ConstGuideId.FREEDOM_DRESS) <= 0
  297. || GuideDataManager.IsGuideFinish(ConstGuideId.ENTER_CHAPTER) <= 0
  298. || GuideDataManager.IsGuideFinish(ConstGuideId.BUY_CLOTHING) <= 0
  299. || GuideDataManager.IsGuideFinish(ConstGuideId.UP_CARD_LV) <= 0
  300. || GuideDataManager.IsGuideFinish(ConstGuideId.ENTER_CHAPTER_1) <= 0
  301. || GuideDataManager.IsGuideFinish(ConstGuideId.ENTER_CHAPTER_2) <= 0
  302. || GuideDataManager.IsGuideFinish(ConstGuideId.ENTER_CHAPTER_3) <= 0
  303. || GuideDataManager.IsGuideFinish(ConstGuideId.ENTER_CHAPTER_4) <= 0
  304. || GuideDataManager.IsGuideFinish(ConstGuideId.ENTER_CHAPTER_5) <= 0
  305. || GuideDataManager.IsGuideFinish(ConstGuideId.UP_CARD_STAR) <= 0
  306. || GuideDataManager.IsGuideFinish(ConstGuideId.ARENA_OPEN) <= 0
  307. || GuideDataManager.IsGuideFinish(ConstGuideId.CLOTHING_DECOMPOSE) <= 0)
  308. {
  309. UpdateToCheckGuide(null);
  310. }
  311. else
  312. {
  313. Timers.inst.Remove(CheckGuide);
  314. }
  315. }
  316. protected override void UpdateToCheckGuide(object param)
  317. {
  318. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  319. GComponent unPasslevelCom = _unPasslevelItem == null ? null : _unPasslevelItem.asCom;
  320. bool isGuide0 = GuideController.TryGuide(unPasslevelCom, ConstGuideId.START_FIGHT, 1, "尝试换上一套衣服吧。");
  321. bool isGuide1 = GuideController.TryGuide(_ui.m_btnHome, ConstGuideId.FREEDOM_DRESS, 1, "获得的服饰随时可以查看和试穿。");
  322. bool isGuide2 = GuideController.TryGuide(unPasslevelCom, ConstGuideId.ENTER_CHAPTER, 5, "来继续我们的旅程吧。");
  323. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER, 5);
  324. bool isGuide3 = GuideController.TryGuide(unPasslevelCom, ConstGuideId.ENTER_CHAPTER_1, 4, "来继续我们的旅程吧。");
  325. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_1, 4);
  326. bool isGuide4 = GuideController.TryGuide(unPasslevelCom, ConstGuideId.BUY_CLOTHING, 1, "衣服被弄脏了,到机场更衣室换身衣服吧。");
  327. bool isGuide5 = GuideController.TryGuide(_ui.m_btnHome, ConstGuideId.UP_CARD_LV, 1, "点击返回主界面。");
  328. bool isGuide6 = GuideController.TryGuide(_ui.m_btnHome, ConstGuideId.CLOTHING_DECOMPOSE, 1, "点击返回主界面。");
  329. bool isGuide7 = GuideController.TryGuide(unPasslevelCom, ConstGuideId.ENTER_CHAPTER_2, 4, "来继续我们的旅程吧。");
  330. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_2, 4);
  331. bool isGuide8 = GuideController.TryGuide(unPasslevelCom, ConstGuideId.ENTER_CHAPTER_3, 3, "来继续我们的旅程吧。");
  332. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_3, 3);
  333. bool isGuide10 = GuideController.TryGuide(unPasslevelCom, ConstGuideId.ENTER_CHAPTER_4, 4, "来继续我们的旅程吧。");
  334. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_4, 4);
  335. bool isGuide11 = GuideController.TryGuide(unPasslevelCom, ConstGuideId.ENTER_CHAPTER_5, 4, "来继续我们的旅程吧。");
  336. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_5, 4);
  337. bool isGuide9 = GuideController.TryGuide(_ui.m_btnHome, ConstGuideId.UP_CARD_STAR, 1, "点击返回主界面。");
  338. bool isGuide12 = GuideController.TryGuide(_ui.m_btnHome, ConstGuideId.ARENA_OPEN, 1, "点击返回主界面。");
  339. _ui.m_chapter.target.scrollPane.touchEffect = !isGuide0 && !isGuide1 && !isGuide2 && !isGuide3 && !isGuide4 && !isGuide5 && !isGuide6 && !isGuide7 && !isGuide8 && !isGuide9 && !isGuide10;
  340. }
  341. protected override void TryCompleteGuide()
  342. {
  343. base.TryCompleteGuide();
  344. // GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.ENTER_CHAPTER);
  345. GuideController.TryCompleteGuideIndex(ConstGuideId.ENTER_CHAPTER, 5);
  346. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER, 5);
  347. // GuideCfg cfg1 = GuideCfgArray.Instance.GetCfg(ConstGuideId.ENTER_CHAPTER_1);
  348. GuideController.TryCompleteGuideIndex(ConstGuideId.ENTER_CHAPTER_1, 4);
  349. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_1, 4);
  350. // GuideCfg cfg2 = GuideCfgArray.Instance.GetCfg(ConstGuideId.ENTER_CHAPTER_2);
  351. GuideController.TryCompleteGuideIndex(ConstGuideId.ENTER_CHAPTER_2, 4);
  352. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_2, 4);
  353. // GuideCfg cfg3 = GuideCfgArray.Instance.GetCfg(ConstGuideId.ENTER_CHAPTER_3);
  354. GuideController.TryCompleteGuideIndex(ConstGuideId.ENTER_CHAPTER_3, 3);
  355. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_3, 3);
  356. // GuideCfg cfg4 = GuideCfgArray.Instance.GetCfg(ConstGuideId.ENTER_CHAPTER_4);
  357. GuideController.TryCompleteGuideIndex(ConstGuideId.ENTER_CHAPTER_4, 4);
  358. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_4, 4);
  359. // GuideCfg cfg5 = GuideCfgArray.Instance.GetCfg(ConstGuideId.ENTER_CHAPTER_5);
  360. GuideController.TryCompleteGuideIndex(ConstGuideId.ENTER_CHAPTER_5, 4);
  361. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_5, 4);
  362. }
  363. }
  364. }