From 2133492efe3b9a64a4ee91451e3eaa0df5697657 Mon Sep 17 00:00:00 2001 From: Insality Date: Sat, 17 May 2025 18:06:26 +0300 Subject: [PATCH] Update properties panel, add refresh button --- druid/druid.atlas | 3 + druid/images/icons/icon_refresh.png | Bin 0 -> 593 bytes .../properties_panel/properties_panel.gui | 18 ++++ .../properties_panel/properties_panel.lua | 77 +++++++++--------- 4 files changed, 61 insertions(+), 37 deletions(-) create mode 100644 druid/images/icons/icon_refresh.png diff --git a/druid/druid.atlas b/druid/druid.atlas index 10868c4..94cba34 100644 --- a/druid/druid.atlas +++ b/druid/druid.atlas @@ -28,4 +28,7 @@ images { images { image: "/druid/images/icons/icon_arrow.png" } +images { + image: "/druid/images/icons/icon_refresh.png" +} extrude_borders: 2 diff --git a/druid/images/icons/icon_refresh.png b/druid/images/icons/icon_refresh.png new file mode 100644 index 0000000000000000000000000000000000000000..970fc3c5ed1db7c0a17c841cf8f47d316da120cb GIT binary patch literal 593 zcmV-X0|WK~#7F?UlPq z13?sq&w2q7gT_uF5Rnjw+K3j$Run<3)I!0+XAlcT@h-lC*horWLeYpIXeVN@F^$9~ zL{r2I$A8!fZq}V-cC!{rKKPiO<(xCKyR$PyHU1;aY`{jH*gEnVF*uq<_<-yFO7RWk z5)=)giNhG|khdSARpS_n!NX{7V4J*k3C9e>$SLB7&~%bBukZx91=0ltr)^I#OTUC_Cyd(q zr{n?g$>1oAv$;cRCmvXy{)Ie(+(TJI{2>cYF{(Gfifgw_$yO}hL2@yHC(CsJvk#I> zkRujltL0XjTuk8B)}J8v4BPtp8xm$8;?hIs9BLokhz-b`B3b!s>%->BXJwZ)PBsw( z*KD~7ato4rx%345fUB^j!r*&sZrerPV1&GY#2x<08Jv-etQZ$$^MFb^#4l4dpuje( zsdOA~ksqMYihPy2 fUYcsu_)B~N#Pd&c+(L|M00000NkvXXu0mjfIqCw- literal 0 HcmV?d00001 diff --git a/druid/widget/properties_panel/properties_panel.gui b/druid/widget/properties_panel/properties_panel.gui index 63ba475..dfbad11 100644 --- a/druid/widget/properties_panel/properties_panel.gui +++ b/druid/widget/properties_panel/properties_panel.gui @@ -106,6 +106,24 @@ nodes { x: 152.0 y: -4.0 } + color { + x: 0.306 + y: 0.31 + z: 0.314 + } + type: TYPE_BOX + texture: "druid/icon_refresh" + id: "icon_refresh" + pivot: PIVOT_NE + parent: "header" + inherit_alpha: true + size_mode: SIZE_MODE_AUTO +} +nodes { + position { + x: 112.0 + y: -4.0 + } scale { x: -1.0 } diff --git a/druid/widget/properties_panel/properties_panel.lua b/druid/widget/properties_panel/properties_panel.lua index 8f19358..8709000 100644 --- a/druid/widget/properties_panel/properties_panel.lua +++ b/druid/widget/properties_panel/properties_panel.lua @@ -61,6 +61,10 @@ function M:init() end) gui.set_enabled(self.button_back.node, false) + self.button_refresh = self.druid:new_button("icon_refresh", function() + self.is_dirty = true + end) + -- We not using as a part of properties, since it handled in a way to be paginable self.paginator = self.druid:new_widget(property_left_right_selector, "property_left_right_selector", "root") self.paginator:set_text("Page") @@ -388,8 +392,7 @@ function M:render_lua_table(data) for i = 1, #component_order do local component_id = component_order[i] - local component = data[component_id] - self:add_property_component(component_id, component, data) + self:add_property_component(component_id, data) end local metatable = getmetatable(data) @@ -403,7 +406,7 @@ function M:render_lua_table(data) for i = 1, #metatable_order do local component_id = metatable_order[i] local component = metatable.__index[component_id] - self:add_property_component("M:" .. component_id, component, data) + self:add_property_component("M:" .. component_id, data) end end end @@ -411,32 +414,32 @@ end ---@private ---@param component_id string ----@param component table ----@param context table -function M:add_property_component(component_id, component, context) +---@param data table +function M:add_property_component(component_id, data) + local component = data[component_id] local component_type = type(component) if component_type == "table" then - local is_empty = next(component) == nil - local is_array = component[1] ~= nil - local name = "Inspect" - if is_empty then - name = "Inspect (Empty)" - end - if is_array then - name = "Inspect (" .. #component .. ")" - end - - local button_name = component_id - -- If it's a number or array, try to get the id/name/prefab_id from the component - if type(component) == "table" and type(component_id) == "number" then - local extracted_id = component.name or component.prefab_id or component.node_id or component.id - if extracted_id then - button_name = component_id .. ". " .. extracted_id - end - end - self:add_button(function(button) + local is_empty = next(component) == nil + local is_array = component[1] ~= nil + local name = "Inspect" + if is_empty then + name = "Inspect (Empty)" + end + if is_array then + name = "Inspect (" .. #component .. ")" + end + + local button_name = component_id + -- If it's a number or array, try to get the id/name/prefab_id from the component + if type(component) == "table" and type(component_id) == "number" then + local extracted_id = component.name or component.prefab_id or component.node_id or component.id + if extracted_id then + button_name = component_id .. ". " .. extracted_id + end + end + button:set_text_property(button_name) button:set_text_button(name) button.button.on_click:subscribe(function() @@ -450,9 +453,9 @@ function M:add_property_component(component_id, component, context) if component_type == "string" then self:add_input(function(input) input:set_text_property(tostring(component_id)) - input:set_text_value(tostring(component)) + input:set_text_value(tostring(data[component_id])) input:on_change(function(_, value) - context[component_id] = value + data[component_id] = value end) end) end @@ -460,9 +463,9 @@ function M:add_property_component(component_id, component, context) if component_type == "number" then self:add_input(function(input) input:set_text_property(tostring(component_id)) - input:set_text_value(tostring(helper.round(component, 3))) + input:set_text_value(tostring(helper.round(data[component_id], 3))) input:on_change(function(_, value) - context[component_id] = tonumber(value) + data[component_id] = tonumber(value) end) end) end @@ -470,9 +473,9 @@ function M:add_property_component(component_id, component, context) if component_type == "boolean" then self:add_checkbox(function(checkbox) checkbox:set_text_property(tostring(component_id)) - checkbox:set_value(component) + checkbox:set_value(data[component_id]) checkbox:on_change(function(value) - context[component_id] = value + data[component_id] = value end) end) end @@ -482,17 +485,17 @@ function M:add_property_component(component_id, component, context) ---@cast component vector3 self:add_vector3(function(vector3) vector3:set_text_property(tostring(component_id)) - vector3:set_value(component.x, component.y, component.z) + vector3:set_value(data[component_id].x, data[component_id].y, data[component_id].z) vector3.on_change:subscribe(function(value) - component.x = value.x - component.y = value.y - component.z = value.z + data[component_id].x = value.x + data[component_id].y = value.y + data[component_id].z = value.z end) end) else self:add_text(function(text) text:set_text_property(tostring(component_id)) - text:set_text_value(tostring(component)) + text:set_text_value(tostring(data[component_id])) end) end end @@ -502,7 +505,7 @@ function M:add_property_component(component_id, component, context) button:set_text_property(tostring(component_id)) button:set_text_button("Call") button.button.on_click:subscribe(function() - component(context) + component(data) end) end) end