TravelView.cs 8.7 KB

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