TravelView.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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_btnSpeedUp.onClick.Add(OnBtnSpeedUpClick);
  49. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("cj_bg_ychm");
  50. _effectUIDic.Add("XQFS_Kuang_All", EffectUIPool.CreateEffectUI(_ui.m_bg_eff, "ui_HaiZhiShi", "XQFS_Kuang_All"));
  51. _effectUIDic.Add("XQFS_DouBao01", EffectUIPool.CreateEffectUI(_ui.m_btnGo.m_btnGo_db_eff, "ui_HaiZhiShi", "XQFS_DouBao01"));
  52. _effectUIDic.Add("XQFS_DouBao_Loading", EffectUIPool.CreateEffectUI(_ui.m_db_loadingEff_holder, "ui_HaiZhiShi", "XQFS_DouBao_Loading"));
  53. // 省略号特效
  54. _effectUIDic.Add("XQFS_Text_Loading", EffectUIPool.CreateEffectUI(_ui.m_txt_eff, "ui_HaiZhiShi", "XQFS_Text_Loading"));
  55. _effectUIDic.Add("XQFS_Button_YouLi", EffectUIPool.CreateEffectUI(_ui.m_btnGo.m_btnGo_eff, "ui_HaiZhiShi", "XQFS_Button_YouLi"));
  56. _effectUIDic.Add("XQFS_XinFeng_ComBack", EffectUIPool.CreateEffectUI(_ui.m_btnGet.m_btnGet_eff, "ui_HaiZhiShi", "XQFS_XinFeng_ComBack"));
  57. }
  58. protected override void AddEventListener()
  59. {
  60. base.AddEventListener();
  61. EventAgent.AddEventListener(ConstMessage.TRAVEL_STATE_CHANGE, UpdateView);
  62. }
  63. protected override void OnShown()
  64. {
  65. base.OnShown();
  66. _valueBarController.OnShown();
  67. UpdateView();
  68. Timers.inst.AddUpdate(CheckGuide);
  69. }
  70. protected override void OnHide()
  71. {
  72. base.OnHide();
  73. _valueBarController.OnHide();
  74. Timers.inst.Remove(UpdateTime);
  75. Timers.inst.Remove(CheckGuide);
  76. }
  77. protected override void RemoveEventListener()
  78. {
  79. base.RemoveEventListener();
  80. EventAgent.RemoveEventListener(ConstMessage.TRAVEL_STATE_CHANGE, UpdateView);
  81. }
  82. private void UpdateView()
  83. {
  84. _ui.m_c1.selectedIndex = TravelDataManager.Instance.TravelData?.Status ?? 0;
  85. if (_ui.m_c1.selectedIndex == (int)TravelGuideType.NoTravel)
  86. {
  87. ItemCfg cfg = ItemCfgArray.Instance.GetCfg(GlobalCfgArray.globalCfg.travelCostArr[0]);
  88. _ui.m_btnGo.m_loaIcon.url = ResPathUtil.GetCommonGameResPath(cfg.res);
  89. _ui.m_btnGo.m_txtCount.text = string.Format("{0}", GlobalCfgArray.globalCfg.travelCostArr[1]);
  90. }
  91. else if (_ui.m_c1.selectedIndex == (int)TravelGuideType.Travel)
  92. {
  93. long endTime = TravelDataManager.Instance.TravelData.EndTime;
  94. long curTime = TimeHelper.ServerNow();
  95. _ui.m_txtTime.text = "";
  96. int secCount = (int)((endTime - curTime) / 1000);
  97. UpdateTime(null);
  98. Timers.inst.Add(1, secCount + 2, UpdateTime);
  99. }
  100. UpdateRedDots();
  101. }
  102. private void UpdateTime(object param)
  103. {
  104. long endTime = TravelDataManager.Instance.TravelData.EndTime;
  105. long curTime = TimeHelper.ServerNow();
  106. if (curTime >= endTime)
  107. {
  108. Timers.inst.Remove(UpdateTime);
  109. TravelDataManager.Instance.TravelData.Status = (int)TravelGuideType.TravelComplete;
  110. _ui.m_txtTime.text = "";
  111. UpdateView();
  112. }
  113. // 如果大于1分钟,则显示上少1s
  114. if(endTime - curTime > 60000)
  115. {
  116. endTime -= 1000;
  117. }
  118. _ui.m_txtTime.text = string.Format("大约{0}后归来", TimeUtil.FormattingTime(curTime, endTime));
  119. }
  120. private void OnBtnBackClick()
  121. {
  122. ViewManager.GoBackFrom(typeof(TravelView).FullName);
  123. }
  124. // private void OnBtnTipsClick()
  125. // {
  126. // }
  127. private void OnBtnGoClick()
  128. {
  129. if (PoemPhotoDataManager.Instance.WsqsPhotoInfos.Count >= RoleDataManager.WanShuiQianShanMaxStorageCount)
  130. {
  131. PromptController.Instance.ShowFloatTextPrompt("明信片装不下了,先删除一些再去游历吧");
  132. return;
  133. }
  134. long hasCount = ItemDataManager.GetItemNum(GlobalCfgArray.globalCfg.travelCostArr[0]);
  135. if (hasCount < GlobalCfgArray.globalCfg.travelCostArr[1])
  136. {
  137. PromptController.Instance.ShowFloatTextPrompt("消耗不足");
  138. return;
  139. }
  140. ViewManager.Show<TravelDressupView>();
  141. }
  142. private void OnBtnGetClick()
  143. {
  144. ViewManager.Show<TravelRewardView>();
  145. }
  146. private void OnBtnPhotoClick()
  147. {
  148. ViewManager.Show<PoemPhotoView>(PictureSourceType.WanShuiQianShan);
  149. }
  150. private void OnBtnFieldGuideClick()
  151. {
  152. ViewManager.Show<TravelGuideView>();
  153. }
  154. private void CheckGuide(object param)
  155. {
  156. if (GuideDataManager.IsGuideFinish(ConstGuideId.TRAVEL) <= 0)
  157. {
  158. UpdateToCheckGuide(null);
  159. }
  160. else
  161. {
  162. Timers.inst.Remove(CheckGuide);
  163. }
  164. }
  165. protected override void UpdateToCheckGuide(object param)
  166. {
  167. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  168. GuideController.TryGuide(null, ConstGuideId.TRAVEL, 1, "四方关津已经打通,带上心仪的服饰,就可以外出游历啦!", -1, true,
  169. _ui.m_btnPhoto.y + _ui.m_btnPhoto.height + 100);
  170. GuideController.TryCompleteGuide(ConstGuideId.TRAVEL, 1);
  171. }
  172. private void UpdateRedDots()
  173. {
  174. RedDotController.Instance.SetComRedDot(_ui.m_btnFieldGuide, RedDotDataManager.Instance.GetTravelGuideRed(), "", -15, 8);
  175. }
  176. private void OnBtnSpeedUpClick()
  177. {
  178. ViewManager.Show<TravelTimeDetailView>();
  179. }
  180. }
  181. }