From 0d07deb23aefc939c22f5a254340e0f6f4686d19 Mon Sep 17 00:00:00 2001 From: Insality Date: Tue, 29 Sep 2020 23:09:37 +0300 Subject: [PATCH] Renamed class functions --- druid/base/back_handler.lua | 8 ++-- druid/base/blocker.lua | 12 +++--- druid/base/button.lua | 22 +++++----- druid/base/drag.lua | 14 +++---- druid/base/hover.lua | 22 +++++----- druid/base/swipe.lua | 14 +++---- druid/base/text.lua | 22 +++++----- druid/event.lua | 16 +++---- druid/extended/checkbox.lua | 18 ++++---- druid/extended/checkbox_group.lua | 10 ++--- druid/extended/component.template.lua | 26 ++++++------ druid/extended/dynamic_grid.lua | 1 + druid/extended/input.lua | 24 +++++------ druid/extended/lang_text.lua | 14 +++---- druid/extended/progress.lua | 24 +++++------ druid/extended/radio_group.lua | 10 ++--- druid/extended/slider.lua | 14 +++---- druid/extended/timer.lua | 20 ++++----- druid/system/druid_instance.lua | 60 +++++++++++++-------------- 19 files changed, 176 insertions(+), 175 deletions(-) diff --git a/druid/base/back_handler.lua b/druid/base/back_handler.lua index b00779a..daabd9a 100644 --- a/druid/base/back_handler.lua +++ b/druid/base/back_handler.lua @@ -13,14 +13,14 @@ local Event = require("druid.event") local const = require("druid.const") local component = require("druid.component") -local M = component.create("back_handler", { const.ON_INPUT }) +local BackHandler = component.create("back_handler", { const.ON_INPUT }) --- Component init function -- @function back_handler:init -- @tparam callback callback On back button -- @tparam[opt] params Callback argument -function M.init(self, callback, params) +function BackHandler:init(callback, params) self.params = params self.on_back = Event(callback) @@ -31,7 +31,7 @@ end -- @function back_handler:on_input -- @tparam string action_id on_input action id -- @tparam table action on_input action -function M.on_input(self, action_id, action) +function BackHandler:on_input(action_id, action) if not action[const.RELEASED] then return false end @@ -45,4 +45,4 @@ function M.on_input(self, action_id, action) end -return M +return BackHandler diff --git a/druid/base/blocker.lua b/druid/base/blocker.lua index 79238d2..4f36ae8 100644 --- a/druid/base/blocker.lua +++ b/druid/base/blocker.lua @@ -14,13 +14,13 @@ local Event = require("druid.event") local const = require("druid.const") local component = require("druid.component") -local M = component.create("blocker", { const.ON_INPUT }) +local Blocker = component.create("blocker", { const.ON_INPUT }) --- Component init function -- @function blocker:init -- @tparam node node Gui node -function M.init(self, node) +function Blocker:init(node) self.node = self:get_node(node) self.on_click = Event() @@ -28,7 +28,7 @@ function M.init(self, node) end -function M.on_input(self, action_id, action) +function Blocker:on_input(action_id, action) if action_id ~= const.ACTION_TOUCH and action_id ~= const.ACTION_MULTITOUCH and action_id ~= nil then @@ -50,7 +50,7 @@ end --- Set enabled blocker component state -- @function blocker:set_enabled -- @tparam bool state Enabled state -function M.set_enabled(self, state) +function Blocker:set_enabled(state) gui.set_enabled(self.node, state) end @@ -58,9 +58,9 @@ end --- Return blocked enabled state -- @function blocker:is_enabled -- @treturn bool True, if blocker is enabled -function M.is_enabled(self, state) +function Blocker:is_enabled(state) return gui.is_enabled(self.node) end -return M +return Blocker diff --git a/druid/base/button.lua b/druid/base/button.lua index a18b0a8..e1ac309 100644 --- a/druid/base/button.lua +++ b/druid/base/button.lua @@ -26,7 +26,7 @@ local const = require("druid.const") local helper = require("druid.helper") local component = require("druid.component") -local M = component.create("button", { const.ON_INPUT }) +local Button = component.create("button", { const.ON_INPUT }) local function is_input_match(self, action_id) @@ -141,7 +141,7 @@ end -- @tfield function on_hover (self, node, hover_state) -- @tfield function on_mouse_hover (self, node, hover_state) -- @tfield function on_set_enabled (self, node, enabled_state) -function M.on_style_change(self, style) +function Button:on_style_change(style) self.style = {} self.style.LONGTAP_TIME = style.LONGTAP_TIME or 0.4 self.style.AUTOHOLD_TRIGGER = style.AUTOHOLD_TRIGGER or 0.8 @@ -161,7 +161,7 @@ end -- @tparam function callback Button callback -- @tparam[opt] table params Button callback params -- @tparam[opt] node anim_node Button anim node (node, if not provided) -function M.init(self, node, callback, params, anim_node) +function Button:init(node, callback, params, anim_node) self.druid = self:get_druid() self.node = self:get_node(node) @@ -188,7 +188,7 @@ function M.init(self, node, callback, params, anim_node) end -function M.on_input(self, action_id, action) +function Button:on_input(action_id, action) if not is_input_match(self, action_id) then return false end @@ -257,7 +257,7 @@ function M.on_input(self, action_id, action) end -function M.on_input_interrupt(self) +function Button:on_input_interrupt() self.can_action = false end @@ -266,7 +266,7 @@ end -- @function button:set_enabled -- @tparam bool state Enabled state -- @treturn druid.button Current button instance -function M.set_enabled(self, state) +function Button:set_enabled(state) self.disabled = not state self.hover:set_enabled(state) self.style.on_set_enabled(self, self.node, state) @@ -278,7 +278,7 @@ end --- Return button enabled state -- @function button:is_enabled -- @treturn bool True, if button is enabled -function M.is_enabled(self) +function Button:is_enabled() return not self.disabled end @@ -288,7 +288,7 @@ end -- @function button:set_click_zone -- @tparam node zone Gui node -- @treturn druid.button Current button instance -function M.set_click_zone(self, zone) +function Button:set_click_zone(zone) self.click_zone = self:get_node(zone) self.hover:set_click_zone(zone) @@ -300,7 +300,7 @@ end -- @function button:set_key_trigger -- @tparam hash key The action_id of the key -- @treturn druid.button Current button instance -function M.set_key_trigger(self, key) +function Button:set_key_trigger(key) self.key_trigger = hash(key) return self @@ -310,9 +310,9 @@ end --- Get key-code to trigger this button -- @function button:get_key_trigger -- @treturn hash The action_id of the key -function M.get_key_trigger(self) +function Button:get_key_trigger() return self.key_trigger end -return M +return Button diff --git a/druid/base/drag.lua b/druid/base/drag.lua index a48f28c..bef0b7a 100644 --- a/druid/base/drag.lua +++ b/druid/base/drag.lua @@ -27,7 +27,7 @@ local const = require("druid.const") local helper = require("druid.helper") local component = require("druid.component") -local M = component.create("drag", { const.ON_INPUT_HIGH }) +local Drag = component.create("drag", { const.ON_INPUT_HIGH }) local function start_touch(self, touch) @@ -129,7 +129,7 @@ end -- or create your own style -- @table Style -- @tfield[opt=10] number DRAG_DEADZONE Distance in pixels to start dragging -function M.on_style_change(self, style) +function Drag:on_style_change(style) self.style = {} self.style.DRAG_DEADZONE = style.DRAG_DEADZONE or 10 end @@ -139,7 +139,7 @@ end -- @tparam node node GUI node to detect dragging -- @tparam function on_drag_callback Callback for on_drag_event(self, dx, dy) -- @function drag:init -function M.init(self, node, on_drag_callback) +function Drag:init(node, on_drag_callback) self.node = self:get_node(node) self.dx = 0 @@ -163,14 +163,14 @@ function M.init(self, node, on_drag_callback) end -function M.on_input_interrupt(self) +function Drag:on_input_interrupt() if self.is_drag or self.is_touch then end_touch(self) end end -function M.on_input(self, action_id, action) +function Drag:on_input(action_id, action) if action_id ~= const.ACTION_TOUCH and action_id ~= const.ACTION_MULTITOUCH then return false end @@ -243,9 +243,9 @@ end -- restrict events outside stencil node -- @function drag:set_click_zone -- @tparam node zone Gui node -function M.set_click_zone(self, zone) +function Drag:set_click_zone(zone) self.click_zone = self:get_node(zone) end -return M +return Drag diff --git a/druid/base/hover.lua b/druid/base/hover.lua index a625307..221c7b6 100644 --- a/druid/base/hover.lua +++ b/druid/base/hover.lua @@ -11,14 +11,14 @@ local const = require("druid.const") local helper = require("druid.helper") local component = require("druid.component") -local M = component.create("hover", { const.ON_INPUT }) +local Hover = component.create("hover", { const.ON_INPUT }) --- Component init function -- @function hover:init -- @tparam node node Gui node -- @tparam function on_hover_callback Hover callback -function M.init(self, node, on_hover_callback) +function Hover:init(node, on_hover_callback) self.node = self:get_node(node) self._is_hovered = false @@ -31,7 +31,7 @@ function M.init(self, node, on_hover_callback) end -function M.on_input(self, action_id, action) +function Hover:on_input(action_id, action) if action_id ~= const.ACTION_TOUCH and action_id ~= nil then return false end @@ -49,7 +49,7 @@ function M.on_input(self, action_id, action) is_pick = is_pick and gui.pick_node(self.click_zone, action.x, action.y) end - local hover_function = action_id and M.set_hover or M.set_mouse_hover + local hover_function = action_id and self.set_hover or self.set_mouse_hover if not is_pick then hover_function(self, false) @@ -64,7 +64,7 @@ function M.on_input(self, action_id, action) end -function M.on_input_interrupt(self) +function Hover:on_input_interrupt() self:set_hover(false) end @@ -72,7 +72,7 @@ end --- Set hover state -- @function hover:set_hover -- @tparam bool state The hover state -function M.set_hover(self, state) +function Hover:set_hover(state) if self._is_hovered ~= state then self._is_hovered = state self.on_hover:trigger(self:get_context(), state) @@ -82,7 +82,7 @@ end --- Set mouse hover state -- @function hover:set_mouse_hover -- @tparam bool state The mouse hover state -function M.set_mouse_hover(self, state) +function Hover:set_mouse_hover(state) if self._is_mouse_hovered ~= state then self._is_mouse_hovered = state self.on_mouse_hover:trigger(self:get_context(), state) @@ -94,7 +94,7 @@ end -- no click events outside stencil node -- @function hover:set_click_zone -- @tparam node zone Gui node -function M.set_click_zone(self, zone) +function Hover:set_click_zone(zone) self.click_zone = self:get_node(zone) end @@ -104,7 +104,7 @@ end -- any hover events -- @function hover:set_enabled -- @tparam bool state The hover enabled state -function M.set_enabled(self, state) +function Hover:set_enabled(state) self._is_enabled = state if not state then @@ -121,9 +121,9 @@ end --- Return current hover enabled state -- @function hover:is_enabled -- @treturn bool The hover enabled state -function M.is_enabled(self) +function Hover:is_enabled() return self._is_enabled end -return M +return Hover diff --git a/druid/base/swipe.lua b/druid/base/swipe.lua index 5b39cf4..09a9eae 100644 --- a/druid/base/swipe.lua +++ b/druid/base/swipe.lua @@ -17,7 +17,7 @@ local const = require("druid.const") local helper = require("druid.helper") local component = require("druid.component") -local M = component.create("swipe", { const.ON_INPUT }) +local Swipe = component.create("swipe", { const.ON_INPUT }) local function start_swipe(self, action) @@ -69,7 +69,7 @@ end -- @tfield[opt=0.4] number SWIPE_TIME Maximum time for swipe trigger -- @tfield[opt=50] number SWIPE_THRESHOLD Minimum distance for swipe trigger -- @tfield[opt=false] bool SWIPE_TRIGGER_ON_MOVE If true, trigger on swipe moving, not only release action -function M.on_style_change(self, style) +function Swipe:on_style_change(style) self.style = {} self.style.SWIPE_TIME = style.SWIPE_TIME or 0.4 self.style.SWIPE_THRESHOLD = style.SWIPE_THRESHOLD or 50 @@ -81,7 +81,7 @@ end -- @function swipe:init -- @tparam node node Gui node -- @tparam function on_swipe_callback Swipe callback for on_swipe_end event -function M.init(self, node, on_swipe_callback) +function Swipe:init(node, on_swipe_callback) self._trigger_on_move = self.style.SWIPE_TRIGGER_ON_MOVE self.node = self:get_node(node) @@ -93,7 +93,7 @@ function M.init(self, node, on_swipe_callback) end -function M.on_input(self, action_id, action) +function Swipe:on_input(action_id, action) if action_id ~= const.ACTION_TOUCH then return false end @@ -126,7 +126,7 @@ function M.on_input(self, action_id, action) end -function M.on_input_interrupt(self) +function Swipe:on_input_interrupt() reset_swipe(self) end @@ -135,9 +135,9 @@ end -- restrict events outside stencil node -- @function swipe:set_click_zone -- @tparam node zone Gui node -function M.set_click_zone(self, zone) +function Swipe:set_click_zone(zone) self.click_zone = self:get_node(zone) end -return M +return Swipe diff --git a/druid/base/text.lua b/druid/base/text.lua index 923c77f..c5018cd 100644 --- a/druid/base/text.lua +++ b/druid/base/text.lua @@ -24,7 +24,7 @@ local Event = require("druid.event") local const = require("druid.const") local component = require("druid.component") -local M = component.create("text", { const.ON_LAYOUT_CHANGE }) +local Text = component.create("text", { const.ON_LAYOUT_CHANGE }) local function update_text_size(self) @@ -81,7 +81,7 @@ end -- @tparam node node Gui text node -- @tparam[opt] string value Initial text. Default value is node text from GUI scene. -- @tparam[opt] bool no_adjust If true, text will be not auto-adjust size -function M.init(self, node, value, no_adjust) +function Text:init(node, value, no_adjust) self.node = self:get_node(node) self.pos = gui.get_position(self.node) @@ -107,7 +107,7 @@ function M.init(self, node, value, no_adjust) end -function M.on_layout_change(self) +function Text:on_layout_change() self:set_to(self.last_value) end @@ -115,7 +115,7 @@ end --- Calculate text width with font with respect to trailing space -- @function text:get_text_width -- @tparam[opt] string text -function M.get_text_width(self, text) +function Text:get_text_width(text) text = text or self.last_value local font = gui.get_font(self.node) local scale = gui.get_scale(self.node) @@ -136,7 +136,7 @@ end --- Set text to text field -- @function text:set_to -- @tparam string set_to Text for node -function M.set_to(self, set_to) +function Text:set_to(set_to) self.last_value = set_to gui.set_text(self.node, set_to) @@ -151,7 +151,7 @@ end --- Set color -- @function text:set_color -- @tparam vector4 color Color for node -function M.set_color(self, color) +function Text:set_color(color) self.color = color gui.set_color(self.node, color) end @@ -160,7 +160,7 @@ end --- Set alpha -- @function text:set_alpha -- @tparam number alpha Alpha for node -function M.set_alpha(self, alpha) +function Text:set_alpha(alpha) self.color.w = alpha gui.set_color(self.node, self.color) end @@ -169,7 +169,7 @@ end --- Set scale -- @function text:set_scale -- @tparam vector3 scale Scale for node -function M.set_scale(self, scale) +function Text:set_scale(scale) self.last_scale = scale gui.set_scale(self.node, scale) end @@ -179,7 +179,7 @@ end -- his text area -- @function text:set_pivot -- @tparam gui.pivot pivot Gui pivot constant -function M.set_pivot(self, pivot) +function Text:set_pivot(pivot) local prev_pivot = gui.get_pivot(self.node) local prev_offset = const.PIVOTS[prev_pivot] @@ -202,9 +202,9 @@ end --- Return true, if text with line break -- @function text:is_multiline -- @treturn bool Is text node with line break -function M.is_multiline(self) +function Text:is_multiline() return gui.get_line_break(self.node) end -return M +return Text diff --git a/druid/event.lua b/druid/event.lua index a31d6cc..a8ada46 100644 --- a/druid/event.lua +++ b/druid/event.lua @@ -4,13 +4,13 @@ local class = require("druid.system.middleclass") -- @class DruidEvent -local M = class("druid.event") +local Event = class("druid.event") --- Event constructur -- @function Event -- @tparam function initial_callback Subscribe the callback on new event, if callback exist -function M.initialize(self, initial_callback) +function Event:initialize(initial_callback) self._callbacks = {} if initial_callback then @@ -22,7 +22,7 @@ end --- Subscribe callback on event -- @function event:subscribe -- @tparam function callback Callback itself -function M.subscribe(self, callback) +function Event:subscribe(callback) assert(type(self) == "table", "You should subscribe to event with : syntax") assert(type(callback) == "function", "Callback should be function") @@ -35,7 +35,7 @@ end --- Unsubscribe callback on event -- @function event:unsubscribe -- @tparam function callback Callback itself -function M.unsubscribe(self, callback) +function Event:unsubscribe(callback) for i = 1, #self._callbacks do if self._callbacks[i] == callback then table.remove(self._callbacks, i) @@ -48,14 +48,14 @@ end --- Return true, if event have at lease one handler -- @function event:is_exist -- @treturn bool True if event have handlers -function M.is_exist(self) +function Event:is_exist() return #self._callbacks > 0 end --- Clear the all event handlers -- @function event:clear -function M.clear(self) +function Event:clear() self._callbacks = {} end @@ -63,11 +63,11 @@ end --- Trigger the event and call all subscribed callbacks -- @function event:trigger -- @param ... All event params -function M.trigger(self, ...) +function Event:trigger(...) for i = 1, #self._callbacks do self._callbacks[i](...) end end -return M +return Event diff --git a/druid/extended/checkbox.lua b/druid/extended/checkbox.lua index 7129ab8..bfe7c6e 100644 --- a/druid/extended/checkbox.lua +++ b/druid/extended/checkbox.lua @@ -15,11 +15,11 @@ local const = require("druid.const") local Event = require("druid.event") local component = require("druid.component") -local M = component.create("checkbox", { const.ON_LAYOUT_CHANGE }) +local Checkbox = component.create("checkbox", { const.ON_LAYOUT_CHANGE }) local function on_click(self) - M.set_state(self, not self.state) + self:set_state(not self.state) end @@ -28,7 +28,7 @@ end -- or create your own style -- @table Style -- @tfield function on_change_state (self, node, state) -function M.on_style_change(self, style) +function Checkbox:on_style_change(style) self.style = {} self.style.on_change_state = style.on_change_state or function(_, node, state) @@ -42,19 +42,19 @@ end -- @tparam node node Gui node -- @tparam function callback Checkbox callback -- @tparam[opt=node] node click node Trigger node, by default equals to node -function M.init(self, node, callback, click_node) +function Checkbox:init(node, callback, click_node) self.druid = self:get_druid() self.node = self:get_node(node) self.click_node = self:get_node(click_node) self.button = self.druid:new_button(self.click_node or self.node, on_click) - M.set_state(self, false, true) + self:set_state(false, true) self.on_change_state = Event(callback) end -function M.on_layout_change(self) +function Checkbox:on_layout_change() self:set_state(self.state, true) end @@ -63,7 +63,7 @@ end -- @function checkbox:set_state -- @tparam bool state Checkbox state -- @tparam bool is_silent Don't trigger on_change_state if true -function M.set_state(self, state, is_silent) +function Checkbox:set_state(state, is_silent) self.state = state self.style.on_change_state(self, self.node, state) @@ -76,9 +76,9 @@ end --- Return checkbox state -- @function checkbox:get_state -- @treturn bool Checkbox state -function M.get_state(self) +function Checkbox:get_state() return self.state end -return M +return Checkbox diff --git a/druid/extended/checkbox_group.lua b/druid/extended/checkbox_group.lua index 85bb211..376c712 100644 --- a/druid/extended/checkbox_group.lua +++ b/druid/extended/checkbox_group.lua @@ -12,7 +12,7 @@ local Event = require("druid.event") local component = require("druid.component") -local M = component.create("checkbox_group") +local CheckboxGroup = component.create("checkbox_group") --- Component init function @@ -20,7 +20,7 @@ local M = component.create("checkbox_group") -- @tparam node[] node Array of gui node -- @tparam function callback Checkbox callback -- @tparam[opt=node] node[] click node Array of trigger nodes, by default equals to nodes -function M.init(self, nodes, callback, click_nodes) +function CheckboxGroup:init(nodes, callback, click_nodes) self.druid = self:get_druid() self.checkboxes = {} @@ -40,7 +40,7 @@ end --- Set checkbox group state -- @function checkbox_group:set_state -- @tparam bool[] indexes Array of checkbox state -function M.set_state(self, indexes) +function CheckboxGroup:set_state(indexes) for i = 1, #indexes do if self.checkboxes[i] then self.checkboxes[i]:set_state(indexes[i], true) @@ -52,7 +52,7 @@ end --- Return checkbox group state -- @function checkbox_group:get_state -- @treturn bool[] Array if checkboxes state -function M.get_state(self) +function CheckboxGroup:get_state() local result = {} for i = 1, #self.checkboxes do @@ -63,4 +63,4 @@ function M.get_state(self) end -return M +return CheckboxGroup diff --git a/druid/extended/component.template.lua b/druid/extended/component.template.lua index 4637ca1..bea40d4 100644 --- a/druid/extended/component.template.lua +++ b/druid/extended/component.template.lua @@ -1,64 +1,64 @@ local const = require("druid.const") local component = require("druid.component") -local M = component.create("my_component_name", { const.ON_UPDATE }) +local Component = component.create("my_component_name", { const.ON_UPDATE }) -- Component constructor -function M.init(self, ...) +function Component:init(...) end -- Call only if exist interest: const.ON_UPDATE -function M.update(self, dt) +function Component:update(dt) end -- Call only if exist interest: const.ON_INPUT or const.ON_INPUT_HIGH -function M.on_input(self, action_id, action) +function Component:on_input(action_id, action) return false end -- Call on component creation and on component:set_style() function -function M.on_style_change(self, style) +function Component:on_style_change(style) end -- Call only if exist interest: const.ON_MESSAGE -function M.on_message(self, message_id, message, sender) +function Component:on_message(message_id, message, sender) end -- Call only if component with ON_LANGUAGE_CHANGE interest -function M.on_language_change(self) +function Component:on_language_change() end -- Call only if component with ON_LAYOUT_CHANGE interest -function M.on_layout_change(self) +function Component:on_layout_change() end -- Call, if input was capturing before this component -- Example: scroll is start scrolling, so you need unhover button -function M.on_input_interrupt(self) +function Component:on_input_interrupt() end -- Call, if game lost focus. Need ON_FOCUS_LOST intereset -function M.on_focus_lost(self) +function Component:on_focus_lost() end -- Call, if game gained focus. Need ON_FOCUS_GAINED intereset -function M.on_focus_gained(self) +function Component:on_focus_gained() end -- Call on component remove or on druid:final -function M.on_remove(self) +function Component:on_remove() end -return M +return Component diff --git a/druid/extended/dynamic_grid.lua b/druid/extended/dynamic_grid.lua index ff96d4f..e009459 100644 --- a/druid/extended/dynamic_grid.lua +++ b/druid/extended/dynamic_grid.lua @@ -25,6 +25,7 @@ local component = require("druid.component") local DynamicGrid = component.create("dynamic_grid", { const.ON_LAYOUT_CHANGE }) + local SIDE_VECTORS = { LEFT = vmath.vector3(-1, 0, 0), RIGHT = vmath.vector3(1, 0, 0), diff --git a/druid/extended/input.lua b/druid/extended/input.lua index a7a244c..b70608c 100644 --- a/druid/extended/input.lua +++ b/druid/extended/input.lua @@ -27,7 +27,7 @@ local const = require("druid.const") local component = require("druid.component") local utf8 = require("druid.system.utf8") -local M = component.create("input", { const.ON_INPUT, const.ON_FOCUS_LOST }) +local Input = component.create("input", { const.ON_INPUT, const.ON_FOCUS_LOST }) --- Mask text by replacing every character with a mask character @@ -97,7 +97,7 @@ end -- @tfield function on_unselect (self, button_node) Callback on input field unselecting -- @tfield function on_input_wrong (self, button_node) Callback on wrong user input -- @tfield table button_style Custom button style for input node -function M.on_style_change(self, style) +function Input:on_style_change(style) self.style = {} self.style.IS_LONGTAP_ERASE = style.IS_LONGTAP_ERASE or false @@ -115,7 +115,7 @@ function M.on_style_change(self, style) end -function M.init(self, click_node, text_node, keyboard_type) +function Input:init(click_node, text_node, keyboard_type) self.druid = self:get_druid(self) self.text = self.druid:new_text(text_node) @@ -149,7 +149,7 @@ function M.init(self, click_node, text_node, keyboard_type) end -function M.on_input(self, action_id, action) +function Input:on_input(action_id, action) if self.selected then local input_text = nil if action_id == const.ACTION_TEXT then @@ -213,12 +213,12 @@ function M.on_input(self, action_id, action) end -function M.on_focus_lost(self) +function Input:on_focus_lost() unselect(self) end -function M.on_input_interrupt(self) +function Input:on_input_interrupt() -- unselect(self) end @@ -226,7 +226,7 @@ end --- Set text for input field -- @function input:set_text -- @tparam string input_text The string to apply for input field -function M.set_text(self, input_text) +function Input:set_text(input_text) -- Case when update with marked text if input_text then self.value = input_text @@ -273,7 +273,7 @@ end --- Return current input field text -- @function input:get_text -- @treturn string The current input field text -function M.get_text(self) +function Input:get_text() return self.value .. self.marked_value end @@ -283,7 +283,7 @@ end -- @function input:set_max_length -- @tparam number max_length Maximum length for input text field -- @treturn druid.input Current input instance -function M.set_max_length(self, max_length) +function Input:set_max_length(max_length) self.max_length = max_length return self end @@ -295,7 +295,7 @@ end -- @function input:set_allowerd_characters -- @tparam string characters Regulax exp. for validate user input -- @treturn druid.input Current input instance -function M.set_allowed_characters(self, characters) +function Input:set_allowed_characters(characters) self.allowed_characters = characters return self end @@ -303,10 +303,10 @@ end --- Reset current input selection and return previous value -- @function input:reset_changes -function M.reset_changes(self) +function Input:reset_changes() self:set_text(self.previous_value) unselect(self) end -return M +return Input diff --git a/druid/extended/lang_text.lua b/druid/extended/lang_text.lua index e12aff8..61d345f 100644 --- a/druid/extended/lang_text.lua +++ b/druid/extended/lang_text.lua @@ -15,7 +15,7 @@ local const = require("druid.const") local settings = require("druid.system.settings") local component = require("druid.component") -local M = component.create("lang_text", { const.ON_LANGUAGE_CHANGE }) +local LangText = component.create("lang_text", { const.ON_LANGUAGE_CHANGE }) --- Component init function @@ -23,7 +23,7 @@ local M = component.create("lang_text", { const.ON_LANGUAGE_CHANGE }) -- @tparam node node The text node -- @tparam string locale_id Default locale id -- @tparam bool no_adjust If true, will not correct text size -function M.init(self, node, locale_id, no_adjust) +function LangText:init(node, locale_id, no_adjust) self.druid = self:get_druid() self.text = self.druid:new_text(node, locale_id, no_adjust) self.last_locale_args = {} @@ -36,9 +36,9 @@ function M.init(self, node, locale_id, no_adjust) end -function M.on_language_change(self) +function LangText:on_language_change() if self.last_locale then - M.translate(self, self.last_locale, unpack(self.last_locale_args)) + self:translate(self.last_locale, unpack(self.last_locale_args)) end end @@ -46,7 +46,7 @@ end --- Setup raw text to lang_text component -- @function lang_text:set_to -- @tparam string text Text for text node -function M.set_to(self, text) +function LangText:set_to(text) self.last_locale = false self.text:set_to(text) self.on_change:trigger() @@ -56,11 +56,11 @@ end --- Translate the text by locale_id -- @function lang_text:translate -- @tparam string locale_id Locale id -function M.translate(self, locale_id, ...) +function LangText:translate(locale_id, ...) self.last_locale_args = {...} self.last_locale = locale_id or self.last_locale self.text:set_to(settings.get_text(self.last_locale, ...)) end -return M +return LangText diff --git a/druid/extended/progress.lua b/druid/extended/progress.lua index e9df28f..2a343ba 100644 --- a/druid/extended/progress.lua +++ b/druid/extended/progress.lua @@ -20,7 +20,7 @@ local const = require("druid.const") local helper = require("druid.helper") local component = require("druid.component") -local M = component.create("progress", { const.ON_UPDATE, const.ON_LAYOUT_CHANGE }) +local Progress = component.create("progress", { const.ON_UPDATE, const.ON_LAYOUT_CHANGE }) local function check_steps(self, from, to, exactly) @@ -71,7 +71,7 @@ end -- @table Style -- @tfield[opt=5] number SPEED Progress bas fill rate. More -> faster -- @tfield[opt=0.005] number MIN_DELTA Minimum step to fill progress bar -function M.on_style_change(self, style) +function Progress:on_style_change(style) self.style = {} self.style.SPEED = style.SPEED or 5 self.style.MIN_DELTA = style.MIN_DELTA or 0.005 @@ -83,7 +83,7 @@ end -- @tparam string|node node Progress bar fill node or node name -- @tparam string key Progress bar direction: const.SIDE.X or const.SIDE.Y -- @tparam[opt=1] number init_value Initial value of progress bar -function M.init(self, node, key, init_value) +function Progress:init(node, key, init_value) assert(key == const.SIDE.X or const.SIDE.Y, "Progress bar key should be 'x' or 'y'") self.prop = hash("scale."..key) @@ -106,12 +106,12 @@ function M.init(self, node, key, init_value) end -function M.on_layout_change(self) +function Progress:on_layout_change() self:set_to(self.last_value) end -function M.update(self, dt) +function Progress:update(dt) if self.target then local prev_value = self.last_value local step = math.abs(self.last_value - self.target) * (self.style.SPEED*dt) @@ -133,14 +133,14 @@ end --- Fill a progress bar and stop progress animation -- @function progress:fill -function M.fill(self) +function Progress:fill() set_bar_to(self, 1, true) end --- Empty a progress bar -- @function progress:empty -function M.empty(self) +function Progress:empty() set_bar_to(self, 0, true) end @@ -148,14 +148,14 @@ end --- Instant fill progress bar to value -- @function progress:set_to -- @tparam number to Progress bar value, from 0 to 1 -function M.set_to(self, to) +function Progress:set_to(to) set_bar_to(self, to) end --- Return current progress bar value -- @function progress:get -function M.get(self) +function Progress:get() return self.last_value end @@ -165,7 +165,7 @@ end -- @tparam number[] steps Array of progress bar values -- @tparam function callback Callback on intersect step value -- @usage progress:set_steps({0, 0.3, 0.6, 1}, function(self, step) end) -function M.set_steps(self, steps, callback) +function Progress:set_steps(steps, callback) self.steps = steps self.step_callback = callback end @@ -175,7 +175,7 @@ end -- @function progress:to -- @tparam number to value between 0..1 -- @tparam[opt] function callback Callback on animation ends -function M.to(self, to, callback) +function Progress:to(to, callback) to = helper.clamp(to, 0, 1) -- cause of float error local value = helper.round(to, 5) @@ -190,4 +190,4 @@ function M.to(self, to, callback) end -return M +return Progress diff --git a/druid/extended/radio_group.lua b/druid/extended/radio_group.lua index 8701ad0..75be888 100644 --- a/druid/extended/radio_group.lua +++ b/druid/extended/radio_group.lua @@ -12,7 +12,7 @@ local Event = require("druid.event") local component = require("druid.component") -local M = component.create("radio_group") +local RadioGroup = component.create("radio_group") local function on_checkbox_click(self, index) @@ -29,7 +29,7 @@ end -- @tparam node[] node Array of gui node -- @tparam function callback Radio callback -- @tparam[opt=node] node[] click node Array of trigger nodes, by default equals to nodes -function M.init(self, nodes, callback, click_nodes) +function RadioGroup:init(nodes, callback, click_nodes) self.druid = self:get_druid() self.checkboxes = {} @@ -49,7 +49,7 @@ end --- Set radio group state -- @function radio_group:set_state -- @tparam number index Index in radio group -function M.set_state(self, index) +function RadioGroup:set_state(index) on_checkbox_click(self, index) end @@ -57,7 +57,7 @@ end --- Return radio group state -- @function radio_group:get_state -- @treturn number Index in radio group -function M.get_state(self) +function RadioGroup:get_state() local result = -1 for i = 1, #self.checkboxes do @@ -71,4 +71,4 @@ function M.get_state(self) end -return M +return RadioGroup diff --git a/druid/extended/slider.lua b/druid/extended/slider.lua index 616e4e4..2661927 100644 --- a/druid/extended/slider.lua +++ b/druid/extended/slider.lua @@ -22,7 +22,7 @@ local helper = require("druid.helper") local const = require("druid.const") local component = require("druid.component") -local M = component.create("slider", { const.ON_INPUT_HIGH, const.ON_LAYOUT_CHANGE }) +local Slider = component.create("slider", { const.ON_INPUT_HIGH, const.ON_LAYOUT_CHANGE }) local function on_change_value(self) @@ -41,7 +41,7 @@ end -- @tparam node node Gui pin node -- @tparam vector3 end_pos The end position of slider -- @tparam[opt] function callback On slider change callback -function M.init(self, node, end_pos, callback) +function Slider:init(node, end_pos, callback) self.node = self:get_node(node) self.start_pos = gui.get_position(self.node) @@ -59,12 +59,12 @@ function M.init(self, node, end_pos, callback) end -function M.on_layout_change(self) +function Slider:on_layout_change() self:set(self.value, true) end -function M.on_input(self, action_id, action) +function Slider:on_input(action_id, action) if action_id ~= const.ACTION_TOUCH then return false end @@ -133,7 +133,7 @@ end -- @function slider:set -- @tparam number value Value from 0 to 1 -- @tparam[opt] bool is_silent Don't trigger event if true -function M.set(self, value, is_silent) +function Slider:set(value, is_silent) value = helper.clamp(value, 0, 1) set_position(self, value) self.value = value @@ -148,9 +148,9 @@ end -- @function slider:set_steps -- @tparam number[] steps Array of steps -- @usage slider:set_steps({0, 0.2, 0.6, 1}) -function M.set_steps(self, steps) +function Slider:set_steps(steps) self.steps = steps end -return M +return Slider diff --git a/druid/extended/timer.lua b/druid/extended/timer.lua index cbf02df..34b6b98 100644 --- a/druid/extended/timer.lua +++ b/druid/extended/timer.lua @@ -22,7 +22,7 @@ local formats = require("druid.helper.formats") local helper = require("druid.helper") local component = require("druid.component") -local M = component.create("timer", { const.ON_UPDATE }) +local Timer = component.create("timer", { const.ON_UPDATE }) --- Component init function @@ -31,7 +31,7 @@ local M = component.create("timer", { const.ON_UPDATE }) -- @tparam number seconds_from Start timer value in seconds -- @tparam[opt=0] number seconds_to End timer value in seconds -- @tparam[opt] function callback Function on timer end -function M.init(self, node, seconds_from, seconds_to, callback) +function Timer:init(node, seconds_from, seconds_to, callback) self.node = self:get_node(node) seconds_from = math.max(seconds_from, 0) seconds_to = math.max(seconds_to or 0, 0) @@ -52,7 +52,7 @@ function M.init(self, node, seconds_from, seconds_to, callback) end -function M.update(self, dt) +function Timer:update(dt) if not self.is_on then return end @@ -63,7 +63,7 @@ function M.update(self, dt) 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) + self:set_to(self.value) self.on_tick:trigger(self:get_context(), self.value) @@ -77,7 +77,7 @@ end --- Set text to text field -- @function timer:set_to -- @tparam number set_to Value in seconds -function M.set_to(self, set_to) +function Timer:set_to(set_to) self.last_value = set_to gui.set_text(self.node, formats.second_string_min(set_to)) end @@ -86,7 +86,7 @@ end --- Called when update -- @function timer:set_state -- @tparam bool is_on Timer enable state -function M.set_state(self, is_on) +function Timer:set_state(is_on) self.is_on = is_on self.on_set_enabled:trigger(self:get_context(), is_on) @@ -97,14 +97,14 @@ end -- @function timer:set_interval -- @tparam number from Start time in seconds -- @tparam number to Target time in seconds -function M.set_interval(self, from, to) +function Timer:set_interval(from, to) self.from = from self.value = from self.temp = 0 self.target = to - M.set_state(self, true) - M.set_to(self, from) + self:set_state(true) + self:set_to(from) end -return M \ No newline at end of file +return Timer diff --git a/druid/system/druid_instance.lua b/druid/system/druid_instance.lua index f3c4c99..c459c65 100644 --- a/druid/system/druid_instance.lua +++ b/druid/system/druid_instance.lua @@ -137,7 +137,7 @@ end -- @function druid:initialize -- @tparam context table Druid context. Usually it is self of script -- @tparam style table Druid style module -function Druid.initialize(self, context, style) +function Druid:initialize(context, style) self._context = context self._style = style or settings.default_style self._deleted = false @@ -156,7 +156,7 @@ end -- @function druid:create -- @tparam Component component Component module -- @tparam args ... Other component params to pass it to component:init function -function Druid.create(self, component, ...) +function Druid:create(component, ...) local instance = create(self, component) if instance.init then @@ -170,7 +170,7 @@ end --- Call on final function on gui_script. It will call on_remove -- on all druid components -- @function druid:final -function Druid.final(self) +function Druid:final() local components = self.components[const.ALL] for i = #components, 1, -1 do @@ -189,7 +189,7 @@ end -- Component `on_remove` function will be invoked, if exist. -- @function druid:remove -- @tparam Component component Component instance -function Druid.remove(self, component) +function Druid:remove(component) if self._is_input_processing then table.insert(self._late_remove, component) return @@ -232,7 +232,7 @@ end --- Druid update function -- @function druid:update -- @tparam number dt Delta time -function Druid.update(self, dt) +function Druid:update(dt) local components = self.components[const.ON_UPDATE] for i = 1, #components do components[i]:update(dt) @@ -244,7 +244,7 @@ end -- @function druid:on_input -- @tparam hash action_id Action_id from on_input -- @tparam table action Action from on_input -function Druid.on_input(self, action_id, action) +function Druid:on_input(action_id, action) self._is_input_processing = true local is_input_consumed = false @@ -273,7 +273,7 @@ end -- @tparam hash message_id Message_id from on_message -- @tparam table message Message from on_message -- @tparam hash sender Sender from on_message -function Druid.on_message(self, message_id, message, sender) +function Druid:on_message(message_id, message, sender) local specific_ui_message = const.SPECIFIC_UI_MESSAGES[message_id] if specific_ui_message then @@ -296,7 +296,7 @@ end --- Druid on focus lost interest function. -- This one called by on_window_callback by global window listener -- @function druid:on_focus_lost -function Druid.on_focus_lost(self) +function Druid:on_focus_lost() local components = self.components[const.ON_FOCUS_LOST] for i = 1, #components do components[i]:on_focus_lost() @@ -307,7 +307,7 @@ end --- Druid on focus gained interest function. -- This one called by on_window_callback by global window listener -- @function druid:on_focus_gained -function Druid.on_focus_gained(self) +function Druid:on_focus_gained() local components = self.components[const.ON_FOCUS_GAINED] for i = 1, #components do components[i]:on_focus_gained() @@ -318,7 +318,7 @@ end --- Druid on layout change function. -- Called on update gui layout -- @function druid:on_layout_change -function Druid.on_layout_change(self) +function Druid:on_layout_change() local components = self.components[const.ON_LAYOUT_CHANGE] for i = 1, #components do components[i]:on_layout_change() @@ -330,7 +330,7 @@ end -- This one called by global gruid.on_language_change, but can be -- call manualy to update all translations -- @function druid.on_language_change -function Druid.on_language_change(self) +function Druid:on_language_change() local components = self.components[const.ON_LANGUAGE_CHANGE] for i = 1, #components do components[i]:on_language_change() @@ -342,7 +342,7 @@ end -- @function druid:new_button -- @tparam args ... button init args -- @treturn Component button component -function Druid.new_button(self, ...) +function Druid:new_button(...) return Druid.create(self, button, ...) end @@ -351,7 +351,7 @@ end -- @function druid:new_blocker -- @tparam args ... blocker init args -- @treturn Component blocker component -function Druid.new_blocker(self, ...) +function Druid:new_blocker(...) return Druid.create(self, blocker, ...) end @@ -360,7 +360,7 @@ end -- @function druid:new_back_handler -- @tparam args ... back_handler init args -- @treturn Component back_handler component -function Druid.new_back_handler(self, ...) +function Druid:new_back_handler(...) return Druid.create(self, back_handler, ...) end @@ -369,7 +369,7 @@ end -- @function druid:new_hover -- @tparam args ... hover init args -- @treturn Component hover component -function Druid.new_hover(self, ...) +function Druid:new_hover(...) return Druid.create(self, hover, ...) end @@ -378,7 +378,7 @@ end -- @function druid:new_text -- @tparam args ... text init args -- @treturn Component text component -function Druid.new_text(self, ...) +function Druid:new_text(...) return Druid.create(self, text, ...) end @@ -388,7 +388,7 @@ end -- @tparam args ... grid init args -- @treturn Component grid component -- @deprecated -function Druid.new_grid(self, ...) +function Druid:new_grid(...) helper.deprecated("The druid:new_grid is deprecated. Please use druid:new_static_grid instead") return Druid.create(self, static_grid, ...) end @@ -398,7 +398,7 @@ end -- @function druid:new_static_grid -- @tparam args ... grid init args -- @treturn Component grid component -function Druid.new_static_grid(self, ...) +function Druid:new_static_grid(...) return Druid.create(self, static_grid, ...) end @@ -407,7 +407,7 @@ end -- @function druid:new_scroll -- @tparam args ... scroll init args -- @treturn Component scroll component -function Druid.new_scroll(self, ...) +function Druid:new_scroll(...) return Druid.create(self, scroll, ...) end @@ -416,7 +416,7 @@ end -- @function druid:new_swipe -- @tparam args ... swipe init args -- @treturn Component swipe component -function Druid.new_swipe(self, ...) +function Druid:new_swipe(...) return Druid.create(self, swipe, ...) end @@ -425,7 +425,7 @@ end -- @function druid:new_drag -- @tparam args ... drag init args -- @treturn Componetn drag component -function Druid.new_drag(self, ...) +function Druid:new_drag(...) return Druid.create(self, drag, ...) end @@ -434,7 +434,7 @@ end -- @function druid:new_dynamic_grid -- @tparam args ... grid init args -- @treturn Component grid component -function Druid.new_dynamic_grid(self, ...) +function Druid:new_dynamic_grid(...) -- return helper.extended_component("dynamic_grid") return Druid.create(self, dynamic_grid, ...) end @@ -444,7 +444,7 @@ end -- @function druid:new_lang_text -- @tparam args ... lang_text init args -- @treturn Component lang_text component -function Druid.new_lang_text(self, ...) +function Druid:new_lang_text(...) -- return helper.extended_component("lang_text") return Druid.create(self, lang_text, ...) end @@ -454,7 +454,7 @@ end -- @function druid:new_slider -- @tparam args ... slider init args -- @treturn Component slider component -function Druid.new_slider(self, ...) +function Druid:new_slider(...) -- return helper.extended_component("slider") return Druid.create(self, slider, ...) end @@ -464,7 +464,7 @@ end -- @function druid:new_checkbox -- @tparam args ... checkbox init args -- @treturn Component checkbox component -function Druid.new_checkbox(self, ...) +function Druid:new_checkbox(...) -- return helper.extended_component("checkbox") return Druid.create(self, checkbox, ...) end @@ -474,7 +474,7 @@ end -- @function druid:new_input -- @tparam args ... input init args -- @treturn Component input component -function Druid.new_input(self, ...) +function Druid:new_input(...) -- return helper.extended_component("input") return Druid.create(self, input, ...) end @@ -484,7 +484,7 @@ end -- @function druid:new_checkbox_group -- @tparam args ... checkbox_group init args -- @treturn Component checkbox_group component -function Druid.new_checkbox_group(self, ...) +function Druid:new_checkbox_group(...) -- return helper.extended_component("checkbox_group") return Druid.create(self, checkbox_group, ...) end @@ -494,7 +494,7 @@ end -- @function druid:new_radio_group -- @tparam args ... radio_group init args -- @treturn Component radio_group component -function Druid.new_radio_group(self, ...) +function Druid:new_radio_group(...) -- return helper.extended_component("radio_group") return Druid.create(self, radio_group, ...) end @@ -504,7 +504,7 @@ end -- @function druid:new_timer -- @tparam args ... timer init args -- @treturn Component timer component -function Druid.new_timer(self, ...) +function Druid:new_timer(...) -- return helper.extended_component("timer") return Druid.create(self, timer, ...) end @@ -514,7 +514,7 @@ end -- @function druid:new_progress -- @tparam args ... progress init args -- @treturn Component progress component -function Druid.new_progress(self, ...) +function Druid:new_progress(...) -- return helper.extended_component("progress") return Druid.create(self, progress, ...) end