mirror of
https://github.com/Insality/druid
synced 2025-06-27 10:27:48 +02:00
Update timer & text
This commit is contained in:
parent
a0113d3356
commit
54345b924b
@ -1752,7 +1752,7 @@ function druid_instance.new_text(self, node, value, no_adjust) end
|
|||||||
--- Create @{Timer} component
|
--- Create @{Timer} component
|
||||||
---@param self druid_instance
|
---@param self druid_instance
|
||||||
---@param node string|node Gui text node
|
---@param node string|node Gui text node
|
||||||
---@param seconds_from number Start timer value in seconds
|
---@param seconds_from number|nil Start timer value in seconds
|
||||||
---@param seconds_to number|nil End timer value in seconds
|
---@param seconds_to number|nil End timer value in seconds
|
||||||
---@param callback function|nil Function on timer end
|
---@param callback function|nil Function on timer end
|
||||||
---@return druid.timer @{Timer} component
|
---@return druid.timer @{Timer} component
|
||||||
|
@ -86,6 +86,13 @@ local utf8 = utf8 or utf8_lua --[[@as utf8]]
|
|||||||
local Text = component.create("text")
|
local Text = component.create("text")
|
||||||
|
|
||||||
local function update_text_size(self)
|
local function update_text_size(self)
|
||||||
|
if self.scale.x == 0 or self.scale.y == 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if self.start_scale.x == 0 or self.start_scale.y == 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local size = vmath.vector3(
|
local size = vmath.vector3(
|
||||||
self.start_size.x * (self.start_scale.x / self.scale.x),
|
self.start_size.x * (self.start_scale.x / self.scale.x),
|
||||||
self.start_size.y * (self.start_scale.y / self.scale.y),
|
self.start_size.y * (self.start_scale.y / self.scale.y),
|
||||||
@ -207,6 +214,8 @@ local function update_text_with_trim(self, trim_postfix)
|
|||||||
end
|
end
|
||||||
|
|
||||||
gui.set_text(self.node, new_text .. trim_postfix)
|
gui.set_text(self.node, new_text .. trim_postfix)
|
||||||
|
else
|
||||||
|
gui.set_text(self.node, self.last_value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -47,18 +47,19 @@ end
|
|||||||
--- The @{Timer} constructor
|
--- The @{Timer} constructor
|
||||||
-- @tparam Timer self @{Timer}
|
-- @tparam Timer self @{Timer}
|
||||||
-- @tparam node node Gui text node
|
-- @tparam node node Gui text node
|
||||||
-- @tparam number seconds_from Start timer value in seconds
|
-- @tparam number|nil seconds_from Start timer value in seconds
|
||||||
-- @tparam number|nil seconds_to End timer value in seconds
|
-- @tparam number|nil seconds_to End timer value in seconds
|
||||||
-- @tparam function|nil callback Function on timer end
|
-- @tparam function|nil callback Function on timer end
|
||||||
function Timer.init(self, node, seconds_from, seconds_to, callback)
|
function Timer.init(self, node, seconds_from, seconds_to, callback)
|
||||||
self.node = self:get_node(node)
|
self.node = self:get_node(node)
|
||||||
seconds_from = math.max(seconds_from, 0)
|
|
||||||
seconds_to = math.max(seconds_to or 0, 0)
|
seconds_to = math.max(seconds_to or 0, 0)
|
||||||
|
|
||||||
self.on_tick = Event()
|
self.on_tick = Event()
|
||||||
self.on_set_enabled = Event()
|
self.on_set_enabled = Event()
|
||||||
self.on_timer_end = Event(callback)
|
self.on_timer_end = Event(callback)
|
||||||
|
|
||||||
|
if seconds_from then
|
||||||
|
seconds_from = math.max(seconds_from, 0)
|
||||||
self:set_to(seconds_from)
|
self:set_to(seconds_from)
|
||||||
self:set_interval(seconds_from, seconds_to)
|
self:set_interval(seconds_from, seconds_to)
|
||||||
|
|
||||||
@ -66,6 +67,7 @@ function Timer.init(self, node, seconds_from, seconds_to, callback)
|
|||||||
self:set_state(false)
|
self:set_state(false)
|
||||||
self.on_timer_end:trigger(self:get_context(), self)
|
self.on_timer_end:trigger(self:get_context(), self)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user