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

321 lines
12 KiB
Lua
Raw Normal View History

2020-05-09 13:31:21 +08:00
local ATM_MainMatchView={}
local this=ATM_MainMatchView
local commonInfo = require("Modules/ArenaTopMatch/View/ATM_CommonInfo")
--初始化组件(用于子类重写)
function ATM_MainMatchView:InitComponent()
this.btnRecord = Util.GetGameObject(self.gameObject, "record")
this.btnTeamRank = Util.GetGameObject(self.gameObject, "teamRank")
this.btnFightDetail = Util.GetGameObject(self.gameObject, "btnDetail")
this.containPanel = Util.GetGameObject(self.gameObject, "contain")
this.lockPanel = Util.GetGameObject(self.gameObject, "contain/LockBg")
this.lockContext = Util.GetGameObject(this.lockPanel, "context"):GetComponent("Text")
this.lockTime = Util.GetGameObject(this.lockPanel, "JoinRoot/time"):GetComponent("Text")
this.lockTip = Util.GetGameObject(this.lockPanel, "JoinRoot/tip"):GetComponent("Text")
this.outTip = Util.GetGameObject(this.lockPanel, "OutRoot/Text"):GetComponent("Text")
2020-07-08 15:02:16 +08:00
this.WeedOutText = Util.GetGameObject(this.lockPanel, "WeedOutRoot/Text"):GetComponent("Text")
this.WeedOutMyRank = Util.GetGameObject(this.lockPanel, "WeedOutRoot/MyRank"):GetComponent("Text")
this.WeedOutMyRankText = Util.GetGameObject(this.lockPanel, "WeedOutRoot/MyRank/Text"):GetComponent("Text")
this.WeedOutBestRank = Util.GetGameObject(this.lockPanel, "WeedOutRoot/BestRank"):GetComponent("Text")
this.WeedOutBestRankText = Util.GetGameObject(this.lockPanel, "WeedOutRoot/BestRank/Text"):GetComponent("Text")
2020-05-09 13:31:21 +08:00
this.lockIn = Util.GetGameObject(this.lockPanel, "JoinRoot")
this.lockOut = Util.GetGameObject(this.lockPanel, "OutRoot")
2020-07-08 15:02:16 +08:00
this.WeedOutRoot = Util.GetGameObject(this.lockPanel, "WeedOutRoot")
2020-05-09 13:31:21 +08:00
2020-07-03 16:09:15 +08:00
this.effect = Util.GetGameObject(self.gameObject, "bg/UI_effect_ArenaMainPanel_particle")
2020-05-09 13:31:21 +08:00
2020-07-03 16:09:15 +08:00
this.orggroup = Util.GetGameObject(this.lockPanel, "orggroup")
this.Demons = Util.GetGameObject(this.lockPanel, "Demons")
this.myBaby = {}
for i = 1, 6 do
this.myBaby[i] = Util.GetGameObject(this.lockPanel,"Demons/heroPro (" .. i .. ")")
end
2020-05-09 13:31:21 +08:00
end
--绑定事件(用于子类重写)
function ATM_MainMatchView:BindEvent()
commonInfo.BindEvent()
Util.AddClick(this.btnRecord, function ()
-- UIManager.OpenPanel(UIName.RecordPopup)
ArenaTopMatchManager.RequestBattleHistory(function()
UIManager.OpenPanel(UIName.RecordPopup)
end)
end)
Util.AddClick(this.btnTeamRank, function ()
ArenaTopMatchManager.RequestMyTeamRank(function()
UIManager.OpenPanel(UIName.ATMTeamRankPopup)
end)
end)
Util.AddClick(this.btnFightDetail, function ()
2020-07-08 15:02:16 +08:00
this.battleDetailBtnClick()
2020-05-09 13:31:21 +08:00
end)
end
--添加事件监听(用于子类重写)
function ATM_MainMatchView:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.TopMatch.OnTopMatchDataUpdate, this.OnOpen, this)
2020-07-08 15:02:16 +08:00
Game.GlobalEvent:AddEvent(GameEvent.ATM_RankView.OnOpenBattle, this.battleDetailBtnClick)
2020-05-09 13:31:21 +08:00
end
--移除事件监听(用于子类重写)
function ATM_MainMatchView:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.TopMatch.OnTopMatchDataUpdate, this.OnOpen, this)
2020-07-08 15:02:16 +08:00
Game.GlobalEvent:RemoveEvent(GameEvent.ATM_RankView.OnOpenBattle, this.battleDetailBtnClick)
2020-05-09 13:31:21 +08:00
end
--界面打开时调用(用于子类重写)
function ATM_MainMatchView:OnOpen(...)
local isActive = ArenaTopMatchManager.IsTopMatchActive()
this.StateChange(isActive)
end
-- 状态切换
2020-07-10 13:38:50 +08:00
local isJoin = nil
local isOver = nil
local baseData
2020-05-09 13:31:21 +08:00
function this.StateChange(isOpen)
baseData = ArenaTopMatchManager.GetBaseData()
2020-05-09 13:31:21 +08:00
-- 没开启或者开启没参赛都属于未参赛
2020-07-10 13:38:50 +08:00
isJoin = baseData.joinState == 1
isOver = baseData.progress == -2
2020-07-03 16:09:15 +08:00
LogGreen("isOpen "..tostring(isOpen).." "..tostring(isJoin).." "..tostring(isOver).." "..baseData.joinState)
2020-07-08 15:02:16 +08:00
local battleInfo = ArenaTopMatchManager.GetBattleInfo()
LogGreen("battleInfo.result "..battleInfo.result.." baseData.battleState "..baseData.battleState)
2020-07-10 13:38:50 +08:00
LogGreen("baseData.loser "..tostring(baseData.loser))
2020-05-09 13:31:21 +08:00
if isOpen then
if isJoin then
this.SetPlayerInfo()
2020-07-10 13:38:50 +08:00
if baseData.loser then
2020-07-08 15:02:16 +08:00
this.SetWeedOutRootInfo()
end
2020-05-09 13:31:21 +08:00
else
this.SetNotJionInfo()
end
2020-08-15 00:08:25 +08:00
if isOver then
this.SetOverInfo()
end
2020-05-09 13:31:21 +08:00
else
if isOver then
this.SetOverInfo()
else
this.SetLockInfo()
end
end
2020-07-08 15:02:16 +08:00
2020-08-15 00:08:25 +08:00
this.containPanel:SetActive(not isOpen or not isJoin or baseData.loser or isOver)-- or isOver
2020-05-09 13:31:21 +08:00
this.btnRecord:SetActive(isOpen and isJoin)
this.btnTeamRank:SetActive(isOpen and isJoin)
this.btnFightDetail:SetActive(isOpen and isJoin and baseData.battleState == TOP_MATCH_TIME_STATE.OPEN_IN_END and not baseData.loser)
-- this.orggroup:SetActive(not isOpen and not isOver)
2020-08-15 00:08:25 +08:00
-- this.Demons:SetActive(not isOpen and not isOver) --not isOpen or (isOpen and isOver)
this.orggroup:SetActive(true)
this.Demons:SetActive(true)
this.FreshTeam()
2020-05-09 13:31:21 +08:00
end
2020-07-08 15:02:16 +08:00
function this.battleDetailBtnClick()
local battleInfo = ArenaTopMatchManager.GetBattleInfo()
if not isJoin or (isJoin and isOver) or baseData.loser then
2020-07-10 13:38:50 +08:00
return
end
2020-07-08 15:02:16 +08:00
if battleInfo.result == -1 then
return
end
2020-07-24 10:01:48 +08:00
if ArenaTopMatchManager.GetIsBattleEndState(1) then
2020-09-11 21:10:39 +08:00
return
end
if UIManager.IsOpen(UIName.BattlePanel) then
2020-07-24 10:01:48 +08:00
return
end
2020-07-08 15:02:16 +08:00
local nameStr = battleInfo.myInfo.name.."|"..battleInfo.enemyInfo.name
ArenaTopMatchManager.RequestReplayRecord(battleInfo.result, battleInfo.fightData, nameStr, function()
local blueInfo = battleInfo.myInfo
local redInfo = battleInfo.enemyInfo
--构建显示结果数据
local arg = {}
arg.result = battleInfo.result
arg.blue = {}
arg.blue.uid = blueInfo.uid
arg.blue.name = blueInfo.name
arg.blue.head = blueInfo.head
arg.blue.frame = blueInfo.headFrame
arg.red = {}
arg.red.uid = redInfo.uid
arg.red.name = redInfo.name
arg.red.head = redInfo.head
arg.red.frame = redInfo.headFrame
UIManager.OpenPanel(UIName.ArenaResultPopup, arg)
end)
end
2020-05-09 13:31:21 +08:00
function this.SetPlayerInfo()
this.lockIn:SetActive(false)
this.lockOut:SetActive(false)
2020-07-08 15:02:16 +08:00
this.WeedOutRoot:SetActive(false)
2020-05-09 13:31:21 +08:00
local battleInfo = ArenaTopMatchManager.GetBattleInfo()
local attInfo = battleInfo.myInfo
local defInfo = battleInfo.enemyInfo
local myResult = -1
local blueInfo = nil
local redInfo = nil
2020-07-31 15:40:43 +08:00
-- LogPink("battleInfo.result "..battleInfo.result)
2020-07-15 18:23:40 +08:00
local battleEndResultSortState = true --true 战斗最终直接赋值 false 颠倒赋值
2020-07-31 15:40:43 +08:00
-- LogRed("PlayerManager.uid "..PlayerManager.uid.." "..attInfo.uid.." "..defInfo.uid)
2020-05-09 13:31:21 +08:00
if attInfo.uid == PlayerManager.uid then
blueInfo = attInfo
redInfo = defInfo
myResult = battleInfo.result
2020-07-15 18:23:40 +08:00
battleEndResultSortState = true
2020-05-09 13:31:21 +08:00
elseif defInfo.uid == PlayerManager.uid then
blueInfo = defInfo
redInfo = attInfo
if battleInfo.result ~= -1 then
myResult = (battleInfo.result + 1) % 2
end
2020-07-15 18:23:40 +08:00
battleEndResultSortState = false
2020-05-09 13:31:21 +08:00
end
--if battleInfo.result == 0 then -- 如果进攻方失败,则如果我是进攻方则我失败,反之胜利
-- myResult = attInfo.uid == PlayerManager.uid and 0 or 1
--elseif battleInfo.result == 1 then -- 如果进攻方胜利,则如果我是进攻方则我胜利
-- myResult = attInfo.uid == PlayerManager.uid and 1 or 0
--end
local baseData = ArenaTopMatchManager.GetBaseData()
commonInfo.SetActive(true)
2020-07-15 18:23:40 +08:00
commonInfo.SetInfoData(1, blueInfo, redInfo, myResult, baseData == TOP_MATCH_STAGE.CHOOSE,battleEndResultSortState)
2020-05-09 13:31:21 +08:00
end
function this.SetLockInfo()
2020-07-03 16:09:15 +08:00
--加一套编队
2020-05-09 13:31:21 +08:00
this.lockIn:SetActive(true)
this.lockOut:SetActive(false)
2020-07-08 15:02:16 +08:00
this.WeedOutRoot:SetActive(false)
2020-05-09 13:31:21 +08:00
commonInfo.SetActive(false)
2020-06-23 18:36:24 +08:00
this.lockContext.text = Language[10169]
this.lockTip.text = Language[10170]
2020-05-09 13:31:21 +08:00
if not this.lockTimer then
local startTime = ArenaTopMatchManager.GetTopMatchTime()
local during = startTime - PlayerManager.serverTime
during = during <= 0 and 0 or during
this.lockTime.text = TimeToHMS(during)
this.lockTimer = Timer.New(function ()
local startTime = ArenaTopMatchManager.GetTopMatchTime()
local during = startTime - PlayerManager.serverTime
during = during <= 0 and 0 or during
local timeStr = TimeToHMS(during)
this.lockTime.text = timeStr
end, 1, -1, true)
this.lockTimer:Start()
end
2020-07-03 16:09:15 +08:00
this.FreshTeam()
end
function this.FreshTeam()
Util.AddOnceClick(this.orggroup, function ()
UIManager.OpenPanel(UIName.FormationPanelV2, FORMATION_TYPE.ARENA_TOP_MATCH, function()
-- 重新获取战斗数据
--ArenaTopMatchManager.RequestTopMatchBaseInfo()
end)
end)
for i, demon in ipairs(this.myBaby) do
Util.GetGameObject(demon, "frame"):GetComponent("Image").sprite = Util.LoadSprite(GetQuantityImageByquality(1))
Util.GetGameObject(demon, "hero"):SetActive(false)
end
2020-07-23 14:36:28 +08:00
local formation = FormationManager.GetFormationByID(FormationTypeDef.ARENA_TOM_MATCH)
2020-07-03 16:09:15 +08:00
for i, hero in ipairs(formation.teamHeroInfos) do
local heroData = HeroManager.GetSingleHeroData(hero.heroId)
local heroGo = Util.GetGameObject(this.myBaby[hero.position], "hero")
heroGo:SetActive(true)
Util.GetGameObject(heroGo, "lvbg/levelText"):GetComponent("Text").text = heroData.lv
SetHeroStars(Util.GetGameObject(heroGo, "starGrid"), heroData.star)
local demonId = heroData.id
local heroConfig = ConfigManager.GetConfigData(ConfigName.HeroConfig, demonId)
2020-07-25 19:59:43 +08:00
Util.GetGameObject(this.myBaby[hero.position], "frame"):GetComponent("Image").sprite = Util.LoadSprite(GetQuantityImageByquality(heroConfig.Quality,heroData.star))
2020-07-03 16:09:15 +08:00
Util.GetGameObject(heroGo, "icon"):GetComponent("Image").sprite = Util.LoadSprite(GetResourcePath(heroConfig.Icon))
Util.GetGameObject(heroGo, "proIcon"):GetComponent("Image").sprite = Util.LoadSprite(GetProStrImageByProNum(heroConfig.PropertyName))
end
2020-05-09 13:31:21 +08:00
end
function this.SetNotJionInfo()
this.lockIn:SetActive(false)
this.lockOut:SetActive(true)
2020-07-08 15:02:16 +08:00
this.WeedOutRoot:SetActive(false)
2020-05-09 13:31:21 +08:00
commonInfo.SetActive(false)
2020-06-23 18:36:24 +08:00
this.lockContext.text = Language[10171]
this.outTip.text = Language[10172]
2020-05-09 13:31:21 +08:00
end
function this.SetOverInfo()
this.lockIn:SetActive(false)
this.lockOut:SetActive(true)
2020-07-08 15:02:16 +08:00
this.WeedOutRoot:SetActive(false)
2020-05-09 13:31:21 +08:00
commonInfo.SetActive(false)
2020-06-23 18:36:24 +08:00
this.lockContext.text = Language[10173]
this.outTip.text = Language[10174]
2020-05-09 13:31:21 +08:00
end
2020-07-08 15:02:16 +08:00
function this.SetWeedOutRootInfo()
this.lockIn:SetActive(false)
this.lockOut:SetActive(false)
this.WeedOutRoot:SetActive(true)
commonInfo.SetActive(false)
local tmData = ArenaTopMatchManager.GetBaseData()
this.WeedOutText.text = Language[12208]
this.WeedOutMyRank.text = Language[10104]
this.WeedOutMyRankText.text = tmData.myrank <= 0 and Language[10041] or ArenaTopMatchManager.GetRankNameByRank(tmData.myrank)
2020-07-25 20:42:11 +08:00
this.WeedOutBestRank.text = Language[12245]
2020-07-08 15:02:16 +08:00
this.WeedOutBestRankText.text = tmData.maxRank <= 0 and Language[10094] or this.GetRankName(tmData.maxRank)
end
2020-05-09 13:31:21 +08:00
2020-07-08 15:02:16 +08:00
-- 获取我得排名信息
function this.GetRankName(rank)
if rank == 1 then
return Language[10095]
elseif rank == 2 then
return Language[10096]
else
local maxTurn = ArenaTopMatchManager.GetEliminationMaxRound()
for i = 1, maxTurn do
if i == maxTurn then
local config = ConfigManager.GetConfigData(ConfigName.ChampionshipSetting, 1)
return config.ChampionshipPlayer..Language[10097]
end
if rank > math.pow(2, i) and rank <= math.pow(2, i+1) then
return (i+1)..Language[10097]
end
end
end
end
2020-05-09 13:31:21 +08:00
-- 层级改变回调
local orginLayer = 0
function ATM_MainMatchView:OnSortingOrderChange(sort)
Util.AddParticleSortLayer(this.effect, sort - orginLayer)
orginLayer = sort
end
--界面关闭时调用(用于子类重写)
function ATM_MainMatchView:OnClose()
if this.lockTimer then
this.lockTimer:Stop()
this.lockTimer = nil
end
commonInfo.SetEffectPopupShow(false)
end
--界面销毁时调用(用于子类重写)
function ATM_MainMatchView:OnDestroy()
end
2020-06-23 18:36:24 +08:00
return ATM_MainMatchView