mirror of
https://github.com/Insality/druid.git
synced 2025-06-27 18:37:44 +02:00
Separate style progrese
This commit is contained in:
parent
efef4d194d
commit
125506a4f1
@ -6,8 +6,6 @@
|
|||||||
-- Repeated tap
|
-- Repeated tap
|
||||||
|
|
||||||
local const = require("druid.const")
|
local const = require("druid.const")
|
||||||
local settings = require("druid.settings")
|
|
||||||
local b_settings = settings.button
|
|
||||||
local helper = require("druid.helper")
|
local helper = require("druid.helper")
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
@ -26,16 +24,16 @@ M.interest = {
|
|||||||
-- @tparam[opt] string event Button react event, const.ACTION_TOUCH by default
|
-- @tparam[opt] string event Button react event, const.ACTION_TOUCH by default
|
||||||
function M.init(self, node, callback, params, anim_node, event)
|
function M.init(self, node, callback, params, anim_node, event)
|
||||||
assert(callback, "Button should have callback. To block input on zone use blocker component")
|
assert(callback, "Button should have callback. To block input on zone use blocker component")
|
||||||
self.style = self.druid_style.BUTTON or {}
|
self.style = helper.get_style(self, "BUTTON")
|
||||||
|
|
||||||
self.node = helper.node(node)
|
self.node = helper.node(node)
|
||||||
|
|
||||||
self.event = const.ACTION_TOUCH
|
self.event = const.ACTION_TOUCH
|
||||||
self.anim_node = anim_node and helper.node(anim_node) or self.node
|
self.anim_node = anim_node and helper.node(anim_node) or self.node
|
||||||
self.scale_from = gui.get_scale(self.anim_node)
|
self.scale_from = gui.get_scale(self.anim_node)
|
||||||
self.pos = gui.get_position(self.anim_node)
|
self.pos = gui.get_position(self.anim_node)
|
||||||
self.callback = callback
|
self.callback = callback
|
||||||
self.params = params
|
self.params = params
|
||||||
self.hover_anim = b_settings.IS_HOVER
|
self.hover_anim = self.style.IS_HOVER
|
||||||
self.click_zone = nil
|
self.click_zone = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -3,8 +3,6 @@
|
|||||||
|
|
||||||
local const = require("druid.const")
|
local const = require("druid.const")
|
||||||
local helper = require("druid.helper")
|
local helper = require("druid.helper")
|
||||||
local settings = require("druid.settings")
|
|
||||||
local p_settings = settings.progress
|
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
@ -20,14 +18,12 @@ M.interest = {
|
|||||||
-- @tparam string key Progress bar direction (x or y)
|
-- @tparam string key Progress bar direction (x or y)
|
||||||
-- @tparam number init_value Initial value of progress bar
|
-- @tparam number init_value Initial value of progress bar
|
||||||
function M.init(self, node, key, init_value)
|
function M.init(self, node, key, init_value)
|
||||||
if key ~= const.SIDE.X and key ~= const.SIDE.Y then
|
assert(key == const.SIDE.X or const.SIDE.Y, "Progress bar key should be 'x' or 'y'")
|
||||||
settings.log("progress component: key must be 'x' or 'y'. Passed:", key)
|
|
||||||
key = const.SIDE.X
|
|
||||||
end
|
|
||||||
|
|
||||||
self.prop = hash("scale."..key)
|
self.prop = hash("scale."..key)
|
||||||
self.key = key
|
self.key = key
|
||||||
|
|
||||||
|
self.style = helper.get_style(self, "PROGRESS")
|
||||||
self.node = helper.node(node)
|
self.node = helper.node(node)
|
||||||
self.scale = gui.get_scale(self.node)
|
self.scale = gui.get_scale(self.node)
|
||||||
self.size = gui.get_size(self.node)
|
self.size = gui.get_size(self.node)
|
||||||
@ -152,8 +148,8 @@ end
|
|||||||
function M.update(self, dt)
|
function M.update(self, dt)
|
||||||
if self.target then
|
if self.target then
|
||||||
local prev_value = self.last_value
|
local prev_value = self.last_value
|
||||||
local step = math.abs(self.last_value - self.target) * (p_settings.SPEED*dt)
|
local step = math.abs(self.last_value - self.target) * (self.style.SPEED*dt)
|
||||||
step = math.max(step, p_settings.MIN_DELTA)
|
step = math.max(step, self.style.MIN_DELTA)
|
||||||
self:set_to(helper.step(self.last_value, self.target, step))
|
self:set_to(helper.step(self.last_value, self.target, step))
|
||||||
|
|
||||||
if self.last_value == self.target then
|
if self.last_value == self.target then
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
local helper = require("druid.helper")
|
local helper = require("druid.helper")
|
||||||
local const = require("druid.const")
|
local const = require("druid.const")
|
||||||
local settings = require("druid.settings").scroll
|
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
@ -18,10 +17,12 @@ M.current_scroll = nil
|
|||||||
|
|
||||||
|
|
||||||
function M.init(self, scroll_parent, input_zone, border)
|
function M.init(self, scroll_parent, input_zone, border)
|
||||||
|
self.style = helper.get_style(self, "SCROLL")
|
||||||
self.node = helper.node(scroll_parent)
|
self.node = helper.node(scroll_parent)
|
||||||
self.input_zone = helper.node(input_zone)
|
self.input_zone = helper.node(input_zone)
|
||||||
|
|
||||||
self.zone_size = gui.get_size(self.input_zone)
|
self.zone_size = gui.get_size(self.input_zone)
|
||||||
self.soft_size = settings.SOFT_ZONE_SIZE
|
self.soft_size = self.style.SOFT_ZONE_SIZE
|
||||||
|
|
||||||
-- Distance from node to node's center
|
-- Distance from node to node's center
|
||||||
local offset = helper.get_pivot_offset(gui.get_pivot(self.input_zone))
|
local offset = helper.get_pivot_offset(gui.get_pivot(self.input_zone))
|
||||||
@ -61,16 +62,16 @@ local function check_soft_target(self)
|
|||||||
local b = self.border
|
local b = self.border
|
||||||
|
|
||||||
if t.y < b.y then
|
if t.y < b.y then
|
||||||
t.y = helper.step(t.y, b.y, math.abs(t.y - b.y) * settings.BACK_SPEED)
|
t.y = helper.step(t.y, b.y, math.abs(t.y - b.y) * self.style.BACK_SPEED)
|
||||||
end
|
end
|
||||||
if t.x < b.x then
|
if t.x < b.x then
|
||||||
t.x = helper.step(t.x, b.x, math.abs(t.x - b.x) * settings.BACK_SPEED)
|
t.x = helper.step(t.x, b.x, math.abs(t.x - b.x) * self.style.BACK_SPEED)
|
||||||
end
|
end
|
||||||
if t.y > b.w then
|
if t.y > b.w then
|
||||||
t.y = helper.step(t.y, b.w, math.abs(t.y - b.w) * settings.BACK_SPEED)
|
t.y = helper.step(t.y, b.w, math.abs(t.y - b.w) * self.style.BACK_SPEED)
|
||||||
end
|
end
|
||||||
if t.x > b.z then
|
if t.x > b.z then
|
||||||
t.x = helper.step(t.x, b.z, math.abs(t.x - b.z) * settings.BACK_SPEED)
|
t.x = helper.step(t.x, b.z, math.abs(t.x - b.z) * self.style.BACK_SPEED)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -94,8 +95,8 @@ local function update_hand_scroll(self, dt)
|
|||||||
inert.x = math.abs(inert.x) * helper.sign(delta_x)
|
inert.x = math.abs(inert.x) * helper.sign(delta_x)
|
||||||
inert.y = math.abs(inert.y) * helper.sign(delta_y)
|
inert.y = math.abs(inert.y) * helper.sign(delta_y)
|
||||||
|
|
||||||
inert.x = inert.x * settings.FRICT_HOLD
|
inert.x = inert.x * self.style.FRICT_HOLD
|
||||||
inert.y = inert.y * settings.FRICT_HOLD
|
inert.y = inert.y * self.style.FRICT_HOLD
|
||||||
|
|
||||||
set_pos(self, self.target)
|
set_pos(self, self.target)
|
||||||
end
|
end
|
||||||
@ -116,11 +117,11 @@ local function check_points(self)
|
|||||||
|
|
||||||
local inert = self.inert
|
local inert = self.inert
|
||||||
if not self.is_inert then
|
if not self.is_inert then
|
||||||
if math.abs(inert.x) > settings.DEADZONE then
|
if math.abs(inert.x) > self.style.DEADZONE then
|
||||||
self:scroll_to_index(self.selected - helper.sign(inert.x))
|
self:scroll_to_index(self.selected - helper.sign(inert.x))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if math.abs(inert.y) > settings.DEADZONE then
|
if math.abs(inert.y) > self.style.DEADZONE then
|
||||||
self:scroll_to_index(self.selected + helper.sign(inert.y))
|
self:scroll_to_index(self.selected + helper.sign(inert.y))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -154,13 +155,14 @@ local function check_points(self)
|
|||||||
temp_dist_on_inert = dist
|
temp_dist_on_inert = dist
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self:scroll_to_index(index_on_inert or index)
|
self:scroll_to_index(index_on_inert or index)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function check_threshold(self)
|
local function check_threshold(self)
|
||||||
local inert = self.inert
|
local inert = self.inert
|
||||||
if not self.is_inert or vmath.length(inert) < settings.INERT_THRESHOLD then
|
if not self.is_inert or vmath.length(inert) < self.style.INERT_THRESHOLD then
|
||||||
check_points(self)
|
check_points(self)
|
||||||
inert.x = 0
|
inert.x = 0
|
||||||
inert.y = 0
|
inert.y = 0
|
||||||
@ -171,11 +173,11 @@ end
|
|||||||
local function update_free_inert(self, dt)
|
local function update_free_inert(self, dt)
|
||||||
local inert = self.inert
|
local inert = self.inert
|
||||||
if inert.x ~= 0 or inert.y ~= 0 then
|
if inert.x ~= 0 or inert.y ~= 0 then
|
||||||
self.target.x = self.pos.x + (inert.x * dt * settings.INERT_SPEED)
|
self.target.x = self.pos.x + (inert.x * dt * self.style.INERT_SPEED)
|
||||||
self.target.y = self.pos.y + (inert.y * dt * settings.INERT_SPEED)
|
self.target.y = self.pos.y + (inert.y * dt * self.style.INERT_SPEED)
|
||||||
|
|
||||||
inert.x = inert.x * settings.FRICT
|
inert.x = inert.x * self.style.FRICT
|
||||||
inert.y = inert.y * settings.FRICT
|
inert.y = inert.y * self.style.FRICT
|
||||||
|
|
||||||
-- Stop, when low inert speed and go to points
|
-- Stop, when low inert speed and go to points
|
||||||
check_threshold(self)
|
check_threshold(self)
|
||||||
@ -275,7 +277,7 @@ function M.on_input(self, action_id, action)
|
|||||||
self.target.y = self.pos.y
|
self.target.y = self.pos.y
|
||||||
else
|
else
|
||||||
local dist = helper.distance(action.x, action.y, inp.start_x, inp.start_y)
|
local dist = helper.distance(action.x, action.y, inp.start_x, inp.start_y)
|
||||||
if not M.current_scroll and dist >= settings.DEADZONE then
|
if not M.current_scroll and dist >= self.style.DEADZONE then
|
||||||
local dx = math.abs(inp.start_x - action.x)
|
local dx = math.abs(inp.start_x - action.x)
|
||||||
local dy = math.abs(inp.start_y - action.y)
|
local dy = math.abs(inp.start_y - action.y)
|
||||||
inp.side = (dx > dy) and const.SIDE.X or const.SIDE.Y
|
inp.side = (dx > dy) and const.SIDE.X or const.SIDE.Y
|
||||||
@ -331,7 +333,7 @@ function M.scroll_to(self, point, is_instant)
|
|||||||
self.target = target
|
self.target = target
|
||||||
set_pos(self, target)
|
set_pos(self, target)
|
||||||
else
|
else
|
||||||
gui.animate(self.node, gui.PROP_POSITION, target, gui.EASING_OUTSINE, settings.ANIM_SPEED, 0, function()
|
gui.animate(self.node, gui.PROP_POSITION, target, gui.EASING_OUTSINE, self.style.ANIM_SPEED, 0, function()
|
||||||
self.animate = false
|
self.animate = false
|
||||||
self.target = target
|
self.target = target
|
||||||
set_pos(self, target)
|
set_pos(self, target)
|
||||||
|
@ -4,17 +4,20 @@
|
|||||||
-- to create your own rich components.
|
-- to create your own rich components.
|
||||||
-- @module druid
|
-- @module druid
|
||||||
|
|
||||||
|
|
||||||
local const = require("druid.const")
|
local const = require("druid.const")
|
||||||
local druid_input = require("druid.helper.druid_input")
|
local druid_input = require("druid.helper.druid_input")
|
||||||
local settings = require("druid.settings")
|
local settings = require("druid.settings")
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
|
||||||
local log = settings.log
|
local log = settings.log
|
||||||
local _fct_metatable = {}
|
local _fct_metatable = {}
|
||||||
-- Temporary, what the place for it?
|
-- Temporary, what the place for it?
|
||||||
local default_style = {}
|
local default_style = {}
|
||||||
|
|
||||||
|
|
||||||
--- Basic components
|
--- Basic components
|
||||||
M.comps = {
|
M.comps = {
|
||||||
button = require("druid.base.button"),
|
button = require("druid.base.button"),
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
--- Druid helper module
|
--- Druid helper module
|
||||||
-- @module helper
|
-- @module helper
|
||||||
|
|
||||||
|
|
||||||
local const = require("druid.const")
|
local const = require("druid.const")
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
|
||||||
--- Text node or icon node can be nil
|
--- Text node or icon node can be nil
|
||||||
local function get_text_width(text_node)
|
local function get_text_width(text_node)
|
||||||
if text_node then
|
if text_node then
|
||||||
@ -154,4 +156,13 @@ function M.get_druid(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function M.get_style(self, section)
|
||||||
|
if not self.druid_style then
|
||||||
|
return {}
|
||||||
|
end
|
||||||
|
|
||||||
|
return self.druid_style[section] or {}
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
-- @module rich.progress_rich
|
-- @module rich.progress_rich
|
||||||
|
|
||||||
local helper = require("druid.helper")
|
local helper = require("druid.helper")
|
||||||
local settings = require("druid.settings")
|
|
||||||
local pr_settings = settings.progress_rich
|
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
|
||||||
function M.init(self, name, red, green, key)
|
function M.init(self, name, red, green, key)
|
||||||
self.druid = helper.get_druid(self)
|
self.druid = helper.get_druid(self)
|
||||||
|
self.style = helper.get_style(self, "PROGRESS_RICH")
|
||||||
self.red = self.druid:new_progress(red, key)
|
self.red = self.druid:new_progress(red, key)
|
||||||
self.green = self.druid:new_progress(green, key)
|
self.green = self.druid:new_progress(green, key)
|
||||||
self.fill = self.druid:new_progress(name, key)
|
self.fill = self.druid:new_progress(name, key)
|
||||||
@ -51,7 +50,7 @@ function M.to(self, to, callback)
|
|||||||
if self.fill.last_value < to then
|
if self.fill.last_value < to then
|
||||||
self.red:to(self.fill.last_value)
|
self.red:to(self.fill.last_value)
|
||||||
self.green:to(to, function()
|
self.green:to(to, function()
|
||||||
self.timer = timer.delay(pr_settings.DELAY, false, function()
|
self.timer = timer.delay(self.style.DELAY, false, function()
|
||||||
self.red:to(to)
|
self.red:to(to)
|
||||||
self.fill:to(to, callback)
|
self.fill:to(to, callback)
|
||||||
end)
|
end)
|
||||||
@ -61,7 +60,7 @@ function M.to(self, to, callback)
|
|||||||
if self.fill.last_value > to then
|
if self.fill.last_value > to then
|
||||||
self.green:to(self.red.last_value)
|
self.green:to(self.red.last_value)
|
||||||
self.fill:to(to, function()
|
self.fill:to(to, function()
|
||||||
self.timer = timer.delay(pr_settings.DELAY, false, function()
|
self.timer = timer.delay(self.style.DELAY, false, function()
|
||||||
self.green:to(to)
|
self.green:to(to)
|
||||||
self.red:to(to, callback)
|
self.red:to(to, callback)
|
||||||
end)
|
end)
|
||||||
|
@ -3,32 +3,9 @@
|
|||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
-- TODO: to JSON?
|
|
||||||
M.is_debug = false
|
M.is_debug = false
|
||||||
M.button = {
|
|
||||||
IS_HOVER = true,
|
|
||||||
IS_HOLD = true
|
|
||||||
}
|
|
||||||
|
|
||||||
M.progress = {
|
|
||||||
SPEED = 5, -- progress bar fill rate, more faster
|
|
||||||
MIN_DELTA = 0.005
|
|
||||||
}
|
|
||||||
|
|
||||||
M.progress_rich = {
|
|
||||||
DELAY = 1, -- delay in seconds before main fill
|
|
||||||
}
|
|
||||||
|
|
||||||
M.scroll = {
|
|
||||||
FRICT_HOLD = 0.8, -- mult. for inert, while touching
|
|
||||||
FRICT = 0.93, -- mult for free inert
|
|
||||||
INERT_THRESHOLD = 2, -- speed to stop inertion
|
|
||||||
INERT_SPEED = 25, -- koef. of inert speed
|
|
||||||
DEADZONE = 6, -- in px
|
|
||||||
SOFT_ZONE_SIZE = 160, -- size of outside zone (back move)
|
|
||||||
BACK_SPEED = 0.2, -- lerp speed
|
|
||||||
ANIM_SPEED = 0.3, -- gui.animation speed to point
|
|
||||||
}
|
|
||||||
|
|
||||||
function M.get_text(name)
|
function M.get_text(name)
|
||||||
-- override to get text for localized text
|
-- override to get text for localized text
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
local M = {}
|
|
||||||
|
|
||||||
|
|
||||||
M.BUTTON = {
|
|
||||||
HOVER_SCALE = vmath.vector3(-0.025, -0.025, 1),
|
|
||||||
HOVER_TIME = 0.05,
|
|
||||||
SCALE_CHANGE = vmath.vector3(-0.05, - 0.05, 1),
|
|
||||||
BTN_SOUND = "click",
|
|
||||||
BTN_SOUND_DISABLED = "click",
|
|
||||||
DISABLED_COLOR = vmath.vector4(0, 0, 0, 1),
|
|
||||||
ENABLED_COLOR = vmath.vector4(1),
|
|
||||||
}
|
|
||||||
|
|
||||||
return M
|
|
@ -1,37 +1,66 @@
|
|||||||
local settings = require("druid.settings")
|
local settings = require("druid.settings")
|
||||||
local anims = require("druid.styles.bounce.anims")
|
local anims = require("druid.styles.bounce.anims")
|
||||||
local const = require("druid.styles.bounce.const")
|
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
|
||||||
M.BUTTON = {
|
M.BUTTON = {
|
||||||
|
HOVER_SCALE = vmath.vector3(-0.025, -0.025, 1),
|
||||||
|
HOVER_TIME = 0.05,
|
||||||
|
SCALE_CHANGE = vmath.vector3(-0.05, - 0.05, 1),
|
||||||
|
BTN_SOUND = "click",
|
||||||
|
BTN_SOUND_DISABLED = "click",
|
||||||
|
DISABLED_COLOR = vmath.vector4(0, 0, 0, 1),
|
||||||
|
ENABLED_COLOR = vmath.vector4(1),
|
||||||
|
IS_HOVER = true,
|
||||||
|
|
||||||
on_hover = function(self, node, state)
|
on_hover = function(self, node, state)
|
||||||
if self.hover_anim then
|
if self.hover_anim then
|
||||||
local scale_to = self.scale_from + const.BUTTON.HOVER_SCALE
|
local scale_to = self.scale_from + M.BUTTON.HOVER_SCALE
|
||||||
|
|
||||||
local target_scale = state and scale_to or self.scale_from
|
local target_scale = state and scale_to or self.scale_from
|
||||||
anims.hover_scale(self, target_scale, const.BUTTON.HOVER_TIME)
|
anims.hover_scale(self, target_scale, M.BUTTON.HOVER_TIME)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_click = function(self, node)
|
on_click = function(self, node)
|
||||||
local scale_to = self.scale_from + const.BUTTON.SCALE_CHANGE
|
local scale_to = self.scale_from + M.BUTTON.SCALE_CHANGE
|
||||||
anims.tap_scale_animation(self, node, scale_to)
|
anims.tap_scale_animation(self, node, scale_to)
|
||||||
settings.play_sound(const.BUTTON.BTN_SOUND)
|
settings.play_sound(M.BUTTON.BTN_SOUND)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_click_disabled = function(self, node)
|
on_click_disabled = function(self, node)
|
||||||
settings.play_sound(const.BUTTON.BTN_SOUND_DISABLED)
|
settings.play_sound(M.BUTTON.BTN_SOUND_DISABLED)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_set_enabled = function(self, node, state)
|
on_set_enabled = function(self, node, state)
|
||||||
if state then
|
if state then
|
||||||
gui.set_color(node, const.BUTTON.ENABLED_COLOR)
|
gui.set_color(node, M.BUTTON.ENABLED_COLOR)
|
||||||
else
|
else
|
||||||
gui.set_color(node, const.BUTTON.DISABLED_COLOR)
|
gui.set_color(node, M.BUTTON.DISABLED_COLOR)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
M.SCROLL = {
|
||||||
|
FRICT_HOLD = 0.8, -- mult. for inert, while touching
|
||||||
|
FRICT = 0.93, -- mult for free inert
|
||||||
|
INERT_THRESHOLD = 2, -- speed to stop inertion
|
||||||
|
INERT_SPEED = 25, -- koef. of inert speed
|
||||||
|
DEADZONE = 6, -- in px
|
||||||
|
SOFT_ZONE_SIZE = 160, -- size of outside zone (back move)
|
||||||
|
BACK_SPEED = 0.2, -- lerp speed
|
||||||
|
ANIM_SPEED = 0.3, -- gui.animation speed to point
|
||||||
|
}
|
||||||
|
|
||||||
|
M.PROGRESS = {
|
||||||
|
SPEED = 5, -- progress bar fill rate, more faster
|
||||||
|
MIN_DELTA = 0.005
|
||||||
|
}
|
||||||
|
|
||||||
|
M.PROGRESS_RICH = {
|
||||||
|
DELAY = 1, -- delay in seconds before main fill
|
||||||
|
}
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
Loading…
x
Reference in New Issue
Block a user