StoryChapterView.cs 13 KB

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