SuitGuideListView.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. using FairyGUI;
  2. using UI.FieldGuide;
  3. using UI.CommonGame;
  4. using System.Collections.Generic;
  5. using UI.ClothingSynthetic;
  6. using UnityEngine;
  7. using System;
  8. namespace GFGGame
  9. {
  10. public class SuitGuideListView : BaseWindow
  11. {
  12. private UI_SuitGuideListUI _ui;
  13. private List<int> _suitIds;
  14. private int _suitTypeId;
  15. private Dictionary<int, EffectUI> _effectUIDic = new Dictionary<int, EffectUI>();
  16. public override void Dispose()
  17. {
  18. foreach (var v in _effectUIDic)
  19. {
  20. EffectUIPool.Recycle(v.Value);
  21. }
  22. _effectUIDic.Clear();
  23. if (_ui != null)
  24. {
  25. _ui.Dispose();
  26. _ui = null;
  27. }
  28. base.Dispose();
  29. }
  30. protected override void OnInit()
  31. {
  32. base.OnInit();
  33. packageName = UI_SuitGuideListUI.PACKAGE_NAME;
  34. _ui = UI_SuitGuideListUI.Create();
  35. this.viewCom = _ui.target;
  36. isfullScreen = true;
  37. isReturnView = true;
  38. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("tjbg");
  39. _ui.m_listSuitCom.m_listSuit.itemRenderer = RenderListSuitItem;
  40. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  41. _ui.m_btnSearch.onClick.Add(OnClickBtnSearch);
  42. }
  43. protected override void AddEventListener()
  44. {
  45. base.AddEventListener();
  46. EventAgent.AddEventListener(ConstMessage.JUMP_TO_SOURCE, this.Hide);
  47. EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateSuitStatus);
  48. EventAgent.AddEventListener(ConstMessage.SUIT_BOX_STATUS_CHANGED, UpdateSuitStatus);
  49. EventAgent.AddEventListener(ConstMessage.SUIT_BOX_STATUS_CHANGED, UpdateListSuit);
  50. EventAgent.AddEventListener(ConstMessage.DRESS_SEARCH, FilterItems);
  51. EventAgent.AddEventListener(ConstMessage.DRESS_FILTER, FilterItems);
  52. EventAgent.AddEventListener(ConstMessage.DRESS_FILTER_RESET, ResetFilter);
  53. }
  54. protected override void OnShown()
  55. {
  56. base.OnShown();
  57. _suitTypeId = (int)viewData;
  58. UpdateListSuit();
  59. if (backRefresh)
  60. {
  61. _ui.m_In.Play();
  62. }
  63. }
  64. protected override void OnHide()
  65. {
  66. base.OnHide();
  67. DressUpMenuItemDataManager.Clear();
  68. // 清空服装过滤界面选择
  69. EventAgent.DispatchEvent(ConstMessage.DRESS_FILTER_RESET_ALL);
  70. }
  71. protected override void RemoveEventListener()
  72. {
  73. base.RemoveEventListener();
  74. EventAgent.RemoveEventListener(ConstMessage.JUMP_TO_SOURCE, this.Hide);
  75. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateSuitStatus);
  76. EventAgent.RemoveEventListener(ConstMessage.SUIT_BOX_STATUS_CHANGED, UpdateSuitStatus);
  77. EventAgent.RemoveEventListener(ConstMessage.SUIT_BOX_STATUS_CHANGED, UpdateListSuit);
  78. EventAgent.RemoveEventListener(ConstMessage.DRESS_SEARCH, FilterItems);
  79. EventAgent.RemoveEventListener(ConstMessage.DRESS_FILTER, FilterItems);
  80. EventAgent.RemoveEventListener(ConstMessage.DRESS_FILTER_RESET, ResetFilter);
  81. }
  82. private void FilterItems(EventContext context)
  83. {
  84. UpdateListSuit();
  85. if (context.data.ToString() == ConstMessage.DRESS_SEARCH)
  86. {
  87. _suitIds = DressUpMenuItemDataManager.DressSearch(_suitIds, DressFilterItemType.Suit);
  88. }
  89. else if (context.data.ToString() == ConstMessage.DRESS_FILTER)
  90. {
  91. _suitIds = DressUpMenuItemDataManager.DressFilter(_suitIds, DressFilterItemType.Suit);
  92. }
  93. ViewManager.Hide<ModalStatusView>();
  94. _ui.m_listSuitCom.m_listSuit.numItems = _suitIds.Count;
  95. UpdateProgress();
  96. _ui.m_Refresh.Play();
  97. }
  98. private void OnClickBtnBack()
  99. {
  100. Hide();
  101. }
  102. private void OnClickBtnSearch()
  103. {
  104. ViewManager.Show<DressFilterView>(new object[] { 0, 2 });
  105. }
  106. private void UpdateListSuit()
  107. {
  108. _suitIds = SuitUtil.GetSuitIdList(true, true, _suitTypeId, 0);
  109. UpdateProgress();
  110. }
  111. private void UpdateProgress()
  112. {
  113. int haveCount = SuitUtil.GetHaveSuitCount(_suitIds);
  114. int totalCount = _suitIds.Count;
  115. SuitGuideMenuCfg cfg = SuitGuideMenuCfgArray.Instance.GetCfg(_suitTypeId);
  116. _ui.m_title.text = cfg.name;
  117. _ui.m_progress.target.value = haveCount;
  118. _ui.m_progress.target.max = totalCount;
  119. _ui.m_progress.m_title1.SetVar("value", haveCount.ToString()).SetVar("max", totalCount.ToString()).FlushVars();
  120. if (totalCount > 0)
  121. {
  122. _ui.m_progress.m_rate.SetVar("rate", FieldGuideView.ProgressCalculate(haveCount, totalCount).ToString()).FlushVars();
  123. }
  124. else
  125. {
  126. _ui.m_progress.m_rate.SetVar("rate", "0").FlushVars();
  127. }
  128. foreach (var v in _effectUIDic)
  129. {
  130. EffectUIPool.Recycle(v.Value);
  131. }
  132. _effectUIDic.Clear();
  133. _ui.m_listSuitCom.m_listSuit.numItems = _suitIds.Count;
  134. _ui.m_listSuitCom.m_listSuit.scrollPane.ScrollTop();
  135. UpdateSuitStatus();
  136. }
  137. private void RenderListSuitItem(int index, GObject item)
  138. {
  139. UI_SuitComitem listItem = UI_SuitComitem.Proxy(item);
  140. int suitId = _suitIds[index];
  141. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(suitId);
  142. if ((suitCfg.rarity - 1) == 4)
  143. {
  144. bool haveSuit = DressUpMenuSuitDataManager.CheckHaveSuit(suitId);
  145. if (haveSuit && !_effectUIDic.ContainsKey(index))
  146. {
  147. _effectUIDic.Add(index, EffectUIPool.CreateEffectUI(listItem.m_holderBg, "ui_KP", "KP_Other_Gold_Frame"));
  148. }
  149. }
  150. listItem.m_txtName.text = suitCfg.name;
  151. listItem.m_loaderPic.url = ResPathUtil.GetFieldGuideIconPath(suitCfg.res);
  152. RarityIconController.UpdateRarityIcon(listItem.m_rarity, suitId, false, true);
  153. listItem.target.data = suitId;
  154. listItem.m_loaderBonusBox.target.onClick.Clear();
  155. listItem.m_loaderBonusBox.target.onClick.Add(() =>
  156. {
  157. SuitUtil.ShowSuitGuideBonus(suitId);
  158. });
  159. UI_SuitComitem.ProxyEnd();
  160. }
  161. private void UpdateSuitStatus(EventContext eventContext = null)
  162. {
  163. int num = _ui.m_listSuitCom.m_listSuit.numChildren;
  164. for (int i = 0; i < num; i++)
  165. {
  166. UI_CompSuitItem listItem = UI_CompSuitItem.Proxy(_ui.m_listSuitCom.m_listSuit.GetChildAt(i));
  167. UpdateSuitStatusView(listItem);
  168. UI_CompSuitItem.ProxyEnd();
  169. }
  170. }
  171. private void UpdateSuitStatusView(UI_CompSuitItem listItem)
  172. {
  173. int suitId = (int)listItem.target.data;
  174. int count = 0;
  175. int totalCount = 0;
  176. DressUpMenuSuitDataManager.GetSuitProgressBySuitId(suitId, out count, out totalCount);
  177. listItem.m_progBar.max = totalCount;
  178. listItem.m_progBar.value = count;
  179. bool haveSuit = DressUpMenuSuitDataManager.CheckHaveSuit(suitId);
  180. listItem.m_state.selectedIndex = (haveSuit ? 0 : 1);
  181. int status = DressUpMenuSuitDataManager.GetSuitGuideBonusStatus(suitId);
  182. RedDotController.Instance.SetComRedDot(listItem.m_loaderBonusBox.target, status == ConstBonusStatus.CAN_GET, "", -3, -1);
  183. if (status == ConstBonusStatus.CAN_GET)
  184. {
  185. listItem.m_loaderBonusBox.m_loaderBonusBox.url = "ui://FieldGuide/tujian_lw_1";
  186. }
  187. else
  188. {
  189. listItem.m_loaderBonusBox.m_loaderBonusBox.url = "ui://FieldGuide/tujian_lw_2";
  190. }
  191. listItem.m_bg.onClick.Clear();
  192. listItem.m_bg.onClick.Add(() =>
  193. {
  194. if (haveSuit)
  195. {
  196. ViewManager.Show<SuitShowView>(new object[] { _suitTypeId, suitId, _suitIds }, false, false);
  197. }
  198. else
  199. {
  200. ViewManager.Show<SuitPartsDetailView>(suitId);
  201. }
  202. });
  203. }
  204. private void ResetFilter()
  205. {
  206. UpdateListSuit();
  207. }
  208. }
  209. }