From 08eae3800c8e086585d552985232edad34aa832c Mon Sep 17 00:00:00 2001 From: Insality Date: Sun, 7 Apr 2019 15:19:39 +0300 Subject: [PATCH] rename instance to self, update example --- druid/base/android_back.lua | 12 +-- druid/base/button.lua | 144 ++++++++++++++++----------------- druid/base/grid.lua | 102 +++++++++++------------ druid/base/progress.lua | 108 ++++++++++++------------- druid/base/text.lua | 66 +++++++-------- druid/base/timer.lua | 62 +++++++------- example/example.gui.gui_script | 2 + 7 files changed, 249 insertions(+), 247 deletions(-) diff --git a/druid/base/android_back.lua b/druid/base/android_back.lua index d40892c..775b01e 100644 --- a/druid/base/android_back.lua +++ b/druid/base/android_back.lua @@ -6,19 +6,19 @@ M.interest = { } -function M.init(instance, callback, params) - instance.event = data.A_ANDR_BACK - instance.callback = callback - instance.params = params +function M.init(self, callback, params) + self.event = data.A_ANDR_BACK + self.callback = callback + self.params = params end --- input handler -- @param action_id - input action id -- @param action - input action -function M.on_input(instance, action_id, action) +function M.on_input(self, action_id, action) if action[data.RELEASED] then - instance.callback(instance.parent.parent, instance.params) + self.callback(self.parent.parent, self.params) end return true end diff --git a/druid/base/button.lua b/druid/base/button.lua index 48a1d2b..f5bfab2 100644 --- a/druid/base/button.lua +++ b/druid/base/button.lua @@ -15,47 +15,47 @@ M.DEFAULT_ACTIVATE_SCALE = vmath.vector3(1, 1, 1) M.DEFAUL_ACTIVATION_TIME = 0.2 -function M.init(instance, node, callback, params, anim_node, event) - instance.node = helper.get_node(node) - instance.event = data.A_TOUCH - instance.anim_node = anim_node and helper.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 - 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.hover_anim = b_settings.IS_HOVER - instance.sound = b_settings.BTN_SOUND - instance.sound_disable = b_settings.BTN_SOUND_DISABLED - instance.ext_zone = nil +function M.init(self, node, callback, params, anim_node, event) + self.node = helper.get_node(node) + self.event = data.A_TOUCH + self.anim_node = anim_node and helper.get_node(anim_node) or self.node + self.scale_from = gui.get_scale(self.anim_node) + self.scale_to = self.scale_from + b_settings.SCALE_CHANGE + self.scale_hover_to = self.scale_from + b_settings.HOVER_SCALE + self.pos = gui.get_position(self.anim_node) + self.callback = callback + self.params = params + self.tap_anim = M.tap_scale_animation + self.back_anim = M.back_scale_animation + self.hover_anim = b_settings.IS_HOVER + self.sound = b_settings.BTN_SOUND + self.sound_disable = b_settings.BTN_SOUND_DISABLED + self.ext_zone = nil end -local function set_hover(instance, state) - if instance.hover_anim and instance._is_hovered ~= state then - local target_scale = state and instance.scale_hover_to or instance.scale_from - ui_animate.scale(instance, instance.node, target_scale, b_settings.HOVER_TIME) - instance._is_hovered = state +local function set_hover(self, state) + if self.hover_anim and self._is_hovered ~= state then + local target_scale = state and self.scale_hover_to or self.scale_from + ui_animate.scale(self, self.node, target_scale, b_settings.HOVER_TIME) + self._is_hovered = state end end -local function on_button_release(instance) - if not instance.disabled then - if not instance.stub and instance.can_action then - instance.can_action = false - instance.tap_anim(instance) - settings.play_sound(instance.sound) - instance.callback(instance.parent.parent, instance.params, instance) +local function on_button_release(self) + if not self.disabled then + if not self.stub and self.can_action then + self.can_action = false + self.tap_anim(self) + settings.play_sound(self.sound) + self.callback(self.parent.parent, self.params, self) else - set_hover(instance, false) + set_hover(self, false) end return true else - instance.sound_disable() + self.sound_disable() return false end end @@ -64,124 +64,124 @@ 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 not helper.is_enabled(instance.node) then +function M.on_input(self, action_id, action) + if not helper.is_enabled(self.node) then return false end - local is_pick = gui.pick_node(instance.node, action.x, action.y) - if instance.ext_zone then - is_pick = is_pick and gui.pick_node(instance.ext_zone, action.x, action.y) + local is_pick = gui.pick_node(self.node, action.x, action.y) + if self.ext_zone then + is_pick = is_pick and gui.pick_node(self.ext_zone, action.x, action.y) end if is_pick then if action.pressed then -- Can interact if start touch on the button - instance.can_action = true + self.can_action = true return true end if action.released then - set_hover(instance, false) - return on_button_release(instance) + set_hover(self, false) + return on_button_release(self) else - set_hover(instance, true) + set_hover(self, true) end - return not instance.disabled + return not self.disabled else -- Can't interact, if touch outside of button - instance.can_action = false - set_hover(instance, false) + self.can_action = false + set_hover(self, false) return false end end -function M.on_swipe(instance) +function M.on_swipe(self) -- unhover button if start swipe - instance.can_action = false - set_hover(instance, false) + self.can_action = false + set_hover(self, false) end -function M.tap_scale_animation(instance) - ui_animate.scale_to(instance, instance.anim_node, instance.scale_to, +function M.tap_scale_animation(self) + ui_animate.scale_to(self, self.anim_node, self.scale_to, function() - if instance.back_anim then - instance.back_anim(instance) + if self.back_anim then + self.back_anim(self) end end ) end -function M.back_scale_animation(instance) - ui_animate.scale_to(instance, instance.anim_node, instance.scale_from) +function M.back_scale_animation(self) + ui_animate.scale_to(self, self.anim_node, self.scale_from) end -function M.deactivate(instance, is_animate, callback) - instance.disabled = true +function M.deactivate(self, is_animate, callback) + self.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) + callback(self.parent.parent) end end - ui_animate.color(instance, instance.node, M.DEFAULT_DEACTIVATE_COLOR, + ui_animate.color(self, self.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, + ui_animate.scale_y_from_to(self, self.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, + ui_animate.scale_x_from_to(self, self.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) + gui.set_color(self.node, M.DEFAULT_DEACTIVATE_COLOR) + gui.set_scale(self.node, M.DEFAULT_DEACTIVATE_SCALE) if callback then - callback(instance.parent.parent) + callback(self.parent.parent) end end end -function M.activate(instance, is_animate, callback) +function M.activate(self, is_animate, callback) if is_animate then local counter = 0 local clbk = function() counter = counter + 1 if counter == 3 then - instance.disabled = false + self.disabled = false if callback then - callback(instance.parent.parent) + callback(self.parent.parent) end end end - ui_animate.color(instance, instance.node, ui_animate.TINT_SHOW, + ui_animate.color(self, self.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, + ui_animate.scale_y_from_to(self, self.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, + ui_animate.scale_x_from_to(self, self.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 + gui.set_color(self.node, ui_animate.TINT_SHOW) + gui.set_scale(self.node, M.DEFAULT_ACTIVATE_SCALE) + self.disabled = false if callback then - callback(instance.parent.parent) + callback(self.parent.parent) end end end --- Set additional node, what need to be clicked on button click -- Used, if need setup, what button can be clicked only in special zone -function M.set_ext_zone(instance, zone) - instance.ext_zone = helper.get_node(zone) +function M.set_ext_zone(self, zone) + self.ext_zone = helper.get_node(zone) end diff --git a/druid/base/grid.lua b/druid/base/grid.lua index e7e9a80..496aea3 100644 --- a/druid/base/grid.lua +++ b/druid/base/grid.lua @@ -7,107 +7,107 @@ local M = {} -- Allow different node sizes, allow animation with node insert -function M.init(instance, parent, element, in_row) - instance.parent = helper.get_node(parent) - instance.nodes = {} +function M.init(self, parent, element, in_row) + self.parent = helper.get_node(parent) + self.nodes = {} - instance.offset = vmath.vector3(0) - instance.anchor = vmath.vector3(0.5, 0, 0) - instance.in_row = in_row or 1 - instance.node_size = gui.get_size(helper.get_node(element)) - instance.border = vmath.vector4(0) - instance.border_offset = vmath.vector3(0) + self.offset = vmath.vector3(0) + self.anchor = vmath.vector3(0.5, 0, 0) + self.in_row = in_row or 1 + self.node_size = gui.get_size(helper.get_node(element)) + self.border = vmath.vector4(0) + self.border_offset = vmath.vector3(0) end -local function check_border(instance, pos) - local border = instance.border - local size = instance.node_size +local function check_border(self, pos) + local border = self.border + local size = self.node_size - local W = pos.x - size.x/2 + instance.border_offset.x - local E = pos.x + size.x/2 + instance.border_offset.x - local N = pos.y + size.y/2 + instance.border_offset.y - local S = pos.y - size.y/2 + instance.border_offset.y + local W = pos.x - size.x/2 + self.border_offset.x + local E = pos.x + size.x/2 + self.border_offset.x + local N = pos.y + size.y/2 + self.border_offset.y + local S = pos.y - size.y/2 + self.border_offset.y border.x = math.min(border.x, W) border.y = math.max(border.y, N) border.z = math.max(border.z, E) border.w = math.min(border.w, S) - instance.border_offset = vmath.vector3( - (border.x + (border.z - border.x) * instance.anchor.x), - (border.y + (border.w - border.y) * instance.anchor.y), + self.border_offset = vmath.vector3( + (border.x + (border.z - border.x) * self.anchor.x), + (border.y + (border.w - border.y) * self.anchor.y), 0 ) end local temp_pos = vmath.vector3(0) -local function get_pos(instance, index) - local row = math.ceil(index / instance.in_row) - 1 - local col = (index - row * instance.in_row) - 1 +local function get_pos(self, index) + local row = math.ceil(index / self.in_row) - 1 + local col = (index - row * self.in_row) - 1 - temp_pos.x = col * (instance.node_size.x + instance.offset.x) - instance.border_offset.x - temp_pos.y = -row * (instance.node_size.y + instance.offset.y) - instance.border_offset.y + temp_pos.x = col * (self.node_size.x + self.offset.x) - self.border_offset.x + temp_pos.y = -row * (self.node_size.y + self.offset.y) - self.border_offset.y return temp_pos end -local function update_pos(instance) - for i = 1, #instance.nodes do - local node = instance.nodes[i] - gui.set_position(node, get_pos(instance, i)) +local function update_pos(self) + for i = 1, #self.nodes do + local node = self.nodes[i] + gui.set_position(node, get_pos(self, i)) end end -function M.set_offset(instance, offset) - instance.offset = offset - update_pos(instance) +function M.set_offset(self, offset) + self.offset = offset + update_pos(self) end -function M.set_anchor(instance, anchor) - instance.anchor = anchor - update_pos(instance) +function M.set_anchor(self, anchor) + self.anchor = anchor + update_pos(self) end -function M.add(instance, item, index) - index = index or (#instance.nodes + 1) - table.insert(instance.nodes, index, item) - gui.set_parent(item, instance.parent) +function M.add(self, item, index) + index = index or (#self.nodes + 1) + table.insert(self.nodes, index, item) + gui.set_parent(item, self.parent) - local pos = get_pos(instance, index) - check_border(instance, pos) - update_pos(instance) + local pos = get_pos(self, index) + check_border(self, pos) + update_pos(self) end -function M.get_size(instance) +function M.get_size(self) return vmath.vector3( - instance.border.z - instance.border.x, - instance.border.w - instance.border.y, + self.border.z - self.border.x, + self.border.w - self.border.y, 0) end -function M.get_all_pos(instance) +function M.get_all_pos(self) local result = {} - for i = 1, #instance.nodes do - table.insert(result, gui.get_position(instance.nodes[i])) + for i = 1, #self.nodes do + table.insert(result, gui.get_position(self.nodes[i])) end return result end -function M.clear(instance) - for i = 1, #instance.nodes do - gui.delete_node(instance.nodes[i]) +function M.clear(self) + for i = 1, #self.nodes do + gui.delete_node(self.nodes[i]) end - instance.nodes = {} + self.nodes = {} end diff --git a/druid/base/progress.lua b/druid/base/progress.lua index 69eebe3..2df0663 100644 --- a/druid/base/progress.lua +++ b/druid/base/progress.lua @@ -13,135 +13,135 @@ local PROP_Y = "y" local PROP_X = "x" -function M.init(instance, name, key, init_value) +function M.init(self, name, key, init_value) if key ~= PROP_X and key ~= PROP_Y then settings.log("progress component: key must be 'x' or 'y'. Passed:", key) key = PROP_X end - instance.prop = hash("scale."..key) - instance.key = key + self.prop = hash("scale."..key) + self.key = key - instance.node = helper.get_node(name) - instance.scale = gui.get_scale(instance.node) - instance.size = gui.get_size(instance.node) - instance.max_size = instance.size[instance.key] - instance.slice = gui.get_slice9(instance.node) + self.node = helper.get_node(name) + self.scale = gui.get_scale(self.node) + self.size = gui.get_size(self.node) + self.max_size = self.size[self.key] + self.slice = gui.get_slice9(self.node) if key == PROP_X then - instance.slice_size = instance.slice.x + instance.slice.z + self.slice_size = self.slice.x + self.slice.z else - instance.slice_size = instance.slice.y + instance.slice.w + self.slice_size = self.slice.y + self.slice.w end - instance:set_to(init_value or 1) + self:set_to(init_value or 1) end -local function check_steps(instance, from, to, exactly) - if not instance.steps then +local function check_steps(self, from, to, exactly) + if not self.steps then return end - for i = 1, #instance.steps do - local step = instance.steps[i] + for i = 1, #self.steps do + local step = self.steps[i] local v1, v2 = from, to if v1 > v2 then v1, v2 = v2, v1 end if v1 < step and step < v2 then - instance.step_callback(instance.parent.parent, step) + self.step_callback(self.parent.parent, step) end if exactly and exactly == step then - instance.step_callback(instance.parent.parent, step) + self.step_callback(self.parent.parent, step) end end end -local function set_bar_to(instance, set_to, is_silence) - local prev_value = instance.last_value - instance.last_value = set_to +local function set_bar_to(self, set_to, is_silence) + local prev_value = self.last_value + self.last_value = set_to - local total_width = set_to * instance.max_size + local total_width = set_to * self.max_size - local scale = math.min(total_width / instance.slice_size, 1) - local size = math.max(total_width, instance.slice_size) + local scale = math.min(total_width / self.slice_size, 1) + local size = math.max(total_width, self.slice_size) - instance.scale[instance.key] = scale - gui.set_scale(instance.node, instance.scale) - instance.size[instance.key] = size - gui.set_size(instance.node, instance.size) + self.scale[self.key] = scale + gui.set_scale(self.node, self.scale) + self.size[self.key] = size + gui.set_size(self.node, self.size) if not is_silence then - check_steps(instance, prev_value, set_to) + check_steps(self, prev_value, set_to) end end --- Fill a progress bar and stop progress animation -function M.fill(instance) - set_bar_to(instance, 1, true) +function M.fill(self) + set_bar_to(self, 1, true) end --- To empty a progress bar -function M.empty(instance) - set_bar_to(instance, 0, true) +function M.empty(self) + set_bar_to(self, 0, true) end --- Set fill a progress bar to value -- @param to - value between 0..1 -function M.set_to(instance, to) - set_bar_to(instance, to) +function M.set_to(self, to) + set_bar_to(self, to) end -function M.get(instance) - return instance.last_value +function M.get(self) + return self.last_value end -function M.set_steps(instance, steps, step_callback) - instance.steps = steps - instance.step_callback = step_callback +function M.set_steps(self, steps, step_callback) + self.steps = steps + self.step_callback = step_callback end --- Start animation of a progress bar -- @param to - value between 0..1 -- @param callback - callback when progress ended if need -function M.to(instance, to, callback) +function M.to(self, to, callback) to = helper.clamp(to, 0, 1) -- cause of float error local value = helper.round(to, 5) - if value ~= instance.last_value then - instance.target = value - instance.target_callback = callback + if value ~= self.last_value then + self.target = value + self.target_callback = callback else if callback then - callback(instance.parent.parent, to) + callback(self.parent.parent, to) end end end -function M.update(instance, dt) - if instance.target then - local prev_value = instance.last_value - local step = math.abs(instance.last_value - instance.target) * (p_settings.SPEED*dt) +function M.update(self, dt) + if self.target then + local prev_value = self.last_value + local step = math.abs(self.last_value - self.target) * (p_settings.SPEED*dt) step = math.max(step, p_settings.MIN_DELTA) - instance:set_to(helper.step(instance.last_value, instance.target, step)) + self:set_to(helper.step(self.last_value, self.target, step)) - if instance.last_value == instance.target then - check_steps(instance, prev_value, instance.target, instance.target) + if self.last_value == self.target then + check_steps(self, prev_value, self.target, self.target) - if instance.target_callback then - instance.target_callback(instance.parent.parent, instance.target) + if self.target_callback then + self.target_callback(self.parent.parent, self.target) end - instance.target = nil + self.target = nil end end end diff --git a/druid/base/text.lua b/druid/base/text.lua index 3f3993f..6ff27fb 100644 --- a/druid/base/text.lua +++ b/druid/base/text.lua @@ -8,76 +8,76 @@ M.interest = { } -function M.init(instance, node, value, is_locale, max_width) - instance.max_width = max_width - instance.node = helper.get_node(node) - instance.start_scale = gui.get_scale(instance.node) - instance.last_color = gui.get_color(instance.node) +function M.init(self, node, value, is_locale, max_width) + self.max_width = max_width + self.node = helper.get_node(node) + self.start_scale = gui.get_scale(self.node) + self.last_color = gui.get_color(self.node) if is_locale then - instance.text_id = value - instance:translate() + self.text_id = value + self:translate() else - instance:set_to(value or 0) + self:set_to(value or 0) end - return instance + return self end -function M.translate(instance) - if instance.text_id then - instance:set_to(settings.get_text(instance.text_id)) +function M.translate(self) + if self.text_id then + self:set_to(settings.get_text(self.text_id)) end end --- Setup scale x, but can only be smaller, than start text scale -local function setup_max_width(instance) - local metrics = gui.get_text_metrics_from_node(instance.node) - local cur_scale = gui.get_scale(instance.node) +local function setup_max_width(self) + local metrics = gui.get_text_metrics_from_node(self.node) + local cur_scale = gui.get_scale(self.node) - if metrics.width * cur_scale.x > instance.max_width then - local scale_modifier = instance.max_width / metrics.width - scale_modifier = math.min(scale_modifier, instance.start_scale.x) + if metrics.width * cur_scale.x > self.max_width then + local scale_modifier = self.max_width / metrics.width + scale_modifier = math.min(scale_modifier, self.start_scale.x) local new_scale = vmath.vector3(scale_modifier, scale_modifier, cur_scale.z) - gui.set_scale(instance.node, new_scale) + gui.set_scale(self.node, new_scale) 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) +function M.set_to(self, set_to) + self.last_value = set_to + gui.set_text(self.node, set_to) - if instance.max_width then - setup_max_width(instance) + if self.max_width then + setup_max_width(self) end end --- Set color -- @param color -function M.set_color(instance, color) - instance.last_color = color - gui.set_color(instance.node, color) +function M.set_color(self, color) + self.last_color = color + gui.set_color(self.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) +function M.set_alpha(self, alpha) + self.last_color.w = alpha + gui.set_color(self.node, self.last_color) end --- Set scale -- @param scale -function M.set_scale(instance, scale) - instance.last_scale = scale - gui.set_scale(instance.node, scale) +function M.set_scale(self, scale) + self.last_scale = scale + gui.set_scale(self.node, scale) end diff --git a/druid/base/timer.lua b/druid/base/timer.lua index 14cb8c6..73fb49e 100644 --- a/druid/base/timer.lua +++ b/druid/base/timer.lua @@ -9,66 +9,66 @@ M.interest = { local empty = function() end -function M.init(instance, node, seconds_from, seconds_to, callback) - instance.node = helper.get_node(node) +function M.init(self, node, seconds_from, seconds_to, callback) + self.node = helper.get_node(node) 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 + self:set_to(seconds_from) + self:set_interval(seconds_from, seconds_to) + self.callback = callback if seconds_to - seconds_from == 0 then - instance:set_state(false) - instance.callback(instance.parent.parent, instance) + self:set_state(false) + self.callback(self.parent.parent, self) end - return instance + return self 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)) +function M.set_to(self, set_to) + self.last_value = set_to + gui.set_text(self.node, formats.second_string_min(set_to)) end --- Called when update -- @param is_on - boolean is timer on -function M.set_state(instance, is_on) - instance.is_on = is_on +function M.set_state(self, is_on) + self.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.from = from - instance.value = from - instance.temp = 0 - instance.target = to - M.set_state(instance, true) - M.set_to(instance, from) +function M.set_interval(self, from, to) + self.from = from + self.value = from + self.temp = 0 + self.target = to + M.set_state(self, true) + M.set_to(self, 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)) +function M.update(self, dt) + if self.is_on then + self.temp = self.temp + dt + local dist = math.min(1, math.abs(self.value - self.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) + if self.temp > dist then + self.temp = self.temp - dist + self.value = helper.step(self.value, self.target, 1) + M.set_to(self, self.value) + if self.value == self.target then + self:set_state(false) + self.callback(self.parent.parent, self) end end end diff --git a/example/example.gui.gui_script b/example/example.gui.gui_script index e8ff623..1acb004 100644 --- a/example/example.gui.gui_script +++ b/example/example.gui.gui_script @@ -94,6 +94,7 @@ local function init_grid(self) -- 4 items per row local grid = self.druid:new_grid("grid_1", prefab, 4) + grid:set_anchor(vmath.vector3(0)) grid:set_offset(vmath.vector3(2, 2, 0)) for i = 1, 16 do local node = gui.clone(prefab) @@ -120,6 +121,7 @@ local function init_grid(self) local grid3 = self.druid:new_grid("grid_3", prefab, 10) + grid3:set_anchor(vmath.vector3(0)) grid3:set_offset(vmath.vector3(5, 0, 0)) for i = 1, 4 do local node = gui.clone(prefab)