FieldGuideView.cs 5.8 KB

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