SuitGuideView.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. using FairyGUI;
  2. using UI.FieldGuide;
  3. using UI.CommonGame;
  4. using System.Collections.Generic;
  5. namespace GFGGame
  6. {
  7. public class SuitGuideView : BaseWindow
  8. {
  9. private UI_SuitGuideUI _ui;
  10. private ValueBarController _valueBarController;
  11. private int _menuType = ConstSuitGuideTypeId.TYPE_1;
  12. private int[] _menuTypeDataArray;
  13. private List<int> _suitIds;
  14. private int _suitTypeId;
  15. public override void Dispose()
  16. {
  17. _valueBarController.Dispose();
  18. _valueBarController = null;
  19. base.Dispose();
  20. }
  21. protected override void OnInit()
  22. {
  23. base.OnInit();
  24. packageName = UI_SuitGuideUI.PACKAGE_NAME;
  25. _ui = UI_SuitGuideUI.Create();
  26. this.viewCom = _ui.target;
  27. isfullScreen = true;
  28. _valueBarController = new ValueBarController(_ui.m_valueBar);
  29. _ui.m_listSuit.itemRenderer = ListSuitItemRenderer;
  30. _ui.m_listType.itemRenderer = ListTypeItemRenderer;
  31. _ui.m_comBoxSort.items = new string[] { "默认排序", "稀有度高", "稀有度低", "收集度高", "收集度低" };
  32. _ui.m_listType.onClickItem.Add(OnClickListTypeItem);
  33. _ui.m_comBoxSort.onChanged.Add(OnComboBoxSortChanged);
  34. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  35. _ui.m_btnSwitch.onClick.Add(OnClickBtnSwitch);
  36. _ui.m_btnHaveGot.onChanged.Add(OnClickBtnHaveGot);
  37. _ui.m_btnNotGet.onChanged.Add(OnClickBtnNotGet);
  38. }
  39. protected override void OnShown()
  40. {
  41. base.OnShown();
  42. _valueBarController.OnShown();
  43. _ui.m_btnHaveGot.selected = true;
  44. _ui.m_btnNotGet.selected = true;
  45. UpdateListType();
  46. EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateSuitStatus);
  47. }
  48. protected override void OnHide()
  49. {
  50. base.OnHide();
  51. _valueBarController.OnHide();
  52. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateSuitStatus);
  53. }
  54. private void OnClickListTypeItem()
  55. {
  56. UpdateListSuit();
  57. }
  58. private void OnComboBoxSortChanged()
  59. {
  60. UpdateListSuit();
  61. }
  62. private void OnClickBtnBack()
  63. {
  64. this.Hide();
  65. }
  66. private void OnClickBtnSwitch()
  67. {
  68. _menuType = 3 - _menuType;
  69. UpdateListType();
  70. }
  71. private void OnClickBtnHaveGot()
  72. {
  73. if (!_ui.m_btnHaveGot.selected)
  74. {
  75. _ui.m_btnNotGet.selected = true;
  76. }
  77. UpdateListSuit();
  78. }
  79. private void OnClickBtnNotGet()
  80. {
  81. if (!_ui.m_btnNotGet.selected)
  82. {
  83. _ui.m_btnHaveGot.selected = true;
  84. }
  85. UpdateListSuit();
  86. }
  87. private void UpdateListType()
  88. {
  89. _ui.m_listType.RemoveChildrenToPool();
  90. switch(_menuType)
  91. {
  92. case ConstSuitGuideTypeId.TYPE_1:
  93. _menuTypeDataArray = new int[]{0, 1, 2, 3, 4, 5};
  94. break;
  95. default:
  96. _menuTypeDataArray = new int[]{6, 7, 8, 9, 10};
  97. break;
  98. }
  99. _ui.m_listType.numItems = _menuTypeDataArray.Length;
  100. _ui.m_listType.selectedIndex = 0;
  101. UpdateListSuit();
  102. }
  103. private void ListTypeItemRenderer(int index, object item)
  104. {
  105. UI_ButtonSuitType listItem = UI_ButtonSuitType.Proxy(item as GObject);
  106. int typeId = _menuTypeDataArray[index];
  107. SuitGuideMenuCfg cfg = SuitGuideMenuCfgArray.Instance.GetCfg(typeId);
  108. listItem.target.title = cfg.name;
  109. listItem.target.data = typeId;
  110. listItem.m_imgLine.visible = (index != 0);
  111. UI_ButtonSuitType.ProxyEnd();
  112. }
  113. private void UpdateListSuit()
  114. {
  115. _ui.m_listSuit.RemoveChildrenToPool();
  116. UI_ButtonSuitType listItem = UI_ButtonSuitType.Proxy(_ui.m_listType.GetChildAt(_ui.m_listType.selectedIndex));
  117. _suitTypeId = (int)listItem.target.data;
  118. _suitIds = SuitUtil.GetSuitIdList(_ui.m_btnNotGet.selected, _ui.m_btnHaveGot.selected, _suitTypeId, _ui.m_comBoxSort.selectedIndex);
  119. _ui.m_listSuit.numItems = _suitIds.Count;
  120. _ui.m_listSuit.scrollPane.ScrollTop();
  121. UI_ButtonSuitType.ProxyEnd();
  122. }
  123. private void ListSuitItemRenderer(int index, GObject item)
  124. {
  125. UI_CompSuitItem listItem = UI_CompSuitItem.Proxy(item);
  126. int suitId = _suitIds[index];
  127. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(suitId);
  128. listItem.m_txtName.text = suitCfg.name;
  129. listItem.m_loaderPic.url = ResPathUtil.GetFieldGuideIconPath(suitCfg.res);
  130. RarityIconController.UpdateRarityIcon(listItem.m_rarity, suitId, false, true);
  131. listItem.target.data = suitId;
  132. UpdateSuitStatusView(listItem);
  133. listItem.m_loaderBonusBox.onClick.Clear();
  134. listItem.m_loaderBonusBox.onClick.Add(() => {
  135. SuitUtil.ShowSuitGuideBonus(suitId);
  136. });
  137. }
  138. private void UpdateSuitStatus(EventContext eventContext)
  139. {
  140. int num = _ui.m_listSuit.numChildren;
  141. for(int i = 0; i < num; i++)
  142. {
  143. UI_CompSuitItem listItem = UI_CompSuitItem.Proxy(_ui.m_listSuit.GetChildAt(i));
  144. UpdateSuitStatusView(listItem);
  145. }
  146. }
  147. private void UpdateSuitStatusView(UI_CompSuitItem listItem)
  148. {
  149. int suitId = (int)listItem.target.data;
  150. int count = 0;
  151. int totalCount = 0;
  152. DressUpMenuSuitDataManager.GetSuitProgressBySuitId(suitId, out count, out totalCount);
  153. listItem.m_progBar.max = totalCount;
  154. listItem.m_progBar.value = count;
  155. bool haveSuit = DressUpMenuSuitDataManager.CheckHaveSuit(suitId);
  156. listItem.m_imgLock.visible = listItem.m_imgLockBg.visible = !haveSuit;
  157. int status = DressUpMenuSuitDataManager.GetSuitGuideBonusStatus(suitId);
  158. if(status == ConstBonusStatus.CAN_GET)
  159. {
  160. listItem.m_loaderBonusBox.url = "ui://FieldGuide/tujian_lw_1";
  161. }
  162. else
  163. {
  164. listItem.m_loaderBonusBox.url = "ui://FieldGuide/tujian_lw_2";
  165. }
  166. listItem.m_bg.onClick.Clear();
  167. listItem.m_bg.onClick.Add(() => {
  168. if (haveSuit)
  169. {
  170. ViewManager.Show(ViewName.SUIT_SHOW_VIEW, new object[] { _suitTypeId, suitId, _suitIds });
  171. }
  172. else
  173. {
  174. ViewManager.Show(ViewName.SUIT_PARTS_DETAIL_VIEW, suitId);
  175. }
  176. });
  177. }
  178. }
  179. }