DressUpGuideView.cs 14 KB

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