StroyFightResultView.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 struct StoryFightResultData
  10. {
  11. public bool Result;
  12. public int Score;
  13. public int Star;
  14. public bool FirstPass;
  15. public List<ItemData> BonusList;
  16. }
  17. public class StroyFightResultView : BaseView
  18. {
  19. private UI_StoryFightResultUI _ui;
  20. private GameObject _sceneObject;
  21. private GameObject _scenePrefab;
  22. private List<ItemData> _currentBonusList;
  23. private bool result = false;
  24. private bool _fistPassLastLvl = false;
  25. public override void Dispose()
  26. {
  27. if (_scenePrefab != null)
  28. {
  29. GameObject.Destroy(_scenePrefab);
  30. _scenePrefab = null;
  31. }
  32. if (_ui != null)
  33. {
  34. _ui.Dispose();
  35. }
  36. _ui = null;
  37. base.Dispose();
  38. }
  39. protected override void Init()
  40. {
  41. base.Init();
  42. _ui = UI_StoryFightResultUI.Create();
  43. viewCom = _ui.target;
  44. isfullScreen = true;
  45. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneFightResult"));
  46. }
  47. protected override void OnInit()
  48. {
  49. base.OnInit();
  50. _ui.m_btnClose.enabled = false;
  51. _ui.m_btnClose.onClick.Add(OnClickBtnClose);
  52. }
  53. protected override void OnShown()
  54. {
  55. base.OnShown();
  56. var resultData = (StoryFightResultData)this.viewData;
  57. // Timers.inst.AddUpdate(UpdateToCheckGuide);
  58. if (_sceneObject == null)
  59. {
  60. _sceneObject = GameObject.Instantiate(_scenePrefab);
  61. }
  62. _currentBonusList = resultData.BonusList;
  63. //判断是否是首次打通最后一关
  64. int nextLevelID = StoryDataManager.currentLevelCfgId + 1;
  65. StoryLevelCfg nextLevelCfg = StoryLevelCfgArray.Instance.GetCfg(nextLevelID);
  66. _fistPassLastLvl = (nextLevelCfg == null) && resultData.FirstPass;
  67. SceneController.UpdateRole(EquipDataCache.cacher.equipDatas, _sceneObject);
  68. _ui.m_selfScore.m_txtScore.text = "" + resultData.Score;
  69. _ui.m_expBar.m_txtLvl.text = "" + GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl);
  70. RoleLevelCfg roleLevelCfg = RoleLevelCfgArray.Instance.GetCfg(GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl));
  71. _ui.m_expBar.m_pbExp.max = roleLevelCfg.exp;
  72. _ui.m_expBar.m_pbExp.value = GameGlobal.myNumericComponent.GetAsInt(NumericType.Exp);
  73. result = resultData.Result;
  74. StoryUtil.UpdateStar(resultData.Star, _ui.m_selfScore.m_flower.target);
  75. _ui.m_selfScore.m_bg.url = "ui://Main/zd_jsjm_jszi_" + resultData.Star;
  76. TextFormat tf = _ui.m_selfScore.m_txtScore.textFormat;
  77. UpdateToCheckGuide(null);
  78. if (!result)
  79. {
  80. tf.font = "ui://Main/Font3";
  81. _ui.m_expBar.m_txtLvlAdded.text = "0";
  82. _ui.m_expBar.target.visible = false;
  83. _ui.m_btnClose.enabled = true;
  84. }
  85. else
  86. {
  87. tf.font = "ui://Main/Font2";
  88. _ui.m_expBar.target.visible = true;
  89. _ui.m_btnClose.enabled = false;
  90. //过关
  91. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(StoryDataManager.currentLevelCfgId);
  92. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  93. _ui.m_expBar.m_txtLvlAdded.text = "" + fightCfg.exp;
  94. Timers.inst.Add(0.5f, 1, AddExp);
  95. }
  96. _ui.m_selfScore.m_txtScore.textFormat = tf;
  97. }
  98. protected override void OnHide()
  99. {
  100. base.OnHide();
  101. Timers.inst.Remove(AddExp);
  102. if (_sceneObject != null)
  103. {
  104. GameObject.Destroy(_sceneObject);
  105. _sceneObject = null;
  106. }
  107. _currentBonusList = null;
  108. }
  109. private void OnClickBtnClose()
  110. {
  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. //尝试显示奖励
  121. BonusController.TryShowBonusList(_currentBonusList);
  122. StoryDataManager.currentCardId = -1;
  123. }
  124. private void AddExp(object param)
  125. {
  126. _ui.m_expBar.m_txtLvl.text = "" + GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl);
  127. int exp = GameGlobal.myNumericComponent.GetAsInt(NumericType.Exp);
  128. if (exp <= _ui.m_expBar.m_pbExp.value)
  129. {
  130. _ui.m_expBar.m_pbExp.value = 0;
  131. }
  132. _ui.m_expBar.m_pbExp.TweenValue(exp, 0.2f);
  133. _ui.m_btnClose.enabled = true;
  134. }
  135. protected override void UpdateToCheckGuide(object param)
  136. {
  137. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  138. if (!result) GuideController.TryGuide(null, ConstGuideId.FIRST_FIGHT_FAILED, 1, "不要气馁呀,可以通过再次挑战已通关的关卡、摘星、绣坊等途径获取更多的物资来提升自己的战斗力哦!", false, 0, true, false, (int)(this.viewCom.height - 150));
  139. if (result) GuideController.TryGuide(null, ConstGuideId.FIRST_FIGHT_SINGLE_WIN, 1, "这条连衣裙可真好看!点击空白区域继续", false, 0, true, false, (int)(this.viewCom.height - 150));
  140. if (result) GuideController.TryGuide(null, ConstGuideId.FIRST_FIGHT_TARGET_WIN, 1, "你太厉害了,初次对战就获得了这么好的战绩,继续加油吧", false, 0, true, false, (int)(this.viewCom.height - 350));
  141. }
  142. protected override void TryCompleteGuide()
  143. {
  144. GuideCfg cfg;
  145. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.FIRST_FIGHT_FAILED);
  146. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  147. GuideController.TryCompleteGuide(ConstGuideId.FIRST_FIGHT_FAILED, 1);
  148. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.FIRST_FIGHT_SINGLE_WIN);
  149. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  150. GuideController.TryCompleteGuide(ConstGuideId.FIRST_FIGHT_SINGLE_WIN, 1);
  151. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.FIRST_FIGHT_TARGET_WIN);
  152. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  153. GuideController.TryCompleteGuide(ConstGuideId.FIRST_FIGHT_TARGET_WIN, 1);
  154. }
  155. }
  156. }