FieldGuideView.cs 8.6 KB

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