FieldGuideView.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. // this.Hide();
  68. _startInAnim = true;
  69. ViewManager.GoBackFrom(ViewName.FIELD_GUIDE_VIEW);
  70. }
  71. private void UpdateList()
  72. {
  73. _ui.m_listGuide.numItems = _listGuideDatas.Length;
  74. }
  75. private void ListGuideItemRenderer(int index, GObject item)
  76. {
  77. UI_CompGuideItem listItem = UI_CompGuideItem.Proxy(item);
  78. int id = _listGuideDatas[index];
  79. listItem.m_loaderPic.url = "ui://FieldGuide/tujian_tup_" + id;
  80. listItem.target.data = id;
  81. bool red = actions[index] == null ? false : actions[index]();
  82. RedDotController.Instance.SetComRedDot(listItem.target, red, "", -46, 51);
  83. if (_startInAnim)
  84. {
  85. listItem.m_Init.Play();
  86. }
  87. UI_CompGuideItem.ProxyEnd();
  88. }
  89. private void OnClickListGuideItem(EventContext context)
  90. {
  91. GObject listItem = context.data as GObject;
  92. int id = (int)listItem.data;
  93. switch (id)
  94. {
  95. case ConstFieldGuideId.SUIT_GUIDE:
  96. ViewManager.Show<SuitGuideView>(null, new object[] { ViewName.FIELD_GUIDE_VIEW, this.viewData });
  97. break;
  98. case ConstFieldGuideId.CHAPTER_ITEM:
  99. ViewManager.Show<ChapterItemGuideView>(null, new object[] { ViewName.FIELD_GUIDE_VIEW, this.viewData });
  100. break;
  101. case ConstFieldGuideId.TRAVEL_GUIDE:
  102. ViewManager.Show<TravelGuideView>(null, new object[] { ViewName.FIELD_GUIDE_VIEW, this.viewData });
  103. break;
  104. case ConstFieldGuideId.DRESS_UP_GUIDE:
  105. ViewManager.Show<DressUpGuideView>(null, new object[] { ViewName.FIELD_GUIDE_VIEW, this.viewData });
  106. break;
  107. case ConstFieldGuideId.CARD_GUIDE:
  108. ViewManager.Show<CardGuideView>(null, new object[] { ViewName.FIELD_GUIDE_VIEW, this.viewData });
  109. break;
  110. }
  111. }
  112. private void GetGuideProgress(int id, out int haveCount, out int totalCount)
  113. {
  114. switch (id)
  115. {
  116. case ConstFieldGuideId.SUIT_GUIDE:
  117. DressUpMenuSuitDataManager.GetTotalProgress(out haveCount, out totalCount);
  118. break;
  119. case ConstFieldGuideId.CHAPTER_ITEM:
  120. InstanceZonesDataManager.GetTotalProgress(out haveCount, out totalCount);
  121. break;
  122. case ConstFieldGuideId.TRAVEL_GUIDE:
  123. TravelDataManager.Instance.GetTotalTravelProgress(out haveCount, out totalCount);
  124. break;
  125. case ConstFieldGuideId.CARD_GUIDE:
  126. CardDataManager.GetTotalProgress(out haveCount, out totalCount);
  127. break;
  128. case ConstFieldGuideId.DRESS_UP_GUIDE:
  129. DressUpMenuItemDataManager.GetTotalProgress(out haveCount, out totalCount);
  130. break;
  131. default:
  132. haveCount = 0;
  133. totalCount = 1;
  134. break;
  135. }
  136. if (totalCount == 0) totalCount = 1;
  137. }
  138. private IEnumerator UpdatePrgress()
  139. {
  140. int num = _ui.m_listGuide.numChildren;
  141. bool playAnim = _startInAnim;
  142. _startInAnim = false;
  143. for (int i = 0; i < num; i++)
  144. {
  145. UI_CompGuideItem listItem = UI_CompGuideItem.Proxy(_ui.m_listGuide.GetChildAt(i));
  146. int id = (int)listItem.target.data;
  147. int haveCount = 0;
  148. int totalCount = 1;
  149. GetGuideProgress(id, out haveCount, out totalCount);
  150. decimal value = ProgressCalculate(haveCount, totalCount);
  151. listItem.m_txtProgress.text = value.ToString();
  152. if (playAnim)
  153. {
  154. listItem.m_In.Play();
  155. // µ¹ÊýµÚ¶þ¸ö
  156. if (i == num - 2)
  157. {
  158. yield return new WaitForSeconds(0.02f);
  159. }
  160. else if (i < num - 2)
  161. {
  162. yield return new WaitForSeconds(0.05f);
  163. }
  164. }
  165. UI_CompGuideItem.ProxyEnd();
  166. }
  167. }
  168. public static int ProgressCalculate(int haveCount, int totalCount)
  169. {
  170. float rate = haveCount * 100.0f / totalCount;
  171. int result = 0;
  172. if (rate > 0 && rate <= 1)
  173. {
  174. result = 1;
  175. }
  176. else if (rate >= 99 && rate < 100)
  177. {
  178. result = 99;
  179. }
  180. else
  181. {
  182. result = (int)Math.Round(rate);
  183. }
  184. return result;
  185. }
  186. }
  187. }