TravelView.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. using ET;
  2. using FairyGUI;
  3. using System.Collections.Generic;
  4. using UI.Travel;
  5. using UnityEngine;
  6. namespace GFGGame
  7. {
  8. public class TravelView : BaseWindow
  9. {
  10. private UI_TravelUI _ui;
  11. private ValueBarController _valueBarController;
  12. private Dictionary<string, EffectUI> _effectUIDic = new Dictionary<string, EffectUI>();
  13. public override void Dispose()
  14. {
  15. // Clear Effect
  16. foreach (var v in _effectUIDic)
  17. {
  18. EffectUIPool.Recycle(v.Value);
  19. }
  20. _effectUIDic.Clear();
  21. if (_valueBarController != null)
  22. {
  23. _valueBarController.Dispose();
  24. _valueBarController = null;
  25. }
  26. if (_ui != null)
  27. {
  28. _ui.Dispose();
  29. _ui = null;
  30. }
  31. base.Dispose();
  32. }
  33. protected override void OnInit()
  34. {
  35. base.OnInit();
  36. packageName = UI_TravelUI.PACKAGE_NAME;
  37. _ui = UI_TravelUI.Create();
  38. this.viewCom = _ui.target;
  39. isfullScreen = true;
  40. isReturnView = true;
  41. _valueBarController = new ValueBarController(_ui.m_comValueBar);
  42. _ui.m_btnback.onClick.Add(OnBtnBackClick);
  43. // _ui.m_btnTips.onClick.Add(OnBtnTipsClick);
  44. _ui.m_btnGo.target.onClick.Add(OnBtnGoClick);
  45. _ui.m_btnGet.target.onClick.Add(OnBtnGetClick);
  46. _ui.m_btnPhoto.onClick.Add(OnBtnPhotoClick);
  47. _ui.m_btnFieldGuide.onClick.Add(OnBtnFieldGuideClick);
  48. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("cj_bg_ychm");
  49. _effectUIDic.Add("XQFS_Kuang_All", EffectUIPool.CreateEffectUI(_ui.m_bg_eff, "ui_HaiZhiShi", "XQFS_Kuang_All"));
  50. // 省略号特效
  51. _effectUIDic.Add("XQFS_Text_Loading", EffectUIPool.CreateEffectUI(_ui.m_txt_eff, "ui_HaiZhiShi", "XQFS_Text_Loading"));
  52. _effectUIDic.Add("XQFS_Button_YouLi", EffectUIPool.CreateEffectUI(_ui.m_btnGo.m_btnGo_eff, "ui_HaiZhiShi", "XQFS_Button_YouLi"));
  53. _effectUIDic.Add("XQFS_XinFeng_ComBack", EffectUIPool.CreateEffectUI(_ui.m_btnGet.m_btnGet_eff, "ui_HaiZhiShi", "XQFS_XinFeng_ComBack"));
  54. }
  55. protected override void AddEventListener()
  56. {
  57. base.AddEventListener();
  58. EventAgent.AddEventListener(ConstMessage.TRAVEL_STATE_CHANGE, UpdateView);
  59. }
  60. protected override void OnShown()
  61. {
  62. base.OnShown();
  63. _valueBarController.OnShown();
  64. // _valueBarController.Controller(7);
  65. UpdateView();
  66. Timers.inst.AddUpdate(CheckGuide);
  67. }
  68. protected override void OnHide()
  69. {
  70. base.OnHide();
  71. _valueBarController.OnHide();
  72. Timers.inst.Remove(UpdateTime);
  73. Timers.inst.Remove(CheckGuide);
  74. }
  75. protected override void RemoveEventListener()
  76. {
  77. base.RemoveEventListener();
  78. EventAgent.RemoveEventListener(ConstMessage.TRAVEL_STATE_CHANGE, UpdateView);
  79. }
  80. private void UpdateView()
  81. {
  82. _ui.m_c1.selectedIndex = TravelDataManager.Instance.TravelData?.Status ?? 0;
  83. if (_ui.m_c1.selectedIndex == (int)TravelGuideType.NoTravel)
  84. {
  85. ItemCfg cfg = ItemCfgArray.Instance.GetCfg(GlobalCfgArray.globalCfg.travelCostArr[0]);
  86. _ui.m_btnGo.m_loaIcon.url = ResPathUtil.GetCommonGameResPath(cfg.res);
  87. _ui.m_btnGo.m_txtCount.text = string.Format("{0}", GlobalCfgArray.globalCfg.travelCostArr[1]);
  88. }
  89. else if (_ui.m_c1.selectedIndex == (int)TravelGuideType.Travel)
  90. {
  91. long endTime = TravelDataManager.Instance.TravelData.EndTime;
  92. long curTime = TimeHelper.ServerNow();
  93. _ui.m_txtTime.text = "";
  94. int secCount = (int)((endTime - curTime) / 1000);
  95. UpdateTime(null);
  96. Timers.inst.Add(1, secCount + 2, UpdateTime);
  97. }
  98. }
  99. private void UpdateTime(object param)
  100. {
  101. long endTime = TravelDataManager.Instance.TravelData.EndTime;
  102. long curTime = TimeHelper.ServerNow();
  103. if (curTime >= endTime)
  104. {
  105. Timers.inst.Remove(UpdateTime);
  106. TravelDataManager.Instance.TravelData.Status = (int)TravelGuideType.TravelComplete;
  107. _ui.m_txtTime.text = "";
  108. UpdateView();
  109. }
  110. _ui.m_txtTime.text = string.Format("大约{0}后归来", TimeUtil.FormattingTime(curTime, endTime));
  111. }
  112. private void OnBtnBackClick()
  113. {
  114. ViewManager.GoBackFrom(typeof(TravelView).FullName);
  115. }
  116. // private void OnBtnTipsClick()
  117. // {
  118. // }
  119. private void OnBtnGoClick()
  120. {
  121. if (PoemPhotoDataManager.Instance.WsqsPhotoInfos.Count >= RoleDataManager.WanShuiQianShanMaxStorageCount)
  122. {
  123. PromptController.Instance.ShowFloatTextPrompt("明信片装不下了,先删除一些再去游历吧");
  124. return;
  125. }
  126. long hasCount = ItemDataManager.GetItemNum(GlobalCfgArray.globalCfg.travelCostArr[0]);
  127. if (hasCount < GlobalCfgArray.globalCfg.travelCostArr[1])
  128. {
  129. PromptController.Instance.ShowFloatTextPrompt("消耗不足");
  130. return;
  131. }
  132. ViewManager.Show<TravelDressupView>();
  133. }
  134. private void OnBtnGetClick()
  135. {
  136. ViewManager.Show<TravelRewardView>();
  137. }
  138. private void OnBtnPhotoClick()
  139. {
  140. ViewManager.Show<PoemPhotoView>(PictureSourceType.WanShuiQianShan);
  141. }
  142. private void OnBtnFieldGuideClick()
  143. {
  144. ViewManager.Show<TravelGuideView>();
  145. }
  146. private void CheckGuide(object param)
  147. {
  148. if (GuideDataManager.IsGuideFinish(ConstGuideId.TRAVEL) <= 0)
  149. {
  150. UpdateToCheckGuide(null);
  151. }
  152. else
  153. {
  154. Timers.inst.Remove(CheckGuide);
  155. }
  156. }
  157. protected override void UpdateToCheckGuide(object param)
  158. {
  159. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  160. GuideController.TryGuide(null, ConstGuideId.TRAVEL, 1, "四方关津已经打通,带上心仪的服饰,就可以外出游历啦!", -1, true,
  161. _ui.m_btnPhoto.y + _ui.m_btnPhoto.height + 100);
  162. GuideController.TryCompleteGuide(ConstGuideId.TRAVEL, 1);
  163. }
  164. }
  165. }