StroyFightResultView.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 GameObject _gameObject;
  23. private GameObject _gameObject1;
  24. private GoWrapper _wrapper;
  25. private StoryLevelCfg _levelCfg;
  26. private StoryFightResultData _resultData;
  27. public override void Dispose()
  28. {
  29. SceneController.DestroyObjectFromView(_gameObject);
  30. SceneController.DestroyObjectFromView(_gameObject1);
  31. if (_scenePrefab != null)
  32. {
  33. GameObject.Destroy(_scenePrefab);
  34. _scenePrefab = null;
  35. }
  36. if (_ui != null)
  37. {
  38. _ui.Dispose();
  39. }
  40. _ui = null;
  41. base.Dispose();
  42. }
  43. protected override void Init()
  44. {
  45. base.Init();
  46. _ui = UI_StoryFightResultUI.Create();
  47. viewCom = _ui.target;
  48. isfullScreen = true;
  49. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneFightResult"));
  50. }
  51. protected override void OnInit()
  52. {
  53. base.OnInit();
  54. _ui.m_btnClose.enabled = false;
  55. _ui.m_btnClose.onClick.Add(OnClickBtnClose);
  56. string resPath = ResPathUtil.GetViewEffectPath("ui_zhandou", "ui_zd_zdjs_jdt");
  57. SceneController.AddObjectToView(_gameObject1, null, _ui.m_expBar.m_pbExp.m_holder, resPath, out _gameObject1, out GoWrapper wrapper);
  58. }
  59. protected override void OnShown()
  60. {
  61. base.OnShown();
  62. _resultData = (StoryFightResultData)this.viewData;
  63. if (_sceneObject == null)
  64. {
  65. _sceneObject = GameObject.Instantiate(_scenePrefab);
  66. }
  67. InstanceZonesDataManager.usedRecommend = false;
  68. SceneController.UpdateRole(EquipDataCache.cacher.equipDatas, _sceneObject);
  69. MusicManager.Instance.Play(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT));
  70. _ui.m_txtScore.text = "" + _resultData.Score;
  71. _ui.m_expBar.m_txtLvl.text = "" + GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl);
  72. StoryUtil.UpdateStar(_resultData.Star, _ui.m_flower.target);
  73. string resPath = ResPathUtil.GetViewEffectPath("ui_zhandou", string.Format("zd_zdjs_{0}", _resultData.Star));
  74. SceneController.AddObjectToView(_gameObject, _wrapper, _ui.m_holder, resPath, out _gameObject, out _wrapper, 120);
  75. _ui.m_holder.visible = true;
  76. TextFormat tf = _ui.m_txtScore.textFormat;
  77. UpdateToCheckGuide(null);
  78. _ui.m_c1.selectedIndex = 0;
  79. _levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
  80. if (_levelCfg.type == ConstInstanceZonesType.Field)
  81. {
  82. _ui.m_c1.selectedIndex = 1;
  83. Timers.inst.Add(3, 1, OnClickBtnClose);
  84. }
  85. if (!this._resultData.Result)
  86. {
  87. tf.font = "ui://Main/Font3";
  88. _ui.m_expBar.m_txtLvlAdded.text = "0";
  89. _ui.m_expBar.target.visible = false;
  90. _ui.m_btnClose.enabled = true;
  91. }
  92. else
  93. {
  94. tf.font = "ui://Main/Font2";
  95. _ui.m_expBar.target.visible = true;
  96. _ui.m_btnClose.enabled = false;
  97. //过关
  98. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(_levelCfg.fightID);
  99. _ui.m_expBar.m_txtLvlAdded.text = "" + fightCfg.exp;
  100. Timers.inst.Add(0.5f, 1, this.AddExp);
  101. }
  102. _ui.m_txtScore.textFormat = tf;
  103. _ui.m_t0.SetValue("posY", 33, this.viewCom.height - 235);
  104. _ui.m_t0.Play();
  105. }
  106. protected override void OnHide()
  107. {
  108. base.OnHide();
  109. Timers.inst.Remove(AddExp);
  110. if (_sceneObject != null)
  111. {
  112. GameObject.Destroy(_sceneObject);
  113. _sceneObject = null;
  114. }
  115. }
  116. private async void OnClickBtnClose(object param)
  117. {
  118. this.Hide();
  119. if (_levelCfg.type == ConstInstanceZonesType.Field)
  120. {
  121. _ui.m_c1.selectedIndex = 1;
  122. Timers.inst.Remove(OnClickBtnClose);
  123. if (!this._resultData.Result || FieldDataManager.Instance.currFightLv == FieldCfgArray.Instance.GetCfg(FieldDataManager.Instance.chapterId).num)
  124. {
  125. ViewManager.Show<FieldView>();
  126. if (FieldDataManager.Instance.currFightLv <= 1) return;
  127. bool result = await FieldSProxy.ReqFieldInstanceResult();
  128. if (result)
  129. {
  130. ViewManager.Show<FieldFightEndView>();
  131. }
  132. }
  133. else
  134. {
  135. ViewManager.Show<FieldView>();
  136. ViewManager.Show<FieldFightInfoView>();
  137. }
  138. }
  139. else
  140. {
  141. InstanceZonesController.OnFinishStoryLevel(InstanceZonesDataManager.currentLevelCfgId, _resultData.FirstPass, true);
  142. //尝试显示奖励
  143. BonusController.TryShowBonusList(_resultData.BonusList);
  144. }
  145. InstanceZonesDataManager.currentCardId = -1;
  146. }
  147. private void AddExp(object param)
  148. {
  149. int lv = GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl);
  150. _ui.m_expBar.m_txtLvl.text = lv.ToString();
  151. float exp = GameGlobal.myNumericComponent.GetAsInt(NumericType.Exp);
  152. float cfgExp = RoleLevelCfgArray.Instance.GetCfg(lv).exp;
  153. float initWidth = _ui.m_expBar.m_pbExp.m_bar.target.initWidth;
  154. float curWidth = _ui.m_expBar.m_pbExp.m_bar.target.width;
  155. float width = exp / cfgExp * initWidth;
  156. if (width <= curWidth)
  157. {
  158. _ui.m_expBar.m_pbExp.m_bar.target.width = 0;
  159. }
  160. GTween.To(_ui.m_expBar.m_pbExp.m_bar.target.width, width, 0.2f).SetTarget(_ui.m_expBar.m_pbExp.m_bar).OnUpdate((GTweener t) =>
  161. {
  162. _ui.m_expBar.m_pbExp.m_bar.target.width = t.value.x;
  163. }); ;
  164. // _ui.m_expBar.m_pbExp..TweenValue(exp, 0.2f);
  165. _ui.m_btnClose.enabled = true;
  166. }
  167. protected override void UpdateToCheckGuide(object param)
  168. {
  169. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  170. if (!_resultData.Result) GuideController.TryGuide(null, ConstGuideId.FIRST_FIGHT_FAILED, 1, "不要气馁呀,可以通过再次挑战已通关的关卡、摘星、绣坊等途径获取更多的物资来提升自己的战斗力哦!", -1, true, (int)(this.viewCom.height - 150));
  171. if (_resultData.Result) GuideController.TryGuide(null, ConstGuideId.FIRST_FIGHT_SINGLE_WIN, 1, "这条连衣裙可真好看!点击空白区域继续", -1, true, (int)(this.viewCom.height - 400));
  172. if (_resultData.Result) GuideController.TryGuide(null, ConstGuideId.FIRST_FIGHT_TARGET_WIN, 1, "你太厉害了,初次对战就获得了这么好的战绩,继续加油吧", -1, true, (int)(this.viewCom.height - 400));
  173. }
  174. protected override void TryCompleteGuide()
  175. {
  176. GuideCfg cfg;
  177. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.FIRST_FIGHT_FAILED);
  178. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  179. GuideController.TryCompleteGuide(ConstGuideId.FIRST_FIGHT_FAILED, 1);
  180. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.FIRST_FIGHT_SINGLE_WIN);
  181. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  182. GuideController.TryCompleteGuide(ConstGuideId.FIRST_FIGHT_SINGLE_WIN, 1);
  183. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.FIRST_FIGHT_TARGET_WIN);
  184. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  185. GuideController.TryCompleteGuide(ConstGuideId.FIRST_FIGHT_TARGET_WIN, 1);
  186. }
  187. }
  188. }