This commit is contained in:
Insality
2025-03-25 22:56:47 +02:00
parent fb9c80b284
commit e83e5a6c84
9 changed files with 116 additions and 75 deletions

View File

@@ -310,7 +310,6 @@ function M:set_web_user_interaction(is_web_mode)
end
---@param action_id hash The action id
---@return boolean is_match True if the input matches the button
function M:_is_input_match(action_id)

View File

@@ -9,7 +9,7 @@ local COLOR_Z = hash("color.z")
local M = {}
---Get color color by id
---Get color color by string (hex or from palette)
---@param color_id string
---@return vector4
function M.get(color_id)

View File

@@ -135,8 +135,9 @@ end
---@param nodes table<hash, node>|nil
---@return druid.instance
function M:get_druid(template, nodes)
local context = { _context = self }
local druid_instance = setmetatable(context, { __index = self._meta.druid })
local druid_instance = setmetatable({
_context = self
}, { __index = self._meta.druid })
if template then
self:set_template(template)

View File

@@ -112,12 +112,14 @@ end
---Get a binded widget to the current game object.
--- msg.url(nil, nil, "go_widget") -- current game object
--- msg.url(nil, object_url, "go_widget") -- other game object
---@generic T: druid.widget
---@param widget_class T The class of the widget to return
---@param gui_url_string string? GUI url, if nil current gui will be used
---@param gui_url url GUI url
---@return T
function M.get_widget(widget_class, gui_url_string)
local gui_url = msg.url(gui_url_string)
function M.get_widget(widget_class, gui_url)
gui_url = gui_url or msg.url()
local guis = REGISTERED_GUI_WIDGETS[gui_url.socket]
if not guis then
return nil

View File

@@ -34,6 +34,7 @@
---@field upper fun()
---@field rep fun()
-- This one should be a part of Defold annotations
---@class action
---@field value number The amount of input given by the user. This is usually 1 for buttons and 0-1 for analogue inputs. This is not present for mouse movement.
---@field pressed boolean If the input was pressed this frame. This is not present for mouse movement.

View File

@@ -8,31 +8,29 @@ local druid_component = require("druid.component")
---The Druid Factory used to create components
---@class druid.instance
---@field components_all druid.component[] All created components
---@field components_interest table<string, druid.component[]> All components sorted by interest
---@field private _context table Druid context, usually a self of gui script
---@field private _style table Druid style table
---@field private _is_late_remove_enabled boolean
---@field private _late_remove druid.component[]
---@field private _input_blacklist druid.component[]|nil
---@field private _input_whitelist druid.component[]|nil
---@field private input_inited boolean
---@field private _late_init_timer_id number
---@field private _input_components druid.component[]
---@field package input_inited boolean Used to check if input is initialized
---@field package components_all druid.component[] All created components
---@field package components_interest table<string, druid.component[]> All components sorted by interest
---@field package _context table Druid context, usually a self of gui script
---@field package _style table Druid style table
---@field package _late_init_timer_id number Timer id for late init
---@field package _late_remove druid.component[] Components to be removed on late update
---@field package _is_late_remove_enabled boolean Used to check if components should be removed on late update
---@field package _input_blacklist druid.component[]|nil Components that should not receive input
---@field package _input_whitelist druid.component[]|nil Components that should receive input
local M = {}
local MSG_ADD_FOCUS = hash("acquire_input_focus")
local MSG_REMOVE_FOCUS = hash("release_input_focus")
local IS_NO_AUTO_INPUT = sys.get_config_int("druid.no_auto_input", 0) == 1
local INTERESTS_CACHE = {} -- Cache interests per component class in runtime
local function set_input_state(self, is_input_inited)
if IS_NO_AUTO_INPUT or (self.input_inited == is_input_inited) then
return
end
self.input_inited = is_input_inited
msg.post(".", is_input_inited and MSG_ADD_FOCUS or MSG_REMOVE_FOCUS)
msg.post(".", is_input_inited and "acquire_input_focus" or "release_input_focus")
end
@@ -98,7 +96,7 @@ local function register_interests(self, instance)
end
-- Create the Druid component instance
---Create the Druid component instance
---@param self druid.instance
---@param instance_class druid.component
---@return druid.component
@@ -148,8 +146,8 @@ end
---Check whitelists and blacklists for input components
---@param component druid.component
---@return boolean
---@param component druid.component The component to check
---@return boolean is_can_use True if component can be processed on input step
function M:_can_use_input_component(component)
local can_by_whitelist = true
local can_by_blacklist = true
@@ -181,7 +179,7 @@ end
---Druid class constructor which used to create a Druid's components
---@param context table Druid context. Usually it is self of gui script
---@param style table? Druid style table
---@return druid.instance
---@return druid.instance instance The new Druid instance
function M.create_druid_instance(context, style)
local self = setmetatable({}, { __index = M })
@@ -244,8 +242,8 @@ end
---Remove created component from Druid instance.
--
-- Component `on_remove` function will be invoked, if exist.
---
---Component `on_remove` function will be invoked, if exist.
---@generic T: druid.component
---@param component T Component instance
---@return boolean is_removed True if component was removed
@@ -422,8 +420,8 @@ end
---Calls the on_language_change function in all related components
-- This one called by global druid.on_language_change, but can be
-- call manualy to update all translations
---This one called by global druid.on_language_change, but can be
---call manualy to update all translations
---@private
function M:on_language_change()
local components = self.components_interest[const.ON_LANGUAGE_CHANGE]
@@ -540,7 +538,7 @@ end
local back_handler = require("druid.base.back_handler")
---Create BackHandler component
---@param callback function|nil The callback(self, custom_args) to call on back event
---@param callback function|event|nil The callback(self, custom_args) to call on back event
---@param params any|nil Callback argument
---@return druid.back_handler back_handler The new back handler component
function M:new_back_handler(callback, params)
@@ -722,7 +720,7 @@ end
local rich_input = require("druid.custom.rich_input.rich_input")
---Create RichInput component.
-- As a template please check rich_input.gui layout.
---As a template please check rich_input.gui layout.
---@param template string The template string name
---@param nodes table|nil Nodes table from gui.clone_tree
---@return druid.rich_input rich_input The new rich input component