diff --git a/alpha_todo.txt b/alpha_todo.txt index 65da880..e5c646a 100644 --- a/alpha_todo.txt +++ b/alpha_todo.txt @@ -2,9 +2,9 @@ Simple to-do for Druid Alpha 0.2.0 -- High -- remove button event and match_event from druid -- add hover component -- add druid events/triggers? better callback system ++ remove button event and match_event from druid ++ add hover component ++ add druid events/triggers? better callback system - better name for locale component? lang? lang_text? - better scroll size management, check different cases. So implicit now - better grid + scroll management @@ -22,6 +22,7 @@ Simple to-do for Druid Alpha 0.2.0 - separate custom data and predefined fields in components? - unify component api (get/set/to and other general stuff) - compare with gooey +- button and hover click restriction zone? -- Low @@ -31,3 +32,4 @@ Simple to-do for Druid Alpha 0.2.0 - add good examples with template and/or nodes (basic component no use any of them) - try use final druid in real project (FI uses custom druid) (use in 4321?) - Druid store assest - separate repository with rich components +- ability to control buttons via controller. Select it by cursor (d-pad) diff --git a/druid/base/button.lua b/druid/base/button.lua index 36bc2d4..d0de518 100644 --- a/druid/base/button.lua +++ b/druid/base/button.lua @@ -16,6 +16,26 @@ local function on_button_hover(self, hover_state) self.style.on_hover(self, self.anim_node, hover_state) end + +local function on_button_release(self) + if not self.disabled then + if not self.stub and self.can_action then + self.can_action = false + if self.style.on_click then + self.style.on_click(self, self.anim_node) + end + self.callback(self:get_context(), self.params, self) + end + return true + else + if self.style.on_click_disabled then + self.style.on_click_disabled(self, self.anim_node) + end + return false + end +end + + --- Component init function -- @function button:init -- @tparam table self Component instance @@ -44,25 +64,6 @@ function M.init(self, node, callback, params, anim_node, event) end -local function on_button_release(self) - if not self.disabled then - if not self.stub and self.can_action then - self.can_action = false - if self.style.on_click then - self.style.on_click(self, self.anim_node) - end - self.callback(self:get_context(), self.params, self) - end - return true - else - if self.style.on_click_disabled then - self.style.on_click_disabled(self, self.anim_node) - end - return false - end -end - - function M.on_input(self, action_id, action) if action_id ~= const.ACTION_TOUCH then return false diff --git a/druid/base/locale.lua b/druid/base/lang_text.lua similarity index 90% rename from druid/base/locale.lua rename to druid/base/lang_text.lua index d419f01..760190e 100644 --- a/druid/base/locale.lua +++ b/druid/base/lang_text.lua @@ -1,12 +1,12 @@ --- Component to handle all GUI texts -- Good working with localization system --- @module druid.locale +-- @module druid.lang_text local const = require("druid.const") local settings = require("druid.system.settings") local component = require("druid.component") -local M = component.create("locale", { const.ON_CHANGE_LANGUAGE }) +local M = component.create("lang_text", { const.ON_CHANGE_LANGUAGE }) function M.init(self, node, lang_id, no_adjust) diff --git a/druid/system/druid_instance.lua b/druid/system/druid_instance.lua index 9907edd..08e790a 100644 --- a/druid/system/druid_instance.lua +++ b/druid/system/druid_instance.lua @@ -6,7 +6,7 @@ -- @see druid.back_handler -- @see druid.input -- @see druid.text --- @see druid.locale +-- @see druid.lang_text -- @see druid.timer -- @see druid.progress -- @see druid.grid @@ -26,7 +26,7 @@ local blocker = require("druid.base.blocker") local back_handler = require("druid.base.back_handler") local hover = require("druid.base.hover") local text = require("druid.base.text") -local locale = require("druid.base.locale") +local lang_text = require("druid.base.lang_text") local timer = require("druid.base.timer") local progress = require("druid.base.progress") local grid = require("druid.base.grid") @@ -269,12 +269,12 @@ function Druid.new_text(self, ...) end ---- Create locale basic component --- @function druid:new_locale --- @tparam args ... locale init args --- @treturn Component locale component -function Druid.new_locale(self, ...) - return Druid.create(self, locale, ...) +--- Create lang_text basic component +-- @function druid:new_lang_text +-- @tparam args ... lang_text init args +-- @treturn Component lang_text component +function Druid.new_lang_text(self, ...) + return Druid.create(self, lang_text, ...) end diff --git a/example/kenney/gui/main/main.gui_script b/example/kenney/gui/main/main.gui_script index 0f9fed2..357e8b3 100644 --- a/example/kenney/gui/main/main.gui_script +++ b/example/kenney/gui/main/main.gui_script @@ -29,7 +29,7 @@ end local function init_top_panel(self) self.druid:new_button("button_left/button", on_control_button, -1) self.druid:new_button("button_right/button", on_control_button, 1) - self.header = self.druid:new_locale("text_header", "main_page") + self.header = self.druid:new_lang_text("text_header", "main_page") end diff --git a/example/kenney/page/main.lua b/example/kenney/page/main.lua index cefd09d..e4d719f 100644 --- a/example/kenney/page/main.lua +++ b/example/kenney/page/main.lua @@ -26,16 +26,16 @@ end local function setup_texts(self) - self.druid:new_locale("text_button", "ui_section_button") - self.druid:new_locale("text_text", "ui_section_text") - self.druid:new_locale("text_timer", "ui_section_timer") - self.druid:new_locale("text_progress", "ui_section_progress") - self.druid:new_locale("text_slider", "ui_section_slider") - self.druid:new_locale("text_radio", "ui_section_radio") - self.druid:new_locale("text_checkbox", "ui_section_checkbox") + self.druid:new_lang_text("text_button", "ui_section_button") + self.druid:new_lang_text("text_text", "ui_section_text") + self.druid:new_lang_text("text_timer", "ui_section_timer") + self.druid:new_lang_text("text_progress", "ui_section_progress") + self.druid:new_lang_text("text_slider", "ui_section_slider") + self.druid:new_lang_text("text_radio", "ui_section_radio") + self.druid:new_lang_text("text_checkbox", "ui_section_checkbox") - self.druid:new_locale("text_translated", "ui_text_example") - self.druid:new_locale("text_button_lang", "ui_text_change_lang") + self.druid:new_lang_text("text_translated", "ui_text_example") + self.druid:new_lang_text("text_button_lang", "ui_text_change_lang") self.druid:new_text("text_simple", "Simple") end diff --git a/example/kenney/page/texts.lua b/example/kenney/page/texts.lua index c1386ce..d1d459d 100644 --- a/example/kenney/page/texts.lua +++ b/example/kenney/page/texts.lua @@ -19,7 +19,7 @@ local function setup_texts(self) self.druid:new_text("text_multiline", "Simple multiline text with smth") local anchoring = self.druid:new_text("text_anchoring", "Anchoring") self.druid:new_text("text_no_adjust", "Without adjust size", true) - self.druid:new_locale("text_locale", "ui_text_example") + self.druid:new_lang_text("text_locale", "ui_text_example") local big_text = "Check max size" local width = self.druid:new_text("text_max_width", big_text)