FieldGuideView.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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[3] { ConstFieldGuideId.SUIT_GUIDE, ConstFieldGuideId.CHAPTER_ITEM, ConstFieldGuideId.TRAVEL_GUIDE };
  13. GetRedCall[] actions = new GetRedCall[] { RedDotDataManager.Instance.GetFieldGuideRed, null };
  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_compBanner.m_listTab.itemRenderer = ListBannerItemRenderer;
  31. _ui.m_compBanner.m_listTab.numItems = _listBannerDatas.Length;
  32. _ui.m_listGuide.itemRenderer = ListGuideItemRenderer;
  33. // _ui.m_listGuide.numItems = _listGuideDatas.Length;
  34. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  35. _ui.m_listGuide.onClickItem.Add(OnClickListGuideItem);
  36. _ui.m_compBanner.m_listTab.onClickItem.Add(OnClickListBannerItem);
  37. _ui.m_compBanner.m_loaderPic.onClick.Add(OnClickBannerPic);
  38. }
  39. protected override void AddEventListener()
  40. {
  41. EventAgent.AddEventListener(ConstMessage.SUIT_GUIDE_BOX_BONUS, UpdateList);
  42. EventAgent.AddEventListener(ConstMessage.JUMP_TO_SOURCE, this.Hide);
  43. }
  44. protected override void OnShown()
  45. {
  46. base.OnShown();
  47. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("fuben_bjbj");
  48. _ui.m_listGuide.numItems = _listGuideDatas.Length;
  49. UpdatePrgress();
  50. _ui.m_compBanner.m_listTab.selectedIndex = 0;
  51. UpdateBanner(_ui.m_compBanner.m_listTab.GetChildAt(_ui.m_compBanner.m_listTab.selectedIndex));
  52. Timers.inst.Add(3, 0, SwitchBannerPic);
  53. }
  54. protected override void OnHide()
  55. {
  56. base.OnHide();
  57. Timers.inst.Remove(SwitchBannerPic);
  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. ViewManager.GoBackFrom(ViewName.FIELD_GUIDE_VIEW);
  69. }
  70. private void UpdateList()
  71. {
  72. _ui.m_listGuide.numItems = _listGuideDatas.Length;
  73. }
  74. private void ListBannerItemRenderer(int index, GObject item)
  75. {
  76. UI_ButtonBannerPage listItem = UI_ButtonBannerPage.Proxy(item);
  77. int id = _listBannerDatas[index];
  78. listItem.target.data = id;
  79. UI_ButtonBannerPage.ProxyEnd();
  80. }
  81. private void OnClickBannerPic()
  82. {
  83. int id = _listBannerDatas[_ui.m_compBanner.m_listTab.selectedIndex];
  84. switch (id)
  85. {
  86. case ConstBannerId.ZHAI_XING:
  87. ViewManager.Show(ViewName.LUCKY_BOX_VIEW, null, new object[] { ViewName.FIELD_GUIDE_VIEW, this.viewData });
  88. this.Hide();
  89. break;
  90. }
  91. }
  92. private void ListGuideItemRenderer(int index, GObject item)
  93. {
  94. UI_CompGuideItem listItem = UI_CompGuideItem.Proxy(item);
  95. int id = _listGuideDatas[index];
  96. listItem.m_loaderTitle.url = "ui://FieldGuide/tujian_taoz_" + id;
  97. listItem.m_loaderPic.url = "ui://FieldGuide/tujian_tup_" + id;
  98. listItem.target.data = id;
  99. bool red = actions[index] == null ? false : actions[index]();
  100. RedDotController.Instance.SetComRedDot(listItem.target, red, "", -20);
  101. UI_CompGuideItem.ProxyEnd();
  102. }
  103. private void OnClickListBannerItem(EventContext context)
  104. {
  105. UpdateBanner(context.data as GObject);
  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(ViewName.SUIT_GUIDE_VIEW, 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. }
  123. }
  124. private void GetGuideProgress(int id, out int haveCount, out int totalCount)
  125. {
  126. switch (id)
  127. {
  128. case ConstFieldGuideId.SUIT_GUIDE:
  129. DressUpMenuSuitDataManager.GetTotalProgress(out haveCount, out totalCount);
  130. break;
  131. case ConstFieldGuideId.CHAPTER_ITEM:
  132. InstanceZonesDataManager.GetTotalProgress(out haveCount, out totalCount);
  133. break;
  134. case ConstFieldGuideId.TRAVEL_GUIDE:
  135. InstanceZonesDataManager.GetTotalProgress(out haveCount, out totalCount);
  136. break;
  137. default:
  138. haveCount = 0;
  139. totalCount = 1;
  140. break;
  141. }
  142. }
  143. private void UpdatePrgress()
  144. {
  145. int num = _ui.m_listGuide.numChildren;
  146. for (int i = 0; i < num; i++)
  147. {
  148. UI_CompGuideItem listItem = UI_CompGuideItem.Proxy(_ui.m_listGuide.GetChildAt(i));
  149. int id = (int)listItem.target.data;
  150. int haveCount = 0;
  151. int totalCount = 1;
  152. GetGuideProgress(id, out haveCount, out totalCount);
  153. decimal value = Math.Floor((decimal)100 * haveCount / totalCount);
  154. listItem.m_txtProgress.text = value + "%";
  155. UI_CompGuideItem.ProxyEnd();
  156. }
  157. }
  158. private void UpdateBanner(GObject listItem)
  159. {
  160. string resName = "tujian_huodtu_1";
  161. int id = (int)listItem.data;
  162. switch (id)
  163. {
  164. case ConstBannerId.ZHAI_XING:
  165. resName = "tujian_huodtu_1";
  166. break;
  167. }
  168. _ui.m_compBanner.m_loaderPic.url = "ui://FieldGuide/" + resName;
  169. UpdateListBannerItems();
  170. }
  171. private void UpdateListBannerItems()
  172. {
  173. int num = _ui.m_compBanner.m_listTab.numChildren;
  174. // for (int i = 0; i < num; i++)
  175. // {
  176. // UI_ButtonBannerPage listItem = UI_ButtonBannerPage.Proxy(_ui.m_compBanner.m_listTab.GetChildAt(i));
  177. // if (listItem.target.selected)
  178. // {
  179. // listItem.target.width = 47;
  180. // }
  181. // else
  182. // {
  183. // listItem.target.width = 15;
  184. // }
  185. // }
  186. // _ui.m_compBanner.m_listTab.ResizeToFit();
  187. }
  188. private void SwitchBannerPic(object param)
  189. {
  190. int index = _ui.m_compBanner.m_listTab.selectedIndex;
  191. index++;
  192. if (index >= _listBannerDatas.Length)
  193. {
  194. index = 0;
  195. }
  196. _ui.m_compBanner.m_listTab.selectedIndex = index;
  197. UpdateBanner(_ui.m_compBanner.m_listTab.GetChildAt(_ui.m_compBanner.m_listTab.selectedIndex));
  198. }
  199. }
  200. }