----- 装备合成 ----- local this = {} local sortingOrder=0 local equipStarsConfig = ConfigManager.GetConfig(ConfigName.EquipStarsConfig) local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig) local TabBox = require("Modules/Common/TabBox") local _TabData={ [1] = { default = "zbhc_sanji2", select = "zbhc_sanji1", name = Language[10427] }, [2] = { default = "zbhc_sanji2", select = "zbhc_sanji1", name = Language[10428] }, [3] = { default = "zbhc_sanji2", select = "zbhc_sanji1", name = Language[10429] }, [4] = { default = "zbhc_sanji2", select = "zbhc_sanji1", name = Language[10430] }, --[5] = { default = "r_hero_xuanze_002", select = "r_hero_xuanze_001", name = "戒指" }, --[6] = { default = "r_hero_xuanze_002", select = "r_hero_xuanze_001", name = "腰带" } } local _TabFontColor = { default = Color.New(130 / 255, 128 / 255, 120 / 255, 1), select = Color.New(243 / 255, 235 / 255, 202 / 255, 1)} local _TabImagePos = { default = -3, select = -10} local curIndex = 0 local compoundNum = 0 local compoundMaxNum = 0 --this.tabs = {} local curNeedEquip = {} local curSelectEquip = {} local curSelectGO local materidaIsCan = false local bagPosEquips = {} local needGoldNum = 0 function this:InitComponent(gameObject) this.tabBox = Util.GetGameObject(gameObject, "CompoundPanel_Equip/TabBox") this.needGoldText = Util.GetGameObject(gameObject, "CompoundPanel_Equip/compoundBtn/needGoldText"):GetComponent("Text") this.compoundBtn = Util.GetGameObject(gameObject, "CompoundPanel_Equip/compoundBtn") this.autoCompoundBtn = Util.GetGameObject(gameObject, "CompoundPanel_Equip/autoCompoundBtn") this.addBtn = Util.GetGameObject(gameObject, "CompoundPanel_Equip/titleGo/addBtn") this.subtractBtn = Util.GetGameObject(gameObject, "CompoundPanel_Equip/titleGo/subtractBtn") this.numText = Util.GetGameObject(gameObject, "CompoundPanel_Equip/titleGo/numText"):GetComponent("Text") this.progressText = Util.GetGameObject(gameObject, "CompoundPanel_Equip/titleGo/progressText"):GetComponent("Text") this.needEquip = Util.GetGameObject(gameObject, "CompoundPanel_Equip/titleGo/needEquip") this.compoundEquip = Util.GetGameObject(gameObject, "CompoundPanel_Equip/titleGo/compoundEquip") this.progressImage = Util.GetGameObject(gameObject, "CompoundPanel_Equip/titleGo/progress/Image"):GetComponent("Image") --for i = 1, 6 do -- this.tabs[i] = Util.GetGameObject(gameObject, "CompoundPanel_Equip/Tabs/Btn" .. i) --end this.equipPre = Util.GetGameObject(gameObject, "CompoundPanel_Equip/equipPre") this.ScrollBar=Util.GetGameObject(gameObject, "CompoundPanel_Equip/Scrollbar"):GetComponent("Scrollbar") local v2 = Util.GetGameObject(gameObject, "CompoundPanel_Equip/scroll"):GetComponent("RectTransform").rect this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, Util.GetGameObject(gameObject, "CompoundPanel_Equip/scroll").transform, this.equipPre, this.ScrollBar, Vector2.New(-v2.x*2, -v2.y*2), 1, 5, Vector2.New(50,15)) this.ScrollView.moveTween.MomentumAmount = 1 this.ScrollView.moveTween.Strength = 1 end function this:BindEvent() Util.AddClick(this.compoundBtn, function() this.Compound(curIndex) end) -- Util.AddClick(this.autoCompoundBtn, function() this.AutoCompound(curIndex) end) Util.AddClick(this.addBtn, function() this.CompoundNumChange(1) end) Util.AddClick(this.subtractBtn, function() this.CompoundNumChange(2) end) end function this:AddListener() Game.GlobalEvent:AddEvent(GameEvent.Bag.BagGold,this.ShowGoldNum0) end function this:RemoveListener() Game.GlobalEvent:RemoveEvent(GameEvent.Bag.BagGold,this.ShowGoldNum0) end function this.ShowGoldNum0() if needGoldNum > BagManager.GetItemCountById(14) then materidaIsCan = false this.needGoldText.text = string.format("%s", needGoldNum) else materidaIsCan = true this.needGoldText.text =string.format("%s", needGoldNum) end end function this:OnShow(...) curIndex = 1 sortingOrder =0 needGoldNum=0 this.TabCtrl = TabBox.New() this.TabCtrl:SetTabAdapter(this.TabAdapter) this.TabCtrl:SetChangeTabCallBack(this.SwitchView) this.TabCtrl:Init(this.tabBox, _TabData,curIndex) end local sortingOrder = 0 function this:OnSortingOrderChange(_sortingOrder) sortingOrder = _sortingOrder end function this.OnClickTabBtn(_curIndex) curIndex = _curIndex bagPosEquips = EquipManager.GetEquipCompoundDataByEquipPosition1(curIndex) local equipDatas = EquipManager.GetAllSEquipsByPosition(curIndex) if equipDatas and #equipDatas > 0 then curSelectEquip = equipDatas[1] end this.ScrollView:SetData(equipDatas, function (index, go) this.SingleItemDataShow(go, equipDatas[index],equipStarsConfig[equipDatas[index].Star]) end) this.ShowTitleData(equipStarsConfig[curSelectEquip.Star]) end function this.ShowTitleData(curEquipStarsConfig) this.ShowTitleEquipData(this.compoundEquip,curSelectEquip,curEquipStarsConfig) --得到静态表中合成当前装备需要的装备 curNeedEquip = ConfigManager.GetConfigDataByDoubleKey(ConfigName.EquipConfig,"Position",curSelectEquip.Position,"Star",curSelectEquip.Star - 1) this.ShowTitleEquipData(this.needEquip,curNeedEquip,equipStarsConfig[curSelectEquip.Star - 1])--需要的材料 --得到背包中中合成当前装备需要的装备 local allCanCompoundEquips = EquipManager.GetBagCompoundEquipDatasByequipSData(curSelectEquip) local num = 0 for i=1,#allCanCompoundEquips do num=num+allCanCompoundEquips[i].num end this.progressText.text = num .. "/" .. equipStarsConfig[curSelectEquip.Star - 1].RankupCount this.progressImage.fillAmount = num / equipStarsConfig[curSelectEquip.Star - 1].RankupCount compoundNum = math.floor(num / equipStarsConfig[curSelectEquip.Star - 1].RankupCount) compoundMaxNum = math.floor(num / equipStarsConfig[curSelectEquip.Star - 1].RankupCount) this.ShowGoldNum(equipStarsConfig[curSelectEquip.Star - 1],compoundNum) end function this.ShowGoldNum(upEquipStarsConfig,compoundNum) needGoldNum = compoundNum * upEquipStarsConfig.RankupResources[1][2] if needGoldNum > BagManager.GetItemCountById(upEquipStarsConfig.RankupResources[1][1]) then materidaIsCan = false this.needGoldText.text = string.format("%s", needGoldNum) else materidaIsCan = true this.needGoldText.text =string.format("%s", needGoldNum) end this.numText.text = compoundNum Util.SetGray(this.addBtn,false) Util.SetGray(this.subtractBtn,false) this.addBtn:GetComponent("Button").enabled = true this.subtractBtn:GetComponent("Button").enabled = true if compoundNum >= compoundMaxNum then Util.SetGray(this.addBtn,true) this.addBtn:GetComponent("Button").enabled = false end if compoundNum <= 1 then Util.SetGray(this.subtractBtn,true) this.subtractBtn:GetComponent("Button").enabled = false end if compoundNum == 0 then Util.SetGray(this.addBtn,true) Util.SetGray(this.subtractBtn,true) this.addBtn:GetComponent("Button").enabled = false this.subtractBtn:GetComponent("Button").enabled = false end end function this.ShowTitleEquipData(_go,_itemData,curEquipStarsConfig) Util.GetGameObject(_go.transform,"frame"):GetComponent("Image").sprite=Util.LoadSprite(GetQuantityImageByquality(curEquipStarsConfig.Quality)) Util.GetGameObject(_go.transform,"icon"):GetComponent("Image").sprite=Util.LoadSprite(GetResourcePath(itemConfig[_itemData.Id].ResourceID)) Util.GetGameObject(_go.transform,"name"):GetComponent("Text").text = itemConfig[_itemData.Id].Name --Util.GetGameObject(_go.transform,"name"):GetComponent("Text").text=_itemData.Name SetHeroStars(Util.GetGameObject(_go.transform, "star"), curEquipStarsConfig.Stars,1,nil,-15) Util.AddClick(Util.GetGameObject(_go.transform,"icon"), function() UIManager.OpenPanel(UIName.HandBookEquipInfoPanel, _itemData.Id) end) end function this.SingleItemDataShow(_go,_itemData,curEquipStarsConfig) Util.GetGameObject(_go.transform,"frame"):GetComponent("Image").sprite=Util.LoadSprite(GetQuantityImageByquality(curEquipStarsConfig.Quality)) Util.GetGameObject(_go.transform,"icon"):GetComponent("Image").sprite=Util.LoadSprite(GetResourcePath(itemConfig[_itemData.Id].ResourceID)) Util.GetGameObject(_go.transform,"name"):GetComponent("Text").text=_itemData.Name SetHeroStars(Util.GetGameObject(_go.transform, "star"), curEquipStarsConfig.Stars,1,nil,-15) local choosed =Util.GetGameObject(_go.transform, "choosed") choosed:SetActive(curSelectEquip.Id == _itemData .Id) local redPoint = Util.GetGameObject(_go.transform,"redPoint") redPoint:SetActive(bagPosEquips[curEquipStarsConfig.Id - 1] and bagPosEquips[curEquipStarsConfig.Id - 1] >= equipStarsConfig[curEquipStarsConfig.Id - 1].RankupCount) if curSelectEquip.Id == _itemData .Id then curSelectGO = _go end Util.AddOnceClick(Util.GetGameObject(_go.transform,"icon"), function() if curSelectEquip.Id == _itemData .Id then return else curSelectEquip = _itemData choosed:SetActive(true) if curSelectGO then Util.GetGameObject(curSelectGO.transform, "choosed"):SetActive(false) curSelectGO = _go end end this.ShowTitleData(curEquipStarsConfig) end) Util.AddLongPressClick(Util.GetGameObject(_go.transform,"icon"), function() UIManager.OpenPanel(UIName.HandBookEquipInfoPanel, _itemData.Id) end, 0.5) end --加减方法 function this.CompoundNumChange(type) if type == 1 then--加 compoundNum = compoundNum + 1 else--减 compoundNum = compoundNum - 1 end --LogError("compoundNum "..compoundNum) this.ShowGoldNum(equipStarsConfig[curSelectEquip.Star],compoundNum) end function this.Compound() --LogError(" `````````````````` "..curIndex.." "..curSelectEquip.Star.." "..compoundNum) if compoundNum <= 0 then PopupTipPanel.ShowTip(Language[10431]) return end if not materidaIsCan then UIManager.OpenPanel(UIName.QuickPurchasePanel, { type = UpViewRechargeType.Gold }) return end NetManager.ComplexEquipRequest(curIndex,curSelectEquip.Star,compoundNum,function(msg) UIManager.OpenPanel(UIName.RewardItemPopup,msg.drop,1,function() this.OnClickTabBtn(curIndex) end) end) end function this.AutoCompound(_position) --进度剩余的的装备材料的数量 local curPosEquips = EquipManager.GetEquipCompoundDataByEquipPosition1(_position) local bagPosEquips = EquipManager.GetEquipCompoundDataByEquipPosition1(_position) --进度需要的消耗材料的数量 local shengGoldNum = 0 --进度剩余的的消耗材料的数量 local bagNums = {} --已有的消耗材料数量 for i = 1, #curPosEquips do if equipStarsConfig[i].RankupResources then for j = 1, #equipStarsConfig[i].RankupResources do bagNums[equipStarsConfig[i].RankupResources[j][1]] = BagManager.GetItemCountById(equipStarsConfig[i].RankupResources[j][1]) end end end --一种装备一种装备的循环检测 金币能合成的数量 与 背包装备能合成的数量 取最小值 然后扣除临时消耗道具 --最后所有装备存在curPosEquips 与 之前背包 bagPosEquips 作比较 看合成了什么装备 删除了什么装备 和计算消耗材料 local isNoGold = false--是否缺金币 for i = 1, #curPosEquips do local materialEndNum = -1 --合成的1个 下一个装备的需要的消耗材料的数量 local materialNums = {} --当前已有的消耗材料能合成的下一个装备的数量最大数量 if equipStarsConfig[i].RankupResources then for j = 1, #equipStarsConfig[i].RankupResources do local itemId = equipStarsConfig[i].RankupResources[j][1] materialNums[itemId] = equipStarsConfig[i].RankupResources[j][2] local curItmeCompoundNums =math.floor( bagNums[itemId] / equipStarsConfig[i].RankupResources[j][2]) if materialEndNum == -1 then materialEndNum = curItmeCompoundNums elseif materialEndNum > curItmeCompoundNums then materialEndNum = curItmeCompoundNums end end end if i < #curPosEquips or i == 1 then --当前拥有的装备材料能合成的下一个装备的数量 local curQuEquipCompoundNum = math.floor(curPosEquips[i] / equipStarsConfig[i].RankupCount) local endCompoundNum = materialEndNum > curQuEquipCompoundNum and curQuEquipCompoundNum or materialEndNum if not isNoGold and materialEndNum < 1 and curQuEquipCompoundNum > 0 then isNoGold = true end for itemId, num in pairs(materialNums) do bagNums[itemId] = bagNums[itemId] - endCompoundNum * num shengGoldNum = shengGoldNum + endCompoundNum * num end curPosEquips[i] = curPosEquips[i] - endCompoundNum * equipStarsConfig[i].RankupCount if curPosEquips[i + 1] then curPosEquips[i + 1] = curPosEquips[i + 1] + endCompoundNum end end end local curRewards = {} for i = 1, #curPosEquips do local str = "" if curPosEquips[i] - bagPosEquips[i] > 0 then str = Language[10432]..i.." "..curPosEquips[i] - bagPosEquips[i] local singleEquipData = {} singleEquipData.id = ConfigManager.GetConfigDataByDoubleKey(ConfigName.EquipConfig,"Position",curIndex,"Star",i).Id singleEquipData.num = curPosEquips[i] - bagPosEquips[i] table.insert(curRewards,{singleEquipData.id,singleEquipData.num}) else str = str .. Language[10433]..bagPosEquips[i] - curPosEquips[i] end end if isNoGold then PopupTipPanel.ShowTip(Language[10431]) return end if shengGoldNum <= 0 then PopupTipPanel.ShowTip(Language[10434]) return end UIManager.OpenPanel(UIName.GeneralPopup,GENERAL_POPUP_TYPE.EquipCompound, shengGoldNum,curRewards,function () NetManager.ComplexEquipRequest(curIndex,0,0,function(msg) this.OnClickTabBtn(curIndex) UIManager.OpenPanel(UIName.RewardItemPopup,msg.drop,1,function() end) end) end) end -- tab节点显示自定义 function this.TabAdapter(tab, index, status) local tabLab = Util.GetGameObject(tab, "Text") local tabImage = Util.GetGameObject(tab,"Image") tabImage:GetComponent("Image").sprite = Util.LoadSprite(_TabData[index][status]) tabImage:GetComponent("Image"):SetNativeSize() tabLab:GetComponent("Text").text = _TabData[index].name tabLab:GetComponent("Text").color = _TabFontColor[status] tabImage.transform.localPosition = Vector3.New( tabImage.transform.localPosition.x, _TabImagePos[status], 0); end --切换视图 function this.SwitchView(index) this.OnClickTabBtn(index) end function this:OnClose() needGoldNum=0 end function this:OnDestroy() needGoldNum=0 end return this