miduo_client/Assets/ManagedResources/~Lua/Modules/WorldArena/WorldArenaBattleInfoPanel.lua

450 lines
19 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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 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)
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.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
end
--刷新战斗消耗信息
function this.RefreshBattleCastInfo()
local leftTimes = WorldArenaManager.GetArenaChallengeTimes()
LogError("lefttime=="..leftTimes)
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:BindEvent()
Util.AddClick(this.btn_close, function()
self:ClosePanel()
end)
Util.AddClick(this.btn_fight, function()
if type~=1 then
self:ClosePanel()
return
end
local list={2001,2002,2003}
NetManager.CrossYuXuLunDaoChallengeRequest(list,enemyId,1,function(msg)
LogError("战斗结束")
resultList=msg.fightResult
fightDataList=msg.fightData
LogError("myscore=="..msg.myScore.."defScore=="..msg.defScore)
-- for i = 1, #this.playBacks do
-- this.playBacks[i]:SetActive(true)
-- end
--播放打的动画
if this.TimeCounter then
this.TimeCounter=nil
end
local currIndex=1
local _TimeUpdate=function()
this.rightTeam[currIndex]:GetComponent("RectTransform").anchoredPosition=Vector3.New(101,this.rightTeam[currIndex]:GetComponent("RectTransform").anchoredPosition.y,0)
this.leftTeam[currIndex]:GetComponent("RectTransform").anchoredPosition=Vector3.New(278,this.leftTeam[currIndex]:GetComponent("RectTransform").anchoredPosition.y,0)
LogError("left pos.x=="..this.leftTeam[currIndex].transform.localPosition.x)
LogError("right pos.x=="..this.rightTeam[currIndex].transform.localPosition.x)
this.playBacks[currIndex]:SetActive(true)
this.ShowBattleState(currIndex,3)
this.leftTeam[currIndex]:GetComponent("RectTransform").anchoredPosition=Vector3.New(192,this.leftTeam[currIndex]:GetComponent("RectTransform").anchoredPosition.y,0)
this.rightTeam[currIndex]:GetComponent("RectTransform").anchoredPosition=Vector3.New(192,this.rightTeam[currIndex]:GetComponent("RectTransform").anchoredPosition.y,0)
LogError("left pos.x=="..this.leftTeam[currIndex].transform.localPosition.x)
LogError("right pos.x=="..this.rightTeam[currIndex].transform.localPosition.x)
LogError("--------------")
currIndex=currIndex+1
if this.TimeCounter and currIndex>3 then
this.TimeCounter:Stop()
this.TimeCounter = nil
end
end
this.TimeCounter = Timer.New(_TimeUpdate,1.5, -1, true)
this.TimeCounter:Start()
end)
end)
--回放按钮点击事件
for i = 1, #this.playBacks do
Util.AddClick(this.playBacks[i],function()
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.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)
-- 请求数据
-- ArenaManager.RequestArenaRecord()
type=_type
-- 刷新显示
-- this.RefreshRecordList()
if state==1 then
for i = 1, 3 do
this.playBacks[i]:SetActive(false)
end
end
if type==1 then
this.titleTxt.text="挑战"
this.btnText.text="免费挑战"
else
this.titleTxt.text="回放"
this.btnText.text="确定"
end
this.ShowInfo(msg)
this.RefreshBattleCastInfo()
end
function this.ShowInfo(msg)
--我的信息
myInfoData=msg.myTeamInfo
enInfoData=msg.defTeamInfo
this.myName.text= PracticeManager.SetNameColor(JingJiShouWeiToEn(PlayerManager.nickName),msg.myTeamInfo.practiceLevel)
this.myServer.text= PracticeManager.SetNameColor(PlayerManager.serverInfo.name,1)
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.name,msg.defTeamInfo.practiceLevel)
this.rightServer.text= PracticeManager.SetNameColor(msg.defTeamInfo.serverName,1)
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
LogError("myteam len=="..#msg.myTeamInfo.crossTeam[1].team)
this.SetTeamInfo(this.myTeamInfo,msg.myTeamInfo.crossTeam,1)
this.SetTeamInfo(this.enTeamInfo,msg.defTeamInfo.crossTeam)
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 title = Util.GetGameObject(go,"Title"):GetComponent("Text")
local teamList ={}
for i = 1, 6 do
local aa=Util.GetGameObject(go,"Demons/heroPro ("..i..")")
table.insert(teamList,aa)
end
--title.text = string.format( "第%s队",NumToChinese[index])
--self:SetImgPos(go,data.totalForce)
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 and type==1 then
table.insert(heroList,{heroId=heroTid,position=hero.position})
end
end
end
if type and type==1 then
allTeams[index]=heroList
end
end
end
function this:OnClose()
if this.TimeCounter then
this.TimeCounter:Stop()
this.TimeCounter = nil
end
end
--界面销毁时调用(用于子类重写)
function WorldArenaBattleInfoPanel:OnDestroy()
this.spLoader:Destroy()
-- 头像
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
end
return WorldArenaBattleInfoPanel