| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451 | using System;using System.Collections.Generic;using System.Linq;using ET;using FairyGUI;using UI.ClothingDecompose;using UI.CommonGame;namespace GFGGame{    public class ClothingDecomposeView : BaseWindow    {        private UI_ClothingDecomposeUI _ui;        private ValueBarController _valueBarController;        private List<int> _clothingDatas = new List<int>();        private Dictionary<int, long> _decomposeData = new Dictionary<int, long>();        private long _decomposeCount = 0;//要分解物品的数量        private long _decoNormalCount = 0;//要分解普通物品的数量        private int _curRarity = 0;        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_ClothingDecomposeUI.PACKAGE_NAME;            _ui = UI_ClothingDecomposeUI.Create();            this.viewCom = _ui.target;            isfullScreen = true;            isReturnView = true;            this.clickBlankToClose = false;            _valueBarController = new ValueBarController(_ui.m_valueBar);            _ui.m_btnBack.onClick.Add(OnClickBtnBack);            _ui.m_bg.url = ResPathUtil.GetBgImgPath("quanping_moren_bg");            _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(RuleController.ShowRuleView);            _ui.m_btnRule.data = 300019;            _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);            _ui.m_c1.onChanged.Add(OnClickDecomposeType);            // DecomposeDataManager.Instance.InitSuitSyntheticMaterias();        }        private void OnClickDecomposeType()        {            _ui.m_listTab.selectedIndex = _curRarity - 1;            OnClickBtnRarity(_curRarity);            if (_ui.m_c1.selectedIndex == 0)                _ui.m_btnRule.data = 300019;            else                _ui.m_btnRule.data = 300020;        }        protected override void OnShown()        {            base.OnShown();            DecomposeDataManager.Instance.TidyDecomposeData();            _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 = 0;            //    OnClickBtnRarity(ConstDressRarity.Rarity_FANPIN);            //}            //Timers.inst.AddUpdate(CheckGuide);        }        protected override void OnHide()        {            base.OnHide();            _valueBarController.OnHide();            //Timers.inst.Remove(CheckGuide);        }        private void OnClickBtnRarity(int rarity)        {            _curRarity = rarity;            if (_ui.m_c1.selectedIndex == 0)                _clothingDatas = DecomposeDataManager.Instance.GetDecomposeDataByRarity(rarity);            else if (_ui.m_c1.selectedIndex == 1)                _clothingDatas = DecomposeDataManager.Instance.GetDecomposeMaterialByRarity(rarity);            _ui.m_list.visible = _clothingDatas != null && _clothingDatas.Count > 0;            _ui.m_txtNone.visible = _clothingDatas == null || _clothingDatas.Count == 0;            _ui.m_listReward.visible = _clothingDatas != null && _clothingDatas.Count > 0;            _ui.m_TouchSelect.selectedIndex = 0;            CancleAll();            UpdateConsume();        }                      private void ListItemRander(int index, GObject obj)         {            UI_ComItem item = UI_ComItem.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, true);            item.m_CountType.selectedIndex = 1;            item.m_ButtonType.selectedIndex = 1;            item.m_ShowName.selectedIndex = 1;            item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg.res, ext);            item.m_txtName.text = itemCfg.name;            long itemHasCount = DecomposeDataManager.Instance.CanDecomposeCount(_ui.m_c1.selectedIndex,itemCfg.id);            long itemCount = _decomposeData.ContainsKey(_clothingDatas[index]) ? _decomposeData[_clothingDatas[index]] : 0;            item.m_txtDecomHasCount.text ="/" + itemHasCount;            item.m_QualityType.selectedIndex = itemCfg.rarity - 1;            item.m_txtDecomCount.text = itemCount.ToString();            if (itemCount > 0)                item.m_TouchType.selectedIndex = 1;            else                item.m_TouchType.selectedIndex = 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_loaBg.data == null)            {                item.m_loaBg.onClick.Add(OnListItemClick);            }            item.m_loaBg.data = index;            item.target.data = itemCfg;            UI_ComItem.ProxyEnd();        }        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.CanDecomposeCount(_ui.m_c1.selectedIndex, itemId)) return;            if ((_decomposeCount + _decoNormalCount) == DecomposeDataManager.MaxCount)            {                PromptController.Instance.ShowFloatTextPrompt("已达到单次可分解上限,请分批操作");                return;            }            // if (!DecomposeDataManager.Instance.CheckIsItemForSuitSynthetic(itemId))            // {            //     PromptController.Instance.ShowFloatTextPrompt("这是套装合成材料,先别分解了吧!");            //     return;            // }            UI_ComItem item = UI_ComItem.Proxy(com);            item.m_btnMinus.visible = true;            item.m_TouchType.selectedIndex = 1;            _decomposeData[itemId] = _decomposeData[itemId] + 1;            ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);            if(itemCfg.suitId > 0)                _decomposeCount += 1;            else                _decoNormalCount += 1;            item.m_txtDecomCount.text = _decomposeData[itemId].ToString();            UI_ComItem.ProxyEnd();            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_ComItem item = UI_ComItem.Proxy(com);            int itemId = (com.data as ItemCfg).id;            _decomposeData[itemId] = _decomposeData[itemId] - 1;            ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);            if (itemCfg.suitId > 0)                _decomposeCount -= 1;            else                _decoNormalCount -= 1;            item.m_txtDecomCount.text = _decomposeData[itemId].ToString();            if (_decomposeData[itemId] == 0)            {                _decomposeData.Remove(itemId);                item.m_TouchType.selectedIndex = 0;                item.m_btnMinus.visible = false;            }            UI_ComItem.ProxyEnd();            UpdateConsume();        }        private void OnClickBtnSelect()        {            if (_ui.m_btnSelect.selected)            {                SelectAll();            }            else            {                CancleAll();            }            UpdateConsume();        }        private void SelectAll()        {            if (_clothingDatas == null)                return;            long lastCount = DecomposeDataManager.MaxCount - _decomposeCount - _decoNormalCount;            for (int i = 0; i < _clothingDatas.Count; i++)            {                int itemId = _clothingDatas[i];                // if (!DecomposeDataManager.Instance.CheckIsItemForSuitSynthetic(itemId))                // {                //     continue;                // }                long itemHasCount = DecomposeDataManager.Instance.CanDecomposeCount(_ui.m_c1.selectedIndex,itemId);                long itemLastCount = _decomposeData.ContainsKey(itemId) ? itemHasCount - _decomposeData[itemId] : itemHasCount;                long count = Math.Min(lastCount, itemLastCount);                lastCount -= count;                if (!_decomposeData.ContainsKey(itemId)) _decomposeData[itemId] = 0;                _decomposeData[itemId] = _decomposeData[itemId] + count;                ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);                if (itemCfg.suitId > 0)                    _decomposeCount += count;                else                    _decoNormalCount += count;                if (lastCount == 0) break;            }            _ui.m_list.numItems = _clothingDatas.Count;        }        private void CancleAll()        {            _decomposeCount = 0;            _decoNormalCount = 0;            _decomposeData.Clear();            if (_clothingDatas != null)                _ui.m_list.numItems = _clothingDatas.Count;        }        private void UpdateConsume()        {            int consumeId;            int arrLength = 0;            int consumeCount;            DecomposeCfg cfg = DecomposeCfgArray.Instance.GetCfg(_curRarity);            if (_ui.m_c1.selectedIndex == 0)            {                DecomposeCfg decomposeCfg = DecomposeCfgArray.Instance.GetCfg(_curRarity);                consumeId = decomposeCfg.consumeId;                if(_decomposeCount > 0)                    arrLength = decomposeCfg.itemsArr.Length;                else if(_decoNormalCount > 0)                    arrLength = decomposeCfg.items2Arr.Length;                consumeCount = decomposeCfg.consumeCount;            }            else            {                DecomposeSkillCfg decomposeSkillCfg = DecomposeSkillCfgArray.Instance.GetCfg(_curRarity);                consumeId = decomposeSkillCfg.consumeId;                arrLength = decomposeSkillCfg.itemsArr.Length;                consumeCount = decomposeSkillCfg.consumeCount;            }            ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(consumeId);            _ui.m_listReward.numItems = (_decomposeCount + _decoNormalCount) > 0 ? arrLength : 0;            _ui.m_txtShow.text = string.Format("*  分解{0}件{1}可获得  *", StringUtil.GetColorText((_decomposeCount + _decoNormalCount).ToString(), "#DA826E"), ConstDressRarity.DressRarityList()[_curRarity]);            ET.Log.Debug("分解消耗:  " + consumeId + "   找不到物品配置");            if (itemCfg == null)            {                _ui.m_txtConsume.visible = false;                return;            }            _ui.m_txtConsume.visible = true;            _ui.m_txtConsume.text = string.Format("消耗{0}X{1}", itemCfg.name, (_decomposeCount * consumeCount));        }        private void ListRewardItemRander(int index, GObject obj)        {            UI_ListRewardItem item = UI_ListRewardItem.Proxy(obj);            int itemId = 0;            long itemNum = 0;            if (_ui.m_c1.selectedIndex == 0)            {                DecomposeCfg decomposeCfg = DecomposeCfgArray.Instance.GetCfg(_curRarity);                if (_decomposeCount > 0) {                    itemId = decomposeCfg.itemsArr[index][0];                }                itemNum = decomposeCfg.itemsArr[index][1] * _decomposeCount;                if (_decoNormalCount > 0) {                    if (itemId == 0) {                        itemId = decomposeCfg.items2Arr[index][0];                        itemNum = decomposeCfg.items2Arr[index][1] * _decoNormalCount;                    }                    else {                        for (int i = 0; i < decomposeCfg.items2Arr.Length; i++) {                            if (itemId == decomposeCfg.items2Arr[i][0])                            {                                itemNum = itemNum + decomposeCfg.items2Arr[i][1] * _decoNormalCount;                                break;                            }                        }                    }                }            }            else            {                DecomposeSkillCfg decomposeSkillCfg = DecomposeSkillCfgArray.Instance.GetCfg(_curRarity);                itemId = decomposeSkillCfg.itemsArr[index][0];                itemNum = decomposeSkillCfg.itemsArr[index][1] * _decomposeCount;            }            ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);            item.m_txtCount.text = itemNum.ToString();            string ext = ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType, true);            item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg.res, ext);            item.target.data = itemCfg;            UI_ListRewardItem.ProxyEnd();        }        private void OnClickListRewardItem(EventContext context)        {            UI_ListRewardItem item = UI_ListRewardItem.Proxy((context.data as GObject));            GoodsItemTipsController.ShowItemTips((item.target.data as ItemCfg).id);            UI_ListRewardItem.ProxyEnd();        }        private void OnClickBtnDecompose()        {            if (_curRarity > ConstDressRarity.Rarity_ZHENXI)            {                AlertUI.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);            if ((_decomposeCount + _decoNormalCount) <= 0)            {                String str = "";                if (_ui.m_c1.selectedIndex == 0)                    str = "未选择分解服装";                else                    str = "未选择分解技能书";                PromptController.Instance.ShowFloatTextPrompt(str);                return;            }            long consumeCount = 0;            if (itemCfg != null && itemCfg.suitId > 0)                consumeCount = cfg.consumeCount * _decomposeCount;            else                 consumeCount = cfg.consumeCount * _decoNormalCount;            if (consumeCount > ItemDataManager.GetItemNum(cfg.consumeId))            {                PromptController.Instance.ShowFloatTextPrompt(string.Format("{0}不足", itemCfg.name));                return;            }            List<int> itemIds = _decomposeData.Keys.ToList<int>();            List<long> itemNums = _decomposeData.Values.ToList<long>();            if (_ui.m_c1.selectedIndex == 0)            {                bool result = await ClothingDecomposeSProxy.ClothingDecompose(itemIds, itemNums);                if (result)                {                    OnClickBtnRarity(_curRarity);                    LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.FU_ZHUANG_FEN_JIE, 2);                }            }            else            {                bool result = await ClothingDecomposeSProxy.SkillBookDecompose(itemIds, itemNums);                if (result)                {                    OnClickBtnRarity(_curRarity);                    LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.SKILL_BOOK_FEN_JIE, 2);                }            }        }        private void OnClickBtnBack()        {            ViewManager.GoBackFrom(typeof(ClothingDecomposeView).FullName);        }        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.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, "回到绣坊界面。");        }    }}
 |