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

258 lines
9.6 KiB
Lua

require("Base/BasePanel")
local DemonSlayerNewPanel = Inherit(BasePanel)
local this = DemonSlayerNewPanel
local sortingOrder = 0
local actRankConfig = ConfigManager.GetConfig(ConfigName.ActivityRankingReward)
local itemsGrid = {} --item重复利用
local allRankData, myRankData
local npcList = {}
local btnState = {
[1] = { Img = "s_slbz_1anniuhuangse", Text = Language[10505] },
[2] = { Img = "s_slbz_1anniuongse", Text = Language[10024] },
[3] = { Img = "s_slbz_1anniuhuise", Text = Language[10025] },
}
--初始化组件(用于子类重写)
function DemonSlayerNewPanel: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.pos = Util.GetGameObject(self.gameObject, "pos")
this.textNum = Util.GetGameObject(self.gameObject, "rewardContent/textNum")
this.tips = Util.GetGameObject(self.textNum, "Tips")
this.obj = Util.GetGameObject(self.textNum, "Obj")
this.nextLevel = Util.GetGameObject(self.obj, "num"):GetComponent("Text")
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 DemonSlayerNewPanel: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.DemonSlayerNew, pos.x, pos.y)
end)
Util.AddClick(this.btnRank, function()
UIManager.OpenPanel(UIName.RankingSingleListPanel, rankKingList[4])
end)
end
--添加事件监听(用于子类重写)
function DemonSlayerNewPanel:AddListener()
end
--移除事件监听(用于子类重写)
function DemonSlayerNewPanel:RemoveListener()
end
--界面打开时调用(用于子类重写)
function DemonSlayerNewPanel:OnOpen()
end
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
function DemonSlayerNewPanel:OnShow()
DemonSlayerNewPanel:Refresh(false)
end
function DemonSlayerNewPanel:Refresh(isAnim)
local ActInfo = CommonActPageManager.GetData(ActivityTypeDef.DemonSlayerNew)
CheckRedPointStatus(RedPointType.DemonSlayerNew)
this.ActId = ActInfo.activityId
DemonSlayerNewPanel:SetState(ActInfo)
DemonSlayerNewPanel:SetRank(ActInfo)
DemonSlayerNewPanel:OnShowData(ActInfo, isAnim)
DemonSlayerNewPanel:SetTime(ActInfo)
end
function DemonSlayerNewPanel:SetRank(ActInfo)
RankingManager.InitData(RANK_TYPE.MONSTER_RANK, function()
allRankData, myRankData = RankingManager.GetRankingInfo()
self:SetPlayer()
end)
end
function DemonSlayerNewPanel:SetPlayer()
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
-- 获取向左时的偏移值
local PlayerRoleConFig = ConfigManager.TryGetConfigData(ConfigName.PlayerRole, curPlayerLiveViewData.ride)
if PlayerRoleConFig and PlayerRoleConFig.RideOffset and PlayerRoleConFig.RideOffset[3] then
local offset = Vector3.New(0, 0, 0)
offset.x = PlayerRoleConFig.RideOffset[3][1]
offset.y = PlayerRoleConFig.RideOffset[3][2]
npcList[i].transform.localPosition = Vector3.New(0, 122, 0) -
offset * GetPlayerRoleSingleConFig().Scale11
end
else
image.enabled = true
item.text = Language[10506]
end
end
end
function DemonSlayerNewPanel:SetState(ActInfo)
local extraTime = ConfigManager.GetConfigData(ConfigName.GlobalActivity, ActInfo.activityId).GapTime * 86400
local time1 = ActInfo.endTime - GetTimeStamp()
local num = 0
for i = 1, #ActInfo.rewards do
num = ActInfo.rewards[i].otherData.Values[1][2] - ActInfo.rewards[i].progress
if num > 0 then
this.nextLevel.text = num
break
end
end
this.tips:SetActive(num <= 0)
this.obj:SetActive(num > 0)
end
function DemonSlayerNewPanel:OnShowData(ActInfo, isAnim)
this.ScrollView:SetData(ActInfo.rewards, function(index, go)
DemonSlayerNewPanel:SingleDataShow(go, ActInfo.rewards[index], index)
end, nil, isAnim)
end
function DemonSlayerNewPanel:SingleDataShow(pre, data, index)
local btnGet = Util.GetGameObject(pre, "Button"):GetComponent("Image")
local btnText = Util.GetGameObject(btnGet.gameObject, "Text"):GetComponent("Text")
local level = Util.GetGameObject(pre, "Text"):GetComponent("Text")
local rewards = Util.GetGameObject(pre, "rewards")
local shows = data.otherData.Reward
local progress = Util.GetGameObject(pre, "progress"):GetComponent("Text")
progress.gameObject:SetActive(data.otherData.State == 1)
progress.text = string.format("%s/%s", data.progress, data.otherData.Values[1][2])
level.text = string.format(Language[10507], data.otherData.Values[1][2])
btnGet.sprite = this.spLoader:LoadSprite(btnState[data.otherData.State].Img)
btnText.text = btnState[data.otherData.State].Text
--滚动条复用重设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.8, 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.8, false, false, false, self.sortingOrder)
itemsGrid[pre][i].gameObject:SetActive(true)
end
end
Util.AddOnceClick(btnGet.gameObject, function()
if data.otherData.State == 1 then
JumpManager.GoJump(1011)
elseif data.otherData.State == 2 then
NetManager.GetActivityRewardRequest(data.missionId, this.ActId, function(drop)
UIManager.OpenPanel(UIName.RewardItemPopup, drop, 1, function()
this:Refresh(true)
end)
end)
end
end)
end
function DemonSlayerNewPanel:SetTime(ActInfo)
local extraTime = ConfigManager.GetConfigData(ConfigName.GlobalActivity, ActInfo.activityId).GapTime * 86400
--设置一进去的时间,不设置的话一进去会不对
local time = ActInfo.endTime - GetTimeStamp() - extraTime
local timeStr = Language[10508]
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()
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
DemonSlayerNewPanel:ClosePanel()
end
end, 1, -1, true)
self.timer:Start()
end
--界面关闭时调用(用于子类重写)
function DemonSlayerNewPanel: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 DemonSlayerNewPanel:OnDestroy()
this.spLoader:Destroy()
if self.timer then
self.timer:Stop()
self.timer = nil
end
sortingOrder = 0
end
return DemonSlayerNewPanel