DressUpGuideView.cs 12 KB

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