mirror of
https://github.com/Insality/druid.git
synced 2025-09-27 10:02:18 +02:00
remove components from main factory
This commit is contained in:
11
druid/base/android_back.lua
Normal file
11
druid/base/android_back.lua
Normal file
@@ -0,0 +1,11 @@
|
||||
local M = {}
|
||||
|
||||
--- input handler
|
||||
-- @param action_id - input action id
|
||||
-- @param action - input action
|
||||
function M.on_input(instance, action_id, action)
|
||||
instance.callback(instance.parent.parent)
|
||||
return true
|
||||
end
|
||||
|
||||
return M
|
139
druid/base/button.lua
Normal file
139
druid/base/button.lua
Normal file
@@ -0,0 +1,139 @@
|
||||
local data = require("druid.data")
|
||||
local ui_animate = require "druid.help_modules.druid_animate"
|
||||
|
||||
local M = {}
|
||||
M.interest = {
|
||||
data.ON_INPUT
|
||||
}
|
||||
|
||||
M.DEFAULT_SCALE_CHANGE = vmath.vector3(-0.05, - 0.1, 1)
|
||||
M.DEFAULT_POS_CHANGE = vmath.vector3(0, - 10, 0)
|
||||
M.DEFAULT_MOVE_SPEED = 5
|
||||
M.DEFAULT_ALPHA_DOWN = 0.8
|
||||
M.DEFAULT_TIME_ANIM = 0.1
|
||||
M.DEFAULT_DEACTIVATE_COLOR = vmath.vector4(0, 0, 0, 0)
|
||||
M.DEFAULT_DEACTIVATE_SCALE = vmath.vector3(0.8, 0.9, 1)
|
||||
M.DEFAULT_ACTIVATE_SCALE = vmath.vector3(1, 1, 1)
|
||||
M.DEFAUL_ACTIVATION_TIME = 0.2
|
||||
|
||||
|
||||
function M.init(instance, callback, event, action, animate_node_name, sound)
|
||||
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.scale_from = gui.get_scale(instance.anim_node)
|
||||
instance.scale_to = instance.scale_from + M.DEFAULT_SCALE_CHANGE
|
||||
instance.pos = gui.get_position(instance.anim_node)
|
||||
instance.callback = callback
|
||||
-- instance.params = params
|
||||
instance.tap_anim = M.tap_scale_animation
|
||||
instance.back_anim = M.back_scale_animation
|
||||
-- instance.sound = sound or M.BTN_SOUND_FUNC
|
||||
-- instance.sound_disable = sound_disable or M.BTN_SOUND_DISABLE_FUNC
|
||||
end
|
||||
|
||||
--- Set text to text field
|
||||
-- @param action_id - input action id
|
||||
-- @param action - input 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 not instance.disabled then
|
||||
instance.tap_anim(instance)
|
||||
return true
|
||||
else
|
||||
-- instance.sound_disable()
|
||||
return false
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function M.tap_scale_animation(instance)
|
||||
ui_animate.scale_to(instance, instance.anim_node, instance.scale_to,
|
||||
function()
|
||||
if instance.back_anim then
|
||||
instance.back_anim(instance)
|
||||
end
|
||||
-- instance.sound()
|
||||
instance.callback(instance.parent.parent, instance.params, instance)
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
function M.back_scale_animation(instance)
|
||||
ui_animate.scale_to(instance, instance.anim_node, instance.scale_from)
|
||||
end
|
||||
|
||||
function M.tap_tab_animation(instance, force)
|
||||
ui_animate.alpha(instance, instance.anim_node, M.DEFAULT_ALPHA_DOWN, nil, M.DEFAULT_TIME_ANIM)
|
||||
ui_animate.fly_to(instance, instance.anim_node, instance.pos + M.DEFAULT_POS_CHANGE, M.DEFAULT_MOVE_SPEED)
|
||||
ui_animate.scale_to(instance, instance.anim_node, instance.scale_to,
|
||||
function()
|
||||
if instance.back_anim then
|
||||
instance.back_anim(instance)
|
||||
end
|
||||
instance.callback(instance.parent.parent, instance.params, force)
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
function M.back_tab_animation(instance)
|
||||
ui_animate.alpha(instance, instance.anim_node, 1, nil, M.DEFAULT_TIME_ANIM)
|
||||
ui_animate.fly_to(instance, instance.anim_node, instance.pos, M.DEFAULT_MOVE_SPEED)
|
||||
ui_animate.scale_to(instance, instance.anim_node, instance.scale_from)
|
||||
end
|
||||
|
||||
function M.deactivate(instance, is_animate, callback)
|
||||
instance.disabled = true
|
||||
if is_animate then
|
||||
local counter = 0
|
||||
local clbk = function()
|
||||
counter = counter + 1
|
||||
if counter == 3 and callback then
|
||||
callback(instance.parent.parent)
|
||||
end
|
||||
end
|
||||
ui_animate.color(instance, instance.node, M.DEFAULT_DEACTIVATE_COLOR, clbk, M.DEFAUL_ACTIVATION_TIME, 0,
|
||||
gui.EASING_OUTBOUNCE)
|
||||
ui_animate.scale_y_from_to(instance, instance.node, M.DEFAULT_ACTIVATE_SCALE.x, M.DEFAULT_DEACTIVATE_SCALE.x, clbk,
|
||||
M.DEFAUL_ACTIVATION_TIME, gui.EASING_OUTBOUNCE)
|
||||
ui_animate.scale_x_from_to(instance, instance.node, M.DEFAULT_ACTIVATE_SCALE.y, M.DEFAULT_DEACTIVATE_SCALE.y, clbk,
|
||||
M.DEFAUL_ACTIVATION_TIME, gui.EASING_OUTBOUNCE)
|
||||
else
|
||||
gui.set_color(instance.node, M.DEFAULT_DEACTIVATE_COLOR)
|
||||
gui.set_scale(instance.node, M.DEFAULT_DEACTIVATE_SCALE)
|
||||
if callback then
|
||||
callback(instance.parent.parent)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function M.activate(instance, is_animate, callback)
|
||||
if is_animate then
|
||||
local counter = 0
|
||||
local clbk = function()
|
||||
counter = counter + 1
|
||||
if counter == 3 then
|
||||
instance.disabled = false
|
||||
if callback then
|
||||
callback(instance.parent.parent)
|
||||
end
|
||||
end
|
||||
end
|
||||
ui_animate.color(instance, instance.node, ui_animate.TINT_SHOW, clbk, M.DEFAUL_ACTIVATION_TIME, 0,
|
||||
gui.EASING_OUTBOUNCE)
|
||||
ui_animate.scale_y_from_to(instance, instance.node, M.DEFAULT_DEACTIVATE_SCALE.x, M.DEFAULT_ACTIVATE_SCALE.x, clbk,
|
||||
M.DEFAUL_ACTIVATION_TIME, gui.EASING_OUTBOUNCE)
|
||||
ui_animate.scale_x_from_to(instance, instance.node, M.DEFAULT_DEACTIVATE_SCALE.y, M.DEFAULT_ACTIVATE_SCALE.y, clbk,
|
||||
M.DEFAUL_ACTIVATION_TIME, gui.EASING_OUTBOUNCE)
|
||||
else
|
||||
gui.set_color(instance.node, ui_animate.TINT_SHOW)
|
||||
gui.set_scale(instance.node, M.DEFAULT_ACTIVATE_SCALE)
|
||||
instance.disabled = false
|
||||
if callback then
|
||||
callback(instance.parent.parent)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
42
druid/base/text.lua
Normal file
42
druid/base/text.lua
Normal file
@@ -0,0 +1,42 @@
|
||||
local M = {}
|
||||
|
||||
local ui_animate = require "druid.help_modules.druid_animate"
|
||||
|
||||
--- Bounce text field
|
||||
function M.bounce(instance, callback)
|
||||
gui.set_scale(instance.node, instance.scale_from)
|
||||
ui_animate.bounce(nil, instance.node, instance.scale_to, callback)
|
||||
end
|
||||
|
||||
--- Set text to text field
|
||||
-- @param set_to - set value to text field
|
||||
function M.set_to(instance, set_to)
|
||||
instance.last_value = set_to
|
||||
gui.set_text(instance.node, set_to)
|
||||
end
|
||||
|
||||
--- Set color
|
||||
-- @param color
|
||||
function M.set_color(instance, color)
|
||||
instance.last_color = color
|
||||
gui.set_color(instance.node, color)
|
||||
end
|
||||
|
||||
--- Set scale
|
||||
-- @param scale
|
||||
function M.set_scale(instance, scale)
|
||||
instance.last_scale = scale
|
||||
gui.set_scale(instance.node, scale)
|
||||
end
|
||||
|
||||
--- Called when layout updated (rotate for example)
|
||||
function M.on_layout_updated(instance)
|
||||
if instance.last_color then
|
||||
M.set_color(instance, instance.last_color)
|
||||
end
|
||||
if instance.last_scale then
|
||||
M.set_scale(instance, instance.last_scale)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
53
druid/base/timer.lua
Normal file
53
druid/base/timer.lua
Normal file
@@ -0,0 +1,53 @@
|
||||
local M = {}
|
||||
|
||||
local formats = require "druid.help_modules.formats"
|
||||
|
||||
--- Set text to text field
|
||||
-- @param set_to - set value in seconds
|
||||
function M.set_to(instance, set_to)
|
||||
instance.last_value = set_to
|
||||
gui.set_text(instance.node, formats.second_string_min(set_to))
|
||||
end
|
||||
|
||||
--- Called when layout updated (rotate for example)
|
||||
function M.on_layout_updated(instance)
|
||||
M.set_to(instance, instance.last_value)
|
||||
end
|
||||
|
||||
--- Called when update
|
||||
-- @param is_on - boolean is timer on
|
||||
function M.set_work_mode(instance, is_on)
|
||||
instance.is_on = is_on
|
||||
end
|
||||
|
||||
--- Set time interval
|
||||
-- @param from - "from" time in seconds
|
||||
-- @param to - "to" time in seconds
|
||||
function M.set_interval(instance, from, to)
|
||||
instance.second_from = from
|
||||
instance.seconds_counter = from
|
||||
instance.seconds_temp = 0
|
||||
instance.seconds_to = to
|
||||
instance.second_step = from < to and 1 or - 1
|
||||
M.set_work_mode(instance, true)
|
||||
M.set_to(instance, from)
|
||||
end
|
||||
|
||||
--- Called when update
|
||||
-- @param dt - delta time
|
||||
function M.on_updated(instance, dt)
|
||||
if instance.is_on then
|
||||
instance.seconds_temp = instance.seconds_temp + dt
|
||||
if instance.seconds_temp > 1 then
|
||||
instance.seconds_temp = instance.seconds_temp - 1
|
||||
instance.seconds_counter = instance.seconds_counter + instance.second_step
|
||||
M.set_to(instance, instance.seconds_counter)
|
||||
if instance.seconds_counter == instance.seconds_to then
|
||||
instance.is_on = false
|
||||
instance.callback(instance)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
Reference in New Issue
Block a user