FieldGuideView.cs 7.4 KB

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