DressUpGuideView.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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. /// <summary>
  190. /// 根据一级菜单的按钮点击,更新itemIDList
  191. /// </summary>
  192. /// <param name="index">点击按钮的index</param>
  193. private void UpdateItemIdListByType1(int index)
  194. {
  195. _lastClickIndex.typeIndex = 1;
  196. _lastClickIndex.index = index;
  197. // 点击了“全部服装”
  198. if (index == 0)
  199. {
  200. _itemIdList = DressUpMenuItemDataManager.GetAllDressUpGuideIdListBySubType(0);
  201. }
  202. else
  203. {
  204. DressUpMenuItemCfg1 item1 = DressUpMenuItemCfg1Array.Instance.dataArray[index - 1];
  205. // 存在二级菜单
  206. if (item1.subMenusArr.Length > 0)
  207. {
  208. _currentList2 = item1.subMenusArr.Clone() as int[];
  209. List<int> types = new List<int>();
  210. for (int i = 0; i < _currentList2.Length; i++)
  211. {
  212. DressUpMenuItemCfg2 item2 = DressUpMenuItemCfg2Array.Instance.dataArray[_currentList2[i] - 1];
  213. types.Add(item2.type);
  214. }
  215. _itemIdList = DressUpMenuItemDataManager.GetAllDressUpGuideIdListBySubTypes(types);
  216. ShowListType2();
  217. }
  218. else
  219. {
  220. _itemIdList = DressUpMenuItemDataManager.GetAllDressUpGuideIdListBySubType(item1.type);
  221. }
  222. }
  223. _itemIdList = GetFilterList(_itemIdList, _filterStr);
  224. }
  225. /// <summary>
  226. /// 根据二级菜单的按钮点击,更新itemIDList
  227. /// </summary>
  228. /// <param name="index">点击按钮的index</param>
  229. private void UpdateItemIdListByType2(int index)
  230. {
  231. _lastClickIndex.typeIndex = 2;
  232. _lastClickIndex.index = index;
  233. if (index == 0)
  234. {
  235. List<int> types = new List<int>();
  236. for (int i = 0; i < _currentList2.Length; i++)
  237. {
  238. DressUpMenuItemCfg2 item2 = DressUpMenuItemCfg2Array.Instance.dataArray[_currentList2[i] - 1];
  239. types.Add(item2.type);
  240. }
  241. _itemIdList = DressUpMenuItemDataManager.GetAllDressUpGuideIdListBySubTypes(types);
  242. }
  243. else
  244. {
  245. DressUpMenuItemCfg2 item2 = DressUpMenuItemCfg2Array.Instance.dataArray[_currentList2[index - 1] - 1];
  246. _itemIdList = DressUpMenuItemDataManager.GetAllDressUpGuideIdListBySubType(item2.type);
  247. }
  248. _itemIdList = GetFilterList(_itemIdList, _filterStr);
  249. }
  250. /// <summary>
  251. /// 更新散件列表UI,及收集度
  252. /// </summary>
  253. private void UpdateItemListUI(bool refreshProgress = true)
  254. {
  255. int haveCount = 0;
  256. int totalCount = 0;
  257. _ui.m_listDressUp.numItems = _itemIdList.Count;
  258. _ui.m_listDressUp.scrollPane.ScrollTop();
  259. if (refreshProgress)
  260. {
  261. for (int i = 0; i < _itemIdList.Count; i++)
  262. {
  263. if (DressUpMenuItemDataManager.CheckHasItem(_itemIdList[i]))
  264. {
  265. ++haveCount;
  266. }
  267. ++totalCount;
  268. }
  269. UpdateProgress(haveCount, totalCount);
  270. }
  271. }
  272. private void ShowListType2()
  273. {
  274. _ui.m_c1.selectedIndex = 1;
  275. _ui.m_listType2.selectedIndex = 0;
  276. _ui.m_listType2.scrollPane.SetPercX(0, false);
  277. _lastClickIndex.typeIndex = 2;
  278. _lastClickIndex.index = 0;
  279. }
  280. private void ShowListType1()
  281. {
  282. _ui.m_c1.selectedIndex = 0;
  283. _currentList2 = null;
  284. }
  285. /// <summary>
  286. /// 更新收集进度
  287. /// </summary>
  288. private void UpdateProgress(int haveCount, int totalCount)
  289. {
  290. _ui.m_progressBar.target.max = totalCount;
  291. _ui.m_progressBar.target.value = haveCount;
  292. _ui.m_progressBar.m_title1.SetVar("value", haveCount.ToString()).SetVar("max", totalCount.ToString()).FlushVars();
  293. if(totalCount > 0)
  294. {
  295. _ui.m_progressBar.m_rate.SetVar("rate", FieldGuideView.ProgressCalculate(haveCount, totalCount).ToString()).FlushVars();
  296. }
  297. else
  298. {
  299. _ui.m_progressBar.m_rate.SetVar("rate", "0").FlushVars();
  300. }
  301. }
  302. private void OnClickBtnBack()
  303. {
  304. _startInAnim = true;
  305. ViewManager.GoBackFrom(typeof(DressUpGuideView).FullName);
  306. }
  307. private void OnClickBtnSearch()
  308. {
  309. ViewManager.Show<DressFilterView>(false);
  310. }
  311. private void FilterItems(EventContext context)
  312. {
  313. _filterStr = "";
  314. // 过滤之前,需要更新_itemIdList为全部物品
  315. if (_lastClickIndex.typeIndex == 1)
  316. {
  317. UpdateItemIdListByType1(_lastClickIndex.index);
  318. }
  319. else if (_lastClickIndex.typeIndex == 2)
  320. {
  321. UpdateItemIdListByType2(_lastClickIndex.index);
  322. }
  323. _filterStr = context.data.ToString();
  324. _itemIdList = GetFilterList(_itemIdList, _filterStr);
  325. UpdateItemListUI();
  326. ViewManager.Hide<ModalStatusView>();
  327. _ui.m_Refresh.Play();
  328. }
  329. private void LoadFinished()
  330. {
  331. UpdateItemIdListByType1(0);
  332. UpdateItemListUI();
  333. }
  334. private List<int> GetFilterList(List<int> list, string filterStr)
  335. {
  336. if (filterStr == ConstMessage.DRESS_SEARCH)
  337. {
  338. list = DressUpMenuItemDataManager.DressSearch(list, DressFilterItemType.DressUpItem);
  339. }
  340. else if (filterStr == ConstMessage.DRESS_FILTER)
  341. {
  342. list = DressUpMenuItemDataManager.DressFilter(list, DressFilterItemType.DressUpItem);
  343. }
  344. return list;
  345. }
  346. private void ResetFilterStr()
  347. {
  348. _filterStr = "";
  349. if (_lastClickIndex.typeIndex == 1)
  350. {
  351. UpdateItemIdListByType1(_lastClickIndex.index);
  352. }
  353. else if(_lastClickIndex.typeIndex == 2)
  354. {
  355. UpdateItemIdListByType2(_lastClickIndex.index);
  356. }
  357. UpdateItemListUI();
  358. }
  359. }
  360. }