StroyFightResultView.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. using FairyGUI;
  2. using UnityEngine;
  3. using UI.Main;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. namespace GFGGame
  7. {
  8. public class StroyFightResultView : BaseView
  9. {
  10. private UI_StoryFightResultUI _ui;
  11. private GameObject _sceneObject;
  12. private GameObject _scenePrefab;
  13. private List<ItemData> _currentBonusList;
  14. private bool _fistPassLastLvl;
  15. private bool _curLvfirstPass = false;
  16. private bool resule = false;
  17. public override void Dispose()
  18. {
  19. if (_scenePrefab != null)
  20. {
  21. GameObject.Destroy(_scenePrefab);
  22. _scenePrefab = null;
  23. }
  24. if (_ui != null)
  25. {
  26. _ui.Dispose();
  27. }
  28. _ui = null;
  29. base.Dispose();
  30. }
  31. protected override void Init()
  32. {
  33. base.Init();
  34. _ui = UI_StoryFightResultUI.Create();
  35. viewCom = _ui.target;
  36. isfullScreen = true;
  37. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneFightResult"));
  38. }
  39. protected override void OnInit()
  40. {
  41. base.OnInit();
  42. _ui.m_btnClose.enabled = false;
  43. _ui.m_btnClose.onClick.Add(OnClickBtnClose);
  44. }
  45. protected override void OnShown()
  46. {
  47. base.OnShown();
  48. // Timers.inst.AddUpdate(UpdateToCheckGuide);
  49. if (_sceneObject == null)
  50. {
  51. _sceneObject = GameObject.Instantiate(_scenePrefab);
  52. }
  53. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(StoryDataManager.currentLevelID);
  54. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  55. bool hasFightTarget = fightCfg.targetName != null && fightCfg.targetName.Length > 0;
  56. int score = EquipDataCache.cacher.totalScore;
  57. SceneController.UpdateRole(EquipDataCache.cacher.equipDatas, _sceneObject);
  58. _ui.m_selfScore.m_txtScore.text = "" + score;
  59. _ui.m_expBar.m_txtLvl.text = "" + RoleDataManager.lvl;
  60. RoleLevelCfg roleLevelCfg = RoleLevelCfgArray.Instance.GetCfg(RoleDataManager.lvl);
  61. _ui.m_expBar.m_pbExp.max = roleLevelCfg.exp;
  62. _ui.m_expBar.m_pbExp.value = RoleDataManager.exp;
  63. resule = GetFightResult();
  64. int starCount = !resule ? 0 : StoryDataManager.GetResultStarCount(score);
  65. StoryUtil.UpdateStar(starCount, _ui.m_selfScore.m_flower.target);
  66. _ui.m_selfScore.m_bg.url = "ui://Main/zd_jsjm_jszi_" + starCount;
  67. TextFormat tf = _ui.m_selfScore.m_txtScore.textFormat;
  68. UpdateToCheckGuide(null);
  69. if (!resule)
  70. {
  71. tf.font = "ui://Main/Font3";
  72. _ui.m_expBar.m_txtLvlAdded.text = "0";
  73. _ui.m_expBar.target.visible = false;
  74. _ui.m_btnClose.enabled = true;
  75. string txt = "不要气馁呀,可以通过再次挑战已通关的关卡、摘星、绣坊等途径获取更多的物资来提升自己的战斗力哦!";
  76. int targetY = (int)_ui.m_expBar.target.y - 250;
  77. GuideController.TryGuideByGuideId(null, ConstGuideId.CHAPTER_RESULT_VIEW, 5, false, txt, targetY);
  78. }
  79. else
  80. {
  81. tf.font = "ui://Main/Font2";
  82. _ui.m_expBar.target.visible = true;
  83. _ui.m_btnClose.enabled = false;
  84. //过关
  85. _ui.m_expBar.m_txtLvlAdded.text = "" + fightCfg.exp;
  86. _currentBonusList = StoryDataManager.PassCurrentLevel(out _fistPassLastLvl, out _curLvfirstPass);
  87. if (_curLvfirstPass)
  88. {
  89. FunctionOpenDataManager.Instance.CheckHasChapterFunOpen(StoryDataManager._passChapter + 1, StoryDataManager._passLevel);//首次通过要检查是否有功能开启
  90. }
  91. }
  92. Timers.inst.Add(0.5f, 1, AddExp);
  93. _ui.m_selfScore.m_txtScore.textFormat = tf;
  94. }
  95. private bool GetFightResult()
  96. {
  97. bool equipedNeeded = EquipDataCache.cacher.CheckEquipedFightNeeded();
  98. if (!equipedNeeded)
  99. {
  100. PromptController.Instance.ShowFloatTextPrompt("未穿必需物品");
  101. return false;//没穿必需品
  102. }
  103. int starCount = StoryDataManager.GetResultStarCount(EquipDataCache.cacher.totalScore);
  104. StoryDataManager.SetScore(EquipDataCache.cacher.totalScore, starCount);
  105. if (starCount <= 0)
  106. {
  107. return false;//低于一星
  108. }
  109. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(StoryDataManager.currentLevelID);
  110. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  111. bool hasFightTarget = fightCfg.targetName != null && fightCfg.targetName.Length > 0;
  112. if (hasFightTarget && EquipDataCache.cacher.totalScore < EquipDataCache.cacher.npcTotalScore)
  113. {
  114. return false;//分数低于对战对象
  115. }
  116. return true;
  117. }
  118. protected override void OnHide()
  119. {
  120. base.OnHide();
  121. // Timers.inst.Remove(UpdateToCheckGuide);
  122. TryCompleteGuide();
  123. GuideController.TryCompleteGuide(ConstGuideId.CHAPTER_RESULT_VIEW);
  124. GuideController.TryCompleteGuide(ConstGuideId.FIGHT_RESULT_TIPS_GUIDE);
  125. Timers.inst.Remove(AddExp);
  126. if (_sceneObject != null)
  127. {
  128. GameObject.Destroy(_sceneObject);
  129. _sceneObject = null;
  130. }
  131. _currentBonusList = null;
  132. }
  133. private void OnClickBtnClose()
  134. {
  135. List<ItemData> bonusList = _currentBonusList;
  136. this.Hide();
  137. if (_fistPassLastLvl)
  138. {
  139. ViewManager.Show(ViewName.STORY_CHAPTER_LIST_VIEW);
  140. }
  141. else
  142. {
  143. ViewManager.Show(ViewName.STORY_CHAPTER_VIEW, StoryDataManager.currentChapter, ViewManager.GetGoBackDatas(ViewName.STORY_CHAPTER_VIEW));
  144. }
  145. if (bonusList != null && bonusList.Count > 0)
  146. {
  147. ViewManager.Show(ViewName.GET_BONUS_VIEW, bonusList);
  148. }
  149. StoryDataManager.currentCardId = -1;
  150. }
  151. private void AddExp(object param)
  152. {
  153. _ui.m_expBar.m_txtLvl.text = "" + RoleDataManager.lvl;
  154. if (RoleDataManager.exp <= _ui.m_expBar.m_pbExp.value)
  155. {
  156. _ui.m_expBar.m_pbExp.value = 0;
  157. }
  158. _ui.m_expBar.m_pbExp.TweenValue(RoleDataManager.exp, 0.2f);
  159. _ui.m_btnClose.enabled = true;
  160. int targetY = (int)_ui.m_expBar.target.y - 250;
  161. int count = GuideDataManager.GetGuideCount(ConstGuideId.CHAPTER_RESULT_VIEW);
  162. string txt = null;
  163. if (_curLvfirstPass && StoryDataManager._passChapter + 1 == 1 && StoryDataManager._passLevel == 2)
  164. {
  165. txt = "这条连衣裙可真好看!点击空白区域继续";
  166. }
  167. else if (_curLvfirstPass && StoryDataManager._passChapter + 1 == 1 && StoryDataManager._passLevel == 6)
  168. {
  169. txt = "你太厉害了,初次对战就获得了这么好的战绩,继续加油吧";
  170. }
  171. GuideController.TryGuideByGuideId(null, ConstGuideId.FIGHT_RESULT_TIPS_GUIDE, 2, false, txt, targetY);
  172. }
  173. protected override void UpdateToCheckGuide(object param)
  174. {
  175. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  176. if (!resule) GuideController.TryGuide(null, ConstGuideId.FIRST_FIGHT_FAILED, 1, "不要气馁呀,可以通过再次挑战已通关的关卡、摘星、绣坊等途径获取更多的物资来提升自己的战斗力哦!", false, 0, true, false, (int)(this.viewCom.height - 150));
  177. if (resule) GuideController.TryGuide(null, ConstGuideId.FIRST_FIGHT_SINGLE_WIN, 1, "这条连衣裙可真好看!点击空白区域继续", false, 0, true, false, (int)(this.viewCom.height - 150));
  178. if (resule) GuideController.TryGuide(null, ConstGuideId.FIRST_FIGHT_TARGET_WIN, 1, "你太厉害了,初次对战就获得了这么好的战绩,继续加油吧", false, 0, true, false, (int)(this.viewCom.height - 350));
  179. }
  180. private void TryCompleteGuide()
  181. {
  182. GuideCfg cfg;
  183. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.FIRST_FIGHT_FAILED);
  184. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  185. GuideController.TryCompleteGuide(ConstGuideId.FIRST_FIGHT_FAILED, 1);
  186. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.FIRST_FIGHT_SINGLE_WIN);
  187. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  188. GuideController.TryCompleteGuide(ConstGuideId.FIRST_FIGHT_SINGLE_WIN, 1);
  189. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.FIRST_FIGHT_TARGET_WIN);
  190. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  191. GuideController.TryCompleteGuide(ConstGuideId.FIRST_FIGHT_TARGET_WIN, 1);
  192. }
  193. }
  194. }