FieldGuideView.cs 7.3 KB

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