ClothingSyntheticView.cs 19 KB

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