SuitGuideListView.cs 8.6 KB

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