StroyFightResultView.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. int targetY = (int)_ui.m_expBar.target.y - 250;
  76. }
  77. else
  78. {
  79. tf.font = "ui://Main/Font2";
  80. _ui.m_expBar.target.visible = true;
  81. _ui.m_btnClose.enabled = false;
  82. //过关
  83. _ui.m_expBar.m_txtLvlAdded.text = "" + fightCfg.exp;
  84. _currentBonusList = StoryDataManager.PassCurrentLevel(out _fistPassLastLvl, out _curLvfirstPass);
  85. if (_curLvfirstPass)
  86. {
  87. FunctionOpenDataManager.Instance.CheckHasChapterFunOpen(StoryDataManager._passChapter + 1, StoryDataManager._passLevel);//首次通过要检查是否有功能开启
  88. }
  89. }
  90. Timers.inst.Add(0.5f, 1, AddExp);
  91. _ui.m_selfScore.m_txtScore.textFormat = tf;
  92. }
  93. private bool GetFightResult()
  94. {
  95. bool equipedNeeded = EquipDataCache.cacher.CheckEquipedFightNeeded();
  96. if (!equipedNeeded)
  97. {
  98. PromptController.Instance.ShowFloatTextPrompt("未穿必需物品");
  99. return false;//没穿必需品
  100. }
  101. int starCount = StoryDataManager.GetResultStarCount(EquipDataCache.cacher.totalScore);
  102. StoryDataManager.SetScore(EquipDataCache.cacher.totalScore, starCount);
  103. if (starCount <= 0)
  104. {
  105. return false;//低于一星
  106. }
  107. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(StoryDataManager.currentLevelID);
  108. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  109. bool hasFightTarget = fightCfg.targetName != null && fightCfg.targetName.Length > 0;
  110. if (hasFightTarget && EquipDataCache.cacher.totalScore < EquipDataCache.cacher.npcTotalScore)
  111. {
  112. return false;//分数低于对战对象
  113. }
  114. return true;
  115. }
  116. protected override void OnHide()
  117. {
  118. base.OnHide();
  119. Timers.inst.Remove(AddExp);
  120. if (_sceneObject != null)
  121. {
  122. GameObject.Destroy(_sceneObject);
  123. _sceneObject = null;
  124. }
  125. _currentBonusList = null;
  126. }
  127. private void OnClickBtnClose()
  128. {
  129. List<ItemData> bonusList = _currentBonusList;
  130. this.Hide();
  131. if (_fistPassLastLvl)
  132. {
  133. ViewManager.Show(ViewName.STORY_CHAPTER_LIST_VIEW);
  134. }
  135. else
  136. {
  137. ViewManager.Show(ViewName.STORY_CHAPTER_VIEW, StoryDataManager.currentChapter, ViewManager.GetGoBackDatas(ViewName.STORY_CHAPTER_VIEW));
  138. }
  139. if (bonusList != null && bonusList.Count > 0)
  140. {
  141. ViewManager.Show(ViewName.GET_BONUS_VIEW, bonusList);
  142. }
  143. StoryDataManager.currentCardId = -1;
  144. }
  145. private void AddExp(object param)
  146. {
  147. _ui.m_expBar.m_txtLvl.text = "" + RoleDataManager.lvl;
  148. if (RoleDataManager.exp <= _ui.m_expBar.m_pbExp.value)
  149. {
  150. _ui.m_expBar.m_pbExp.value = 0;
  151. }
  152. _ui.m_expBar.m_pbExp.TweenValue(RoleDataManager.exp, 0.2f);
  153. _ui.m_btnClose.enabled = true;
  154. int targetY = (int)_ui.m_expBar.target.y - 250;
  155. }
  156. protected override void UpdateToCheckGuide(object param)
  157. {
  158. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  159. if (!resule) GuideController.TryGuide(null, ConstGuideId.FIRST_FIGHT_FAILED, 1, "不要气馁呀,可以通过再次挑战已通关的关卡、摘星、绣坊等途径获取更多的物资来提升自己的战斗力哦!", false, 0, true, false, (int)(this.viewCom.height - 150));
  160. if (resule) GuideController.TryGuide(null, ConstGuideId.FIRST_FIGHT_SINGLE_WIN, 1, "这条连衣裙可真好看!点击空白区域继续", false, 0, true, false, (int)(this.viewCom.height - 150));
  161. if (resule) GuideController.TryGuide(null, ConstGuideId.FIRST_FIGHT_TARGET_WIN, 1, "你太厉害了,初次对战就获得了这么好的战绩,继续加油吧", false, 0, true, false, (int)(this.viewCom.height - 350));
  162. }
  163. protected override void TryCompleteGuide()
  164. {
  165. GuideCfg cfg;
  166. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.FIRST_FIGHT_FAILED);
  167. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  168. GuideController.TryCompleteGuide(ConstGuideId.FIRST_FIGHT_FAILED, 1);
  169. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.FIRST_FIGHT_SINGLE_WIN);
  170. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  171. GuideController.TryCompleteGuide(ConstGuideId.FIRST_FIGHT_SINGLE_WIN, 1);
  172. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.FIRST_FIGHT_TARGET_WIN);
  173. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  174. GuideController.TryCompleteGuide(ConstGuideId.FIRST_FIGHT_TARGET_WIN, 1);
  175. }
  176. }
  177. }