miduo_client/Assets/ManagedResources/~Lua/Modules/Arena/View/ArenaView.lua

476 lines
21 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.

local ArenaView = {}
local this = ArenaView
local rewardBoxBtn = {}
local myRank
local arenaBattleReward = ConfigManager.GetConfig(ConfigName.ArenaBattleReward)
local arenaReward = ConfigManager.GetConfig(ConfigName.ArenaReward)
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
--初始化组件(用于子类重写)
function ArenaView:InitComponent()
this.spLoader = SpriteLoader.New()
this.DailyReward = Util.GetGameObject(self.gameObject, "finalTarget/Reward/dailyReward"):GetComponent("Text")
this.SeasonReward = Util.GetGameObject(self.gameObject, "finalTarget/Reward/seasonReward"):GetComponent("Text")
this.content = Util.GetGameObject(self.gameObject, "content")
this.ArenaName = Util.GetGameObject(self.gameObject, "nameImg/name")
this.ArenaTime = Util.GetGameObject(self.gameObject, "timelab")
this.Integral = Util.GetGameObject(self.gameObject, "myScore/integral")
this.FormationBtn = Util.GetGameObject(self.gameObject, "formationBtn")
--this.DiffDemons = {}
--for i = 1, 3 do
-- table.insert(this.DiffDemons, Util.GetGameObject(self.gameObject, "diffdemons/icon_"..i))
--end
this.Demons = {}
for i = 1, 6 do
if not this.Demons[i] then
this.Demons[i] = {}
this.Demons[i].go = Util.GetGameObject(self.gameObject, "defendbox/Demons/heroPro (" .. i .. ")")
this.Demons[i].frame = Util.GetGameObject(this.Demons[i].go, "frame"):GetComponent("Image")
this.Demons[i].hero = Util.GetGameObject(this.Demons[i].go, "hero")
this.Demons[i].levelText = Util.GetGameObject(this.Demons[i].hero, "lvbg/levelText"):GetComponent("Text")
this.Demons[i].starGrid = Util.GetGameObject(this.Demons[i].hero, "starGrid")
this.Demons[i].icon = Util.GetGameObject(this.Demons[i].hero, "icon"):GetComponent("Image")
this.Demons[i].proIcon = Util.GetGameObject(this.Demons[i].hero, "proIcon"):GetComponent("Image")
end
end
this.Enemys = {}
for i = 1, 4 do
table.insert(this.Enemys, Util.GetGameObject(self.gameObject, "challengebox/enemy_"..i))
end
this.RecordBtn = Util.GetGameObject(self.gameObject, "rightUp/record")
this.RefreshBtn = Util.GetGameObject(self.gameObject, "refresh")
this.RewardBtn = Util.GetGameObject(self.gameObject, "rightUp/reward")
this.StoreBtn = Util.GetGameObject(self.gameObject, "rightUp/store")
this.sortBtn = Util.GetGameObject(self.gameObject, "rightUp/sortBtn")
this.helpBtn = Util.GetGameObject(self.gameObject, "rightUp/helpBtn")
this.helpPosition=this.helpBtn:GetComponent("RectTransform").localPosition
this.myRank=Util.GetGameObject(self.gameObject,"MyRank")
this.rank=Util.GetGameObject(this.myRank,"Rank"):GetComponent("Text")
this.power=Util.GetGameObject(self.gameObject,"powerImg/Power"):GetComponent("Text")
--this.formationPower=Util.GetGameObject(self.gameObject,"defendbox/FormationPower/Text"):GetComponent("Text")
this.effect = Util.GetGameObject(self.gameObject, "bg/UI_effect_ArenaMainPanel_particle")
--宝箱部分
this.progressImage = Util.GetGameObject(self.gameObject, "finalTarget/progressbar/progress"):GetComponent("Image")
this.progressTipText = Util.GetGameObject(self.gameObject, "finalTarget/Text (1)"):GetComponent("Text")
rewardBoxBtn = {}
for i = 1, 5 do
rewardBoxBtn[i] = Util.GetGameObject(self.gameObject, "finalTarget/rewardProgress/rewardBoxBtn (" .. i .. ")")
rewardBoxBtn[i].transform.localPosition = Vector3.New(arenaBattleReward[i].Position[1], arenaBattleReward[i].Position[2] ,0)
end
this.freeTimes = Util.GetGameObject(self.gameObject, "count/text"):GetComponent("Text")
end
--绑定事件(用于子类重写)
function ArenaView:BindEvent()
-- 防守编队
Util.AddClick(this.FormationBtn, function()
if not ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.ARENA) then
PopupTipPanel.ShowTip(Language[10075])
return
end
UIManager.OpenPanel(UIName.FormationPanelV2, FORMATION_TYPE.ARENA_DEFEND)
end)
-- 挑战按钮
for i, enemy in ipairs(this.Enemys) do
local challengeBtn = Util.GetGameObject(enemy, "challenge")
Util.AddClick(challengeBtn, function()
if not ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.ARENA) then
PopupTipPanel.ShowTip(Language[10075])
return
end
-- 只在活动时间范围内可点
if ArenaManager.GetLeftTime() > 0 then
-- 添加次数限制
local leftTimes = ArenaManager.GetArenaChallengeTimes()
if leftTimes <= 0 then
local itemId, needNum = ArenaManager.GetArenaChallengeCost()
local haveNum = BagManager.GetItemCountById(itemId)
if haveNum < needNum then
UIManager.OpenPanel(UIName.QuickPurchasePanel, { type = UpViewRechargeType.ChallengeTicket })
PopupTipPanel.ShowTip(Language[10078])
return
end
end
-- 敌方数据获取
local EnemyList = ArenaManager.GetEnemyList()
if EnemyList[i] then
--直接主线阵容进战斗
-- 请求开始挑战
local isSkip = 0--ArenaManager.IsSkipFight() and 1 or 0
ArenaManager.RequestArenaChallenge(i, isSkip)
end
else
PopupTipPanel.ShowTip(Language[10092])
end
end)
end
--排行
Util.AddClick(this.sortBtn, function()
UIManager.OpenPanel(UIName.RankingSingleListPanel,rankKingList[6])
end)
-- 刷新按钮
Util.AddClick(this.RefreshBtn, function()
PlaySoundWithoutClick("UI_refresh")
if not ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.ARENA) then
PopupTipPanel.ShowTip(Language[10075])
return
end
ArenaManager.RequestNewArenaEnemy()
end)
-- 记录按钮
Util.AddClick(this.RecordBtn, function()
if not ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.ARENA) then
PopupTipPanel.ShowTip(Language[10075])
return
end
UIManager.OpenPanel(UIName.ArenaRecordPopup)
ResetServerRedPointStatus(RedPointType.Arena_Record)
end)
-- 帮助按钮
Util.AddClick(this.helpBtn, function()
UIManager.OpenPanel(UIName.HelpPopup,HELP_TYPE.Arena,this.helpPosition.x,this.helpPosition.y)
end)
-- 奖励按钮
Util.AddClick(this.RewardBtn, function()
UIManager.OpenPanel(UIName.GeneralRankRewardPanel,3,myRank)
end)
--商店按钮
Util.AddClick(this.StoreBtn, function()
if not ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.ARENA) then
PopupTipPanel.ShowTip(Language[10075])
return
end
JumpManager.GoJump(20010)
end)
end
--添加事件监听(用于子类重写)
function ArenaView:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.Formation.OnFormationChange, this.RefreshDefendFormation)
Game.GlobalEvent:AddEvent(GameEvent.Arena.OnBaseDataChange, this.RefreshBaseData)
Game.GlobalEvent:AddEvent(GameEvent.Arena.OnBaseDataChange, this.RefreshEnemyData)
Game.GlobalEvent:AddEvent(GameEvent.FiveAMRefresh.ServerNotifyRefresh, this.ZeroRefresh)
Game.GlobalEvent:AddEvent(GameEvent.Bag.BagGold, this.RefreshEnemyData)
Game.GlobalEvent:AddEvent(GameEvent.Arena.OnRankDataChange, this.RefreshRankInfo)
-- 绑定红点
BindRedPointObject(RedPointType.Arena_Record, Util.GetGameObject(self.gameObject, "record/redpot"))
end
--移除事件监听(用于子类重写)
function ArenaView:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.Formation.OnFormationChange, this.RefreshDefendFormation)
Game.GlobalEvent:RemoveEvent(GameEvent.Arena.OnBaseDataChange, this.RefreshBaseData)
Game.GlobalEvent:RemoveEvent(GameEvent.Arena.OnBaseDataChange, this.RefreshEnemyData)
Game.GlobalEvent:RemoveEvent(GameEvent.FiveAMRefresh.ServerNotifyRefresh, this.ZeroRefresh)
Game.GlobalEvent:RemoveEvent(GameEvent.Bag.BagGold, this.RefreshEnemyData)
Game.GlobalEvent:RemoveEvent(GameEvent.Arena.OnRankDataChange, this.RefreshRankInfo)
-- 清除红点
ClearRedPointObject(RedPointType.Arena_Record)
end
--界面打开时调用(用于子类重写)
function ArenaView:OnOpen( sortingOrder,_parent)
this.sortingOrder = sortingOrder or 0
this.parent = _parent
this.RefreshBaseData()
this.RefreshEnemyData()
this.RefreshDefendFormation()
this.StartCountTime()
this.RefreshRankInfo()
this.ShowRewardBoxProgressData()
-- 延迟刷新一遍数据,避免来回切换页签,向服务器不停发数据
if this.delayRefresh then return end
--
NetManager.RequestBaseArenaData()
-- 刷新排名数据
ArenaManager.RequestNextPageRank(true)
this.delayRefresh = Timer.New(function()
this.delayRefresh = nil
end, 1)
this.delayRefresh:Start()
this.RefreshReward()
end
-- 0点在这个界面时刷新数据
function this.ZeroRefresh()
NetManager.RequestBaseArenaData()
end
-- 刷新排名信息
function this.RefreshRankInfo()
local _, myRankInfo = ArenaManager.GetRankInfo()
myRank = myRankInfo.personInfo.rank
if myRank<0 then
myRank=Language[10036]
end
this.rank.text=Language[10093]..myRank
this.power.text=myRankInfo.personInfo.totalForce
-- 刷新奖励显示
this.RefreshReward()
end
-- 刷新奖励信息
function this.RefreshReward()
if tonumber(myRank) and tonumber(myRank) > 0 then
for k,value in ConfigPairs(arenaReward) do
if myRank <= 3 then
this.DailyReward.text = Language[10094]..GetLanguageStrById(itemConfig[arenaReward[myRank].DailyReward[1][1]].Name).."<color=green>+"..arenaReward[myRank].DailyReward[1][2].."</color>"..
GetLanguageStrById(itemConfig[arenaReward[myRank].DailyReward[2][1]].Name).."<color=green>+"..arenaReward[myRank].DailyReward[2][2].."</color>"
this.SeasonReward.text = Language[10095]..GetLanguageStrById(itemConfig[arenaReward[myRank].SeasonReward[1][1]].Name).."<color=green>+"..arenaReward[myRank].SeasonReward[1][2].."</color>"..
GetLanguageStrById(itemConfig[arenaReward[myRank].SeasonReward[2][1]].Name).."<color=green>+"..arenaReward[myRank].SeasonReward[2][2].."</color>"
else
-- LogRed("myrank"..myRank.." value.MinRank:"..tostring(value.MinRank).." value.MinRank:"..tostring(value.MaxRank))
if myRank>=value.MinRank and myRank <= value.MaxRank then
this.DailyReward.text = Language[10094]..GetLanguageStrById(itemConfig[value.DailyReward[1][1]].Name).."<color=green>+"..value.DailyReward[1][2].."</color>"..GetLanguageStrById(itemConfig[value.DailyReward[2][1]].Name).."<color=green>+"..value.DailyReward[2][2].."</color>"
this.SeasonReward.text = Language[10095]..GetLanguageStrById(itemConfig[value.SeasonReward[1][1]].Name).."<color=green>+"..value.SeasonReward[1][2].."</color>"..GetLanguageStrById(itemConfig[value.SeasonReward[2][1]].Name).."<color=green>+"..value.SeasonReward[2][2].."</color>"
end
end
end
else
this.DailyReward.text = Language[10096]
this.SeasonReward.text = Language[10097]
end
end
-- 刷新防守编队显示
function this.RefreshDefendFormation()
local formation = FormationManager.GetFormationByID(FormationTypeDef.FORMATION_ARENA_DEFEND)
for i, demon in ipairs(this.Demons) do
demon.frame.sprite = this.spLoader:LoadSprite(GetQuantityImageByquality(1))
demon.hero.gameObject:SetActive(false)
end
for i, hero in ipairs(formation.teamHeroInfos) do
local heroData = HeroManager.GetSingleHeroData(hero.heroId)
this.Demons[hero.position].hero:SetActive(true)
this.Demons[hero.position].levelText.text = heroData.lv
local star,starType = heroData.GetStar(1)
local starSize = Vector2.New(35,35)
local starScale = -8
if starType == 3 then
starSize = Vector2.New(1,-15.65)
starScale = -13
elseif starType == 2 then
starSize = Vector2.New(60,57)
end
SetHeroStars(this.spLoader, this.Demons[hero.position].starGrid , star,starType,starSize,starScale)
--SetHeroFlyEffect(go,this.spLoader,star,this.sortingOrder,1)
Util.SetParticleSortLayer(this.Demons[hero.position].starGrid,this.sortingOrder + 1)
local heroConfig = ConfigManager.GetConfigData(ConfigName.HeroConfig, heroData.id)
this.Demons[hero.position].frame.sprite = this.spLoader:LoadSprite(GetQuantityImageByquality(heroConfig.Quality, heroData.star))
this.Demons[hero.position].icon.sprite = this.spLoader:LoadSprite(heroData.icon)
this.Demons[hero.position].proIcon.sprite = this.spLoader:LoadSprite(GetProStrImageByProNum(heroData.changeProId))
end
end
-- 刷新基础数据显示
function this.RefreshBaseData()
this.ArenaName:GetComponent("Text").text = ArenaManager.GetArenaName()
local baseData = ArenaManager.GetArenaBaseData()
local allNums = baseData.successNums + baseData.failNums
local rate = 0
if allNums ~= 0 then
rate = math.floor(baseData.successNums / allNums * 100)
end
this.Integral:GetComponent("Text").text = Language[10098]..baseData.score
end
-- 开始计时
function this.StartCountTime()
local dayText = Util.GetGameObject(this.ArenaTime,"day"):GetComponent("Text")
local hourText = Util.GetGameObject(this.ArenaTime,"hour"):GetComponent("Text")
local minText = Util.GetGameObject(this.ArenaTime,"min"):GetComponent("Text")
local secText = Util.GetGameObject(this.ArenaTime,"sec"):GetComponent("Text")
local second = ArenaManager.GetLeftTime()
if this.TimeCounter then return end
local function _TimeUpdate()
local day = math.floor(second / (24 * 3600))
local minute = math.floor(second / 60) % 60
local sec = second % 60
local hour = math.floor(math.floor(second - day * 24 * 3600 - sec - minute * 60) / 3600)
dayText.text = day
minText.text = minute
secText.text = sec
hourText.text = hour
second = second -1
if second <= 0 then
if this.parent then
this.parent:ClosePanel()
else
UIManager.OpenPanel(UIName.MainPanel)
end
if this.TimeCounter then
this.TimeCounter:Stop()
this.TimeCounter = nil
end
end
end
_TimeUpdate()
this.TimeCounter = Timer.New(_TimeUpdate, 1, -1, true)
this.TimeCounter:Start()
end
-- 刷新敌人列表
function this.RefreshEnemyData()
local prefab = {}
local leftTimes = ArenaManager.GetArenaChallengeTimes()
this.freeTimes.text = string.format("%s次", math.max(leftTimes, 0))
local EnemyList = ArenaManager.GetEnemyList()
table.sort(EnemyList, function(a,b) return a.personInfo.score > b.personInfo.score end)
for i, node in ipairs(this.Enemys) do
node:SetActive(false)
if EnemyList[i] then
table.insert(prefab,node)
local lv_name = Util.GetGameObject(node, "name")
local integral = Util.GetGameObject(node, "integralTip")
-- Util.GetGameObject(node, "power"):SetActive(false)
-- Util.GetGameObject(node, "integral"):SetActive(false)
local power = Util.GetGameObject(node, "powerTip")
local headroot = Util.GetGameObject(node, "headroot")
local bg = Util.GetGameObject(node, "bg")
local btnText = Util.GetGameObject(node, "challenge/Text"):GetComponent("Text")
local btnItem = Util.GetGameObject(node, "challenge/item"):GetComponent("Image")
local btnItemNum = Util.GetGameObject(node, "challenge/item/num"):GetComponent("Text")
lv_name:GetComponent("Text").text = PracticeManager.SetNameColor(JingJiShouWeiToEn(EnemyList[i].personInfo.name),EnemyList[i].personInfo.practiceLevel)
integral:GetComponent("Text").text = Language[11693].. EnemyList[i].personInfo.score
power:GetComponent("Text").text = Language[12179]..EnemyList[i].personInfo.totalForce
btnText.gameObject:SetActive(leftTimes > 0)
btnText.text = Language[10099]
btnItem.gameObject:SetActive(leftTimes <= 0)
if leftTimes <= 0 then
local itemId, needNum = ArenaManager.GetArenaChallengeCost()
local haveNum = BagManager.GetItemCountById(itemId)
btnItem.sprite = SetIcon(this.spLoader, itemId)
btnItemNum.text = "×"..needNum
btnItemNum.color = haveNum < needNum and UIColor.NOT_ENOUGH_RED or UIColor.BTN_TEXT
end
if not this.HeadList then
this.HeadList = {}
end
if not this.HeadList[i] then
this.HeadList[i] = SubUIManager.Open(SubUIConfig.PlayerHeadView, headroot.transform)
end
this.HeadList[i]:Reset()
this.HeadList[i]:SetHead(EnemyList[i].personInfo.head)
this.HeadList[i]:SetFrame(EnemyList[i].personInfo.headFrame)
this.HeadList[i]:SetLevel(EnemyList[i].personInfo.level)
this.HeadList[i]:SetScale(Vector3.one*0.8)
this.HeadList[i]:SetLayer(this.sortingOrder)
this.HeadList[i]:SetEffectScale(0.85)
Util.AddOnceClick(bg, function()
UIManager.OpenPanel(UIName.PlayerInfoPopup, EnemyList[i].personInfo.uid, PLAYER_INFO_VIEW_TYPE.ARENA)
end)
end
end
SecTorPlayAnim(prefab)
end
--显示上边积分奖励
function this.ShowRewardBoxProgressData()
local baseData = ArenaManager.GetArenaBaseData()
local allNums = baseData.successNums + baseData.failNums
local allBoxGetState = ArenaManager.GetHadTakeBoxData()
local maxNum = 0
for _, configInfo in ConfigPairs(ConfigManager.GetConfig(ConfigName.ArenaBattleReward)) do
if configInfo.BattleTimes > maxNum then
maxNum = configInfo.BattleTimes
end
end
for i = 1, #rewardBoxBtn do
if arenaBattleReward[i] then
local state = 1--1 未完成 2 未领取 3 已完成allNums >= arenaBattleReward[i].BattleTimes and false
if allNums < arenaBattleReward[i].BattleTimes then
state = 1
elseif allNums >= arenaBattleReward[i].BattleTimes and not allBoxGetState[i] then
state = 2
else
state = 3
end
Util.GetGameObject(rewardBoxBtn[i], "redPoint"):SetActive(state == 2)
Util.GetGameObject(rewardBoxBtn[i], "Text"):GetComponent("Text").text = arenaBattleReward[i].BattleTimes..Language[10048]
Util.GetGameObject(rewardBoxBtn[i], "getFinish"):SetActive(state == 3)
Util.AddOnceClick(rewardBoxBtn[i], function()
if state == 1 then
UIManager.OpenPanel(UIName.BoxRewardShowPopup,arenaBattleReward[i].Reward,rewardBoxBtn[i].transform.localPosition.x,-400,arenaBattleReward[i].BattleTimes .. Language[10100])
return
elseif state == 3 then
PopupTipPanel.ShowTip(Language[10101])
return
elseif state == 2 then
NetManager.TakeArenaBattleRewardRequest(i, function(msg)
UIManager.OpenPanel(UIName.RewardItemPopup, msg.drop, 1,function ()
this.ShowRewardBoxProgressData()
CheckRedPointStatus(RedPointType.Arena_Reward)
end)
end)
end
end)
end
end
this.progressImage.fillAmount = allNums/maxNum
this.progressTipText.text = Language[10102]..allNums..Language[10048]
end
-- 层级改变回调
local orginLayer = 0
function ArenaView:OnSortingOrderChange(sort)
Util.AddParticleSortLayer(this.effect, sort - orginLayer)
--
for i, node in ipairs(this.Enemys) do
if this.HeadList and this.HeadList[i] then
this.HeadList[i]:SetLayer(sort)
end
end
for i, demon in ipairs(this.Demons) do
Util.SetParticleSortLayer(demon.starGrid,sort + 1)
end
orginLayer = sort
end
--界面关闭时调用(用于子类重写)
function ArenaView:OnClose()
if this.TimeCounter then
this.TimeCounter:Stop()
this.TimeCounter = nil
end
end
function ArenaView:OnDestroy()
this.spLoader:Destroy()
for _, head in ipairs(this.HeadList) do
head:Recycle()
end
this.HeadList= nil
this.Demons = {}
end
return ArenaView