5 Commits

Author SHA1 Message Date
Insality
181a0aab43 Update docs and changelog 2025-09-27 13:52:47 +03:00
Insality
9e29c0ebde Update editor script linking messages 2025-09-27 13:34:15 +03:00
Insality
2a754c4159 Use editor script to set gui script path 2025-09-27 13:24:31 +03:00
Insality
9bf4d32d40 Update 2025-09-27 12:49:43 +03:00
Insality
9ee084c502 Update 2025-09-15 00:56:05 +03:00
10 changed files with 61 additions and 114 deletions

View File

@@ -1,8 +1,11 @@
---@alias color vector4|vector3|string
local PALETTE_DATA = {} local PALETTE_DATA = {}
local COLOR_WHITE = vmath.vector4(1, 1, 1, 1) local COLOR_WHITE = vmath.vector4(1, 1, 1, 1)
local COLOR_X = hash("color.x") local COLOR_X = hash("color.x")
local COLOR_Y = hash("color.y") local COLOR_Y = hash("color.y")
local COLOR_Z = hash("color.z") local COLOR_Z = hash("color.z")
local ALPHA = hash("color.w")
local M = {} local M = {}
@@ -81,7 +84,6 @@ function M.lerp(t, color1, color2)
end end
---Convert hex color to rgb values. ---Convert hex color to rgb values.
---@param hex string Hex color. #00BBAA or 00BBAA or #0BA or 0BA ---@param hex string Hex color. #00BBAA or 00BBAA or #0BA or 0BA
---@return number, number, number ---@return number, number, number

View File

@@ -34,7 +34,7 @@ local rich_text = require("druid.custom.rich_text.module.rt")
---@field scale vector3 ---@field scale vector3
---@field size vector3 ---@field size vector3
---@field metrics druid.rich_text.metrics ---@field metrics druid.rich_text.metrics
---@field pivot userdata ---@field pivot constant
---@field text string ---@field text string
---@field shadow vector4 ---@field shadow vector4
---@field outline vector4 ---@field outline vector4
@@ -68,7 +68,7 @@ local rich_text = require("druid.custom.rich_text.module.rt")
---The component that handles a rich text display, allows to custom color, size, font, etc. of the parts of the text ---The component that handles a rich text display, allows to custom color, size, font, etc. of the parts of the text
---@class druid.rich_text: druid.component ---@class druid.rich_text: druid.component
---@field root node The root node of the rich text ---@field root node The root text node of the rich text
---@field text_prefab node The text prefab node ---@field text_prefab node The text prefab node
---@field private _last_value string The last value of the rich text ---@field private _last_value string The last value of the rich text
---@field private _settings table The settings of the rich text ---@field private _settings table The settings of the rich text
@@ -255,4 +255,18 @@ function M:_create_settings()
end end
---Set the width of the rich text, not affects the size of current spawned words
---@param width number
function M:set_width(width)
self._settings.width = width
end
---Set the height of the rich text, not affects the size of current spawned words
---@param height number
function M:set_height(height)
self._settings.height = height
end
return M return M

View File

@@ -147,7 +147,7 @@ function M.get_widget(widget_class, gui_url, params)
for index = 1, #registered_druids do for index = 1, #registered_druids do
local druid = registered_druids[index] local druid = registered_druids[index]
if druid.fragment == gui_url.fragment and druid.path == gui_url.path then if druid.fragment == gui_url.fragment and druid.path == gui_url.path then
return druid.new_widget:trigger(widget_class, nil, nil, params) return druid.new_widget(widget_class, nil, nil, params)
end end
end end

View File

@@ -1,7 +1,7 @@
--- Module for assigning layers to GUI nodes based on textures and fonts --- Module for assigning layers to GUI nodes based on textures and fonts
local defold_parser = require("druid.editor_scripts.defold_parser.defold_parser") local defold_parser = require("druid.editor_scripts.defold_parser.defold_parser")
local system = require("druid.editor_scripts.defold_parser.system.system") local system = require("druid.editor_scripts.defold_parser.system.parser_internal")
local M = {} local M = {}

