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

244 lines
8.1 KiB
Lua
Raw Normal View History

2020-09-23 20:27:29 +08:00
require("Base/BasePanel")
2020-09-24 17:07:12 +08:00
local DemonSlayerPanel = Inherit(BasePanel)
2020-09-23 20:27:29 +08:00
local this = DemonSlayerPanel
2020-09-24 17:07:12 +08:00
local sortingOrder = 0
local allData={}
local actRankConfig = ConfigManager.GetConfig(ConfigName.ActivityRankingReward)
local itemsGrid = {}--item重复利用
local state = 0
2020-09-24 20:47:16 +08:00
local allRankData,myRankData
2020-09-24 17:07:12 +08:00
local rankImage={
[1] = "r_playerrumble_paiming_01",
[2] = "r_playerrumble_paiming_02",
[3] = "r_playerrumble_paiming_03",
}
2020-09-23 20:27:29 +08:00
--初始化组件(用于子类重写)
function DemonSlayerPanel:InitComponent()
this.btnBack = Util.GetGameObject(self.gameObject,"BackBtn")
this.helpBtn = Util.GetGameObject(self.gameObject,"HelpBtn")
2020-09-24 20:47:16 +08:00
this.btnRank = Util.GetGameObject(self.gameObject,"RankList")
2020-09-23 20:27:29 +08:00
2020-09-24 17:07:12 +08:00
this.time = Util.GetGameObject(self.gameObject, "rewardContent/time")
this.leftTime = Util.GetGameObject(self.gameObject, "rewardContent/time/num"):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
2020-09-23 20:27:29 +08:00
end
--绑定事件(用于子类重写)
function DemonSlayerPanel:BindEvent()
Util.AddClick(this.btnBack, function()
self:ClosePanel()
end)
Util.AddClick(this.helpBtn, function()
local pos = this.helpBtn.transform.localPosition
2020-09-24 17:07:12 +08:00
UIManager.OpenPanel(UIName.HelpPopup, HELP_TYPE.DemonSlayer, pos.x, pos.y)
2020-09-23 20:27:29 +08:00
end)
2020-09-24 20:47:16 +08:00
Util.AddClick(this.btnRank, function()
UIManager.OpenPanel(UIName.RankingSingleListPanel,rankKingList[11])
end)
2020-09-23 20:27:29 +08:00
end
--添加事件监听(用于子类重写)
function DemonSlayerPanel:AddListener()
end
--移除事件监听(用于子类重写)
function DemonSlayerPanel:RemoveListener()
end
2020-09-24 20:47:16 +08:00
-- function DemonSlayerPanel:OnSortingOrderChange()
-- for i, v in pairs(itemsGrid) do
-- for j = 1, #itemsGrid[i] do
-- itemsGrid[i][j]:SetEffectLayer()
-- end
-- end
-- end
2020-09-23 20:27:29 +08:00
--界面打开时调用(用于子类重写)
function DemonSlayerPanel:OnOpen()
end
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
function DemonSlayerPanel:OnShow()
2020-09-24 17:07:12 +08:00
DemonSlayerPanel:Refresh()
end
function DemonSlayerPanel:Refresh()
local ActInfo = ActivityGiftManager.GetActivityTypeInfo(ActivityTypeDef.DemonSlayer)
DemonSlayerPanel:SetState(ActInfo)
2020-09-24 20:47:16 +08:00
DemonSlayerPanel:SetRank(ActInfo)
2020-09-24 17:07:12 +08:00
DemonSlayerPanel:OnShowData(ActInfo)
DemonSlayerPanel:SetTime(ActInfo)
end
2020-09-24 20:47:16 +08:00
function DemonSlayerPanel:SetRank(ActInfo)
2020-09-24 17:07:12 +08:00
if state == 0 then
RankingManager.InitData(RANK_TYPE.MONSTER_RANK,function ()
allRankData,myRankData = RankingManager.GetRankingInfo()
2020-09-24 20:47:16 +08:00
if not myRankData.rank or (myRankData.rank and myRankData.rank < 1) then--排名对比 <0未上榜
this.myRank.text = Language[10041] --未上榜
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 = "虚位以待"
end
2020-09-24 17:07:12 +08:00
end)
elseif state == 1 then
2020-09-24 20:47:16 +08:00
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[10041] --未上榜
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 = allRankData[i].userName
end
end,ActInfo.activityId)
2020-09-24 17:07:12 +08:00
end
end
function DemonSlayerPanel:SetState(ActInfo)
local extraTime = ConfigManager.GetConfigData(ConfigName.GlobalActivity,ActInfo.activityId).GapTime*86400
2020-09-24 20:47:16 +08:00
local time1 = ActInfo.endTime - GetTimeStamp()
if time1 - extraTime > 0 then
state = 0--7天内
2020-09-24 17:07:12 +08:00
else
2020-09-24 20:47:16 +08:00
state = 1--2天内
2020-09-24 17:07:12 +08:00
end
2020-09-23 20:27:29 +08:00
end
2020-09-24 17:07:12 +08:00
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
-- SecTorPlayAnim(prefab)
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 = Util.LoadSprite(rankImage[index])
num:SetActive(false)
rank:SetActive(false)
rank2:SetActive(true)
else
num:SetActive(true)
rank2:SetActive(false)
rank:SetActive(true)
num:GetComponent("Text").text = data.MinRank.."-"..data.MaxRank
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,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,sortingOrder)
itemsGrid[pre][i].gameObject:SetActive(true)
end
end
end
function DemonSlayerPanel:SetTime(ActInfo)
local extraTime = ConfigManager.GetConfigData(ConfigName.GlobalActivity,ActInfo.activityId).GapTime*86400
--设置一进去的时间,不设置的话一进去会不对
this.time:SetActive(state == 0)
local time = ActInfo.endTime - GetTimeStamp() - extraTime
if time > 86400 then
this.leftTime.text = TimeToDH(time)
else
this.leftTime.text = TimeToHMS(time)
end
--计时器
2020-09-24 20:47:16 +08:00
this.timer = Timer.New(function ()
2020-09-24 17:07:12 +08:00
if state == 0 then
this.time:SetActive(true)
local time = ActInfo.endTime - GetTimeStamp() - extraTime
if time > 86400 then
this.leftTime.text = TimeToDH(time)
else
this.leftTime.text = TimeToHMS(time)
end
time = time -1
if time <= 0 then
DemonSlayerPanel:Refresh()
end
elseif state == 1 then
-- body
this.time:SetActive(false)
local time = ActInfo.endTime - GetTimeStamp()
time = time -1
if time <= 0 then
self:ClosePanel()
PopupTipPanel.ShowTip(Language[10029])
end
end
end,1,-1,true):Start()
end
2020-09-23 20:27:29 +08:00
--界面关闭时调用(用于子类重写)
function DemonSlayerPanel:OnClose()
2020-09-24 17:07:12 +08:00
sortingOrder = 0
2020-09-24 20:47:16 +08:00
if this.timer then
this.timer:Stop()
this.timer = nil
end
2020-09-23 20:27:29 +08:00
end
--界面销毁时调用(用于子类重写)
function DemonSlayerPanel:OnDestroy()
2020-09-24 17:07:12 +08:00
sortingOrder = 0
2020-09-23 20:27:29 +08:00
end
return DemonSlayerPanel