StoryChapterView.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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 AddEventListener()
  55. {
  56. EventAgent.AddEventListener(ConstMessage.NOTICE_MAINSTORY_BOXBONUS_STATE, UpdateBonusBox);
  57. }
  58. protected override void OnShown()
  59. {
  60. base.OnShown();
  61. _ui.target.touchable = false;
  62. MusicManager.Instance.Play(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT));
  63. _chapterID = (int)viewData;
  64. MainStoryDataManager.currentChapterCfgId = _chapterID;
  65. _compChapter = (GComponent)UIPackage.CreateObject("Main", "CompChapter" + _chapterID);
  66. StoryChapterCfg cfg = StoryChapterCfgArray.Instance.GetCfg(_chapterID);
  67. _compChapter.GetChild("loaBg").asLoader.url = ResPathUtil.GetBgImgPath(cfg.bgRes);
  68. _ui.m_chapter.AddChild(_compChapter);
  69. InitChapter();
  70. _valueBarController.OnShown();
  71. _ui.target.touchable = true;
  72. Timers.inst.AddUpdate(CheckGuide);
  73. }
  74. protected override void OnHide()
  75. {
  76. base.OnHide();
  77. _unPasslevelItem = null;
  78. _endLevelItem = null;
  79. _ui.m_chapter.RemoveChildren(0, 0, true);
  80. _valueBarController.OnHide();
  81. Timers.inst.Remove(CheckGuide);
  82. }
  83. protected override void RemoveEventListener()
  84. {
  85. base.RemoveEventListener();
  86. EventAgent.RemoveEventListener(ConstMessage.NOTICE_MAINSTORY_BOXBONUS_STATE, UpdateBonusBox);
  87. }
  88. private void OnClickBtnBack()
  89. {
  90. ViewManager.GoBackFrom(ViewName.STORY_CHAPTER_VIEW);
  91. }
  92. private void OnClickBtnHome()
  93. {
  94. GameController.GoBackToMainView();
  95. }
  96. private void InitChapter()
  97. {
  98. StoryChapterCfg chapterCfg = StoryChapterCfgArray.Instance.GetCfg(_chapterID);
  99. _ui.m_txtChapterName.text = StoryUtil.GetChapterOrderText(_chapterID) + "·" + chapterCfg.name;
  100. int starCountChapter = InstanceZonesDataManager.GetChapterStarCount(_chapterID, chapterCfg.type, chapterCfg.subType);
  101. _ui.m_txtStarCount.text = "" + starCountChapter + "/" + chapterCfg.bonusStar3;
  102. UpdateBonusBoxName(_ui.m_bonusBox1, "" + chapterCfg.bonusStar1);
  103. UpdateBonusBoxName(_ui.m_bonusBox2, "" + chapterCfg.bonusStar2);
  104. UpdateBonusBoxName(_ui.m_bonusBox3, "" + chapterCfg.bonusStar3);
  105. UpdateBonusBox();
  106. var list = StoryLevelCfgArray.Instance.GetCfgs(chapterCfg.type, chapterCfg.subType, chapterCfg.id);
  107. int endLevel = 0;
  108. for (int i = 0; i < list.Count; i++)
  109. {
  110. StoryLevelCfg levelCfg = list[i];
  111. GObject obj = _compChapter.GetChild("g" + levelCfg.order);
  112. if (obj != null)
  113. {
  114. UI_CompStoryLevelItem levelItem = UI_CompStoryLevelItem.Proxy(obj);
  115. levelItem.target.data = levelCfg.id;
  116. if (MainStoryDataManager.CheckLevelUnlock(levelCfg.id))
  117. {
  118. levelItem.target.visible = true;
  119. levelItem.target.onClick.Clear();
  120. levelItem.target.onClick.Add(OnClickLevelItem);
  121. string showId = StoryUtil.GetChapterOrder(_chapterID) + "_" + levelCfg.order;
  122. levelItem.m_txtOrder.text = showId;
  123. if (levelCfg.fightID.Length > 0)
  124. {
  125. levelItem.m_bg.url = "ui://Main/zx_gka_zb_2";
  126. int score = InstanceZonesDataManager.GetScoreHighest(levelCfg.id);
  127. if (score <= 0)
  128. {
  129. levelItem.m_flower.target.visible = false;
  130. }
  131. else
  132. {
  133. levelItem.m_flower.target.visible = true;
  134. int starCount = InstanceZonesDataManager.GetStarCountHistory(levelCfg.id);
  135. StoryUtil.UpdateStar(starCount, levelItem.m_flower.target);
  136. }
  137. }
  138. else
  139. {
  140. levelItem.m_bg.url = "ui://Main/zx_gka_zb_1";
  141. levelItem.m_flower.target.visible = false;
  142. }
  143. // levelItem.m_iconUnPass.visible =
  144. levelItem.m_holder.visible = !InstanceZonesDataManager.CheckLevelPass(levelCfg.id);
  145. // if (levelItem.m_holder.visible)
  146. // {
  147. // }
  148. if (levelItem.m_holder.visible)
  149. {
  150. //设置为解锁关卡
  151. MainStoryDataManager.currentLevelCfgId = levelCfg.id;
  152. _unPasslevelItem = levelItem.target;
  153. _gameObject = null;
  154. _wrapper = null;
  155. string resPath = ResPathUtil.GetViewEffectPath("ui_gk", "ui_gk_sg");
  156. SceneController.AddObjectToView(_gameObject, _wrapper, levelItem.m_holder, resPath, out _gameObject, out _wrapper);
  157. }
  158. if (levelCfg.order > endLevel)
  159. {
  160. endLevel = levelCfg.order;
  161. _endLevelItem = levelItem.target;
  162. }
  163. }
  164. else
  165. {
  166. levelItem.target.visible = false;
  167. }
  168. UI_CompStoryLevelItem.ProxyEnd();
  169. }
  170. }
  171. if (_endLevelItem != null)
  172. {
  173. float tx = _endLevelItem.x + _endLevelItem.width / 2;
  174. float ty = _endLevelItem.y + _endLevelItem.height / 2;
  175. tx = tx - _ui.m_chapter.width / 2;
  176. ty = ty - _ui.m_chapter.height / 2;
  177. _ui.m_chapter.scrollPane.SetPosX(tx, false);
  178. _ui.m_chapter.scrollPane.SetPosY(ty, false);
  179. }
  180. }
  181. private void OnClickLevelItem(EventContext context)
  182. {
  183. UI_CompStoryLevelItem levelItem = UI_CompStoryLevelItem.Proxy(context.sender as GObject);
  184. int levelCfgId = (int)levelItem.target.data;
  185. UI_CompStoryLevelItem.ProxyEnd();
  186. StoryController.ShowLevelView(levelCfgId);
  187. }
  188. private void UpdateBonusBoxName(UI_CompBonusBox bonusBox, string name)
  189. {
  190. bonusBox.m_txtName.text = name;
  191. }
  192. private void UpdateBonusBox()
  193. {
  194. UpdateBonusBoxStatus(_ui.m_bonusBox1, 0);
  195. UpdateBonusBoxStatus(_ui.m_bonusBox2, 1);
  196. UpdateBonusBoxStatus(_ui.m_bonusBox3, 2);
  197. }
  198. private void UpdateBonusBoxStatus(UI_CompBonusBox bonusBox, int index)
  199. {
  200. int status = MainStoryDataManager.GetChapterBonusStatus(MainStoryDataManager.currentChapterCfgId, index);
  201. bonusBox.m_iconActive.visible = status == ConstBonusStatus.CAN_GET;
  202. bonusBox.m_ComRewardEffect.visible = status == ConstBonusStatus.CAN_GET;
  203. if (status == ConstBonusStatus.GOT)
  204. {
  205. bonusBox.m_icon.url = "ui://Main/zx_gka_baoxiang_2";
  206. }
  207. else
  208. {
  209. bonusBox.m_icon.url = "ui://Main/zx_gka_baoxiang_1";
  210. }
  211. bonusBox.target.data = status;
  212. }
  213. private async void OnClickBonusBox(UI_CompBonusBox bonusBox, int index)
  214. {
  215. int status = (int)bonusBox.target.data;
  216. if (status == ConstBonusStatus.CAN_GET)
  217. {
  218. bool got = await MainStorySProxy.GetMainStoryBoxBonus(MainStoryDataManager.currentChapterCfgId, index);
  219. if (got)
  220. {
  221. List<ItemData> bonusList = MainStoryDataManager.GetChapterBonus(MainStoryDataManager.currentChapterCfgId, index);
  222. if (bonusList != null && bonusList.Count > 0)
  223. {
  224. BonusController.TryShowBonusList(bonusList);
  225. }
  226. UpdateBonusBoxStatus(bonusBox, index);
  227. }
  228. }
  229. else if (status == ConstBonusStatus.GOT)
  230. {
  231. PromptController.Instance.ShowFloatTextPrompt("这个宝箱已经被领取过了");
  232. }
  233. else
  234. {
  235. PromptController.Instance.ShowFloatTextPrompt("关卡总分不足,继续加油吧。");
  236. }
  237. }
  238. private void CheckGuide(object param)
  239. {
  240. if (GuideDataManager.IsGuideFinish(ConstGuideId.START_STORY) <= 0
  241. || GuideDataManager.IsGuideFinish(ConstGuideId.SINGLE_FIGHT) <= 0
  242. || GuideDataManager.IsGuideFinish(ConstGuideId.LUCKY_BOX) <= 0
  243. || GuideDataManager.IsGuideFinish(ConstGuideId.BUY_CLOTHING) <= 0)
  244. {
  245. UpdateToCheckGuide(null);
  246. }
  247. else
  248. {
  249. Timers.inst.Remove(CheckGuide);
  250. }
  251. }
  252. protected override void UpdateToCheckGuide(object param)
  253. {
  254. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  255. GuideController.TryGuide(_unPasslevelItem, ConstGuideId.START_STORY, 1, "点击关卡,开启新历程");
  256. GuideController.TryGuide(_unPasslevelItem, ConstGuideId.SINGLE_FIGHT, 1, "遇到意外事件了,暂时解释不清,先按请求换上服饰吧");
  257. GuideController.TryGuide(_ui.m_btnHome, ConstGuideId.LUCKY_BOX, 1, "点击返回主界面");
  258. GuideController.TryGuide(_unPasslevelItem, ConstGuideId.BUY_CLOTHING, 1, "");
  259. }
  260. protected override void TryCompleteGuide()
  261. {
  262. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.START_STORY);
  263. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  264. GuideController.TryCompleteGuide(ConstGuideId.START_STORY, 1);
  265. }
  266. }
  267. }