View File

@@ -12,7 +12,7 @@ end
function M.create_druid_gui_script(selection) function M.create_druid_gui_script(selection)
local gui_filepath = editor.get(selection, "path") local gui_filepath = editor.get(selection, "path")
local filename = gui_filepath:match("([^/]+)%.gui$") local filename = gui_filepath:match("([^/]+)%.gui$")
print("Create Druid GUI Script for", gui_filepath) print("Create GUI script for", gui_filepath)
local absolute_project_path = editor.external_file_attributes(".").path local absolute_project_path = editor.external_file_attributes(".").path
local widget_resource_path = gui_filepath:gsub("%.gui$", ".gui_script") local widget_resource_path = gui_filepath:gsub("%.gui$", ".gui_script")
@@ -25,8 +25,8 @@ function M.create_druid_gui_script(selection)
local f = io.open(new_widget_absolute_path, "r") local f = io.open(new_widget_absolute_path, "r")
if f then if f then
f:close() f:close()
print("Widget file already exists at " .. new_widget_absolute_path) print("GUI script file already exists at " .. new_widget_absolute_path)
print("Creation aborted to prevent overwriting") error("Creation aborted to prevent overwriting")
return return
end end
@@ -37,7 +37,7 @@ function M.create_druid_gui_script(selection)
local template_content = editor.get(template_path, "text") local template_content = editor.get(template_path, "text")
if not template_content then if not template_content then
print("Error: Could not load template from", template_path) print("Error: Could not load template from", template_path)
print("Check the template path in [Druid] Settings") error("Check the template path in [Druid] Settings")
return return
end end
@@ -54,90 +54,12 @@ function M.create_druid_gui_script(selection)
file:write(template_content) file:write(template_content)
file:close() file:close()
print("Widget created at " .. widget_resource_path) print("Widget created: " .. widget_resource_path)
editor.transact({
editor.tx.set(selection, "script", widget_resource_path)
})
editor.save()
M.link_gui_script(selection, widget_resource_path)
end
---Links a GUI script to a GUI file by updating the script property
---@param selection string The GUI resource to modify
---@param widget_resource_path string The path to the GUI script to link
function M.link_gui_script(selection, widget_resource_path)
local defold_parser = require("druid.editor_scripts.defold_parser.defold_parser")
local system = require("druid.editor_scripts.defold_parser.system.system")
local gui_filepath = editor.get(selection, "path")
print("Linking GUI script to", gui_filepath)
-- Get the absolute path to the file
local absolute_project_path = editor.external_file_attributes(".").path
if not absolute_project_path:match("[\\/]$") then
absolute_project_path = absolute_project_path .. "/"
end
local clean_gui_path = gui_filepath
if clean_gui_path:sub(1, 1) == "/" then
clean_gui_path = clean_gui_path:sub(2)
end
local gui_absolute_path = absolute_project_path .. clean_gui_path
-- Create a backup
local backup_path = gui_absolute_path .. ".backup"
print("Creating backup at:", backup_path)
-- Read and write backup
local content, err_read = system.read_file(gui_absolute_path)
if not content then
print("Error reading original file for backup:", err_read)
return
end
local success, err_write = system.write_file(backup_path, content)
if not success then
print("Error creating backup file:", err_write)
return
end
-- Parse the GUI file
print("Parsing GUI file...")
local gui_data = defold_parser.load_from_file(gui_absolute_path)
if not gui_data then
print("Error: Failed to parse GUI file")
return
end
-- Update the script property
print("Setting script property to:", widget_resource_path)
gui_data.script = widget_resource_path
-- Write the updated GUI file
print("Writing updated GUI file...")
local save_success = defold_parser.save_to_file(gui_absolute_path, gui_data)
if not save_success then
print("Error: Failed to save GUI file")
print("Attempting to restore from backup...")
-- Restore from backup on failure
local backup_content, backup_err_read = system.read_file(backup_path)
if not backup_content then
print("Error reading backup file:", backup_err_read)
return
end
local restore_success, restore_err_write = system.write_file(gui_absolute_path, backup_content)
if not restore_success then
print("Critical: Failed to restore from backup:", restore_err_write)
return
end
print("Restored successfully from backup")
return
end
-- Remove backup on success
os.remove(backup_path)
print("Successfully linked GUI script to:", gui_filepath)
end end

