FieldGuideView.cs 6.0 KB

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