SuitGuideDetailView.cs 12 KB

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