ClothingSyntheticView.cs 20 KB

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