SuitGuideListView.cs 8.8 KB

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