mirror of
https://github.com/Insality/druid.git
synced 2025-06-27 10:27:47 +02:00
dirty button changes. Hover animations. Call button, if only touch start and ended on this button
This commit is contained in:
parent
10d84670b9
commit
a0a171df55
@ -2,10 +2,15 @@ local data = require("druid.data")
|
|||||||
local ui_animate = require "druid.help_modules.druid_animate"
|
local ui_animate = require "druid.help_modules.druid_animate"
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
M.interest = {
|
M.interest = {
|
||||||
data.ON_INPUT
|
data.ON_INPUT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local BTN_SOUND = "button_click"
|
||||||
|
local BTN_SOUND_DISABLED = "button_click_disabled"
|
||||||
|
local HOVER_SCALE = vmath.vector3(-0.025, -0.025, 1)
|
||||||
|
|
||||||
M.DEFAULT_SCALE_CHANGE = vmath.vector3(-0.05, - 0.1, 1)
|
M.DEFAULT_SCALE_CHANGE = vmath.vector3(-0.05, - 0.1, 1)
|
||||||
M.DEFAULT_POS_CHANGE = vmath.vector3(0, - 10, 0)
|
M.DEFAULT_POS_CHANGE = vmath.vector3(0, - 10, 0)
|
||||||
M.DEFAULT_MOVE_SPEED = 5
|
M.DEFAULT_MOVE_SPEED = 5
|
||||||
@ -17,35 +22,66 @@ M.DEFAULT_ACTIVATE_SCALE = vmath.vector3(1, 1, 1)
|
|||||||
M.DEFAUL_ACTIVATION_TIME = 0.2
|
M.DEFAUL_ACTIVATION_TIME = 0.2
|
||||||
|
|
||||||
|
|
||||||
function M.init(instance, callback, event, action, animate_node_name, sound)
|
function M.init(instance, callback, params, animate_node_name, event)
|
||||||
instance.event = event or data.A_TOUCH
|
instance.event = event or data.A_TOUCH
|
||||||
instance.action = action or data.RELEASED
|
|
||||||
instance.anim_node = animate_node_name and gui.get_node(animate_node_name) or instance.node
|
instance.anim_node = animate_node_name and gui.get_node(animate_node_name) or instance.node
|
||||||
instance.scale_from = gui.get_scale(instance.anim_node)
|
instance.scale_from = gui.get_scale(instance.anim_node)
|
||||||
instance.scale_to = instance.scale_from + M.DEFAULT_SCALE_CHANGE
|
instance.scale_to = instance.scale_from + M.DEFAULT_SCALE_CHANGE
|
||||||
|
instance.scale_hover_to = instance.scale_from + HOVER_SCALE
|
||||||
instance.pos = gui.get_position(instance.anim_node)
|
instance.pos = gui.get_position(instance.anim_node)
|
||||||
instance.callback = callback
|
instance.callback = callback
|
||||||
-- instance.params = params
|
instance.params = params
|
||||||
instance.tap_anim = M.tap_scale_animation
|
instance.tap_anim = M.tap_scale_animation
|
||||||
instance.back_anim = M.back_scale_animation
|
instance.back_anim = M.back_scale_animation
|
||||||
-- instance.sound = sound or M.BTN_SOUND_FUNC
|
instance.hover_anim = true
|
||||||
-- instance.sound_disable = sound_disable or M.BTN_SOUND_DISABLE_FUNC
|
-- instance.sound = sound or BTN_SOUND
|
||||||
|
-- instance.sound_disable = sound_disable or BTN_SOUND_DISABLED
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Set text to text field
|
--- Set text to text field
|
||||||
-- @param action_id - input action id
|
-- @param action_id - input action id
|
||||||
-- @param action - input action
|
-- @param action - input action
|
||||||
function M.on_input(instance, action_id, action)
|
function M.on_input(instance, action_id, action)
|
||||||
if gui.is_enabled(instance.node) and gui.pick_node(instance.node, action.x, action.y) then
|
if gui.pick_node(instance.node, action.x, action.y) then
|
||||||
|
if action.pressed then
|
||||||
|
instance.can_action = true
|
||||||
|
instance.repeated_counter = 0
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
if action.released then
|
||||||
if not instance.disabled then
|
if not instance.disabled then
|
||||||
|
if not instance.stub and instance.can_action then
|
||||||
|
instance.can_action = false
|
||||||
instance.tap_anim(instance)
|
instance.tap_anim(instance)
|
||||||
|
-- instance.sound()
|
||||||
|
instance.callback(instance.parent.parent, instance.params, instance)
|
||||||
|
else
|
||||||
|
if instance.hover_anim then
|
||||||
|
gui.animate(instance.node, "scale", instance.scale_from, gui.EASING_OUTSINE, 0.05)
|
||||||
|
end
|
||||||
|
end
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
-- instance.sound_disable()
|
instance.sound_disable()
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
-- scale in
|
||||||
|
if instance.hover_anim then
|
||||||
|
gui.animate(instance.node, "scale", instance.scale_hover_to, gui.EASING_OUTSINE, 0.05)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return not instance.disabled
|
||||||
|
else
|
||||||
|
-- scale back
|
||||||
|
-- bad solition, remake with flag
|
||||||
|
instance.can_action = false
|
||||||
|
if instance.hover_anim then
|
||||||
|
gui.animate(instance.node, "scale", instance.scale_from, gui.EASING_OUTSINE, 0.05)
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.tap_scale_animation(instance)
|
function M.tap_scale_animation(instance)
|
||||||
@ -55,7 +91,6 @@ function M.tap_scale_animation(instance)
|
|||||||
instance.back_anim(instance)
|
instance.back_anim(instance)
|
||||||
end
|
end
|
||||||
-- instance.sound()
|
-- instance.sound()
|
||||||
instance.callback(instance.parent.parent, instance.params, instance)
|
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user