| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 | using System;using System.Collections.Generic;using System.Linq;using FairyGUI;using UI.ClothingDecompose;namespace GFGGame{    public class ClothingDecomposeView : BaseWindow    {        private UI_ClothingDecomposeUI _ui;        private ValueBarController _valueBarController;        private List<int> _clothingDatas = new List<int>();        private Dictionary<int, int> _decomposeData = new Dictionary<int, int>();        private int _decomposeCount = 0;//要分解物品的数量        private int _curRarity = 0;        public override void Dispose()        {            _valueBarController.Dispose();            _valueBarController = null;            base.Dispose();        }        protected override void OnInit()        {            base.OnInit();            packageName = UI_ClothingDecomposeUI.PACKAGE_NAME;            _ui = UI_ClothingDecomposeUI.Create();            this.viewCom = _ui.target;            isfullScreen = true;            this.clickBlankToClose = false;            _valueBarController = new ValueBarController(_ui.m_valueBar);            _ui.m_btnBack.onClick.Add(OnClickBtnBack);            _ui.m_listTab.onClickItem.Add((EventContext context) =>            {                int index = _ui.m_listTab.GetChildIndex(context.data as GObject);                OnClickBtnRarity(index + 1);            });            _ui.m_btnSelect.onClick.Add(OnClickBtnSelect);            _ui.m_btnRule.onClick.Add(OnClickBtnRule);            _ui.m_btnDecompose.onClick.Add(OnClickBtnDecompose);            _ui.m_list.itemRenderer = ListItemRander;            _ui.m_list.SetVirtual();            _ui.m_listReward.itemRenderer = ListRewardItemRander;            _ui.m_listReward.onClickItem.Add(OnClickListRewardItem);        }        protected override void OnShown()        {            base.OnShown();            _ui.m_c1.selectedIndex = 0;            _ui.m_listTab.selectedIndex = 0;            _valueBarController.OnShown();            _valueBarController.Controller(6);            OnClickBtnRarity(ConstDressRarity.Rarity_FANPIN);            if (GuideDataManager.currentGuideId == GuideCfgArray.Instance.GetCfg(ConstGuideId.CLOTHING_DECOMPOSE).id)            {                _ui.m_listTab.selectedIndex = 1;                OnClickBtnRarity(ConstDressRarity.Rarity_ZHENXI);            }        }        protected override void OnHide()        {            base.OnHide();            _valueBarController.OnHide();        }        private void OnClickBtnRarity(int rarity)        {            _curRarity = rarity;            _clothingDatas = DecomposeDataManager.Instance.GetDecomposeDataByRarity(rarity);            _ui.m_list.visible = _clothingDatas != null && _clothingDatas.Count > 0;            _ui.m_txtNone.visible = _clothingDatas == null || _clothingDatas.Count == 0;            if (_clothingDatas == null) return;            _ui.m_list.numItems = _clothingDatas.Count;            _ui.m_btnSelect.selected = false;            CancleAll();            UpdateConsume();        }        private void ListItemRander(int index, GObject obj)        {            UI_ListItem item = UI_ListItem.Proxy(obj);            ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_clothingDatas[index]);            RarityIconController.UpdateRarityIcon(item.m_loaRarity, itemCfg.id, false);            string ext = ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType);            item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg.res, ext);            item.m_txtName.text = itemCfg.name;            item.m_imgSelect.visible = false;            int itemHasCount = DecomposeDataManager.Instance.ItemCanDecomposeCount(itemCfg.id);            item.m_txtHasCount.text = itemHasCount.ToString();            int itemCount = _decomposeData.ContainsKey(_clothingDatas[index]) ? _decomposeData[_clothingDatas[index]] : 0;            item.m_txtCount.text = itemCount.ToString();            item.m_imgSelect.visible = itemCount > 0;            item.m_btnMinus.visible = itemCount > 0;            if (item.m_btnMinus.data == null)            {                item.m_btnMinus.onClick.Add(OnClickBtnMinus);            }            item.m_btnMinus.data = index;            if (item.m_loaItem.data == null)            {                item.m_loaItem.onClick.Add(OnListItemClick);            }            item.m_loaItem.data = index;            item.target.data = itemCfg;        }        private void OnListItemClick(EventContext context)        {            int index = (int)((context.sender as GLoader).data);            int childIndex = _ui.m_list.ItemIndexToChildIndex(index);            GComponent com = _ui.m_list.GetChildAt(childIndex).asCom;            int itemId = (com.data as ItemCfg).id;            if (!_decomposeData.ContainsKey(itemId)) _decomposeData[itemId] = 0;            if (_decomposeData[itemId] == DecomposeDataManager.Instance.ItemCanDecomposeCount(itemId)) return;            if (_decomposeCount == DecomposeDataManager.MaxCount)            {                PromptController.Instance.ShowFloatTextPrompt("已达到单次可分解上限,请分批操作");                return;            }            UI_ListItem item = UI_ListItem.Proxy(com);            item.m_btnMinus.visible = true;            item.m_imgSelect.visible = true;            _decomposeData[itemId] = _decomposeData[itemId] + 1;            _decomposeCount += 1;            item.m_txtCount.text = _decomposeData[itemId].ToString();            UpdateConsume();        }        private void OnClickBtnMinus(EventContext context)        {            int index = (int)((context.sender as GButton).data);            int childIndex = _ui.m_list.ItemIndexToChildIndex(index);            GComponent com = _ui.m_list.GetChildAt(childIndex).asCom;            UI_ListItem item = UI_ListItem.Proxy(com);            int itemId = (com.data as ItemCfg).id;            _decomposeData[itemId] = _decomposeData[itemId] - 1;            _decomposeCount -= 1;            item.m_txtCount.text = _decomposeData[itemId].ToString();            if (_decomposeData[itemId] == 0)            {                _decomposeData.Remove(itemId);                item.m_imgSelect.visible = false;                item.m_btnMinus.visible = false;            }            UpdateConsume();        }        private void OnClickBtnSelect()        {            if (_ui.m_btnSelect.selected)            {                SelectAll();            }            else            {                CancleAll();            }            UpdateConsume();        }        private void SelectAll()        {            int lastCount = DecomposeDataManager.MaxCount - _decomposeCount;            for (int i = 0; i < _clothingDatas.Count; i++)            {                int itemId = _clothingDatas[i];                int itemHasCount = DecomposeDataManager.Instance.ItemCanDecomposeCount(itemId);                int itemLastCount = _decomposeData.ContainsKey(itemId) ? itemHasCount - _decomposeData[itemId] : itemHasCount;                int count = Math.Min(lastCount, itemLastCount);                lastCount -= count;                if (!_decomposeData.ContainsKey(itemId)) _decomposeData[itemId] = 0;                _decomposeData[itemId] = _decomposeData[itemId] + count;                _decomposeCount += count;                if (lastCount == 0) break;            }            _ui.m_list.numItems = _clothingDatas.Count;        }        private void CancleAll()        {            _decomposeData.Clear();            _ui.m_list.numItems = _clothingDatas.Count;            _decomposeCount = 0;        }        private void UpdateConsume()        {            DecomposeCfg cfg = DecomposeCfgArray.Instance.GetCfg(_curRarity);            ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(cfg.consumeId);            _ui.m_listReward.numItems = _decomposeCount > 0 ? cfg.itemsArr.Length : 0;            _ui.m_txtShow.text = string.Format("*  分解{0}件{1}可获得  *", StringUtil.GetColorText(_decomposeCount.ToString(), "#DA826E"), ConstDressRarity.DressRarityList()[_curRarity]);            _ui.m_txtConsume.text = string.Format("消耗{0}X{1}", itemCfg.name, (_decomposeCount * cfg.consumeCount));        }        private void ListRewardItemRander(int index, GObject obj)        {            UI_ListRewardItem item = UI_ListRewardItem.Proxy(obj);            DecomposeCfg decomposeCfg = DecomposeCfgArray.Instance.GetCfg(_curRarity);            ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(decomposeCfg.itemsArr[index][0]);            item.m_txtCount.text = (decomposeCfg.itemsArr[index][1] * _decomposeCount).ToString();            string ext = ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType);            item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg.res, ext);            item.target.data = itemCfg;        }        private void OnClickListRewardItem(EventContext context)        {            UI_ListRewardItem item = UI_ListRewardItem.Proxy((context.data as GObject));            GoodsItemTipsController.ShowItemTips((item.target.data as ItemCfg).id);        }        private void OnClickBtnDecompose()        {            if (_curRarity > ConstDressRarity.Rarity_ZHENXI)            {                Alert.Show(string.Format("当前选择的稀有度为{0},是否确定分解?", ConstDressRarity.DressRarityList()[_curRarity])).SetLeftButton(true).SetRightButton(true, "确定", (object data) => { DecomposeItem(); });            }            else            {                DecomposeItem();            }        }        private async void DecomposeItem()        {            DecomposeCfg cfg = DecomposeCfgArray.Instance.GetCfg(_curRarity);            ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(cfg.consumeId);            int consumeCount = cfg.consumeCount * _decomposeCount;            if (consumeCount > ItemDataManager.GetItemNum(cfg.consumeId))            {                PromptController.Instance.ShowFloatTextPrompt(string.Format("{0}不足", itemCfg.name));                return;            }            List<int> itemIds = _decomposeData.Keys.ToList<int>();            List<int> itemNums = _decomposeData.Values.ToList<int>();            bool result = await ClothingDecomposeSProxy.ClothingDecompose(itemIds, itemNums);            if (result)            {                OnClickBtnRarity(_curRarity);            }        }        private void OnClickBtnRule()        {            ViewManager.Show<ClothingDecomposeRuleView>();        }        private void OnClickBtnBack()        {            ViewManager.GoBackFrom(typeof(ClothingDecomposeView).FullName);        }        protected override void UpdateToCheckGuide(object param)        {            if (!ViewManager.CheckIsTopView(this.viewCom)) return;            GuideController.TryGuide(_ui.m_list, ConstGuideId.CLOTHING_DECOMPOSE, 4, "选择重复获得的服饰部件", 0);            GuideController.TryGuide(_ui.m_btnDecompose, ConstGuideId.CLOTHING_DECOMPOSE, 5, "分解获得的材料可用于新服饰合成");            GuideController.TryCompleteGuide(ConstGuideId.CLOTHING_DECOMPOSE, 5);            GuideController.TryGuide(_ui.m_btnBack, ConstGuideId.CLOTHING_SYNTHETIC, 1, "回到绣坊界面");        }    }}
 |