ClothingSyntheticView.cs 16 KB

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