DressUpGuideView.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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. //TODO 看看要怎么重新做换装数据加载
  138. // LoadingView.Instance.SetProgress(FieldGuideView.ProgressCalculate(DressUpConfigUtil.LoadCount, sum));
  139. yield return new WaitForEndOfFrame();
  140. }
  141. LoadingView.Instance.SetProgress(100, () => { ViewManager.Hide<LoadingView>(); }
  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 =
  217. CommonDataManager.Tables.TblDressUpMenuItemCfg2.DataList[_currentList2[i] - 1];
  218. types.Add(item2.Type);
  219. }
  220. _itemIdList = DressUpMenuItemDataManager.GetAllDressUpGuideIdListBySubTypes(types);
  221. ShowListType2();
  222. }
  223. else
  224. {
  225. _itemIdList = DressUpMenuItemDataManager.GetAllDressUpGuideIdListBySubType(item1.Type);
  226. }
  227. }
  228. _itemIdList = GetFilterList(_itemIdList, _filterStr);
  229. }
  230. /// <summary>
  231. /// 根据二级菜单的按钮点击,更新itemIDList
  232. /// </summary>
  233. /// <param name="index">点击按钮的index</param>
  234. private void UpdateItemIdListByType2(int index)
  235. {
  236. _lastClickIndex.typeIndex = 2;
  237. _lastClickIndex.index = index;
  238. if (index == 0)
  239. {
  240. List<int> types = new List<int>();
  241. for (int i = 0; i < _currentList2.Count; i++)
  242. {
  243. DressUpMenuItemCfg2 item2 =
  244. CommonDataManager.Tables.TblDressUpMenuItemCfg2.DataList[_currentList2[i] - 1];
  245. types.Add(item2.Type);
  246. }
  247. _itemIdList = DressUpMenuItemDataManager.GetAllDressUpGuideIdListBySubTypes(types);
  248. }
  249. else
  250. {
  251. DressUpMenuItemCfg2 item2 =
  252. CommonDataManager.Tables.TblDressUpMenuItemCfg2.DataList[_currentList2[index - 1] - 1];
  253. _itemIdList = DressUpMenuItemDataManager.GetAllDressUpGuideIdListBySubType(item2.Type);
  254. }
  255. _itemIdList = GetFilterList(_itemIdList, _filterStr);
  256. }
  257. /// <summary>
  258. /// 更新散件列表UI,及收集度
  259. /// </summary>
  260. private void UpdateItemListUI(bool refreshProgress = true)
  261. {
  262. int haveCount = 0;
  263. int totalCount = 0;
  264. _ui.m_listDressUp.numItems = _itemIdList.Count;
  265. _ui.m_listDressUp.scrollPane.ScrollTop();
  266. if (refreshProgress)
  267. {
  268. for (int i = 0; i < _itemIdList.Count; i++)
  269. {
  270. if (DressUpMenuItemDataManager.CheckHasItem(_itemIdList[i]))
  271. {
  272. ++haveCount;
  273. }
  274. ++totalCount;
  275. }
  276. UpdateProgress(haveCount, totalCount);
  277. }
  278. }
  279. private void ShowListType2()
  280. {
  281. _ui.m_c1.selectedIndex = 1;
  282. _ui.m_listType2.selectedIndex = 0;
  283. _ui.m_listType2.scrollPane.SetPercX(0, false);
  284. _lastClickIndex.typeIndex = 2;
  285. _lastClickIndex.index = 0;
  286. }
  287. private void ShowListType1()
  288. {
  289. _ui.m_c1.selectedIndex = 0;
  290. _lastClickIndex.typeIndex = 1;
  291. _currentList2 = null;
  292. }
  293. /// <summary>
  294. /// 更新收集进度
  295. /// </summary>
  296. private void UpdateProgress(int haveCount, int totalCount)
  297. {
  298. _ui.m_progressBar.target.max = totalCount;
  299. _ui.m_progressBar.target.value = haveCount;
  300. _ui.m_progressBar.m_title1.SetVar("value", haveCount.ToString()).SetVar("max", totalCount.ToString())
  301. .FlushVars();
  302. if (totalCount > 0)
  303. {
  304. _ui.m_progressBar.m_rate
  305. .SetVar("rate", FieldGuideView.ProgressCalculate(haveCount, totalCount).ToString()).FlushVars();
  306. }
  307. else
  308. {
  309. _ui.m_progressBar.m_rate.SetVar("rate", "0").FlushVars();
  310. }
  311. }
  312. private void OnClickBtnBack()
  313. {
  314. _startInAnim = true;
  315. ViewManager.GoBackFrom(typeof(DressUpGuideView).FullName);
  316. }
  317. private void OnClickBtnSearch()
  318. {
  319. ViewManager.Show<DressFilterView>(false);
  320. }
  321. private void FilterItems(EventContext context)
  322. {
  323. _filterStr = "";
  324. // 过滤之前,需要更新_itemIdList为全部物品
  325. if (_lastClickIndex.typeIndex == 1)
  326. {
  327. UpdateItemIdListByType1(_lastClickIndex.index);
  328. }
  329. else if (_lastClickIndex.typeIndex == 2)
  330. {
  331. UpdateItemIdListByType2(_lastClickIndex.index);
  332. }
  333. _filterStr = context.data.ToString();
  334. _itemIdList = GetFilterList(_itemIdList, _filterStr);
  335. UpdateItemListUI();
  336. ViewManager.Hide<ModalStatusView>();
  337. _ui.m_Refresh.Play();
  338. }
  339. private void LoadFinished()
  340. {
  341. UpdateItemIdListByType1(0);
  342. UpdateItemListUI();
  343. }
  344. private List<int> GetFilterList(List<int> list, string filterStr)
  345. {
  346. if (filterStr == ConstMessage.DRESS_SEARCH)
  347. {
  348. list = DressUpMenuItemDataManager.DressSearch(list, DressFilterItemType.DressUpItem);
  349. }
  350. else if (filterStr == ConstMessage.DRESS_FILTER)
  351. {
  352. list = DressUpMenuItemDataManager.DressFilter(list, DressFilterItemType.DressUpItem);
  353. }
  354. return list;
  355. }
  356. private void ResetFilterStr()
  357. {
  358. _filterStr = "";
  359. if (_lastClickIndex.typeIndex == 1)
  360. {
  361. UpdateItemIdListByType1(_lastClickIndex.index);
  362. }
  363. else if (_lastClickIndex.typeIndex == 2)
  364. {
  365. UpdateItemIdListByType2(_lastClickIndex.index);
  366. }
  367. UpdateItemListUI();
  368. }
  369. }
  370. }