TravelView.cs 7.5 KB

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