CardSyntheticView.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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 List<ItemData> _materiarsOfSelectedItem;
  22. private ItemCfg _cardItem;
  23. private UI_MateriasListItem listTypeItem_CloSynthetic;
  24. private UI_Component2 _compMover;
  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 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. UpdateView();
  76. Timers.inst.AddUpdate(CheckGuide);
  77. }
  78. protected override void OnHide()
  79. {
  80. base.OnHide();
  81. _valueBarController.OnHide();
  82. _ui.m_listMaterias.selectedIndex = 0;
  83. Timers.inst.Remove(CheckGuide);
  84. }
  85. protected override void RemoveEventListener()
  86. {
  87. base.RemoveEventListener();
  88. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, OnItemNumChanged);
  89. }
  90. private void OnClickBtnBack()
  91. {
  92. DressUpMenuSuitDataManager.chooseClothing = 0;
  93. ViewManager.GoBackFrom(typeof(CardSyntheticView).FullName);
  94. }
  95. private async void OnClickBtnProcuction()
  96. {
  97. bool isfirst;
  98. //这里应该是制作卡牌次数
  99. if (ItemDataManager.GetItemNum(_cardId) > 0)
  100. {
  101. isfirst = false;
  102. }
  103. else
  104. {
  105. isfirst = true;
  106. }
  107. if (ItemDataManager.GetItemNum(_cardId) >= _cardItem.syntheticTimes)
  108. {
  109. isfirst = false;
  110. PromptController.Instance.ShowFloatTextPrompt("制作已上限");
  111. return;
  112. }
  113. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_cardId);
  114. if (itemCfg == null)
  115. {
  116. ET.Log.Error("OnClickBtnProcuction itemCfg is null");
  117. return;
  118. }
  119. if (!ItemUtil.CheckItemEnough(itemCfg.syntheticCostID, itemCfg.syntheticCostNum))
  120. {
  121. long has = ItemDataManager.GetItemNum(itemCfg.syntheticCostID);
  122. ItemUtil.BuyCurrency(itemCfg.syntheticCostID, itemCfg.syntheticCostNum - has);
  123. return;
  124. }
  125. List<ItemData> materiarsOfSelectedItem = ItemUtil.CreateItemDataList(itemCfg.syntheticMateriarsArr);
  126. for (int i = 0; i < materiarsOfSelectedItem.Count; i++)
  127. {
  128. ItemData itemData = materiarsOfSelectedItem[i];
  129. if (itemData == null || !ItemUtil.CheckItemEnough(itemData.id, itemData.num, true)) return;
  130. }
  131. bool result = await ClothingSyntheticSProxy.CardSynthetic(_cardId, isfirst);
  132. if (result)
  133. {
  134. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.FU_ZHUANG_HE_CHENG, 2);
  135. }
  136. }
  137. private void UpdateView()
  138. {
  139. UpdateName(_cardItem.name);
  140. _ui.m_comImgCard.m_ComCardImgRes.m_loaCard.url = ResPathUtil.GetCardPath(_cardItem.res);
  141. _ui.m_timesText.text = string.Format("{0}/{1}", ItemDataManager.GetItemNum(_cardId), _cardItem.syntheticTimes);
  142. UpdateSelectedItemInfo();
  143. }
  144. private void UpdateSelectedItemInfo()
  145. {
  146. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_cardId);
  147. //属性展示
  148. RarityIconController.UpdateRarityIcon(_ui.m_loaRarity, _cardId, false);
  149. _ui.m_txtGong.text = "" + itemCfg.score1;
  150. _ui.m_txtShang.text = "" + itemCfg.score2;
  151. _ui.m_txtJue.text = "" + itemCfg.score3;
  152. _ui.m_txtZhi.text = "" + itemCfg.score4;
  153. //合成显示
  154. ItemCfg clothingSyntheticCfg = ItemCfgArray.Instance.GetCfg(_cardId);
  155. // string costName = ItemUtil.GetItemName(clothingSyntheticCfg.syntheticCostID);
  156. // _ui.m_txtCost.SetVar("v1", "" + clothingSyntheticCfg.syntheticCostNum).SetVar("v2", costName).FlushVars();
  157. if (clothingSyntheticCfg.syntheticCostID <= 0)
  158. {
  159. Log.Error($"请为物品 {clothingSyntheticCfg.id} 增加合成相关配置!");
  160. return;
  161. }
  162. ItemUtil.UpdateItemNeedNum(_ui.m_comCostCurrency, clothingSyntheticCfg.syntheticCostID, clothingSyntheticCfg.syntheticCostNum);
  163. _materiarsOfSelectedItem = ItemUtil.CreateItemDataList(clothingSyntheticCfg.syntheticMateriarsArr);
  164. _ui.m_listMaterias.numItems = _materiarsOfSelectedItem.Count;
  165. _ui.m_listMaterias.selectedIndex = 0;
  166. //这里应该是制作卡牌次数
  167. _ui.m_btnProduction.grayed = ItemDataManager.GetItemNum(_cardId) > clothingSyntheticCfg.syntheticTimes;
  168. }
  169. private void UpdateName(string name)
  170. {
  171. string names = name;
  172. _ui.m_txtName0.text = "";
  173. _ui.m_txtName1.text = "";
  174. _ui.m_txtName2.text = "";
  175. _ui.m_txtName3.text = "";
  176. _ui.m_txtName4.text = "";
  177. switch (names.Length)
  178. {
  179. case 1:
  180. _ui.m_txtName0.text = names.Substring(0, 1);
  181. break;
  182. case 2:
  183. _ui.m_txtName0.text = names.Substring(0, 1);
  184. _ui.m_txtName2.text = names.Substring(1, 1);
  185. break;
  186. case 3:
  187. _ui.m_txtName0.text = names.Substring(0, 1);
  188. _ui.m_txtName1.text = names.Substring(1, 1);
  189. _ui.m_txtName2.text = names.Substring(2, 1);
  190. break;
  191. case 4:
  192. _ui.m_txtName0.text = names.Substring(0, 1);
  193. _ui.m_txtName1.text = names.Substring(1, 1);
  194. _ui.m_txtName2.text = names.Substring(2, 1);
  195. _ui.m_txtName3.text = names.Substring(3, 1);
  196. break;
  197. default:
  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. _ui.m_txtName3.text = names.Substring(3, 1);
  202. _ui.m_txtName4.text = names.Substring(4);
  203. break;
  204. }
  205. }
  206. private void RenderListMateriasItem(int index, GObject obj)
  207. {
  208. UI_MateriasListItem listItem = UI_MateriasListItem.Proxy(obj);
  209. ItemData itemData = _materiarsOfSelectedItem[index];
  210. ItemCfg materiasItemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  211. listItem.m_txtName.text = ItemUtil.GetItemName(itemData.id);
  212. listItem.m_loaderIcon.url = ResPathUtil.GetIconPath(materiasItemCfg);
  213. long num = ItemDataManager.GetItemNum(itemData.id);
  214. ItemCfg materialCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  215. bool isDressUp = materialCfg.itemType == ConstItemType.DRESS_UP;
  216. long numSynthetic = Math.Max(num, 0);
  217. listItem.m_txtProgess.text = numSynthetic + "/" + itemData.num;
  218. listItem.m_loaderIcon.visible = true;
  219. listItem.m_txtProgess.visible = true;
  220. // listItem.target.onClick.Clear();
  221. // if (listItem.target.data == null)
  222. // {
  223. // listItem.target.onClick.Add(OnClickMateriasItemPlus);
  224. // }
  225. listItem.target.data = index;
  226. UI_MateriasListItem.ProxyEnd();
  227. }
  228. private void OnClickMateriasItemPlus(EventContext context)
  229. {
  230. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.CLOTHING_SYNTHETIC);
  231. if (GuideDataManager.currentGuideId == cfg.id)
  232. {
  233. return;
  234. }
  235. int index = (int)(context.data as GObject).data;
  236. _ui.m_listMaterias.selectedIndex = index;
  237. ItemData itemData = _materiarsOfSelectedItem[index];
  238. if (itemData == null)
  239. {
  240. ET.Log.Error("OnClickMateriasItemPlus itemData is null");
  241. return;
  242. }
  243. object[] sourceDatas = new object[] { itemData.id, new object[] { typeof(CardSyntheticView).FullName, new object[] { _cardId } }, (int)itemData.num };
  244. GoodsItemTipsController.ShowItemTips(itemData.id, sourceDatas);
  245. }
  246. private void OnClickBtnHome()
  247. {
  248. GameController.GoBackToMainView();
  249. }
  250. private void OnItemNumChanged()
  251. {
  252. _ui.m_listMaterias.numItems = _materiarsOfSelectedItem.Count;
  253. //这里应该是制作卡牌次数
  254. _ui.m_btnProduction.grayed = ItemDataManager.GetItemNum(_cardId) > _cardItem.syntheticTimes;
  255. _ui.m_timesText.text = string.Format("{0}/{1}", ItemDataManager.GetItemNum(_cardId), _cardItem.syntheticTimes);
  256. }
  257. private void CheckGuide(object param)
  258. {
  259. //if (GuideDataManager.IsGuideFinish(ConstGuideId.CLOTHING_SYNTHETIC) <= 0)
  260. //{
  261. // UpdateToCheckGuide(null);
  262. //}
  263. //else
  264. //{
  265. // Timers.inst.Remove(CheckGuide);
  266. //}
  267. }
  268. protected override void UpdateToCheckGuide(object param)
  269. {
  270. //if (ViewManager.isViewOpen(typeof(GuideView).Name))
  271. //{
  272. // (ViewManager.GetUIView(typeof(GuideView).Name) as GuideView).viewCom.visible = !ViewManager.isViewOpen(typeof(GetSuitItemVIew).Name);
  273. //}
  274. //if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  275. //int itemId = 10566;
  276. //int itemIndex = 0;
  277. //for (int i = 0; i < _ui.m_listClothing.numItems; i++)
  278. //{
  279. // UI_ClothingListItem listItem = UI_ClothingListItem.Proxy(_ui.m_listClothing.GetChildAt(i));
  280. // int temp = (int)listItem.target.data;
  281. // UI_ClothingListItem.ProxyEnd();
  282. // if (temp == itemId)
  283. // {
  284. // itemIndex = i;
  285. // break;
  286. // }
  287. //}
  288. //bool guide = GuideController.TryGuide(_ui.m_listClothing, ConstGuideId.CLOTHING_SYNTHETIC, 3, "找到需要合成的物品。", itemIndex);
  289. //if (guide) _ui.m_listClothing.ScrollToView(itemIndex);
  290. //GuideController.TryGuide(_ui.m_listMaterias, ConstGuideId.CLOTHING_SYNTHETIC, 4, "这里可以查看合成需要的材料,和材料的获取途径。", 0);
  291. //UI_MateriasListItem.ProxyEnd();
  292. //GuideController.TryGuide(_ui.m_btnProduction, ConstGuideId.CLOTHING_SYNTHETIC, 5, "点击获得新的服饰。");
  293. //GuideController.TryGuide(_ui.m_btnBack, ConstGuideId.CLOTHING_SYNTHETIC, 6, "获得新衣服啦,继续通关主线剧情吧。");
  294. }
  295. }
  296. }