FieldGuideView.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. 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. _ui.m_listGuide.itemRenderer = ListGuideItemRenderer;
  33. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  34. _ui.m_listGuide.onClickItem.Add(OnClickListGuideItem);
  35. }
  36. protected override void AddEventListener()
  37. {
  38. EventAgent.AddEventListener(ConstMessage.SUIT_GUIDE_BOX_BONUS, UpdateList);
  39. EventAgent.AddEventListener(ConstMessage.JUMP_TO_SOURCE, this.Hide);
  40. }
  41. protected override void OnShown()
  42. {
  43. base.OnShown();
  44. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("tjbg");
  45. _ui.m_listGuide.numItems = _listGuideDatas.Length;
  46. _ui.m_openViewAction.Play();
  47. Timers.inst.StartCoroutine(UpdatePrgress());
  48. }
  49. protected override void OnHide()
  50. {
  51. base.OnHide();
  52. }
  53. protected override void RemoveEventListener()
  54. {
  55. base.RemoveEventListener();
  56. EventAgent.RemoveEventListener(ConstMessage.SUIT_GUIDE_BOX_BONUS, UpdateList);
  57. EventAgent.RemoveEventListener(ConstMessage.JUMP_TO_SOURCE, this.Hide);
  58. }
  59. private void OnClickBtnBack()
  60. {
  61. // this.Hide();
  62. _ui.m_listGuide.scrollPane.ScrollTop();
  63. ViewManager.GoBackFrom(ViewName.FIELD_GUIDE_VIEW);
  64. }
  65. private void UpdateList()
  66. {
  67. _ui.m_listGuide.numItems = _listGuideDatas.Length;
  68. }
  69. private void ListBannerItemRenderer(int index, GObject item)
  70. {
  71. UI_ButtonBannerPage listItem = UI_ButtonBannerPage.Proxy(item);
  72. int id = _listBannerDatas[index];
  73. listItem.target.data = id;
  74. UI_ButtonBannerPage.ProxyEnd();
  75. }
  76. private void ListGuideItemRenderer(int index, GObject item)
  77. {
  78. UI_CompGuideItem listItem = UI_CompGuideItem.Proxy(item);
  79. int id = _listGuideDatas[index];
  80. listItem.m_loaderPic.url = "ui://FieldGuide/tujian_tup_" + id;
  81. listItem.target.data = id;
  82. bool red = actions[index] == null ? false : actions[index]();
  83. RedDotController.Instance.SetComRedDot(listItem.target, red, "", -46, 51);
  84. listItem.m_Init.Play();
  85. UI_CompGuideItem.ProxyEnd();
  86. }
  87. private void OnClickListGuideItem(EventContext context)
  88. {
  89. GObject listItem = context.data as GObject;
  90. int id = (int)listItem.data;
  91. switch (id)
  92. {
  93. case ConstFieldGuideId.SUIT_GUIDE:
  94. ViewManager.Show<SuitGuideView>(null, new object[] { ViewName.FIELD_GUIDE_VIEW, this.viewData });
  95. break;
  96. case ConstFieldGuideId.CHAPTER_ITEM:
  97. ViewManager.Show<ChapterItemGuideView>(null, new object[] { ViewName.FIELD_GUIDE_VIEW, this.viewData });
  98. break;
  99. case ConstFieldGuideId.TRAVEL_GUIDE:
  100. ViewManager.Show<TravelGuideView>(null, new object[] { ViewName.FIELD_GUIDE_VIEW, this.viewData });
  101. break;
  102. case ConstFieldGuideId.DRESS_UP_GUIDE:
  103. ViewManager.Show<DressUpGuideView>(null, new object[] { ViewName.FIELD_GUIDE_VIEW, this.viewData });
  104. break;
  105. case ConstFieldGuideId.CARD_GUIDE:
  106. ViewManager.Show<CardGuideView>(null, new object[] { ViewName.FIELD_GUIDE_VIEW, this.viewData });
  107. break;
  108. }
  109. }
  110. private void GetGuideProgress(int id, out int haveCount, out int totalCount)
  111. {
  112. switch (id)
  113. {
  114. case ConstFieldGuideId.SUIT_GUIDE:
  115. DressUpMenuSuitDataManager.GetTotalProgress(out haveCount, out totalCount);
  116. break;
  117. case ConstFieldGuideId.CHAPTER_ITEM:
  118. InstanceZonesDataManager.GetTotalProgress(out haveCount, out totalCount);
  119. break;
  120. case ConstFieldGuideId.TRAVEL_GUIDE:
  121. TravelDataManager.Instance.GetTotalTravelProgress(out haveCount, out totalCount);
  122. break;
  123. case ConstFieldGuideId.CARD_GUIDE:
  124. CardDataManager.GetTotalProgress(out haveCount, out totalCount);
  125. break;
  126. case ConstFieldGuideId.DRESS_UP_GUIDE:
  127. DressUpMenuItemDataManager.GetTotalProgress(out haveCount, out totalCount);
  128. break;
  129. default:
  130. haveCount = 0;
  131. totalCount = 1;
  132. break;
  133. }
  134. if (totalCount == 0) totalCount = 1;
  135. }
  136. private IEnumerator UpdatePrgress()
  137. {
  138. int num = _ui.m_listGuide.numChildren;
  139. for (int i = 0; i < num; i++)
  140. {
  141. UI_CompGuideItem listItem = UI_CompGuideItem.Proxy(_ui.m_listGuide.GetChildAt(i));
  142. int id = (int)listItem.target.data;
  143. int haveCount = 0;
  144. int totalCount = 1;
  145. GetGuideProgress(id, out haveCount, out totalCount);
  146. decimal value = ProgressCalculate(haveCount, totalCount);
  147. listItem.m_txtProgress.text = value.ToString();
  148. listItem.m_In.Play();
  149. UI_CompGuideItem.ProxyEnd();
  150. yield return new WaitForSeconds(0.02f);
  151. }
  152. }
  153. public static int ProgressCalculate(int haveCount, int totalCount)
  154. {
  155. float rate = haveCount * 100.0f / totalCount;
  156. int result = 0;
  157. if (rate > 0 && rate <= 1)
  158. {
  159. result = 1;
  160. }
  161. else if (rate >= 99 && rate < 100)
  162. {
  163. result = 99;
  164. }
  165. else
  166. {
  167. result = (int)Math.Round(rate);
  168. }
  169. return result;
  170. }
  171. }
  172. }