ClothingSyntheticView.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. using System.Collections;
  2. using UnityEngine;
  3. using UI.ClothingSynthetic;
  4. using UI.CommonGame;
  5. using FairyGUI;
  6. using System.Collections.Generic;
  7. using System;
  8. using ET;
  9. namespace GFGGame
  10. {
  11. public class ClothingSyntheticView : BaseWindow
  12. {
  13. private const int HEAD_Y = 942;
  14. private const int FA_XING_Y = 609;
  15. private const int UPPER_BODY_Y = 383;
  16. private const int LOWER_BODY_Y = 112;
  17. private const int SHOES_Y = -287;
  18. private const int BODY_Y = 289;
  19. private const float HEAD_SCALE = 3f;
  20. private const float FA_XING_SCALE = 2f;
  21. private const float UPPER_BODY_SCALE = 1.5f;
  22. private const float LOWER_BODY_SCALE = 1.4f;
  23. private const float SHOES_SCALE = 2.5f;
  24. private const float BODY_SCALE = 1f;
  25. private const float DURATION = 0.6f;
  26. private readonly int[] HEAD_Y_ARR = new int[] { ConstDressUpItemType.TOU_SHI, ConstDressUpItemType.ER_SHI, ConstDressUpItemType.JING_SHI, ConstDressUpItemType.ZHUANG_RONG };
  27. private readonly int[] FA_XING_Y_ARR = new int[] { ConstDressUpItemType.FA_XING };
  28. private readonly int[] UPPER_BODY_Y_ARR = new int[] { ConstDressUpItemType.NEI_DA, ConstDressUpItemType.SHANG_YI };
  29. private readonly int[] LOWER_BODY_Y_ARR = new int[] { ConstDressUpItemType.XIA_ZHUANG, ConstDressUpItemType.SHOU_SHI };
  30. private readonly int[] SHOES_Y_ARR = new int[] { ConstDressUpItemType.WA_ZI, ConstDressUpItemType.XIE_ZI };
  31. private UI_ClothingSyntheticUI _ui;
  32. private GameObject _scenePrefab;
  33. private GameObject _sceneObject;
  34. private GoWrapper _wrapper;
  35. private DressUpObjDataCache _dressUpObjDataCache;
  36. private ValueBarController _valueBarController;
  37. private GComponent _imgSelected;
  38. private int _suitId;
  39. private int _itemId;
  40. private int[] _items;
  41. private int _selectedItemId;
  42. private GComponent _selectedListItem;
  43. private List<ItemData> _materiarsOfSelectedItem;
  44. private UI_MateriasListItem listTypeItem_CloSynthetic;
  45. public override void Dispose()
  46. {
  47. if (_valueBarController != null)
  48. {
  49. _valueBarController.Dispose();
  50. _valueBarController = null;
  51. }
  52. if (_sceneObject != null)
  53. {
  54. GameObject.Destroy(_sceneObject);
  55. _sceneObject = null;
  56. }
  57. if (_scenePrefab != null)
  58. {
  59. GFGAsset.Release(ResPathUtil.GetPrefabPath("SceneDressUpSynthetic"));
  60. _scenePrefab = null;
  61. }
  62. if (_imgSelected != null)
  63. {
  64. _imgSelected.RemoveFromParent();
  65. _imgSelected.Dispose();
  66. }
  67. if (_dressUpObjDataCache != null)
  68. {
  69. _dressUpObjDataCache.Dispose();
  70. _dressUpObjDataCache = null;
  71. }
  72. if (_wrapper != null)
  73. {
  74. _wrapper.Dispose();
  75. _wrapper = null;
  76. }
  77. _ui.m_loaBg.Dispose();
  78. // for (int i = 0; i < _ui.m_listClothing.numItems; i++)
  79. // {
  80. // UI_ClothingListItem listItem = UI_ClothingListItem.Proxy(_ui.m_listClothing.GetChildAt(i));
  81. // listItem.m_loaderIcon.Dispose();
  82. // UI_ClothingListItem.ProxyEnd();
  83. // }
  84. // for (int i = 0; i < _ui.m_listMaterias.numItems; i++)
  85. // {
  86. // UI_MateriasListItem listItem = UI_MateriasListItem.Proxy(_ui.m_listMaterias.GetChildAt(i));
  87. // listItem.m_loaderIcon.Dispose();
  88. // UI_MateriasListItem.ProxyEnd();
  89. // }
  90. if (_ui != null)
  91. {
  92. _ui.Dispose();
  93. _ui = null;
  94. }
  95. base.Dispose();
  96. }
  97. protected override void OnInit()
  98. {
  99. base.OnInit();
  100. packageName = UI_ClothingSyntheticListUI.PACKAGE_NAME;
  101. _ui = UI_ClothingSyntheticUI.Create();
  102. this.viewCom = _ui.target;
  103. isfullScreen = true;
  104. this.clickBlankToClose = false;
  105. _valueBarController = new ValueBarController(_ui.m_valueBar);
  106. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneDressUpSynthetic"));
  107. _dressUpObjDataCache = new DressUpObjDataCache();
  108. _imgSelected = new GComponent();
  109. _imgSelected = UIPackage.CreateObject(UI_ClothingSyntheticUI.PACKAGE_NAME, "ComSelect").asCom;
  110. _ui.m_listClothing.itemRenderer = ListClothingItemRender;
  111. _ui.m_listClothing.onClickItem.Add(OnClickListClothingItem);
  112. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  113. _ui.m_btnProduction.onClick.Add(OnClickBtnProcuction);
  114. _ui.m_btnHome.onClick.Add(OnClickBtnHome);
  115. }
  116. protected override void AddEventListener()
  117. {
  118. base.AddEventListener();
  119. EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, OnItemNumChanged);
  120. }
  121. protected override void OnShown()
  122. {
  123. base.OnShown();
  124. _suitId = (int)(this.viewData as object[])[0];
  125. _selectedItemId = (this.viewData as object[]).Length > 1 ? (int)(this.viewData as object[])[1] : 0;
  126. _valueBarController.OnShown();
  127. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("hc_bj_1");
  128. UpdateClothingList(false);
  129. Timers.inst.AddUpdate(CheckGuide);
  130. }
  131. protected override void OnHide()
  132. {
  133. base.OnHide();
  134. _valueBarController.OnHide();
  135. if (_sceneObject != null)
  136. {
  137. GameObject.Destroy(_sceneObject);
  138. _sceneObject = null;
  139. }
  140. if (_wrapper != null)
  141. {
  142. _wrapper.wrapTarget = null;
  143. }
  144. Timers.inst.Remove(CheckGuide);
  145. }
  146. protected override void RemoveEventListener()
  147. {
  148. base.RemoveEventListener();
  149. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, OnItemNumChanged);
  150. }
  151. private void OnClickBtnBack()
  152. {
  153. ViewManager.GoBackFrom(ViewName.CLOTHING_SYNTHETIC_VIEW);
  154. }
  155. private void OnClickListClothingItem(EventContext context)
  156. {
  157. UpdateSelectedItemInfo(context.data as GComponent, true);
  158. }
  159. private async void OnClickBtnProcuction()
  160. {
  161. if (ItemDataManager.GetItemNum(_selectedItemId) > 0)
  162. {
  163. PromptController.Instance.ShowFloatTextPrompt("不能制作已经拥有的物品!");
  164. return;
  165. }
  166. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_selectedItemId);
  167. //合成消耗判断
  168. if (ItemDataManager.GetItemNum(itemCfg.syntheticCostID) < itemCfg.syntheticCostNum)
  169. {
  170. PromptController.Instance.ShowFloatTextPrompt("消耗不足!", MessageType.WARNING);
  171. return;
  172. }
  173. //合成材料判断
  174. _materiarsOfSelectedItem = ItemUtil.CreateItemDataList(itemCfg.syntheticMateriarsArr);
  175. int count = _materiarsOfSelectedItem.Count;
  176. for (int i = 0; i < count; i++)
  177. {
  178. ItemData itemData = _materiarsOfSelectedItem[i];
  179. int num = ItemDataManager.GetItemNum(itemData.id);
  180. ItemCfg materialCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  181. bool isDressUp = materialCfg.itemType == ConstItemType.DRESS_UP;
  182. int numSynthetic = isDressUp ? Mathf.Max(num - 1, 0) : Mathf.Max(num, 0);
  183. if (numSynthetic < itemData.num)
  184. {
  185. PromptController.Instance.ShowFloatTextPrompt("材料不足!", MessageType.WARNING);
  186. return;
  187. }
  188. }
  189. bool result = await ClothingSyntheticSProxy.ClothtingSynthetic(_selectedItemId);
  190. if (result)
  191. {
  192. _selectedItemId = 0;
  193. UpdateClothingList(true);
  194. LogServerHelper.SendNodeLog((int)PlayParticipationEnum.FU_ZHUANG_HE_CHENG, 2);
  195. }
  196. }
  197. private void ListClothingItemRender(int index, GObject item)
  198. {
  199. UI_ClothingListItem listItem = UI_ClothingListItem.Proxy(item);
  200. int itemId = _items[index];
  201. listItem.target.data = itemId;
  202. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);
  203. listItem.m_loaderIcon.url = ResPathUtil.GetIconPath(itemCfg);
  204. string itemName = itemCfg.name;
  205. listItem.m_txtName.text = itemName;
  206. listItem.m_imgOwned.visible = ItemDataManager.GetItemNum(itemId) > 0;
  207. UI_ClothingListItem.ProxyEnd();
  208. }
  209. private void UpdateRole(bool tween)
  210. {
  211. if (_sceneObject != null)
  212. {
  213. GameObject.Destroy(_sceneObject);
  214. _sceneObject = null;
  215. }
  216. _sceneObject = GameObject.Instantiate(_scenePrefab);
  217. int scale = 45;
  218. _sceneObject.transform.localScale = new Vector3(scale, scale, scale);
  219. _dressUpObjDataCache.setSceneObj(_sceneObject, true);
  220. _dressUpObjDataCache.PutOnDefaultSuitSaved(false);
  221. _dressUpObjDataCache.AddOrRemove(_selectedItemId, true);
  222. if (_wrapper == null)
  223. {
  224. _wrapper = new GoWrapper(_sceneObject);
  225. _ui.m_compHolder.m_compMover.m_holder.SetNativeObject(_wrapper);
  226. }
  227. else
  228. {
  229. _wrapper.wrapTarget = _sceneObject;
  230. }
  231. int type = ItemUtilCS.GetItemSubType(_selectedItemId);
  232. float duration = DURATION;
  233. if (!tween)
  234. {
  235. duration = 0;
  236. }
  237. if (Array.IndexOf(HEAD_Y_ARR, type) >= 0)
  238. {
  239. _ui.m_compHolder.m_compMover.target.TweenMoveY(HEAD_Y, duration);
  240. _ui.m_compHolder.m_compMover.target.TweenScale(new Vector2(HEAD_SCALE, HEAD_SCALE), duration);
  241. }
  242. else if (Array.IndexOf(FA_XING_Y_ARR, type) >= 0)
  243. {
  244. _ui.m_compHolder.m_compMover.target.TweenMoveY(FA_XING_Y, duration);
  245. _ui.m_compHolder.m_compMover.target.TweenScale(new Vector2(FA_XING_SCALE, FA_XING_SCALE), duration);
  246. }
  247. else if (Array.IndexOf(UPPER_BODY_Y_ARR, type) >= 0)
  248. {
  249. _ui.m_compHolder.m_compMover.target.TweenMoveY(UPPER_BODY_Y, duration);
  250. _ui.m_compHolder.m_compMover.target.TweenScale(new Vector2(UPPER_BODY_SCALE, UPPER_BODY_SCALE), duration);
  251. }
  252. else if (Array.IndexOf(LOWER_BODY_Y_ARR, type) >= 0)
  253. {
  254. _ui.m_compHolder.m_compMover.target.TweenMoveY(LOWER_BODY_Y, duration);
  255. _ui.m_compHolder.m_compMover.target.TweenScale(new Vector2(LOWER_BODY_SCALE, LOWER_BODY_SCALE), duration);
  256. }
  257. else if (Array.IndexOf(SHOES_Y_ARR, type) >= 0)
  258. {
  259. _ui.m_compHolder.m_compMover.target.TweenMoveY(SHOES_Y, duration);
  260. _ui.m_compHolder.m_compMover.target.TweenScale(new Vector2(SHOES_SCALE, SHOES_SCALE), duration);
  261. }
  262. else
  263. {
  264. _ui.m_compHolder.m_compMover.target.TweenMoveY(BODY_Y, duration);
  265. _ui.m_compHolder.m_compMover.target.TweenScale(new Vector2(BODY_SCALE, BODY_SCALE), duration);
  266. }
  267. }
  268. private void UpdateClothingList(bool tween)
  269. {
  270. //套装名称
  271. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_suitId);
  272. _ui.m_txtSuitName.text = suitCfg.name;
  273. //进度条
  274. UpdateSuitProgress();
  275. //服装列表
  276. _items = SuitCfgManager.Instance.GetSuitItems(_suitId).Clone() as int[];
  277. ItemUtil.SortItemIdsByOwned(_items);
  278. _ui.m_listClothing.RemoveChildrenToPool();
  279. _ui.m_listClothing.numItems = _items.Length;
  280. if (_ui.m_listClothing.numItems > 0)
  281. {
  282. UI_ClothingListItem listItem = null;
  283. int index = 0;
  284. if (_selectedItemId > 0)
  285. {
  286. int num = _ui.m_listClothing.numChildren;
  287. for (int i = 0; i < num; i++)
  288. {
  289. listItem = UI_ClothingListItem.Proxy(_ui.m_listClothing.GetChildAt(i));
  290. int temp = (int)listItem.target.data;
  291. if (temp == _selectedItemId)
  292. {
  293. index = i;
  294. }
  295. UI_ClothingListItem.ProxyEnd();
  296. }
  297. }
  298. _ui.m_listClothing.ScrollToView(index);
  299. UpdateSelectedItemInfo(_ui.m_listClothing.GetChildAt(index) as GComponent, tween);
  300. }
  301. }
  302. private void UpdateSelectedItemInfo(GComponent listItem, bool tween)
  303. {
  304. _selectedListItem = listItem;
  305. listItem.AddChild(_imgSelected);
  306. _selectedItemId = (int)listItem.data;
  307. UpdateRole(tween);
  308. UpdateSelectedItemInfo();
  309. }
  310. private void UpdateSelectedItemInfo()
  311. {
  312. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_selectedItemId);
  313. //属性展示
  314. _ui.m_compItemInfo.m_txtName.text = itemCfg.name;
  315. RarityIconController.UpdateRarityIcon(_ui.m_compItemInfo.m_rarity, _selectedItemId, false);
  316. _ui.m_compItemInfo.m_txtGong.text = "" + itemCfg.score1;
  317. _ui.m_compItemInfo.m_txtShang.text = "" + itemCfg.score2;
  318. _ui.m_compItemInfo.m_txtJue.text = "" + itemCfg.score3;
  319. _ui.m_compItemInfo.m_txtZhi.text = "" + itemCfg.score4;
  320. UI_ClothingListItem selectedItem = UI_ClothingListItem.Proxy(_selectedListItem);
  321. selectedItem.m_imgOwned.visible = ItemDataManager.GetItemNum(_selectedItemId) > 0;
  322. UI_ClothingListItem.ProxyEnd();
  323. //合成显示
  324. ItemCfg clothingSyntheticCfg = ItemCfgArray.Instance.GetCfg(_selectedItemId);
  325. string costName = ItemUtil.GetItemName(clothingSyntheticCfg.syntheticCostID);
  326. _ui.m_txtCost.SetVar("v1", "" + clothingSyntheticCfg.syntheticCostNum).SetVar("v2", costName).FlushVars();
  327. _materiarsOfSelectedItem = ItemUtil.CreateItemDataList(clothingSyntheticCfg.syntheticMateriarsArr);
  328. int count = _ui.m_listMaterias.numChildren;
  329. for (int i = 0; i < count; i++)
  330. {
  331. UI_MateriasListItem listItem = UI_MateriasListItem.Proxy(_ui.m_listMaterias.GetChildAt(i));
  332. if (i < _materiarsOfSelectedItem.Count)
  333. {
  334. ItemData itemData = _materiarsOfSelectedItem[i];
  335. ItemCfg materiasItemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  336. listItem.m_txtName.text = ItemUtil.GetItemName(itemData.id);
  337. listItem.m_loaderIcon.url = ResPathUtil.GetIconPath(materiasItemCfg);
  338. int num = ItemDataManager.GetItemNum(itemData.id);
  339. ItemCfg materialCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  340. bool isDressUp = materialCfg.itemType == ConstItemType.DRESS_UP;
  341. int numSynthetic = isDressUp ? Mathf.Max(num - 1, 0) : Mathf.Max(num, 0);
  342. listItem.m_groupCount.m_txtProgess.text = numSynthetic + "/" + itemData.num;
  343. listItem.m_loaderIcon.visible = true;
  344. listItem.m_groupCount.target.visible = true;
  345. listItem.m_groupCount.target.onClick.Clear();
  346. listItem.m_groupCount.target.onClick.Add(OnClickMateriasItemPlus);
  347. listItem.target.data = itemData;
  348. }
  349. else
  350. {
  351. listItem.m_txtName.text = "";
  352. listItem.m_loaderIcon.visible = false;
  353. listItem.m_groupCount.target.visible = false;
  354. }
  355. UI_MateriasListItem.ProxyEnd();
  356. }
  357. _ui.m_btnProduction.grayed = ItemDataManager.GetItemNum(_selectedItemId) > 0;
  358. }
  359. private void OnClickMateriasItemPlus(EventContext context)
  360. {
  361. UI_Component3 groupCount = UI_Component3.Proxy(context.sender as GObject);
  362. UI_MateriasListItem listItem = UI_MateriasListItem.Proxy(groupCount.target.parent);
  363. ItemData itemData = listItem.target.data as ItemData;
  364. int num = ItemDataManager.GetItemNum(itemData.id);
  365. int needCount = (itemData.num + 1 - num) > 0 ? itemData.num + 1 - num : 1;
  366. ViewManager.Show(ViewName.APPROACH_OF_ITEM_VIEW, new object[] { itemData.id, new object[] { ViewName.CLOTHING_SYNTHETIC_VIEW, new object[] { _suitId, _selectedItemId } }, needCount });
  367. UI_Component3.ProxyEnd();
  368. UI_MateriasListItem.ProxyEnd();
  369. }
  370. private void OnItemNumChanged()
  371. {
  372. UpdateSuitProgress();
  373. //列表选中项更新
  374. UI_ClothingListItem selectedItem = UI_ClothingListItem.Proxy(_selectedListItem);
  375. selectedItem.m_imgOwned.visible = ItemDataManager.GetItemNum(_selectedItemId) > 0;
  376. UI_ClothingListItem.ProxyEnd();
  377. UpdateSelectedItemInfo();
  378. }
  379. private void UpdateSuitProgress()
  380. {
  381. //进度条
  382. int count = 0;
  383. int totalCount = 0;
  384. DressUpMenuSuitDataManager.GetSuitProgressBySuitId(_suitId, out count, out totalCount);
  385. _ui.m_txtProgress.SetVar("v1", "" + count);
  386. _ui.m_txtProgress.SetVar("v2", "" + totalCount);
  387. _ui.m_txtProgress.FlushVars();
  388. }
  389. private void OnClickBtnHome()
  390. {
  391. GameController.GoBackToMainView();
  392. }
  393. private void CheckGuide(object param)
  394. {
  395. if (GuideDataManager.IsGuideFinish(ConstGuideId.CLOTHING_SYNTHETIC) <= 0)
  396. {
  397. UpdateToCheckGuide(null);
  398. }
  399. else
  400. {
  401. Timers.inst.Remove(CheckGuide);
  402. }
  403. }
  404. protected override void UpdateToCheckGuide(object param)
  405. {
  406. if (ViewManager.isViewOpen(typeof(GuideView).Name))
  407. {
  408. ViewManager.GetUIView(typeof(GuideView).Name).viewCom.visible = !ViewManager.isViewOpen(typeof(GetSuitItemVIew).Name);
  409. }
  410. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  411. int itemId = 10114;
  412. int itemIndex = 0;
  413. for (int i = 0; i < _ui.m_listClothing.numItems; i++)
  414. {
  415. UI_ClothingListItem listItem = UI_ClothingListItem.Proxy(_ui.m_listClothing.GetChildAt(i));
  416. int temp = (int)listItem.target.data;
  417. UI_ClothingListItem.ProxyEnd();
  418. if (temp == itemId)
  419. {
  420. itemIndex = i;
  421. break;
  422. }
  423. }
  424. bool guide = GuideController.TryGuide(_ui.m_listClothing, ConstGuideId.CLOTHING_SYNTHETIC, 4, "找到需要合成的物品", itemIndex);
  425. if (guide) _ui.m_listClothing.ScrollToView(itemIndex);
  426. if (_ui.m_listMaterias.numChildren > 0)
  427. {
  428. listTypeItem_CloSynthetic = UI_MateriasListItem.Proxy(_ui.m_listMaterias.GetChildAt(0));
  429. }
  430. if (listTypeItem_CloSynthetic != null)
  431. {
  432. GuideController.TryGuide(listTypeItem_CloSynthetic.m_loaderIcon, ConstGuideId.CLOTHING_SYNTHETIC, 5, "这里可以查看合成需要的材料,和材料的获取途径");
  433. UI_MateriasListItem.ProxyEnd();
  434. }
  435. GuideController.TryGuide(_ui.m_btnProduction, ConstGuideId.CLOTHING_SYNTHETIC, 6, "点击获得新的服饰");
  436. GuideController.TryGuide(_ui.m_btnHome, ConstGuideId.CLOTHING_SYNTHETIC, 7, "获得必需品啦,继续通关主线剧情吧", -1, true, 180);
  437. }
  438. }
  439. }