CardSyntheticView.cs 15 KB

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