FieldGuideView.cs 7.1 KB

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