FieldGuideView.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 (_startInAnim)
  101. {
  102. listItem.m_Init.Play();
  103. }
  104. UI_CompGuideItem.ProxyEnd();
  105. }
  106. private void OnClickListGuideItem(EventContext context)
  107. {
  108. GObject listItem = context.data as GObject;
  109. int id = (int)listItem.data;
  110. switch (id)
  111. {
  112. case ConstFieldGuideId.SUIT_GUIDE:
  113. ViewManager.Show<SuitGuideView>(null, new object[] { typeof(FieldGuideView).FullName, this.viewData });
  114. break;
  115. case ConstFieldGuideId.CHAPTER_ITEM:
  116. ViewManager.Show<ChapterItemGuideView>(null, new object[] { typeof(FieldGuideView).FullName, this.viewData });
  117. break;
  118. case ConstFieldGuideId.TRAVEL_GUIDE:
  119. ViewManager.Show<TravelGuideView>(null, new object[] { typeof(FieldGuideView).FullName, this.viewData });
  120. break;
  121. case ConstFieldGuideId.DRESS_UP_GUIDE:
  122. ViewManager.Show<DressUpGuideView>(null, new object[] { typeof(FieldGuideView).FullName, this.viewData });
  123. break;
  124. case ConstFieldGuideId.CARD_GUIDE:
  125. ViewManager.Show<CardGuideView>(null, new object[] { typeof(FieldGuideView).FullName, this.viewData });
  126. break;
  127. }
  128. }
  129. private void GetGuideProgress(int id, out int haveCount, out int totalCount)
  130. {
  131. switch (id)
  132. {
  133. case ConstFieldGuideId.SUIT_GUIDE:
  134. DressUpMenuSuitDataManager.GetTotalProgress(out haveCount, out totalCount);
  135. break;
  136. case ConstFieldGuideId.CHAPTER_ITEM:
  137. InstanceZonesDataManager.GetTotalProgress(out haveCount, out totalCount);
  138. break;
  139. case ConstFieldGuideId.TRAVEL_GUIDE:
  140. TravelDataManager.Instance.GetTotalTravelProgress(out haveCount, out totalCount);
  141. break;
  142. case ConstFieldGuideId.CARD_GUIDE:
  143. CardDataManager.GetTotalProgress(out haveCount, out totalCount);
  144. break;
  145. case ConstFieldGuideId.DRESS_UP_GUIDE:
  146. DressUpMenuItemDataManager.GetTotalProgress(out haveCount, out totalCount);
  147. break;
  148. default:
  149. haveCount = 0;
  150. totalCount = 1;
  151. break;
  152. }
  153. if (totalCount == 0) totalCount = 1;
  154. }
  155. private IEnumerator UpdatePrgress()
  156. {
  157. int num = _ui.m_listGuide.numChildren;
  158. bool playAnim = _startInAnim;
  159. _startInAnim = false;
  160. for (int i = 0; i < num; i++)
  161. {
  162. UI_CompGuideItem listItem = UI_CompGuideItem.Proxy(_ui.m_listGuide.GetChildAt(i));
  163. int id = (int)listItem.target.data;
  164. GetGuideProgress(id, out int haveCount, out int totalCount);
  165. decimal value = ProgressCalculate(haveCount, totalCount);
  166. listItem.m_txtProgress.text = value.ToString();
  167. if (playAnim)
  168. {
  169. Action complete = null;
  170. // µ¹ÊýµÚ¶þ¸ö
  171. if (i == num - 1)
  172. {
  173. yield return new WaitForSeconds(0.03f);
  174. complete = UpdateRedDot;
  175. }
  176. else if(i > 0)
  177. {
  178. yield return new WaitForSeconds(0.06f);
  179. }
  180. listItem.m_In.Play(() =>
  181. {
  182. complete?.Invoke();
  183. });
  184. }
  185. UI_CompGuideItem.ProxyEnd();
  186. }
  187. }
  188. public static int ProgressCalculate(int haveCount, int totalCount)
  189. {
  190. float rate = haveCount * 100.0f / totalCount;
  191. int result = 0;
  192. if (rate > 0 && rate <= 1)
  193. {
  194. result = 1;
  195. }
  196. else if (rate >= 99 && rate < 100)
  197. {
  198. result = 99;
  199. }
  200. else
  201. {
  202. result = (int)Math.Round(rate);
  203. }
  204. return result;
  205. }
  206. }
  207. }