FieldGuideView.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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[2] { ConstFieldGuideId.SUIT_GUIDE, ConstFieldGuideId.CHAPTER_ITEM };
  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. }
  120. }
  121. private void GetGuideProgress(int id, out int haveCount, out int totalCount)
  122. {
  123. switch (id)
  124. {
  125. case ConstFieldGuideId.SUIT_GUIDE:
  126. DressUpMenuSuitDataManager.GetTotalProgress(out haveCount, out totalCount);
  127. break;
  128. case ConstFieldGuideId.CHAPTER_ITEM:
  129. InstanceZonesDataManager.GetTotalProgress(out haveCount, out totalCount);
  130. break;
  131. default:
  132. haveCount = 0;
  133. totalCount = 1;
  134. break;
  135. }
  136. }
  137. private void UpdatePrgress()
  138. {
  139. int num = _ui.m_listGuide.numChildren;
  140. for (int i = 0; i < num; i++)
  141. {
  142. UI_CompGuideItem listItem = UI_CompGuideItem.Proxy(_ui.m_listGuide.GetChildAt(i));
  143. int id = (int)listItem.target.data;
  144. int haveCount = 0;
  145. int totalCount = 1;
  146. GetGuideProgress(id, out haveCount, out totalCount);
  147. decimal value = Math.Floor((decimal)100 * haveCount / totalCount);
  148. listItem.m_txtProgress.text = value + "%";
  149. UI_CompGuideItem.ProxyEnd();
  150. }
  151. }
  152. private void UpdateBanner(GObject listItem)
  153. {
  154. string resName = "tujian_huodtu_1";
  155. int id = (int)listItem.data;
  156. switch (id)
  157. {
  158. case ConstBannerId.ZHAI_XING:
  159. resName = "tujian_huodtu_1";
  160. break;
  161. }
  162. _ui.m_compBanner.m_loaderPic.url = "ui://FieldGuide/" + resName;
  163. UpdateListBannerItems();
  164. }
  165. private void UpdateListBannerItems()
  166. {
  167. int num = _ui.m_compBanner.m_listTab.numChildren;
  168. // for (int i = 0; i < num; i++)
  169. // {
  170. // UI_ButtonBannerPage listItem = UI_ButtonBannerPage.Proxy(_ui.m_compBanner.m_listTab.GetChildAt(i));
  171. // if (listItem.target.selected)
  172. // {
  173. // listItem.target.width = 47;
  174. // }
  175. // else
  176. // {
  177. // listItem.target.width = 15;
  178. // }
  179. // }
  180. // _ui.m_compBanner.m_listTab.ResizeToFit();
  181. }
  182. private void SwitchBannerPic(object param)
  183. {
  184. int index = _ui.m_compBanner.m_listTab.selectedIndex;
  185. index++;
  186. if (index >= _listBannerDatas.Length)
  187. {
  188. index = 0;
  189. }
  190. _ui.m_compBanner.m_listTab.selectedIndex = index;
  191. UpdateBanner(_ui.m_compBanner.m_listTab.GetChildAt(_ui.m_compBanner.m_listTab.selectedIndex));
  192. }
  193. }
  194. }