ClothingSyntheticView.cs 15 KB

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