TravelView.cs 7.0 KB

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