diff --git a/druid.code-workspace b/druid.code-workspace index dab8d24..ac43fbc 100644 --- a/druid.code-workspace +++ b/druid.code-workspace @@ -22,6 +22,7 @@ "input": true, "media": true, "build": true, + "docs": true, ".github": true, ".deployer_cache": true, "dist": true diff --git a/druid/annotations.lua b/druid/annotations.lua index f700ff7..8ede88e 100644 --- a/druid/annotations.lua +++ b/druid/annotations.lua @@ -161,7 +161,7 @@ function druid__blocker.init(self, node) end function druid__blocker.is_enabled(self) end --- Set enabled blocker component state. ---- Don't change node enabled state. +--- Don't change node enabled state itself. ---@param self druid.blocker @{Blocker} ---@param state bool Enabled state function druid__blocker.set_enabled(self, state) end diff --git a/druid/base/blocker.lua b/druid/base/blocker.lua index 16a906e..6ee9b26 100644 --- a/druid/base/blocker.lua +++ b/druid/base/blocker.lua @@ -10,6 +10,8 @@ -- • Blocker inheritance @{BaseComponent}, you can use all of its methods in addition to those described here. -- -- • Blocker initial enabled state is `gui.is_enabled(node, true)` +-- +-- • The Blocker node should be enabled to capture the input -- @usage -- local node = gui.get_node("blocker_node") -- local blocker = self.druid:new_blocker(node) @@ -33,7 +35,7 @@ local Blocker = component.create("blocker") -- @tparam node node Gui node function Blocker.init(self, node) self.node = self:get_node(node) - self._is_enabled = gui.is_enabled(node, true) + self._is_enabled = gui.is_enabled(self.node, true) end @@ -53,6 +55,10 @@ function Blocker.on_input(self, action_id, action) return false end + if not gui.is_enabled(self.node, true) then + return false + end + if gui.pick_node(self.node, action.x, action.y) then return true end @@ -63,7 +69,7 @@ end --- Set enabled blocker component state. -- --- Don't change node enabled state. +-- Don't change node enabled state itself. -- @tparam Blocker self @{Blocker} -- @tparam bool state Enabled state function Blocker.set_enabled(self, state) diff --git a/druid/custom/rich_text/module/rt.lua b/druid/custom/rich_text/module/rt.lua index b9c4d58..fa48fec 100755 --- a/druid/custom/rich_text/module/rt.lua +++ b/druid/custom/rich_text/module/rt.lua @@ -534,52 +534,6 @@ function M.tagged(words, tag) end ---- Split a word into it's characters --- @param word The word to split --- @return The individual characters -function M.characters(word) - assert(word) - - local parent = gui.get_parent(word.node) - local font = gui.get_font(word.node) - local layer = gui.get_layer(word.node) - local pivot = gui.get_pivot(word.node) - - local word_length = utf8.len(word.text) - - -- exit early if word is a single character or empty - if word_length <= 1 then - local char = helper.deepcopy(word) - char.node, char.metrics = create_node(char, parent, font) - gui.set_pivot(char.node, pivot) - gui.set_position(char.node, gui.get_position(word.node)) - gui.set_layer(char.node, layer) - return { char } - end - - -- split word into characters - local chars = {} - local position = gui.get_position(word.node) - local position_x = position.x - - for i = 1, word_length do - local char = helper.deepcopy(word) - chars[#chars + 1] = char - char.text = utf8.sub(word.text, i, i) - char.node, char.metrics = create_node(char, parent, font) - gui.set_layer(char.node, layer) - gui.set_pivot(char.node, pivot) - - local sub_metrics = get_text_metrics(word, font, utf8.sub(word.text, 1, i)) - position.x = position_x + sub_metrics.width - char.metrics.width - char.position = vmath.vector3(position) - gui.set_position(char.node, char.position) - end - - return chars -end - - ---Removes the gui nodes created by rich text function M.remove(words) assert(words) diff --git a/druid/custom/rich_text/rich_text.lua b/druid/custom/rich_text/rich_text.lua index 8bcc6e2..d6a7078 100644 --- a/druid/custom/rich_text/rich_text.lua +++ b/druid/custom/rich_text/rich_text.lua @@ -3,10 +3,28 @@ --- Druid Rich Text custom component. -- # Overview # -- --- Heavily inspired by https://github.com/britzl/defold-richtext. +-- Heavily inspired by https://github.com/britzl/defold-richtext. -- -- Uses the same syntax for tags, but currently have less tags support. -- +-- All Rich Text params are adjusted in GUI scene +-- +-- The Rich Text template should have next scheme: +-- +-- root +-- +-- - text_prefab +-- +-- - icon_prefab +-- +-- # Rich Text Setup # +-- • Root node size - maximum width and height of the text +-- • Root anchor - Aligment of the Rich Text inside root node size area +-- • Text prefab - all text params for the text node +-- • Text prefab anchor - Anchor for each text node (you should adjust this only if animate text) +-- • Icon prefab - all node params for the icon node +-- • Icon prefab anchor - Anchor for each icon node (you should adjust this only if animate icon) +-- -- # Notes # -- -- • Nested tags are supported diff --git a/druid/druid.lua b/druid/druid.lua index fffe0c5..fe90baf 100644 --- a/druid/druid.lua +++ b/druid/druid.lua @@ -7,7 +7,7 @@ -- Druid components or make your own game-specific components to make -- amazing GUI in your games. -- --- To start using Druid, please refer to the Basic Usage section below. +-- To start using Druid, please refer to the Usage section below. -- -- # Notes # -- diff --git a/druid/event.lua b/druid/event.lua index bbd49df..6a61594 100644 --- a/druid/event.lua +++ b/druid/event.lua @@ -1,9 +1,10 @@ -- Copyright (c) 2021 Maksim Tuprikov . This code is licensed under MIT license ---- Druid Event module. +--- Druid Event Module -- --- Event is a simple class to handle callbacks. It's used in many Druid components. --- You can subscribe to event with `:subscribe` method and unsubscribe with `:unsubscribe`. +-- The Event module provides a simple class for handling callbacks. It is used in many Druid components. +-- +-- You can subscribe to an event using the `:subscribe` method and unsubscribe using the `:unsubscribe` method. -- @module DruidEvent -- @alias druid.event diff --git a/druid/helper.lua b/druid/helper.lua index 3759984..e79fd40 100644 --- a/druid/helper.lua +++ b/druid/helper.lua @@ -1,6 +1,9 @@ -- Copyright (c) 2021 Maksim Tuprikov . This code is licensed under MIT license --- Helper module with various usefull GUI functions. +-- @usage +-- local helper = require("druid.helper") +-- helper.centrate_nodes(0, node_1, node_2) -- @module Helper -- @alias druid.helper diff --git a/druid/styles/default/style.lua b/druid/styles/default/style.lua index 6908005..3c8a543 100644 --- a/druid/styles/default/style.lua +++ b/druid/styles/default/style.lua @@ -150,7 +150,41 @@ M["text"] = { M["hotkey"] = { - MODIFICATORS = { "key_lshift", "key_rshift", "key_lctrl", "key_rctrl", "key_lalt", "key_ralt", "key_lsuper", "key_rsuper" }, -- Add key ids to mark it as modificator keys + -- Add key ids to mark it as modificator keys + MODIFICATORS = { + "key_lshift", + "key_rshift", + "key_lctrl", + "key_rctrl", + "key_lalt", + "key_ralt", + "key_lsuper", + "key_rsuper" + } +} + + +M["rich_text"] = { + COLORS = { + white = "#FFFFFF", + black = "#000000", + red = "#FF0000", + green = "#00FF00", + blue = "#0000FF", + yellow = "#FFFF00", + magenta = "#FF00FF", + cyan = "#00FFFF", + gray = "#808080", + dark_gray = "#404040", + light_gray = "#C0C0C0", + orange = "#FFA500", + pink = "#FFC0CB", + purple = "#800080", + brown = "#A52A2A", + olive = "#808000", + teal = "#008080", + navy = "#000080", + } }