SuitGuideListView.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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()).FlushVars();
  122. if (totalCount > 0)
  123. {
  124. _ui.m_progress.m_rate.SetVar("rate", FieldGuideView.ProgressCalculate(haveCount, totalCount).ToString()).FlushVars();
  125. }
  126. else
  127. {
  128. _ui.m_progress.m_rate.SetVar("rate", "0").FlushVars();
  129. }
  130. foreach (var v in _effectUIDic)
  131. {
  132. EffectUIPool.Recycle(v.Value);
  133. }
  134. _effectUIDic.Clear();
  135. _ui.m_listSuitCom.m_listSuit.numItems = _suitIds.Count;
  136. _ui.m_listSuitCom.m_listSuit.scrollPane.ScrollTop();
  137. UpdateSuitStatus();
  138. }
  139. private void RenderListSuitItem(int index, GObject item)
  140. {
  141. UI_SuitComitem listItem = UI_SuitComitem.Proxy(item);
  142. int suitId = _suitIds[index];
  143. SuitCfg suitCfg = CommonDataManager.Tables.TblSuitCfg.GetOrDefault(suitId);
  144. if ((suitCfg.Rarity - 1) == 4)
  145. {
  146. bool haveSuit = DressUpMenuSuitDataManager.CheckHaveSuit(suitId);
  147. if (haveSuit && !_effectUIDic.ContainsKey(index))
  148. {
  149. _effectUIDic.Add(index, EffectUIPool.CreateEffectUI(listItem.m_holderBg, "ui_KP", "KP_Other_Gold_Frame"));
  150. }
  151. }
  152. listItem.m_txtName.text = suitCfg.Name;
  153. listItem.m_loaderPic.url = ResPathUtil.GetFieldGuideIconPath(suitCfg.Res);
  154. RarityIconController.UpdateRarityIcon(listItem.m_rarity, suitId, false, true);
  155. listItem.target.data = suitId;
  156. listItem.m_loaderBonusBox.target.onClick.Clear();
  157. listItem.m_loaderBonusBox.target.onClick.Add(() =>
  158. {
  159. SuitUtil.ShowSuitGuideBonus(suitId);
  160. });
  161. UI_SuitComitem.ProxyEnd();
  162. }
  163. private void UpdateSuitStatus(EventContext eventContext = null)
  164. {
  165. int num = _ui.m_listSuitCom.m_listSuit.numChildren;
  166. for (int i = 0; i < num; i++)
  167. {
  168. UI_CompSuitItem listItem = UI_CompSuitItem.Proxy(_ui.m_listSuitCom.m_listSuit.GetChildAt(i));
  169. UpdateSuitStatusView(listItem);
  170. UI_CompSuitItem.ProxyEnd();
  171. }
  172. }
  173. private void UpdateSuitStatusView(UI_CompSuitItem listItem)
  174. {
  175. int suitId = (int)listItem.target.data;
  176. int count = 0;
  177. int totalCount = 0;
  178. DressUpMenuSuitDataManager.GetSuitProgressBySuitId(suitId, out count, out totalCount);
  179. listItem.m_progBar.max = totalCount;
  180. listItem.m_progBar.value = count;
  181. bool haveSuit = DressUpMenuSuitDataManager.CheckHaveSuit(suitId);
  182. listItem.m_state.selectedIndex = (haveSuit ? 0 : 1);
  183. int status = DressUpMenuSuitDataManager.GetSuitGuideBonusStatus(suitId);
  184. RedDotController.Instance.SetComRedDot(listItem.m_loaderBonusBox.target, status == ConstBonusStatus.CAN_GET, "", -3, -1);
  185. if (status == ConstBonusStatus.CAN_GET)
  186. {
  187. listItem.m_loaderBonusBox.m_loaderBonusBox.url = "ui://FieldGuide/tujian_lw_1";
  188. }
  189. else
  190. {
  191. listItem.m_loaderBonusBox.m_loaderBonusBox.url = "ui://FieldGuide/tujian_lw_2";
  192. }
  193. listItem.m_bg.onClick.Clear();
  194. listItem.m_bg.onClick.Add(() =>
  195. {
  196. if (haveSuit)
  197. {
  198. ViewManager.Show<SuitShowView>(new object[] { _suitTypeId, suitId, _suitIds }, false, false);
  199. }
  200. else
  201. {
  202. ViewManager.Show<SuitPartsDetailView>(suitId);
  203. }
  204. });
  205. }
  206. private void ResetFilter()
  207. {
  208. UpdateListSuit();
  209. }
  210. }
  211. }