From 54345b924bebbe7cbce719d3a32c3fc667381c02 Mon Sep 17 00:00:00 2001 From: Insality Date: Tue, 15 Oct 2024 01:30:28 +0300 Subject: [PATCH] Update timer & text --- druid/annotations.lua | 2 +- druid/base/text.lua | 9 +++++++++ druid/extended/timer.lua | 16 +++++++++------- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/druid/annotations.lua b/druid/annotations.lua index 3f0f074..e614543 100644 --- a/druid/annotations.lua +++ b/druid/annotations.lua @@ -1752,7 +1752,7 @@ function druid_instance.new_text(self, node, value, no_adjust) end --- Create @{Timer} component ---@param self druid_instance ---@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 callback function|nil Function on timer end ---@return druid.timer @{Timer} component diff --git a/druid/base/text.lua b/druid/base/text.lua index 5d44c20..3aaa063 100755 --- a/druid/base/text.lua +++ b/druid/base/text.lua @@ -86,6 +86,13 @@ local utf8 = utf8 or utf8_lua --[[@as utf8]] local Text = component.create("text") 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( self.start_size.x * (self.start_scale.x / self.scale.x), 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 gui.set_text(self.node, new_text .. trim_postfix) + else + gui.set_text(self.node, self.last_value) end end diff --git a/druid/extended/timer.lua b/druid/extended/timer.lua index beb2af5..235f4be 100644 --- a/druid/extended/timer.lua +++ b/druid/extended/timer.lua @@ -47,24 +47,26 @@ end --- The @{Timer} constructor -- @tparam Timer self @{Timer} -- @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 function|nil callback Function on timer end function Timer.init(self, node, seconds_from, seconds_to, callback) self.node = self:get_node(node) - seconds_from = math.max(seconds_from, 0) seconds_to = math.max(seconds_to or 0, 0) self.on_tick = Event() self.on_set_enabled = Event() self.on_timer_end = Event(callback) - self:set_to(seconds_from) - self:set_interval(seconds_from, seconds_to) + if seconds_from then + seconds_from = math.max(seconds_from, 0) + self:set_to(seconds_from) + self:set_interval(seconds_from, seconds_to) - if seconds_to - seconds_from == 0 then - self:set_state(false) - self.on_timer_end:trigger(self:get_context(), self) + if seconds_to - seconds_from == 0 then + self:set_state(false) + self.on_timer_end:trigger(self:get_context(), self) + end end return self