StroyFightResultView.cs 7.3 KB

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