StoryChapterView.cs 11 KB

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