SuitGuideDetailView.cs 12 KB

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