StoryChapterView.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. using FairyGUI;
  2. using UI.CommonGame;
  3. using UI.Main;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. namespace GFGGame
  7. {
  8. public class StoryChapterView : BaseView
  9. {
  10. private UI_StoryChapterUI _ui;
  11. private int _chapterID;
  12. private GComponent _compChapter;
  13. private ValueBarController _valueBarController;
  14. private GObject _unPasslevelItem;
  15. private GObject _endLevelItem;
  16. private GameObject _gameObject;
  17. private GoWrapper _wrapper;
  18. public override void Dispose()
  19. {
  20. if (_valueBarController != null)
  21. {
  22. _valueBarController.Dispose();
  23. _valueBarController = null;
  24. }
  25. SceneController.DestroyObjectFromView(_gameObject);
  26. base.Dispose();
  27. }
  28. protected override void Init()
  29. {
  30. base.Init();
  31. _ui = UI_StoryChapterUI.Create();
  32. viewCom = _ui.target;
  33. isfullScreen = true;
  34. }
  35. protected override void OnInit()
  36. {
  37. base.OnInit();
  38. _valueBarController = new ValueBarController(_ui.m_valueBar);
  39. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  40. _ui.m_btnHome.onClick.Add(OnClickBtnHome);
  41. _ui.m_bonusBox1.target.onClick.Add(() =>
  42. {
  43. OnClickBonusBox(_ui.m_bonusBox1, 0);
  44. });
  45. _ui.m_bonusBox2.target.onClick.Add(() =>
  46. {
  47. OnClickBonusBox(_ui.m_bonusBox2, 1);
  48. });
  49. _ui.m_bonusBox3.target.onClick.Add(() =>
  50. {
  51. OnClickBonusBox(_ui.m_bonusBox3, 2);
  52. });
  53. }
  54. protected override void OnShown()
  55. {
  56. base.OnShown();
  57. MusicManager.Instance.Play(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT));
  58. _chapterID = (int)viewData;
  59. StoryDataManager.currentChapter = _chapterID;
  60. _compChapter = (GComponent)UIPackage.CreateObject("Main", "CompChapter" + _chapterID);
  61. _ui.m_chapter.AddChild(_compChapter);
  62. InitChapter();
  63. _valueBarController.OnShown();
  64. if (GuideDataManager.GetGuideCount(ConstGuideId.SINGLE_FIGHT_GUIDE) <= 0
  65. || GuideDataManager.GetGuideCount(ConstGuideId.MAIN_UI_BTN_ZHAI_XING) <= 0
  66. || GuideDataManager.GetGuideCount(ConstGuideId.SUIT_SYNTHETIC_GUIDE) <= 0
  67. || GuideDataManager.GetGuideCount(ConstGuideId.CARD_UP_STAR) <= 0)
  68. {
  69. Timers.inst.AddUpdate(UpdateToCheckGuide);
  70. }
  71. Timers.inst.AddUpdate(UpdateToCheckGuide);
  72. }
  73. protected override void OnHide()
  74. {
  75. base.OnHide();
  76. _unPasslevelItem = null;
  77. _endLevelItem = null;
  78. GuideController.HideGuide();
  79. _ui.m_chapter.RemoveChildren(0, 0, true);
  80. _valueBarController.OnHide();
  81. Timers.inst.Remove(UpdateToCheckGuide);
  82. }
  83. private void OnClickBtnBack()
  84. {
  85. ViewManager.GoBackFrom(ViewName.STORY_CHAPTER_VIEW);
  86. }
  87. private void OnClickBtnHome()
  88. {
  89. GuideController.HideGuide();
  90. GuideController.TryCompleteGuide(ConstGuideId.SINGLE_FIGHT_GUIDE);
  91. GameController.GoBackToMainView();
  92. }
  93. private void InitChapter()
  94. {
  95. StoryChapterCfg chapterCfg = StoryChapterCfgArray.Instance.GetCfg(_chapterID);
  96. _ui.m_txtChapterName.text = StoryUtil.GetChapterOrderText(_chapterID) + "·" + chapterCfg.name;
  97. int starCountChapter = StoryDataManager.GetChapterStarCount(_chapterID);
  98. _ui.m_txtStarCount.text = "" + starCountChapter + "/" + chapterCfg.bonusStar3;
  99. UpdateBonusBoxName(_ui.m_bonusBox1, "" + chapterCfg.bonusStar1);
  100. UpdateBonusBoxName(_ui.m_bonusBox2, "" + chapterCfg.bonusStar2);
  101. UpdateBonusBoxName(_ui.m_bonusBox3, "" + chapterCfg.bonusStar3);
  102. UpdateBonusBoxStatus(_ui.m_bonusBox1, 0);
  103. UpdateBonusBoxStatus(_ui.m_bonusBox2, 1);
  104. UpdateBonusBoxStatus(_ui.m_bonusBox3, 2);
  105. int endLevel = 0;
  106. for (int i = 0; i < _compChapter.numChildren; i++)
  107. {
  108. GObject obj = _compChapter.GetChildAt(i);
  109. if (obj.name.IndexOf("g") == 0)
  110. {
  111. UI_CompStoryLevelItem levelItem = UI_CompStoryLevelItem.Proxy(obj);
  112. int level = int.Parse(levelItem.target.name.Replace("g", ""));
  113. if (StoryDataManager.CheckLevelUnlock(_chapterID, level))
  114. {
  115. levelItem.target.visible = true;
  116. levelItem.target.onClick.Clear();
  117. levelItem.target.onClick.Add(OnClickLevelItem);
  118. string levelID = _chapterID + "_" + level;
  119. string showId = StoryUtil.GetNormalChapterId(_chapterID) + "_" + level;
  120. levelItem.m_txtOrder.text = showId;
  121. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(levelID);
  122. if (levelCfg != null)
  123. {
  124. if (levelCfg.fightID.Length > 0)
  125. {
  126. levelItem.m_bg.url = "ui://Main/zx_gka_zb_2";
  127. int score = StoryDataManager.GetScoreHighest(levelID);
  128. if (score <= 0)
  129. {
  130. levelItem.m_flower.target.visible = false;
  131. }
  132. else
  133. {
  134. levelItem.m_flower.target.visible = true;
  135. int starCount = StoryDataManager.GetStarCountHistory(levelID, score);
  136. StoryUtil.UpdateStar(starCount, levelItem.m_flower.target);
  137. }
  138. }
  139. else
  140. {
  141. levelItem.m_bg.url = "ui://Main/zx_gka_zb_1";
  142. levelItem.m_flower.target.visible = false;
  143. }
  144. // levelItem.m_iconUnPass.visible =
  145. levelItem.m_holder.visible = !StoryDataManager.CheckLevelPass(_chapterID, level);
  146. // if (levelItem.m_holder.visible)
  147. // {
  148. // }
  149. if (levelItem.m_holder.visible)
  150. {
  151. // StoryDataManager.currentChapter = _chapterID;
  152. StoryDataManager.currentLevel = int.Parse(levelItem.target.name.Replace("g", ""));
  153. _unPasslevelItem = levelItem.target;
  154. _gameObject = null;
  155. _wrapper = null;
  156. string resPath = ResPathUtil.GetViewEffectPath("ui_gk", "ui_gk_sg");
  157. SceneController.AddObjectToView(_gameObject, _wrapper, levelItem.m_holder, resPath, out _gameObject, out _wrapper);
  158. }
  159. if (level > endLevel)
  160. {
  161. endLevel = level;
  162. _endLevelItem = levelItem.target;
  163. }
  164. }
  165. else
  166. {
  167. levelItem.target.visible = false;
  168. }
  169. }
  170. else
  171. {
  172. levelItem.target.visible = false;
  173. }
  174. }
  175. }
  176. if (_endLevelItem != null)
  177. {
  178. float tx = _endLevelItem.x + _endLevelItem.width / 2;
  179. float ty = _endLevelItem.y + _endLevelItem.height / 2;
  180. tx = tx - _ui.m_chapter.width / 2;
  181. ty = ty - _ui.m_chapter.height / 2;
  182. _ui.m_chapter.scrollPane.SetPosX(tx, false);
  183. _ui.m_chapter.scrollPane.SetPosY(ty, false);
  184. }
  185. }
  186. private void OnClickLevelItem(EventContext context)
  187. {
  188. UI_CompStoryLevelItem levelItem = UI_CompStoryLevelItem.Proxy(context.sender as GObject);
  189. int level = int.Parse(levelItem.target.name.Replace("g", ""));
  190. StoryController.ShowLevelView(_chapterID, level);
  191. }
  192. private void UpdateBonusBoxName(UI_CompBonusBox bonusBox, string name)
  193. {
  194. bonusBox.m_txtName.text = name;
  195. }
  196. private void UpdateBonusBoxStatus(UI_CompBonusBox bonusBox, int index)
  197. {
  198. int status = StoryDataManager.GetChapterBonusStatus(StoryDataManager.currentChapter, index);
  199. bonusBox.m_iconActive.visible = status == ConstBonusStatus.CAN_GET;
  200. if (status == ConstBonusStatus.GOT)
  201. {
  202. bonusBox.m_icon.url = "ui://Main/zx_gka_baoxiang_2";
  203. }
  204. else
  205. {
  206. bonusBox.m_icon.url = "ui://Main/zx_gka_baoxiang_1";
  207. }
  208. bonusBox.target.data = status;
  209. }
  210. private void OnClickBonusBox(UI_CompBonusBox bonusBox, int index)
  211. {
  212. int status = (int)bonusBox.target.data;
  213. if (status == ConstBonusStatus.CAN_GET)
  214. {
  215. List<ItemData> bonusList = StoryDataManager.GetChapterBonus(StoryDataManager.currentChapter, index);
  216. if (bonusList != null && bonusList.Count > 0)
  217. {
  218. ViewManager.Show(ViewName.GET_BONUS_VIEW, bonusList);
  219. }
  220. UpdateBonusBoxStatus(bonusBox, index);
  221. }
  222. else if (status == ConstBonusStatus.GOT)
  223. {
  224. PromptController.Instance.ShowFloatTextPrompt("这个宝箱已经被领取过了");
  225. }
  226. else
  227. {
  228. PromptController.Instance.ShowFloatTextPrompt("关卡总分不足,继续加油吧。");
  229. }
  230. }
  231. private void UpdateToCheckGuide(object param)
  232. {
  233. // if (this.viewCom.parent != null)
  234. // {
  235. // int index = this.viewCom.parent.GetChildIndex(this.viewCom);
  236. // if (index == this.viewCom.parent.numChildren - 1 && GRoot.inst.GetTopWindow() == null)
  237. // {
  238. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  239. if (_unPasslevelItem != null && GuideDataManager.GetGuideCount(ConstGuideId.SINGLE_FIGHT_GUIDE) <= 0)
  240. {
  241. GuideController.TryGuideChapterViewLevelItem(_unPasslevelItem);
  242. // Timers.inst.Remove(UpdateToCheckGuide);
  243. }
  244. else if (GuideDataManager.GetGuideCount(ConstGuideId.MAIN_UI_BTN_ZHAI_XING) <= 0)
  245. {
  246. GuideController.TryGuideGoBackStoryChapter(_ui.m_btnHome);
  247. // Timers.inst.Remove(UpdateToCheckGuide);
  248. }
  249. else if (GuideDataManager.GetGuideCount(ConstGuideId.SUIT_SYNTHETIC_GUIDE) <= 0 && GuideDataManager.GetGuideCount(ConstGuideId.MAIN_UI_BTN_HUAN_ZHUANG) > 0 && GuideDataManager.currentGuideId != ConstGuideId.SUIT_SYNTHETIC_GUIDE)
  250. {
  251. GuideController.TryGuideStoryChapterView(_unPasslevelItem);
  252. // Timers.inst.Remove(UpdateToCheckGuide);
  253. }
  254. else if (GuideDataManager.GetGuideCount(ConstGuideId.SUIT_SYNTHETIC_GUIDE) <= 0 && GuideDataManager.currentGuideId == ConstGuideId.SUIT_SYNTHETIC_GUIDE)
  255. {
  256. GuideController.TryGuideStoryChapterViewBtnHome(_ui.m_btnHome);
  257. // Timers.inst.Remove(UpdateToCheckGuide);
  258. }
  259. else if (GuideDataManager.GetGuideCount(ConstGuideId.PHOTOGRAPH_GUIDE) <= 0)
  260. {
  261. GuideController.TryGuideGoBackStoryChapter1(_ui.m_btnHome);
  262. }
  263. else if (GuideDataManager.GetGuideCount(ConstGuideId.CARD_UP_STAR) <= 0)
  264. {
  265. GuideController.TryGuideStoryLevelInfoBtnHome(_ui.m_btnHome);
  266. // Timers.inst.Remove(UpdateToCheckGuide);
  267. }
  268. GuideController.TryGuide(_unPasslevelItem, ConstGuideId.SINGLE_FIGHT, 1, "遇到意外事件了,暂时解释不清,先按请求换上服饰吧");
  269. GuideController.TryGuide(_ui.m_btnHome, ConstGuideId.LUCKY_BOX, 1, "点击返回主界面");
  270. GuideController.TryGuide(_unPasslevelItem, ConstGuideId.CLOTHING_SYNTHETIC, 1, "点击下一关");
  271. GuideController.TryGuide(_ui.m_btnHome, ConstGuideId.CLOTHING_SYNTHETIC, 4, "先回到主界面");
  272. GuideController.TryGuide(_ui.m_btnHome, ConstGuideId.UP_CARD_STAR, 1, "点击返回主界面");
  273. GuideController.TryGuide(_ui.m_btnHome, ConstGuideId.PHOTOGRAPH, 1, "拍照功能已开启,解锁更多搭配和玩法哦");
  274. }
  275. }
  276. }