FieldGuideView.cs 7.4 KB

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