StoryChapterView.cs 19 KB

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