FieldGuideView.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. using FairyGUI;
  2. using UI.FieldGuide;
  3. using System.Collections.Generic;
  4. using System;
  5. namespace GFGGame
  6. {
  7. public class FieldGuideView : BaseWindow
  8. {
  9. private delegate bool GetRedCall();
  10. private UI_FieldGuideUI _ui;
  11. private int[] _listBannerDatas = new int[3] { ConstBannerId.ZHAI_XING, ConstBannerId.ZHAI_XING, ConstBannerId.ZHAI_XING };
  12. private int[] _listGuideDatas = new int[5] { ConstFieldGuideId.SUIT_GUIDE, ConstFieldGuideId.CHAPTER_ITEM, ConstFieldGuideId.DRESS_UP_GUIDE, ConstFieldGuideId.CARD_GUIDE, ConstFieldGuideId.TRAVEL_GUIDE };
  13. GetRedCall[] actions = new GetRedCall[] { RedDotDataManager.Instance.GetFieldGuideRed, null, null, null, RedDotDataManager.Instance.GetTravelGuideRed };
  14. public override void Dispose()
  15. {
  16. if (_ui != null)
  17. {
  18. _ui.Dispose();
  19. _ui = null;
  20. }
  21. base.Dispose();
  22. }
  23. protected override void OnInit()
  24. {
  25. base.OnInit();
  26. packageName = UI_FieldGuideUI.PACKAGE_NAME;
  27. _ui = UI_FieldGuideUI.Create();
  28. this.viewCom = _ui.target;
  29. isfullScreen = true;
  30. _ui.m_listGuide.itemRenderer = ListGuideItemRenderer;
  31. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  32. _ui.m_listGuide.onClickItem.Add(OnClickListGuideItem);
  33. }
  34. protected override void AddEventListener()
  35. {
  36. EventAgent.AddEventListener(ConstMessage.SUIT_GUIDE_BOX_BONUS, UpdateList);
  37. EventAgent.AddEventListener(ConstMessage.JUMP_TO_SOURCE, this.Hide);
  38. }
  39. protected override void OnShown()
  40. {
  41. base.OnShown();
  42. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("tjbg");
  43. _ui.m_listGuide.numItems = _listGuideDatas.Length;
  44. UpdatePrgress();
  45. }
  46. protected override void OnHide()
  47. {
  48. base.OnHide();
  49. }
  50. protected override void RemoveEventListener()
  51. {
  52. base.RemoveEventListener();
  53. EventAgent.RemoveEventListener(ConstMessage.SUIT_GUIDE_BOX_BONUS, UpdateList);
  54. EventAgent.RemoveEventListener(ConstMessage.JUMP_TO_SOURCE, this.Hide);
  55. }
  56. private void OnClickBtnBack()
  57. {
  58. // this.Hide();
  59. _ui.m_listGuide.scrollPane.ScrollTop();
  60. ViewManager.GoBackFrom(ViewName.FIELD_GUIDE_VIEW);
  61. }
  62. private void UpdateList()
  63. {
  64. _ui.m_listGuide.numItems = _listGuideDatas.Length;
  65. }
  66. private void ListBannerItemRenderer(int index, GObject item)
  67. {
  68. UI_ButtonBannerPage listItem = UI_ButtonBannerPage.Proxy(item);
  69. int id = _listBannerDatas[index];
  70. listItem.target.data = id;
  71. UI_ButtonBannerPage.ProxyEnd();
  72. }
  73. private void ListGuideItemRenderer(int index, GObject item)
  74. {
  75. UI_CompGuideItem listItem = UI_CompGuideItem.Proxy(item);
  76. int id = _listGuideDatas[index];
  77. listItem.m_loaderPic.url = "ui://FieldGuide/tujian_tup_" + id;
  78. listItem.target.data = id;
  79. bool red = actions[index] == null ? false : actions[index]();
  80. RedDotController.Instance.SetComRedDot(listItem.target, red, "", -46, 51);
  81. UI_CompGuideItem.ProxyEnd();
  82. }
  83. private void OnClickListGuideItem(EventContext context)
  84. {
  85. GObject listItem = context.data as GObject;
  86. int id = (int)listItem.data;
  87. switch (id)
  88. {
  89. case ConstFieldGuideId.SUIT_GUIDE:
  90. ViewManager.Show<SuitGuideView>(null, new object[] { ViewName.FIELD_GUIDE_VIEW, this.viewData });
  91. break;
  92. case ConstFieldGuideId.CHAPTER_ITEM:
  93. ViewManager.Show<ChapterItemGuideView>(null, new object[] { ViewName.FIELD_GUIDE_VIEW, this.viewData });
  94. break;
  95. case ConstFieldGuideId.TRAVEL_GUIDE:
  96. ViewManager.Show<TravelGuideView>(null, new object[] { ViewName.FIELD_GUIDE_VIEW, this.viewData });
  97. break;
  98. case ConstFieldGuideId.DRESS_UP_GUIDE:
  99. ViewManager.Show<DressUpGuideView>(null, new object[] { ViewName.FIELD_GUIDE_VIEW, this.viewData });
  100. break;
  101. case ConstFieldGuideId.CARD_GUIDE:
  102. ViewManager.Show<CardGuideView>(null, new object[] { ViewName.FIELD_GUIDE_VIEW, this.viewData });
  103. break;
  104. }
  105. }
  106. private void GetGuideProgress(int id, out int haveCount, out int totalCount)
  107. {
  108. switch (id)
  109. {
  110. case ConstFieldGuideId.SUIT_GUIDE:
  111. DressUpMenuSuitDataManager.GetTotalProgress(out haveCount, out totalCount);
  112. break;
  113. case ConstFieldGuideId.CHAPTER_ITEM:
  114. InstanceZonesDataManager.GetTotalProgress(out haveCount, out totalCount);
  115. break;
  116. case ConstFieldGuideId.TRAVEL_GUIDE:
  117. TravelDataManager.Instance.GetTotalTravelProgress(out haveCount, out totalCount);
  118. break;
  119. case ConstFieldGuideId.CARD_GUIDE:
  120. CardDataManager.GetTotalProgress(out haveCount, out totalCount);
  121. break;
  122. case ConstFieldGuideId.DRESS_UP_GUIDE:
  123. DressUpMenuItemDataManager.GetTotalProgress(out haveCount, out totalCount);
  124. break;
  125. default:
  126. haveCount = 0;
  127. totalCount = 1;
  128. break;
  129. }
  130. if (totalCount == 0) totalCount = 1;
  131. }
  132. private void UpdatePrgress()
  133. {
  134. int num = _ui.m_listGuide.numChildren;
  135. for (int i = 0; i < num; i++)
  136. {
  137. UI_CompGuideItem listItem = UI_CompGuideItem.Proxy(_ui.m_listGuide.GetChildAt(i));
  138. int id = (int)listItem.target.data;
  139. int haveCount = 0;
  140. int totalCount = 1;
  141. GetGuideProgress(id, out haveCount, out totalCount);
  142. decimal value = ProgressCalculate(haveCount, totalCount);
  143. listItem.m_txtProgress.text = value.ToString();
  144. UI_CompGuideItem.ProxyEnd();
  145. }
  146. }
  147. public static int ProgressCalculate(int haveCount, int totalCount)
  148. {
  149. float rate = haveCount * 100.0f / totalCount;
  150. int result = 0;
  151. if(rate > 0 && rate <= 1)
  152. {
  153. result = 1;
  154. }
  155. else if(rate >= 99 && rate < 100)
  156. {
  157. result = 99;
  158. }
  159. else
  160. {
  161. result = (int)Math.Round(rate);
  162. }
  163. return result;
  164. }
  165. }
  166. }