StroyFightResultView.cs 8.2 KB

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