StoryChapterView.cs 13 KB

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