PGRData/Script/matrix/xui/xuidraw/xuidrawtools/XUiDrawRemainTime.lua

32 lines
735 B
Lua
Raw Normal View History

local timer
local function RemoveTimer()
if timer then
XScheduleManager.UnSchedule(timer)
timer = nil
end
end
local function Init(txt, txtName, time)
if not txt or not txt:Exist() then
return
end
txt.text = CS.XTextManager.GetText(txtName, XUiHelper.GetTime(time))
local refresh = function()
if not txt or not txt:Exist() then
RemoveTimer()
end
time = time - 1
txt.text = CS.XTextManager.GetText(txtName, XUiHelper.GetTime(time))
end
timer = XScheduleManager.ScheduleForever(refresh, XScheduleManager.SECOND)
end
local DrawRemainTime = {}
DrawRemainTime.Init = Init
DrawRemainTime.RemoveTimer = RemoveTimer
return DrawRemainTime