DressUpGuideView.cs 11 KB

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