StroyFightResultView.cs 6.7 KB

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