update scroll and helper

This commit is contained in:
Insality
2019-09-25 20:12:52 +03:00
parent 4ce8e85d15
commit 099eaa1e10
3 changed files with 91 additions and 39 deletions

View File

@@ -99,10 +99,7 @@ end
local function get_zone_center(self)
local pos = vmath.vector3(self.pos)
pos.x = pos.x + self.center_offset.x
pos.y = pos.y + self.center_offset.y
return pos
return self.pos + self.center_offset
end
@@ -257,7 +254,7 @@ end
function M.on_input(self, action_id, action)
if action_id ~= data.A_TOUCH then
if action_id ~= data.ACTION_TOUCH then
return false
end
local inp = self.input
@@ -289,18 +286,21 @@ function M.on_input(self, action_id, action)
M.current_scroll = self
end
end
if M.current_scroll == self then
add_delta(self, action.dx, action.dy)
result = true
end
end
end
if inp.touch and not action.pressed then
if M.current_scroll == self then
add_delta(self, action.dx, action.dy)
result = true
end
end
if action.released then
inp.touch = false
inp.side = false
if M.current_scroll == self then
M.current_scroll = nil
inp.touch = false
inp.side = false
result = true
end
check_threshold(self)
@@ -311,7 +311,7 @@ end
--- Start scroll to point (x, y, z)
function M.scroll_to(self, point)
function M.scroll_to(self, point, is_instant)
local b = self.border
local target = vmath.vector3(point)
target.x = helper.clamp(point.x - self.center_offset.x, b.x, b.z)
@@ -319,12 +319,18 @@ function M.scroll_to(self, point)
cancel_animate(self)
self.animate = true
gui.animate(self.node, gui.PROP_POSITION, target, gui.EASING_OUTSINE, settings.ANIM_SPEED, 0, function()
self.animate = false
self.animate = not is_instant
if is_instant then
self.target = target
set_pos(self, target)
end)
else
gui.animate(self.node, gui.PROP_POSITION, target, gui.EASING_OUTSINE, settings.ANIM_SPEED, 0, function()
self.animate = false
self.target = target
set_pos(self, target)
end)
end
end
@@ -384,4 +390,4 @@ function M.set_border(self, border)
end
return M
return M