123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362 |
- 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 int cardSyntheticCount;
- private List<ItemData> _materiarsOfSelectedItem;
- private ItemCfg _cardItem;
- private UI_MateriasListItem listTypeItem_CloSynthetic;
- 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 async 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");
- ItemCfg item = ItemCfgArray.Instance.GetCfg(_cardItem.transItem);
- _ui.m_skillIcon.url = ResPathUtil.GetIconPath(item.res,"png");
- var response = await ClothingSyntheticSProxy.GetCardSyntheticCount(_cardId);
- cardSyntheticCount = response;
- 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 (cardSyntheticCount > 0)
- {
- isfirst = false;
- }
- else
- {
- isfirst = true;
- }
- if (cardSyntheticCount >= _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<ItemData> 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);
- 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}", cardSyntheticCount, _cardItem.syntheticTimes);
- ItemData itemCount;
- long count;
- if (BagDataManager.Instance.GetBagData().TryGetValue(_cardItem.transItem, out itemCount))
- {
- count = itemCount.num;
- }
- else
- {
- count = 0;
- }
- _ui.m_skillCountText.text = string.Format("已拥有:{0}", count.ToString());
- UpdateSelectedItemInfo();
- RedDotController.Instance.SetComRedDot(_ui.m_btnProduction, RedDotDataManager.Instance.CheckCardCanSynthetic(_cardId),"");
- }
- 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 = cardSyntheticCount > 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 async void OnItemNumChanged()
- {
- _ui.m_listMaterias.numItems = _materiarsOfSelectedItem.Count;
- var response = await ClothingSyntheticSProxy.GetCardSyntheticCount(_cardId);
- cardSyntheticCount = response;
- //这里应该是制作卡牌次数
- _ui.m_btnProduction.grayed = cardSyntheticCount > _cardItem.syntheticTimes;
- RedDotController.Instance.SetComRedDot(_ui.m_btnProduction, RedDotDataManager.Instance.CheckCardCanSynthetic(_cardId), "");
- _ui.m_timesText.text = string.Format("合成次数:{0}/{1}", cardSyntheticCount, _cardItem.syntheticTimes);
- ItemData itemCount;
- long count;
- if (BagDataManager.Instance.GetBagData().TryGetValue(_cardItem.transItem, out itemCount))
- {
- count = itemCount.num;
- }
- else
- {
- count = 0;
- }
- _ui.m_skillCountText.text = string.Format("已拥有:{0}", count.ToString());
- }
- private async void GetCardSyntheticCount(int cardID)
- {
- var response = await ClothingSyntheticSProxy.GetCardSyntheticCount(cardID);
- cardSyntheticCount = response;
- }
- 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, "获得新衣服啦,继续通关主线剧情吧。");
- }
- }
- }
|