SuitGuideView.cs 8.5 KB

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