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 _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; 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 == 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; _decomposeCount += 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; _decomposeCount -= 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; 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; _decomposeCount += count; if (lastCount == 0) break; } _ui.m_list.numItems = _clothingDatas.Count; } private void CancleAll() { _decomposeCount = 0; _decomposeData.Clear(); if (_clothingDatas != null) _ui.m_list.numItems = _clothingDatas.Count; } private void UpdateConsume() { int consumeId; int[][] itemsArr; int consumeCount; DecomposeCfg cfg = DecomposeCfgArray.Instance.GetCfg(_curRarity); if (_ui.m_c1.selectedIndex == 0) { DecomposeCfg decomposeCfg = DecomposeCfgArray.Instance.GetCfg(_curRarity); consumeId = decomposeCfg.consumeId; itemsArr = decomposeCfg.itemsArr; consumeCount = decomposeCfg.consumeCount; } else { DecomposeSkillCfg decomposeSkillCfg = DecomposeSkillCfgArray.Instance.GetCfg(_curRarity); consumeId = decomposeSkillCfg.consumeId; itemsArr = decomposeSkillCfg.itemsArr; consumeCount = decomposeSkillCfg.consumeCount; } ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(consumeId); _ui.m_listReward.numItems = _decomposeCount > 0 ? itemsArr.Length : 0; _ui.m_txtShow.text = string.Format("* 分解{0}件{1}可获得 *", StringUtil.GetColorText(_decomposeCount.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[][] itemsArr; if (_ui.m_c1.selectedIndex == 0) { DecomposeCfg decomposeCfg = DecomposeCfgArray.Instance.GetCfg(_curRarity); itemsArr = decomposeCfg.itemsArr; } else { DecomposeSkillCfg decomposeSkillCfg = DecomposeSkillCfgArray.Instance.GetCfg(_curRarity); itemsArr = decomposeSkillCfg.itemsArr; } ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemsArr[index][0]); item.m_txtCount.text = (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) { String str = ""; if (_ui.m_c1.selectedIndex == 0) str = "未选择分解服装"; else str = "未选择分解技能书"; PromptController.Instance.ShowFloatTextPrompt(str); 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(); 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, "回到绣坊界面。"); } } }