FieldGuideView.cs 6.5 KB

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