DressUpGuideView.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. using FairyGUI;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UI.CommonGame;
  6. using UI.FieldGuide;
  7. using UnityEngine;
  8. namespace GFGGame
  9. {
  10. /// <summary>
  11. /// 服装图鉴界面
  12. /// </summary>
  13. public class DressUpGuideView : BaseWindow
  14. {
  15. private UI_DressUpGuideUI _ui;
  16. private List<int> _itemIdList;
  17. private bool _startInAnim;
  18. private string _filterStr;
  19. // 上次点击单选按钮的index
  20. private struct LastClickIndex
  21. {
  22. public int typeIndex; // 菜单类型:一级/二级
  23. public int index;
  24. }
  25. private LastClickIndex _lastClickIndex;
  26. private int[] _currentList2;
  27. public override void Dispose()
  28. {
  29. if (_ui != null)
  30. {
  31. _ui.Dispose();
  32. _ui = null;
  33. }
  34. base.Dispose();
  35. }
  36. protected override void OnInit()
  37. {
  38. base.OnInit();
  39. packageName = UI_DressUpGuideUI.PACKAGE_NAME;
  40. _ui = UI_DressUpGuideUI.Create();
  41. this.viewCom = _ui.target;
  42. isfullScreen = true;
  43. isReturnView = true;
  44. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("quanping_moren_bg");
  45. _itemIdList = new List<int>();
  46. _startInAnim = true;
  47. _ui.m_btnSearch.onClick.Add(OnClickBtnSearch);
  48. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  49. _ui.m_listType1.onClickItem.Add(OnClickListType1Item);
  50. _ui.m_listType2.onClickItem.Add(OnClickListType2Item);
  51. _ui.m_listDressUp.itemRenderer = RenderListDressUpItem;
  52. _ui.m_listDressUp.onClickItem.Add(OnClickListDressUpItem);
  53. _ui.m_listDressUp.SetVirtual();
  54. _ui.m_btnAccessories.onClick.Add(OnClickBtnAllAccessories);
  55. DressUpMenuItemDataManager.isLoading = true;
  56. }
  57. protected override void AddEventListener()
  58. {
  59. base.AddEventListener();
  60. EventAgent.AddEventListener(ConstMessage.DRESS_SEARCH, FilterItems);
  61. EventAgent.AddEventListener(ConstMessage.DRESS_FILTER, FilterItems);
  62. EventAgent.AddEventListener(ConstMessage.DRESS_FILTER_RESET, ResetFilterStr);
  63. EventAgent.AddEventListener(ConstMessage.DRESS_PART_LOAD_FINISHED, LoadFinished);
  64. }
  65. protected override void RemoveEventListener()
  66. {
  67. base.RemoveEventListener();
  68. EventAgent.RemoveEventListener(ConstMessage.DRESS_SEARCH, FilterItems);
  69. EventAgent.RemoveEventListener(ConstMessage.DRESS_FILTER, FilterItems);
  70. EventAgent.RemoveEventListener(ConstMessage.DRESS_FILTER_RESET, ResetFilterStr);
  71. EventAgent.RemoveEventListener(ConstMessage.DRESS_PART_LOAD_FINISHED, LoadFinished);
  72. }
  73. protected override void OnShown()
  74. {
  75. base.OnShown();
  76. _ui.m_listType1.selectedIndex = 0;
  77. _ui.m_c1.selectedIndex = 0;
  78. _ui.m_listType1.scrollPane.SetPercX(0, false);
  79. if (DressUpMenuItemDataManager.isLoading)
  80. {
  81. ViewManager.Show<LoadingView>();
  82. LoadingView.Instance.SetDesc("正在加载服装数据...");
  83. DressUpConfigUtil.LoadCount = 0;
  84. Timers.inst.StartCoroutine(UpdateLoadProgress());
  85. DressUpMenuItemDataManager.GetAllDressUpGuideIdListBySubTypeAsync();
  86. }
  87. else
  88. {
  89. UpdateItemIdListByType1(0);
  90. UpdateItemListUI();
  91. }
  92. if (_startInAnim)
  93. {
  94. _startInAnim = false;
  95. _ui.m_In.Play();
  96. }
  97. }
  98. protected override void OnHide()
  99. {
  100. base.OnHide();
  101. _itemIdList.Clear();
  102. _currentList2 = null;
  103. _filterStr = "";
  104. DressUpMenuItemDataManager.Clear();
  105. // 清空服装过滤界面选择
  106. EventAgent.DispatchEvent(ConstMessage.DRESS_FILTER_RESET_ALL);
  107. }
  108. /// <summary>
  109. /// 一级菜单的点击
  110. /// </summary>
  111. /// <param name="index"></param>
  112. /// <param name="item"></param>
  113. private void OnClickListType1Item(EventContext context)
  114. {
  115. GObject gObject = context.data as GObject;
  116. int index = _ui.m_listType1.GetChildIndex(gObject);
  117. if (_lastClickIndex.typeIndex == 1 && _lastClickIndex.index == index)
  118. {
  119. return;
  120. }
  121. UpdateItemIdListByType1(index);
  122. UpdateItemListUI();
  123. _ui.m_Refresh.Play();
  124. UI_Button21 button = UI_Button21.Proxy(gObject);
  125. button.m_fadeIn.Play();
  126. UI_Button21.ProxyEnd();
  127. }
  128. private IEnumerator UpdateLoadProgress()
  129. {
  130. while (DressUpMenuItemDataManager.isLoading)
  131. {
  132. int sum = GlobalCfgArray.globalCfg.ClothingPartsCount;
  133. LoadingView.Instance.SetProgress(FieldGuideView.ProgressCalculate(DressUpConfigUtil.LoadCount, sum));
  134. yield return new WaitForEndOfFrame();
  135. }
  136. LoadingView.Instance.SetProgress(100, () =>
  137. {
  138. ViewManager.Hide<LoadingView>();
  139. }
  140. );
  141. }
  142. private void RenderListDressUpItem(int index, GObject item)
  143. {
  144. if(index >= _itemIdList.Count)
  145. {
  146. return;
  147. }
  148. UI_ListDressUpPartsItem listItem = UI_ListDressUpPartsItem.Proxy(item);
  149. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemIdList[index]);
  150. listItem.m_icon.url = ResPathUtil.GetIconPath(itemCfg.res, "png");
  151. listItem.m_txtTitle.text = itemCfg.name;
  152. listItem.m_ScoreType.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + itemCfg.mainScore);
  153. listItem.m_unlockMask.visible = !DressUpMenuItemDataManager.CheckHasItem(itemCfg.id);
  154. RarityIconController.UpdateRarityIcon(listItem.m_rarity, _itemIdList[index], false);
  155. listItem.target.data = _itemIdList[index];
  156. UI_ListDressUpPartsItem.ProxyEnd();
  157. }
  158. private void OnClickListDressUpItem(EventContext eventContext)
  159. {
  160. int id = (int)(eventContext.data as GObject).data;
  161. object[] goBackDatas = ViewManager.GetGoBackDatas(typeof(DressUpGuideView).Name);
  162. object[] sourceDatas = new object[] { id, goBackDatas, 1 };
  163. GoodsItemTipsController.ShowItemTips(id, sourceDatas, DressUpMenuItemDataManager.CheckHasItem(id));
  164. }
  165. /// <summary>
  166. /// 二级菜单的点击
  167. /// </summary>
  168. /// <param name="index"></param>
  169. /// <param name="item"></param>
  170. private void OnClickListType2Item(EventContext eventContext)
  171. {
  172. GObject gObject = eventContext.data as GObject;
  173. int index = _ui.m_listType2.GetChildIndex(gObject);
  174. if (_lastClickIndex.typeIndex == 2 && _lastClickIndex.index == index)
  175. {
  176. return;
  177. }
  178. UpdateItemIdListByType2(index);
  179. UpdateItemListUI();
  180. _ui.m_Refresh.Play();
  181. }
  182. private void OnClickBtnAllAccessories()
  183. {
  184. // 点击饰品按钮回到一级菜单时,需要更新为 全部饰品 选项
  185. UpdateItemIdListByType2(0);
  186. UpdateItemListUI();
  187. ShowListType1();
  188. // 饰品
  189. _lastClickIndex.index = 9;
  190. }
  191. /// <summary>
  192. /// 根据一级菜单的按钮点击,更新itemIDList
  193. /// </summary>
  194. /// <param name="index">点击按钮的index</param>
  195. private void UpdateItemIdListByType1(int index)
  196. {
  197. _lastClickIndex.typeIndex = 1;
  198. _lastClickIndex.index = index;
  199. // 点击了“全部服装”
  200. if (index == 0)
  201. {
  202. _itemIdList = DressUpMenuItemDataManager.GetAllDressUpGuideIdListBySubType(0);
  203. }
  204. else
  205. {
  206. DressUpMenuItemCfg1 item1 = DressUpMenuItemCfg1Array.Instance.dataArray[index - 1];
  207. // 存在二级菜单
  208. if (item1.subMenusArr.Length > 0)
  209. {
  210. _currentList2 = item1.subMenusArr.Clone() as int[];
  211. List<int> types = new List<int>();
  212. for (int i = 0; i < _currentList2.Length; i++)
  213. {
  214. DressUpMenuItemCfg2 item2 = DressUpMenuItemCfg2Array.Instance.dataArray[_currentList2[i] - 1];
  215. types.Add(item2.type);
  216. }
  217. _itemIdList = DressUpMenuItemDataManager.GetAllDressUpGuideIdListBySubTypes(types);
  218. ShowListType2();
  219. }
  220. else
  221. {
  222. _itemIdList = DressUpMenuItemDataManager.GetAllDressUpGuideIdListBySubType(item1.type);
  223. }
  224. }
  225. _itemIdList = GetFilterList(_itemIdList, _filterStr);
  226. }
  227. /// <summary>
  228. /// 根据二级菜单的按钮点击,更新itemIDList
  229. /// </summary>
  230. /// <param name="index">点击按钮的index</param>
  231. private void UpdateItemIdListByType2(int index)
  232. {
  233. _lastClickIndex.typeIndex = 2;
  234. _lastClickIndex.index = index;
  235. if (index == 0)
  236. {
  237. List<int> types = new List<int>();
  238. for (int i = 0; i < _currentList2.Length; i++)
  239. {
  240. DressUpMenuItemCfg2 item2 = DressUpMenuItemCfg2Array.Instance.dataArray[_currentList2[i] - 1];
  241. types.Add(item2.type);
  242. }
  243. _itemIdList = DressUpMenuItemDataManager.GetAllDressUpGuideIdListBySubTypes(types);
  244. }
  245. else
  246. {
  247. DressUpMenuItemCfg2 item2 = DressUpMenuItemCfg2Array.Instance.dataArray[_currentList2[index - 1] - 1];
  248. _itemIdList = DressUpMenuItemDataManager.GetAllDressUpGuideIdListBySubType(item2.type);
  249. }
  250. _itemIdList = GetFilterList(_itemIdList, _filterStr);
  251. }
  252. /// <summary>
  253. /// 更新散件列表UI,及收集度
  254. /// </summary>
  255. private void UpdateItemListUI(bool refreshProgress = true)
  256. {
  257. int haveCount = 0;
  258. int totalCount = 0;
  259. _ui.m_listDressUp.numItems = _itemIdList.Count;
  260. _ui.m_listDressUp.scrollPane.ScrollTop();
  261. if (refreshProgress)
  262. {
  263. for (int i = 0; i < _itemIdList.Count; i++)
  264. {
  265. if (DressUpMenuItemDataManager.CheckHasItem(_itemIdList[i]))
  266. {
  267. ++haveCount;
  268. }
  269. ++totalCount;
  270. }
  271. UpdateProgress(haveCount, totalCount);
  272. }
  273. }
  274. private void ShowListType2()
  275. {
  276. _ui.m_c1.selectedIndex = 1;
  277. _ui.m_listType2.selectedIndex = 0;
  278. _ui.m_listType2.scrollPane.SetPercX(0, false);
  279. _lastClickIndex.typeIndex = 2;
  280. _lastClickIndex.index = 0;
  281. }
  282. private void ShowListType1()
  283. {
  284. _ui.m_c1.selectedIndex = 0;
  285. _lastClickIndex.typeIndex = 1;
  286. _currentList2 = null;
  287. }
  288. /// <summary>
  289. /// 更新收集进度
  290. /// </summary>
  291. private void UpdateProgress(int haveCount, int totalCount)
  292. {
  293. _ui.m_progressBar.target.max = totalCount;
  294. _ui.m_progressBar.target.value = haveCount;
  295. _ui.m_progressBar.m_title1.SetVar("value", haveCount.ToString()).SetVar("max", totalCount.ToString()).FlushVars();
  296. if(totalCount > 0)
  297. {
  298. _ui.m_progressBar.m_rate.SetVar("rate", FieldGuideView.ProgressCalculate(haveCount, totalCount).ToString()).FlushVars();
  299. }
  300. else
  301. {
  302. _ui.m_progressBar.m_rate.SetVar("rate", "0").FlushVars();
  303. }
  304. }
  305. private void OnClickBtnBack()
  306. {
  307. _startInAnim = true;
  308. ViewManager.GoBackFrom(typeof(DressUpGuideView).FullName);
  309. }
  310. private void OnClickBtnSearch()
  311. {
  312. ViewManager.Show<DressFilterView>(false);
  313. }
  314. private void FilterItems(EventContext context)
  315. {
  316. _filterStr = "";
  317. // 过滤之前,需要更新_itemIdList为全部物品
  318. if (_lastClickIndex.typeIndex == 1)
  319. {
  320. UpdateItemIdListByType1(_lastClickIndex.index);
  321. }
  322. else if (_lastClickIndex.typeIndex == 2)
  323. {
  324. UpdateItemIdListByType2(_lastClickIndex.index);
  325. }
  326. _filterStr = context.data.ToString();
  327. _itemIdList = GetFilterList(_itemIdList, _filterStr);
  328. UpdateItemListUI();
  329. ViewManager.Hide<ModalStatusView>();
  330. _ui.m_Refresh.Play();
  331. }
  332. private void LoadFinished()
  333. {
  334. UpdateItemIdListByType1(0);
  335. UpdateItemListUI();
  336. }
  337. private List<int> GetFilterList(List<int> list, string filterStr)
  338. {
  339. if (filterStr == ConstMessage.DRESS_SEARCH)
  340. {
  341. list = DressUpMenuItemDataManager.DressSearch(list, DressFilterItemType.DressUpItem);
  342. }
  343. else if (filterStr == ConstMessage.DRESS_FILTER)
  344. {
  345. list = DressUpMenuItemDataManager.DressFilter(list, DressFilterItemType.DressUpItem);
  346. }
  347. return list;
  348. }
  349. private void ResetFilterStr()
  350. {
  351. _filterStr = "";
  352. if (_lastClickIndex.typeIndex == 1)
  353. {
  354. UpdateItemIdListByType1(_lastClickIndex.index);
  355. }
  356. else if(_lastClickIndex.typeIndex == 2)
  357. {
  358. UpdateItemIdListByType2(_lastClickIndex.index);
  359. }
  360. UpdateItemListUI();
  361. }
  362. }
  363. }