StroyFightResultView.cs 9.4 KB

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