ClothingSyntheticView.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. using UnityEngine;
  2. using UI.ClothingSynthetic;
  3. using FairyGUI;
  4. using System.Collections.Generic;
  5. using System;
  6. using ET;
  7. using System.Collections;
  8. namespace GFGGame
  9. {
  10. public class ClothingSyntheticView : BaseWindow
  11. {
  12. private const int HEAD_Y = 942;
  13. private const int FA_XING_Y = 609;
  14. private const int UPPER_BODY_Y = 383;
  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 DressUpObjUI _dressUpObjUI;
  32. private ValueBarController _valueBarController;
  33. private GImage _imgSelected;
  34. private int _suitId;
  35. private int _itemId;
  36. private int[] _items;
  37. private int _selectedItemId;
  38. private GComponent _selectedListItem;
  39. private List<ItemData> _materiarsOfSelectedItem;
  40. private UI_MateriasListItem listTypeItem_CloSynthetic;
  41. public override void Dispose()
  42. {
  43. if (_valueBarController != null)
  44. {
  45. _valueBarController.Dispose();
  46. _valueBarController = null;
  47. }
  48. if (_imgSelected != null)
  49. {
  50. _imgSelected.RemoveFromParent();
  51. _imgSelected.Dispose();
  52. }
  53. if (_dressUpObjUI != null)
  54. {
  55. _dressUpObjUI.Dispose();
  56. _dressUpObjUI = null;
  57. }
  58. if (_ui != null)
  59. {
  60. _ui.Dispose();
  61. _ui = null;
  62. }
  63. base.Dispose();
  64. }
  65. protected override void OnInit()
  66. {
  67. base.OnInit();
  68. packageName = UI_ClothingSyntheticListUI.PACKAGE_NAME;
  69. _ui = UI_ClothingSyntheticUI.Create();
  70. this.viewCom = _ui.target;
  71. isfullScreen = true;
  72. //layer = ConstViewLayer.TOP;
  73. isReturnView = true;
  74. //this.clickBlankToClose = false;
  75. _valueBarController = new ValueBarController(_ui.m_valueBar);
  76. _dressUpObjUI = new DressUpObjUI("SceneDressUpSynthetic");
  77. _imgSelected = new GImage();
  78. _imgSelected = UIPackage.CreateObject(UI_ClothingSyntheticUI.PACKAGE_NAME, "hc_kuang_4").asImage;
  79. _ui.m_listClothing.itemRenderer = ListClothingItemRender;
  80. _ui.m_listClothing.onClickItem.Add(OnClickListClothingItem);
  81. _ui.m_listMaterias.itemRenderer = RenderListMateriasItem;
  82. _ui.m_listMaterias.onClickItem.Add(OnClickMateriasItemPlus);
  83. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  84. _ui.m_btnProduction.onClick.Add(OnClickBtnProcuction);
  85. _ui.m_btnHome.onClick.Add(OnClickBtnHome);
  86. }
  87. protected override void AddEventListener()
  88. {
  89. base.AddEventListener();
  90. EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, OnItemNumChanged);
  91. }
  92. protected override void OnShown()
  93. {
  94. base.OnShown();
  95. _suitId = 0;
  96. _selectedItemId = 0;
  97. if (this.viewData != null)
  98. {
  99. _suitId = (int)(this.viewData as object[])[0];
  100. _selectedItemId = (this.viewData as object[]).Length > 1 ? (int)(this.viewData as object[])[1] : 0;
  101. }
  102. _valueBarController.OnShown();
  103. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("hc_bj_1");
  104. UpdateClothingList(false);
  105. Timers.inst.AddUpdate(CheckGuide);
  106. }
  107. protected override void OnHide()
  108. {
  109. base.OnHide();
  110. _valueBarController.OnHide();
  111. _ui.m_listMaterias.selectedIndex = 0;
  112. Timers.inst.Remove(CheckGuide);
  113. _dressUpObjUI.dressUpObj.TakeOffAll();
  114. }
  115. protected override void RemoveEventListener()
  116. {
  117. base.RemoveEventListener();
  118. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, OnItemNumChanged);
  119. }
  120. private void OnClickBtnBack()
  121. {
  122. ViewManager.GoBackFrom(typeof(ClothingSyntheticView).FullName);
  123. }
  124. private void OnClickListClothingItem(EventContext context)
  125. {
  126. UpdateSelectedItemInfo(context.data as GComponent, true);
  127. }
  128. private async void OnClickBtnProcuction()
  129. {
  130. if (ItemDataManager.GetItemNum(_selectedItemId) > 0)
  131. {
  132. PromptController.Instance.ShowFloatTextPrompt("不能制作已经拥有的物品");
  133. return;
  134. }
  135. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_selectedItemId);
  136. if (itemCfg == null) {
  137. ET.Log.Error("OnClickBtnProcuction itemCfg is null");
  138. return;
  139. }
  140. if (!ItemUtil.CheckItemEnough(itemCfg.syntheticCostID, itemCfg.syntheticCostNum))
  141. {
  142. long has = ItemDataManager.GetItemNum(itemCfg.syntheticCostID);
  143. ItemUtil.BuyCurrency(itemCfg.syntheticCostID, itemCfg.syntheticCostNum - has);
  144. return;
  145. }
  146. List<ItemData> materiarsOfSelectedItem = ItemUtil.CreateItemDataList(itemCfg.syntheticMateriarsArr);
  147. for (int i = 0; i < materiarsOfSelectedItem.Count; i++)
  148. {
  149. ItemData itemData = materiarsOfSelectedItem[i];
  150. if (itemData == null || !ItemUtil.CheckItemEnough(itemData.id, itemData.num, true)) return;
  151. }
  152. bool result = await ClothingSyntheticSProxy.ClothtingSynthetic(_selectedItemId);
  153. if (result)
  154. {
  155. _selectedItemId = 0;
  156. UpdateClothingList(true);
  157. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.FU_ZHUANG_HE_CHENG, 2);
  158. // 发送服装合成成功事件
  159. EventAgent.DispatchEvent(ConstMessage.CLOTHING_SYNTHETIC_SUCCESS);
  160. EventAgent.DispatchEvent(ConstMessage.STUDIO_FILING_UPDATE);
  161. }
  162. }
  163. private void ListClothingItemRender(int index, GObject item)
  164. {
  165. UI_ClothingListItem listItem = UI_ClothingListItem.Proxy(item);
  166. int itemId = _items[index];
  167. listItem.target.data = itemId;
  168. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);
  169. listItem.m_loaderIcon.url = ResPathUtil.GetIconPath(itemCfg);
  170. string itemName = itemCfg.name;
  171. listItem.m_txtName.text = itemName;
  172. listItem.m_imgOwned.visible = ItemDataManager.GetItemNum(itemId) > 0;
  173. RedDotController.Instance.SetComRedDot(listItem.target, RedDotDataManager.Instance.CheckCanSynthetic(itemId), "", -18, 20);
  174. UI_ClothingListItem.ProxyEnd();
  175. }
  176. private EaseType ease = EaseType.CubicOut;
  177. private void UpdateRole(bool tween)
  178. {
  179. _dressUpObjUI.ResetSceneObj(45, true, true, null, false);
  180. _dressUpObjUI.dressUpObj.AddOrRemove(_selectedItemId, true);
  181. _imgSelected.visible = _dressUpObjUI.dressUpObj.CheckDressUpItemIsOn(_selectedItemId);
  182. _dressUpObjUI.UpdateWrapper(_ui.m_compHolder.m_compMover.m_holder);
  183. int type = ItemUtilCS.GetItemSubType(_selectedItemId);
  184. float duration = DURATION;
  185. if (!tween)
  186. {
  187. duration = 0;
  188. _ui.m_hide.Play();
  189. }
  190. var dy = _ui.m_compHolder.target.height - 642;
  191. if (Array.IndexOf(HEAD_Y_ARR, type) >= 0)
  192. {
  193. _ui.m_compHolder.m_compMover.target.TweenMoveY(HEAD_Y + dy, duration).SetEase(ease);
  194. _ui.m_compHolder.m_compMover.target.TweenScale(new Vector2(HEAD_SCALE, HEAD_SCALE), duration).SetEase(ease);
  195. }
  196. else if (Array.IndexOf(FA_XING_Y_ARR, type) >= 0)
  197. {
  198. _ui.m_compHolder.m_compMover.target.TweenMoveY(FA_XING_Y + dy, duration).SetEase(ease);
  199. _ui.m_compHolder.m_compMover.target.TweenScale(new Vector2(FA_XING_SCALE, FA_XING_SCALE), duration).SetEase(ease);
  200. }
  201. else if (Array.IndexOf(UPPER_BODY_Y_ARR, type) >= 0)
  202. {
  203. _ui.m_compHolder.m_compMover.target.TweenMoveY(UPPER_BODY_Y + dy, duration).SetEase(ease);
  204. _ui.m_compHolder.m_compMover.target.TweenScale(new Vector2(UPPER_BODY_SCALE, UPPER_BODY_SCALE), duration).SetEase(ease);
  205. }
  206. else if (Array.IndexOf(LOWER_BODY_Y_ARR, type) >= 0)
  207. {
  208. _ui.m_compHolder.m_compMover.target.TweenMoveY(LOWER_BODY_Y + dy, duration).SetEase(ease);
  209. _ui.m_compHolder.m_compMover.target.TweenScale(new Vector2(LOWER_BODY_SCALE, LOWER_BODY_SCALE), duration).SetEase(ease);
  210. }
  211. else if (Array.IndexOf(SHOES_Y_ARR, type) >= 0)
  212. {
  213. _ui.m_compHolder.m_compMover.target.TweenMoveY(SHOES_Y + dy, duration).SetEase(ease);
  214. _ui.m_compHolder.m_compMover.target.TweenScale(new Vector2(SHOES_SCALE, SHOES_SCALE), duration).SetEase(ease);
  215. }
  216. else
  217. {
  218. _ui.m_compHolder.m_compMover.target.TweenMoveY(BODY_Y + dy, duration).SetEase(ease);
  219. _ui.m_compHolder.m_compMover.target.TweenScale(new Vector2(BODY_SCALE, BODY_SCALE), duration).SetEase(ease);
  220. }
  221. if (!tween)
  222. {
  223. Timers.inst.StartCoroutine(DelayShow());
  224. }
  225. }
  226. /// <summary>
  227. /// 延迟一帧 防止闪一下
  228. /// </summary>
  229. /// <returns></returns>
  230. private IEnumerator DelayShow()
  231. {
  232. yield return new WaitForEndOfFrame();
  233. _ui.m_show.Play();
  234. }
  235. private void UpdateClothingList(bool tween)
  236. {
  237. //套装名称
  238. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_suitId);
  239. _ui.m_txtSuitName.text = suitCfg.name;
  240. //进度条
  241. UpdateSuitProgress();
  242. //服装列表
  243. _items = SuitCfgArray.Instance.GetSuitItems(_suitId).Clone() as int[];
  244. ItemUtil.SortItemIdsByOwned(_items);
  245. _ui.m_listClothing.RemoveChildrenToPool();
  246. _ui.m_listClothing.numItems = _items.Length;
  247. if (_ui.m_listClothing.numItems > 0)
  248. {
  249. UI_ClothingListItem listItem = null;
  250. int index = 0;
  251. if (_selectedItemId > 0)
  252. {
  253. int num = _ui.m_listClothing.numChildren;
  254. for (int i = 0; i < num; i++)
  255. {
  256. listItem = UI_ClothingListItem.Proxy(_ui.m_listClothing.GetChildAt(i));
  257. int temp = (int)listItem.target.data;
  258. if (temp == _selectedItemId)
  259. {
  260. index = i;
  261. }
  262. UI_ClothingListItem.ProxyEnd();
  263. }
  264. }
  265. _ui.m_listClothing.ScrollToView(index);
  266. _ui.m_listClothing.selectedIndex = index;
  267. UpdateSelectedItemInfo(_ui.m_listClothing.GetChildAt(index) as GComponent, tween);
  268. }
  269. }
  270. private void UpdateSelectedItemInfo(GComponent listItem, bool tween)
  271. {
  272. _selectedListItem = listItem;
  273. listItem.AddChildAt(_imgSelected, 1);
  274. _selectedItemId = (int)listItem.data;
  275. UpdateRole(tween);
  276. UpdateSelectedItemInfo();
  277. }
  278. private void UpdateSelectedItemInfo()
  279. {
  280. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_selectedItemId);
  281. //属性展示
  282. _ui.m_compItemInfo.m_txtName.text = itemCfg.name;
  283. RarityIconController.UpdateRarityIcon(_ui.m_compItemInfo.m_rarity, _selectedItemId, false);
  284. _ui.m_compItemInfo.m_txtGong.text = "" + itemCfg.score1;
  285. _ui.m_compItemInfo.m_txtShang.text = "" + itemCfg.score2;
  286. _ui.m_compItemInfo.m_txtJue.text = "" + itemCfg.score3;
  287. _ui.m_compItemInfo.m_txtZhi.text = "" + itemCfg.score4;
  288. UI_ClothingListItem selectedItem = UI_ClothingListItem.Proxy(_selectedListItem);
  289. selectedItem.m_imgOwned.visible = ItemDataManager.GetItemNum(_selectedItemId) > 0;
  290. UI_ClothingListItem.ProxyEnd();
  291. //合成显示
  292. ItemCfg clothingSyntheticCfg = ItemCfgArray.Instance.GetCfg(_selectedItemId);
  293. // string costName = ItemUtil.GetItemName(clothingSyntheticCfg.syntheticCostID);
  294. // _ui.m_txtCost.SetVar("v1", "" + clothingSyntheticCfg.syntheticCostNum).SetVar("v2", costName).FlushVars();
  295. if (clothingSyntheticCfg.syntheticCostID <= 0)
  296. {
  297. Log.Error($"请为物品 {clothingSyntheticCfg.id} 增加合成相关配置!");
  298. return;
  299. }
  300. ItemUtil.UpdateItemNeedNum(_ui.m_comCostCurrency, clothingSyntheticCfg.syntheticCostID, clothingSyntheticCfg.syntheticCostNum);
  301. _materiarsOfSelectedItem = ItemUtil.CreateItemDataList(clothingSyntheticCfg.syntheticMateriarsArr);
  302. _ui.m_listMaterias.numItems = _materiarsOfSelectedItem.Count;
  303. _ui.m_listMaterias.selectedIndex = 0;
  304. _ui.m_btnProduction.grayed = ItemDataManager.GetItemNum(_selectedItemId) > 0;
  305. }
  306. private void RenderListMateriasItem(int index, GObject obj)
  307. {
  308. UI_MateriasListItem listItem = UI_MateriasListItem.Proxy(obj);
  309. ItemData itemData = _materiarsOfSelectedItem[index];
  310. ItemCfg materiasItemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  311. listItem.m_txtName.text = ItemUtil.GetItemName(itemData.id);
  312. listItem.m_loaderIcon.url = ResPathUtil.GetIconPath(materiasItemCfg);
  313. long num = ItemDataManager.GetItemNum(itemData.id);
  314. ItemCfg materialCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  315. bool isDressUp = materialCfg.itemType == ConstItemType.DRESS_UP;
  316. long numSynthetic = Math.Max(num, 0);
  317. listItem.m_txtProgess.text = numSynthetic + "/" + itemData.num;
  318. listItem.m_loaderIcon.visible = true;
  319. listItem.m_txtProgess.visible = true;
  320. // listItem.target.onClick.Clear();
  321. // if (listItem.target.data == null)
  322. // {
  323. // listItem.target.onClick.Add(OnClickMateriasItemPlus);
  324. // }
  325. listItem.target.data = index;
  326. UI_MateriasListItem.ProxyEnd();
  327. }
  328. private void OnClickMateriasItemPlus(EventContext context)
  329. {
  330. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.CLOTHING_SYNTHETIC);
  331. if (GuideDataManager.currentGuideId == cfg.id)
  332. {
  333. return;
  334. }
  335. if (ItemDataManager.GetItemNum(_selectedItemId) > 0)
  336. {
  337. PromptController.Instance.ShowFloatTextPrompt("该部件已制作完成");
  338. return;
  339. }
  340. int index = (int)(context.data as GObject).data;
  341. _ui.m_listMaterias.selectedIndex = index;
  342. ItemData itemData = _materiarsOfSelectedItem[index];
  343. if (itemData == null)
  344. {
  345. ET.Log.Error("OnClickMateriasItemPlus itemData is null");
  346. return;
  347. }
  348. object[] sourceDatas = new object[] { itemData.id, new object[] { typeof(ClothingSyntheticView).FullName, new object[] { _suitId, _selectedItemId } }, (int)itemData.num };
  349. GoodsItemTipsController.ShowItemTips(itemData.id, sourceDatas);
  350. }
  351. private void OnItemNumChanged()
  352. {
  353. UpdateSuitProgress();
  354. //列表选中项更新
  355. UI_ClothingListItem selectedItem = UI_ClothingListItem.Proxy(_selectedListItem);
  356. selectedItem.m_imgOwned.visible = ItemDataManager.GetItemNum(_selectedItemId) > 0;
  357. UI_ClothingListItem.ProxyEnd();
  358. _ui.m_listClothing.numItems = _ui.m_listClothing.numItems;
  359. UpdateSelectedItemInfo();
  360. }
  361. private void UpdateSuitProgress()
  362. {
  363. //进度条
  364. int count = 0;
  365. int totalCount = 0;
  366. DressUpMenuSuitDataManager.GetSuitProgressBySuitId(_suitId, out count, out totalCount);
  367. _ui.m_txtProgress.text = string.Format("{0}/{1}", count, totalCount);
  368. }
  369. private void OnClickBtnHome()
  370. {
  371. GameController.GoBackToMainView();
  372. }
  373. private void CheckGuide(object param)
  374. {
  375. if (GuideDataManager.IsGuideFinish(ConstGuideId.CLOTHING_SYNTHETIC) <= 0)
  376. {
  377. UpdateToCheckGuide(null);
  378. }
  379. else
  380. {
  381. Timers.inst.Remove(CheckGuide);
  382. }
  383. }
  384. protected override void UpdateToCheckGuide(object param)
  385. {
  386. if (ViewManager.isViewOpen(typeof(GuideView).Name))
  387. {
  388. (ViewManager.GetUIView(typeof(GuideView).Name) as GuideView).viewCom.visible = !ViewManager.isViewOpen(typeof(GetSuitItemVIew).Name);
  389. }
  390. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  391. int itemId = 10566;
  392. int itemIndex = 0;
  393. for (int i = 0; i < _ui.m_listClothing.numItems; i++)
  394. {
  395. UI_ClothingListItem listItem = UI_ClothingListItem.Proxy(_ui.m_listClothing.GetChildAt(i));
  396. int temp = (int)listItem.target.data;
  397. UI_ClothingListItem.ProxyEnd();
  398. if (temp == itemId)
  399. {
  400. itemIndex = i;
  401. break;
  402. }
  403. }
  404. bool guide = GuideController.TryGuide(_ui.m_listClothing, ConstGuideId.CLOTHING_SYNTHETIC, 3, "找到需要合成的物品。", itemIndex);
  405. if (guide) _ui.m_listClothing.ScrollToView(itemIndex);
  406. GuideController.TryGuide(_ui.m_listMaterias, ConstGuideId.CLOTHING_SYNTHETIC, 4, "这里可以查看合成需要的材料,和材料的获取途径。", 0);
  407. UI_MateriasListItem.ProxyEnd();
  408. GuideController.TryGuide(_ui.m_btnProduction, ConstGuideId.CLOTHING_SYNTHETIC, 5, "点击获得新的服饰。");
  409. GuideController.TryGuide(_ui.m_btnBack, ConstGuideId.CLOTHING_SYNTHETIC, 6, "获得新衣服啦,继续通关主线剧情吧。");
  410. }
  411. }
  412. }