CardSyntheticView.cs 14 KB

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