FieldFightInfoView.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System.Linq;
  2. using cfg.GfgCfg;
  3. using FairyGUI;
  4. using UI.Field;
  5. using UnityEngine;
  6. namespace GFGGame
  7. {
  8. public class FieldFightInfoView : BaseWindow
  9. {
  10. private UI_FieldFightInfoUI _ui;
  11. // private StoryLevelCfg _storyLevelCfg;
  12. // private StoryFightCfg _storyFightCfg;
  13. private int _time = 3;
  14. public override void Dispose()
  15. {
  16. if (_ui != null)
  17. {
  18. _ui.Dispose();
  19. _ui = null;
  20. }
  21. base.Dispose();
  22. }
  23. protected override void OnInit()
  24. {
  25. base.OnInit();
  26. _ui = UI_FieldFightInfoUI.Create();
  27. this.viewCom = _ui.target;
  28. this.viewCom.Center();
  29. this.modal = true;
  30. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  31. this.clickBlankToClose = false;
  32. _ui.m_btnStop.onClick.Add(OnBtnStopClick);
  33. }
  34. protected override void OnShown()
  35. {
  36. base.OnShown();
  37. _time = 3;
  38. UpdateView();
  39. }
  40. private void UpdateView()
  41. {
  42. FieldDataManager dataManager = FieldDataManager.Instance;
  43. FieldCfg fieldCfg = CommonDataManager.Tables.TblFieldCfg.GetOrDefault(dataManager.chapterId);
  44. StoryLevelCfg storyLevelCfg = CommonDataManager.Tables.TblStoryLevelCfg.DataList
  45. .Where(a => a.Type == fieldCfg.Type &&
  46. a.SubType == 0 &&
  47. a.ChapterId == fieldCfg.Id).ToList()[dataManager.currFightLv];
  48. StoryFightCfg storyFightCfg =
  49. CommonDataManager.Tables.TblStoryFightCfg.GetOrDefault(int.Parse(storyLevelCfg.FightID));
  50. dataManager.currFightLv++;
  51. FieldFightDataManager.Instance.currentLevelCfgId = storyLevelCfg.Id;
  52. _ui.m_txtName.text = storyFightCfg.TargetName;
  53. _ui.m_txtDesc.text = storyLevelCfg.Desc;
  54. string num = StringUtil.GetColorText(string.Format("{0}/{1}", dataManager.currFightLv, fieldCfg.Num),
  55. "#BB674E");
  56. _ui.m_txtNum.text = string.Format("第{0}轮", num);
  57. _ui.m_loaNpc.url = ResPathUtil.GetNpcHeadPath(storyFightCfg.TargetRes);
  58. _ui.m_txtTime.text = string.Format("{0}秒后自动进入下一轮", _time);
  59. Timers.inst.Add(1, _time, OnTimerUpdate, 1);
  60. }
  61. private void OnTimerUpdate(object param)
  62. {
  63. _time -= (int)param;
  64. if (_time == 0)
  65. {
  66. Timers.inst.Remove(OnTimerUpdate);
  67. InstanceZonesDataManager.currentCardId = FieldFightDataManager.Instance.CurrentCardId;
  68. InstanceZonesDataManager.currentScoreType = FieldFightDataManager.Instance.CurrentScoreType;
  69. InstanceZonesDataManager.currentLevelCfgId = FieldFightDataManager.Instance.currentLevelCfgId;
  70. ViewManager.Show<StoryFightTargetView>(null, true);
  71. this.Hide();
  72. }
  73. _ui.m_txtTime.text = string.Format("{0}秒后自动进入下一轮", _time);
  74. }
  75. private void OnBtnStopClick()
  76. {
  77. Timers.inst.Remove(OnTimerUpdate);
  78. AlertUI.Show("确认中止本轮挑战?")
  79. .SetLeftButton(true, "取消", (object data) => { Timers.inst.Add(1, _time, OnTimerUpdate, 1); })
  80. .SetRightButton(true, "中止", async (object data) =>
  81. {
  82. this.Hide();
  83. bool result = await FieldSProxy.ReqFieldInstanceResult();
  84. if (result)
  85. {
  86. FieldDataManager.Instance.accumulateReward = 0;
  87. ViewManager.Show<FieldFightEndView>();
  88. }
  89. });
  90. }
  91. protected override void OnHide()
  92. {
  93. base.OnHide();
  94. }
  95. }
  96. }