using System; using System.Collections.Generic; using System.Linq; using ET; using FairyGUI; using UI.ClothingDecompose; namespace GFGGame { public class ClothingDecomposeView : BaseWindow { private UI_ClothingDecomposeUI _ui; private ValueBarController _valueBarController; private List _clothingDatas = new List(); private Dictionary _decomposeData = new Dictionary(); private long _decomposeCount = 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; 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); } Timers.inst.AddUpdate(CheckGuide); } protected override void OnHide() { base.OnHide(); _valueBarController.OnHide(); Timers.inst.Remove(CheckGuide); } 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, true); item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg.res, ext); item.m_txtName.text = itemCfg.name; item.m_imgSelect.visible = false; long itemHasCount = DecomposeDataManager.Instance.ItemCanDecomposeCount(itemCfg.id); item.m_txtHasCount.text = itemHasCount.ToString(); long 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; UI_ListItem.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.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(); UI_ListItem.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_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; } UI_ListItem.ProxyEnd(); UpdateConsume(); } private void OnClickBtnSelect() { if (_ui.m_btnSelect.selected) { SelectAll(); } else { CancleAll(); } UpdateConsume(); } private void SelectAll() { long lastCount = DecomposeDataManager.MaxCount - _decomposeCount; for (int i = 0; i < _clothingDatas.Count; i++) { int itemId = _clothingDatas[i]; long itemHasCount = DecomposeDataManager.Instance.ItemCanDecomposeCount(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; _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, 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 <= 0) { PromptController.Instance.ShowFloatTextPrompt("未选择分解服装"); return; } long consumeCount = cfg.consumeCount * _decomposeCount; if (consumeCount > ItemDataManager.GetItemNum(cfg.consumeId)) { PromptController.Instance.ShowFloatTextPrompt(string.Format("{0}不足", itemCfg.name)); return; } List itemIds = _decomposeData.Keys.ToList(); List itemNums = _decomposeData.Values.ToList(); bool result = await ClothingDecomposeSProxy.ClothingDecompose(itemIds, itemNums); if (result) { OnClickBtnRarity(_curRarity); LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.FU_ZHUANG_FEN_JIE, 2); } } private void OnClickBtnRule() { ViewManager.Show(); } private void OnClickBtnBack() { ViewManager.GoBackFrom(typeof(ClothingDecomposeView).FullName); } private void CheckGuide(object param) { if (GuideDataManager.IsGuideFinish(ConstGuideId.CLOTHING_DECOMPOSE) <= 0 || 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, "回到绣坊界面。"); } } }