SuitGuideDetailView.cs 12 KB

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