SuitGuideView.cs 8.7 KB

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