FieldGuideView.cs 6.6 KB

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