DressUpGuideView.cs 14 KB

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