Add on_input_wrong, add allowerd_characters, add simple wrong animation

This commit is contained in:
Insality 2020-04-18 02:01:45 +03:00
parent f02c68242a
commit 6d84f06c32
4 changed files with 53 additions and 10 deletions

View File

@ -1,13 +1,28 @@
Druid 0.3.0: Druid 0.3.0:
- Druid:final now is important function for correct working
- Add swipe basic component - 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. - 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 - Add input basic component
- Input component handle user text input. Input contains from button and text component. Button needed for selecting input field - 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 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. - 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 - 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

View File

@ -15,6 +15,7 @@
-- @tfield node node Trigger node -- @tfield node node Trigger node
-- @tfield[opt=node] node anim_node Animation node -- @tfield[opt=node] node anim_node Animation node
-- @tfield vector3 start_scale Initial scale of anim_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 vector3 pos Initial pos of anim_node
-- @tfield any params Params to click callbacks -- @tfield any params Params to click callbacks
-- @tfield druid.hover hover Druid hover logic component -- @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.anim_node = anim_node and helper:get_node(anim_node) or self.node
self.start_scale = gui.get_scale(self.anim_node) self.start_scale = gui.get_scale(self.anim_node)
self.start_pos = gui.get_position(self.anim_node)
self.params = params self.params = params
self.hover = self.druid:new_hover(node, on_button_hover) self.hover = self.druid:new_hover(node, on_button_hover)
self.click_zone = nil self.click_zone = nil

View File

@ -20,7 +20,7 @@ local function select(self)
self.on_input_select:trigger(self:get_context()) self.on_input_select:trigger(self:get_context())
if self.style.on_select then if self.style.on_select then
self.style.on_select(self) self.style.on_select(self, self.button.node)
end end
end end
end end
@ -35,7 +35,7 @@ local function unselect(self)
self.on_input_unselect:trigger(self:get_context()) self.on_input_unselect:trigger(self:get_context())
if self.style.on_unselect then if self.style.on_unselect then
self.style.on_unselect(self) self.style.on_unselect(self, self.button.node)
end end
end end
end end
@ -62,7 +62,7 @@ function M.init(self, click_node, text_node, keyboard_type)
self.market_text_width = 0 self.market_text_width = 0
self.total_width = 0 self.total_width = 0
self.max_length = 18 self.max_length = nil
self.allowed_characters = nil self.allowed_characters = nil
self.keyboard_type = keyboard_type or gui.KEYBOARD_TYPE_NUMBER_PAD 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_text = Event()
self.on_input_empty = Event() self.on_input_empty = Event()
self.on_input_full = Event() self.on_input_full = Event()
self.on_input_wrong = Event()
end end
@ -100,6 +101,11 @@ function M.on_input(self, action_id, action)
if self.max_length then if self.max_length then
input_text = utf8.sub(input_text, 1, self.max_length) input_text = utf8.sub(input_text, 1, self.max_length)
end 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 end
self.marked_value = "" self.marked_value = ""
end end
@ -186,4 +192,15 @@ function M.get_text(self)
end 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 return M

View File

@ -84,15 +84,24 @@ M["swipe"] = {
M["input"] = { M["input"] = {
BUTTON_SELECT_INCREASE = 1.1, 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 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, end,
on_unselect = function(self)
local button = self.button.node on_unselect = function(self, button_node)
local start_scale = self.button.start_scale 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, end,
button = { button = {