TravelView.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. using ET;
  2. using FairyGUI;
  3. using UI.Travel;
  4. using UnityEngine;
  5. namespace GFGGame
  6. {
  7. public class TravelView : BaseWindow
  8. {
  9. private UI_TravelUI _ui;
  10. private ValueBarController _valueBarController;
  11. public override void Dispose()
  12. {
  13. if (_valueBarController != null)
  14. {
  15. _valueBarController.Dispose();
  16. _valueBarController = null;
  17. }
  18. if (_ui != null)
  19. {
  20. _ui.Dispose();
  21. _ui = null;
  22. }
  23. base.Dispose();
  24. }
  25. protected override void OnInit()
  26. {
  27. base.OnInit();
  28. packageName = UI_TravelUI.PACKAGE_NAME;
  29. _ui = UI_TravelUI.Create();
  30. this.viewCom = _ui.target;
  31. isfullScreen = true;
  32. _valueBarController = new ValueBarController(_ui.m_comValueBar);
  33. _ui.m_btnback.onClick.Add(OnBtnBackClick);
  34. // _ui.m_btnTips.onClick.Add(OnBtnTipsClick);
  35. _ui.m_btnGo.target.onClick.Add(OnBtnGoClick);
  36. _ui.m_btnGet.onClick.Add(OnBtnGetClick);
  37. _ui.m_btnPhoto.onClick.Add(OnBtnPhotoClick);
  38. _ui.m_btnFieldGuide.onClick.Add(OnBtnFieldGuideClick);
  39. }
  40. protected override void AddEventListener()
  41. {
  42. base.AddEventListener();
  43. EventAgent.AddEventListener(ConstMessage.TRAVEL_STATE_CHANGE, UpdateView);
  44. }
  45. protected override void OnShown()
  46. {
  47. base.OnShown();
  48. _valueBarController.OnShown();
  49. _valueBarController.Controller(7);
  50. UpdateView();
  51. }
  52. protected override void OnHide()
  53. {
  54. base.OnHide();
  55. _valueBarController.OnHide();
  56. Timers.inst.Remove(UpdateTime);
  57. }
  58. protected override void RemoveEventListener()
  59. {
  60. base.RemoveEventListener();
  61. EventAgent.RemoveEventListener(ConstMessage.TRAVEL_STATE_CHANGE, UpdateView);
  62. }
  63. private void UpdateView()
  64. {
  65. _ui.m_c1.selectedIndex = TravelDataManager.Instance.TravelData.Status;
  66. if (_ui.m_c1.selectedIndex == (int)TravelGuideType.NoTravel)
  67. {
  68. ItemCfg cfg = ItemCfgArray.Instance.GetCfg(GlobalCfgArray.globalCfg.travelCostArr[0]);
  69. _ui.m_btnGo.m_loaIcon.url = ResPathUtil.GetCommonGameResPath(cfg.res);
  70. _ui.m_btnGo.m_txtCount.text = string.Format("-{0}", GlobalCfgArray.globalCfg.travelCostArr[1]);
  71. }
  72. else if (_ui.m_c1.selectedIndex == (int)TravelGuideType.Travel)
  73. {
  74. int endTime = (int)(TravelDataManager.Instance.TravelData.CreationTime / 1000) + TravelDataManager.Instance.TravelData.TravelNeedHour * 5;// *
  75. int curTime = TimeHelper.ServerNowSecs;
  76. Timers.inst.Add(1, endTime - curTime + 1, UpdateTime);
  77. }
  78. }
  79. private void UpdateTime(object param)
  80. {
  81. int endTime = (int)(TravelDataManager.Instance.TravelData.CreationTime / 1000) + TravelDataManager.Instance.TravelData.TravelNeedHour * 5;// * TimeUtil.SECOND_PER_HOUR
  82. int curTime = TimeHelper.ServerNowSecs;
  83. if (curTime >= endTime)
  84. {
  85. Timers.inst.Remove(UpdateTime);
  86. TravelDataManager.Instance.TravelData.Status = (int)TravelGuideType.TravelComplete;
  87. UpdateView();
  88. }
  89. _ui.m_txtTime.text = string.Format("大约{0}后归来", TimeUtil.FormattingTime(curTime, endTime));
  90. }
  91. private void OnBtnBackClick()
  92. {
  93. ViewManager.GoBackFrom(typeof(TravelView).FullName);
  94. }
  95. // private void OnBtnTipsClick()
  96. // {
  97. // }
  98. private void OnBtnGoClick()
  99. {
  100. if (PoemPhotoDataManager.Instance.WsqsPhotoInfos.Count >= GlobalCfgArray.globalCfg.maxTravelCount)
  101. {
  102. PromptController.Instance.ShowFloatTextPrompt("明信片装不下了,先删除一些再去游历吧");
  103. return;
  104. }
  105. ViewManager.Show<TravelDressupView>(null, new object[] { typeof(TravelView).FullName, this.viewData });
  106. }
  107. private void OnBtnGetClick()
  108. {
  109. ViewManager.Show<TravelRewardView>(null, new object[] { typeof(TravelView).FullName, this.viewData });
  110. }
  111. private void OnBtnPhotoClick()
  112. {
  113. ViewManager.Show<PoemPhotoView>(PictureSourceType.WanShuiQianShan, new object[] { typeof(TravelView).FullName, this.viewData });
  114. }
  115. private void OnBtnFieldGuideClick()
  116. {
  117. ViewManager.Show<TravelGuideView>(null, new object[] { typeof(TravelView).FullName, this.viewData });
  118. }
  119. }
  120. }