using UnityEngine; using UI.ClothingSynthetic; using UI.CardSynthetic; using FairyGUI; using System.Collections.Generic; using System; using ET; using System.Collections; using System.Threading.Tasks; using YooAsset; namespace GFGGame { public class CardSyntheticView : BaseWindow { private UI_CardSyntheticUI _ui; private ValueBarController _valueBarController; private int _cardId; private int _chapterID; private int _itemId; private int[] _items; private List _materiarsOfSelectedItem; private ItemCfg _cardItem; private UI_MateriasListItem listTypeItem_CloSynthetic; private UI_Component2 _compMover; public override void Dispose() { if (_valueBarController != null) { _valueBarController.Dispose(); _valueBarController = null; } if (_ui != null) { _ui.Dispose(); _ui = null; } base.Dispose(); } protected override void OnInit() { base.OnInit(); packageName = UI_CardSyntheticUI.PACKAGE_NAME; _ui = UI_CardSyntheticUI.Create(); this.viewCom = _ui.target; isfullScreen = true; //layer = ConstViewLayer.TOP; isReturnView = true; _valueBarController = new ValueBarController(_ui.m_valueBar); _ui.m_listMaterias.itemRenderer = RenderListMateriasItem; _ui.m_listMaterias.onClickItem.Add(OnClickMateriasItemPlus); _ui.m_btnBack.onClick.Add(OnClickBtnBack); _ui.m_btnProduction.onClick.Add(OnClickBtnProcuction); _ui.m_btnHome.onClick.Add(OnClickBtnHome); _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("hc_bj_1"); } protected override void AddEventListener() { base.AddEventListener(); EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, OnItemNumChanged); } protected override void OnShown() { base.OnShown(); _cardId = 0; //_chapterID = 0; if (this.viewData != null) { _cardId = (int)(this.viewData as object[])[0]; //if ((this.viewData as object[]).Length > 2) // _chapterID = (int)(this.viewData as object[])[2]; } _cardItem = ItemCfgArray.Instance.GetCfg(_cardId); _valueBarController.OnShown(); _ui.m_loaBg2.url = ResPathUtil.GetBgImgPath("hc_bj_1"); UpdateView(); Timers.inst.AddUpdate(CheckGuide); } protected override void OnHide() { base.OnHide(); _valueBarController.OnHide(); _ui.m_listMaterias.selectedIndex = 0; Timers.inst.Remove(CheckGuide); } protected override void RemoveEventListener() { base.RemoveEventListener(); EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, OnItemNumChanged); } private void OnClickBtnBack() { DressUpMenuSuitDataManager.chooseClothing = 0; ViewManager.GoBackFrom(typeof(CardSyntheticView).FullName); } private async void OnClickBtnProcuction() { bool isfirst; //这里应该是制作卡牌次数 if (ItemDataManager.GetItemNum(_cardId) > 0) { isfirst = false; } else { isfirst = true; } if (ItemDataManager.GetItemNum(_cardId) >= _cardItem.syntheticTimes) { isfirst = false; PromptController.Instance.ShowFloatTextPrompt("制作已上限"); return; } ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_cardId); if (itemCfg == null) { ET.Log.Error("OnClickBtnProcuction itemCfg is null"); return; } if (!ItemUtil.CheckItemEnough(itemCfg.syntheticCostID, itemCfg.syntheticCostNum)) { long has = ItemDataManager.GetItemNum(itemCfg.syntheticCostID); ItemUtil.BuyCurrency(itemCfg.syntheticCostID, itemCfg.syntheticCostNum - has); return; } List materiarsOfSelectedItem = ItemUtil.CreateItemDataList(itemCfg.syntheticMateriarsArr); for (int i = 0; i < materiarsOfSelectedItem.Count; i++) { ItemData itemData = materiarsOfSelectedItem[i]; if (itemData == null || !ItemUtil.CheckItemEnough(itemData.id, itemData.num, true)) return; } bool result = await ClothingSyntheticSProxy.CardSynthetic(_cardId, isfirst); if (result) { LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.FU_ZHUANG_HE_CHENG, 2); } } private void UpdateView() { UpdateName(_cardItem.name); _ui.m_comImgCard.m_ComCardImgRes.m_loaCard.url = ResPathUtil.GetCardPath(_cardItem.res); _ui.m_timesText.text = string.Format("{0}/{1}", ItemDataManager.GetItemNum(_cardId), _cardItem.syntheticTimes); UpdateSelectedItemInfo(); } private void UpdateSelectedItemInfo() { ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_cardId); //属性展示 RarityIconController.UpdateRarityIcon(_ui.m_loaRarity, _cardId, false); _ui.m_txtGong.text = "" + itemCfg.score1; _ui.m_txtShang.text = "" + itemCfg.score2; _ui.m_txtJue.text = "" + itemCfg.score3; _ui.m_txtZhi.text = "" + itemCfg.score4; //合成显示 ItemCfg clothingSyntheticCfg = ItemCfgArray.Instance.GetCfg(_cardId); // string costName = ItemUtil.GetItemName(clothingSyntheticCfg.syntheticCostID); // _ui.m_txtCost.SetVar("v1", "" + clothingSyntheticCfg.syntheticCostNum).SetVar("v2", costName).FlushVars(); if (clothingSyntheticCfg.syntheticCostID <= 0) { Log.Error($"请为物品 {clothingSyntheticCfg.id} 增加合成相关配置!"); return; } ItemUtil.UpdateItemNeedNum(_ui.m_comCostCurrency, clothingSyntheticCfg.syntheticCostID, clothingSyntheticCfg.syntheticCostNum); _materiarsOfSelectedItem = ItemUtil.CreateItemDataList(clothingSyntheticCfg.syntheticMateriarsArr); _ui.m_listMaterias.numItems = _materiarsOfSelectedItem.Count; _ui.m_listMaterias.selectedIndex = 0; //这里应该是制作卡牌次数 _ui.m_btnProduction.grayed = ItemDataManager.GetItemNum(_cardId) > clothingSyntheticCfg.syntheticTimes; } private void UpdateName(string name) { string names = name; _ui.m_txtName0.text = ""; _ui.m_txtName1.text = ""; _ui.m_txtName2.text = ""; _ui.m_txtName3.text = ""; _ui.m_txtName4.text = ""; switch (names.Length) { case 1: _ui.m_txtName0.text = names.Substring(0, 1); break; case 2: _ui.m_txtName0.text = names.Substring(0, 1); _ui.m_txtName2.text = names.Substring(1, 1); break; case 3: _ui.m_txtName0.text = names.Substring(0, 1); _ui.m_txtName1.text = names.Substring(1, 1); _ui.m_txtName2.text = names.Substring(2, 1); break; case 4: _ui.m_txtName0.text = names.Substring(0, 1); _ui.m_txtName1.text = names.Substring(1, 1); _ui.m_txtName2.text = names.Substring(2, 1); _ui.m_txtName3.text = names.Substring(3, 1); break; default: _ui.m_txtName0.text = names.Substring(0, 1); _ui.m_txtName1.text = names.Substring(1, 1); _ui.m_txtName2.text = names.Substring(2, 1); _ui.m_txtName3.text = names.Substring(3, 1); _ui.m_txtName4.text = names.Substring(4); break; } } private void RenderListMateriasItem(int index, GObject obj) { UI_MateriasListItem listItem = UI_MateriasListItem.Proxy(obj); ItemData itemData = _materiarsOfSelectedItem[index]; ItemCfg materiasItemCfg = ItemCfgArray.Instance.GetCfg(itemData.id); listItem.m_txtName.text = ItemUtil.GetItemName(itemData.id); listItem.m_loaderIcon.url = ResPathUtil.GetIconPath(materiasItemCfg); long num = ItemDataManager.GetItemNum(itemData.id); ItemCfg materialCfg = ItemCfgArray.Instance.GetCfg(itemData.id); bool isDressUp = materialCfg.itemType == ConstItemType.DRESS_UP; long numSynthetic = Math.Max(num, 0); listItem.m_txtProgess.text = numSynthetic + "/" + itemData.num; listItem.m_loaderIcon.visible = true; listItem.m_txtProgess.visible = true; // listItem.target.onClick.Clear(); // if (listItem.target.data == null) // { // listItem.target.onClick.Add(OnClickMateriasItemPlus); // } listItem.target.data = index; UI_MateriasListItem.ProxyEnd(); } private void OnClickMateriasItemPlus(EventContext context) { GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.CLOTHING_SYNTHETIC); if (GuideDataManager.currentGuideId == cfg.id) { return; } int index = (int)(context.data as GObject).data; _ui.m_listMaterias.selectedIndex = index; ItemData itemData = _materiarsOfSelectedItem[index]; if (itemData == null) { ET.Log.Error("OnClickMateriasItemPlus itemData is null"); return; } object[] sourceDatas = new object[] { itemData.id, new object[] { typeof(CardSyntheticView).FullName, new object[] { _cardId } }, (int)itemData.num }; GoodsItemTipsController.ShowItemTips(itemData.id, sourceDatas); } private void OnClickBtnHome() { GameController.GoBackToMainView(); } private void OnItemNumChanged() { _ui.m_listMaterias.numItems = _materiarsOfSelectedItem.Count; //这里应该是制作卡牌次数 _ui.m_btnProduction.grayed = ItemDataManager.GetItemNum(_cardId) > _cardItem.syntheticTimes; _ui.m_timesText.text = string.Format("{0}/{1}", ItemDataManager.GetItemNum(_cardId), _cardItem.syntheticTimes); } private void CheckGuide(object param) { //if (GuideDataManager.IsGuideFinish(ConstGuideId.CLOTHING_SYNTHETIC) <= 0) //{ // UpdateToCheckGuide(null); //} //else //{ // Timers.inst.Remove(CheckGuide); //} } protected override void UpdateToCheckGuide(object param) { //if (ViewManager.isViewOpen(typeof(GuideView).Name)) //{ // (ViewManager.GetUIView(typeof(GuideView).Name) as GuideView).viewCom.visible = !ViewManager.isViewOpen(typeof(GetSuitItemVIew).Name); //} //if (!ViewManager.CheckIsTopView(this.viewCom)) return; //int itemId = 10566; //int itemIndex = 0; //for (int i = 0; i < _ui.m_listClothing.numItems; i++) //{ // UI_ClothingListItem listItem = UI_ClothingListItem.Proxy(_ui.m_listClothing.GetChildAt(i)); // int temp = (int)listItem.target.data; // UI_ClothingListItem.ProxyEnd(); // if (temp == itemId) // { // itemIndex = i; // break; // } //} //bool guide = GuideController.TryGuide(_ui.m_listClothing, ConstGuideId.CLOTHING_SYNTHETIC, 3, "找到需要合成的物品。", itemIndex); //if (guide) _ui.m_listClothing.ScrollToView(itemIndex); //GuideController.TryGuide(_ui.m_listMaterias, ConstGuideId.CLOTHING_SYNTHETIC, 4, "这里可以查看合成需要的材料,和材料的获取途径。", 0); //UI_MateriasListItem.ProxyEnd(); //GuideController.TryGuide(_ui.m_btnProduction, ConstGuideId.CLOTHING_SYNTHETIC, 5, "点击获得新的服饰。"); //GuideController.TryGuide(_ui.m_btnBack, ConstGuideId.CLOTHING_SYNTHETIC, 6, "获得新衣服啦,继续通关主线剧情吧。"); } } }