DressUpGuideView.cs 13 KB

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