StoryChapterView.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("zxian_bg3");
  59. }
  60. protected override void AddEventListener()
  61. {
  62. EventAgent.AddEventListener(ConstMessage.NOTICE_MAINSTORY_BOXBONUS_STATE, UpdateBonusBox);
  63. }
  64. protected override void OnShown()
  65. {
  66. base.OnShown();
  67. _ui.target.touchable = false;
  68. MusicManager.Instance.Play(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT));
  69. _chapterID = (int)viewData;
  70. MainStoryDataManager.currentChapterCfgId = _chapterID;
  71. // StoryChapterCfg cfg = StoryChapterCfgArray.Instance.GetCfg(_chapterID);
  72. InitChapter();
  73. _valueBarController.OnShown();
  74. // _valueBarController.Controller(1);
  75. _ui.target.touchable = true;
  76. Timers.inst.AddUpdate(CheckGuide);
  77. }
  78. protected override void OnHide()
  79. {
  80. base.OnHide();
  81. _unPasslevelItem = null;
  82. _endLevelItem = null;
  83. _ui.m_chapter.RemoveChildren(0, 0, true);
  84. _valueBarController.OnHide();
  85. Timers.inst.Remove(CheckGuide);
  86. }
  87. protected override void RemoveEventListener()
  88. {
  89. base.RemoveEventListener();
  90. EventAgent.RemoveEventListener(ConstMessage.NOTICE_MAINSTORY_BOXBONUS_STATE, UpdateBonusBox);
  91. }
  92. private void OnClickBtnBack()
  93. {
  94. ViewManager.GoBackFrom(ViewName.STORY_CHAPTER_VIEW);
  95. }
  96. private void OnClickBtnHome()
  97. {
  98. GameController.GoBackToMainView();
  99. }
  100. private void InitChapter()
  101. {
  102. StoryChapterCfg chapterCfg = StoryChapterCfgArray.Instance.GetCfg(_chapterID);
  103. _ui.m_txtChapterName0.text = chapterCfg.name.Length > 0 ? chapterCfg.name[0].ToString() : "";
  104. _ui.m_txtChapterName1.text = chapterCfg.name.Length > 1 ? chapterCfg.name[1].ToString() : "";
  105. _ui.m_txtChapterName2.text = chapterCfg.name.Length > 2 ? chapterCfg.name[2].ToString() : "";
  106. _ui.m_txtChapterName3.text = chapterCfg.name.Length > 3 ? chapterCfg.name[3].ToString() : "";
  107. _ui.m_txtChapterName4.text = chapterCfg.name.Length > 4 ? chapterCfg.name[4].ToString() : "";
  108. int order = StoryUtil.GetChapterOrder(chapterCfg.id);
  109. _ui.m_txtChapter.text = order < 10 ? "0" + order : order.ToString();
  110. int starCountChapter = InstanceZonesDataManager.GetChapterStarCount(_chapterID, chapterCfg.type, chapterCfg.subType);
  111. _ui.m_txtStarCount.text = "" + starCountChapter + "/" + chapterCfg.bonusStar3;
  112. UpdateBonusBoxName(_ui.m_bonusBox1, "" + chapterCfg.bonusStar1);
  113. UpdateBonusBoxName(_ui.m_bonusBox2, "" + chapterCfg.bonusStar2);
  114. UpdateBonusBoxName(_ui.m_bonusBox3, "" + chapterCfg.bonusStar3);
  115. UpdateBonusBox();
  116. var list = StoryLevelCfgArray.Instance.GetCfgsBytypeAndsubTypeAndchapterId(chapterCfg.type, chapterCfg.subType, chapterCfg.id);
  117. int endLevel = 0;
  118. _compChapter = (GComponent)UIPackage.CreateObject("Main", "CompChapter");
  119. float starPosY = _compChapter.GetChild("imgBegin").asImage.y;
  120. _ui.m_chapter.scrollPane.touchEffect = true;
  121. _ui.m_chapter.AddChild(_compChapter);
  122. int lineGap = 4800 / list.Count;
  123. for (int i = 0; i < list.Count; i++)
  124. {
  125. GObject obj = UIPackage.CreateObject("Main", "CompStoryLevelItem");
  126. _compChapter.AddChild(obj);
  127. GObject posGrh0 = _compChapter.GetChild(string.Format("grh{0}_0", i));
  128. GObject posGrh1 = _compChapter.GetChild(string.Format("grh{0}_1", i));
  129. obj.SetPosition(posGrh0 == null ? posGrh1.x : posGrh0.x, starPosY - lineGap * i - 100, 0); ;
  130. StoryLevelCfg levelCfg = list[i];
  131. UI_CompStoryLevelItem levelItem = UI_CompStoryLevelItem.Proxy(obj);
  132. levelItem.target.data = levelCfg.id;
  133. if (MainStoryDataManager.CheckLevelUnlock(levelCfg.id))
  134. {
  135. levelItem.m_c2.selectedIndex = posGrh0 == null ? 1 : 0;
  136. levelItem.target.visible = true;
  137. levelItem.target.onClick.Clear();
  138. levelItem.target.onClick.Add(OnClickLevelItem);
  139. string showId = StoryUtil.GetChapterOrder(_chapterID) + "-" + levelCfg.order;
  140. levelItem.m_txtDialogOrder.text = showId;
  141. levelItem.m_txtFightOrder.text = showId;
  142. if (levelCfg.fightID.Length > 0)
  143. {
  144. levelItem.m_c1.selectedIndex = 1;
  145. int score = InstanceZonesDataManager.GetScoreHighest(levelCfg.id);
  146. if (score <= 0)
  147. {
  148. levelItem.m_flower.target.visible = false;
  149. }
  150. else
  151. {
  152. levelItem.m_flower.target.visible = true;
  153. int starCount = InstanceZonesDataManager.GetStarCountHistory(levelCfg.id);
  154. StoryUtil.UpdateStar(starCount, levelItem.m_flower.target);
  155. }
  156. }
  157. else
  158. {
  159. levelItem.m_c1.selectedIndex = 0;
  160. levelItem.m_flower.target.visible = false;
  161. }
  162. levelItem.m_holder.visible = !InstanceZonesDataManager.CheckLevelPass(levelCfg.id);
  163. if (levelItem.m_holder.visible)
  164. {
  165. //设置为解锁关卡
  166. MainStoryDataManager.currentLevelCfgId = levelCfg.id;
  167. _unPasslevelItem = levelItem.target;
  168. _gameObject = null;
  169. _wrapper = null;
  170. string resPath = ResPathUtil.GetViewEffectPath("ui_gk", "ui_gk_sg");
  171. SceneController.AddObjectToView(_gameObject, _wrapper, levelItem.m_holder, resPath, out _gameObject, out _wrapper);
  172. }
  173. if (levelCfg.order > endLevel)
  174. {
  175. endLevel = levelCfg.order;
  176. _endLevelItem = levelItem.target;
  177. }
  178. }
  179. else
  180. {
  181. levelItem.target.visible = false;
  182. }
  183. UI_CompStoryLevelItem.ProxyEnd();
  184. }
  185. if (_endLevelItem != null)
  186. {
  187. float tx = _endLevelItem.x + _endLevelItem.width / 2;
  188. float ty = _endLevelItem.y + _endLevelItem.height / 2;
  189. tx = tx - _ui.m_chapter.width / 2;
  190. ty = ty - _ui.m_chapter.height / 2;
  191. _ui.m_chapter.scrollPane.SetPosX(tx, false);
  192. _ui.m_chapter.scrollPane.SetPosY(ty, false);
  193. }
  194. }
  195. private void OnClickLevelItem(EventContext context)
  196. {
  197. UI_CompStoryLevelItem levelItem = UI_CompStoryLevelItem.Proxy(context.sender as GObject);
  198. int levelCfgId = (int)levelItem.target.data;
  199. UI_CompStoryLevelItem.ProxyEnd();
  200. StoryController.ShowLevelView(levelCfgId);
  201. TryCompleteGuide();
  202. }
  203. private void UpdateBonusBoxName(UI_CompBonusBox bonusBox, string name)
  204. {
  205. bonusBox.m_txtName.text = name;
  206. }
  207. private void UpdateBonusBox()
  208. {
  209. UpdateBonusBoxStatus(_ui.m_bonusBox1, 0);
  210. UpdateBonusBoxStatus(_ui.m_bonusBox2, 1);
  211. UpdateBonusBoxStatus(_ui.m_bonusBox3, 2);
  212. }
  213. private void UpdateBonusBoxStatus(UI_CompBonusBox bonusBox, int index)
  214. {
  215. int status = MainStoryDataManager.GetChapterBonusStatus(MainStoryDataManager.currentChapterCfgId, index);
  216. bonusBox.m_iconActive.visible = status == ConstBonusStatus.CAN_GET;
  217. // bonusBox.m_ComRewardEffect.visible = status == ConstBonusStatus.CAN_GET;
  218. if (status == ConstBonusStatus.GOT)
  219. {
  220. bonusBox.m_icon.url = "ui://Main/zxian_gift_get";
  221. }
  222. else
  223. {
  224. bonusBox.m_icon.url = "ui://Main/zxian_gift_unget";
  225. }
  226. bonusBox.target.data = status;
  227. }
  228. private async void OnClickBonusBox(UI_CompBonusBox bonusBox, int index)
  229. {
  230. int status = (int)bonusBox.target.data;
  231. if (status == ConstBonusStatus.CAN_GET)
  232. {
  233. bool got = await MainStorySProxy.GetMainStoryBoxBonus(MainStoryDataManager.currentChapterCfgId, index);
  234. if (got)
  235. {
  236. List<ItemData> bonusList = MainStoryDataManager.GetChapterBonus(MainStoryDataManager.currentChapterCfgId, index);
  237. if (bonusList != null && bonusList.Count > 0)
  238. {
  239. BonusController.TryShowBonusList(bonusList);
  240. }
  241. UpdateBonusBoxStatus(bonusBox, index);
  242. }
  243. }
  244. // else if (status == ConstBonusStatus.GOT)
  245. // {
  246. // PromptController.Instance.ShowFloatTextPrompt("这个宝箱已经被领取过了");
  247. // }
  248. else
  249. {
  250. List<ItemData> rewards = StoryBonusDataCache.GetChapterBonusList(_chapterID, index);
  251. int star = StoryBonusDataCache.GetChapterBonusStar(_chapterID, index);
  252. ViewManager.Show<RewardPreView>(new object[] { rewards, "宝箱奖励", string.Format("本章达成{0}星可领取", star) });
  253. // PromptController.Instance.ShowFloatTextPrompt("关卡总分不足,继续加油吧。");
  254. }
  255. }
  256. private void CheckGuide(object param)
  257. {
  258. if (GuideDataManager.IsGuideFinish(ConstGuideId.START_FIGHT) <= 0
  259. || GuideDataManager.IsGuideFinish(ConstGuideId.FREEDOM_DRESS) <= 0
  260. || GuideDataManager.IsGuideFinish(ConstGuideId.ENTER_CHAPTER) <= 0
  261. || GuideDataManager.IsGuideFinish(ConstGuideId.BUY_CLOTHING) <= 0
  262. || GuideDataManager.IsGuideFinish(ConstGuideId.UP_CARD_LV) <= 0
  263. || GuideDataManager.IsGuideFinish(ConstGuideId.ENTER_CHAPTER_1) <= 0
  264. || GuideDataManager.IsGuideFinish(ConstGuideId.ENTER_CHAPTER_2) <= 0
  265. || GuideDataManager.IsGuideFinish(ConstGuideId.ENTER_CHAPTER_3) <= 0
  266. || GuideDataManager.IsGuideFinish(ConstGuideId.ENTER_CHAPTER_4) <= 0
  267. || GuideDataManager.IsGuideFinish(ConstGuideId.ENTER_CHAPTER_5) <= 0
  268. || GuideDataManager.IsGuideFinish(ConstGuideId.UP_CARD_STAR) <= 0
  269. || GuideDataManager.IsGuideFinish(ConstGuideId.ARENA_OPEN) <= 0
  270. || GuideDataManager.IsGuideFinish(ConstGuideId.CLOTHING_DECOMPOSE) <= 0)
  271. {
  272. UpdateToCheckGuide(null);
  273. }
  274. else
  275. {
  276. Timers.inst.Remove(CheckGuide);
  277. }
  278. }
  279. protected override void UpdateToCheckGuide(object param)
  280. {
  281. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  282. GComponent unPasslevelCom = _unPasslevelItem == null ? null : _unPasslevelItem.asCom;
  283. bool isGuide0 = GuideController.TryGuide(unPasslevelCom, ConstGuideId.START_FIGHT, 1, "尝试换上一套衣服吧。");
  284. bool isGuide1 = GuideController.TryGuide(_ui.m_btnHome, ConstGuideId.FREEDOM_DRESS, 1, "获得的服饰随时可以查看和试穿。");
  285. bool isGuide2 = GuideController.TryGuide(unPasslevelCom, ConstGuideId.ENTER_CHAPTER, 5, "来继续我们的旅程吧。");
  286. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER, 5);
  287. bool isGuide3 = GuideController.TryGuide(unPasslevelCom, ConstGuideId.ENTER_CHAPTER_1, 4, "来继续我们的旅程吧。");
  288. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_1, 4);
  289. bool isGuide4 = GuideController.TryGuide(unPasslevelCom, ConstGuideId.BUY_CLOTHING, 1, "衣服被弄脏了,到机场更衣室换身衣服吧。");
  290. bool isGuide5 = GuideController.TryGuide(_ui.m_btnHome, ConstGuideId.UP_CARD_LV, 1, "点击返回主界面。");
  291. bool isGuide6 = GuideController.TryGuide(_ui.m_btnHome, ConstGuideId.CLOTHING_DECOMPOSE, 1, "点击返回主界面。");
  292. bool isGuide7 = GuideController.TryGuide(unPasslevelCom, ConstGuideId.ENTER_CHAPTER_2, 4, "来继续我们的旅程吧。");
  293. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_2, 4);
  294. bool isGuide8 = GuideController.TryGuide(unPasslevelCom, ConstGuideId.ENTER_CHAPTER_3, 3, "来继续我们的旅程吧。");
  295. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_3, 3);
  296. bool isGuide10 = GuideController.TryGuide(unPasslevelCom, ConstGuideId.ENTER_CHAPTER_4, 4, "来继续我们的旅程吧。");
  297. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_4, 4);
  298. bool isGuide11 = GuideController.TryGuide(unPasslevelCom, ConstGuideId.ENTER_CHAPTER_5, 4, "来继续我们的旅程吧。");
  299. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_5, 4);
  300. bool isGuide9 = GuideController.TryGuide(_ui.m_btnHome, ConstGuideId.UP_CARD_STAR, 1, "点击返回主界面。");
  301. bool isGuide12 = GuideController.TryGuide(_ui.m_btnHome, ConstGuideId.ARENA_OPEN, 1, "点击返回主界面。");
  302. _ui.m_chapter.scrollPane.touchEffect = !isGuide0 && !isGuide1 && !isGuide2 && !isGuide3 && !isGuide4 && !isGuide5 && !isGuide6 && !isGuide7 && !isGuide8 && !isGuide9 && !isGuide10;
  303. }
  304. protected override void TryCompleteGuide()
  305. {
  306. base.TryCompleteGuide();
  307. // GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.ENTER_CHAPTER);
  308. GuideController.TryCompleteGuideIndex(ConstGuideId.ENTER_CHAPTER, 5);
  309. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER, 5);
  310. // GuideCfg cfg1 = GuideCfgArray.Instance.GetCfg(ConstGuideId.ENTER_CHAPTER_1);
  311. GuideController.TryCompleteGuideIndex(ConstGuideId.ENTER_CHAPTER_1, 4);
  312. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_1, 4);
  313. // GuideCfg cfg2 = GuideCfgArray.Instance.GetCfg(ConstGuideId.ENTER_CHAPTER_2);
  314. GuideController.TryCompleteGuideIndex(ConstGuideId.ENTER_CHAPTER_2, 4);
  315. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_2, 4);
  316. // GuideCfg cfg3 = GuideCfgArray.Instance.GetCfg(ConstGuideId.ENTER_CHAPTER_3);
  317. GuideController.TryCompleteGuideIndex(ConstGuideId.ENTER_CHAPTER_3, 3);
  318. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_3, 3);
  319. // GuideCfg cfg4 = GuideCfgArray.Instance.GetCfg(ConstGuideId.ENTER_CHAPTER_4);
  320. GuideController.TryCompleteGuideIndex(ConstGuideId.ENTER_CHAPTER_4, 4);
  321. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_4, 4);
  322. // GuideCfg cfg5 = GuideCfgArray.Instance.GetCfg(ConstGuideId.ENTER_CHAPTER_5);
  323. GuideController.TryCompleteGuideIndex(ConstGuideId.ENTER_CHAPTER_5, 4);
  324. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_5, 4);
  325. }
  326. }
  327. }