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

@@ -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