StroyFightResultView.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. // Timers.inst.AddUpdate(UpdateToCheckGuide);
  64. if (_sceneObject == null)
  65. {
  66. _sceneObject = GameObject.Instantiate(_scenePrefab);
  67. }
  68. SceneController.UpdateRole(EquipDataCache.cacher.equipDatas, _sceneObject);
  69. _ui.m_txtScore.text = "" + _resultData.Score;
  70. _ui.m_expBar.m_txtLvl.text = "" + GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl);
  71. RoleLevelCfg roleLevelCfg = RoleLevelCfgArray.Instance.GetCfg(GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl));
  72. // _ui.m_expBar.m_pbExp.max = roleLevelCfg.exp;
  73. // _ui.m_expBar.m_pbExp.value = GameGlobal.myNumericComponent.GetAsInt(NumericType.Exp);
  74. StoryUtil.UpdateStar(_resultData.Star, _ui.m_flower.target);
  75. string resPath = ResPathUtil.GetViewEffectPath("ui_zhandou", string.Format("zd_zdjs_{0}", _resultData.Star));
  76. SceneController.AddObjectToView(_gameObject, _wrapper, _ui.m_holder, resPath, out _gameObject, out _wrapper, 120);
  77. // _ui.m_selfScore.m_bg.url = "ui://Main/zd_jsjm_jszi_" + _resultData.Star;
  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. }
  94. else
  95. {
  96. tf.font = "ui://Main/Font2";
  97. _ui.m_expBar.target.visible = true;
  98. _ui.m_btnClose.enabled = false;
  99. //过关
  100. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(_levelCfg.fightID);
  101. _ui.m_expBar.m_txtLvlAdded.text = "" + fightCfg.exp;
  102. Timers.inst.Add(0.5f, 1, this.AddExp);
  103. }
  104. _ui.m_txtScore.textFormat = tf;
  105. _ui.m_t0.SetValue("posY", 33, this.viewCom.height - 235);
  106. _ui.m_t0.Play();
  107. }
  108. protected override void OnHide()
  109. {
  110. base.OnHide();
  111. Timers.inst.Remove(AddExp);
  112. if (_sceneObject != null)
  113. {
  114. GameObject.Destroy(_sceneObject);
  115. _sceneObject = null;
  116. }
  117. }
  118. private void OnClickBtnClose(object param)
  119. {
  120. this.Hide();
  121. if (_levelCfg.type == ConstInstanceZonesType.Field)
  122. {
  123. _ui.m_c1.selectedIndex = 1;
  124. Timers.inst.Remove(OnClickBtnClose);
  125. ViewManager.Show<FieldView>();
  126. ViewManager.Show<FieldFightInfoView>();
  127. }
  128. else
  129. {
  130. InstanceZonesController.OnFinishStoryLevel(InstanceZonesDataManager.currentLevelCfgId, _resultData.FirstPass, true);
  131. //尝试显示奖励
  132. BonusController.TryShowBonusList(_resultData.BonusList);
  133. }
  134. InstanceZonesDataManager.currentCardId = -1;
  135. }
  136. private void AddExp(object param)
  137. {
  138. int lv = GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl);
  139. _ui.m_expBar.m_txtLvl.text = lv.ToString();
  140. float exp = GameGlobal.myNumericComponent.GetAsInt(NumericType.Exp);
  141. float cfgExp = RoleLevelCfgArray.Instance.GetCfg(lv).exp;
  142. float initWidth = _ui.m_expBar.m_pbExp.m_bar.target.initWidth;
  143. float curWidth = _ui.m_expBar.m_pbExp.m_bar.target.width;
  144. float width = exp / cfgExp * initWidth;
  145. if (width <= curWidth)
  146. {
  147. _ui.m_expBar.m_pbExp.m_bar.target.width = 0;
  148. }
  149. 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) =>
  150. {
  151. _ui.m_expBar.m_pbExp.m_bar.target.width = t.value.x;
  152. }); ;
  153. // _ui.m_expBar.m_pbExp..TweenValue(exp, 0.2f);
  154. _ui.m_btnClose.enabled = true;
  155. }
  156. protected override void UpdateToCheckGuide(object param)
  157. {
  158. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  159. if (!_resultData.Result) GuideController.TryGuide(null, ConstGuideId.FIRST_FIGHT_FAILED, 1, "不要气馁呀,可以通过再次挑战已通关的关卡、摘星、绣坊等途径获取更多的物资来提升自己的战斗力哦!", -1, true, (int)(this.viewCom.height - 150));
  160. if (_resultData.Result) GuideController.TryGuide(null, ConstGuideId.FIRST_FIGHT_SINGLE_WIN, 1, "这条连衣裙可真好看!点击空白区域继续", -1, true, (int)(this.viewCom.height - 400));
  161. if (_resultData.Result) GuideController.TryGuide(null, ConstGuideId.FIRST_FIGHT_TARGET_WIN, 1, "你太厉害了,初次对战就获得了这么好的战绩,继续加油吧", -1, true, (int)(this.viewCom.height - 400));
  162. }
  163. protected override void TryCompleteGuide()
  164. {
  165. GuideCfg cfg;
  166. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.FIRST_FIGHT_FAILED);
  167. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  168. GuideController.TryCompleteGuide(ConstGuideId.FIRST_FIGHT_FAILED, 1);
  169. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.FIRST_FIGHT_SINGLE_WIN);
  170. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  171. GuideController.TryCompleteGuide(ConstGuideId.FIRST_FIGHT_SINGLE_WIN, 1);
  172. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.FIRST_FIGHT_TARGET_WIN);
  173. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  174. GuideController.TryCompleteGuide(ConstGuideId.FIRST_FIGHT_TARGET_WIN, 1);
  175. }
  176. }
  177. }