CardSyntheticView.cs 13 KB

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