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

476 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 WorldArenaMainPanel = Inherit(BasePanel)
local this = WorldArenaMainPanel
local arenaBattleReward = ConfigManager.GetConfig(ConfigName.ArenaBattleReward)
local MServerRankConfig=ConfigManager.GetConfig(ConfigName.MServerRankConfig)
local rewardBoxBtn
local titleLive
local myRank=0
local leftTimes=0
local battleTimes=0
local challengeTime=0
local rewardState=nil
local enemyList={}
local freeTimes=0
--初始化组件(用于子类重写)
function WorldArenaMainPanel:InitComponent()
this.spLoader = SpriteLoader.New()
this.btnBack = Util.GetGameObject(self.gameObject, "btnBack")
this.ArenaName = Util.GetGameObject(self.gameObject, "nameImg/name")
this.ArenaTime = Util.GetGameObject(self.gameObject, "timelab")
this.Integral = Util.GetGameObject(self.gameObject, "myScore/integral"):GetComponent("Text")
this.endTime = Util.GetGameObject(self.gameObject, "myScore/Text"):GetComponent("Text")
this.rankPar= Util.GetGameObject(self.gameObject, "center/ranks")
this.rankName= Util.GetGameObject(self.gameObject, "center/Text"):GetComponent("Text")
this.StarList={}
for i = 1, 5 do
table.insert(this.StarList, Util.GetGameObject(self.gameObject, "starPar/Image"..i))
end
this.Enemys = {}
for i = 1, 5 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.FormationBtn = Util.GetGameObject(self.gameObject, "rightUp/formationBtn")
--this.rank=Util.GetGameObject(this.myRank,"Rank"):GetComponent("Text")
this.power=Util.GetGameObject(self.gameObject,"powerImg/Power"):GetComponent("Text")
--宝箱部分
this.progressImage = Util.GetGameObject(self.gameObject, "finalTarget/progressbar/progress"):GetComponent("Image")
this.progressTipText = Util.GetGameObject(self.gameObject, "finalTarget/Text (1)"):GetComponent("Text")
rewardBoxBtn = {}
this.freeTimes = Util.GetGameObject(self.gameObject, "count/text"):GetComponent("Text")
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.UpView = SubUIManager.Open(SubUIConfig.UpView, self.transform, { showType = UpViewOpenType.ShowLeft})
this.OpenView()
end
--绑定事件(用于子类重写)
function WorldArenaMainPanel:BindEvent()
Util.AddClick(this.btnBack, function()
PlaySoundWithoutClick(SoundConfig.Sound_UICancel)
this:ClosePanel()
end)
-- 防守编队
Util.AddClick(this.FormationBtn, function()
-- if not ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.ARENA) then
-- PopupTipPanel.ShowTip(Language[10075])
-- return
-- end
UIManager.OpenPanel(UIName.WorldArenaMyTeamPanel,1)
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.JumpServer_YuXu) then
PopupTipPanel.ShowTip(Language[10075])
return
end
-- 只在活动时间范围内可点
-- if ArenaManager.GetLeftTime() > 0 then
-- 添加次数限制
leftTimes = PrivilegeManager.GetPrivilegeRemainValue(0)
if leftTimes <= 0 then
local itemId, needNum = WorldArenaManager.GetArenaChallengeCost()
local haveNum = BagManager.GetItemCountById(itemId)
if haveNum < needNum then
UIManager.OpenPanel(UIName.QuickPurchasePanel, { type = UpViewRechargeType.ChallengeTicket })
PopupTipPanel.ShowTip("挑战券不足!")
return
end
end
NetManager.CrossYuXuLunDaoChallengeBeforeRequest(PlayerManager.uid,enemyList[i],function(msg)
LogError("open battleinfo ???")
UIManager.OpenPanel(UIName.WorldArenaBattleInfoPanel,msg,1, function()
self:RefreshChallengeList()
end)
end)
-- else
-- PopupTipPanel.ShowTip(Language[10092])
-- end
end)
end
--排行
Util.AddClick(this.sortBtn, function()
UIManager.OpenPanel(UIName.RankingSingleListPanel,rankKingList[31])
end)
-- 刷新按钮
this._RefreshTimeStemp=0
Util.AddClick(this.RefreshBtn, function()
local curTimeStemp = GetTimeStamp()
local limitTime = 3
-- 计算距离下一次刷新剩余时间
local lastTime = math.floor(limitTime - (curTimeStemp - this._RefreshTimeStemp))
if this._RefreshTimeStemp ~= 0 and lastTime > 0 then
PopupTipPanel.ShowTip(lastTime..Language[10079])
return
end
this._RefreshTimeStemp = curTimeStemp
self:RefreshChallengeList()
end)
-- 记录按钮
Util.AddClick(this.RecordBtn, function()
if not ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.JumpServer_YuXu) then
PopupTipPanel.ShowTip(Language[10075])
return
end
NetManager.CrossYuXuLunDaoBattleRecordRequest(PlayerManager.uid,function(msg)
UIManager.OpenPanel(UIName.WorldArenaRecordPopup,msg.recordData)
end)
-- ResetServerRedPointStatus(RedPointType.WorldArena_Record)
end)
-- 帮助按钮
Util.AddClick(this.helpBtn, function()
UIManager.OpenPanel(UIName.HelpPopup,HELP_TYPE.YuXu,this.helpPosition.x,this.helpPosition.y)
end)
-- 奖励按钮
Util.AddClick(this.RewardBtn, function()
UIManager.OpenPanel(UIName.WorldArenaRankRewardPanel,myRank)
end)
--商店按钮
Util.AddClick(this.StoreBtn, function()
if not ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.JumpServer_YuXu) then
PopupTipPanel.ShowTip(Language[10075])
return
end
JumpManager.GoJump(40032)
end)
end
-- 刷新挑战列表
function WorldArenaMainPanel:RefreshChallengeList()
if not ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.ARENA) then
PopupTipPanel.ShowTip(Language[10075])
return
end
NetManager.CrossYuXuLunDaoChangeEnemyInfoRequest(function(msg)
PlaySoundWithoutClick("UI_refresh")
this:RefreshEnemyData(msg.arenaEnemys)
end)
end
--添加事件监听(用于子类重写)
function WorldArenaMainPanel:AddListener()
--BindRedPointObject(RedPointType.WorldArena_Record, Util.GetGameObject(self.gameObject, "record/redpot"))
end
--移除事件监听(用于子类重写)
function WorldArenaMainPanel:RemoveListener()
-- ClearRedPointObject(RedPointType.WorldArena_Record)
end
local grid, rankData
--界面打开时调用(用于子类重写)
local oldScore
function WorldArenaMainPanel:OnOpen(...)
-- 参数保存
local args = {...}
NetManager.CrossYuXuLunDaoGetInfoRequest(function(msg)
local currRankId=msg.newLevelId
LogError(" newMyscore=="..msg.newMyscore.." oldmyscore=="..msg.oldMyscore)
grid, rankData=WorldArenaManager.GetRankImgByScore(msg.newMyscore)
oldScore=msg.oldMyscore
--新赛季本地数据制成0
if msg.drop and #msg.drop>0 then
LogError("有充值奖励")
WorldArenaManager.AddReward(msg.drop)
PlayerPrefs.SetInt(PlayerManager.uid.."yuxulundaoScore",0)
end
myRank=msg.myRank
rewardState=msg.dailyRewardState
challengeTime=msg.changedTimes
freeTimes=PrivilegeManager.GetPrivilegeRemainValue(0)
WorldArenaManager.SetNewScore(msg.newMyscore)
WorldArenaManager.SetMyData(myRank,challengeTime)
this.Integral.text="积分:"..msg.newMyscore
LogError("self.sorlayer=="..self.sortingOrder)
this.SetStarShow(grid,self.sortingOrder)
this.endTime.text="周日23:30赛季结束"
this:RefreshEnemyData(msg.arenaEnemys)
LogError(" main panel".." battletime=="..challengeTime.." rank=="..myRank.."freeTimes=="..freeTimes)
if freeTimes==0 then
this.freeTimes.gameObject:SetActive(false)
this.freeTimes.transform.parent.gameObject:SetActive(false)
end
this.freeTimes.text = string.format("%s次", math.max(freeTimes, 0))
--检测段位是否发生变化
if msg.updrop and #msg.updrop>0 then
LogError("有升级奖励")
WorldArenaManager.AddReward(msg.updrop)
end
this.CheckIsRankChange(msg.updrop)
if msg.isFirst then
FormationManager.RefreshFormationData()
end
end)
end
--星级和段位图标显示
function this.SetStarShow(grade,layer)
-- 设置星级
WorldArenaManager.SetStarShow(this.StarList, rankData.RankLevel)
if titleLive then
destroy(titleLive)
titleLive=nil
end
titleLive = poolManager:LoadAsset("fx_duanwei_0"..grade, PoolManager.AssetType.GameObject)
titleLive.transform:SetParent(this.rankPar.transform)
titleLive.transform.localPosition=Vector3.New(0,-600,0)
titleLive.transform.localScale =Vector3.New(1,1,1)
SetParticleSortLayer(titleLive,layer)
this.rankName.text=rankData.RankName
--this.RefreshEnemyData()
this.ShowRewardBoxProgressData()
end
--显示上边积分奖励
function this.ShowRewardBoxProgressData()
-- local baseData = ArenaManager.GetArenaBaseData()
local allNums = WorldArenaManager.GetchallengeTimes()
--宝箱领取状态
local allBoxGetState = rewardState
local maxNum = 0
local config=ConfigManager.GetConfigDataByKey(ConfigName.MServerRankConfig,1)
local rewards=config.DailyReward
for i = 1, #rewards do
if rewards[i][1]>maxNum then
maxNum=rewards[i][1]
end
end
for i = 1, #rewardBoxBtn do
if rewards[i] then
local state = 1--1 未完成 2 未领取 3 已完成allNums >= arenaBattleReward[i].BattleTimes and false
--LogError("allnum=="..allNums.." rewards[i][1]== "..rewards[i][1].." boxstate=="..allBoxGetState[i])
if allNums < rewards[i][1] then
state = 1
elseif allNums >= rewards[i][1] and allBoxGetState[i]~=2 then
state = 2
else
state = 3
end
Util.GetGameObject(rewardBoxBtn[i], "redPoint"):SetActive(state == 2)
Util.GetGameObject(rewardBoxBtn[i], "Text"):GetComponent("Text").text = rewards[i][1]..Language[10048]
Util.GetGameObject(rewardBoxBtn[i], "getFinish"):SetActive(state == 3)
Util.AddOnceClick(rewardBoxBtn[i], function()
if state == 1 then
UIManager.OpenPanel(UIName.BoxRewardShowPopup,{{rewards[i][2], rewards[i][3]}},rewardBoxBtn[i].transform.localPosition.x,-400,rewards[i][1] .. Language[10100])
return
elseif state == 3 then
PopupTipPanel.ShowTip(Language[10101])
return
elseif state == 2 then
NetManager.CrossYuXuLunDaoGetDailyRewardRequest(i, function(msg)
allBoxGetState[i]=2
--this.ShowRewardBoxProgressData()
UIManager.OpenPanel(UIName.RewardItemPopup, msg.drop, 1,function ()
CheckRedPointStatus(RedPointType.Arena_Reward)
end)
end)
end
end)
end
end
this.progressImage.fillAmount = allNums/maxNum
this.progressTipText.text = "今日挑战"
end
-- 刷新敌人列表
function this:RefreshEnemyData(team)
local prefab = {}
--local leftTimes=time
table.sort(team, function(a,b) return a.score > b.score end)
local EnemyList =team -- ArenaManager.GetEnemyList()
enemyList={}
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"):GetComponent("Text")
local integral = Util.GetGameObject(node, "integralTip"):GetComponent("Text")
-- 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")
local rankImg= Util.GetGameObject(node, "rankImg"):GetComponent("Image")
local rankId=WorldArenaManager.GetRankImgByScore(EnemyList[i].score)
rankImg.sprite=this.spLoader:LoadSprite("y_yuxulundao_xiaobiao_0"..rankId)
local name=EnemyList[i].servername.." "..EnemyList[i].name
lv_name.text = PracticeManager.SetNameColor(JingJiShouWeiToEn(name),EnemyList[i].practiceLevel)
integral:GetComponent("Text").text = Language[11693].. EnemyList[i].score
power:GetComponent("Text").text = Language[12179]..EnemyList[i].totalForce
btnText.gameObject:SetActive(freeTimes > 0)
btnText.text = Language[10099]
btnItem.gameObject:SetActive(freeTimes <= 0)
if freeTimes <= 0 then
local itemId, needNum = WorldArenaManager.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].head)
this.HeadList[i]:SetFrame(EnemyList[i].headFrame)
this.HeadList[i]:SetLevel(EnemyList[i].level)
this.HeadList[i]:SetScale(Vector3.one*0.8)
this.HeadList[i]:SetLayer(self.sortingOrder)
this.HeadList[i]:SetEffectScale(0.85)
table.insert(enemyList,EnemyList[i].uid)
Util.AddOnceClick(bg, function()
LogError("uid=="..EnemyList[i].uid)
UIManager.OpenPanel(UIName.WorldArenaOtherTeamPanel, EnemyList[i].uid,1)
end)
end
end
SecTorPlayAnim(prefab)
end
function WorldArenaMainPanel:OnFocus()
local newScore=WorldArenaManager.GetNewScore()
grid,rankData=WorldArenaManager.GetRankImgByScore(newScore)
this.SetStarShow(grid,self.sortingOrder)
this.Integral.text="积分:"..newScore
freeTimes=PrivilegeManager.GetPrivilegeRemainValue(0)
this.freeTimes.text = string.format("%s次", math.max(freeTimes, 0))
this.CheckIsRankChange()
this.ShowRewardBoxProgressData()
for key, value in ipairs(this.Enemys) do
local btnText = Util.GetGameObject(value, "challenge/Text"):GetComponent("Text")
local btnItem = Util.GetGameObject(value, "challenge/item"):GetComponent("Image")
local btnItemNum = Util.GetGameObject(value, "challenge/item/num"):GetComponent("Text")
btnText.gameObject:SetActive(freeTimes > 0)
btnText.text = Language[10099]
btnItem.gameObject:SetActive(freeTimes <= 0)
if freeTimes <= 0 then
local itemId, needNum = WorldArenaManager.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
end
end
function this.CheckIsRankChange(resetData)
local lastScore=PlayerPrefs.GetInt(PlayerManager.uid.."yuxulundaoScore")
LogError("lastscore=="..lastScore)
local aa,oldData=WorldArenaManager.GetRankImgByScore(lastScore)
if oldData.Id~=rankData.Id then
UIManager.OpenPanel(UIName.WorldArenaUpRewardPanel,resetData)
end
end
-- 打开,重新打开时回调
function WorldArenaMainPanel:OnShow()
SoundManager.PlayMusic(SoundConfig.BGM_Arena)
local allDamage=0
for i = 2001, 2003 do
allDamage=allDamage+FormationManager.GetFormationPower(i)
end
this.power.text=allDamage
end
function WorldArenaMainPanel:OnSortingOrderChange(order)
--this.sortingOrder=order
if titleLive then
SetParticleSortLayer(titleLive,self.sortingOrder)
end
end
--界面关闭时调用(用于子类重写)
function WorldArenaMainPanel:OnClose()
end
--界面销毁时调用(用于子类重写)
function WorldArenaMainPanel:OnDestroy()
SubUIManager.Close(this.UpView)
if titleLive then
destroy(titleLive)
titleLive=nil
end
-- 清除红点
-- ClearRedPointObject(RedPointType.Arena_Shop)
this.spLoader:Destroy()
if this.shopView then
this.shopView.gameObject:SetActive(true) -- 重置一下显示状态,避免其他界面打开时状态错误
this.shopView = SubUIManager.Close(this.shopView)
this.shopView = nil
end
if this.HeadList then
for i = 1, #this.HeadList do
this.HeadList[i]:Recycle()
this.HeadList[i]=nil
end
end
end
--
function this.OpenView()
-- 货币界面
this.UpView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = PanelType.WorldArena })
end
function this.CloseView(index)
if this._CurLogicIndex ~= index then return end
-- 商店界面特殊处理
if index == 3 then
if this.shopView then
this.shopView.gameObject:SetActive(false)
end
return
end
local logic = this.ViewLogicList[index]
if logic then
if logic.RemoveListener then
logic:RemoveListener()
end
if logic.OnClose then
logic:OnClose()
end
logic.gameObject:SetActive(false)
end
end
return WorldArenaMainPanel