CardSyntheticView.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. using UnityEngine;
  2. using UI.ClothingSynthetic;
  3. using UI.CardSynthetic;
  4. using FairyGUI;
  5. using System.Collections.Generic;
  6. using System;
  7. using ET;
  8. using System.Collections;
  9. using System.Threading.Tasks;
  10. using YooAsset;
  11. namespace GFGGame
  12. {
  13. public class CardSyntheticView : BaseWindow
  14. {
  15. private UI_CardSyntheticUI _ui;
  16. private DressUpObjUI _dressUpObjUI;
  17. private ValueBarController _valueBarController;
  18. private GImage _imgSelected;
  19. private int _cardId;
  20. private int _chapterID;
  21. private int _itemId;
  22. private int[] _items;
  23. private int _selectedItemId;
  24. private GComponent _selectedListItem;
  25. private List<ItemData> _materiarsOfSelectedItem;
  26. private UI_MateriasListItem listTypeItem_CloSynthetic;
  27. private UI_Component2 _compMover;
  28. public override void Dispose()
  29. {
  30. if (_valueBarController != null)
  31. {
  32. _valueBarController.Dispose();
  33. _valueBarController = null;
  34. }
  35. if (_imgSelected != null)
  36. {
  37. _imgSelected.RemoveFromParent();
  38. _imgSelected.Dispose();
  39. }
  40. if (_dressUpObjUI != null)
  41. {
  42. _dressUpObjUI.Dispose();
  43. _dressUpObjUI = null;
  44. }
  45. if (_ui != null)
  46. {
  47. _ui.Dispose();
  48. _ui = null;
  49. }
  50. base.Dispose();
  51. }
  52. protected override void OnInit()
  53. {
  54. base.OnInit();
  55. packageName = UI_CardSyntheticUI.PACKAGE_NAME;
  56. _ui = UI_CardSyntheticUI.Create();
  57. this.viewCom = _ui.target;
  58. isfullScreen = true;
  59. //layer = ConstViewLayer.TOP;
  60. isReturnView = true;
  61. _valueBarController = new ValueBarController(_ui.m_valueBar);
  62. _dressUpObjUI = new DressUpObjUI("SceneDressUpSynthetic");
  63. _ui.m_listMaterias.itemRenderer = RenderListMateriasItem;
  64. _ui.m_listMaterias.onClickItem.Add(OnClickMateriasItemPlus);
  65. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  66. _ui.m_btnProduction.onClick.Add(OnClickBtnProcuction);
  67. _ui.m_btnHome.onClick.Add(OnClickBtnHome);
  68. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("hc_bj_1");
  69. }
  70. protected override void AddEventListener()
  71. {
  72. base.AddEventListener();
  73. EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, OnItemNumChanged);
  74. }
  75. protected override void OnShown()
  76. {
  77. base.OnShown();
  78. _cardId = 0;
  79. _selectedItemId = 0;
  80. _chapterID = 0;
  81. if (this.viewData != null)
  82. {
  83. _cardId = (int)(this.viewData as object[])[0];
  84. _selectedItemId = (this.viewData as object[]).Length > 1 ? (int)(this.viewData as object[])[1] : 0;
  85. if ((this.viewData as object[]).Length > 2)
  86. _chapterID = (int)(this.viewData as object[])[2];
  87. }
  88. if (DressUpMenuSuitDataManager.chooseClothing > 0)
  89. _selectedItemId = DressUpMenuSuitDataManager.chooseClothing;
  90. _valueBarController.OnShown();
  91. _ui.m_loaBg2.url = ResPathUtil.GetBgImgPath("hc_bj_1");
  92. UpdateView();
  93. Timers.inst.AddUpdate(CheckGuide);
  94. }
  95. protected override void OnHide()
  96. {
  97. base.OnHide();
  98. _valueBarController.OnHide();
  99. _ui.m_listMaterias.selectedIndex = 0;
  100. Timers.inst.Remove(CheckGuide);
  101. _dressUpObjUI.dressUpObj.TakeOffAll();
  102. if (_chapterID > 0)
  103. MainStoryDataManager.currentChapterCfgId = _chapterID;
  104. }
  105. protected override void RemoveEventListener()
  106. {
  107. base.RemoveEventListener();
  108. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, OnItemNumChanged);
  109. }
  110. private void OnClickBtnBack()
  111. {
  112. DressUpMenuSuitDataManager.chooseClothing = 0;
  113. ViewManager.GoBackFrom(typeof(ClothingSyntheticView).FullName);
  114. }
  115. private async void OnClickBtnProcuction()
  116. {
  117. if (ItemDataManager.GetItemNum(_selectedItemId) > 0)
  118. {
  119. PromptController.Instance.ShowFloatTextPrompt("不能制作已经拥有的物品");
  120. return;
  121. }
  122. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_selectedItemId);
  123. if (itemCfg == null)
  124. {
  125. ET.Log.Error("OnClickBtnProcuction itemCfg is null");
  126. return;
  127. }
  128. if (!ItemUtil.CheckItemEnough(itemCfg.syntheticCostID, itemCfg.syntheticCostNum))
  129. {
  130. long has = ItemDataManager.GetItemNum(itemCfg.syntheticCostID);
  131. ItemUtil.BuyCurrency(itemCfg.syntheticCostID, itemCfg.syntheticCostNum - has);
  132. return;
  133. }
  134. List<ItemData> materiarsOfSelectedItem = ItemUtil.CreateItemDataList(itemCfg.syntheticMateriarsArr);
  135. for (int i = 0; i < materiarsOfSelectedItem.Count; i++)
  136. {
  137. ItemData itemData = materiarsOfSelectedItem[i];
  138. if (itemData == null || !ItemUtil.CheckItemEnough(itemData.id, itemData.num, true)) return;
  139. }
  140. bool result = await ClothingSyntheticSProxy.ClothtingSynthetic(_selectedItemId);
  141. if (result)
  142. {
  143. _selectedItemId = 0;
  144. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.FU_ZHUANG_HE_CHENG, 2);
  145. // 发送服装合成成功事件
  146. EventAgent.DispatchEvent(ConstMessage.CLOTHING_SYNTHETIC_SUCCESS);
  147. }
  148. }
  149. private void UpdateView()
  150. {
  151. ItemCfg cardItem = ItemCfgArray.Instance.GetCfg(_cardId);
  152. UpdateName(cardItem.name);
  153. _ui.m_comImgCard.m_ComCardImgRes.m_loaCard.url = ResPathUtil.GetCardPath(cardItem.res);
  154. UpdateSelectedItemInfo();
  155. }
  156. private void UpdateSelectedItemInfo()
  157. {
  158. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_cardId);
  159. //属性展示
  160. RarityIconController.UpdateRarityIcon(_ui.m_loaRarity, _cardId, false);
  161. _ui.m_txtGong.text = "" + itemCfg.score1;
  162. _ui.m_txtShang.text = "" + itemCfg.score2;
  163. _ui.m_txtJue.text = "" + itemCfg.score3;
  164. _ui.m_txtZhi.text = "" + itemCfg.score4;
  165. //合成显示
  166. ItemCfg clothingSyntheticCfg = ItemCfgArray.Instance.GetCfg(_selectedItemId);
  167. // string costName = ItemUtil.GetItemName(clothingSyntheticCfg.syntheticCostID);
  168. // _ui.m_txtCost.SetVar("v1", "" + clothingSyntheticCfg.syntheticCostNum).SetVar("v2", costName).FlushVars();
  169. if (clothingSyntheticCfg.syntheticCostID <= 0)
  170. {
  171. Log.Error($"请为物品 {clothingSyntheticCfg.id} 增加合成相关配置!");
  172. return;
  173. }
  174. ItemUtil.UpdateItemNeedNum(_ui.m_comCostCurrency, clothingSyntheticCfg.syntheticCostID, clothingSyntheticCfg.syntheticCostNum);
  175. _materiarsOfSelectedItem = ItemUtil.CreateItemDataList(clothingSyntheticCfg.syntheticMateriarsArr);
  176. _ui.m_listMaterias.numItems = _materiarsOfSelectedItem.Count;
  177. _ui.m_listMaterias.selectedIndex = 0;
  178. _ui.m_btnProduction.grayed = ItemDataManager.GetItemNum(_selectedItemId) > 0;
  179. }
  180. private void UpdateName(string name)
  181. {
  182. string names = name;
  183. _ui.m_txtName0.text = "";
  184. _ui.m_txtName1.text = "";
  185. _ui.m_txtName2.text = "";
  186. _ui.m_txtName3.text = "";
  187. _ui.m_txtName4.text = "";
  188. switch (names.Length)
  189. {
  190. case 1:
  191. _ui.m_txtName0.text = names.Substring(0, 1);
  192. break;
  193. case 2:
  194. _ui.m_txtName0.text = names.Substring(0, 1);
  195. _ui.m_txtName2.text = names.Substring(1, 1);
  196. break;
  197. case 3:
  198. _ui.m_txtName0.text = names.Substring(0, 1);
  199. _ui.m_txtName1.text = names.Substring(1, 1);
  200. _ui.m_txtName2.text = names.Substring(2, 1);
  201. break;
  202. case 4:
  203. _ui.m_txtName0.text = names.Substring(0, 1);
  204. _ui.m_txtName1.text = names.Substring(1, 1);
  205. _ui.m_txtName2.text = names.Substring(2, 1);
  206. _ui.m_txtName3.text = names.Substring(3, 1);
  207. break;
  208. default:
  209. _ui.m_txtName0.text = names.Substring(0, 1);
  210. _ui.m_txtName1.text = names.Substring(1, 1);
  211. _ui.m_txtName2.text = names.Substring(2, 1);
  212. _ui.m_txtName3.text = names.Substring(3, 1);
  213. _ui.m_txtName4.text = names.Substring(4);
  214. break;
  215. }
  216. }
  217. private void RenderListMateriasItem(int index, GObject obj)
  218. {
  219. UI_MateriasListItem listItem = UI_MateriasListItem.Proxy(obj);
  220. ItemData itemData = _materiarsOfSelectedItem[index];
  221. ItemCfg materiasItemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  222. listItem.m_txtName.text = ItemUtil.GetItemName(itemData.id);
  223. listItem.m_loaderIcon.url = ResPathUtil.GetIconPath(materiasItemCfg);
  224. long num = ItemDataManager.GetItemNum(itemData.id);
  225. ItemCfg materialCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  226. bool isDressUp = materialCfg.itemType == ConstItemType.DRESS_UP;
  227. long numSynthetic = Math.Max(num, 0);
  228. listItem.m_txtProgess.text = numSynthetic + "/" + itemData.num;
  229. listItem.m_loaderIcon.visible = true;
  230. listItem.m_txtProgess.visible = true;
  231. // listItem.target.onClick.Clear();
  232. // if (listItem.target.data == null)
  233. // {
  234. // listItem.target.onClick.Add(OnClickMateriasItemPlus);
  235. // }
  236. listItem.target.data = index;
  237. UI_MateriasListItem.ProxyEnd();
  238. }
  239. private void OnClickMateriasItemPlus(EventContext context)
  240. {
  241. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.CLOTHING_SYNTHETIC);
  242. if (GuideDataManager.currentGuideId == cfg.id)
  243. {
  244. return;
  245. }
  246. if (ItemDataManager.GetItemNum(_selectedItemId) > 0)
  247. {
  248. PromptController.Instance.ShowFloatTextPrompt("该材料已获得");
  249. return;
  250. }
  251. int index = (int)(context.data as GObject).data;
  252. _ui.m_listMaterias.selectedIndex = index;
  253. ItemData itemData = _materiarsOfSelectedItem[index];
  254. if (itemData == null)
  255. {
  256. ET.Log.Error("OnClickMateriasItemPlus itemData is null");
  257. return;
  258. }
  259. object[] sourceDatas = new object[] { itemData.id, new object[] { typeof(ClothingSyntheticView).FullName, new object[] { _cardId, _selectedItemId } }, (int)itemData.num };
  260. GoodsItemTipsController.ShowItemTips(itemData.id, sourceDatas);
  261. }
  262. private void OnItemNumChanged()
  263. {
  264. //列表选中项更新
  265. UI_ClothingListItem selectedItem = UI_ClothingListItem.Proxy(_selectedListItem);
  266. selectedItem.m_imgOwned.visible = ItemDataManager.GetItemNum(_selectedItemId) > 0;
  267. UI_ClothingListItem.ProxyEnd();
  268. UpdateSelectedItemInfo();
  269. }
  270. private void OnClickBtnHome()
  271. {
  272. GameController.GoBackToMainView();
  273. }
  274. private void CheckGuide(object param)
  275. {
  276. //if (GuideDataManager.IsGuideFinish(ConstGuideId.CLOTHING_SYNTHETIC) <= 0)
  277. //{
  278. // UpdateToCheckGuide(null);
  279. //}
  280. //else
  281. //{
  282. // Timers.inst.Remove(CheckGuide);
  283. //}
  284. }
  285. protected override void UpdateToCheckGuide(object param)
  286. {
  287. //if (ViewManager.isViewOpen(typeof(GuideView).Name))
  288. //{
  289. // (ViewManager.GetUIView(typeof(GuideView).Name) as GuideView).viewCom.visible = !ViewManager.isViewOpen(typeof(GetSuitItemVIew).Name);
  290. //}
  291. //if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  292. //int itemId = 10566;
  293. //int itemIndex = 0;
  294. //for (int i = 0; i < _ui.m_listClothing.numItems; i++)
  295. //{
  296. // UI_ClothingListItem listItem = UI_ClothingListItem.Proxy(_ui.m_listClothing.GetChildAt(i));
  297. // int temp = (int)listItem.target.data;
  298. // UI_ClothingListItem.ProxyEnd();
  299. // if (temp == itemId)
  300. // {
  301. // itemIndex = i;
  302. // break;
  303. // }
  304. //}
  305. //bool guide = GuideController.TryGuide(_ui.m_listClothing, ConstGuideId.CLOTHING_SYNTHETIC, 3, "找到需要合成的物品。", itemIndex);
  306. //if (guide) _ui.m_listClothing.ScrollToView(itemIndex);
  307. //GuideController.TryGuide(_ui.m_listMaterias, ConstGuideId.CLOTHING_SYNTHETIC, 4, "这里可以查看合成需要的材料,和材料的获取途径。", 0);
  308. //UI_MateriasListItem.ProxyEnd();
  309. //GuideController.TryGuide(_ui.m_btnProduction, ConstGuideId.CLOTHING_SYNTHETIC, 5, "点击获得新的服饰。");
  310. //GuideController.TryGuide(_ui.m_btnBack, ConstGuideId.CLOTHING_SYNTHETIC, 6, "获得新衣服啦,继续通关主线剧情吧。");
  311. }
  312. }
  313. }