SuitGuideDetailView.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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 SuitGuideDetailView : BaseWindow
  11. {
  12. private UI_SuitGuideDetailUI _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. if (_ui != null)
  19. {
  20. _ui.Dispose();
  21. _ui = null;
  22. }
  23. base.Dispose();
  24. }
  25. protected override void OnInit()
  26. {
  27. base.OnInit();
  28. packageName = UI_SuitGuideDetailUI.PACKAGE_NAME;
  29. _ui = UI_SuitGuideDetailUI.Create();
  30. this.viewCom = _ui.target;
  31. isfullScreen = true;
  32. isReturnView = true;
  33. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("tjbg");
  34. _ui.m_listSuit.itemRenderer = RenderListSuitItem;
  35. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  36. _ui.m_btnSearch.onClick.Add(OnClickBtnSearch);
  37. }
  38. protected override void AddEventListener()
  39. {
  40. base.AddEventListener();
  41. EventAgent.AddEventListener(ConstMessage.JUMP_TO_SOURCE, this.Hide);
  42. EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateSuitStatus);
  43. EventAgent.AddEventListener(ConstMessage.SUIT_BOX_STATUS_CHANGED, UpdateSuitStatus);
  44. EventAgent.AddEventListener(ConstMessage.SUIT_BOX_STATUS_CHANGED, UpdateListSuit);
  45. EventAgent.AddEventListener(ConstMessage.DRESS_SEARCH, FilterItems);
  46. EventAgent.AddEventListener(ConstMessage.DRESS_FILTER, FilterItems);
  47. EventAgent.AddEventListener(ConstMessage.DRESS_FILTER_RESET, ResetFilter);
  48. }
  49. protected override void OnShown()
  50. {
  51. base.OnShown();
  52. _suitTypeId = (int)viewData;
  53. UpdateListSuit();
  54. if (backRefresh)
  55. {
  56. _ui.m_In.Play();
  57. }
  58. }
  59. protected override void OnHide()
  60. {
  61. base.OnHide();
  62. foreach (var v in _effectUIDic)
  63. {
  64. EffectUIPool.Recycle(v.Value);
  65. }
  66. _effectUIDic.Clear();
  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_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_listSuit.numItems = _suitIds.Count;
  134. _ui.m_listSuit.scrollPane.ScrollTop();
  135. }
  136. private void RenderListSuitItem(int index, GObject item)
  137. {
  138. UI_CompSuitItem listItem = UI_CompSuitItem.Proxy(item);
  139. int suitId = _suitIds[index];
  140. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(suitId);
  141. listItem.m_txtName.text = suitCfg.name;
  142. listItem.m_loaderPic.url = ResPathUtil.GetFieldGuideIconPath(suitCfg.res);
  143. listItem.m_c1.SetSelectedIndex(suitCfg.rarity - 1);
  144. if((suitCfg.rarity - 1) == 3)
  145. _effectUIDic.Add(index, EffectUIPool.CreateEffectUI(listItem.m_holderBg, "ui_KP", "KP_Other_Gold_Frame"));
  146. RarityIconController.UpdateRarityIcon(listItem.m_rarity, suitId, false, true);
  147. listItem.target.data = suitId;
  148. UpdateSuitStatusView(listItem);
  149. listItem.m_loaderBonusBox.target.onClick.Clear();
  150. listItem.m_loaderBonusBox.target.onClick.Add(() =>
  151. {
  152. SuitUtil.ShowSuitGuideBonus(suitId);
  153. });
  154. UI_CompSuitItem.ProxyEnd();
  155. }
  156. private void UpdateSuitStatus(EventContext eventContext)
  157. {
  158. int num = _ui.m_listSuit.numChildren;
  159. for (int i = 0; i < num; i++)
  160. {
  161. UI_CompSuitItem listItem = UI_CompSuitItem.Proxy(_ui.m_listSuit.GetChildAt(i));
  162. UpdateSuitStatusView(listItem);
  163. UI_CompSuitItem.ProxyEnd();
  164. }
  165. }
  166. private void UpdateSuitStatusView(UI_CompSuitItem listItem)
  167. {
  168. int suitId = (int)listItem.target.data;
  169. int count = 0;
  170. int totalCount = 0;
  171. DressUpMenuSuitDataManager.GetSuitProgressBySuitId(suitId, out count, out totalCount);
  172. listItem.m_progBar.max = totalCount;
  173. listItem.m_progBar.value = count;
  174. bool haveSuit = DressUpMenuSuitDataManager.CheckHaveSuit(suitId);
  175. listItem.m_unlockMask.visible = !haveSuit;
  176. int status = DressUpMenuSuitDataManager.GetSuitGuideBonusStatus(suitId);
  177. RedDotController.Instance.SetComRedDot(listItem.m_loaderBonusBox.target, status == ConstBonusStatus.CAN_GET, "", -3, -1);
  178. if (status == ConstBonusStatus.CAN_GET)
  179. {
  180. listItem.m_loaderBonusBox.m_loaderBonusBox.url = "ui://FieldGuide/tujian_lw_1";
  181. }
  182. else
  183. {
  184. listItem.m_loaderBonusBox.m_loaderBonusBox.url = "ui://FieldGuide/tujian_lw_2";
  185. }
  186. listItem.m_bg.onClick.Clear();
  187. listItem.m_bg.onClick.Add(() =>
  188. {
  189. if (haveSuit)
  190. {
  191. ViewManager.Show<SuitShowView>(new object[] { _suitTypeId, suitId, _suitIds }, false, false);
  192. }
  193. else
  194. {
  195. ViewManager.Show<SuitPartsDetailView>(suitId);
  196. }
  197. });
  198. }
  199. private void ResetFilter()
  200. {
  201. UpdateListSuit();
  202. }
  203. }
  204. }