require("Base/BasePanel") FormationEditPopup = Inherit(BasePanel) local this = FormationEditPopup local chooseIndex=0 local choosedList={} local deleteList={} local curFormationIndex local order=0 -- local orderImageTextList={} -- 妖灵师等级限制显示 local _LimitLevel = 0 local _LimitNum = 0 local _BloodList = nil -- local curFormation local sortType = 1 -- 1:品阶 2:等级 local proId=0--0 全部 1 火 2风 3 水 4 地 5时空 local tabs = {}--筛选按钮 local maxNum =5 --最大上阵人数 local goList={} --当前英雄对应预设的集合 local func=nil --回调 local healHero = {}--需要忽略的神将id function FormationEditPopup:InitComponent() this.spLoader = SpriteLoader.New() this.mask = Util.GetGameObject(this.gameObject, "BgMask") this.BtnBack = Util.GetGameObject(this.gameObject, "bg/btnBack") this.BtnSure = Util.GetGameObject(this.gameObject, "bg/btnSure") this.allBtn=Util.GetGameObject(this.gameObject,"bg/allBtn") this.cardPre = Util.GetGameObject(this.gameObject, "item") this.grid = Util.GetGameObject(this.gameObject, "bg/scroll") this.desc=Util.GetGameObject(this.gameObject,"bg/desc"):GetComponent("Text") local particles=this.cardPre:GetComponentsInChildren(typeof(UnityEngine.ParticleSystem)) --筛选按钮 for i = 0, 5 do tabs[i] = Util.GetGameObject(this.gameObject, "bg/Tabs/Grid/Btn" .. i) end this.selectBtn = Util.GetGameObject(this.gameObject, "bg/Tabs/SelectBtn") this.ShaiXuanBtn = Util.GetGameObject(self.gameObject, "bg/ShaiXuanBtn") this.ShaiXuanBtnLv = Util.GetGameObject(self.gameObject, "bg/ShaiXuanBtn/Lv") this.ShaiXuanBtnQu = Util.GetGameObject(self.gameObject, "bg/ShaiXuanBtn/Qu") this.ScrollBar = Util.GetGameObject(self.gameObject, "bg/Scrollbar"):GetComponent("Scrollbar") this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, Util.GetGameObject(self.gameObject, "scroll").transform, this.cardPre, this.ScrollBar, Vector2.New(927.5, 927), 1, 5, Vector2.New(19.32, 40)) this.ScrollView.gameObject:GetComponent("RectTransform").anchoredPosition = Vector2.New(0, 0) this.ScrollView.gameObject:GetComponent("RectTransform").anchorMin = Vector2.New(0.5, 0.5) this.ScrollView.gameObject:GetComponent("RectTransform").anchorMax = Vector2.New(0.5, 0.5) this.ScrollView.gameObject:GetComponent("RectTransform").pivot = Vector2.New(0.5, 0.5) this.ScrollView.moveTween.MomentumAmount = 1 this.ScrollView.moveTween.Strength = 1 -- this.isHaveInTeam = false healHero = string.split(ConfigManager.GetConfigDataByKey(ConfigName.SpecialConfig,"Id",86).Value,"|") end --是否是治疗神将 function FormationEditPopup:isNotHealHero(hero) for i = 1, #healHero do if hero.id == tonumber(healHero[i]) then return false end end return true end function FormationEditPopup:BindEvent() Util.AddClick(this.BtnBack, function() PlaySoundWithoutClick(SoundConfig.Sound_UICancel) Game.GlobalEvent:DispatchEvent(GameEvent.Map.Out,0) self:ClosePanel() end) Util.AddClick(this.mask, function() PlaySoundWithoutClick(SoundConfig.Sound_UICancel) Game.GlobalEvent:DispatchEvent(GameEvent.Map.Out,0) self:ClosePanel() end) --选定按钮 Util.AddClick(this.BtnSure, function() local go=function() local heros={} for i, v in ipairs(choosedList) do local hero = {} hero.heroId = v.did hero.position = #choosedList + 1 table.insert(heros,hero) end table.sort(heros,function (a,b) return HeroManager.GetSingleHeroData(a.heroId).warPower > HeroManager.GetSingleHeroData(b.heroId).warPower end) for i = 1, #heros do heros[i].position = i end if #choosedList <= maxNum and #choosedList > 0 then NetManager.TrialHeroInfoSaveRequest(heros,function(msg) PopupTipPanel.ShowTip(Language[10670]) local heros = msg.heroes if heros and #heros > 1 then table.sort(heros,function (a,b) return a.position < b.position end) end MapManager.trialHeroInfo = heros if func~=nil then --保存完毕后 将英雄did合集传递过去 此时我拥有这些英雄 不用担心英雄已被删除 func(heros) end PlayerPrefs.SetInt(PlayerManager.uid.."Trial",1)--设置森罗红点关 CheckRedPointStatus(RedPointType.Trial) self:ClosePanel() end) else PopupTipPanel.ShowTip(Language[10671]) end end if #choosedList < maxNum and #choosedList > 0 then MsgPanel.ShowTwo(Language[10672], nil, function() go() end) else go() end end) --一键选择 Util.AddClick(this.allBtn,function() for i, v in pairs(goList) do --先关闭全部选择项 清空选择列表 Util.GetGameObject(v, "choosed"):SetActive(false) end choosedList={} --按战力从大到小排序 local heros = {} if proId == ProIdConst.All then heros = HeroManager.GetAllHeroDatas(_LimitLevel) else heros = HeroManager.GetHeroDataByProperty(proId, _LimitLevel) end table.sort(heros,function(a,b) local aWarPower = HeroPowerManager.GetHeroPower(a.dynamicId) local bWarPower = HeroPowerManager.GetHeroPower(b.dynamicId) if aWarPower==bWarPower then return a.id>b.id else return aWarPower>bWarPower end end) --将战力前5英雄选中赋值 for index, value in ipairs(heros) do local go local isNotHeal = self:isNotHealHero(heros[index]) for k, v in pairs(goList) do if k and heros[index] and k==heros[index].dynamicId and isNotHeal then --goList的键值是英雄did 若它与当前英雄列表中的did相等 go=Util.GetGameObject(v, "choosed") go.gameObject:SetActive(true) end end order=order+1 if heros[index] and isNotHeal then --若存在该索引 就插入数据(当我筛选某一元素时,该元素英雄长度可能不为5) table.insert(choosedList,{did = heros[index].dynamicId, choosed = go,position=order}) end if #choosedList == 5 then break end end this.RefreshDesc() end) --筛选按钮 for i = 0, 5 do Util.AddClick(tabs[i], function() if i == proId then proId=ProIdConst.All else proId=i end this.OnClickTabBtn(proId) end) end --品阶等级筛选 Util.AddClick(this.ShaiXuanBtn, function() if sortType == SortTypeConst.Lv then sortType = SortTypeConst.Natural else sortType = SortTypeConst.Lv end this.ShaiXuanBtnLv:SetActive(sortType ~= SortTypeConst.Lv) this.ShaiXuanBtnQu:SetActive(sortType ~= SortTypeConst.Natural) this.OnClickTabBtn(proId) end) end function FormationEditPopup:AddListener() end function FormationEditPopup:RemoveListener() end function FormationEditPopup:OnOpen(...) local args={...} func=args[1] choosedList ={} order = 0--#curFormation.teamHeroInfos sortType = SortTypeConst.Lv proId = ProIdConst.All this.OnClickTabBtn(proId) this.ShaiXuanBtnLv:SetActive(sortType ~= SortTypeConst.Lv) this.ShaiXuanBtnQu:SetActive(sortType ~= SortTypeConst.Natural) end function FormationEditPopup:OnClose() end function FormationEditPopup:OnSortingOrderChange() this.ScrollView:ForeachItemGO(function(index, go) Util.SetParticleSortLayer(go,this.sortingOrder + 1) end) end function FormationEditPopup:OnDestroy() this.spLoader:Destroy() this.ScrollView = nil end --点击页签__根据sortType和职业属性/类型进行排序 function this.OnClickTabBtn(_proId) local heros this.selectBtn:SetActive(proId ==_proId) this.selectBtn.transform:SetParent(tabs[_proId].transform) this.selectBtn.transform:DOAnchorPos(Vector3.zero,0) this.selectBtn.transform:DOScale(Vector3.one,0) if _proId == ProIdConst.All then heros = HeroManager.GetAllHeroDatas(_LimitLevel) else heros = HeroManager.GetHeroDataByProperty(_proId, _LimitLevel) end this.SetRoleList(heros) this.RefreshDesc() end --设置英雄列表数据 function this.SetRoleList(_roleDatas) this:SortHeroDatas(_roleDatas) goList={} this.ScrollView:SetData(_roleDatas, function(index, go) this.SingleHeroDataShow(go, _roleDatas[index]) end) end --设置单个英雄数据 function this.SingleHeroDataShow(_go, _heroData) local heroData = _heroData local go = _go goList[heroData.dynamicId]=go local choosed = Util.GetGameObject(go, "choosed") choosed:SetActive(false) for i,v in ipairs(choosedList) do if(heroData.dynamicId==v.did) then choosed:SetActive(true) end end Util.GetGameObject(go, "frame"):GetComponent("Image").sprite = this.spLoader:LoadSprite(GetHeroQuantityImageByquality(heroData.heroConfig.Quality,heroData.star)) Util.GetGameObject(go, "icon"):GetComponent("Image").sprite = this.spLoader:LoadSprite(heroData.icon) Util.GetGameObject(go, "lv/Text"):GetComponent("Text").text = heroData.lv Util.GetGameObject(go, "icon"):GetComponent("Image").sprite = this.spLoader:LoadSprite(heroData.icon) Util.GetGameObject(go, "proIcon"):GetComponent("Image").sprite = this.spLoader:LoadSprite(GetProStrImageByProNum(heroData.changeProId)) --剩余血量 无尽副本才显示 local hpExp = Util.GetGameObject(go, "hpExp") local heroHp = FormationManager.GetFormationHeroHp(curFormationIndex, heroData.dynamicId) local starGrid = Util.GetGameObject(go, "star") local starPre = Util.GetGameObject(go, "starPre") local star,starType = heroData.GetStar(1) SetHeroStars(this.spLoader, starGrid, star,starType) local effect=SetHeroFlyEffect(Util.GetGameObject(go, "GameObject"),this.spLoader,heroData.star,this.sortingOrder + 1,1,3) if effect then local particles=effect:GetComponentsInChildren(typeof(UnityEngine.ParticleSystem)) for key, value in pairs(particles:ToTable()) do local mat=value:GetComponent(typeof(UnityEngine.Renderer)) if mat.material.shader.name=="YXZ/Effect/Mix Masking(Without Moving)_alphablend" then mat.material.shader=poolManager:LoadAsset("YXZ_MixMaskingWithoutMoving_alphablend_1",poolManager.AssetType.Other) end end end local meshs1=starGrid:GetComponentsInChildren(typeof(UnityEngine.ParticleSystem)) for key, value in pairs(meshs1:ToTable()) do local mat=value:GetComponent(typeof(UnityEngine.Renderer)) if mat.material.shader.name=="UI Particles/Additive" then mat.material.shader=poolManager:LoadAsset("UI-Particle-Add_1",poolManager.AssetType.Other) end end Util.SetParticleSortLayer(starGrid,this.sortingOrder + 1) this.SetHeroBlood(hpExp, heroHp, go) -- Click On Util.AddOnceClick(go, function() -- if heroData.changeProId==5 then -- PopupTipPanel.ShowTip("神系必须转换其他阵营才能上阵") -- return -- end for k, v in ipairs(choosedList) do if v.did == heroData.dynamicId then --选择的条目已存在,移除选择的item choosed:SetActive(false) table.remove(choosedList,k) order=order-1 chooseIndex=v.position for i,v in ipairs(choosedList) do if(choosedList[i].position>chooseIndex) then choosedList[i].position=v.position-1 end end this.RefreshDesc() return end end -- 当前可选的最大上阵人数 if #choosedList >= maxNum then PopupTipPanel.ShowTip(Language[10673]) return end -- 判断是否有血量 if heroHp and heroHp <= 0 then PopupTipPanel.ShowTip(Language[10674]) return end choosed:SetActive(true) order=order+1 table.insert(choosedList, {did = heroData.dynamicId, choosed = choosed, position=order}) choosedList[heroData.dynamicId] = choosed this.RefreshDesc() end) Util.AddLongPressClick(go, function() UIManager.OpenPanel(UIName.RoleInfoPopup, heroData) end, 0.5) end --刷新描述信息 function this.RefreshDesc() this.desc.text=string.format(Language[10675],maxNum,#choosedList,maxNum) end -- 设置妖灵师血量 function this.SetHeroBlood(hpExp, heroHp, go) if heroHp then hpExp:SetActive(true) hpExp:GetComponent("Slider").value = heroHp Util.SetGray(go, heroHp <= 0) else hpExp:SetActive(false) end end function this:SortHeroDatas(_heroDatas) local choosed = {} local dieHeros = {} -- local curFormation = FormationManager.GetFormationByID(curFormationIndex) for i = 1, #_heroDatas do local heroHp = FormationManager.GetFormationHeroHp(curFormationIndex, _heroDatas[i].dynamicId) if heroHp then if heroHp <= 0 then dieHeros[_heroDatas[i].dynamicId] = _heroDatas[i].dynamicId end end end -- for j = 1, #curFormation.teamHeroInfos do -- local teamInfo = curFormation.teamHeroInfos[j] -- choosed[teamInfo.heroId] = j -- end table.sort(_heroDatas, function(a, b) if (choosed[a.dynamicId] and choosed[b.dynamicId]) or (not choosed[a.dynamicId] and not choosed[b.dynamicId]) then if (dieHeros[a.dynamicId] and dieHeros[b.dynamicId]) or (not dieHeros[a.dynamicId] and not dieHeros[b.dynamicId]) then if sortType == SortTypeConst.Natural then if a.heroConfig.Natural == b.heroConfig.Natural then if a.heroConfig.Quality == b.heroConfig.Quality then if a.star == b.star then if a.lv == b.lv then if a.id == b.id then return a.sortId > b.sortId else return a.id > b.id end else return a.lv > b.lv end else return a.star > b.star end else return a.heroConfig.Quality > b.heroConfig.Quality end else return a.heroConfig.Natural > b.heroConfig.Natural end else if a.lv == b.lv then if a.heroConfig.Quality == b.heroConfig.Quality then if a.star == b.star then if a.heroConfig.Natural == b.heroConfig.Natural then if a.id == b.id then return a.sortId > b.sortId else return a.id > b.id end else return a.heroConfig.Natural > b.heroConfig.Natural end else return a.star > b.star end else return a.heroConfig.Quality > b.heroConfig.Quality end else return a.lv > b.lv end end else return not dieHeros[a.dynamicId] and dieHeros[b.dynamicId] end else return choosed[a.dynamicId] and not choosed[b.dynamicId] end end) end function this.OnClickEnterHeroInfo(_curhero, _heros) UIManager.OpenPanel(UIName.RoleInfoPanel, _curhero, _heros) end return FormationEditPopup