using System; using System.Collections.Generic; using FairyGUI; using UI.ClothingDecompose; namespace GFGGame { public class ClothingDecomposeView : BaseWindow { private UI_ClothingDecomposeUI _ui; private ValueBarController _valueBarController; private List _datas = new List(); private Dictionary _decomposeData = new Dictionary(); 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_comBtnTab.m_btnRarity0.onClick.Add(() => OnClickBtnRarity(ConstDressRarity.Rarity_FANPIN)); _ui.m_comBtnTab.m_btnRarity1.onClick.Add(() => OnClickBtnRarity(ConstDressRarity.Rarity_ZHENXI)); _ui.m_comBtnTab.m_btnRarity2.onClick.Add(() => OnClickBtnRarity(ConstDressRarity.Rarity_DIANCANG)); _ui.m_comBtnTab.m_btnRarity3.onClick.Add(() => OnClickBtnRarity(ConstDressRarity.Rarity_TIANYI)); _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; _valueBarController.OnShown(); _valueBarController.Controller(6); OnClickBtnRarity(ConstDressRarity.Rarity_FANPIN); } protected override void OnHide() { base.OnHide(); _valueBarController.OnHide(); } private void OnClickBtnRarity(int rarity) { _curRarity = rarity; _datas = DecomposeDataManager.Instance.GetDecomposeDataByRarity(rarity); _ui.m_list.visible = _datas != null && _datas.Count > 0; _ui.m_txtNone.visible = _datas == null || _datas.Count == 0; if (_datas == null) return; _ui.m_list.numItems = _datas.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(_datas[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(_datas[index]) ? _decomposeData[_datas[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 < _datas.Count; i++) { int itemId = _datas[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 = _datas.Count; } private void CancleAll() { _decomposeData.Clear(); _ui.m_list.numItems = _datas.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_txtConsume.text = string.Format("消耗{0}X{1}", itemCfg.name, (_decomposeCount * cfg.consumeCount)); _ui.m_txtShow.text = string.Format("* 分解{0}件{1}可获得 *", StringUtil.GetColorText(_decomposeCount.ToString(), "#DA826E"), ConstDressRarity.DressRarityList()[_curRarity]); } 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 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; } ItemDataManager.Remove(cfg.consumeId, consumeCount); foreach (int key in _decomposeData.Keys) { ItemDataManager.Remove(key, _decomposeData[key]); } List listReward = new List(); for (int i = 0; i < cfg.itemsArr.Length; i++) { ItemData itemData = new ItemData(); itemData.id = cfg.itemsArr[i][0]; itemData.num = cfg.itemsArr[i][1] * _decomposeCount; listReward.Add(itemData); ItemDataManager.Add(itemData.id, itemData.num); } BonusController.TryShowBonusList(listReward); OnClickBtnRarity(_curRarity); } private void OnClickBtnRule() { ViewManager.Show(); } private void OnClickBtnBack() { ViewManager.GoBackFrom(typeof(ClothingDecomposeView).FullName); } } }