| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416 | using System.Collections;using UnityEngine;using UI.ClothingSynthetic;using UI.CommonGame;using FairyGUI;using System.Collections.Generic;using System;namespace GFGGame{    public class ClothingSyntheticView : BaseWindow    {        private const int HEAD_Y = 842;        private const int FA_XING_Y = 609;        private const int UPPER_BODY_Y = 459;        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 GameObject _scenePrefab;        private GameObject _sceneObject;        private GoWrapper _wrapper;        private DressUpObjDataCache _dressUpObjDataCache;        private ValueBarController _valueBarController;        private GComponent _imgSelected;        private int _suitId;        private int _itemId;        private int[] _items;        private int _selectedItemId;        private GComponent _selectedListItem;        private List<ItemData> _materiarsOfSelectedItem;        private UI_MateriasListItem listTypeItem_CloSynthetic;        public override void Dispose()        {            if (_valueBarController != null)            {                _valueBarController.Dispose();                _valueBarController = null;            }            if (_scenePrefab != null)            {                GameObject.Destroy(_scenePrefab);                _scenePrefab = null;            }            if (_imgSelected != null)            {                _imgSelected.RemoveFromParent();                _imgSelected.Dispose();            }            if (_dressUpObjDataCache != null)            {                _dressUpObjDataCache.Dispose();                _dressUpObjDataCache = null;            }            base.Dispose();        }        protected override void OnInit()        {            base.OnInit();            packageName = UI_ClothingSyntheticListUI.PACKAGE_NAME;            _ui = UI_ClothingSyntheticUI.Create();            this.viewCom = _ui.target;            isfullScreen = true;            this.clickBlankToClose = false;            _valueBarController = new ValueBarController(_ui.m_valueBar);            _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneDressUpSynthetic"));            _dressUpObjDataCache = new DressUpObjDataCache();            _imgSelected = new GComponent();            _imgSelected = UIPackage.CreateObject(UI_ClothingSyntheticUI.PACKAGE_NAME, "ComSelect").asCom;            _ui.m_listClothing.itemRenderer = ListClothingItemRender;            _ui.m_listClothing.onClickItem.Add(OnClickListClothingItem);            _ui.m_btnBack.onClick.Add(OnClickBtnBack);            _ui.m_btnProduction.onClick.Add(OnClickBtnProcuction);            _ui.m_btnHome.onClick.Add(OnClickBtnHome);        }        protected override void OnShown()        {            base.OnShown();            _suitId = (int)(this.viewData as object[])[0];            _selectedItemId = (this.viewData as object[]).Length > 1 ? (int)(this.viewData as object[])[1] : 0;            _valueBarController.OnShown();            UpdateClothingList(false);            EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, OnItemNumChanged);        }        protected override void OnHide()        {            base.OnHide();            _valueBarController.OnHide();            if (_sceneObject != null)            {                GameObject.Destroy(_sceneObject);                _sceneObject = null;            }            if (_wrapper != null)            {                _wrapper.wrapTarget = null;            }            EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, OnItemNumChanged);        }        private void OnClickBtnBack()        {            ViewManager.GoBackFrom(ViewName.CLOTHING_SYNTHETIC_VIEW);        }        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 (ItemDataManager.GetItemNum(itemCfg.syntheticCostID) < itemCfg.syntheticCostNum)            {                PromptController.Instance.ShowFloatTextPrompt("消耗不足!", MessageType.WARNING);                return;            }            //合成材料判断            _materiarsOfSelectedItem = ItemUtil.CreateItemDataList(itemCfg.syntheticMateriarsArr);            int count = _materiarsOfSelectedItem.Count;            for (int i = 0; i < count; i++)            {                ItemData itemData = _materiarsOfSelectedItem[i];                int num = ItemDataManager.GetItemNum(itemData.id);                ItemCfg materialCfg = ItemCfgArray.Instance.GetCfg(itemData.id);                bool isDressUp = materialCfg.itemType == ConstItemType.DRESS_UP;                int numSynthetic = isDressUp ? Mathf.Max(num - 1, 0) : Mathf.Max(num, 0);                if (numSynthetic < itemData.num)                {                    PromptController.Instance.ShowFloatTextPrompt("材料不足!", MessageType.WARNING);                    return;                }            }            bool result = await ClothingSyntheticSProxy.ClothtingSynthetic(_selectedItemId);            if (result)            {                _selectedItemId = 0;                UpdateClothingList(true);            }        }        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;        }        private void UpdateRole(bool tween)        {            if (_sceneObject != null)            {                GameObject.Destroy(_sceneObject);                _sceneObject = null;            }            _sceneObject = GameObject.Instantiate(_scenePrefab);            int scale = 45;            _sceneObject.transform.localScale = new Vector3(scale, scale, scale);            _dressUpObjDataCache.setSceneObj(_sceneObject, true);            _dressUpObjDataCache.PutOnDefaultSuitSaved(false);            _dressUpObjDataCache.AddOrRemove(_selectedItemId, true);            if (_wrapper == null)            {                _wrapper = new GoWrapper(_sceneObject);                _ui.m_compHolder.m_compMover.m_holder.SetNativeObject(_wrapper);            }            else            {                _wrapper.wrapTarget = _sceneObject;            }            int type = ItemUtilCS.GetItemSubType(_selectedItemId);            float duration = DURATION;            if (!tween)            {                duration = 0;            }            if (Array.IndexOf(HEAD_Y_ARR, type) >= 0)            {                _ui.m_compHolder.m_compMover.target.TweenMoveY(HEAD_Y, duration);                _ui.m_compHolder.m_compMover.target.TweenScale(new Vector2(HEAD_SCALE, HEAD_SCALE), duration);            }            else if (Array.IndexOf(FA_XING_Y_ARR, type) >= 0)            {                _ui.m_compHolder.m_compMover.target.TweenMoveY(FA_XING_Y, duration);                _ui.m_compHolder.m_compMover.target.TweenScale(new Vector2(FA_XING_SCALE, FA_XING_SCALE), duration);            }            else if (Array.IndexOf(UPPER_BODY_Y_ARR, type) >= 0)            {                _ui.m_compHolder.m_compMover.target.TweenMoveY(UPPER_BODY_Y, duration);                _ui.m_compHolder.m_compMover.target.TweenScale(new Vector2(UPPER_BODY_SCALE, UPPER_BODY_SCALE), duration);            }            else if (Array.IndexOf(LOWER_BODY_Y_ARR, type) >= 0)            {                _ui.m_compHolder.m_compMover.target.TweenMoveY(LOWER_BODY_Y, duration);                _ui.m_compHolder.m_compMover.target.TweenScale(new Vector2(LOWER_BODY_SCALE, LOWER_BODY_SCALE), duration);            }            else if (Array.IndexOf(SHOES_Y_ARR, type) >= 0)            {                _ui.m_compHolder.m_compMover.target.TweenMoveY(SHOES_Y, duration);                _ui.m_compHolder.m_compMover.target.TweenScale(new Vector2(SHOES_SCALE, SHOES_SCALE), duration);            }            else            {                _ui.m_compHolder.m_compMover.target.TweenMoveY(BODY_Y, duration);                _ui.m_compHolder.m_compMover.target.TweenScale(new Vector2(BODY_SCALE, BODY_SCALE), duration);            }        }        private void UpdateClothingList(bool tween)        {            //套装名称            SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_suitId);            _ui.m_txtSuitName.text = suitCfg.name;            //进度条            UpdateSuitProgress();            //服装列表            _items = SuitCfgManager.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.m_listClothing.ScrollToView(index);                UpdateSelectedItemInfo(_ui.m_listClothing.GetChildAt(index) as GComponent, tween);            }        }        private void UpdateSelectedItemInfo(GComponent listItem, bool tween)        {            _selectedListItem = listItem;            listItem.AddChild(_imgSelected);            _selectedItemId = (int)listItem.data;            UpdateRole(tween);            UpdateSelectedItemInfo();        }        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;            //合成显示            ItemCfg clothingSyntheticCfg = ItemCfgArray.Instance.GetCfg(_selectedItemId);            string costName = ItemUtil.GetItemName(clothingSyntheticCfg.syntheticCostID);            _ui.m_txtCost.SetVar("v1", "" + clothingSyntheticCfg.syntheticCostNum).SetVar("v2", costName).FlushVars();            _materiarsOfSelectedItem = ItemUtil.CreateItemDataList(clothingSyntheticCfg.syntheticMateriarsArr);            int count = _ui.m_listMaterias.numChildren;            for (int i = 0; i < count; i++)            {                UI_MateriasListItem listItem = UI_MateriasListItem.Proxy(_ui.m_listMaterias.GetChildAt(i));                if (i < _materiarsOfSelectedItem.Count)                {                    ItemData itemData = _materiarsOfSelectedItem[i];                    ItemCfg materiasItemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);                    listItem.m_txtName.text = ItemUtil.GetItemName(itemData.id);                    listItem.m_loaderIcon.url = ResPathUtil.GetIconPath(materiasItemCfg);                    int num = ItemDataManager.GetItemNum(itemData.id);                    ItemCfg materialCfg = ItemCfgArray.Instance.GetCfg(itemData.id);                    bool isDressUp = materialCfg.itemType == ConstItemType.DRESS_UP;                    int numSynthetic = isDressUp ? Mathf.Max(num - 1, 0) : Mathf.Max(num, 0);                    listItem.m_groupCount.m_txtProgess.text = numSynthetic + "/" + itemData.num;                    listItem.m_loaderIcon.visible = true;                    listItem.m_groupCount.target.visible = true;                    listItem.m_groupCount.target.onClick.Clear();                    listItem.m_groupCount.target.onClick.Add(OnClickMateriasItemPlus);                    listItem.target.data = itemData;                }                else                {                    listItem.m_txtName.text = "";                    listItem.m_loaderIcon.visible = false;                    listItem.m_groupCount.target.visible = false;                }            }            _ui.m_btnProduction.grayed = ItemDataManager.GetItemNum(_selectedItemId) > 0;        }        private void OnClickMateriasItemPlus(EventContext context)        {            UI_Component3 groupCount = UI_Component3.Proxy(context.sender as GObject);            UI_MateriasListItem listItem = UI_MateriasListItem.Proxy(groupCount.target.parent);            ItemData itemData = listItem.target.data as ItemData;            int num = ItemDataManager.GetItemNum(itemData.id);            int needCount = (itemData.num + 1 - num) > 0 ? itemData.num + 1 - num : 1;            ViewManager.Show(ViewName.APPROACH_OF_ITEM_VIEW, new object[] { itemData.id, new object[] { ViewName.CLOTHING_SYNTHETIC_VIEW, new object[] { _suitId, _selectedItemId } }, needCount });        }        private void OnItemNumChanged()        {            UpdateSuitProgress();            //列表选中项更新            UI_ClothingListItem selectedItem = UI_ClothingListItem.Proxy(_selectedListItem);            selectedItem.m_imgOwned.visible = ItemDataManager.GetItemNum(_selectedItemId) > 0;            UpdateSelectedItemInfo();        }        private void UpdateSuitProgress()        {            //进度条            int count = 0;            int totalCount = 0;            DressUpMenuSuitDataManager.GetSuitProgressBySuitId(_suitId, out count, out totalCount);            _ui.m_txtProgress.SetVar("v1", "" + count);            _ui.m_txtProgress.SetVar("v2", "" + totalCount);            _ui.m_txtProgress.FlushVars();        }        private void OnClickBtnHome()        {            GameController.GoBackToMainView();        }        protected override void UpdateToCheckGuide(object param)        {            if (ViewManager.isViewOpen(typeof(GuideView).Name))            {                ViewManager.GetUIView(typeof(GuideView).Name).viewCom.visible = !ViewManager.isViewOpen(typeof(GetSuitItemVIew).Name);            }            if (!ViewManager.CheckIsTopView(this.viewCom)) return;            int itemId = 10114;            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;                if (temp == itemId)                {                    itemIndex = i;                    break;                }            }            bool guide = GuideController.TryGuide(_ui.m_listClothing, ConstGuideId.CLOTHING_SYNTHETIC, 4, "找到需要合成的物品", itemIndex);            if (guide) _ui.m_listClothing.ScrollToView(itemIndex);            if (_ui.m_listMaterias.numChildren > 0)            {                listTypeItem_CloSynthetic = UI_MateriasListItem.Proxy(_ui.m_listMaterias.GetChildAt(0));            }            if (listTypeItem_CloSynthetic != null) GuideController.TryGuide(listTypeItem_CloSynthetic.m_loaderIcon, ConstGuideId.CLOTHING_SYNTHETIC, 5, "这里可以查看合成需要的材料,和材料的获取途径");            GuideController.TryGuide(_ui.m_btnProduction, ConstGuideId.CLOTHING_SYNTHETIC, 6, "点击获得新的服饰");            GuideController.TryGuide(_ui.m_btnHome, ConstGuideId.CLOTHING_SYNTHETIC, 7, "获得必需品啦,继续通关主线剧情吧", -1, true, 180);        }    }}
 |