FieldGuideView.cs 8.1 KB

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