PGRData/Script/matrix/xui/xuifubenfashionstory/XUiGridFashionStoryTrial.lua
2024-09-01 22:49:41 +02:00

91 lines
No EOL
3 KiB
Lua

local XUiGridFashionStoryTrial = XClass(nil, "UiGridFashionStoryTrial")
function XUiGridFashionStoryTrial:Ctor(ui, parent)
self.GameObject = ui.gameObject
self.Transform = ui.transform
self.Parent = parent
XTool.InitUiObject(self)
self:AutoAddListener()
end
function XUiGridFashionStoryTrial:Refresh(stageId, activityId, entranceCb,singleLineId)
if stageId == XFashionStoryConfigs.StoryEntranceId and activityId and singleLineId then
self.IsStoryEntrance = true
self.ActivityId = activityId
self.EntranceCb = entranceCb
self.SingleLineId=singleLineId
else
self.IsStoryEntrance = false
self.ActivityId = nil
end
self.StageId = stageId
self.BtnSummer:SetRawImage(self.IsStoryEntrance and XFashionStoryConfigs.GetStoryEntranceBg(singleLineId) or XFubenConfigs.GetStageIcon(stageId))
self.ImageStoryProcess:SetSprite(self.IsStoryEntrance and XFashionStoryConfigs.GetStoryEntranceFinishTag(singleLineId) or XFashionStoryConfigs.GetTrialFinishTag(stageId))
if self.IsStoryEntrance then
local passNum, totalNum = XDataCenter.FashionStoryManager.GetChapterProgress(self.ActivityId)
self.TxtStoryProcessNumber.text= string.format("%d/%d",passNum, totalNum)
self.TxtStoryProcess.gameObject:SetActiveEx(true)
self.PanelPass.gameObject:SetActiveEx(false)
else
local isPassed = XDataCenter.FubenManager.CheckStageIsPass(self.StageId)
self.PanelPass.gameObject:SetActiveEx(isPassed)
self.TxtStoryProcess.gameObject:SetActiveEx(false)
end
self:RefreshLeftTime()
end
function XUiGridFashionStoryTrial:AutoAddListener()
self.BtnSummer.CallBack = function()
self:OnClick()
end
end
function XUiGridFashionStoryTrial:OnClick()
if self.IsStoryEntrance then
self.EntranceCb()
else
XEventManager.DispatchEvent(XEventId.EVENT_FASHION_STORY_OPEN_TRIAL_DETAIL, self.StageId)
end
end
function XUiGridFashionStoryTrial:RefreshLeftTime()
local leftTime
if self.IsStoryEntrance then
leftTime = XDataCenter.FashionStoryManager.GetStoryTimeStamp(self.ActivityId)
else
leftTime = XDataCenter.FashionStoryManager.GetTrialStageLeftTimeStamp(self.StageId)
end
-- 刷新剩余时间
local func = function()
leftTime = leftTime > 0 and leftTime or 0
local strTime = XUiHelper.GetTime(leftTime, XUiHelper.TimeFormatType.ACTIVITY)
if self.TxtLeftTime then
self.TxtLeftTime.text = CSXTextManagerGetText("FashionStoryTrialStageLeftTime", strTime)
end
if leftTime <= 0 then
self:RemoveTimer()
XEventManager.DispatchEvent(XEventId.EVENT_FASHION_STORY_TRIAL_REFRESH)
end
end
func()
self.Parent:RegisterTimerFun(self.StageId, function()
leftTime = leftTime - 1
func()
end)
end
function XUiGridFashionStoryTrial:OnRecycle()
self:RemoveTimer()
end
function XUiGridFashionStoryTrial:RemoveTimer()
self.Parent:RemoveTimerFun(self.StageId)
end
return XUiGridFashionStoryTrial