From 5d5fe7f374442e2656a6240b7e40b46d689eadd6 Mon Sep 17 00:00:00 2001 From: Insality Date: Mon, 14 Oct 2024 22:13:57 +0300 Subject: [PATCH] Rich text based only on text node --- druid/custom/rich_text/module/rt.lua | 12 ++++----- druid/custom/rich_text/rich_text.lua | 38 ++++++++++------------------ 2 files changed, 20 insertions(+), 30 deletions(-) diff --git a/druid/custom/rich_text/module/rt.lua b/druid/custom/rich_text/module/rt.lua index 7531ebb..feaeb71 100755 --- a/druid/custom/rich_text/module/rt.lua +++ b/druid/custom/rich_text/module/rt.lua @@ -117,8 +117,8 @@ end ---@return druid.rich_text.metrics local function get_image_metrics(word, settings) local node_prefab = settings.node_prefab - gui.set_texture(node_prefab, word.image.texture or settings.default_texture) - gui.play_flipbook(node_prefab, word.image.anim or settings.default_animation) + gui.set_texture(node_prefab, word.image.texture) + gui.play_flipbook(node_prefab, word.image.anim) local node_size = gui.get_size(node_prefab) local aspect = node_size.x / node_size.y node_size.x = word.image.width or node_size.x @@ -175,7 +175,7 @@ function M.create(text, settings, style) -- Image params ---@type druid.rich_text.image image = nil, - image_color = gui.get_color(settings.node_prefab), + --image_color = gui.get_color(settings.node_prefab), -- Tags br = nil, nobr = nil, @@ -204,8 +204,8 @@ function M._fill_properties(word, metrics, settings) if word.image then -- Image properties - word.scale = gui.get_scale(settings.node_prefab) * word.relative_scale * settings.adjust_scale - word.pivot = gui.get_pivot(settings.node_prefab) + word.scale = vmath.vector3(word.relative_scale * settings.adjust_scale) + word.pivot = gui.PIVOT_CENTER word.size = metrics.node_size word.offset = vmath.vector3(0, 0, 0) if word.image.width then @@ -407,7 +407,7 @@ function M._update_nodes(lines, settings) local word = line[word_index] local node if word.image then - node = word.node or gui.clone(settings.node_prefab) + node = word.node or gui.new_box_node(vmath.vector3(0), word.size) gui.set_size_mode(node, gui.SIZE_MODE_MANUAL) gui.set_texture(node, word.image.texture or settings.default_texture) gui.play_flipbook(node, hash(word.image.anim or settings.default_animation)) diff --git a/druid/custom/rich_text/rich_text.lua b/druid/custom/rich_text/rich_text.lua index 48a5fd7..1cf9a10 100644 --- a/druid/custom/rich_text/rich_text.lua +++ b/druid/custom/rich_text/rich_text.lua @@ -106,29 +106,23 @@ local rich_text = require("druid.custom.rich_text.module.rt") local RichText = component.create("rich_text") -local SCHEME = { - ROOT = "root", - TEXT_PREFAB = "text_prefab", - ICON_PREFAB = "icon_prefab" -} - --- The @{RichText} constructor -- @tparam RichText self @{RichText} -- @tparam string template The Rich Text template name -- @tparam table nodes The node table, if prefab was copied by gui.clone_tree() -function RichText.init(self, template, nodes) - self.druid = self:get_druid(template, nodes) - - self.root = self:get_node(SCHEME.ROOT) - - self.text_prefab = self:get_node(SCHEME.TEXT_PREFAB) - self.icon_prefab = self:get_node(SCHEME.ICON_PREFAB) - - gui.set_enabled(self.text_prefab, false) - gui.set_enabled(self.icon_prefab, false) +function RichText.init(self, text_node, value) + self.root = self:get_node(text_node) + self.text_prefab = self.root + self._last_value = value or gui.get_text(self.text_prefab) + gui.set_text(self.root, "") self._settings = self:_create_settings() + + if value then + self:set_text(value) + end + end @@ -228,9 +222,6 @@ end function RichText:on_remove() - pcall(gui.set_texture, self.icon_prefab, self._settings.default_texture) - pcall(gui.play_flipbook, self.icon_prefab, self._settings.default_animation) - self:clear() end @@ -292,7 +283,6 @@ function RichText:_create_settings() height = root_size.y, combine_words = false, -- disabled now text_prefab = self.text_prefab, - node_prefab = self.icon_prefab, -- Text Settings shadow = gui.get_shadow(self.text_prefab), @@ -303,10 +293,10 @@ function RichText:_create_settings() -- Image settings image_pixel_grid_snap = false, -- disabled now - node_scale = gui.get_scale(self.icon_prefab), - image_scale = gui.get_scale(self.icon_prefab), - default_animation = gui.get_flipbook(self.icon_prefab), - default_texture = gui.get_texture(self.icon_prefab), + node_scale = gui.get_scale(self.text_prefab), + image_scale = gui.get_scale(self.text_prefab), + --default_animation = gui.get_flipbook(self.icon_prefab), + --default_texture = gui.get_texture(self.icon_prefab), } end