require("Base/BasePanel") local WorldArenaBattleInfoPanel = Inherit(BasePanel) 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 function OnBeginDrag(self, Pointgo, data) if state~=1 then return end local num=999 for i = 1, 3 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, 3 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 --如果滑动距离太短,阵容放回原来的地方 LogError(" num=="..num) if num>100 then LogError("**********") 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 LogError("targetInfo==nil") 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) LogError("起始id=="..currIndex.." 终点id=="..targetIndex) --发送协议保存队伍 if currIndex ~= targetIndex then -- 交换编队数据 local tempFormation = self.curFormation[2000 + currIndex] self.curFormation[2000 + currIndex] = self.curFormation[2000 + targetIndex] self.curFormation[2000 + targetIndex] = tempFormation -- 保存 for i = 1, 3 do local heros = {} for _, hero in ipairs(self.curFormation[i+2000].teamHeroInfos) do table.insert(heros, {heroId = hero.heroId, position = hero.position}) end FormationManager.SaveFormation(i+2000, heros, FormationManager.formationList[2001].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) 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() end function this:OnSortingOrderChange() if myHeadObj then myHeadObj:SetLayer(self.sortingOrder) end Util.SetParticleSortLayer(this.effect, self.sortingOrder+10) end --刷新战斗消耗信息 function this.RefreshBattleCastInfo() 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 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) 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 isAnim then return end if myHeroNum==0 then PopupTipPanel.ShowTip("编队为空,无法挑战") return end if type~=1 then self:ClosePanel() return end local list={2001,2002,2003} local num=PrivilegeManager.GetPrivilegeRemainValue(0) local costType=0 if num>0 then costType=0 else costType=1 end if costType==1 then local itemId, needNum = WorldArenaManager.GetArenaChallengeCost() local haveNum = BagManager.GetItemCountById(itemId) if haveNum < needNum then --UIManager.OpenPanel(UIName.QuickPurchasePanel, { type = UpViewRechargeType.yuxulundaoTicket }) PopupTipPanel.ShowTip("邀请函不足!") return end end NetManager.CrossYuXuLunDaoChallengeRequest(list,enemyId,costType,function(msg) resultList=msg.fightResult fightDataList=msg.fightData isAnim = true self:PlayFightAnim(this.leftTeam, this.rightTeam, 3, function(index) this.ShowBattleState(index,3) this.playBacks[index]:SetActive(true) if index >= 3 then isAnim = false state = 3 type = 2 this.btnItem.gameObject:SetActive(false) this.btnText.gameObject:SetActive(true) this.btnText.text="确定" end end) this.myScore.gameObject:SetActive(true) this.enScore.gameObject:SetActive(true) this.myScore.text= msg.myScore>0 and "积分+"..msg.myScore or "积分"..msg.myScore this.myScore.color = msg.myScore>0 and UIColor.GREEN or UIColor.RED this.enScore.text= msg.defScore>0 and "积分+"..msg.defScore or "积分"..msg.defScore this.enScore.color = msg.defScore>0 and UIColor.GREEN or UIColor.RED WorldArenaManager.SetNewScore(msg.myNewScore) WorldArenaManager.SetMyData(msg.myRank,WorldArenaManager.GetchallengeTimes()+1) LogError("myscore=="..msg.myScore.."defScore=="..msg.defScore.." rank=="..msg.myRank.." challengetime=="..msg.changedTimes.." myNewScore=="..msg.myNewScore) --添加奖励 -- if msg.drop then LogError("掉落物品数量:"..#msg.drop) WorldArenaManager.AddReward(msg.drop) end if num>0 then PrivilegeManager.RefreshPrivilegeUsedTimes(2028, 1) end end) end) --回放按钮点击事件 for i = 1, #this.playBacks do Util.AddClick(this.playBacks[i],function() if not leftAllTeam[i] or not rightAllTeam[i] or #leftAllTeam[i]==0 or #rightAllTeam[i]==0 then PopupTipPanel.ShowTip("本场战斗无法回放!") return end local nameStr = myInfoData.name.."|"..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 = myInfoData.name arg.blue.head = myInfoData.head arg.blue.frame = myInfoData.headFrame arg.blue.deltaScore = myInfoData.myScoreChange arg.red= {} arg.red.uid = enInfoData.uid arg.red.name = enInfoData.name arg.red.head = enInfoData.head arg.red.frame = enInfoData.headFrame 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,closeFunc,list) -- 请求数据 -- ArenaManager.RequestArenaRecord() 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 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) elseif state==3 then this.myScore.gameObject:SetActive(true) this.enScore.gameObject:SetActive(true) for i = 1, 3 do this.playBacks[i]:SetActive(true) this.ShowBattleState(i,3) end end this.ShowInfo(msg) this.RefreshBattleCastInfo() self.curFormation = {} for i = 1, 3 do local team=FormationManager.GetFormationByID(i+2000) local cTeam = FormationManager.MakeAEmptyTeam(i+2000) for j = 1, #team.teamHeroInfos do table.insert(cTeam.teamHeroInfos, team.teamHeroInfos[j]) end self.curFormation[i+2000] = cTeam end end function this.ShowInfo(msg) --我的信息 myInfoData=msg.myTeamInfo enInfoData=msg.defTeamInfo if msg.fightData then fightDataList=msg.fightData end this.myName.text= PracticeManager.SetNameColor(msg.myTeamInfo.serverName.." "..PlayerManager.nickName,msg.myTeamInfo.practiceLevel) this.myServer.gameObject:SetActive(false) this.myRankImg.sprite=this.spLoader:LoadSprite("y_yuxulundao_xiaobiao_0"..1) if not myHeadObj then myHeadObj = SubUIManager.Open(SubUIConfig.PlayerHeadView, this.myHeadPar.transform) end myHeadObj:Reset() myHeadObj:SetScale(Vector3.one * 0.7) myHeadObj:SetHead(msg.myTeamInfo.head) myHeadObj:SetFrame(msg.myTeamInfo.headFrame) myHeadObj:SetLevel(msg.myTeamInfo.level) myHeadObj:SetLayer(this.sortingOrder) myHeadObj:SetEffectScale(0.7) --敌人信息 this.rightName.text= PracticeManager.SetNameColor(msg.defTeamInfo.serverName.." "..msg.defTeamInfo.name,msg.defTeamInfo.practiceLevel) this.rightServer.gameObject:SetActive(false) local enRank=WorldArenaManager.GetRankImgByScore(msg.defTeamInfo.crossTeamScore) this.enRankImg.sprite=this.spLoader:LoadSprite("y_yuxulundao_xiaobiao_0"..enRank) if not enHeadObj then enHeadObj = SubUIManager.Open(SubUIConfig.PlayerHeadView, this.enHeadPar.transform) end enHeadObj:Reset() enHeadObj:SetScale(Vector3.one * 0.7) enHeadObj:SetHead(msg.defTeamInfo.head) enHeadObj:SetFrame(msg.defTeamInfo.headFrame) enHeadObj:SetLevel(msg.defTeamInfo.level) enHeadObj:SetLayer(this.sortingOrder) enHeadObj:SetEffectScale(0.7) enemyId=msg.defTeamInfo.uid for i = 1, 3 do if state==1 then this.playBacks[i]:SetActive(false) elseif state==3 then this.playBacks[i]:SetActive(true) end end if state==3 then this.myScore.text= msg.myScore>0 and "积分+"..msg.myScore or "积分"..msg.myScore this.myScore.color = msg.myScore>0 and UIColor.GREEN or UIColor.RED this.enScore.text= msg.defScore>0 and "积分+"..msg.defScore or "积分"..msg.defScore this.enScore.color = msg.defScore>0 and UIColor.GREEN or UIColor.RED 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 --end end --编队信息 local allTeams={} function this.SetTeamInfo(_go,teamData,type) for index = 1, 3 do local go = Util.GetGameObject(_go,"defendbox"..index) local data = teamData[index] local fightTxt=Util.GetGameObject(go,"WarPower/Text"):GetComponent("Text") local teamList ={} for i = 1, 6 do local aa=Util.GetGameObject(go,"Demons/heroPro ("..i..")") table.insert(teamList,aa) end for i, demon in ipairs(teamList) do Util.GetGameObject(demon, "frame"):GetComponent("Image").sprite = this.spLoader:LoadSprite(GetQuantityImageByquality(1)) Util.GetGameObject(demon, "pos"):GetComponent("Image").sprite=this.spLoader:LoadSprite("bd_xinkapaifan"..i) Util.GetGameObject(demon, "hero"):SetActive(false) end --队伍阵容 local heroList={} for i, hero in ipairs(data.team) do local heroTid = data.team[i].heroTid if heroTid then local heroGo = Util.GetGameObject(teamList[hero.position], "hero") heroGo:SetActive(true) Util.GetGameObject(heroGo, "starGrid").transform.localScale=Vector3.one*0.7 SetHeroStars(this.spLoader, Util.GetGameObject(heroGo, "starGrid"), hero.star,nil,nil,-15) local heroConfig = ConfigManager.GetConfigData(ConfigName.HeroConfig, heroTid) Util.GetGameObject(heroGo, "proIcon"):GetComponent("Image").sprite = this.spLoader:LoadSprite(GetProStrImageByProNum(heroConfig.PropertyName)) Util.GetGameObject(heroGo, "lvbg/levelText"):GetComponent("Text").text = hero.level Util.GetGameObject(teamList[hero.position], "frame"):GetComponent("Image").sprite = this.spLoader:LoadSprite(GetQuantityImageByquality(heroConfig.Quality, hero.star)) SetHeroIcon(this.spLoader, hero,Util.GetGameObject(heroGo, "icon"):GetComponent("Image"),heroConfig) local frameBtn = Util.GetGameObject(teamList[hero.position], "frame") --local heroData = {} -- Util.AddOnceClick(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 -- 执行关闭方法 if _CloseFunc then -- 如果是挑战完成了,返回就刷新挑战列表 if state == 3 then _CloseFunc() end _CloseFunc = nil end -- 重置状态 --state = 1 isAnim = false end --界面销毁时调用(用于子类重写) function WorldArenaBattleInfoPanel:OnDestroy() this.spLoader:Destroy() leftAllTeam={} rightAllTeam={} -- 头像 if myHeadObj then myHeadObj:Recycle() myHeadObj = nil end if enHeadObj then enHeadObj:Recycle() enHeadObj = nil end resultList=nil fightDataList=nil if this.TimeCounter then this.TimeCounter:Stop() this.TimeCounter = nil end myHeroNum=0 state=1 end return WorldArenaBattleInfoPanel