require("Base/BasePanel") local WorldArenaBattleInfoPanel = Inherit(BasePanel) local endLess=ConfigManager.GetConfig(ConfigName.EndlessHeroProp) local this = WorldArenaBattleInfoPanel local state=1 -- 1:开战前 2.:开战中 3:开战后 local myHeadObj=nil local enHeadObj=nil local resultList={} local fightDataList={} local type=0 local enemyId=0 local myInfoData=nil local enInfoData=nil local targetIndex=0 local currIndex=0 local myHeroNum=0 local isAnim = false local _CloseFunc = nil local leftAllTeam={} local rightAllTeam={} local allMyHeros={} local isSame=false local curType=0 local teamLen=0 local floor local function OnBeginDrag(self, Pointgo, data) if state~=1 then return end local num=999 for i = 1, #GodsWayTeam[curType] do local dis = math.abs(Pointgo.transform.parent.parent.localPosition.y - this.leftTeam[i].transform.localPosition.y ) if dis <= num then num = dis currIndex=i end end self.oldGrid = Pointgo.transform.parent.parent self.tempInfo.transform.localPosition = Pointgo.transform.parent.parent.localPosition Pointgo.transform.parent:SetParent(self.tempInfo.transform) Pointgo.transform.parent.localPosition = Vector3.zero end local function OnDrag(self, Pointgo, data) if state~=1 then return end local pos = self.tempInfo.transform.localPosition local y = pos.y + data.delta.y >= -400 and pos.y + data.delta.y or -400 y = y <= 450 and y or 450 self.tempInfo.transform.localPosition = Vector2.New(pos.x , y) end local function OnEndDrag(self, Pointgo, data) if state~=1 then return end --Pointgo.transform.parent.localPosition = Vector3.zero local num = 999 local obj = nil for i = 1, #GodsWayTeam[curType] do local dis = math.abs( self.tempInfo.transform.localPosition.y - this.leftTeam[i].transform.localPosition.y ) --LogError(" temp y=="..self.tempInfo.transform.localPosition.y.." leftteam y=="..this.leftTeam[i].transform.localPosition.y) if dis <= num then num = dis obj = this.leftTeam[i] targetIndex=i end end --如果滑动距离太短,阵容放回原来的地方 if num>100 then local target=Util.GetGameObject(self.tempInfo.transform, "Demons") target.transform:SetParent(self.oldGrid.transform) target.transform:SetSiblingIndex(1) target.transform.localPosition=Vector3.New(0,-67,0) return end if obj.transform.childCount > 0 then local targetInfo=Util.GetGameObject(obj.transform, "Demons") if targetInfo then targetInfo.transform:SetParent(self.oldGrid.transform) targetInfo.transform:SetSiblingIndex(1) targetInfo.transform.localPosition=Vector3.New(0,-67,0) else local target=Util.GetGameObject(self.tempInfo.transform, "Demons") target.transform:SetParent(self.oldGrid.transform) target.transform:SetSiblingIndex(1) target.transform.localPosition=Vector3.New(0,-67,0) return end else obj = self.oldGrid end --local curInfo = self.tempInfo.transform:GetChild(0) local curInfo =Util.GetGameObject(self.tempInfo.transform, "Demons").transform curInfo:SetParent(obj.transform) curInfo.transform:SetSiblingIndex(1) curInfo.localPosition = Vector3.New(0,-67,0) --发送协议保存队伍 if currIndex ~= targetIndex then -- 交换编队数据 local tempFormation = self.curFormation[GodsWayTeam[curType][currIndex]] self.curFormation[GodsWayTeam[curType][currIndex]] = self.curFormation[GodsWayTeam[curType][targetIndex]] self.curFormation[GodsWayTeam[curType][targetIndex]] = tempFormation -- 保存 local upHeros={} for i = 1, #GodsWayTeam[curType] do local heros = {} for _, hero in ipairs(self.curFormation[GodsWayTeam[curType][i]].teamHeroInfos) do if BattleUtil.ChecklistIsContainValue(upHeros,hero.heroId) then PopupTipPanel.ShowTip("编队中有相同英雄!!") return else table.insert(upHeros,hero.heroId) end table.insert(heros, {heroId = hero.heroId, position = hero.position}) end FormationManager.SaveFormation(GodsWayTeam[curType][i], heros, FormationManager.formationList[GodsWayTeam[curType][1]].teamPokemonInfos) end local teampos={} teampos=leftAllTeam[currIndex] leftAllTeam[currIndex]=leftAllTeam[targetIndex] leftAllTeam[targetIndex]=teampos end end --初始化组件(用于子类重写) function WorldArenaBattleInfoPanel:InitComponent() this.spLoader = SpriteLoader.New() this.btn_close=Util.GetGameObject(self.transform, "BG/BackBtn") this.btn_fight=Util.GetGameObject(self.transform, "BG/btn_fight") this.myName=Util.GetGameObject(self.transform, "BG/info/name"):GetComponent("Text") this.rightName=Util.GetGameObject(self.transform, "BG/rightInfo/name"):GetComponent("Text") this.myServer=Util.GetGameObject(self.transform, "BG/info/profess"):GetComponent("Text") this.rightServer=Util.GetGameObject(self.transform, "BG/rightInfo/profess"):GetComponent("Text") this.myHeadPar=Util.GetGameObject(self.transform, "BG/info/head") this.enHeadPar=Util.GetGameObject(self.transform, "BG/rightInfo/head") this.myRankImg=Util.GetGameObject(self.transform, "BG/info/Image"):GetComponent("Image") this.enRankImg=Util.GetGameObject(self.transform, "BG/rightInfo/Image"):GetComponent("Image") this.myScore=Util.GetGameObject(self.transform, "BG/info/Text"):GetComponent("Text") this.enScore=Util.GetGameObject(self.transform, "BG/rightInfo/Text"):GetComponent("Text") this.titleTxt=Util.GetGameObject(self.transform, "BG/title"):GetComponent("Text") this.myTeamInfo=Util.GetGameObject(self.transform, "BG/myInfo") this.enTeamInfo=Util.GetGameObject(self.transform, "BG/enInfo") this.effect=Util.GetGameObject(self.transform, "BG/Effect") this.effect:SetActive(false) this.hintTxt=Util.GetGameObject(self.transform, "BG/hintTxt"):GetComponent("Text") screenAdapte(this.effect) --我方阵营 this.leftTeam={} --第一局胜利图标 this.myResult={} this.InfoList = {} this.dragViewList = {} this.triggerList = {} self.tempInfo=Util.GetGameObject(self.transform, "BG/myInfo/teamInfo") this.OnBeginDrag = function(p,d) OnBeginDrag(self,p,d) end this.OnDrag= function(p,d) OnDrag(self,p,d) end this.OnEndDrag= function(p,d) OnEndDrag(self,p,d) end for i = 1, 3 do table.insert(this.leftTeam,Util.GetGameObject(self.transform, "BG/myInfo/defendbox"..i)) table.insert(this.myResult,Util.GetGameObject(self.transform, "BG/myInfo/defendbox"..i.."/Image")) this.myResult[i]:SetActive(false) this.InfoList[i]=Util.GetGameObject(self.transform, "BG/myInfo/defendbox"..i.."/Demons") this.dragViewList[i] = SubUIManager.Open(SubUIConfig.DragView, this.InfoList[i].transform) this.dragViewList[i].transform:SetSiblingIndex(6) this.triggerList[i]=Util.GetEventTriggerListener(this.dragViewList[i].gameObject) this.triggerList[i].onBeginDrag = this.triggerList[i].onBeginDrag + this.OnBeginDrag this.triggerList[i].onDrag = this.triggerList[i].onDrag + this.OnDrag this.triggerList[i].onEndDrag = this.triggerList[i].onEndDrag + this.OnEndDrag end this.rightTeam={} this.enResult={} for i = 1, 3 do table.insert(this.rightTeam,Util.GetGameObject(self.transform, "BG/enInfo/defendbox"..i)) table.insert(this.enResult,Util.GetGameObject(self.transform, "BG/enInfo/defendbox"..i .."/Image")) this.enResult[i]:SetActive(false) end --回放按钮集合 this.playBacks={} for i = 1, 3 do table.insert(this.playBacks,Util.GetGameObject(self.transform, "BG/playBacks/Image"..i)) end this.btnText = Util.GetGameObject(self.transform, "BG/btn_fight/Text"):GetComponent("Text") this.btnItem = Util.GetGameObject(self.transform, "BG/btn_fight/Image"):GetComponent("Image") this.btnItemNum = Util.GetGameObject(self.transform, "BG/btn_fight/Image/numText"):GetComponent("Text") this.RefreshBattleCastInfo() this.teamNames={} for i=1,3 do table.insert(this.teamNames, Util.GetGameObject(self.transform, "BG/Text ("..i..")")) end end function this:OnSortingOrderChange() if myHeadObj then myHeadObj:SetLayer(self.sortingOrder) end Util.SetParticleSortLayer(this.effect, self.sortingOrder+10) end --刷新战斗消耗信息 function this.RefreshBattleCastInfo() -- if type==1 then -- local leftTimes = WorldArenaManager.GetFreeTime() -- this.btnText.gameObject:SetActive(leftTimes > 0) -- this.btnItem.gameObject:SetActive(leftTimes<=0) -- this.btnItemNum.gameObject:SetActive(leftTimes<=0) -- if leftTimes<=0 then -- local itemId, needNum = WorldArenaManager.GetArenaChallengeCost() -- local haveNum = BagManager.GetItemCountById(itemId) -- this.btnItem.sprite = SetIcon(this.spLoader, itemId) -- this.btnItemNum.text = "×"..needNum -- this.btnItemNum.color = haveNum < needNum and UIColor.NOT_ENOUGH_RED or UIColor.BTN_TEXT -- end -- else this.btnText.gameObject:SetActive(true) this.btnItem.gameObject:SetActive(false) --end end function WorldArenaBattleInfoPanel:PlayFightAnim(leftList, rightList, num, func) coroutine.start(function() for i = 1, num do leftList[i].transform:DOLocalMoveX(90, 0.2, false):OnComplete(function() leftList[i].transform:DOLocalMoveX(10, 0.3, false):OnComplete(function() if func then func(i) end end) end) SoundManager.PlaySound(SoundConfig.Audio_c_skr_0028_skeff_slidesk_attacked) this.effect:SetActive(true) rightList[i].transform:DOLocalMoveX(-80, 0.2, false):OnComplete(function() rightList[i].transform:DOLocalMoveX(10, 0.3, false) end) coroutine.wait(0.5) this.effect:SetActive(false) end end) end --绑定事件(用于子类重写) function WorldArenaBattleInfoPanel:BindEvent() Util.AddClick(this.btn_close, function() if state==2 then return end if not isAnim then self:ClosePanel() end end) Util.AddClick(this.btn_fight, function() if not ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.GodsWayTower_1) then PopupTipPanel.ShowTip(Language[10075]) return end if type~=1 then self:ClosePanel() return end -- 动画中不能再执行 state=2 if isAnim then LogError("正在播放动画") return end if myHeroNum==0 then PopupTipPanel.ShowTip("编队为空,无法挑战") return end if isSame then PopupTipPanel.ShowTip("检测到多个阵容使用相同英雄,无法开战") return end floor=GodsWayTowerManager.GetTowerFloorByType(curType) NetManager.RequestDuoDuiChallenge(curType,floor+1,1,function(msg) resultList=msg.result fightDataList=msg.data isAnim = true self:PlayFightAnim(this.leftTeam, this.rightTeam, teamLen, function(index) this.ShowBattleState(index,3) state=2 this.playBacks[index]:SetActive(true) if index >= #GodsWayTeam[curType] then isAnim = false state = 3 type = 2 this.btnItem.gameObject:SetActive(false) this.btnText.gameObject:SetActive(true) this.btnText.text="确定" local winNum=0 for i = 1, #resultList do if resultList[i]==1 then winNum=winNum+1 end end LogError("winnum==="..winNum) local isWin=false if curType==1 then isWin=winNum==2 elseif curType==2 then isWin=winNum==3 end if isWin then GodsWayTowerManager.SetTowerFloorByType(curType,1) UIManager.OpenPanel(UIName.RewardItemPopup,msg.drop,1) Game.GlobalEvent:DispatchEvent(GameEvent.FourEle.RefreshView) else UIManager.OpenPanel(UIName.BattleFailPopup, nil, true, nil, BATTLE_TYPE.GodsWayTower) end end end) end) end) --回放按钮点击事件 for i = 1, #this.playBacks do Util.AddClick(this.playBacks[i],function() if state==2 then return end if not leftAllTeam[i] or not rightAllTeam[i] or #leftAllTeam[i]==0 or #rightAllTeam[i]==0 then PopupTipPanel.ShowTip("本场战斗无法回放!") return end --LogError("myInfoData.name=="..myInfoData.name) local nameStr = "1111".."|".."enInfoData.name" local realResult = resultList[i] --(resultList[i] + 1) % 2 -- 服务器返回的是我的结果,转换为真实结果 this.RequestReplayRecord(realResult,fightDataList[i], nameStr,function() --this:ClosePanel() --构建显示结果数据(我永远在蓝方) local arg = {} arg.panelType=1 arg.result = realResult arg.blue = {} arg.blue.uid = myInfoData.uid arg.blue.name =PracticeManager.SetNameColor(NameManager.roleName,PracticeManager.PracticeLevel) --myInfoData.name arg.blue.head = PlayerManager.head arg.blue.frame = HeadManager.GetCurFrameId() --arg.blue.deltaScore = myInfoData.myScoreChange arg.red= {} arg.red.uid = enInfoData.uid local enemyFloor=floor+1 arg.red.name =PracticeManager.SetNameColor("第"..enemyFloor.."层",1)--enInfoData.name local towerConfig=ConfigManager.TryGetConfigDataByThreeKey(ConfigName.DuoDuiTower,"Type",curType,"TowerNumber",enemyFloor,"TowerWave1",i) local enemeyHead=PlayerManager.head if towerConfig then local id=towerConfig.Hero[5] local heroConfig=ConfigManager.GetConfigData(ConfigName.DuoDuiTowerHero,id) if heroConfig then enemeyHead=heroConfig.Hero end end arg.red.head = enemeyHead arg.red.frame = HeadManager.GetCurFrameId() --arg.red.deltaScore = enInfoData.myScoreChange UIManager.OpenPanel(UIName.ArenaResultPopup, arg) end) end) end end function this.RequestReplayRecord(isWin, fightData, nameStr, doneFunc,battle_type) local fightData = BattleManager.GetBattleServerData({fightData = fightData}, 1) local battlePanel = UIManager.OpenPanel(UIName.BattlePanel, fightData, battle_type and battle_type or BATTLE_TYPE.BACK, doneFunc) battlePanel:ShowNameShow(isWin, nameStr) end --添加事件监听(用于子类重写) function WorldArenaBattleInfoPanel:AddListener() -- Game.GlobalEvent:AddEvent(GameEvent.Arena.OnRecordDataChange, this.RefreshRecordList) end --移除事件监听(用于子类重写) function WorldArenaBattleInfoPanel:RemoveListener() -- Game.GlobalEvent:RemoveEvent(GameEvent.Arena.OnRecordDataChange, this.RefreshRecordList) end --界面打开时调用(用于子类重写) function WorldArenaBattleInfoPanel:OnOpen(msg,_type,_curType,closeFunc,list) -- 请求数据 -- ArenaManager.RequestArenaRecord() curType=_curType for i=1,#this.teamNames do if i<= #GodsWayTeam[curType] then this.teamNames[i]:SetActive(true) else this.teamNames[i]:SetActive(false) end end type=_type _CloseFunc = closeFunc -- 刷新显示 -- this.RefreshRecordList() if type==1 then this.titleTxt.text="挑战" this.btnText.text="挑战" else this.titleTxt.text="回放" this.btnText.text="确定" end --如果有结果list if list then state=3 resultList=list else state=1 end if state==1 then for i = 1, 3 do this.playBacks[i]:SetActive(false) this.ShowBattleState(i, state) end --this.myScore.gameObject:SetActive(false) --this.enScore.gameObject:SetActive(false) this.hintTxt.gameObject:SetActive(true) elseif state==3 then this.hintTxt.gameObject:SetActive(false) this.myScore.gameObject:SetActive(true) this.enScore.gameObject:SetActive(true) for i = 1, teamLen do this.playBacks[i]:SetActive(true) this.ShowBattleState(i,3) end end this.ShowInfo(msg) this.RefreshBattleCastInfo() teamLen=#GodsWayTeam[curType] self.curFormation = {} for i = 1, teamLen do local team=FormationManager.GetFormationByID(GodsWayTeam[curType][i]) local cTeam = FormationManager.MakeAEmptyTeam(GodsWayTeam[curType][i]) for j = 1, #team.teamHeroInfos do table.insert(cTeam.teamHeroInfos, team.teamHeroInfos[j]) end self.curFormation[GodsWayTeam[curType][i]] = cTeam end end function this.ShowInfo(msg) --我的信息 myInfoData=msg.myTeamInfo enInfoData=msg.defTeamInfo if msg.fightData then fightDataList=msg.fightData end for i = 1, #GodsWayTeam[curType] do if state==1 then this.playBacks[i]:SetActive(false) elseif state==3 then this.playBacks[i]:SetActive(true) end end this.SetTeamInfo(this.myTeamInfo,msg.myTeamInfo.crossTeam,1) this.SetTeamInfo(this.enTeamInfo,msg.defTeamInfo.crossTeam,2) end function this.ShowBattleState(index,state) --for i = 1, 3 do -- Util.GetGameObject(this.leftTeam[index], "Text").gameObject:SetActive(state~=3) -- Util.GetGameObject(this.rightTeam[index], "Text").gameObject:SetActive(state~=3) local leftImg=Util.GetGameObject(this.leftTeam[index], "Image"):GetComponent("Image") local rightImg=Util.GetGameObject(this.rightTeam[index], "Image"):GetComponent("Image") leftImg.gameObject:SetActive(state==3) rightImg.gameObject:SetActive(state==3) if state==3 then if resultList[index]==1 then leftImg.sprite=this.spLoader:LoadSprite("UI_effect_JJC_JieSuan_ShengLi_png_zh") rightImg.sprite=this.spLoader:LoadSprite("UI_effect_JJC_JieSuan_ShiBai_png_zh") else leftImg.sprite=this.spLoader:LoadSprite("UI_effect_JJC_JieSuan_ShiBai_png_zh") rightImg.sprite=this.spLoader:LoadSprite("UI_effect_JJC_JieSuan_ShengLi_png_zh") end end leftImg:GetComponent("PlayFlyAnim"):PlayAnim(true) rightImg:GetComponent("PlayFlyAnim"):PlayAnim(true) --end end --编队信息 local allTeams={} function this.SetTeamInfo(_go,teamData,type) LogError("type==="..type) for i = 1, 3 do Util.GetGameObject(_go,"defendbox"..i):SetActive(false) end for index = 1, #GodsWayTeam[curType] do local go = Util.GetGameObject(_go,"defendbox"..index) go:SetActive(true) local data = teamData[index] local fightTxt=Util.GetGameObject(go,"Demons/WarPower/Text"):GetComponent("Text") fightTxt.text=tostring(data.totalForce) local teamList ={} for i = 1, 6 do if not teamList[i] then teamList[i] = {} teamList[i].go = Util.GetGameObject(go,"Demons/heroPro ("..i..")") teamList[i].frameBtn = Util.GetGameObject(teamList[i].go, "frame") teamList[i].frame = teamList[i].frameBtn:GetComponent("Image") teamList[i].pos = Util.GetGameObject(teamList[i].go, "pos"):GetComponent("Image") teamList[i].hero = Util.GetGameObject(teamList[i].go, "hero") teamList[i].starGrid = Util.GetGameObject(teamList[i].hero, "starGrid") teamList[i].proIcon = Util.GetGameObject(teamList[i].hero, "proIcon"):GetComponent("Image") teamList[i].levelText = Util.GetGameObject(teamList[i].hero, "lvbg/levelText"):GetComponent("Text") teamList[i].icon = Util.GetGameObject(teamList[i].hero, "icon"):GetComponent("Image") end end for i, demon in ipairs(teamList) do demon.frame.sprite = this.spLoader:LoadSprite(GetQuantityImageByquality(1)) demon.pos:GetComponent("Image").sprite=this.spLoader:LoadSprite("bd_xinkapaifan"..i) demon.hero:SetActive(false) end --队伍阵容 local heroList={} for i, hero in ipairs(data.team) do local heroTid = data.team[i].heroTid if heroTid then teamList[hero.position].hero:SetActive(true) teamList[hero.position].starGrid.transform.localScale=Vector3.one*0.7 local star,starType = GetStarOrGodSoulLv(1,hero) --LogError("star=="..star.." startype=="..starType) local starScale = -15 local starSize = Vector2.New(32,32) if starType == 3 then starScale = -16 starSize = Vector2.New(0.8,-15) elseif starType == 2 then starSize = Vector2.New(48,48) end if type==1 and isSame==false then isSame=BattleUtil.ChecklistIsContainValue(allMyHeros,hero.heroid) if isSame==false then table.insert(allMyHeros,hero.heroid) end end SetHeroStars(this.spLoader, teamList[hero.position].starGrid, star,nil,nil,-10) Util.SetParticleSortLayer(teamList[hero.position].starGrid,this.sortingOrder + 1) local heroConfig = ConfigManager.GetConfigData(ConfigName.HeroConfig, heroTid) teamList[hero.position].proIcon.sprite = this.spLoader:LoadSprite(GetProStrImageByProNum(heroConfig.PropertyName)) teamList[hero.position].levelText.text =endLess[heroTid].Level or hero.level teamList[hero.position].frame.sprite = this.spLoader:LoadSprite(GetQuantityImageByquality(heroConfig.Quality, hero.star)) SetHeroIcon(this.spLoader, hero,teamList[hero.position].icon,heroConfig) SetHeroFlyEffect(teamList[hero.position].hero,this.spLoader,star,this.sortingOrder+1,0.6,2) --local heroData = {} -- Util.AddOnceClick(teamList[i].frameBtn, function() -- NetManager.ViewHeroInfoRequest(self.playerId,hero.heroid,1,PLAYER_INFO_VIEW_TYPE.NORMAL,function(msg) -- if not hero.heroid then -- return -- end -- heroData= GoodFriendManager.GetHeroDatas(msg.hero,msg.force,msg.SpecialEffects,msg.guildSkill) -- GoodFriendManager.InitEquipData(msg.equip,heroData) -- UIManager.OpenPanel(UIName.RoleInfoPopup, heroData,true) -- end) -- end) if type then table.insert(heroList,{heroId=heroTid,position=hero.position}) end end end if type==1 then allTeams[index]=heroList leftAllTeam[index]=heroList myHeroNum=myHeroNum+#heroList elseif type==2 then rightAllTeam[index]=heroList end end end function this:OnClose() if this.TimeCounter then this.TimeCounter:Stop() this.TimeCounter = nil end -- 执行关闭方法u if _CloseFunc then -- 如果是挑战完成了,返回就刷新挑战列表 if state == 3 then _CloseFunc() end _CloseFunc = nil end allMyHeros={} isSame=false -- 重置状态 --state = 1 isAnim = false end --界面销毁时调用(用于子类重写) function WorldArenaBattleInfoPanel:OnDestroy() this.spLoader:Destroy() leftAllTeam={} rightAllTeam={} allMyHeros={} isSame=false resultList=nil fightDataList=nil if this.TimeCounter then this.TimeCounter:Stop() this.TimeCounter = nil end myHeroNum=0 state=1 end return WorldArenaBattleInfoPanel