FieldGuideView.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. using FairyGUI;
  2. using UI.FieldGuide;
  3. using System.Collections.Generic;
  4. using System;
  5. using System.Collections;
  6. using UnityEngine;
  7. namespace GFGGame
  8. {
  9. public class FieldGuideView : BaseWindow
  10. {
  11. private delegate bool GetRedCall();
  12. private UI_FieldGuideUI _ui;
  13. private int[] _listGuideDatas = new int[5] { ConstFieldGuideId.SUIT_GUIDE, ConstFieldGuideId.CHAPTER_ITEM, ConstFieldGuideId.DRESS_UP_GUIDE, ConstFieldGuideId.CARD_GUIDE, ConstFieldGuideId.TRAVEL_GUIDE };
  14. GetRedCall[] actions = new GetRedCall[] { RedDotDataManager.Instance.GetFieldGuideRed, null, null, null, RedDotDataManager.Instance.GetTravelGuideRed };
  15. private bool _startInAnim;
  16. public override void Dispose()
  17. {
  18. if (_ui != null)
  19. {
  20. _ui.Dispose();
  21. _ui = null;
  22. }
  23. base.Dispose();
  24. }
  25. protected override void OnInit()
  26. {
  27. base.OnInit();
  28. packageName = UI_FieldGuideUI.PACKAGE_NAME;
  29. _ui = UI_FieldGuideUI.Create();
  30. this.viewCom = _ui.target;
  31. isfullScreen = true;
  32. isReturnView = true;
  33. _startInAnim = true;
  34. _ui.m_listGuide.itemRenderer = ListGuideItemRenderer;
  35. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  36. _ui.m_listGuide.onClickItem.Add(OnClickListGuideItem);
  37. }
  38. protected override void AddEventListener()
  39. {
  40. EventAgent.AddEventListener(ConstMessage.SUIT_GUIDE_BOX_BONUS, UpdateList);
  41. EventAgent.AddEventListener(ConstMessage.JUMP_TO_SOURCE, this.Hide);
  42. }
  43. protected override void OnShown()
  44. {
  45. base.OnShown();
  46. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("tjbg");
  47. _ui.m_listGuide.numItems = _listGuideDatas.Length;
  48. if (_startInAnim)
  49. {
  50. _ui.m_listGuide.scrollPane.ScrollTop();
  51. _ui.m_In.Play();
  52. }
  53. Timers.inst.StartCoroutine(UpdatePrgress());
  54. }
  55. protected override void OnHide()
  56. {
  57. base.OnHide();
  58. }
  59. protected override void RemoveEventListener()
  60. {
  61. base.RemoveEventListener();
  62. EventAgent.RemoveEventListener(ConstMessage.SUIT_GUIDE_BOX_BONUS, UpdateList);
  63. EventAgent.RemoveEventListener(ConstMessage.JUMP_TO_SOURCE, this.Hide);
  64. }
  65. private void OnClickBtnBack()
  66. {
  67. _startInAnim = true;
  68. ViewManager.GoBackFrom(typeof(FieldGuideView).FullName);
  69. HideAllRedDot();
  70. }
  71. private void UpdateList()
  72. {
  73. _ui.m_listGuide.numItems = _listGuideDatas.Length;
  74. UpdateRedDot();
  75. }
  76. private void UpdateRedDot()
  77. {
  78. int num = _ui.m_listGuide.numChildren;
  79. for (int i = 0; i < num; i++)
  80. {
  81. UI_CompGuideItem listItem = UI_CompGuideItem.Proxy(_ui.m_listGuide.GetChildAt(i));
  82. bool red = actions[i] == null ? false : actions[i]();
  83. RedDotController.Instance.SetComRedDot(listItem.target, red, "", -46, 51);
  84. UI_CompGuideItem.ProxyEnd();
  85. }
  86. }
  87. private void HideAllRedDot()
  88. {
  89. int num = _ui.m_listGuide.numChildren;
  90. for (int i = 0; i < num; i++)
  91. {
  92. RedDotController.Instance.SetComRedDot(_ui.m_listGuide.GetChildAt(i).asCom, false);
  93. }
  94. }
  95. private void ListGuideItemRenderer(int index, GObject item)
  96. {
  97. UI_CompGuideItem listItem = UI_CompGuideItem.Proxy(item);
  98. int id = _listGuideDatas[index];
  99. listItem.m_loaderPic.url = "ui://FieldGuide/tujian_tup_" + id;
  100. listItem.target.data = id;
  101. if(id == ConstFieldGuideId.CARD_GUIDE)
  102. {
  103. bool open = FunctionOpenDataManager.Instance.CheckIsFunOpenById(typeof(CardDetailView).Name, false);
  104. listItem.m_lock.visible = !open;
  105. listItem.m_progressGroup.visible = open;
  106. }
  107. if (_startInAnim)
  108. {
  109. listItem.m_Init.Play();
  110. }
  111. UI_CompGuideItem.ProxyEnd();
  112. }
  113. private void OnClickListGuideItem(EventContext context)
  114. {
  115. GObject listItem = context.data as GObject;
  116. int id = (int)listItem.data;
  117. switch (id)
  118. {
  119. case ConstFieldGuideId.SUIT_GUIDE:
  120. ViewManager.Show<SuitGuideView>();
  121. break;
  122. case ConstFieldGuideId.CHAPTER_ITEM:
  123. ViewManager.Show<ChapterItemGuideView>();
  124. break;
  125. case ConstFieldGuideId.TRAVEL_GUIDE:
  126. ViewManager.Show<TravelGuideView>();
  127. ViewManager.Show<TravelGuideView>();
  128. break;
  129. case ConstFieldGuideId.DRESS_UP_GUIDE:
  130. ViewManager.Show<DressUpGuideView>();
  131. break;
  132. case ConstFieldGuideId.CARD_GUIDE:
  133. bool open = FunctionOpenDataManager.Instance.CheckIsFunOpenById(typeof(CardDetailView).Name, false);
  134. if (open)
  135. {
  136. ViewManager.Show<CardGuideView>();
  137. }
  138. else
  139. {
  140. PromptController.Instance.ShowFloatTextPrompt("´Ë¹¦ÄÜ먦Æô~");
  141. }
  142. break;
  143. }
  144. }
  145. private void GetGuideProgress(int id, out int haveCount, out int totalCount)
  146. {
  147. switch (id)
  148. {
  149. case ConstFieldGuideId.SUIT_GUIDE:
  150. DressUpMenuSuitDataManager.GetTotalProgress(out haveCount, out totalCount);
  151. break;
  152. case ConstFieldGuideId.CHAPTER_ITEM:
  153. InstanceZonesDataManager.GetTotalProgress(out haveCount, out totalCount);
  154. break;
  155. case ConstFieldGuideId.TRAVEL_GUIDE:
  156. TravelDataManager.Instance.GetTotalTravelProgress(out haveCount, out totalCount);
  157. break;
  158. case ConstFieldGuideId.CARD_GUIDE:
  159. CardDataManager.GetTotalProgress(out haveCount, out totalCount);
  160. break;
  161. case ConstFieldGuideId.DRESS_UP_GUIDE:
  162. DressUpMenuItemDataManager.GetTotalProgress(out haveCount, out totalCount);
  163. break;
  164. default:
  165. haveCount = 0;
  166. totalCount = 1;
  167. break;
  168. }
  169. if (totalCount == 0) totalCount = 1;
  170. }
  171. private IEnumerator UpdatePrgress()
  172. {
  173. int num = _ui.m_listGuide.numChildren;
  174. bool playAnim = _startInAnim;
  175. _startInAnim = false;
  176. for (int i = 0; i < num; i++)
  177. {
  178. UI_CompGuideItem listItem = UI_CompGuideItem.Proxy(_ui.m_listGuide.GetChildAt(i));
  179. int id = (int)listItem.target.data;
  180. GetGuideProgress(id, out int haveCount, out int totalCount);
  181. decimal value = ProgressCalculate(haveCount, totalCount);
  182. listItem.m_txtProgress.text = value.ToString();
  183. if (playAnim)
  184. {
  185. Action complete = null;
  186. if (i == num - 1)
  187. {
  188. complete = UpdateRedDot;
  189. }
  190. if(i > 0)
  191. {
  192. yield return new WaitForSeconds(0.07f);
  193. }
  194. listItem.m_In.Play(() =>
  195. {
  196. complete?.Invoke();
  197. });
  198. }
  199. UI_CompGuideItem.ProxyEnd();
  200. }
  201. if (!playAnim)
  202. {
  203. UpdateRedDot();
  204. }
  205. }
  206. public static int ProgressCalculate(int haveCount, int totalCount)
  207. {
  208. if(haveCount > totalCount)
  209. {
  210. haveCount = totalCount;
  211. }
  212. float rate = haveCount * 100.0f / totalCount;
  213. int result;
  214. if (rate > 0 && rate <= 1)
  215. {
  216. result = 1;
  217. }
  218. else if (rate >= 99 && rate < 100)
  219. {
  220. result = 99;
  221. }
  222. else
  223. {
  224. result = (int)Math.Round(rate);
  225. }
  226. return result;
  227. }
  228. }
  229. }