FieldGuideView.cs 5.9 KB

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