ClothingSyntheticView.cs 17 KB

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