mirror of
https://github.com/Insality/druid.git
synced 2025-06-27 10:27:47 +02:00
check project code style. add .luacheckrc (#7)
This commit is contained in:
parent
235476fee4
commit
12f5f22b69
51
.luacheckrc
Normal file
51
.luacheckrc
Normal file
@ -0,0 +1,51 @@
|
||||
std = "max"
|
||||
files['.luacheckrc'].global = false
|
||||
unused_args = false
|
||||
|
||||
max_code_line_length = 90
|
||||
max_comment_line_length = false
|
||||
|
||||
globals = {
|
||||
"sys",
|
||||
"go",
|
||||
"gui",
|
||||
"label",
|
||||
"render",
|
||||
"crash",
|
||||
"sprite",
|
||||
"sound",
|
||||
"tilemap",
|
||||
"spine",
|
||||
"particlefx",
|
||||
"physics",
|
||||
"factory",
|
||||
"collectionfactory",
|
||||
"iac",
|
||||
"msg",
|
||||
"vmath",
|
||||
"url",
|
||||
"http",
|
||||
"image",
|
||||
"json",
|
||||
"zlib",
|
||||
"iap",
|
||||
"push",
|
||||
"facebook",
|
||||
"hash",
|
||||
"hash_to_hex",
|
||||
"pprint",
|
||||
"init",
|
||||
"final",
|
||||
"update",
|
||||
"on_input",
|
||||
"on_message",
|
||||
"on_reload",
|
||||
"socket",
|
||||
"table",
|
||||
"debug",
|
||||
"timer",
|
||||
"window",
|
||||
"buffer",
|
||||
"resource",
|
||||
"defos",
|
||||
}
|
15
README.md
15
README.md
@ -1,14 +1,15 @@
|
||||
# druid
|
||||
# Defold Druid
|
||||
Defold UI library
|
||||
--
|
||||
|
||||
This project was created from the "empty" project template.
|
||||
# Install
|
||||
|
||||
The settings in ["game.project"](defold://open?path=/game.project) are all the default. A bootstrap empty ["main.collection"](defold://open?path=/main/main.collection) is included.
|
||||
# Setup
|
||||
|
||||
Check out [the documentation pages](https://defold.com/learn) for examples, tutorials, manuals and API docs.
|
||||
# Usage
|
||||
|
||||
If you run into trouble, help is available in [our forum](https://forum.defold.com).
|
||||
# API
|
||||
|
||||
Happy Defolding!
|
||||
# Authors
|
||||
|
||||
---
|
||||
# License
|
||||
|
@ -1,7 +1,6 @@
|
||||
local data = require("druid.data")
|
||||
|
||||
local M = {}
|
||||
|
||||
M.interest = {
|
||||
data.ON_INPUT
|
||||
}
|
||||
@ -27,4 +26,4 @@ function M.on_input(instance, action_id, action)
|
||||
end
|
||||
|
||||
|
||||
return M
|
||||
return M
|
@ -4,7 +4,6 @@ local settings = require("druid.settings")
|
||||
local b_settings = settings.button
|
||||
|
||||
local M = {}
|
||||
|
||||
M.interest = {
|
||||
data.ON_INPUT
|
||||
}
|
||||
@ -15,9 +14,9 @@ M.DEFAULT_ACTIVATE_SCALE = vmath.vector3(1, 1, 1)
|
||||
M.DEFAUL_ACTIVATION_TIME = 0.2
|
||||
|
||||
|
||||
function M.init(instance, callback, params, animate_node_name, event)
|
||||
function M.init(instance, callback, params, anim_node)
|
||||
instance.event = data.A_TOUCH
|
||||
instance.anim_node = animate_node_name and gui.get_node(animate_node_name) or instance.node
|
||||
instance.anim_node = anim_node and gui.get_node(anim_node) or instance.node
|
||||
instance.scale_from = gui.get_scale(instance.anim_node)
|
||||
instance.scale_to = instance.scale_from + b_settings.SCALE_CHANGE
|
||||
instance.scale_hover_to = instance.scale_from + b_settings.HOVER_SCALE
|
||||
@ -40,6 +39,7 @@ local function set_hover(instance, state)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function on_button_release(instance)
|
||||
if not instance.disabled then
|
||||
if not instance.stub and instance.can_action then
|
||||
@ -83,6 +83,7 @@ function M.on_input(instance, action_id, action)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function M.tap_scale_animation(instance)
|
||||
ui_animate.scale_to(instance, instance.anim_node, instance.scale_to,
|
||||
function()
|
||||
@ -109,12 +110,14 @@ function M.deactivate(instance, is_animate, callback)
|
||||
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)
|
||||
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)
|
||||
@ -137,12 +140,14 @@ function M.activate(instance, is_animate, callback)
|
||||
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)
|
||||
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)
|
||||
|
@ -3,70 +3,71 @@ local settings = require("druid.settings")
|
||||
|
||||
local M = {}
|
||||
M.interest = {
|
||||
data.TRANSLATABLE,
|
||||
data.LAYOUT_CHANGED
|
||||
data.TRANSLATABLE,
|
||||
data.LAYOUT_CHANGED
|
||||
}
|
||||
|
||||
|
||||
function M.init(instance, value, is_locale)
|
||||
instance.last_color = gui.get_color(instance.node)
|
||||
if is_locale then
|
||||
instance.text_id = value
|
||||
instance:translate()
|
||||
else
|
||||
instance:set_to(value or 0)
|
||||
end
|
||||
return instance
|
||||
instance.last_color = gui.get_color(instance.node)
|
||||
if is_locale then
|
||||
instance.text_id = value
|
||||
instance:translate()
|
||||
else
|
||||
instance:set_to(value or 0)
|
||||
end
|
||||
return instance
|
||||
end
|
||||
|
||||
|
||||
function M.translate(instance)
|
||||
if instance.text_id then
|
||||
instance:set_to(settings.get_text(instance.text_id))
|
||||
end
|
||||
if instance.text_id then
|
||||
instance:set_to(settings.get_text(instance.text_id))
|
||||
end
|
||||
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)
|
||||
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)
|
||||
instance.last_color = color
|
||||
gui.set_color(instance.node, color)
|
||||
end
|
||||
|
||||
|
||||
--- Set alpha
|
||||
-- @param alpha, number [0-1]
|
||||
function M.set_alpha(instance, alpha)
|
||||
instance.last_color.w = alpha
|
||||
gui.set_color(instance.node, instance.last_color)
|
||||
instance.last_color.w = alpha
|
||||
gui.set_color(instance.node, instance.last_color)
|
||||
end
|
||||
|
||||
|
||||
--- Set scale
|
||||
-- @param scale
|
||||
function M.set_scale(instance, scale)
|
||||
instance.last_scale = scale
|
||||
gui.set_scale(instance.node, 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
|
||||
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
|
||||
|
||||
return M
|
@ -3,49 +3,48 @@ local formats = require("druid.helper.formats")
|
||||
local helper = require("druid.helper.ui_helper")
|
||||
|
||||
local M = {}
|
||||
|
||||
M.interest = {
|
||||
data.LAYOUT_CHANGED,
|
||||
data.ON_UPDATE
|
||||
data.LAYOUT_CHANGED,
|
||||
data.ON_UPDATE
|
||||
}
|
||||
|
||||
local empty = function() end
|
||||
|
||||
function M.init(instance, seconds_from, seconds_to, callback)
|
||||
seconds_from = math.max(seconds_from, 0)
|
||||
seconds_to = math.max(seconds_to or 0, 0)
|
||||
callback = callback or empty
|
||||
seconds_from = math.max(seconds_from, 0)
|
||||
seconds_to = math.max(seconds_to or 0, 0)
|
||||
callback = callback or empty
|
||||
|
||||
instance:set_to(seconds_from)
|
||||
instance:set_interval(seconds_from, seconds_to)
|
||||
instance.callback = callback
|
||||
instance:set_to(seconds_from)
|
||||
instance:set_interval(seconds_from, seconds_to)
|
||||
instance.callback = callback
|
||||
|
||||
if seconds_to - seconds_from == 0 then
|
||||
instance:set_state(false)
|
||||
instance.callback(instance.parent.parent, instance)
|
||||
end
|
||||
return instance
|
||||
if seconds_to - seconds_from == 0 then
|
||||
instance:set_state(false)
|
||||
instance.callback(instance.parent.parent, instance)
|
||||
end
|
||||
return instance
|
||||
end
|
||||
|
||||
|
||||
--- 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))
|
||||
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)
|
||||
M.set_to(instance, instance.last_value)
|
||||
end
|
||||
|
||||
|
||||
--- Called when update
|
||||
-- @param is_on - boolean is timer on
|
||||
function M.set_state(instance, is_on)
|
||||
instance.is_on = is_on
|
||||
instance.is_on = is_on
|
||||
end
|
||||
|
||||
|
||||
@ -53,32 +52,33 @@ end
|
||||
-- @param from - "from" time in seconds
|
||||
-- @param to - "to" time in seconds
|
||||
function M.set_interval(instance, from, to)
|
||||
instance.from = from
|
||||
instance.value = from
|
||||
instance.temp = 0
|
||||
instance.target = to
|
||||
M.set_state(instance, true)
|
||||
M.set_to(instance, from)
|
||||
instance.from = from
|
||||
instance.value = from
|
||||
instance.temp = 0
|
||||
instance.target = to
|
||||
M.set_state(instance, true)
|
||||
M.set_to(instance, from)
|
||||
end
|
||||
|
||||
|
||||
--- Called when update
|
||||
-- @param dt - delta time
|
||||
function M.update(instance, dt)
|
||||
if instance.is_on then
|
||||
instance.temp = instance.temp + dt
|
||||
local dist = math.min(1, math.abs(instance.value - instance.target))
|
||||
if instance.is_on then
|
||||
instance.temp = instance.temp + dt
|
||||
local dist = math.min(1, math.abs(instance.value - instance.target))
|
||||
|
||||
if instance.temp > dist then
|
||||
instance.temp = instance.temp - dist
|
||||
instance.value = helper.step(instance.value, instance.target, 1)
|
||||
M.set_to(instance, instance.value)
|
||||
if instance.value == instance.target then
|
||||
instance:set_state(false)
|
||||
instance.callback(instance.parent.parent, instance)
|
||||
end
|
||||
end
|
||||
end
|
||||
if instance.temp > dist then
|
||||
instance.temp = instance.temp - dist
|
||||
instance.value = helper.step(instance.value, instance.target, 1)
|
||||
M.set_to(instance, instance.value)
|
||||
if instance.value == instance.target then
|
||||
instance:set_state(false)
|
||||
instance.callback(instance.parent.parent, instance)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
return M
|
@ -9,9 +9,7 @@ local _factory = {}
|
||||
|
||||
local STRING = "string"
|
||||
|
||||
--- New druid era, registering components
|
||||
M.comps = {
|
||||
-- basic
|
||||
button = require("druid.base.button"),
|
||||
android_back = require("druid.base.android_back"),
|
||||
text = require("druid.base.text"),
|
||||
@ -34,6 +32,7 @@ function M.register(name, module)
|
||||
log("Register component", name)
|
||||
end
|
||||
|
||||
|
||||
--- Create UI instance for ui elements
|
||||
-- @return instance with all ui components
|
||||
function M.new(self)
|
||||
@ -46,7 +45,6 @@ function M.new(self)
|
||||
return factory
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
local function input_init(factory)
|
||||
if not factory.input_inited then
|
||||
@ -56,7 +54,7 @@ local function input_init(factory)
|
||||
end
|
||||
|
||||
|
||||
local function create(module, factory, name, ...)
|
||||
local function create(module, factory, name)
|
||||
local instance = setmetatable({}, {__index = module})
|
||||
instance.parent = factory
|
||||
if name then
|
||||
@ -155,4 +153,5 @@ function _factory.update(factory, dt)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return M
|
@ -2,13 +2,14 @@ local M = {}
|
||||
|
||||
local PROP_SCALE = gui.PROP_SCALE
|
||||
local PROP_POSITION = gui.PROP_POSITION
|
||||
M.PROP_POS_X = hash("position.x")
|
||||
M.PROP_POS_Y = hash("position.y")
|
||||
M.PROP_ALPHA = hash("color.w")
|
||||
local PROP_COLOR = hash("color")
|
||||
local PROP_SCALE_X = "scale.x"
|
||||
local PROP_SCALE_Y = "scale.y"
|
||||
|
||||
M.PROP_POS_X = hash("position.x")
|
||||
M.PROP_POS_Y = hash("position.y")
|
||||
M.PROP_ALPHA = hash("color.w")
|
||||
|
||||
M.TINT_HIDE = vmath.vector4(1, 1, 1, 0)
|
||||
M.TINT_SHOW = vmath.vector4(1, 1, 1, 1)
|
||||
|
||||
@ -19,155 +20,167 @@ M.SCALE_ANIMATION_TIME = 0.1
|
||||
M.BOUNCE_ANIMATION_TIME = 0.25
|
||||
M.ALPHA_ANIMATION_TIME = 0.25
|
||||
|
||||
|
||||
function M.alpha(self, node, alpha, callback, time, delay, easing, playback)
|
||||
time = time or M.ALPHA_ANIMATION_TIME
|
||||
delay = delay or 0
|
||||
easing = easing or gui.EASING_LINEAR
|
||||
playback = playback or gui.PLAYBACK_ONCE_FORWARD
|
||||
gui.animate(node, M.PROP_ALPHA, alpha, easing, time, delay,
|
||||
function()
|
||||
if callback then
|
||||
callback(self, node)
|
||||
end
|
||||
end,
|
||||
playback)
|
||||
time = time or M.ALPHA_ANIMATION_TIME
|
||||
delay = delay or 0
|
||||
easing = easing or gui.EASING_LINEAR
|
||||
playback = playback or gui.PLAYBACK_ONCE_FORWARD
|
||||
gui.animate(node, M.PROP_ALPHA, alpha, easing, time, delay,
|
||||
function()
|
||||
if callback then
|
||||
callback(self, node)
|
||||
end
|
||||
end,
|
||||
playback)
|
||||
end
|
||||
|
||||
|
||||
function M.color(self, node, color, callback, time, delay, easing, playback)
|
||||
time = time or M.ALPHA_ANIMATION_TIME
|
||||
delay = delay or 0
|
||||
easing = easing or gui.EASING_LINEAR
|
||||
playback = playback or gui.PLAYBACK_ONCE_FORWARD
|
||||
gui.animate(node, PROP_COLOR, color, easing, time, delay,
|
||||
function()
|
||||
if callback then
|
||||
callback(self, node)
|
||||
end
|
||||
end,
|
||||
playback)
|
||||
time = time or M.ALPHA_ANIMATION_TIME
|
||||
delay = delay or 0
|
||||
easing = easing or gui.EASING_LINEAR
|
||||
playback = playback or gui.PLAYBACK_ONCE_FORWARD
|
||||
gui.animate(node, PROP_COLOR, color, easing, time, delay,
|
||||
function()
|
||||
if callback then
|
||||
callback(self, node)
|
||||
end
|
||||
end,
|
||||
playback)
|
||||
end
|
||||
|
||||
|
||||
function M.shake(self, node, callback, str, time)
|
||||
str = str or - 30
|
||||
time = time or 0.25
|
||||
local pos = gui.get_position(node)
|
||||
pos.x = pos.x + str
|
||||
gui.animate(node, PROP_POSITION, pos, gui.EASING_INELASTIC, time,
|
||||
0,
|
||||
function()
|
||||
if callback then
|
||||
callback(self)
|
||||
end
|
||||
end,
|
||||
gui.PLAYBACK_ONCE_BACKWARD
|
||||
)
|
||||
str = str or - 30
|
||||
time = time or 0.25
|
||||
local pos = gui.get_position(node)
|
||||
pos.x = pos.x + str
|
||||
gui.animate(node, PROP_POSITION, pos, gui.EASING_INELASTIC, time,
|
||||
0,
|
||||
function()
|
||||
if callback then
|
||||
callback(self)
|
||||
end
|
||||
end,
|
||||
gui.PLAYBACK_ONCE_BACKWARD
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
function M.bounce(self, node, change_to, callback, time, easing, playback, delaly)
|
||||
time = time or M.BOUNCE_ANIMATION_TIME
|
||||
delaly = delaly or 0
|
||||
easing = easing or gui.EASING_OUTSINE
|
||||
playback = playback or gui.PLAYBACK_ONCE_PINGPONG
|
||||
gui.animate(node, PROP_SCALE, change_to, easing, time, delaly,
|
||||
function()
|
||||
if callback then
|
||||
callback(self)
|
||||
end
|
||||
end,
|
||||
playback)
|
||||
time = time or M.BOUNCE_ANIMATION_TIME
|
||||
delaly = delaly or 0
|
||||
easing = easing or gui.EASING_OUTSINE
|
||||
playback = playback or gui.PLAYBACK_ONCE_PINGPONG
|
||||
gui.animate(node, PROP_SCALE, change_to, easing, time, delaly,
|
||||
function()
|
||||
if callback then
|
||||
callback(self)
|
||||
end
|
||||
end,
|
||||
playback)
|
||||
end
|
||||
|
||||
|
||||
function M.fly_to(self, node, to_pos, speed, callback, delay, easing)
|
||||
easing = easing or gui.EASING_OUTSINE
|
||||
delay = delay or 0
|
||||
local time = vmath.length(to_pos - gui.get_position(node)) / 100 / speed
|
||||
gui.animate(node, gui.PROP_POSITION, to_pos, easing, time, delay,
|
||||
function()
|
||||
if callback then
|
||||
callback(self, node)
|
||||
end
|
||||
end)
|
||||
easing = easing or gui.EASING_OUTSINE
|
||||
delay = delay or 0
|
||||
local time = vmath.length(to_pos - gui.get_position(node)) / 100 / speed
|
||||
gui.animate(node, gui.PROP_POSITION, to_pos, easing, time, delay,
|
||||
function()
|
||||
if callback then
|
||||
callback(self, node)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
function M.fly_by_x(self, node, to_x, time, callback, delay, easing, playback)
|
||||
playback = playback or gui.PLAYBACK_ONCE_FORWARD
|
||||
easing = easing or gui.EASING_OUTSINE
|
||||
delay = delay or 0
|
||||
gui.animate(node, M.PROP_POS_X, to_x, easing, time, delay,
|
||||
function()
|
||||
if callback then
|
||||
callback(self, node)
|
||||
end
|
||||
end,
|
||||
playback)
|
||||
playback = playback or gui.PLAYBACK_ONCE_FORWARD
|
||||
easing = easing or gui.EASING_OUTSINE
|
||||
delay = delay or 0
|
||||
gui.animate(node, M.PROP_POS_X, to_x, easing, time, delay,
|
||||
function()
|
||||
if callback then
|
||||
callback(self, node)
|
||||
end
|
||||
end,
|
||||
playback)
|
||||
end
|
||||
|
||||
|
||||
function M.fly_by_y(self, node, to_y, time, callback, delay, easing, playback)
|
||||
playback = playback or gui.PLAYBACK_ONCE_FORWARD
|
||||
easing = easing or gui.EASING_OUTSINE
|
||||
delay = delay or 0
|
||||
time = time or 0.25
|
||||
gui.animate(node, M.PROP_POS_Y, to_y, easing, time, delay,
|
||||
function()
|
||||
if callback then
|
||||
callback(self, node)
|
||||
end
|
||||
end,
|
||||
playback)
|
||||
playback = playback or gui.PLAYBACK_ONCE_FORWARD
|
||||
easing = easing or gui.EASING_OUTSINE
|
||||
delay = delay or 0
|
||||
time = time or 0.25
|
||||
gui.animate(node, M.PROP_POS_Y, to_y, easing, time, delay,
|
||||
function()
|
||||
if callback then
|
||||
callback(self, node)
|
||||
end
|
||||
end,
|
||||
playback)
|
||||
end
|
||||
|
||||
|
||||
function M.scale_to(self, node, to, callback, time, delay, easing)
|
||||
easing = easing or gui.EASING_INSINE
|
||||
time = time or M.SCALE_ANIMATION_TIME
|
||||
delay = delay or 0
|
||||
time = time or 0.25
|
||||
gui.animate(node, PROP_SCALE, to, easing, time, delay,
|
||||
function()
|
||||
if callback then
|
||||
callback(self, node)
|
||||
end
|
||||
end
|
||||
)
|
||||
easing = easing or gui.EASING_INSINE
|
||||
time = time or M.SCALE_ANIMATION_TIME
|
||||
delay = delay or 0
|
||||
time = time or 0.25
|
||||
gui.animate(node, PROP_SCALE, to, easing, time, delay,
|
||||
function()
|
||||
if callback then
|
||||
callback(self, node)
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
function M.scale(self, node, to, time)
|
||||
gui.animate(node, "scale", to, gui.EASING_OUTSINE, time)
|
||||
gui.animate(node, "scale", to, gui.EASING_OUTSINE, time)
|
||||
end
|
||||
|
||||
|
||||
function M.scale_x_from_to(self, node, from, to, callback, time, easing, delay, playback)
|
||||
easing = easing or gui.EASING_INSINE
|
||||
time = time or M.SCALE_ANIMATION_TIME
|
||||
delay = delay or 0
|
||||
playback = playback or gui.PLAYBACK_ONCE_FORWARD
|
||||
local scale = gui.get_scale(node)
|
||||
scale.x = from
|
||||
gui.set_scale(node, scale)
|
||||
gui.animate(node, PROP_SCALE_X, to, easing, time, delay,
|
||||
function()
|
||||
if callback then
|
||||
callback(self)
|
||||
end
|
||||
end,
|
||||
playback
|
||||
)
|
||||
easing = easing or gui.EASING_INSINE
|
||||
time = time or M.SCALE_ANIMATION_TIME
|
||||
delay = delay or 0
|
||||
playback = playback or gui.PLAYBACK_ONCE_FORWARD
|
||||
local scale = gui.get_scale(node)
|
||||
scale.x = from
|
||||
gui.set_scale(node, scale)
|
||||
gui.animate(node, PROP_SCALE_X, to, easing, time, delay,
|
||||
function()
|
||||
if callback then
|
||||
callback(self)
|
||||
end
|
||||
end,
|
||||
playback
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
function M.scale_y_from_to(self, node, from, to, callback, time, easing, delay, playback)
|
||||
easing = easing or gui.EASING_INSINE
|
||||
time = time or M.SCALE_ANIMATION_TIME
|
||||
delay = delay or 0
|
||||
playback = playback or gui.PLAYBACK_ONCE_FORWARD
|
||||
local scale = gui.get_scale(node)
|
||||
scale.y = from
|
||||
gui.set_scale(node, scale)
|
||||
gui.animate(node, PROP_SCALE_Y, to, easing, time, delay,
|
||||
function()
|
||||
if callback then
|
||||
callback(self)
|
||||
end
|
||||
end,
|
||||
playback
|
||||
)
|
||||
easing = easing or gui.EASING_INSINE
|
||||
time = time or M.SCALE_ANIMATION_TIME
|
||||
delay = delay or 0
|
||||
playback = playback or gui.PLAYBACK_ONCE_FORWARD
|
||||
local scale = gui.get_scale(node)
|
||||
scale.y = from
|
||||
gui.set_scale(node, scale)
|
||||
gui.animate(node, PROP_SCALE_Y, to, easing, time, delay,
|
||||
function()
|
||||
if callback then
|
||||
callback(self)
|
||||
end
|
||||
end,
|
||||
playback
|
||||
)
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
return M
|
@ -4,12 +4,15 @@ local ADD_FOCUS = hash("acquire_input_focus")
|
||||
local REMOVE_FOCUS = hash("release_input_focus")
|
||||
local PATH_OBJ = "."
|
||||
|
||||
|
||||
function M.focus()
|
||||
msg.post(PATH_OBJ, ADD_FOCUS)
|
||||
msg.post(PATH_OBJ, ADD_FOCUS)
|
||||
end
|
||||
|
||||
|
||||
function M.remove()
|
||||
msg.post(PATH_OBJ, REMOVE_FOCUS)
|
||||
msg.post(PATH_OBJ, REMOVE_FOCUS)
|
||||
end
|
||||
|
||||
|
||||
return M
|
||||
|
@ -7,28 +7,31 @@ local ZERO = "0"
|
||||
-- @param count - count of numerals
|
||||
-- @return string with need count of zero (1,3) -> 001
|
||||
function M.add_prefix_zeros(num, count)
|
||||
local result = tostring(num)
|
||||
for i = string.len(result), count - 1 do
|
||||
result = ZERO..result
|
||||
end
|
||||
return result
|
||||
local result = tostring(num)
|
||||
for i = string.len(result), count - 1 do
|
||||
result = ZERO..result
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
|
||||
-- Convert seconds to string minutes:seconds
|
||||
-- @param num - number of seconds
|
||||
-- @return string minutes:seconds
|
||||
function M.second_string_min(sec)
|
||||
local mins = math.floor(sec / 60)
|
||||
local seconds = math.floor(sec - mins * 60)
|
||||
return string.format("%.2d:%.2d", mins, seconds)
|
||||
local mins = math.floor(sec / 60)
|
||||
local seconds = math.floor(sec - mins * 60)
|
||||
return string.format("%.2d:%.2d", mins, seconds)
|
||||
end
|
||||
|
||||
|
||||
-- Interpolate string with named Parameters in Table
|
||||
-- @param s - string for interpolate
|
||||
-- @param tab - table with parameters
|
||||
-- @return string with replaced parameters
|
||||
function M.interpolate_strinng(s, tab)
|
||||
return (s:gsub('($%b{})', function(w) return tab[w:sub(3, -2)] or w end))
|
||||
return (s:gsub('($%b{})', function(w) return tab[w:sub(3, -2)] or w end))
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
return M
|
@ -1,24 +1,30 @@
|
||||
local M = {}
|
||||
|
||||
function M.centrate_text_with_icon(text_node, icon_node)
|
||||
local metr = gui.get_text_metrics_from_node(text_node)
|
||||
local scl = gui.get_scale(text_node).x
|
||||
local scl_i = gui.get_scale(icon_node).x
|
||||
local pos_i = gui.get_position(icon_node)
|
||||
local pos = gui.get_position(text_node)
|
||||
local w = metr.width * scl * scl_i
|
||||
local icon_w = gui.get_size(icon_node).x * scl_i
|
||||
local width = w + icon_w + (math.abs(pos.x) - icon_w / 2) * scl_i
|
||||
pos_i.x = width / 2 - (icon_w / 2)
|
||||
gui.set_position(icon_node, pos_i)
|
||||
function M.centrate_text_with_icon(text_node, icon_node, offset_x)
|
||||
offset_x = offset_x or 0
|
||||
local metr = gui.get_text_metrics_from_node(text_node)
|
||||
local scl = gui.get_scale(text_node).x
|
||||
local pos = gui.get_position(text_node)
|
||||
local scl_i = gui.get_scale(icon_node).x
|
||||
local pos_i = gui.get_position(icon_node)
|
||||
local w = metr.width * scl -- text width
|
||||
local icon_w = gui.get_size(icon_node).x * scl_i -- icon width
|
||||
local width = w + icon_w
|
||||
|
||||
pos.x = -width/2 + w + offset_x
|
||||
gui.set_position(text_node, pos)
|
||||
pos_i.x = width/2 - icon_w + offset_x
|
||||
gui.set_position(icon_node, pos_i)
|
||||
end
|
||||
|
||||
|
||||
function M.step(current, target, step)
|
||||
if current < target then
|
||||
return math.min(current + step, target)
|
||||
else
|
||||
return math.max(target, current - step)
|
||||
end
|
||||
if current < target then
|
||||
return math.min(current + step, target)
|
||||
else
|
||||
return math.max(target, current - step)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
return M
|
@ -6,7 +6,7 @@ M.button = {
|
||||
IS_HOVER = true,
|
||||
IS_HOLD = true,
|
||||
BTN_SOUND = "click",
|
||||
BTN_SOUND_DISABLED = "button_click_disabled",
|
||||
BTN_SOUND_DISABLED = "click_disabled",
|
||||
HOVER_SCALE = vmath.vector3(-0.025, -0.025, 1),
|
||||
HOVER_TIME = 0.05,
|
||||
SCALE_CHANGE = vmath.vector3(-0.05, - 0.05, 1),
|
||||
@ -24,6 +24,7 @@ function M.play_sound(name)
|
||||
-- override to play sound with name
|
||||
end
|
||||
|
||||
|
||||
function M.log(...)
|
||||
if M.is_debug then
|
||||
print("[Druid]: ", ...)
|
||||
@ -31,5 +32,4 @@ function M.log(...)
|
||||
end
|
||||
|
||||
|
||||
|
||||
return M
|
Loading…
x
Reference in New Issue
Block a user