miduo_client/Assets/ManagedResources/~Lua/Modules/ArenaTopMatch/View/ATM_EliminationView.lua

374 lines
16 KiB
Lua

local ATM_EliminationView={}
local this=ATM_EliminationView
-- Tab管理器
local ArenaTopMatchPanel= require("Modules/ArenaTopMatch/ArenaTopMatchPanel")
local TabBox = require("Modules/Common/TabBox")
local _TabImgData = {select = "r_jingjichang_xiayeqian_01", default = "r_jingjichang_xiayeqian_02",}
local _TabFontColor = { default = Color.New(130 / 255, 128 / 255, 120 / 255, 1),
select = Color.New(243 / 255, 235 / 255, 202 / 255, 1) }
local _TabData = {
[1]= {txt = Language[10150]},
[2]= {txt = Language[10151]},
}
--玩家状态
local PlayerState={
None=-1,
Win=1,
Fail=0,
}
--小组偏移值
local GroupIndex=1
local GroupInfo={Language[10152],Language[10153],Language[10154],Language[10155]}
local battleStage=0
local battleTurn=0
local battleState=0
local _IsShowData = false
local CurTabIndex=1--当前选中页签
---淘汰赛
--初始化组件(用于子类重写)
function ATM_EliminationView:InitComponent()
this.panel=Util.GetGameObject(self.gameObject,"Panel")
this.middle=Util.GetGameObject(this.panel,"Middle")
this.thirtyTwoPre=Util.GetGameObject(this.middle,"ThirtyTwoPre")
this.groupInfo=Util.GetGameObject(this.middle,"ThirtyTwoPre/GroupInfo"):GetComponent("Text")
this.thirtyTwoList = {}
for i = 1, 14 do
this.thirtyTwoList[i]=Util.GetGameObject(this.thirtyTwoPre,"ItemPre ("..i..")")
end
this.playFlyAnim=Util.GetGameObject(this.middle,"ThirtyTwoPre"):GetComponent("PlayFlyAnim")
this.leftBtn=Util.GetGameObject(this.middle,"ThirtyTwoPre/LeftBtn/GameObject")
this.rightBtn=Util.GetGameObject(this.middle,"ThirtyTwoPre/RightBtn/GameObject")
this.fourPre=Util.GetGameObject(this.middle,"FourPre")
this.fourList = {}
for i = 1, 6 do
this.fourList[i]=Util.GetGameObject(this.fourPre,"ItemPre ("..i..")")
end
this.empty=Util.GetGameObject(this.panel,"Empty")
this.emptyInfo=Util.GetGameObject(this.panel,"Empty/Bg/Text"):GetComponent("Text")
this.tabBox=Util.GetGameObject(this.panel,"TabBox")
this.tabCtrl = TabBox.New()
this.tabCtrl:SetTabAdapter(this.TabAdapter)
this.tabCtrl:SetChangeTabCallBack(this.OnTabChange)
this.tabCtrl:Init(this.tabBox, _TabData)
end
--绑定事件(用于子类重写)
function ATM_EliminationView:BindEvent()
--左按钮
Util.AddClick(this.leftBtn,function()
GroupIndex=GroupIndex-1
if GroupIndex<1 then
GroupIndex=4
end
this.Set32Group(GroupIndex)
end)
--右按钮
Util.AddClick(this.rightBtn,function()
GroupIndex=GroupIndex+1
if GroupIndex>4 then
GroupIndex=1
end
this.Set32Group(GroupIndex)
end)
end
--添加事件监听(用于子类重写)
function ATM_EliminationView:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.TopMatch.OnTopMatchDataUpdate, this.RefreshBaseShow)
end
--移除事件监听(用于子类重写)
function ATM_EliminationView:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.TopMatch.OnTopMatchDataUpdate, this.RefreshBaseShow)
end
--界面打开时调用(用于子类重写)
function ATM_EliminationView:OnOpen(...)
battleStage=ArenaTopMatchManager.GetBaseData().battleStage
battleTurn=ArenaTopMatchManager.GetBaseData().battleTurn
battleState=ArenaTopMatchManager.GetBaseData().battleState
LogGreen(Language[10156]..battleStage..Language[10157]..battleTurn..Language[10158]..battleState.."</color>")
local isActive = ArenaTopMatchManager.IsTopMatchActive()
_IsShowData = isActive and (battleStage == TOP_MATCH_STAGE.ELIMINATION or battleStage== TOP_MATCH_STAGE.OVER)
this.empty:SetActive(not _IsShowData)
this.middle:SetActive(_IsShowData)
GroupIndex=1
LogRed("battleState "..battleState)
-- if battleState==1 then return end
if this.tabCtrl then
this.tabCtrl:ChangeTab(1)
end
FixedUpdateBeat:Add(this.OnUpdate, self)
end
function ATM_EliminationView:OnSortingOrderChange(sortingOrder)
--Log("<color=red>32强赛传入层级</color> <color=yellow>"..tostring(sortingOrder).."</color>")
end
--界面关闭时调用(用于子类重写)
function ATM_EliminationView:OnClose()
if this.timer then
this.timer:Stop()
this.timer = nil
end
FixedUpdateBeat:Remove(this.OnUpdate, self)
end
--界面销毁时调用(用于子类重写)
function ATM_EliminationView:OnDestroy()
end
function this.OnUpdate()
if Input.GetKey(UnityEngine.KeyCode.Space) then
Log(GroupIndex)
end
end
-- tab按钮自定义显示设置
function this.TabAdapter(tab, index, status)
local img = Util.GetGameObject(tab, "Image")
local txt = Util.GetGameObject(tab, "Text")
img:GetComponent("Image").sprite = Util.LoadSprite(_TabImgData[status])
txt:GetComponent("Text").text = _TabData[index].txt
txt:GetComponent("Text").color = _TabFontColor[status]
end
-- tab改变回调事件
function this.OnTabChange(index, lastIndex)
this.OnTabChangeView(index)
end
--主动切换页签显示
function this.OnTabChangeView(index)
this.thirtyTwoPre:SetActive(index==1)
this.fourPre:SetActive(index~=1)
if index==1 then
CurTabIndex=index
this.emptyInfo.text=Language[10159]
ArenaTopMatchManager.Request_32_EliminationData(function()
this.Set32Group(1)
end)
this.playFlyAnim:PlayAnim(true)
else
CurTabIndex=2
this.emptyInfo.text=Language[10160]
ArenaTopMatchManager.Request_4_EliminationData(function()
this.Set4Group()
end)
end
end
--被动刷新页签显示
function this.RefreshBaseShow()
battleStage=ArenaTopMatchManager.GetBaseData().battleStage
battleTurn=ArenaTopMatchManager.GetBaseData().battleTurn
battleState=ArenaTopMatchManager.GetBaseData().battleState
LogGreen("battleStage battleTurn battleState "..battleStage.." ".. battleTurn .." "..battleState)
local isActive = ArenaTopMatchManager.IsTopMatchActive()
_IsShowData = isActive and (battleStage == TOP_MATCH_STAGE.ELIMINATION or battleStage== TOP_MATCH_STAGE.OVER)
this.empty:SetActive(not _IsShowData)
this.middle:SetActive(_IsShowData)
this.thirtyTwoPre:SetActive(CurTabIndex==1 and _IsShowData)
this.fourPre:SetActive(CurTabIndex==2 and _IsShowData)
--竞猜按钮竞猜结束后未关闭
if CurTabIndex==1 then
this.emptyInfo.text=Language[10159]
ArenaTopMatchManager.Request_32_EliminationData(function()
Log(Language[10161])
this.Set32Group(GroupIndex)
end)
this.playFlyAnim:PlayAnim(true)
elseif CurTabIndex==2 then
this.emptyInfo.text=Language[10160]
ArenaTopMatchManager.Request_4_EliminationData(function()
Log(Language[10162])
this.Set4Group()
end)
end
end
--设置玩家页签状态
function this.SetPlayerState(obj1,obj2,attackName,defName,state,func)
LogGreen("state "..state)
Util.GetGameObject(obj1,"WinImage"):SetActive(state==PlayerState.Win)
Util.GetGameObject(obj1,"Line/Win"):SetActive(state==PlayerState.Win)
Util.GetGameObject(obj1,"Line/Fail"):SetActive(state==PlayerState.Fail)
Util.GetGameObject(obj1,"Name"):GetComponent("Text").text=attackName
Util.GetGameObject(obj2,"WinImage"):SetActive(state==PlayerState.Fail)
Util.GetGameObject(obj2,"Line/Win"):SetActive(state==PlayerState.Fail)
Util.GetGameObject(obj2,"Line/Fail"):SetActive(state==PlayerState.Win)
Util.GetGameObject(obj2,"Name"):GetComponent("Text").text=defName
if state==PlayerState.Win then
obj1.transform:SetSiblingIndex(1)
obj2.transform:SetSiblingIndex(0)
else
obj1.transform:SetSiblingIndex(0)
obj2.transform:SetSiblingIndex(1)
end
if func then func() end
end
function this.SetPlaySettingBack(playBackBtn,v,fightResult)
playBackBtn:SetActive(_IsShowData and fightResult~=-1)
Util.AddOnceClick(playBackBtn,function()
UIManager.OpenPanel(UIName.TopMatchPlayBattleAinSelectPopup,v)
end)
end
--设置战斗回放按钮
function this.SetPlayBack(playBackBtn, fightResult, id, defInfo, attackInfo)
-- playBackBtn:SetActive(_IsShowData and fightResult~=-1)
-- Util.AddOnceClick(playBackBtn,function()
ArenaTopMatchManager.RequestRecordFightData(fightResult,id, attackInfo.name.."|"..defInfo.name,function()
--构建显示结果数据(我永远在蓝方)
local arg = {}
arg.panelType = 1
arg.result = fightResult
arg.blue = {}
arg.blue.uid = attackInfo.uid
arg.blue.name = attackInfo.name
arg.blue.head = attackInfo.head
arg.blue.frame = attackInfo.headFrame
arg.red = {}
arg.red.uid = defInfo.uid
arg.red.name = defInfo.name
arg.red.head = defInfo.head
arg.red.frame = defInfo.headFrame
UIManager.OpenPanel(UIName.ArenaResultPopup, arg)
end)
-- end)
end
--设置竞猜按钮
function this.SetGuessBtn(guessBtn, isGUess)
guessBtn:SetActive(battleStage == TOP_MATCH_STAGE.ELIMINATION and isGUess==1)
--Log("竞猜"..tostring(battleStage==2)..tostring(battleState==1)..isGUess)
Util.AddOnceClick(guessBtn,function()
if ArenaTopMatchPanel.TabCtrl then
ArenaTopMatchPanel.TabCtrl:ChangeTab(2)
end
end)
end
--设置32强战斗组
function this.Set32Group(index)
this.groupInfo.text=GroupInfo[index]
local data={}
LogGreen("LengthOfTable(ArenaTopMatchManager.EliminationData_32) "..LengthOfTable(ArenaTopMatchManager.EliminationData_32))
for i, v in pairs(ArenaTopMatchManager.EliminationData_32) do
if v._singleData.teamId==index then
table.insert(data,v)
end
end
for i, v in pairs(data) do
LogGreen("v.roundTImes v.position "..v._singleData.roundTImes.." "..v._singleData.position)
if v._singleData.roundTImes==8 then
local item1= Util.GetGameObject(this.thirtyTwoPre,"Pos"..v._singleData.position.."/ItemPre (1)")
local item2= Util.GetGameObject(this.thirtyTwoPre,"Pos"..v._singleData.position.."/ItemPre (2)")
local playBackBtn=Util.GetGameObject(this.thirtyTwoPre,"Pos"..v._singleData.position.."/PlayBackBtn")
local guessBtn=Util.GetGameObject(this.thirtyTwoPre,"Pos"..v._singleData.position.."/GuessBtn")
this.SetPlayerState(item1,item2,v._singleData.attackInfo.name,v._singleData.defInfo.name,v._singleData.fightResult)
-- this.SetPlayBack(playBackBtn,v.fightResult,v.id,v.defInfo,v.attackInfo)
this.SetPlaySettingBack(playBackBtn,v._listData,v._singleData.fightResult)
this.SetGuessBtn(guessBtn,v._singleData.isGUess)
end
if v._singleData.roundTImes==9 then
-- LogGreen("v.position "..v.position)
local item1= Util.GetGameObject(this.thirtyTwoPre,"Pos"..(v._singleData.position+4).."/ItemPre (1)")
local item2= Util.GetGameObject(this.thirtyTwoPre,"Pos"..(v._singleData.position+4).."/ItemPre (2)")
local playBackBtn=Util.GetGameObject(this.thirtyTwoPre,"Pos"..(v._singleData.position+4).."/PlayBackBtn")
local guessBtn=Util.GetGameObject(this.thirtyTwoPre,"Pos"..(v._singleData.position+4).."/GuessBtn")
this.SetPlayerState(item1,item2,v._singleData.attackInfo.name,v._singleData.defInfo.name,v._singleData.fightResult)
-- this.SetPlayBack(playBackBtn,v.fightResult,v.id,v.defInfo,v.attackInfo)
this.SetPlaySettingBack(playBackBtn,v._listData,v._singleData.fightResult)
this.SetGuessBtn(guessBtn,v._singleData.isGUess)
end
if v._singleData.roundTImes==10 then
local item1= Util.GetGameObject(this.thirtyTwoPre,"Pos7/ItemPre (1)")
local item2= Util.GetGameObject(this.thirtyTwoPre,"Pos7/ItemPre (2)")
local playBackBtn=Util.GetGameObject(this.thirtyTwoPre,"Pos7/PlayBackBtn")
local guessBtn=Util.GetGameObject(this.thirtyTwoPre,"Pos7/GuessBtn")
this.SetPlayerState(item1,item2,v._singleData.attackInfo.name,v._singleData.defInfo.name,v._singleData.fightResult)
-- this.SetPlayBack(playBackBtn,v.fightResult,v.id,v.defInfo,v.attackInfo)
this.SetPlaySettingBack(playBackBtn,v._listData,v._singleData.fightResult)
this.SetGuessBtn(guessBtn,v._singleData.isGUess)
end
end
end
--设置4强战斗组
function this.Set4Group()
local data={}
for i, v in pairs(ArenaTopMatchManager.EliminationData_4) do
if v._singleData.teamId==1 then
table.insert(data,v)
end
end
-- 置空显示
local cHead = Util.GetGameObject(this.fourPre,"Pos3/box/head")
this.SetChampionHead(cHead)
for i, v in pairs(data) do
if v._singleData.roundTImes==11 then
local item1= Util.GetGameObject(this.fourPre,"Pos"..v._singleData.position.."/ItemPre (1)")
local item2= Util.GetGameObject(this.fourPre,"Pos"..v._singleData.position.."/ItemPre (2)")
local playBackBtn=Util.GetGameObject(this.fourPre,"Pos"..v._singleData.position.."/PlayBackBtn")
local guessBtn=Util.GetGameObject(this.fourPre,"Pos"..v._singleData.position.."/GuessBtn")
this.SetPlayerState(item1,item2,v._singleData.attackInfo.name,v._singleData.defInfo.name,v._singleData.fightResult)
-- this.SetPlayBack(playBackBtn,v.fightResult,v.id,v.defInfo,v.attackInfo)
this.SetPlaySettingBack(playBackBtn,v._listData,v._singleData.fightResult)
this.SetGuessBtn(guessBtn,v._singleData.isGUess)
end
if v._singleData.roundTImes==12 then
local item1= Util.GetGameObject(this.fourPre,"Pos3/ItemPre (1)")
local item2= Util.GetGameObject(this.fourPre,"Pos3/ItemPre (2)")
local playBackBtn=Util.GetGameObject(this.fourPre,"Pos3/box/PlayBackBtn")
local guessBtn=Util.GetGameObject(this.fourPre,"Pos3/box/GuessBtn")
this.SetPlayerState(item1,item2,v._singleData.attackInfo.name,v._singleData.defInfo.name,v._singleData.fightResult)
-- this.SetPlayBack(playBackBtn,v.fightResult,v.id,v.defInfo,v.attackInfo)
this.SetPlaySettingBack(playBackBtn,v._listData,v._singleData.fightResult)
LogRed("决赛 是否显示竞猜按钮 v.isGUess "..v._singleData.isGUess.." battleStage == TOP_MATCH_STAGE.ELIMINATION and isGUess==1")
LogRed("决赛 是否显示竞猜按钮 v.fightResult "..v._singleData.fightResult)
this.SetGuessBtn(guessBtn,v._singleData.isGUess)
this.SetChampionHead(cHead, v._singleData.fightResult, v._singleData.defInfo, v._singleData.attackInfo)
end
end
end
function this.SetChampionHead(head, fightResult, defInfo, attackInfo)
local headImg = head:GetComponent("Image")
local lvRoot = Util.GetGameObject(head, "lvRoot")
local lv = Util.GetGameObject(head, "lvRoot/lv"):GetComponent("Text")
--
if not fightResult then
headImg.color = Color.New(1,1,1,0)
lvRoot:SetActive(false)
return
end
if (battleStage == TOP_MATCH_STAGE.ELIMINATION
and battleTurn == ArenaTopMatchManager.GetEliminationMaxRound()
and battleState == TOP_MATCH_TIME_STATE.OPEN_IN_END) -- 最后一个阶段的结算阶段
or battleStage == TOP_MATCH_STAGE.OVER -- 已结束
then
headImg.color = Color.New(1,1,1,1)
lvRoot:SetActive(true)
local cInfo = fightResult == 1 and attackInfo or defInfo
headImg.sprite = GetPlayerHeadSprite(cInfo.head)
lv.text = cInfo.level
else
headImg.color = Color.New(1,1,1,0)
lvRoot:SetActive(false)
end
end
return ATM_EliminationView