miduo_client/Assets/ManagedResources/~Lua/Modules/DemonSlayer/DemonSlayerPanel.lua

297 lines
10 KiB
Lua

require("Base/BasePanel")
local DemonSlayerPanel = Inherit(BasePanel)
local this = DemonSlayerPanel
local sortingOrder = 0
local allData={}
local actRankConfig = ConfigManager.GetConfig(ConfigName.ActivityRankingReward)
local itemsGrid = {}--item重复利用
local state = 0
local isPlayAnim = true
local allRankData,myRankData
local npcList={}
local rankImage={
[1] = "r_playerrumble_paiming_01",
[2] = "r_playerrumble_paiming_02",
[3] = "r_playerrumble_paiming_03",
}
--初始化组件(用于子类重写)
function DemonSlayerPanel:InitComponent()
this.spLoader = SpriteLoader.New()
this.btnBack = Util.GetGameObject(self.gameObject,"BackBtn")
this.helpBtn = Util.GetGameObject(self.gameObject,"HelpBtn")
this.btnRank = Util.GetGameObject(self.gameObject,"RankList")
this.timeText = Util.GetGameObject(self.gameObject, "rewardContent/time"):GetComponent("Text")
this.myRank = Util.GetGameObject(self.gameObject, "rewardContent/myRank/num"):GetComponent("Text")
this.pos = Util.GetGameObject(self.gameObject, "pos")
this.itemPre = Util.GetGameObject(self.gameObject, "rewardContent/reward/itemPre")
this.scrollItem = Util.GetGameObject(self.gameObject, "rewardContent/reward/grid")
local rootHight = this.scrollItem.transform.rect.height
local width = this.scrollItem.transform.rect.width
this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, this.scrollItem.transform,
this.itemPre, nil, Vector2.New(width, rootHight), 1, 1, Vector2.New(0, 0))
this.ScrollView.moveTween.MomentumAmount = 1
this.ScrollView.moveTween.Strength = 2
this.ScrollView.elastic = false
end
--绑定事件(用于子类重写)
function DemonSlayerPanel:BindEvent()
Util.AddClick(this.btnBack, function()
self:ClosePanel()
end)
Util.AddClick(this.helpBtn, function()
local pos = this.helpBtn.transform.localPosition
UIManager.OpenPanel(UIName.HelpPopup, HELP_TYPE.DemonSlayer, pos.x, pos.y)
end)
Util.AddClick(this.btnRank, function()
if state == 0 then
UIManager.OpenPanel(UIName.RankingSingleListPanel,rankKingList[4])
elseif state == 1 then
UIManager.OpenPanel(UIName.RankingSingleListPanel,rankKingList[11])
end
end)
end
--添加事件监听(用于子类重写)
function DemonSlayerPanel:AddListener()
end
--移除事件监听(用于子类重写)
function DemonSlayerPanel:RemoveListener()
end
--界面打开时调用(用于子类重写)
function DemonSlayerPanel:OnOpen()
end
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
function DemonSlayerPanel:OnShow()
isPlayAnim = true
DemonSlayerPanel:Refresh()
end
function DemonSlayerPanel:Refresh()
local ActInfo = ActivityGiftManager.GetActivityTypeInfo(ActivityTypeDef.DemonSlayer)
DemonSlayerPanel:SetState(ActInfo)
DemonSlayerPanel:SetRank(ActInfo)
DemonSlayerPanel:OnShowData(ActInfo)
DemonSlayerPanel:SetTime(ActInfo)
end
function DemonSlayerPanel:SetRank(ActInfo)
if state == 0 then
RankingManager.InitData(RANK_TYPE.MONSTER_RANK,function ()
allRankData,myRankData = RankingManager.GetRankingInfo()
if not myRankData.rank or (myRankData.rank and myRankData.rank < 1) then--排名对比 <0未上榜
this.myRank.text = Language[10036] --未上榜
else
this.myRank.text = myRankData.rank --上榜
end
for i = 1, 3 do
local item = Util.GetGameObject(this.pos,"pos"..i.."/name"):GetComponent("Text")
item.text = Language[10423]
end
end)
elseif state == 1 then
RankingManager.InitData(RANK_TYPE.GOLD_EXPER,function ()
allRankData,myRankData = RankingManager.GetRankingInfo()
if not myRankData.rank or (myRankData.rank and myRankData.rank < 1) then--排名对比 <0未上榜
this.myRank.text = Language[10036] --未上榜
else
this.myRank.text = myRankData.rank --上榜
end
for i = 1, 3 do
local item = Util.GetGameObject(this.pos,"pos"..i.."/name"):GetComponent("Text")
local image = Util.GetGameObject(this.pos,"pos"..i.."/ren"):GetComponent("Image")
local livePrefab = Util.GetGameObject(this.pos,"pos"..i.."/ren")
if allRankData[i] then
image.enabled = false
item.text = allRankData[i].userName
if npcList[i] then
npcList[i]:OnClose()
end
local curPlayerLiveViewData = {
skin = allRankData[i].userSkin,
ride = allRankData[i].userMount,
sex = allRankData[i].sex,
designation = allRankData[i].userTitle
}
npcList[i] = PlayerLiveView:New(livePrefab.transform,2, curPlayerLiveViewData)
if curPlayerLiveViewData.ride and curPlayerLiveViewData.ride > 0 then
npcList[i]:OnOpen(GetPlayerRoleSingleConFig().Scale11,Vector3.New(0,-102.73,0),WALK_DIR.IDLE_LEFT)
else
npcList[i]:OnOpen(GetPlayerRoleSingleConFig().Scale11,Vector3.New(0,-102.73,0),WALK_DIR.IDLE_FRONT)
end
else
image.enabled = true
item.text = Language[10423]
end
end
end,ActInfo.activityId)
end
end
function DemonSlayerPanel:SetState(ActInfo)
local extraTime = ConfigManager.GetConfigData(ConfigName.GlobalActivity,ActInfo.activityId).GapTime*86400
local time1 = ActInfo.endTime - GetTimeStamp()
state = time1 - extraTime > 0 and 0 or 1
end
function DemonSlayerPanel:OnShowData(ActInfo)
allData={}
local prefab = {}
allData = ConfigManager.GetAllConfigsDataByKey(ConfigName.ActivityRankingReward,"ActivityId",ActInfo.activityId)
if allData then
this.ScrollView:SetData(allData, function (index, go)
table.insert(prefab,go)
DemonSlayerPanel:SingleDataShow(go, allData[index],index)
end)
end
if isPlayAnim then
SecTorPlayAnim(prefab)
isPlayAnim = false
end
end
function DemonSlayerPanel:SingleDataShow(pre,data,index)
local rank = Util.GetGameObject(pre,"rank")
local rank2 = Util.GetGameObject(pre,"rank2")
local num = Util.GetGameObject(pre,"rank/num")
local rewards = Util.GetGameObject(pre,"rewards")
local shows = data.RankingReward
if index<4 then
rank2:GetComponent("Image").sprite = this.spLoader:LoadSprite(rankImage[index])
num:SetActive(false)
rank:SetActive(false)
rank2:SetActive(true)
else
num:SetActive(true)
rank2:SetActive(false)
rank:SetActive(true)
if data.MaxRank > 200 then
num:GetComponent("Text").text = (data.MinRank-1).."+"
else
num:GetComponent("Text").text = data.MinRank.."-"..data.MaxRank
end
end
--滚动条复用重设itemview
if itemsGrid[pre] then
for i = 1, 5 do
itemsGrid[pre][i].gameObject:SetActive(false)
end
for i = 1, #shows do
if itemsGrid[pre][i] then
itemsGrid[pre][i]:OnOpen(false, {shows[i][1],shows[i][2]}, 0.9,false,false,false,self.sortingOrder)
itemsGrid[pre][i].gameObject:SetActive(true)
end
end
else
itemsGrid[pre]={}
for i = 1, 5 do
itemsGrid[pre][i] = SubUIManager.Open(SubUIConfig.ItemView, rewards.transform)
itemsGrid[pre][i].gameObject:SetActive(false)
end
for i = 1, #shows do
itemsGrid[pre][i]:OnOpen(false, {shows[i][1],shows[i][2]}, 0.9,false,false,false,self.sortingOrder)
itemsGrid[pre][i].gameObject:SetActive(true)
end
end
end
function DemonSlayerPanel:SetTime(ActInfo)
local extraTime = ConfigManager.GetConfigData(ConfigName.GlobalActivity,ActInfo.activityId).GapTime*86400
--设置一进去的时间,不设置的话一进去会不对
local time = ActInfo.endTime - GetTimeStamp() - extraTime
local timeStr = Language[12293]
if time > 0 then
timeStr = Language[12293]
else
timeStr = Language[10471]
end
if time > 3600 then
this.timeText.text = string.format(timeStr,TimeToDHM(time))
else
this.timeText.text = string.format(timeStr,TimeToMS(time))
end
if self.timer then
self.timer:Stop()
self.timer = nil
end
--计时器
self.timer = Timer.New(function ()
if state == 0 then
local time = ActInfo.endTime - GetTimeStamp() - extraTime
if time > 3600 then
this.timeText.text = string.format(timeStr,TimeToDHM(time))
else
this.timeText.text = string.format(timeStr,TimeToMS(time))
end
time = time -1
if time <= 0 then
DemonSlayerPanel:Refresh()
end
elseif state == 1 then
local time = ActInfo.endTime - GetTimeStamp()
if time > 3600 then
this.timeText.text = string.format(timeStr,TimeToDHM(time))
else
this.timeText.text = string.format(timeStr,TimeToMS(time))
end
time = time -1
if time <= 0 then
if self.timer then
self.timer:Stop()
self.timer = nil
end
end
end
end,1,-1,true)
self.timer:Start()
end
--界面关闭时调用(用于子类重写)
function DemonSlayerPanel:OnClose()
if self.timer then
self.timer:Stop()
self.timer = nil
end
for i = 1, #npcList do
npcList[i]:OnClose()
end
sortingOrder = 0
end
--界面销毁时调用(用于子类重写)
function DemonSlayerPanel:OnDestroy()
this.spLoader:Destroy()
if self.timer then
self.timer:Stop()
self.timer = nil
end
sortingOrder = 0
end
return DemonSlayerPanel