DressUpGuideView.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. using FairyGUI;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UI.FieldGuide;
  6. using UnityEngine;
  7. namespace GFGGame
  8. {
  9. /// <summary>
  10. /// 服装图鉴界面
  11. /// </summary>
  12. public class DressUpGuideView : BaseWindow
  13. {
  14. private UI_DressUpGuideUI _ui;
  15. private List<int> _itemIdList;
  16. // 上次点击单选按钮的index
  17. private struct LastClickIndex
  18. {
  19. public int typeIndex;
  20. public int index;
  21. }
  22. private LastClickIndex _lastClickIndex;
  23. private int[] _currentList2;
  24. public override void Dispose()
  25. {
  26. if (_ui != null)
  27. {
  28. _ui.Dispose();
  29. _ui = null;
  30. }
  31. base.Dispose();
  32. }
  33. protected override void OnInit()
  34. {
  35. base.OnInit();
  36. packageName = UI_DressUpGuideUI.PACKAGE_NAME;
  37. _ui = UI_DressUpGuideUI.Create();
  38. this.viewCom = _ui.target;
  39. isfullScreen = true;
  40. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("quanping_moren_bg");
  41. _itemIdList = new List<int>();
  42. _ui.m_btnSearch.onClick.Add(OnClickBtnSearch);
  43. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  44. _ui.m_listType1.onClickItem.Add(OnClickListType1Item);
  45. _ui.m_listType2.onClickItem.Add(OnClickListType2Item);
  46. _ui.m_listDressUp.itemRenderer = RenderListDressUpItem;
  47. _ui.m_listDressUp.onClickItem.Add(OnClickListDressUpItem);
  48. _ui.m_listDressUp.SetVirtual();
  49. _ui.m_btnAccessories.onClick.Add(OnClickBtnAllAccessories);
  50. }
  51. protected override void AddEventListener()
  52. {
  53. base.AddEventListener();
  54. EventAgent.AddEventListener(ConstMessage.DRESS_SEARCH, FilterItems);
  55. EventAgent.AddEventListener(ConstMessage.DRESS_FILTER, FilterItems);
  56. }
  57. protected override void RemoveEventListener()
  58. {
  59. base.RemoveEventListener();
  60. EventAgent.RemoveEventListener(ConstMessage.DRESS_SEARCH, FilterItems);
  61. EventAgent.RemoveEventListener(ConstMessage.DRESS_FILTER, FilterItems);
  62. }
  63. protected override void OnShown()
  64. {
  65. base.OnShown();
  66. _ui.m_listType1.selectedIndex = 0;
  67. _ui.m_c1.selectedIndex = 0;
  68. _ui.m_listType1.scrollPane.SetPercX(0,false);
  69. UpdateItemIdListByType1(0);
  70. UpdateItemList();
  71. }
  72. protected override void OnHide()
  73. {
  74. base.OnHide();
  75. _itemIdList.Clear();
  76. _currentList2 = null;
  77. DressUpMenuItemDataManager.Clear();
  78. }
  79. /// <summary>
  80. /// 一级菜单的点击
  81. /// </summary>
  82. /// <param name="index"></param>
  83. /// <param name="item"></param>
  84. private void OnClickListType1Item(EventContext context)
  85. {
  86. GObject gObject = context.data as GObject;
  87. int index = _ui.m_listType1.GetChildIndex(gObject);
  88. if(_lastClickIndex.typeIndex == 1 && _lastClickIndex.index == index)
  89. {
  90. return;
  91. }
  92. UpdateItemIdListByType1(index);
  93. UpdateItemList();
  94. }
  95. private void RenderListDressUpItem(int index, GObject item)
  96. {
  97. UI_ListDressUpPartsItem listItem = UI_ListDressUpPartsItem.Proxy(item);
  98. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemIdList[index]);
  99. listItem.m_icon.url = ResPathUtil.GetIconPath(itemCfg.res, "png");
  100. listItem.m_txtTitle.text = itemCfg.name;
  101. listItem.m_ScoreType.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + itemCfg.mainScore);
  102. listItem.m_unlockMask.visible = !DressUpMenuItemDataManager.CheckHasItem(itemCfg.id);
  103. RarityIconController.UpdateRarityIcon(listItem.m_rarity, _itemIdList[index], false);
  104. listItem.target.data = _itemIdList[index];
  105. UI_ListDressUpPartsItem.ProxyEnd();
  106. }
  107. private void OnClickListDressUpItem(EventContext eventContext)
  108. {
  109. int id = (int)(eventContext.data as GObject).data;
  110. object[] goBackDatas = ViewManager.GetGoBackDatas(typeof(CardGuideView).Name);
  111. object[] sourceDatas = new object[] { id, goBackDatas, 1 };
  112. GoodsItemTipsController.ShowItemTips(id, sourceDatas, DressUpMenuItemDataManager.CheckHasItem(id));
  113. }
  114. /// <summary>
  115. /// 二级菜单的点击
  116. /// </summary>
  117. /// <param name="index"></param>
  118. /// <param name="item"></param>
  119. private void OnClickListType2Item(EventContext eventContext)
  120. {
  121. GObject gObject = eventContext.data as GObject;
  122. int index = _ui.m_listType2.GetChildIndex(gObject);
  123. if (_lastClickIndex.typeIndex == 2 && _lastClickIndex.index == index)
  124. {
  125. return;
  126. }
  127. UpdateItemIdListByType2(index);
  128. UpdateItemList();
  129. }
  130. private void OnClickBtnAllAccessories()
  131. {
  132. // 点击饰品按钮回到一级菜单时,需要更新为 全部饰品 选项
  133. UpdateItemIdListByType2(0);
  134. UpdateItemList();
  135. ShowListType1();
  136. }
  137. /// <summary>
  138. /// 根据一级菜单的按钮点击,更新itemIDList
  139. /// </summary>
  140. /// <param name="index">点击按钮的index</param>
  141. private void UpdateItemIdListByType1(int index)
  142. {
  143. _lastClickIndex.typeIndex = 1;
  144. _lastClickIndex.index = index;
  145. // 点击了“全部服装”
  146. if (index == 0)
  147. {
  148. _itemIdList = DressUpMenuItemDataManager.GetAllDressUpGuideIdListBySubType(0);
  149. }
  150. else
  151. {
  152. DressUpMenuItemCfg1 item1 = DressUpMenuItemCfg1Array.Instance.dataArray[index - 1];
  153. // 存在二级菜单
  154. if (item1.subMenusArr.Length > 0)
  155. {
  156. _itemIdList.Clear();
  157. _currentList2 = item1.subMenusArr.Clone() as int[];
  158. for (int i = 0; i < item1.subMenusArr.Length; i++)
  159. {
  160. DressUpMenuItemCfg2 item2 = DressUpMenuItemCfg2Array.Instance.dataArray[_currentList2[i] - 1];
  161. _itemIdList.AddRange(DressUpMenuItemDataManager.GetAllDressUpGuideIdListBySubType(item2.type, false));
  162. }
  163. DressUpMenuItemDataManager.SortDressUpGuideIdList(_itemIdList);
  164. ShowListType2();
  165. }
  166. else
  167. {
  168. _itemIdList = DressUpMenuItemDataManager.GetAllDressUpGuideIdListBySubType(item1.type);
  169. }
  170. }
  171. }
  172. /// <summary>
  173. /// 根据二级菜单的按钮点击,更新itemIDList
  174. /// </summary>
  175. /// <param name="index">点击按钮的index</param>
  176. private void UpdateItemIdListByType2(int index)
  177. {
  178. _lastClickIndex.typeIndex = 2;
  179. _lastClickIndex.index = index;
  180. if (index == 0)
  181. {
  182. _itemIdList.Clear();
  183. for (int i = 0; i < _currentList2.Length; i++)
  184. {
  185. DressUpMenuItemCfg2 item2 = DressUpMenuItemCfg2Array.Instance.dataArray[_currentList2[i] - 1];
  186. _itemIdList.AddRange(DressUpMenuItemDataManager.GetAllDressUpGuideIdListBySubType(item2.type, false));
  187. }
  188. DressUpMenuItemDataManager.SortDressUpGuideIdList(_itemIdList);
  189. }
  190. else
  191. {
  192. DressUpMenuItemCfg2 item2 = DressUpMenuItemCfg2Array.Instance.dataArray[_currentList2[index - 1] - 1];
  193. _itemIdList = DressUpMenuItemDataManager.GetAllDressUpGuideIdListBySubType(item2.type);
  194. }
  195. }
  196. /// <summary>
  197. /// 更新散件列表UI,及收集度
  198. /// </summary>
  199. private void UpdateItemList(bool refreshProgress = true)
  200. {
  201. int haveCount = 0;
  202. int totalCount = 0;
  203. _ui.m_listDressUp.numItems = _itemIdList.Count;
  204. _ui.m_listDressUp.scrollPane.ScrollTop();
  205. if (refreshProgress)
  206. {
  207. for (int i = 0; i < _itemIdList.Count; i++)
  208. {
  209. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemIdList[i]);
  210. if (DressUpMenuItemDataManager.CheckHasItem(itemCfg.id))
  211. {
  212. ++haveCount;
  213. }
  214. ++totalCount;
  215. }
  216. UpdateProgress(haveCount, totalCount);
  217. }
  218. }
  219. private void ShowListType2()
  220. {
  221. _ui.m_c1.selectedIndex = 1;
  222. _ui.m_listType2.selectedIndex = 0;
  223. _ui.m_listType2.scrollPane.SetPercX(0, false);
  224. }
  225. private void ShowListType1()
  226. {
  227. _ui.m_c1.selectedIndex = 0;
  228. _currentList2 = null;
  229. }
  230. /// <summary>
  231. /// 更新收集进度
  232. /// </summary>
  233. private void UpdateProgress(int haveCount, int totalCount)
  234. {
  235. _ui.m_progressBar.target.max = totalCount;
  236. _ui.m_progressBar.target.value = haveCount;
  237. _ui.m_progressBar.m_title1.SetVar("value", haveCount.ToString()).SetVar("max", totalCount.ToString()).FlushVars();
  238. _ui.m_progressBar.m_rate.SetVar("rate", FieldGuideView.ProgressCalculate(haveCount, totalCount).ToString()).FlushVars();
  239. }
  240. private void OnClickBtnBack()
  241. {
  242. ViewManager.GoBackFrom(typeof(DressUpGuideView).FullName);
  243. }
  244. private void OnClickBtnSearch()
  245. {
  246. ViewManager.Show<DressFilterView>(false, new object[] { ViewName.DRESS_UP_VIEW });
  247. }
  248. private void FilterItems(EventContext context)
  249. {
  250. if(_lastClickIndex.typeIndex == 1)
  251. {
  252. UpdateItemIdListByType1(_lastClickIndex.index);
  253. }
  254. else if(_lastClickIndex.typeIndex == 2)
  255. {
  256. UpdateItemIdListByType2(_lastClickIndex.index);
  257. }
  258. if (context.data.ToString() == ConstMessage.DRESS_SEARCH)
  259. {
  260. _itemIdList = DressUpMenuItemDataManager.DressSearch(_itemIdList);
  261. }
  262. else if(context.data.ToString() == ConstMessage.DRESS_FILTER)
  263. {
  264. _itemIdList = DressUpMenuItemDataManager.DressFilter(_itemIdList);
  265. }
  266. ViewManager.Hide<ModalStatusView>();
  267. UpdateItemList(false);
  268. }
  269. }
  270. }