SuitGuideDetailView.cs 12 KB

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