----- 易经宝库奖励预览弹窗 ----- local this = {} --传入父脚本模块 local parent --传入特效层级 local sortingOrder=0 local activityId = 0 local activityType = 0 local itemConfig=ConfigManager.GetConfig(ConfigName.ItemConfig) function this:InitComponent(gameObject) this.title = Util.GetGameObject(gameObject,"title"):GetComponent("Text") this.tip = Util.GetGameObject(gameObject,"tip"):GetComponent("Text") this.itemGrid=Util.GetGameObject(gameObject,"panel/itemGrid") this.LookDetailBtn=Util.GetGameObject(gameObject,"panel/Image3/updetail") this.content=Util.GetGameObject(gameObject,"panel/content/grid/Text"):GetComponent("Text") this.time=Util.GetGameObject(gameObject,"tip"):GetComponent("Text") this.grid = Util.GetGameObject(gameObject,"panel/rate/grid") this.pre = Util.GetGameObject(gameObject,"panel/rate/rateprefab") this.ratePreList = {} for i = 1,this.grid.transform.childCount do this.ratePreList[i] = {} this.ratePreList[i].go = this.grid.transform:GetChild(i-1) this.ratePreList[i].star = Util.GetGameObject(this.ratePreList[i].go,"star"):GetComponent("Text") this.ratePreList[i].name = Util.GetGameObject(this.ratePreList[i].go,"name"):GetComponent("Text") this.ratePreList[i].rate = Util.GetGameObject(this.ratePreList[i].go,"rate"):GetComponent("Text") end end function this:BindEvent() Util.AddClick(this.LookDetailBtn,function() this:LookDetailBtnAction() end) end function this:LookDetailBtnAction() if activityType == ActivityTypeDef.FindFairy then UIManager.OpenPanel(UIName.HeroPreviewPanel,true,false) else LogPurple("打开魂印奖励预览") end end function this:AddListener() end function this:RemoveListener() end function this:OnShow(_parent,...) parent=_parent sortingOrder = _parent.sortingOrder local args = {...} local helpType = args[1] local str=ConfigManager.TryGetConfigData(ConfigName.QAConfig,helpType).content str = string.gsub(str,"{","") str = string.gsub(str,"}","") str = string.gsub(str,"|","\n")--换行 this.content.text= str activityType = args[2] local str2 = ActivityGiftManager.GetTimeStartToEnd(activityType) this.time.text="概率有效期:"..str2 local poolUpType = args[3] local poolType = args[4] or 0 local UpItemList=RecruitManager.GetRewardPreviewData(poolUpType) local itemList = RecruitManager.GetRewardPreviewData(poolType) local rateList = this:BuildRateData(activityType,itemList,UpItemList) this:ReFreshUpItem(UpItemList,rateList) end function this:ReFreshUpItem(UpItem,rateList) local rewardData,showData,curScore = DynamicActivityManager.RecrutDetailData(activityType) if(not this.listUpPre) then this.listUpPre={} end for k,v in ipairs(this.listUpPre) do v.gameObject:SetActive(false) end for n,m in ipairs(UpItem) do if m then if not this.listUpPre[n] then this.listUpPre[n] = SubUIManager.Open(SubUIConfig.ItemView,this.itemGrid.transform) end this.listUpPre[n]:OnOpen(false, {m.Reward[1], m.Reward[2]}, 1.1, true) this.listUpPre[n].name:GetComponent("Text").text=""..string.format("%.2f", (rateList[n].value/100000)*100) .."%" this.listUpPre[n].gameObject:SetActive(true) end end end function this:BuildRateData(actType,UpItem,upItemList) local rateList = {} local _rateList = {} if actType == ActivityTypeDef.FindFairy then _rateList = this:ReculateUpHeroRate(UpItem,upItemList,"5星UP!",ConfigName.HeroConfig) rateList = this:RefreshHeroRate(UpItem,_rateList) elseif actType == ActivityTypeDef.QianKunBox then _rateList = this:ReculateUpHeroRate(UpItem,upItemList,"魂印UP!",ConfigName.EquipConfig) rateList = this:RefreshSoulRate(UpItem,_rateList) elseif actType == ActivityTypeDef.LingShouBaoGe then rateList = this:RefreshMonsterRate(UpItem,upItemList,"灵兽UP!",ConfigName.SpiritAnimal) elseif actType == ActivityTypeDef.XiangYaoDuoBao then rateList = this:RefreshNewHeroRate(UpItem,upItemList,"5星UP!",ConfigName.HeroConfig) end for k,v in ipairs(this.ratePreList) do v.go.gameObject:SetActive(false) end for n,m in ipairs(rateList) do if not this.ratePreList[n] then this.ratePreList[n] = {} this.ratePreList[n].go = newObjToParent(this.pre,this.grid) this.ratePreList[n].star = Util.GetGameObject(this.ratePreList[n].go,"star"):GetComponent("Text") this.ratePreList[n].name = Util.GetGameObject(this.ratePreList[n].go,"name"):GetComponent("Text") this.ratePreList[n].rate = Util.GetGameObject(this.ratePreList[n].go,"rate"):GetComponent("Text") end this.ratePreList[n].go.gameObject:SetActive(true) this.ratePreList[n].star.text=m.tag this.ratePreList[n].name.text=m.name this.ratePreList[n].rate.text=string.format("%.2f",(m.value/100000)*100).."%" end return rateList end --通用计算权重功能 function this:ReculateRate(list) local weight=0 for index, v in ipairs(list) do weight=v.Weight+weight end return weight end function this:ReculateUpHeroRate(itemList,UpItemList,_tag,config) local rateList = {} for k,v in ipairs(UpItemList) do for n,m in ipairs(itemList) do if v.Reward[1] == m.Reward[1] then local _config = ConfigManager.GetConfigData(config,v.Reward[1]) local readingName = _config.ReadingName or _config.Name table.insert(rateList,{tag=_tag,name = readingName,value = m.Weight}) break end end end return rateList end function this:RefreshHeroRate(hero,_rateList) local list3={} local list4={} local list5={} local list2={} for index, v in ipairs(hero) do if itemConfig[v.Reward[1]].HeroStar[2]==3 then table.insert(list3,v) elseif itemConfig[v.Reward[1]].HeroStar[2]==4 then table.insert(list4,v) elseif itemConfig[v.Reward[1]].HeroStar[2]==5 then table.insert(list5,v) elseif itemConfig[v.Reward[1]].HeroStar[2]==2 then table.insert(list2,v) end end local valueList5 = this:ReculateRate(list5) for i = 1 , #_rateList do valueList5 = valueList5 - _rateList[i].value end table.insert(_rateList,{tag="5星",name="其他5星",value = valueList5}) table.insert(_rateList,{tag="4星",name="4星神将",value = this:ReculateRate(list4)}) table.insert(_rateList,{tag="3星",name="3星神将",value = this:ReculateRate(list3)}) table.insert(_rateList,{tag="2星",name="2星神将",value = this:ReculateRate(list2)}) return _rateList end function this:RefreshSoulRate(soul,_rateList) local list4={} local list5={} local list6={} local list7={} for index, v in ipairs(soul) do if itemConfig[v.Reward[1]].Quantity==4 and itemConfig[v.Reward[1]].ItemType==13 then table.insert(list4,v)--紫色 elseif itemConfig[v.Reward[1]].Quantity==5 and itemConfig[v.Reward[1]].ItemType==13 then table.insert(list5,v)--金色 elseif itemConfig[v.Reward[1]].Quantity==6 and itemConfig[v.Reward[1]].ItemType==13 then table.insert(list6,v)--红色 else table.insert(list7,v)--其他 end end local valueList6 = this:ReculateRate(list6) for i = 1 , #_rateList do valueList6 = valueList6 - _rateList[i].value end table.insert(_rateList,{tag="红色",name="其他".."红色",value = valueList6}) table.insert(_rateList,{tag="金色",name="金色",value=this:ReculateRate(list5)}) table.insert(_rateList,{tag="紫色",name="紫色",value=this:ReculateRate(list4)}) table.insert(_rateList,{tag="其他",name="其他",value=this:ReculateRate(list7)}) return _rateList end function this:RefreshMonsterRate(UpMonster,_rateList) local list1={} local list2={} local list3={} local list4={} for index, v in ipairs(UpMonster) do if itemConfig[v.Reward[1]].Quantity==5 and (itemConfig[v.Reward[1]].ItemType==22 or itemConfig[v.Reward[1]].ItemType==21) then table.insert(list1,v)--金色灵兽碎片 elseif itemConfig[v.Reward[1]].Quantity==4 and (itemConfig[v.Reward[1]].ItemType==22 or itemConfig[v.Reward[1]].ItemType==21) then table.insert(list2,v)--紫色灵兽碎片 elseif itemConfig[v.Reward[1]].Quantity==3 and (itemConfig[v.Reward[1]].ItemType==22 or itemConfig[v.Reward[1]].ItemType==21) then table.insert(list3,v)--蓝色灵兽碎片 else table.insert(list4,v)--其他 end end local valueList1 = this:ReculateRate(list1) for i = 1 , #_rateList do valueList1 = valueList1 - _rateList[i].value end table.insert(_rateList,{tag="金色",name="其他金色奖励",value=valueList1}) table.insert(_rateList,{tag="紫色",name="紫色奖励",value=this:ReculateRate(list2)}) table.insert(_rateList,{tag="蓝色",name="蓝色奖励",value=this:ReculateRate(list3)}) table.insert(_rateList,{tag="其他",name="其他",value=this:ReculateRate(list4)}) return _rateList end function this:RefreshNewHeroRate(UpMonster,_rateList) local list1={} local list2={} local list3={} local allValue for index, v in ipairs(UpMonster) do if itemConfig[v.Reward[1]].HeroStar[2]==5 then table.insert(list1,v)--五星应雄 elseif itemConfig[v.Reward[1]].HeroStar[2]==4 then table.insert(list2,v)--四星应雄 elseif itemConfig[v.Reward[1]].HeroStar[2]==3 then table.insert(list3,v)--三星应雄 end end local valueList1 = this:ReculateRate(list1) for i = 1 , #_rateList do valueList1 = valueList1 - _rateList[i].value end table.insert(_rateList,{tag="五星",name="其他五星英雄",value=valueList1}) table.insert(_rateList,{tag="四星",name="四星英雄",value=this:ReculateRate(list2)}) table.insert(_rateList,{tag="三星",name="三星英雄",value=this:ReculateRate(list3)}) for i = 1 , #_rateList do allValue = _rateList[i].value end return _rateList end function this:OnClose() end function this:OnDestroy() this.ratePreList = {} this.listUpPre = {} end return this