FieldGuideView.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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>(null, new object[] { typeof(FieldGuideView).FullName, this.viewData });
  121. break;
  122. case ConstFieldGuideId.CHAPTER_ITEM:
  123. ViewManager.Show<ChapterItemGuideView>(null, new object[] { typeof(FieldGuideView).FullName, this.viewData });
  124. break;
  125. case ConstFieldGuideId.TRAVEL_GUIDE:
  126. ViewManager.Show<TravelGuideView>(null, new object[] { typeof(FieldGuideView).FullName, this.viewData });
  127. break;
  128. case ConstFieldGuideId.DRESS_UP_GUIDE:
  129. ViewManager.Show<DressUpGuideView>(null, new object[] { typeof(FieldGuideView).FullName, this.viewData });
  130. break;
  131. case ConstFieldGuideId.CARD_GUIDE:
  132. bool open = FunctionOpenDataManager.Instance.CheckIsFunOpenById(typeof(CardDetailView).Name, false);
  133. if (open)
  134. {
  135. ViewManager.Show<CardGuideView>(null, new object[] { typeof(FieldGuideView).FullName, this.viewData });
  136. }
  137. else
  138. {
  139. PromptController.Instance.ShowFloatTextPrompt("´Ë¹¦ÄÜ먦Æô~");
  140. }
  141. break;
  142. }
  143. }
  144. private void GetGuideProgress(int id, out int haveCount, out int totalCount)
  145. {
  146. switch (id)
  147. {
  148. case ConstFieldGuideId.SUIT_GUIDE:
  149. DressUpMenuSuitDataManager.GetTotalProgress(out haveCount, out totalCount);
  150. break;
  151. case ConstFieldGuideId.CHAPTER_ITEM:
  152. InstanceZonesDataManager.GetTotalProgress(out haveCount, out totalCount);
  153. break;
  154. case ConstFieldGuideId.TRAVEL_GUIDE:
  155. TravelDataManager.Instance.GetTotalTravelProgress(out haveCount, out totalCount);
  156. break;
  157. case ConstFieldGuideId.CARD_GUIDE:
  158. CardDataManager.GetTotalProgress(out haveCount, out totalCount);
  159. break;
  160. case ConstFieldGuideId.DRESS_UP_GUIDE:
  161. DressUpMenuItemDataManager.GetTotalProgress(out haveCount, out totalCount);
  162. break;
  163. default:
  164. haveCount = 0;
  165. totalCount = 1;
  166. break;
  167. }
  168. if (totalCount == 0) totalCount = 1;
  169. }
  170. private IEnumerator UpdatePrgress()
  171. {
  172. int num = _ui.m_listGuide.numChildren;
  173. bool playAnim = _startInAnim;
  174. _startInAnim = false;
  175. for (int i = 0; i < num; i++)
  176. {
  177. UI_CompGuideItem listItem = UI_CompGuideItem.Proxy(_ui.m_listGuide.GetChildAt(i));
  178. int id = (int)listItem.target.data;
  179. GetGuideProgress(id, out int haveCount, out int totalCount);
  180. decimal value = ProgressCalculate(haveCount, totalCount);
  181. listItem.m_txtProgress.text = value.ToString();
  182. if (playAnim)
  183. {
  184. Action complete = null;
  185. if (i == num - 1)
  186. {
  187. complete = UpdateRedDot;
  188. }
  189. if(i > 0)
  190. {
  191. yield return new WaitForSeconds(0.07f);
  192. }
  193. listItem.m_In.Play(() =>
  194. {
  195. complete?.Invoke();
  196. });
  197. }
  198. UI_CompGuideItem.ProxyEnd();
  199. }
  200. if (!playAnim)
  201. {
  202. UpdateRedDot();
  203. }
  204. }
  205. public static int ProgressCalculate(int haveCount, int totalCount)
  206. {
  207. if(haveCount > totalCount)
  208. {
  209. haveCount = totalCount;
  210. }
  211. float rate = haveCount * 100.0f / totalCount;
  212. int result;
  213. if (rate > 0 && rate <= 1)
  214. {
  215. result = 1;
  216. }
  217. else if (rate >= 99 && rate < 100)
  218. {
  219. result = 99;
  220. }
  221. else
  222. {
  223. result = (int)Math.Round(rate);
  224. }
  225. return result;
  226. }
  227. }
  228. }