SuitGuideView.cs 9.0 KB

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