View File

@@ -26,7 +26,7 @@ function M.create_druid_widget(selection)
if f then if f then
f:close() f:close()
print("Widget file already exists at " .. new_widget_absolute_path) print("Widget file already exists at " .. new_widget_absolute_path)
print("Creation aborted to prevent overwriting") error("Creation aborted to prevent overwriting")
return return
end end
@@ -37,7 +37,7 @@ function M.create_druid_widget(selection)
local template_content = editor.get(template_path, "text") local template_content = editor.get(template_path, "text")
if not template_content then if not template_content then
print("Error: Could not load template from", template_path) print("Error: Could not load template from", template_path)
print("Check the template path in [Druid] Settings") error("Check the template path in [Druid] Settings")
return return
end end

View File

@@ -1,7 +1,7 @@
--- Defold Text Proto format encoder/decoder to lua table --- Defold Text Proto format encoder/decoder to lua table
local config = require("druid.editor_scripts.defold_parser.system.config") local config = require("druid.editor_scripts.defold_parser.system.config")
local system = require("druid.editor_scripts.defold_parser.system.system") local parser_internal = require("druid.editor_scripts.defold_parser.system.parser_internal")
local M = {} local M = {}
@@ -17,7 +17,7 @@ function M.decode_defold_object(text)
-- For each line in the text, we go through the following steps: -- For each line in the text, we go through the following steps:
for raw_line in text:gmatch("[^\r\n]+") do for raw_line in text:gmatch("[^\r\n]+") do
system.parse_line(raw_line, stack) parser_internal.parse_line(raw_line, stack)
end end
return root return root
@@ -39,8 +39,8 @@ function M.encode_defold_object(obj, spaces, data_level, extension)
end end
table.sort(keys, function(a, b) table.sort(keys, function(a, b)
local index_a = system.contains(key_order, a) or 0 local index_a = parser_internal.contains(key_order, a) or 0
local index_b = system.contains(key_order, b) or 0 local index_b = parser_internal.contains(key_order, b) or 0
return index_a < index_b return index_a < index_b
end) end)
@@ -63,7 +63,7 @@ function M.encode_defold_object(obj, spaces, data_level, extension)
result = result .. tabString .. key .. ': "' .. encodedChild .. '"\n' result = result .. tabString .. key .. ': "' .. encodedChild .. '"\n'
elseif item_type == "number" or item_type == "boolean" then elseif item_type == "number" or item_type == "boolean" then
local is_contains_dot = string.find(key, "%.") local is_contains_dot = string.find(key, "%.")
if item_type == "number" and (system.contains(config.with_dot_params, key) and not is_contains_dot) then if item_type == "number" and (parser_internal.contains(config.with_dot_params, key) and not is_contains_dot) then
result = result .. tabString .. key .. ': ' .. string.format("%.1f", array_item) .. '\n' result = result .. tabString .. key .. ': ' .. string.format("%.1f", array_item) .. '\n'
else else
result = result .. tabString .. key .. ': ' .. tostring(array_item) .. '\n' result = result .. tabString .. key .. ': ' .. tostring(array_item) .. '\n'
@@ -94,7 +94,7 @@ function M.encode_defold_object(obj, spaces, data_level, extension)
-- Handle scalar values (string, number, boolean) -- Handle scalar values (string, number, boolean)
if value_type == "number" or value_type == "boolean" then if value_type == "number" or value_type == "boolean" then
local is_contains_dot = string.find(key, "%.") local is_contains_dot = string.find(key, "%.")
if value_type == "number" and (system.contains(config.with_dot_params, key) and not is_contains_dot) then if value_type == "number" and (parser_internal.contains(config.with_dot_params, key) and not is_contains_dot) then
result = result .. tabString .. key .. ': ' .. string.format("%.1f", value) .. '\n' result = result .. tabString .. key .. ': ' .. string.format("%.1f", value) .. '\n'
else else
result = result .. tabString .. key .. ': ' .. tostring(value) .. '\n' result = result .. tabString .. key .. ': ' .. tostring(value) .. '\n'
@@ -125,7 +125,7 @@ end
---@param file_path string ---@param file_path string
---@return table|nil, string|nil ---@return table|nil, string|nil
function M.load_from_file(file_path) function M.load_from_file(file_path)
local content, reason = system.read_file(file_path) local content, reason = parser_internal.read_file(file_path)
if not content then if not content then
return nil, reason return nil, reason
end end
@@ -146,7 +146,7 @@ function M.save_to_file(file_path, lua_table)
local encoded_object = M.encode_defold_object(lua_table, nil, nil, defold_format_name) local encoded_object = M.encode_defold_object(lua_table, nil, nil, defold_format_name)
return system.write_file(file_path, encoded_object) return parser_internal.write_file(file_path, encoded_object)
end end

