StroyFightResultView.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 = hasFightTarget ? EquipDataCache.cacher.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 equipedNeeded = EquipDataCache.cacher.CheckEquipedFightNeeded();
  61. int starCount = 0;
  62. if (equipedNeeded)
  63. {
  64. starCount = StoryDataManager.GetResultStarCount(score);
  65. StoryDataManager.SetScore(score, starCount);
  66. }
  67. else
  68. {
  69. PromptController.Instance.ShowFloatTextPrompt("未穿必需物品");
  70. }
  71. StoryUtil.UpdateStar(starCount, _ui.m_selfScore.m_flower.target);
  72. _ui.m_selfScore.m_bg.url = "ui://Main/zd_jsjm_jszi_" + starCount;
  73. TextFormat tf = _ui.m_selfScore.m_txtScore.textFormat;
  74. if (starCount <= 0)
  75. {
  76. tf.font = "ui://Main/Font3";
  77. _ui.m_expBar.m_txtLvlAdded.text = "0";
  78. _ui.m_expBar.target.visible = false;
  79. _ui.m_btnClose.enabled = true;
  80. string txt = "不要气馁呀,可以通过再次挑战已通关的关卡、摘星、绣坊等途径获取更多的物资来提升自己的战斗力哦!";
  81. int targetY = (int)_ui.m_expBar.target.y - 250;
  82. GuideController.TryGuideByGuideId(null, ConstGuideId.CHAPTER_RESULT_VIEW, 5, false, txt, targetY);
  83. }
  84. else
  85. {
  86. tf.font = "ui://Main/Font2";
  87. _ui.m_expBar.target.visible = true;
  88. _ui.m_btnClose.enabled = false;
  89. //过关
  90. _ui.m_expBar.m_txtLvlAdded.text = "" + fightCfg.exp;
  91. _currentBonusList = StoryDataManager.PassCurrentLevel(out _fistPassLastLvl);
  92. Timers.inst.Add(0.5f, 1, AddExp);
  93. }
  94. _ui.m_selfScore.m_txtScore.textFormat = tf;
  95. }
  96. protected override void OnHide()
  97. {
  98. base.OnHide();
  99. GuideController.TryCompleteGuide(ConstGuideId.CHAPTER_RESULT_VIEW);
  100. Timers.inst.Remove(AddExp);
  101. if (_sceneObject != null)
  102. {
  103. GameObject.Destroy(_sceneObject);
  104. _sceneObject = null;
  105. }
  106. _currentBonusList = null;
  107. }
  108. private void OnClickBtnClose()
  109. {
  110. List<ItemData> bonusList = _currentBonusList;
  111. this.Hide();
  112. if (_fistPassLastLvl)
  113. {
  114. ViewManager.Show(ViewName.STORY_CHAPTER_LIST_VIEW);
  115. }
  116. else
  117. {
  118. ViewManager.Show(ViewName.STORY_CHAPTER_VIEW, StoryDataManager.currentChapter, ViewManager.GetGoBackDatas(ViewName.STORY_CHAPTER_VIEW));
  119. }
  120. if (bonusList != null && bonusList.Count > 0)
  121. {
  122. ViewManager.Show(ViewName.GET_BONUS_VIEW, bonusList);
  123. }
  124. StoryDataManager.currentCardId = -1;
  125. }
  126. private void AddExp(object param)
  127. {
  128. _ui.m_expBar.m_txtLvl.text = "" + RoleDataManager.lvl;
  129. if (RoleDataManager.exp <= _ui.m_expBar.m_pbExp.value)
  130. {
  131. _ui.m_expBar.m_pbExp.value = 0;
  132. }
  133. _ui.m_expBar.m_pbExp.TweenValue(RoleDataManager.exp, 0.2f);
  134. _ui.m_btnClose.enabled = true;
  135. int targetY = (int)_ui.m_expBar.target.y - 250;
  136. int count = GuideDataManager.GetGuideCount(ConstGuideId.CHAPTER_RESULT_VIEW);
  137. string txt = null;
  138. if (count == 0)
  139. {
  140. txt = "这条连衣裙可真好看!点击空白区域继续";
  141. }
  142. else
  143. {
  144. txt = "你太厉害了,初次对战就获得了这么好的战绩,继续加油吧";
  145. }
  146. GuideController.TryGuideByGuideId(null, ConstGuideId.CHAPTER_RESULT_VIEW, 2, false, txt, targetY);
  147. }
  148. }
  149. }