From 6d84f06c3237c1f64cbfddf157c05e149f18f1a5 Mon Sep 17 00:00:00 2001 From: Insality Date: Sat, 18 Apr 2020 02:01:45 +0300 Subject: [PATCH] Add on_input_wrong, add allowerd_characters, add simple wrong animation --- docs_md/changelog.md | 17 ++++++++++++++++- druid/base/button.lua | 2 ++ druid/base/input.lua | 23 ++++++++++++++++++++--- druid/styles/default/style.lua | 21 +++++++++++++++------ 4 files changed, 53 insertions(+), 10 deletions(-) diff --git a/docs_md/changelog.md b/docs_md/changelog.md index c3610fc..a103196 100644 --- a/docs_md/changelog.md +++ b/docs_md/changelog.md @@ -1,13 +1,28 @@ Druid 0.3.0: +- Druid:final now is important function for correct working + - Add swipe basic component - Swipe component handle simple swipe gestures on node. It has single callback with direction on swipe. You can adjust a several parameters of swipe in druid style. - Add input basic component - Input component handle user text input. Input contains from button and text component. Button needed for selecting input field + - Long click on input field for clear and select input field + - Click outside of button to unselect input field + - On focus lost (game minimized) input field will be unselected + - You can setup max length of the text + - You can setup allowed characters. On add not allowed characters `on_input_wrong` will be called. By default it cause simple shake animation - Add button on_click_outside event. You can subscribe on this event in button. Was needed for Input component (click outside to deselect input field). +- Add start_pos to button component - Changed input binding settings. Add backspace, enter, text and marked_text. Backspace now is different from android back button. -- Add several examples to druid-assets \ No newline at end of file +- Changed component interest: Renamed on_change_language -> on_language_change +- Add two new component interests: on_focus_gain and on_focus_lost +- Add global druid events: + - on_window_callback: call `druid.on_window_callback(event)` for on_focus_gain/lost correct work + - on_language_change: call `druid.on_language_change()` for update all druid instances lang components + - on_layout_change: call `druid.on_layout_change()` for update all gui layouts (unsupported now) + +- Add several examples to druid-assets respository diff --git a/druid/base/button.lua b/druid/base/button.lua index 05f47d8..9d6bc32 100644 --- a/druid/base/button.lua +++ b/druid/base/button.lua @@ -15,6 +15,7 @@ -- @tfield node node Trigger node -- @tfield[opt=node] node anim_node Animation node -- @tfield vector3 start_scale Initial scale of anim_node +-- @tfield vector3 start_pos Initial pos of anim_node -- @tfield vector3 pos Initial pos of anim_node -- @tfield any params Params to click callbacks -- @tfield druid.hover hover Druid hover logic component @@ -152,6 +153,7 @@ function M.init(self, node, callback, params, anim_node) self.anim_node = anim_node and helper:get_node(anim_node) or self.node self.start_scale = gui.get_scale(self.anim_node) + self.start_pos = gui.get_position(self.anim_node) self.params = params self.hover = self.druid:new_hover(node, on_button_hover) self.click_zone = nil diff --git a/druid/base/input.lua b/druid/base/input.lua index 3682c49..c11b4d2 100644 --- a/druid/base/input.lua +++ b/druid/base/input.lua @@ -20,7 +20,7 @@ local function select(self) self.on_input_select:trigger(self:get_context()) if self.style.on_select then - self.style.on_select(self) + self.style.on_select(self, self.button.node) end end end @@ -35,7 +35,7 @@ local function unselect(self) self.on_input_unselect:trigger(self:get_context()) if self.style.on_unselect then - self.style.on_unselect(self) + self.style.on_unselect(self, self.button.node) end end end @@ -62,7 +62,7 @@ function M.init(self, click_node, text_node, keyboard_type) self.market_text_width = 0 self.total_width = 0 - self.max_length = 18 + self.max_length = nil self.allowed_characters = nil self.keyboard_type = keyboard_type or gui.KEYBOARD_TYPE_NUMBER_PAD @@ -77,6 +77,7 @@ function M.init(self, click_node, text_node, keyboard_type) self.on_input_text = Event() self.on_input_empty = Event() self.on_input_full = Event() + self.on_input_wrong = Event() end @@ -100,6 +101,11 @@ function M.on_input(self, action_id, action) if self.max_length then input_text = utf8.sub(input_text, 1, self.max_length) end + else + self.on_input_wrong:trigger(self:get_context(), action.text) + if self.style.on_input_wrong then + self.style.on_input_wrong(self, self.button.node) + end end self.marked_value = "" end @@ -186,4 +192,15 @@ function M.get_text(self) end +function M.set_max_length(self, max_length) + self.max_length = max_length +end + + +-- [%a%d] for alpha numeric +function M.set_allowed_characters(self, characters) + self.allowed_characters = characters +end + + return M diff --git a/druid/styles/default/style.lua b/druid/styles/default/style.lua index 8fa39cf..7e40eb8 100644 --- a/druid/styles/default/style.lua +++ b/druid/styles/default/style.lua @@ -84,15 +84,24 @@ M["swipe"] = { M["input"] = { BUTTON_SELECT_INCREASE = 1.1, - on_select = function(self) - local button = self.button.node + + on_select = function(self, button_node) local target_scale = self.button.start_scale - gui.animate(button, "scale", target_scale * M.input.BUTTON_SELECT_INCREASE, gui.EASING_OUTSINE, 0.15) + gui.animate(button_node, "scale", target_scale * M.input.BUTTON_SELECT_INCREASE, gui.EASING_OUTSINE, 0.15) end, - on_unselect = function(self) - local button = self.button.node + + on_unselect = function(self, button_node) local start_scale = self.button.start_scale - gui.animate(button, "scale", start_scale, gui.EASING_OUTSINE, 0.15) + gui.animate(button_node, "scale", start_scale, gui.EASING_OUTSINE, 0.15) + end, + + on_input_wrong = function(self, button_node) + local start_pos = self.button.start_pos + gui.animate(button_node, "position.x", start_pos.x - 3, gui.EASING_OUTSINE, 0.05, 0, function() + gui.animate(button_node, "position.x", start_pos.x + 3, gui.EASING_OUTSINE, 0.1, 0, function() + gui.animate(button_node, "position.x", start_pos.x, gui.EASING_OUTSINE, 0.05) + end) + end) end, button = {