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

257 lines
9.5 KiB
Lua

require("Base/BasePanel")
WorldArenaUpRewardPanel = Inherit(BasePanel)
local this = WorldArenaUpRewardPanel
local RankConfig = ConfigManager.GetConfig(ConfigName.MServerRankConfig)
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
local lastRankId = 0
local currRankId = 0
local lastScore = 0
local currScore = 0
local rankData
local maxScore
local minScore
local layer
local aaa
--初始化组件(用于子类重写)
function WorldArenaUpRewardPanel:InitComponent()
this.spLoader = SpriteLoader.New()
this.titleImg = Util.GetGameObject(self.gameObject, "Bg/bg/title"):GetComponent("Image")
this.titleObj = Util.GetGameObject(self.gameObject, "Bg/bg")
this.titleImg.sprite = this.spLoader:LoadSprite("y_yuxulundao_duanweichongzhi_zh")
this.rankName = Util.GetGameObject(self.gameObject, "Bg/rankName"):GetComponent("Text")
this.rankImg = Util.GetGameObject(self.gameObject, "Bg/RankImg")
this.scoreTxt = Util.GetGameObject(self.gameObject, "Bg/hangOnTime"):GetComponent("Text")
this.text1 = Util.GetGameObject(self.gameObject, "Bg/upRewardObj/userNameText"):GetComponent("Text")
this.text1.text = Language[12988]
this.tipImg = Util.GetGameObject(self.gameObject, "tipImage"):GetComponent("Image")
this.tipImg.sprite = this.spLoader:LoadSprite("r_zhandou_rewardtap2_zh")
this.rewardObj = Util.GetGameObject(self.gameObject, "Bg/upRewardObj")
this.rewardObj:SetActive(false)
this.grid = Util.GetGameObject(self.gameObject, "Bg/upRewardObj/scroll/grid")
this.progress = Util.GetGameObject(self.gameObject, "Bg/progressbar/progress"):GetComponent("Image")
this.btn_close = Util.GetGameObject(self.gameObject, "maskImage")
this.starList = {}
for i = 1, 5 do
table.insert(this.starList, Util.GetGameObject(self.gameObject, "Bg/starPar/Image" .. i))
end
end
--绑定事件(用于子类重写)
function WorldArenaUpRewardPanel:BindEvent()
Util.AddClick(self.btn_close, function()
self:ClosePanel()
end)
end
local titleLive
local currRank
local newResore
function WorldArenaUpRewardPanel:OnOpen(data)
--赛季重制显示重置图标
if data then
this.titleObj.gameObject:SetActive(true)
else
this.titleObj.gameObject:SetActive(false)
end
lastScore = PlayerPrefs.GetInt(PlayerManager.uid .. "yuxulundaoScore")
aaa, rankData = WorldArenaManager.GetRankImgByScore(lastScore)
currScore = WorldArenaManager.GetNewScore()
lastRankId = rankData.Id
newResore = WorldArenaManager.GetNewScore()
LogError("upwindow lastScore==" .. lastScore .. " newScore==" .. newResore)
local grade, newRankData = WorldArenaManager.GetRankImgByScore(WorldArenaManager.GetNewScore())
currRankId = newRankData.Id
--rankData=RankConfig[lastRankId]
minScore = rankData.ScoreLow
maxScore = rankData.ScoreUp
currRank = rankData.RankGrade + 1
titleLive = poolManager:LoadAsset("fx_duanwei_0" .. currRank, PoolManager.AssetType.GameObject)
titleLive.transform:SetParent(this.rankImg.transform)
titleLive.transform.localPosition = Vector3.New(0, -600, 0)
titleLive.transform.localScale = Vector3.New(1, 1, 1)
SetParticleSortLayer(titleLive, self.sortingOrder)
if not rankData then
return
end
this.rankName.text = GetLanguageStrById(rankData.RankName)
this.scoreTxt.text = lastScore .. "/" .. rankData.ScoreUp
this.progress.fillAmount = (lastScore - minScore) / (maxScore - minScore)
--currRank=rankData.RankGrade
this.SetStarShow(rankData.RankLevel, rankData.RankGrade + 1, self.sortingOrder)
this.StartProgressChange(function()
local callList2 = Stack.New()
local itemRandomDataList = {}
local aaa = {}
aaa.itemlist = {}
aaa.itemlist = WorldArenaManager.GetReward()
LogError("itemlist len==" .. #WorldArenaManager.GetReward())
LogError("aaa.itemlist len==" .. #aaa.itemlist)
if aaa.itemlist and #aaa.itemlist > 0 then
itemRandomDataList = BagManager.GetTableByBackDropData(aaa)
local baseContentList2 = {}
this.SetItemShow(aaa, itemRandomDataList, this.grid.transform, callList2, baseContentList2)
end
end)
end
--星级和段位图标显示
function this.SetStarShow(star, grade, layer)
-- 设置星级
WorldArenaManager.SetStarShow(this.starList, rankData.RankLevel)
if currRank ~= grade then
if titleLive then
destroy(titleLive)
titleLive = nil
currRank = grade
titleLive = poolManager:LoadAsset("fx_duanwei_0" .. grade, PoolManager.AssetType.GameObject)
titleLive.transform:SetParent(this.rankImg.transform)
if grade == 5 then
titleLive.transform.localPosition = Vector3.New(0, -500, 0)
titleLive.transform.localScale = Vector3.New(0.8, 0.8, 1)
else
titleLive.transform.localPosition = Vector3.New(0, -600, 0)
titleLive.transform.localScale = Vector3.New(1, 1, 1)
end
SetParticleSortLayer(titleLive, layer)
end
this.rankName.text = rankData.RankName
end
end
-- 根据物品列表数据显示物品
function this.SetItemShow(drop, dataList, transform, callList, baseContentList)
this.rewardObj:SetActive(true)
BagManager.OnShowTipDropNumZero(drop)
if drop == nil then return end
for i = 1, #dataList do
dataList[i].itemConfig = itemConfig[dataList[i].sId]
end
--self:ItemDataListSort(dataList)
for i = 1, math.max(#dataList, #baseContentList) do
local go = baseContentList[i]
if not go then
go = SubUIManager.Open(SubUIConfig.ItemView, transform)
go.gameObject.name = "frame" .. i
baseContentList[i] = go
end
go.gameObject:SetActive(false)
end
callList:Clear()
for i = #dataList, 1, -1 do
local view = baseContentList[i]
local curItemData = dataList[i]
view:OnOpen(true, curItemData, 1.15, true, true, false, layer)
--view.gameObject:SetActive(false)
callList:Push(function()
local func = function()
view.gameObject:SetActive(true)
local btn = Util.GetGameObject(view.gameObject, "item/frame"):GetComponent("Button")
btn.enabled = false
PlayUIAnim(view.gameObject, function()
btn.enabled = true
end)
Timer.New(function()
isPopGetSSR = false
if callList:Count() ~= 0 then
callList:Pop()()
end
end, 0.1):Start()
end
func()
end)
end
if callList:Count() ~= 0 then
callList:Pop()()
end
end
function WorldArenaUpRewardPanel:OnSortingOrderChange()
layer = self.sortingOrder
if titleLive then
SetParticleSortLayer(titleLive, self.sortingOrder)
end
end
--滚动条数
local num = 0
--走的条数
local walkNum = 0
local changeNum = 1
--开始进度条滚动
function this.StartProgressChange(func)
if this.TimeCounter then
this.TimeCounter = nil
end
local function _TimeUpdate()
--降低
if lastScore < currScore then
if maxScore - lastScore > 15 and currScore - lastScore > 15 then
changeNum = 12
else
changeNum = 1
end
lastScore = lastScore + changeNum
--经验条走到头
if lastScore == maxScore + 1 then
walkNum = walkNum + 1
if RankConfig[lastRankId + 1] then
lastRankId = lastRankId + 1
rankData = RankConfig[lastRankId]
maxScore = rankData.ScoreUp
minScore = rankData.ScoreLow
this.SetStarShow(rankData.RankLevel, rankData.RankGrade + 1, layer)
end
end
else
if lastScore - minScore > 15 and lastScore - currScore > 15 then
changeNum = 12
else
changeNum = 1
end
lastScore = lastScore - changeNum
if lastScore == minScore - 1 then
walkNum = walkNum + 1
if RankConfig[lastRankId - 1] then
lastRankId = lastRankId - 1
rankData = RankConfig[lastRankId]
maxScore = rankData.ScoreUp
minScore = rankData.ScoreLow
this.SetStarShow(rankData.RankLevel, rankData.RankGrade + 1, layer)
end
end
end
this.scoreTxt.text = lastScore .. "/" .. maxScore
this.progress.fillAmount = (lastScore - minScore) / (maxScore - minScore)
--走完了所有条目走最后半截
if lastScore == currScore then
if this.TimeCounter then
this.TimeCounter:Stop()
this.TimeCounter = nil
if func then
func()
end
end
end
end
this.TimeCounter = Timer.New(_TimeUpdate, 0.005, -1, true)
this.TimeCounter:Start()
end
function this:OnClose()
WorldArenaManager.ClearReward()
PlayerPrefs.SetInt(PlayerManager.uid .. "yuxulundaoScore", newResore)
if this.TimeCounter then
this.TimeCounter:Stop()
this.TimeCounter = nil
end
if titleLive then
destroy(titleLive)
titleLive = nil
end
end
return WorldArenaUpRewardPanel