using UnityEngine; using UI.ClothingSynthetic; using FairyGUI; using System.Collections.Generic; using System; using ET; using System.Collections; using System.Threading.Tasks; using YooAsset; namespace GFGGame { public class ClothingSyntheticView : BaseWindow { private const int HEAD_Y = 942; private const int FA_XING_Y = 609; private const int UPPER_BODY_Y = 383; private const int LOWER_BODY_Y = 112; private const int SHOES_Y = -287; private const int BODY_Y = 289; private const float HEAD_SCALE = 3f; private const float FA_XING_SCALE = 2f; private const float UPPER_BODY_SCALE = 1.5f; private const float LOWER_BODY_SCALE = 1.4f; private const float SHOES_SCALE = 2.5f; private const float BODY_SCALE = 1f; private const float DURATION = 0.6f; private readonly int[] HEAD_Y_ARR = new int[] { ConstDressUpItemType.TOU_SHI, ConstDressUpItemType.ER_SHI, ConstDressUpItemType.JING_SHI, ConstDressUpItemType.ZHUANG_RONG }; private readonly int[] FA_XING_Y_ARR = new int[] { ConstDressUpItemType.FA_XING }; private readonly int[] UPPER_BODY_Y_ARR = new int[] { ConstDressUpItemType.NEI_DA, ConstDressUpItemType.SHANG_YI }; private readonly int[] LOWER_BODY_Y_ARR = new int[] { ConstDressUpItemType.XIA_ZHUANG, ConstDressUpItemType.SHOU_SHI }; private readonly int[] SHOES_Y_ARR = new int[] { ConstDressUpItemType.WA_ZI, ConstDressUpItemType.XIE_ZI }; private UI_ClothingSyntheticUI _ui; private DressUpObjUI _dressUpObjUI; private ValueBarController _valueBarController; private GImage _imgSelected; private int _suitId; private int _chapterID; private int _itemId; private int[] _items; private int _selectedItemId; private GComponent _selectedListItem; private List _materiarsOfSelectedItem; private UI_MateriasListItem listTypeItem_CloSynthetic; private UI_Component2 _compMover; private int _cardID; public override void Dispose() { RemoveSoftMask(); if (_valueBarController != null) { _valueBarController.Dispose(); _valueBarController = null; } if (_imgSelected != null) { _imgSelected.RemoveFromParent(); _imgSelected.Dispose(); } if (_dressUpObjUI != null) { _dressUpObjUI.Dispose(); _dressUpObjUI = null; } if (_ui != null) { _ui.Dispose(); _ui = null; } base.Dispose(); } protected override void OnInit() { base.OnInit(); packageName = UI_ClothingSyntheticListUI.PACKAGE_NAME; _ui = UI_ClothingSyntheticUI.Create(); this.viewCom = _ui.target; isfullScreen = true; //layer = ConstViewLayer.TOP; isReturnView = true; //this.clickBlankToClose = false; _compMover = _ui.m_compHolder.m_compHolder.m_compMover; _valueBarController = new ValueBarController(_ui.m_valueBar); _dressUpObjUI = new DressUpObjUI("SceneDressUpSynthetic"); _imgSelected = new GImage(); _imgSelected = UIPackage.CreateObject(UI_ClothingSyntheticUI.PACKAGE_NAME, "hc_kuang_4").asImage; _ui.m_listClothing.itemRenderer = ListClothingItemRender; _ui.m_listClothing.onClickItem.Add(OnClickListClothingItem); _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_cardSyntheticBtn.onClick.Add(OnClickBtnCardSyntheticView); _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("hc_bj_1"); UpdateMaskHeight(); } protected override void AddEventListener() { base.AddEventListener(); EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, OnItemNumChanged); } protected override void OnShown() { base.OnShown(); _suitId = 0; _selectedItemId = 0; _chapterID = 0; if (this.viewData != null) { _suitId = (int)(this.viewData as object[])[0]; _selectedItemId = (this.viewData as object[]).Length > 1 ? (int)(this.viewData as object[])[1] : 0; if((this.viewData as object[]).Length > 2) _chapterID = (int)(this.viewData as object[])[2]; } UpdateCardSyntheticBtn(); if (DressUpMenuSuitDataManager.chooseClothing > 0) _selectedItemId = DressUpMenuSuitDataManager.chooseClothing; _valueBarController.OnShown(); _ui.m_loaBg2.url = ResPathUtil.GetBgImgPath("hc_bj_1"); UpdateClothingList(false); Timers.inst.AddUpdate(CheckGuide); } protected override void OnHide() { base.OnHide(); _valueBarController.OnHide(); _ui.m_listMaterias.selectedIndex = 0; Timers.inst.Remove(CheckGuide); _dressUpObjUI.dressUpObj.TakeOffAll(); if(_chapterID > 0) MainStoryDataManager.currentChapterCfgId = _chapterID; } protected override void RemoveEventListener() { base.RemoveEventListener(); EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, OnItemNumChanged); } private void OnClickBtnBack() { DressUpMenuSuitDataManager.chooseClothing = 0; ViewManager.GoBackFrom(typeof(ClothingSyntheticView).FullName); } private void OnClickListClothingItem(EventContext context) { UpdateSelectedItemInfo(context.data as GComponent, true); } private async void OnClickBtnProcuction() { if (ItemDataManager.GetItemNum(_selectedItemId) > 0) { PromptController.Instance.ShowFloatTextPrompt("不能制作已经拥有的物品"); return; } ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_selectedItemId); 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.ClothtingSynthetic(_selectedItemId); if (result) { _selectedItemId = 0; UpdateClothingList(true); LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.FU_ZHUANG_HE_CHENG, 2); Timers.inst.AddUpdate(CheckGuide); // 发送服装合成成功事件 EventAgent.DispatchEvent(ConstMessage.CLOTHING_SYNTHETIC_SUCCESS); EventAgent.DispatchEvent(ConstMessage.STUDIO_FILING_UPDATE); } } private void ListClothingItemRender(int index, GObject item) { UI_ClothingListItem listItem = UI_ClothingListItem.Proxy(item); int itemId = _items[index]; listItem.target.data = itemId; ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId); listItem.m_loaderIcon.url = ResPathUtil.GetIconPath(itemCfg); string itemName = itemCfg.name; listItem.m_txtName.text = itemName; listItem.m_imgOwned.visible = ItemDataManager.GetItemNum(itemId) > 0; RedDotController.Instance.SetComRedDot(listItem.target, RedDotDataManager.Instance.CheckCanSynthetic(itemId), "", -18, 20); UI_ClothingListItem.ProxyEnd(); } private EaseType ease = EaseType.CubicOut; private void UpdateRole(bool tween) { // 隐藏遮罩 _ui.m_loaBg2.visible = false; // 根据高度比例放大(越高越大) float rate = Screen.height * 1080f / 1920f / Screen.width; // 平板会比宽手机更宽,设定最小值防止缩小 rate = Mathf.Max(rate, 1); _dressUpObjUI.dressUpObj.TakeOffAll(); _dressUpObjUI.ResetSceneObj(45, true, true, null, false); _dressUpObjUI.dressUpObj.AddOrRemove(_selectedItemId, true, DressUpOption.Add); //_imgSelected.visible = _dressUpObjUI.dressUpObj.CheckDressUpItemIsOn(_selectedItemId); _imgSelected.visible = true; _dressUpObjUI.UpdateWrapper(_compMover.m_holder); int type = ItemUtilCS.GetItemSubType(_selectedItemId); float duration = DURATION; if (!tween) { duration = 0; _ui.m_hide.Play(); } var dy = _ui.m_compHolder.target.height - 642; if (Array.IndexOf(HEAD_Y_ARR, type) >= 0) { _compMover.target.TweenMoveY(HEAD_Y + dy, duration).SetEase(ease); _compMover.target.TweenScale(new Vector2(HEAD_SCALE * rate, HEAD_SCALE * rate), duration).SetEase(ease); } else if (Array.IndexOf(FA_XING_Y_ARR, type) >= 0) { _compMover.target.TweenMoveY(FA_XING_Y + dy, duration).SetEase(ease); _compMover.target.TweenScale(new Vector2(FA_XING_SCALE * rate, FA_XING_SCALE * rate), duration).SetEase(ease); } else if (Array.IndexOf(UPPER_BODY_Y_ARR, type) >= 0) { _ui.m_compHolder.m_compHolder.m_compMover.target.TweenMoveY(UPPER_BODY_Y + dy, duration).SetEase(ease); _compMover.target.TweenScale(new Vector2(UPPER_BODY_SCALE * rate, UPPER_BODY_SCALE * rate), duration).SetEase(ease); } else if (Array.IndexOf(LOWER_BODY_Y_ARR, type) >= 0) { _ui.m_loaBg2.visible = true; _compMover.target.TweenMoveY(LOWER_BODY_Y + dy, duration).SetEase(ease); _compMover.target.TweenScale(new Vector2(LOWER_BODY_SCALE * rate, LOWER_BODY_SCALE * rate), duration).SetEase(ease); } else if (Array.IndexOf(SHOES_Y_ARR, type) >= 0) { _ui.m_loaBg2.visible = true; _compMover.target.TweenMoveY(SHOES_Y + dy, duration).SetEase(ease); _compMover.target.TweenScale(new Vector2(SHOES_SCALE * rate, SHOES_SCALE * rate), duration).SetEase(ease); } else { _compMover.target.TweenMoveY(BODY_Y + dy, duration).SetEase(ease); _compMover.target.TweenScale(new Vector2(BODY_SCALE * rate, BODY_SCALE * rate), duration).SetEase(ease); } if (!tween) { Timers.inst.StartCoroutine(DelayShow()); } } /// /// 延迟一帧 防止闪一下 /// /// private IEnumerator DelayShow() { yield return new WaitForEndOfFrame(); _ui.m_show.Play(); } private void UpdateClothingList(bool tween) { //套装名称 SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_suitId); _ui.m_txtSuitName.text = suitCfg.name; //进度条 UpdateSuitProgress(); //服装列表 _items = SuitCfgArray.Instance.GetSuitItems(_suitId).Clone() as int[]; ItemUtil.SortItemIdsByOwned(_items); _ui.m_listClothing.RemoveChildrenToPool(); _ui.m_listClothing.numItems = _items.Length; if (_ui.m_listClothing.numItems > 0) { UI_ClothingListItem listItem = null; int index = 0; if (_selectedItemId > 0) { int num = _ui.m_listClothing.numChildren; for (int i = 0; i < num; i++) { listItem = UI_ClothingListItem.Proxy(_ui.m_listClothing.GetChildAt(i)); int temp = (int)listItem.target.data; if (temp == _selectedItemId) { index = i; } UI_ClothingListItem.ProxyEnd(); } } _ui.m_listClothing.ScrollToView(index); _ui.m_listClothing.selectedIndex = index; UpdateSelectedItemInfo(_ui.m_listClothing.GetChildAt(index) as GComponent, tween); } } private void UpdateSelectedItemInfo(GComponent listItem, bool tween) { _selectedListItem = listItem; listItem.AddChildAt(_imgSelected, 1); _selectedItemId = (int)listItem.data; DressUpMenuSuitDataManager.chooseClothing = _selectedItemId; UpdateRole(tween); UpdateSelectedItemInfo(); UpdateCardSyntheticBtn(); } private void UpdateSelectedItemInfo() { ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_selectedItemId); //属性展示 _ui.m_compItemInfo.m_txtName.text = itemCfg.name; RarityIconController.UpdateRarityIcon(_ui.m_compItemInfo.m_rarity, _selectedItemId, false); _ui.m_compItemInfo.m_txtGong.text = "" + itemCfg.score1; _ui.m_compItemInfo.m_txtShang.text = "" + itemCfg.score2; _ui.m_compItemInfo.m_txtJue.text = "" + itemCfg.score3; _ui.m_compItemInfo.m_txtZhi.text = "" + itemCfg.score4; UI_ClothingListItem selectedItem = UI_ClothingListItem.Proxy(_selectedListItem); selectedItem.m_imgOwned.visible = ItemDataManager.GetItemNum(_selectedItemId) > 0; UI_ClothingListItem.ProxyEnd(); //合成显示 ItemCfg clothingSyntheticCfg = ItemCfgArray.Instance.GetCfg(_selectedItemId); // 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(_selectedItemId) > 0; } 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; } if (ItemDataManager.GetItemNum(_selectedItemId) > 0) { PromptController.Instance.ShowFloatTextPrompt("该部件已制作完成"); 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(ClothingSyntheticView).FullName, new object[] { _suitId, _selectedItemId } }, (int)itemData.num }; GoodsItemTipsController.ShowItemTips(itemData.id, sourceDatas); } private void OnItemNumChanged() { UpdateSuitProgress(); //列表选中项更新 UI_ClothingListItem selectedItem = UI_ClothingListItem.Proxy(_selectedListItem); selectedItem.m_imgOwned.visible = ItemDataManager.GetItemNum(_selectedItemId) > 0; UI_ClothingListItem.ProxyEnd(); _ui.m_listClothing.numItems = _ui.m_listClothing.numItems; UpdateSelectedItemInfo(); } private void UpdateSuitProgress() { //进度条 int count = 0; int totalCount = 0; DressUpMenuSuitDataManager.GetSuitProgressBySuitId(_suitId, out count, out totalCount); _ui.m_txtProgress.text = string.Format("{0}/{1}", count, totalCount); } private void OnClickBtnHome() { GameController.GoBackToMainView(); } private void CheckGuide(object param) { if (GuideDataManager.IsGuideFinish(ConstGuideId.CLOTHING_SYNTHETIC) <= 0 || (GuideDataManager.IsGuideFinish(ConstGuideId.CARD_HECHENG) <= 0 && IsGetSuit())) { 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, "获得新衣服啦,继续通关主线剧情吧。"); GuideController.TryGuide(_ui.m_cardSyntheticBtn, ConstGuideId.CARD_HECHENG, 1, "领取卡牌。"); GuideController.TryGuide(null, ConstGuideId.CARD_HECHENG, 2, "获得套装卡牌后可进行技能书合成!", -1, true, _ui.target.height - 600); GuideController.TryGuide(_ui.m_cardSyntheticBtn, ConstGuideId.CARD_HECHENG, 3, "进入卡牌合成"); } protected override void TryCompleteGuide() { base.TryCompleteGuide(); GuideController.TryCompleteGuideIndex(ConstGuideId.CARD_HECHENG, 3); GuideController.TryCompleteGuide(ConstGuideId.CARD_HECHENG, 3); } /// /// 按照屏幕尺寸 更新遮罩的高度 /// /// private async Task UpdateMaskHeight() { await Task.Delay(5); _ui.m_compHolder.m_mask.height = _ui.m_posHelper.height; SetSoftMask(); } /// /// 创建二层渐变背景遮罩 /// private void SetSoftMask() { var handle = YooAssets.LoadAssetSync(ResPathUtil.GetMaterialPath("ImageGradient")); Material m = handle.AssetObject as Material; Material copyM = new Material(m.shader); handle.Release(); copyM.CopyPropertiesFromMaterial(m); _ui.m_loaBg2.material = copyM; _ui.m_loaBg2.position = _ui.m_loaBg.position; float startY = _ui.m_loaBg2Pos.position.y; float endY = _ui.m_posHelper.position.y + ViewGlobal.GetRealTopOffset(); float rate = 1 - ((Mathf.Abs(startY - endY)) / _ui.m_loaBg2.height); _ui.m_loaBg2.material.SetFloat("_MinHeight", rate - 0.01f); _ui.m_loaBg2.material.SetFloat("_MaxHeight", rate - 0.03f); } private void RemoveSoftMask() { _ui.m_loaBg2.material = null; } private void UpdateCardSyntheticBtn() { int count = ItemCfgArray.Instance.GetCfgsBysuitId(_suitId).Count - 1; ItemCfg item = ItemCfgArray.Instance.GetCfgsBysuitId(_suitId)[count]; _cardID = item.id; int rewardStatus = DressUpMenuSuitDataManager.GetSuitSyntheticRewardStatus(_suitId); if(item.syntheticTimes > 0) { _ui.m_cardSyntheticBtn.visible = true; if(rewardStatus == 1) { _ui.m_cardSyntheticBtn.icon = ResPathUtil.GetIconPath(ItemCfgArray.Instance.GetCfg(_cardID).res,"png"); RedDotController.Instance.SetComRedDot(_ui.m_cardSyntheticBtn, true, "", -18, 20); } else { _ui.m_cardSyntheticBtn.icon = "ui://ClothingSynthetic/kphc_huimeng"; RedDotController.Instance.SetComRedDot(_ui.m_cardSyntheticBtn, (rewardStatus == 1), "", -18, 20); } } else { _ui.m_cardSyntheticBtn.visible = false; } } private async void OnClickBtnCardSyntheticView() { int rewardStatus = DressUpMenuSuitDataManager.GetSuitSyntheticRewardStatus(_suitId); if (DressUpMenuSuitDataManager.CheckHaveSuit(_suitId)) { if(rewardStatus == 1) { bool result = await ClothingSyntheticSProxy.GetSuitGetReward(_suitId); UpdateCardSyntheticBtn(); } else { ViewManager.Show(new object[] { _cardID, _selectedItemId }); } } else { PromptController.Instance.ShowFloatTextPrompt("集齐套装后可领取卡牌奖励"); } } private bool IsGetSuit() { int count = 0;//套装当前拥有的部件数量 int totalCount = 1; DressUpMenuSuitDataManager.GetSuitProgressBySuitId(_suitId, out count, out totalCount); if (count >= totalCount) { return true; } return false; } } }