require("Base/BasePanel") EquipTreasureStrongPopup = Inherit(BasePanel) local itemConfig=ConfigManager.GetConfig(ConfigName.ItemConfig) local jewelConfig=ConfigManager.GetConfig(ConfigName.JewelConfig) local this=EquipTreasureStrongPopup local curEquipData local haveTreasures={} local type local isMatEnough=true local matId=0 local isCoinEnough=true local isMax=false local isEnough = false local curIndex = 0 --初始化组件(用于子类重写) function EquipTreasureStrongPopup:InitComponent() this.spLoader = SpriteLoader.New() this.content = Util.GetGameObject(self.transform, "bg/content") this.btnBack= Util.GetGameObject(this.content,"btnBack") this.titleTxt=Util.GetGameObject(this.content,"name"):GetComponent("Text") this.itemPre = Util.GetGameObject(this.content,"itemView") this.firstScroll=Util.GetGameObject(this.content,"firstScroll") this.properItemPre = Util.GetGameObject(this.content,"propertyPre") this.propertyGrid=Util.GetGameObject(this.content,"secondScroll/grid") this.costItemGrid=Util.GetGameObject(this.content,"costGrid") this.hintTxt=Util.GetGameObject(this.content,"hintTxt"):GetComponent("Text") this.btnRefine=Util.GetGameObject(this.content,"btnGrid/btnRefine") this.btnRefineText = Util.GetGameObject(this.btnRefine,"Text"):GetComponent("Text") this.btnStrong=Util.GetGameObject(this.content,"btnGrid/btnStrong") this.btnStrongText = Util.GetGameObject(this.btnStrong,"Text"):GetComponent("Text") this.btn_strongPage=Util.GetGameObject(this.content,"btnList/btnStrong") this.btn_refinePage=Util.GetGameObject(this.content,"btnList/btnRefine") this.selectBtn=Util.GetGameObject(this.content,"btnList/selectBtn") this.treasureDatas = {} this.costTreasureDatas = {} this.properList = {} this.properList[0] = {} this.properList[0].go = this.properItemPre this.properList[0].leftTxt = Util.GetGameObject(this.properItemPre,"leftTxt"):GetComponent("Text") this.properList[0].rightTxt = Util.GetGameObject(this.properItemPre,"rightTxt"):GetComponent("Text") local rootHight = this.firstScroll.transform.rect.height local rootWidth=this.firstScroll.transform.rect.width this.firstScrollCycleView = SubUIManager.Open(SubUIConfig.ScrollCycleView,this.firstScroll.transform,this.itemPre,nil, Vector2.New(rootWidth,rootHight), 1, 5, Vector2.New(15,30)) this.gongming = Util.GetGameObject(this.content,"gongming") this.gongming.gameObject:SetActive(false) this.select = Util.GetGameObject(this.content,"select") end --绑定事件(用于子类重写) function EquipTreasureStrongPopup:BindEvent() --关闭按钮 Util.AddClick(this.btnBack, function() PlaySoundWithoutClick(SoundConfig.Sound_UICancel) self:ClosePanel() end) --强化页签 Util.AddClick(this.btn_strongPage, function() this:SetWindShow(1) end) --精炼页签 Util.AddClick(this.btn_refinePage, function() this:SetWindShow(2) end) --强化按钮 Util.AddClick(this.btnStrong, function() if HarmonyManager.IsInfo(curEquipData.upHeroDid) then return end --如果强化界面 强化到最高等级谈提示 精炼界面 就切界面 if type==1 then if isMax then PopupTipPanel.ShowTip(Language[11770]) return end else this:SetWindShow(1) return end --材料是否足够 if isMatEnough==false then UIManager.OpenPanel(UIName.RewardItemSingleShowPopup,matId) return end --金币是否足够 if isCoinEnough==false then PopupTipPanel.ShowTip(Language[11771]) return end NetManager.EquipTreasureBuildRequest(curEquipData.idDyn,1,nil,function (msg) EquipTreasureManager.ChangeTreasureLv(curEquipData.idDyn,type) this:SetWindShow(type) this.treasureDatas[curIndex]:OnOpen(false, {curEquipData.id,0}, 1, true, false, false, 0,curEquipData.idDyn) if isMax then PopupTipPanel.ShowTip(Language[11772]) else --PopupTipPanel.ShowTip("强化成功") end local oldWarPowerValue = EquipTreasureManager.CalculateWarForceBySid(curEquipData.id,curEquipData.lv - 1,curEquipData.refineLv) local newWarPowerValue = EquipTreasureManager.CalculateWarForceBySid(curEquipData.id,curEquipData.lv,curEquipData.refineLv) if oldWarPowerValue ~= newWarPowerValue then UIManager.OpenPanel(UIName.WarPowerChangeNotifyPanelV2,{oldValue = oldWarPowerValue,newValue = newWarPowerValue}) end Game.GlobalEvent:DispatchEvent(GameEvent.Treasure.TreasureLvUp) end) end) --精炼按钮 Util.AddClick(this.btnRefine, function() --如果精炼界面 精炼到最高等级谈提示 否 强化界面 就切界面 if type==2 then if isMax then PopupTipPanel.ShowTip(Language[11773]) return end else this:SetWindShow(2) return end if isMatEnough==false then UIManager.OpenPanel(UIName.RewardItemSingleShowPopup,matId) return end if isCoinEnough==false then PopupTipPanel.ShowTip(Language[11771]) return end local maters={} if haveTreasures then for i, v in pairs(haveTreasures) do local index=1 if v.equip then for i, value in pairs(v.equip) do if #maters < v.needNum then maters[index]=value.idDyn index=index+1 end end end end end NetManager.EquipTreasureBuildRequest(curEquipData.idDyn,2,maters,function (msg) if maters then for i = 1, #maters do EquipTreasureManager.RemoveTreasureByIdDyn(maters[i]) end end EquipTreasureManager.ChangeTreasureLv(curEquipData.idDyn,type) this:SetWindShow(type) this.treasureDatas[curIndex]:OnOpen(false, {curEquipData.id,0}, 1, true, false, false, 0,curEquipData.idDyn) if isMax then PopupTipPanel.ShowTip(Language[11774]) else --PopupTipPanel.ShowTip("精炼成功") end local oldWarPowerValue = EquipTreasureManager.CalculateWarForceBySid(curEquipData.id,curEquipData.lv ,curEquipData.refineLv - 1) local newWarPowerValue = EquipTreasureManager.CalculateWarForceBySid(curEquipData.id,curEquipData.lv,curEquipData.refineLv) if oldWarPowerValue ~= newWarPowerValue then UIManager.OpenPanel(UIName.WarPowerChangeNotifyPanelV2,{oldValue = oldWarPowerValue,newValue = newWarPowerValue}) end Game.GlobalEvent:DispatchEvent(GameEvent.Treasure.TreasureLvUp) end) return end) end --界面打开时调用(用于子类重写) function EquipTreasureStrongPopup:OnOpen(...) local datas={...} curEquipData=datas[1] type=datas[2] end function EquipTreasureStrongPopup:OnShow() local datas = EquipTreasureManager.GetAllHeroEquipedTreasureData() this.formationInfo = FormationManager.GetFormationByID(FormationTypeDef.FORMATION_NORMAL) table.sort(datas,function(a,b) local aIsMainFormation = this:GetHeroIsMainFormation(a.upHeroDid) local bIsMainFormation = this:GetHeroIsMainFormation(b.upHeroDid) if aIsMainFormation and bIsMainFormation then if a.upHeroDid ~= b.upHeroDid then return aIsMainFormation.position < bIsMainFormation.position else return a.equipType < b.equipType end elseif not aIsMainFormation and not bIsMainFormation then if a.quantity == b.quantity then return a.id < b.id else return a.quantity > b.quantity end else return aIsMainFormation end end) this:ShowTopDataList(datas) this:SetWindShow(type) end function EquipTreasureStrongPopup:GetHeroIsMainFormation(HeroId) for k,v in ipairs(this.formationInfo.teamHeroInfos) do if HeroId == v.heroId then return v end end return nil end function EquipTreasureStrongPopup:ShowTopDataList(list) if not this.treasureDatas then this.treasureDatas = {} end this.firstScrollCycleView:ForeachItemGO(function(index, go) go.gameObject:SetActive(false) end) this.firstScrollCycleView:SetData(list,function(index, go) this:SetScrollPre(go,list[index],index) end,false,false) for i = 1,#list do if list[i].idDyn == curEquipData.idDyn then curIndex = i this.firstScrollCycleView:SetIndex(i) break end end end function EquipTreasureStrongPopup:SetScrollPre(go,data,_index) if data.idDyn == curEquipData.idDyn then this.select.transform:SetParent(go.transform) this.select:GetComponent("RectTransform").anchoredPosition3D = Vector3.New(-8.5,6.8,0) this.select.gameObject:SetActive(true) end go.gameObject:SetActive(true) local btn = Util.GetGameObject(go,"btn") local red = Util.GetGameObject(go,"red") if not this.treasureDatas[_index] then this.treasureDatas[_index] = SubUIManager.Open(SubUIConfig.ItemView,go.transform) this.treasureDatas[_index].transform:SetAsFirstSibling() end this.treasureDatas[_index]:OnOpen(false, {data.id,0}, 1, true, false, false, 0,data.idDyn) this.treasureDatas[_index].name:GetComponent("Text").text = HeroManager.GetSingleHeroData(data.upHeroDid).heroConfig.ReadingName red.gameObject:SetActive(false) Util.AddOnceClick(btn,function() this.select.transform:SetParent(go.transform) this.select:GetComponent("RectTransform").anchoredPosition3D = Vector3.New(-8.5,6.8,0) this.select.gameObject:SetActive(true) curEquipData = data curIndex = _index this:SetWindShow(type) end) end --设置界面显示 1.强化 2.精炼 function EquipTreasureStrongPopup:SetWindShow(_index) haveTreasures = {} type = _index curEquipData = EquipTreasureManager.GetSingleEquipTreasreData(curEquipData.idDyn) isMatEnough=true isCoinEnough=true local items, propertyShow if _index == 1 then this.titleTxt.text = Language[11775] this.btnRefine:SetActive(false) this.btnStrong:SetActive(true) this.SetBtnSelect(this.btn_strongPage) isMax = curEquipData.lv == curEquipData.maxLv this.properList[0].leftTxt.text = "强化等级" if isMax then this.properList[0].rightTxt.text = Language[11062] this.btnStrong.gameObject:SetActive(false) else this.btnStrongText.text = Language[11777] this.properList[0].rightTxt.text = string.format( "%d/%d",curEquipData.lv+1,curEquipData.maxLv) end propertyShow = EquipTreasureManager.GetCurrLvAndNextLvPropertyValue(1,curEquipData.levelPool,curEquipData.lv) --显示消耗 items = this:GetCostItems(curEquipData.strongConfig) this.hintTxt.text=Language[11778] else this.titleTxt.text=Language[11779] this.btnRefine:SetActive(true) this.btnStrong:SetActive(false) this.SetBtnSelect(this.btn_refinePage) isMax=curEquipData.refineLv==curEquipData.maxRefineLv this.properList[0].leftTxt.text = "精炼等级" if isMax then this.properList[0].rightTxt.text = Language[11062] this.btnRefine.gameObject:SetActive(false) else this.btnRefineText.text=Language[11781] this.properList[0].rightTxt.text = string.format( "%d/%s",curEquipData.refineLv+1,curEquipData.maxRefineLv) end propertyShow = EquipTreasureManager.GetCurrLvAndNextLvPropertyValue(2,curEquipData.refinePool,curEquipData.refineLv) items = this:GetCostItems(curEquipData.refineConfig) this.hintTxt.text=Language[11782] end if HarmonyManager.IsInfo(curEquipData.upHeroDid) and _index == 1 then this.hintTxt.text = "共鸣中的宝物无法强化" this.hintTxt.gameObject:SetActive(true) else this.hintTxt.gameObject:SetActive(isMax) end this:SetPropertyShow(propertyShow) this:CostShow(items) end function EquipTreasureStrongPopup:CostShow(items) if not this.costItemPreList then this.costItemPreList = {} end --显示消耗物品 if items and isMax==false then this.costItemGrid.gameObject:SetActive(true) for i = 1,math.max(#items,#this.costItemPreList) do if not items[i] then this.costItemPreList[i].gameObject:SetActive(false) else if not this.costItemPreList[i] then this.costItemPreList[i] = SubUIManager.Open(SubUIConfig.ItemView,this.costItemGrid.transform) end this.costItemPreList[i].gameObject:SetActive(true) if items[i].id==curEquipData.id then this.costItemPreList[i]:OnOpen(false,{items[i].id,0}, 0.8, true, items[i].isEnough , false, 0) else this.costItemPreList[i]:OnOpen(false,{items[i].id,0}, 0.8, true, false , false, 0) end if items[i].isEnough then this.costItemPreList[i].name:GetComponent("Text").text = string.format("%s/%s",items[i].haveNum,items[i].needNum) else --如果材料不足默认弹第一个不足的材料tip if isMatEnough then isMatEnough=false matId=items[i].id end this.costItemPreList[i].name:GetComponent("Text").text = string.format("%s/%s",items[i].haveNum,items[i].needNum) end end end else this.costItemGrid.gameObject:SetActive(false) end end --获取消耗物品数据 function EquipTreasureStrongPopup:GetCostItems(_config) if _config==nil then return end local config=_config local exps=config.UpExpend if exps==nil then return end local items={} for i = 1,#exps do local id=exps[i][1] if itemConfig[id]then local item={} item.id=id item.icon=GetResourcePath(itemConfig[id].ResourceID) item.frame=GetQuantityImageByquality(itemConfig[id].Quantity) item.haveNum=BagManager.GetItemCountById(id) item.needNum=exps[i][2] item.isEnough=item.haveNum>=item.needNum items[i]=item end end if config.JewelExpend then for i = 1, #config.JewelExpend do local id=config.JewelExpend[i] local item={} --同类型宝物 local type=id[1] if type==1 then item.id=curEquipData.id item.icon=curEquipData.icon item.frame=curEquipData.frame local equips,num=EquipTreasureManager.GetEnoughRefineTreasure(curEquipData.id,curEquipData.idDyn) if equips then item.haveNum= num else item.haveNum=0 end item.needNum=id[2] local equipValue={} equipValue.equip=equips equipValue.needNum=id[2] --table.insert(haveTreasures,equipValue) haveTreasures[type]=equipValue if item.haveNum>=item.needNum then item.isEnough=true else item.isEnough=false isEnough=false end items[#items+1]=item else item.id=type local config=itemConfig[type] if config then item.icon=GetResourcePath(config.ResourceID) item.frame=GetQuantityImageByquality(config.Quantity) local equips,num=EquipTreasureManager.GetEnoughRefineTreasure(type,curEquipData.idDyn) if equips then item.haveNum= num else item.haveNum=0 end local equipValue={} equipValue.equip=equips equipValue.needNum=id[2] --table.insert(haveTreasures,equipValue) haveTreasures[type]=equipValue item.needNum=id[2] if item.haveNum>=item.needNum then item.isEnough=true else item.isEnough=false isEnough=false end items[#items+1]=item end end end end return items,costCoin end --设置属性的显示 function EquipTreasureStrongPopup:SetPropertyShow(_infos) if this.hintTxt.gameObject.activeInHierarchy then this.properList[0].go.gameObject:SetActive(false) this.propertyGrid.gameObject:SetActive(false) return end this.propertyGrid.gameObject:SetActive(true) if type == 1 and HarmonyManager.IsInfo(curEquipData.upHeroDid) then for i = 0, #this.properList do this.properList[i].go.gameObject:SetActive(false) end --this.gongming.gameObject:SetActive(true) return end --this.gongming.gameObject:SetActive(false) this.properList[0].go.gameObject:SetActive(true) for i = 1, #this.properList do this.properList[i].go.gameObject:SetActive(false) end local index = 1 for key, value in pairs(_infos) do if not this.properList[index] then this.properList[index] = {} this.properList[index].go = newObjToParent(this.properItemPre,this.propertyGrid) this.properList[index].leftTxt = Util.GetGameObject(this.properList[index].go,"leftTxt"):GetComponent("Text") this.properList[index].rightTxt = Util.GetGameObject(this.properList[index].go,"rightTxt"):GetComponent("Text") end this.properList[index].go.gameObject:SetActive(true) local proper=ConfigManager.GetConfigData(ConfigName.PropertyConfig,key) if proper.Style==1 then this.properList[index].leftTxt.text=string.format("%s+%s",GetLanguageStrById(proper.Info),value.currValue) this.properList[index].rightTxt.text= isMax and Language[11062] or value.nextValue else this.properList[index].leftTxt.text=GetLanguageStrById(proper.Info).."+"..value.currValue/100 .."%" this.properList[index].rightTxt.text = isMax and Language[11062] or value.nextValue/100 .."%" end index=index+1 end end --设置物体选中 function this.SetBtnSelect(_parObj) Util.GetGameObject(this.selectBtn, "Text"):GetComponent("Text").text=Util.GetGameObject(_parObj, "Text"):GetComponent("Text").text this.selectBtn.transform:SetParent(_parObj.transform) this.selectBtn.transform.localScale = Vector3.one this.selectBtn.transform.localPosition=Vector3.zero end --界面关闭时调用(用于子类重写) function EquipTreasureStrongPopup:OnClose() curEquipData=nil isEnough=true type=0 isMax=false isCoinEnough=false isMatEnough=false haveTreasures={} matId = 0 end --界面销毁时调用(用于子类重写) function EquipTreasureStrongPopup:OnDestroy() this.spLoader:Destroy() Util.ClearChild(this.propertyGrid.transform) this.properList = {} for i = 1,#this.costItemPreList do SubUIManager.Close(this.costItemPreList[i]) end this.costItemPreList = {} for i = 1,#this.costItemPreList do SubUIManager.Close(this.treasureDatas[i]) end this.costItemPreList = {} SubUIManager.Close(this.firstScrollCycleView) end return EquipTreasureStrongPopup