View File

@@ -720,14 +720,23 @@ Please support me if you like this project! It will help me keep engaged to upda
- Update for using `defold-event` library v12 - Update for using `defold-event` library v12
### Druid 1.2.0 ### Druid 1.2.0
- Fix for blocker internal enabled state depends from GUI node - [Blocker] Fix for internal is_enabled state
- Move to druid colors for rich text - [Button] expose all click functions for the button
- Fix for container stretch mode (stretch and fit is not worked in init function) - [Scroll] Add `scroll_to_make_node_visible` function
- Add split_to_characters in rich text for making fancy text - [Palette] Add Druid Color module
- Druid GO Widgets now can wrap an events to (before only top level functions) - Manage color palettes
- Ability to pass params to Druid GO Widgets - Color convertations
- Update properties panel: - Convenient usage
- Add "scenes" to manage a list of properties with back button support - [Container] Fix for container stretch mode (stretch and fit is not worked in init function)
- Add "refresh" button, which active a 1-sec refresh for current page - [Rich Text] Using color names from the palette
- Add "Render lua table" to easily render your lua tables with a various types support (any simple types and vector, functions, events etc) - [Rich Text] Add `rich_text:set_split_to_characters(true)` to split each letter node separately
- Weird implementation, but nice to have
- [Rich Text] Add `set_width` and `set_height` functions
- [GO Widgets] Now passes events and functions from the widget to the GO context
- [Layout] Add `set_position_function` function, similar to the Grid component
- [Properties Panel] Update with deep navigation support
- Add "Scenes" to manage a list of properties with back button support
- Add "Pages" to manage a a big lists of properties with paginations support
- Add `properties_panel:render_lua_table` to easily render your lua tables with a various types support (any simple types and vector, functions, events etc)
- Add "Refresh" button, which active a 1-sec refresh for current page

View File

@@ -1,8 +1,8 @@
# Memory and FPS Panel Widgets # Memory and FPS Panel Widgets
The `Druid 1.1` comes with widgets and two included widgets are `Memory Panel` and `FPS Panel` which allow you to monitor memory and FPS in your game. The `Druid 1.1` comes with two included widgets: `Memory Panel` and `FPS Panel`, which allow you to monitor memory and FPS in your game.
Widgets in Druid usually consists from two files: GUI, which is used to placed as a template on your GUI scene and Lua script, which is used to be created with Druid. Widgets in Druid usually consist of two files: GUI, which is used to place as a template on your GUI scene and Lua script, which is used to be create with Druid.
<!-- Video --> <!-- Video -->