ClothingSyntheticView.cs 17 KB

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