SuitGuideDetailView.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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. private int index = 0;
  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_SuitGuideDetailUI.PACKAGE_NAME;
  35. _ui = UI_SuitGuideDetailUI.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. _ui.m_leftBtn.onClick.Add(OnClickLeft);
  44. _ui.m_rightBtn.onClick.Add(OnClickRight);
  45. _ui.m_lookBtn.onClick.Add(OnClickLook);
  46. _ui.m_listSuitCom.m_listSuit.scrollPane.onScroll.Add(DoTouch);//滚动时派发事件
  47. _ui.m_listSuitCom.m_listSuit.scrollPane.onScrollEnd.Add(DoTouchEnd);//滚动时派发事件
  48. }
  49. protected override void AddEventListener()
  50. {
  51. base.AddEventListener();
  52. EventAgent.AddEventListener(ConstMessage.JUMP_TO_SOURCE, this.Hide);
  53. EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateSuitStatus);
  54. EventAgent.AddEventListener(ConstMessage.SUIT_BOX_STATUS_CHANGED, UpdateSuitStatus);
  55. EventAgent.AddEventListener(ConstMessage.SUIT_BOX_STATUS_CHANGED, UpdateListSuit);
  56. EventAgent.AddEventListener(ConstMessage.DRESS_SEARCH, FilterItems);
  57. EventAgent.AddEventListener(ConstMessage.DRESS_FILTER, FilterItems);
  58. EventAgent.AddEventListener(ConstMessage.DRESS_FILTER_RESET, ResetFilter);
  59. }
  60. protected override void OnShown()
  61. {
  62. base.OnShown();
  63. _suitTypeId = (int)viewData;
  64. UpdateListSuit();
  65. if (backRefresh)
  66. {
  67. _ui.m_In.Play();
  68. }
  69. }
  70. protected override void OnHide()
  71. {
  72. base.OnHide();
  73. DressUpMenuItemDataManager.Clear();
  74. // 清空服装过滤界面选择
  75. EventAgent.DispatchEvent(ConstMessage.DRESS_FILTER_RESET_ALL);
  76. }
  77. protected override void RemoveEventListener()
  78. {
  79. base.RemoveEventListener();
  80. EventAgent.RemoveEventListener(ConstMessage.JUMP_TO_SOURCE, this.Hide);
  81. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateSuitStatus);
  82. EventAgent.RemoveEventListener(ConstMessage.SUIT_BOX_STATUS_CHANGED, UpdateSuitStatus);
  83. EventAgent.RemoveEventListener(ConstMessage.SUIT_BOX_STATUS_CHANGED, UpdateListSuit);
  84. EventAgent.RemoveEventListener(ConstMessage.DRESS_SEARCH, FilterItems);
  85. EventAgent.RemoveEventListener(ConstMessage.DRESS_FILTER, FilterItems);
  86. EventAgent.RemoveEventListener(ConstMessage.DRESS_FILTER_RESET, ResetFilter);
  87. }
  88. private void FilterItems(EventContext context)
  89. {
  90. UpdateListSuit();
  91. if (context.data.ToString() == ConstMessage.DRESS_SEARCH)
  92. {
  93. _suitIds = DressUpMenuItemDataManager.DressSearch(_suitIds, DressFilterItemType.Suit);
  94. }
  95. else if (context.data.ToString() == ConstMessage.DRESS_FILTER)
  96. {
  97. _suitIds = DressUpMenuItemDataManager.DressFilter(_suitIds, DressFilterItemType.Suit);
  98. }
  99. ViewManager.Hide<ModalStatusView>();
  100. _ui.m_listSuitCom.m_listSuit.numItems = _suitIds.Count;
  101. UpdateProgress();
  102. _ui.m_Refresh.Play();
  103. }
  104. private void OnClickBtnBack()
  105. {
  106. Hide();
  107. }
  108. private void OnClickBtnSearch()
  109. {
  110. ViewManager.Show<DressFilterView>(new object[] { 0, 2 });
  111. }
  112. private void UpdateListSuit()
  113. {
  114. _suitIds = SuitUtil.GetSuitIdList(true, true, _suitTypeId, 0);
  115. UpdateProgress();
  116. }
  117. private void UpdateProgress()
  118. {
  119. int haveCount = SuitUtil.GetHaveSuitCount(_suitIds);
  120. int totalCount = _suitIds.Count;
  121. SuitGuideMenuCfg cfg = SuitGuideMenuCfgArray.Instance.GetCfg(_suitTypeId);
  122. _ui.m_title.text = cfg.name;
  123. _ui.m_progress.target.value = haveCount;
  124. _ui.m_progress.target.max = totalCount;
  125. _ui.m_progress.m_title1.SetVar("value", haveCount.ToString()).SetVar("max", totalCount.ToString()).FlushVars();
  126. if (totalCount > 0)
  127. {
  128. _ui.m_progress.m_rate.SetVar("rate", FieldGuideView.ProgressCalculate(haveCount, totalCount).ToString()).FlushVars();
  129. }
  130. else
  131. {
  132. _ui.m_progress.m_rate.SetVar("rate", "0").FlushVars();
  133. }
  134. foreach (var v in _effectUIDic)
  135. {
  136. EffectUIPool.Recycle(v.Value);
  137. }
  138. _effectUIDic.Clear();
  139. _ui.m_listSuitCom.m_listSuit.numItems = _suitIds.Count;
  140. _ui.m_listSuitCom.m_listSuit.scrollPane.ScrollTop();
  141. _ui.m_listSuitCom.m_listSuit.ScrollToView(0);
  142. if (index <= 0)
  143. {
  144. _ui.m_leftBtn.visible = false;
  145. _ui.m_rightBtn.visible = true;
  146. }
  147. else
  148. {
  149. _ui.m_leftBtn.visible = true;
  150. _ui.m_rightBtn.visible = false;
  151. }
  152. }
  153. private void RenderListSuitItem(int index, GObject item)
  154. {
  155. UI_CompSuitItem listItem = UI_CompSuitItem.Proxy(item);
  156. int suitId = _suitIds[index];
  157. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(suitId);
  158. if ((suitCfg.rarity - 1) == 4)
  159. {
  160. bool haveSuit = DressUpMenuSuitDataManager.CheckHaveSuit(suitId);
  161. if (haveSuit && !_effectUIDic.ContainsKey(index))
  162. {
  163. _effectUIDic.Add(index, EffectUIPool.CreateEffectUI(listItem.m_holderBg, "ui_KP", "KP_Other_Gold_Frame"));
  164. }
  165. }
  166. listItem.m_txtName.text = suitCfg.name;
  167. listItem.m_loaderPic.url = ResPathUtil.GetFieldGuideIconPath(suitCfg.res);
  168. RarityIconController.UpdateRarityIcon(listItem.m_rarity, suitId, false, true);
  169. listItem.target.data = suitId;
  170. UpdateSuitStatusView(listItem);
  171. listItem.m_loaderBonusBox.target.onClick.Clear();
  172. listItem.m_loaderBonusBox.target.onClick.Add(() =>
  173. {
  174. SuitUtil.ShowSuitGuideBonus(suitId);
  175. });
  176. UI_CompSuitItem.ProxyEnd();
  177. }
  178. private void UpdateSuitStatus(EventContext eventContext)
  179. {
  180. int num = _ui.m_listSuitCom.m_listSuit.numChildren;
  181. for (int i = 0; i < num; i++)
  182. {
  183. UI_CompSuitItem listItem = UI_CompSuitItem.Proxy(_ui.m_listSuitCom.m_listSuit.GetChildAt(i));
  184. UpdateSuitStatusView(listItem);
  185. UI_CompSuitItem.ProxyEnd();
  186. }
  187. }
  188. private void UpdateSuitStatusView(UI_CompSuitItem listItem)
  189. {
  190. int suitId = (int)listItem.target.data;
  191. int count = 0;
  192. int totalCount = 0;
  193. DressUpMenuSuitDataManager.GetSuitProgressBySuitId(suitId, out count, out totalCount);
  194. listItem.m_progBar.max = totalCount;
  195. listItem.m_progBar.value = count;
  196. bool haveSuit = DressUpMenuSuitDataManager.CheckHaveSuit(suitId);
  197. listItem.m_state.selectedIndex = (haveSuit ? 0 : 1);
  198. int status = DressUpMenuSuitDataManager.GetSuitGuideBonusStatus(suitId);
  199. RedDotController.Instance.SetComRedDot(listItem.m_loaderBonusBox.target, status == ConstBonusStatus.CAN_GET, "", -3, -1);
  200. if (status == ConstBonusStatus.CAN_GET)
  201. {
  202. listItem.m_loaderBonusBox.m_loaderBonusBox.url = "ui://FieldGuide/tujian_lw_1";
  203. }
  204. else
  205. {
  206. listItem.m_loaderBonusBox.m_loaderBonusBox.url = "ui://FieldGuide/tujian_lw_2";
  207. }
  208. listItem.m_bg.onClick.Clear();
  209. listItem.m_bg.onClick.Add(() =>
  210. {
  211. if (haveSuit)
  212. {
  213. ViewManager.Show<SuitShowView>(new object[] { _suitTypeId, suitId, _suitIds }, false, false);
  214. }
  215. else
  216. {
  217. ViewManager.Show<SuitPartsDetailView>(suitId);
  218. }
  219. });
  220. }
  221. private void ResetFilter()
  222. {
  223. UpdateListSuit();
  224. }
  225. private void OnClickRight()
  226. {
  227. index++;
  228. _ui.m_listSuitCom.m_listSuit.ScrollToView(index, true);
  229. if (index >= _suitIds.Count)
  230. {
  231. _ui.m_leftBtn.visible = false;
  232. _ui.m_rightBtn.visible = true;
  233. }
  234. else
  235. {
  236. _ui.m_leftBtn.visible = true;
  237. _ui.m_rightBtn.visible = false;
  238. }
  239. }
  240. private void OnClickLeft()
  241. {
  242. index--;
  243. _ui.m_listSuitCom.m_listSuit.ScrollToView(index, true);
  244. if (index <= 0)
  245. {
  246. _ui.m_leftBtn.visible = false;
  247. _ui.m_rightBtn.visible = true;
  248. }
  249. else
  250. {
  251. _ui.m_leftBtn.visible = true;
  252. _ui.m_rightBtn.visible = false;
  253. }
  254. }
  255. private void OnClickLook()
  256. {
  257. int suitid = _suitIds[index];
  258. bool haveSuit = DressUpMenuSuitDataManager.CheckHaveSuit(suitid);
  259. if (haveSuit)
  260. {
  261. ViewManager.Show<SuitShowView>(new object[] { _suitTypeId, suitid, _suitIds }, false, false);
  262. }
  263. else
  264. {
  265. ViewManager.Show<SuitPartsDetailView>(suitid);
  266. }
  267. }
  268. private void DoTouchEnd()
  269. {
  270. _ui.m_leftBtn.touchable = true;
  271. _ui.m_rightBtn.touchable = true;
  272. _ui.m_lookBtn.touchable = true;
  273. index = _ui.m_listSuitCom.m_listSuit.GetFirstChildInView();
  274. if (index <= 0)
  275. {
  276. _ui.m_leftBtn.visible = false;
  277. _ui.m_rightBtn.visible = true;
  278. }
  279. else
  280. {
  281. _ui.m_leftBtn.visible = true;
  282. _ui.m_rightBtn.visible = false;
  283. }
  284. }
  285. private void DoTouch()
  286. {
  287. _ui.m_leftBtn.touchable = false;
  288. _ui.m_rightBtn.touchable = false;
  289. _ui.m_lookBtn.touchable = true;
  290. }
  291. }
  292. }