DressUpView.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. using UI.DressUp;
  2. using FairyGUI;
  3. using UnityEngine;
  4. using System.Collections.Generic;
  5. namespace GFGGame
  6. {
  7. public class DressUpView : BaseView
  8. {
  9. public const int BOTTOM_BLANK = 20;
  10. public const int RIGHT_BLANK = 36;
  11. private const int SORT_BY_HIGH_RARITY = 0;
  12. private const int SORT_BY_LOW_RARITY = 1;
  13. private const int SORT_BY_GET_TIME = 2;
  14. private UI_DressUpUI _ui;
  15. private float listType1X = 0;
  16. private float partsListX = 0;
  17. private DressUpListType currentListType;
  18. private int[] _currentList2;
  19. private GameObject _scenePrefab;
  20. private GameObject _sceneObject;
  21. private List<int> _currentList3;
  22. private int _currentMenuType;
  23. private int _rarityIndex = SORT_BY_HIGH_RARITY;
  24. public override void Dispose()
  25. {
  26. if (_scenePrefab != null)
  27. {
  28. GameObject.Destroy(_scenePrefab);
  29. _scenePrefab = null;
  30. }
  31. UI_TypeItem.ClearProxy();
  32. base.Dispose();
  33. }
  34. protected override void Init()
  35. {
  36. base.Init();
  37. packageName = UI_DressUpUI.PACKAGE_NAME;
  38. _ui = UI_DressUpUI.Create();
  39. viewCom = _ui.target;
  40. isfullScreen = true;
  41. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneDressUp"));
  42. }
  43. protected override void OnInit()
  44. {
  45. base.OnInit();
  46. _ui.m_btnLastStep.visible = false;
  47. _ui.m_btnNextStep.visible = false;
  48. _ui.m_btnSearch.visible = true;
  49. _ui.m_btnPhoto.visible = true;
  50. _ui.m_btnAction.visible = false;
  51. _ui.m_comboBox.items = new string[] { "我的套装一", "我的套装二", "我的套装三", "我的套装四", "我的套装五", "我的套装六" };
  52. _ui.m_partsList.m_comboBoxRarity.items = new string[] { "高稀有度", "低稀有度", "最近获得" };
  53. InitLists();
  54. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  55. _ui.m_btnHome.onClick.Add(OnClickBtnHome);
  56. _ui.m_comboBox.onChanged.Add(OnComboBoxChanged);
  57. _ui.m_comListType1.m_listType.onClickItem.Add(OnClickListType1Item);
  58. _ui.m_comListType2.m_listType.onClickItem.Add(OnClickListType2Item);
  59. _ui.m_partsList.m_list.onClickItem.Add(OnClickPartsListItem);
  60. _ui.m_touchPad.onClick.Add(OnTouchPad);
  61. _ui.m_btnDelete.onClick.Add(OnClickBtnDelete);
  62. _ui.m_btnSave.onClick.Add(OnClickBtnSave);
  63. _ui.m_partsList.m_comboBoxRarity.onChanged.Add(OnComboBoxRarityChanged);
  64. _ui.m_btnAction.onClick.Add(OnClickBtnAction);
  65. _ui.m_btnSearch.onClick.Add(OnClickBtnSearch);
  66. _ui.m_btnShow.onClick.Add(OnClickBtnShow);
  67. _ui.m_btnHide.onClick.Add(OnClickBtnHide);
  68. _ui.m_loaShow.onClick.Add(OnClickLoaShow);
  69. _ui.m_btnPhoto.onClick.Add(OnClickBtnPhoto);
  70. EventAgent.AddEventListener(ConstMessage.DRESS_FILTER, UpdatePartsListSort);
  71. EventAgent.AddEventListener(ConstMessage.DRESS_SEARCH, UpdatePartsListSort);
  72. EventAgent.AddEventListener(ConstMessage.CLOSE_PHOTOGRAPHVIEW, UpdateScene);
  73. }
  74. protected override void OnShown()
  75. {
  76. base.OnShown();
  77. _rarityIndex = SORT_BY_HIGH_RARITY;
  78. MusicManager.Instance.Play(ResPathUtil.GetMusicPath(ConstMusicName.DRESS_UP, "mp3"));
  79. _ui.m_comListType1.target.x = _ui.target.width;
  80. _ui.m_comListType2.target.x = _ui.target.width;
  81. _ui.m_partsList.target.x = _ui.target.width;
  82. this.showListType1();
  83. if (_sceneObject == null)
  84. {
  85. _sceneObject = GameObject.Instantiate(_scenePrefab);
  86. EquipDataCache.cacher.setSceneObj(_sceneObject);
  87. }
  88. _ui.m_comboBox.selectedIndex = CustomSuitDataManager.currentIndex;
  89. EquipDataCache.cacher.PutOnCurrentSuitSaved();
  90. GuideController.TryGuideDressUpViewMenuType1(_ui.m_comListType1.m_listType);
  91. GuideController.TryGuideDressUpViewMenuType2(_ui.m_btnPhoto);
  92. }
  93. protected override void OnHide()
  94. {
  95. base.OnHide();
  96. GuideController.HideGuide();
  97. MusicManager.Instance.Play(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT));
  98. if (_sceneObject != null)
  99. {
  100. GameObject.Destroy(_sceneObject);
  101. _sceneObject = null;
  102. }
  103. }
  104. private void OnClickBtnBack()
  105. {
  106. Reset();
  107. GuideController.TryCompleteGuide(ConstGuideId.DRESS_UP_VIEW_BTN_BACK);
  108. this.Hide();
  109. ViewManager.Show(ViewName.MAINUI_VIEW);
  110. }
  111. private void OnClickBtnHome()
  112. {
  113. GameController.GoBackToMainView();
  114. Reset();
  115. }
  116. private void Reset()
  117. {
  118. DressUpMenuItemDataManager.dressFilterType = DressFilterType.None;
  119. DressUpMenuItemDataManager.selectRarityList.Clear();
  120. DressUpMenuItemDataManager.selectScoreList.Clear();
  121. DressUpMenuItemDataManager.selectTagList.Clear();
  122. DressUpMenuItemDataManager.dressSearchTxt = "";
  123. }
  124. private void OnComboBoxChanged()
  125. {
  126. EquipDataCache.cacher.PutOnSuitSaved(_ui.m_comboBox.selectedIndex);
  127. }
  128. private void OnClickListType1Item(EventContext context)
  129. {
  130. GuideController.HideGuide();
  131. GObject typeItem = (GObject)context.data as GObject;
  132. int order = (int)typeItem.data;
  133. DressUpMenuItemCfg1 item1 = DressUpMenuItemCfg1Array.Instance.dataArray[order - 1];
  134. if (item1.subMenusArr.Length > 0)
  135. {
  136. this.showListType2(item1.subMenusArr);
  137. }
  138. else
  139. {
  140. this.showListParts(item1.type);
  141. GuideController.TryGuideDressUpViewMenuPart(_ui.m_partsList.m_list);
  142. }
  143. this.hideListType1();
  144. }
  145. private void OnClickListType2Item(EventContext context)
  146. {
  147. GObject typeItem = (GObject)context.data as GObject;
  148. int order = (int)typeItem.data;
  149. DressUpMenuItemCfg2 item2 = DressUpMenuItemCfg2Array.Instance.dataArray[order - 1];
  150. this.showListParts(item2.type);
  151. this.hideListType2();
  152. }
  153. private void OnClickPartsListItem(EventContext context)
  154. {
  155. GuideController.TryGuideByGuideId(_ui.m_btnSave, ConstGuideId.MAIN_UI_BTN_HUAN_ZHUANG, 1, false, "搭配好的服饰,可以保存随时查看");
  156. GObject listItem = (GObject)context.data as GObject;
  157. int id = (int)listItem.data;
  158. if (_currentMenuType == (int)ConstDressUpItemType.TAO_ZHUANG)
  159. {
  160. EquipDataCache.cacher.PutOnSuitCfg(id, true, false);
  161. UpdateBtnAction();
  162. }
  163. else
  164. {
  165. EquipDataCache.cacher.TryCancelSuit(id);
  166. EquipDataCache.cacher.AddOrRemove(id, true);
  167. UpdateListPartsSelected();
  168. }
  169. }
  170. private void OnTouchPad()
  171. {
  172. if (this.currentListType == DressUpListType.List3)
  173. {
  174. if (_currentList2 != null)
  175. {
  176. this.showListType2();
  177. }
  178. else
  179. {
  180. this.showListType1();
  181. }
  182. this.hideListParts();
  183. }
  184. else if (this.currentListType == DressUpListType.List2)
  185. {
  186. this.showListType1();
  187. this.hideListType2();
  188. }
  189. }
  190. private void OnClickBtnDelete()
  191. {
  192. EquipDataCache.cacher.TakeOffAll();
  193. }
  194. private void OnClickBtnSave()
  195. {
  196. GuideController.TryCompleteGuide(ConstGuideId.MAIN_UI_BTN_HUAN_ZHUANG);
  197. GuideController.TryGuideByGuideId(_ui.m_btnBack, ConstGuideId.DRESS_UP_VIEW_BTN_BACK, 1, false, "保存成功,回主界面看看吧", 0, ConstGuideId.MAIN_UI_BTN_HUAN_ZHUANG);
  198. CustomSuitDataManager.SaveCurrentSuit(_ui.m_comboBox.selectedIndex);
  199. PromptController.Instance.ShowFloatTextPrompt("保存成功", MessageType.SUCCESS);
  200. }
  201. private void OnComboBoxRarityChanged()
  202. {
  203. _rarityIndex = _ui.m_partsList.m_comboBoxRarity.selectedIndex;
  204. this.UpdatePartsListSort();
  205. }
  206. private void OnClickBtnAction()
  207. {
  208. if (!_ui.m_btnAction.grayed)
  209. {
  210. EquipDataCache.cacher.ChangeAction();
  211. }
  212. }
  213. private void OnClickBtnSearch()
  214. {
  215. ViewManager.Show<DressFilterView>(true, new object[] { ViewName.DRESS_UP_VIEW });
  216. }
  217. private void InitLists()
  218. {
  219. _ui.m_comListType2.m_listType.itemRenderer = ListType2Item;
  220. _ui.m_partsList.m_list.itemRenderer = ListPartsItem;
  221. listType1X = _ui.m_comListType1.target.x;
  222. partsListX = _ui.m_partsList.target.x - _ui.m_partsList.target.width - DressUpView.RIGHT_BLANK;
  223. //一级菜单
  224. _ui.m_comListType1.m_listType.itemRenderer = ListType1Item;
  225. _ui.m_comListType1.m_listType.numItems = DressUpMenuItemCfg1Array.Instance.dataArray.Length;
  226. //_ui.m_comListType1.m_listType1.ResizeToFit(_ui.m_comListType1.m_listType1.numItems);
  227. float maxHeight = _ui.target.height - _ui.m_comListType1.target.y - DressUpView.BOTTOM_BLANK;
  228. if (_ui.m_comListType1.m_listType.height > maxHeight)
  229. {
  230. _ui.m_comListType1.m_listType.height = maxHeight;
  231. }
  232. }
  233. private void showListType1()
  234. {
  235. _currentList2 = null;
  236. currentListType = DressUpListType.List1;
  237. GTween.To(_ui.target.width, listType1X, 0.5f)
  238. .SetTarget(_ui.m_comListType1.target)
  239. .OnUpdate((GTweener t) =>
  240. {
  241. _ui.m_comListType1.target.x = t.value.x;
  242. });
  243. }
  244. private void hideListType1()
  245. {
  246. GTween.To(listType1X, _ui.target.width, 0.5f)
  247. .SetTarget(_ui.m_comListType1.target)
  248. .OnUpdate((GTweener t) =>
  249. {
  250. _ui.m_comListType1.target.x = t.value.x;
  251. });
  252. }
  253. private void showListType2(int[] menuStrArr = null)
  254. {
  255. currentListType = DressUpListType.List2;
  256. if (menuStrArr != null && menuStrArr.Length > 0)
  257. {
  258. int len = menuStrArr.Length;
  259. _currentList2 = menuStrArr.Clone() as int[];
  260. _ui.m_comListType2.m_listType.RemoveChildrenToPool();
  261. _ui.m_comListType2.m_listType.numItems = len;
  262. //_ui.m_comListType2.m_listType2.ResizeToFit(_ui.m_comListType2.m_listType2.numItems);
  263. float maxHeight = _ui.target.height - _ui.m_comListType2.m_listType.y - DressUpView.BOTTOM_BLANK;
  264. if (_ui.m_comListType2.m_listType.height > maxHeight)
  265. {
  266. _ui.m_comListType2.m_listType.height = maxHeight;
  267. }
  268. }
  269. GTween.To(_ui.target.width, listType1X, 0.5f)
  270. .SetTarget(_ui.m_comListType2.target)
  271. .OnUpdate((GTweener t) =>
  272. {
  273. _ui.m_comListType2.target.x = t.value.x;
  274. });
  275. }
  276. private void hideListType2()
  277. {
  278. GTween.To(listType1X, _ui.target.width, 0.5f)
  279. .SetTarget(_ui.m_comListType2.target)
  280. .OnUpdate((GTweener t) =>
  281. {
  282. _ui.m_comListType2.target.x = t.value.x;
  283. });
  284. }
  285. private void showListParts(int type)
  286. {
  287. _currentMenuType = type;
  288. if (type == (int)ConstDressUpItemType.TAO_ZHUANG)
  289. {
  290. _ui.m_partsList.m_comboBoxRarity.items = new string[] { "高稀有度", "低稀有度", "最近获得" };
  291. if (_rarityIndex >= SORT_BY_GET_TIME)
  292. {
  293. _rarityIndex = SORT_BY_HIGH_RARITY;
  294. }
  295. }
  296. else
  297. {
  298. _ui.m_partsList.m_comboBoxRarity.items = new string[] { "高稀有度", "低稀有度", "最近获得" };
  299. }
  300. this.UpdatePartsListSort();
  301. _ui.m_partsList.m_list.ResizeToFit(_ui.m_partsList.m_list.numItems);
  302. float maxHeight = _ui.m_partsList.target.height - _ui.m_partsList.m_list.y;// - DressUpView.BOTTOM_BLANK;
  303. if (_ui.m_partsList.m_list.height > maxHeight)
  304. {
  305. _ui.m_partsList.m_list.height = maxHeight;
  306. }
  307. currentListType = DressUpListType.List3;
  308. GTween.To(_ui.target.width, partsListX, 0.5f)
  309. .SetTarget(_ui.m_partsList)
  310. .OnUpdate((GTweener t) =>
  311. {
  312. _ui.m_partsList.target.x = t.value.x;
  313. });
  314. UpdateBtnAction();
  315. }
  316. private void hideListParts()
  317. {
  318. _currentMenuType = 0;
  319. UpdateBtnAction();
  320. GTween.To(partsListX, _ui.target.width, 0.5f)
  321. .SetTarget(_ui.m_partsList)
  322. .OnUpdate((GTweener t) =>
  323. {
  324. _ui.m_partsList.target.x = t.value.x;
  325. });
  326. }
  327. private void ListType1Item(int index, GObject item)
  328. {
  329. UI_TypeItem typeItem = UI_TypeItem.Proxy(item);
  330. DressUpMenuItemCfg1 item1 = DressUpMenuItemCfg1Array.Instance.dataArray[index];
  331. typeItem.m_icon.url = "ui://DressUp/hz_fenleitu_" + item1.id;
  332. //typeItem.m_imgTitle.url = "ui://DressUp/hz_iconzi_" + item1.id;
  333. typeItem.target.data = item1.id;
  334. typeItem.m_imgNeed.visible = false;
  335. }
  336. private void ListType2Item(int index, GObject item)
  337. {
  338. UI_TypeItem typeItem = UI_TypeItem.Proxy(item);
  339. DressUpMenuItemCfg2 item2 = DressUpMenuItemCfg2Array.Instance.dataArray[_currentList2[index] - 1];
  340. typeItem.m_icon.url = "ui://DressUp/hz_fenleituej_" + item2.id;
  341. //typeItem.m_imgTitle.url = "ui://DressUp/hz_iconziej_" + item2.id;
  342. typeItem.target.data = item2.id;
  343. typeItem.m_imgNeed.visible = false;
  344. }
  345. private void ListPartsItem(int index, GObject item)
  346. {
  347. UI_PartsListItem listItem = UI_PartsListItem.Proxy(item);
  348. int id = (int)_currentList3[index];
  349. string iconRes = "";
  350. string partName = "";
  351. string ext = "png";
  352. if (_currentMenuType == (int)ConstDressUpItemType.TAO_ZHUANG)
  353. {
  354. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(id);
  355. iconRes = suitCfg.res;
  356. partName = suitCfg.name;
  357. listItem.m_iconSelected.visible = false;
  358. RarityIconController.UpdateRarityIcon(listItem.m_rarity, id, false, true);
  359. listItem.m_ScoreType.visible = false;
  360. }
  361. else
  362. {
  363. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(id);
  364. iconRes = itemCfg.res;
  365. partName = itemCfg.name;
  366. listItem.m_iconSelected.visible = EquipDataCache.cacher.CheckDressUpItemIsOn(id);
  367. RarityIconController.UpdateRarityIcon(listItem.m_rarity, id, false);
  368. ext = ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType);
  369. listItem.m_ScoreType.visible = true;
  370. int mainScore;
  371. int mainValuel;
  372. ItemDataManager.GetMainScore(id, out mainScore, out mainValuel);
  373. listItem.m_ScoreType.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + mainScore);
  374. }
  375. listItem.m_icon.url = ResPathUtil.GetIconPath(iconRes, ext);
  376. listItem.m_txtTitle.text = partName;
  377. listItem.target.data = id;
  378. listItem.m_txtScore.visible = false;
  379. //listItem.m_ScoreType.visible = true;
  380. listItem.m_imgNeed.visible = false;
  381. }
  382. private void UpdateListPartsSelected()
  383. {
  384. int count = _ui.m_partsList.m_list.numChildren;
  385. for (int i = 0; i < count; i++)
  386. {
  387. UI_PartsListItem listItem = UI_PartsListItem.Proxy(_ui.m_partsList.m_list.GetChildAt(i));
  388. int id = (int)listItem.target.data;
  389. if (_currentMenuType == ConstDressUpItemType.TAO_ZHUANG)
  390. {
  391. listItem.m_iconSelected.visible = false;
  392. }
  393. else
  394. {
  395. listItem.m_iconSelected.visible = EquipDataCache.cacher.CheckDressUpItemIsOn(id);
  396. }
  397. }
  398. }
  399. private void UpdatePartsListSort()
  400. {
  401. if (_currentMenuType == 0) return;
  402. if (_currentMenuType == (int)ConstDressUpItemType.TAO_ZHUANG)
  403. {
  404. _currentList3 = DressUpMenuSuitDataManager.GetSuitIDList();
  405. if (_rarityIndex == SORT_BY_HIGH_RARITY)
  406. {
  407. _currentList3 = SuitUtil.SortSuitListByHighRarity(_currentList3);
  408. }
  409. else if (_rarityIndex == SORT_BY_LOW_RARITY)
  410. {
  411. _currentList3 = SuitUtil.SortSuitListByLowRarity(_currentList3);
  412. }
  413. else
  414. {
  415. _currentList3.Reverse();
  416. }
  417. }
  418. else
  419. {
  420. _currentList3 = DressUpMenuItemDataManager.getItemDatasByType(_currentMenuType);
  421. if (_rarityIndex == SORT_BY_HIGH_RARITY)
  422. {
  423. _currentList3 = DressUpMenuItemDataManager.SortItemListByHighRarity(_currentList3);
  424. }
  425. else if (_rarityIndex == SORT_BY_LOW_RARITY)
  426. {
  427. _currentList3 = DressUpMenuItemDataManager.SortItemListByLowRarity(_currentList3);
  428. }
  429. else
  430. {
  431. _currentList3.Reverse();
  432. }
  433. }
  434. if (DressUpMenuItemDataManager.dressFilterType == DressFilterType.Search)
  435. {
  436. _currentList3 = DressUpMenuItemDataManager.DressSearch(_currentList3, _currentMenuType == (int)ConstDressUpItemType.TAO_ZHUANG);
  437. }
  438. else if (DressUpMenuItemDataManager.dressFilterType == DressFilterType.Filter)
  439. {
  440. _currentList3 = DressUpMenuItemDataManager.DressFilter(_currentList3, _currentMenuType == (int)ConstDressUpItemType.TAO_ZHUANG);
  441. }
  442. _ui.m_partsList.m_list.RemoveChildrenToPool();
  443. _ui.m_partsList.m_list.numItems = _currentList3.Count;
  444. }
  445. private void UpdateBtnAction()
  446. {
  447. _ui.m_btnAction.visible = (_currentMenuType == ConstDressUpItemType.TAO_ZHUANG);
  448. if (_ui.m_btnAction.visible)
  449. {
  450. _ui.m_btnAction.grayed = !EquipDataCache.cacher.HasSuitPicRes;
  451. }
  452. }
  453. private void OnClickBtnShow()
  454. {
  455. Timers.inst.Remove(SetBtnShowVisable);
  456. _ui.m_c1.selectedIndex = 0;
  457. _ui.m_btnHide.visible = true;
  458. _ui.m_btnShow.visible = false;
  459. _ui.m_loaShow.visible = false;
  460. }
  461. private void OnClickBtnHide()
  462. {
  463. _ui.m_c1.selectedIndex = 1;
  464. _ui.m_btnHide.visible = false;
  465. _ui.m_btnShow.visible = true;
  466. _ui.m_loaShow.visible = true;
  467. Timers.inst.Add(2f, 1, SetBtnShowVisable);
  468. }
  469. private void OnClickLoaShow()
  470. {
  471. Timers.inst.Remove(SetBtnShowVisable);
  472. _ui.m_btnShow.alpha = 1;
  473. Timers.inst.Add(2f, 1, SetBtnShowVisable);
  474. _ui.m_btnShow.enabled = true;
  475. }
  476. private void OnClickBtnPhoto()
  477. {
  478. _ui.target.visible = false;
  479. this._sceneObject.gameObject.SetActive(false);
  480. ViewManager.Show<PhotographView>();
  481. }
  482. private void UpdateScene()
  483. {
  484. _ui.target.visible = true;
  485. this._sceneObject.gameObject.SetActive(true);
  486. EquipDataCache.cacher.setSceneObj(_sceneObject);
  487. }
  488. private void SetBtnShowVisable(object param)
  489. {
  490. _ui.m_btnShow.enabled = false;
  491. GTween.To(1, 0, 0.3f).SetTarget(_ui.m_btnShow, TweenPropType.Alpha);
  492. }
  493. }
  494. }