diff --git a/alpha_todo.txt b/alpha_todo.txt index 50baac2..bf7cbc8 100644 --- a/alpha_todo.txt +++ b/alpha_todo.txt @@ -11,7 +11,7 @@ Simple to-do for Druid Alpha 0.2.0 + refactor on_swipe. To on_scroll? Add input priority + separate custom data and predefined fields in components? Every component have their fields and events + How to set custom sprites for button states? -- add druid settings (add auto_focus input and other stuff) ++ add druid settings (add auto_focus input and other stuff) (to game.project) + button add key trigger + button and hover click restriction zone? diff --git a/druid/base/grid.lua b/druid/base/grid.lua index 31ad635..6dad84d 100644 --- a/druid/base/grid.lua +++ b/druid/base/grid.lua @@ -98,7 +98,7 @@ end function M.get_size(self) return vmath.vector3( self.border.z - self.border.x, - self.border.w - self.border.y, + self.border.y - self.border.w, 0) end diff --git a/druid/base/scroll.lua b/druid/base/scroll.lua index 2b7e351..eaa0b5d 100644 --- a/druid/base/scroll.lua +++ b/druid/base/scroll.lua @@ -27,6 +27,25 @@ local function get_border(node) end +local function update_border(self) + local input_border = get_border(self.input_zone) + local content_border = get_border(self.node) + + -- border.x - min content.x node pos + -- border.y - min content.y node pos + -- border.z - max content.x node pos + -- border.w - max content.y node pos + self.border = vmath.vector4( + input_border.x - content_border.x, + -input_border.w + content_border.w, + input_border.z - content_border.z, + -input_border.y + content_border.y + ) + self.can_x = (self.border.x ~= self.border.z) + self.can_y = (self.border.y ~= self.border.w) +end + + function M.init(self, scroll_parent, input_zone, border) self.style = self:get_style() self.node = self:get_node(scroll_parent) @@ -53,14 +72,7 @@ function M.init(self, scroll_parent, input_zone, border) side = false, } - local input_border = get_border(self.input_zone) - local content_border = get_border(self.node) - self:set_border(vmath.vector4( - input_border.x - content_border.x, - -input_border.w + content_border.w, - input_border.z - content_border.z, - -input_border.y + content_border.y - )) + update_border(self) self.on_scroll = Event() self.on_scroll_to = Event() @@ -432,14 +444,9 @@ end -- @function scroll:set_border -- @tparam table self Component instance -- @tparam vmath.vector3 border Size of scrolling area -function M.set_border(self, border) - -- border.x - min content.x node pos - -- border.y - min content.y node pos - -- border.z - max content.x node pos - -- border.w - max content.y node pos - self.border = border - self.can_x = (border.x ~= border.z) - self.can_y = (border.y ~= border.w) +function M.set_border(self, content_size) + gui.set_size(self.node, content_size) + update_border(self) end diff --git a/druid/base/text.lua b/druid/base/text.lua index 95b4ced..1c19c2f 100644 --- a/druid/base/text.lua +++ b/druid/base/text.lua @@ -48,6 +48,9 @@ end --- Setup scale x, but can only be smaller, than start text scale local function update_text_area_size(self) + gui.set_scale(self.node, self.start_scale) + gui.set_size(self.node, self.start_size) + local max_width = self.text_area.x local max_height = self.text_area.y diff --git a/druid/druid.lua b/druid/druid.lua index 0716805..5993e26 100644 --- a/druid/druid.lua +++ b/druid/druid.lua @@ -20,8 +20,6 @@ local settings = require("druid.system.settings") local M = {} -local log = settings.log - --- Register external druid component. -- After register you can create the component with @@ -37,7 +35,7 @@ function M.register(name, module) return druid_instance.create(self, module, ...) end - log("Register component", name) + -- print("Register component", name) end diff --git a/druid/system/druid_instance.lua b/druid/system/druid_instance.lua index 1a217ca..f06f10b 100644 --- a/druid/system/druid_instance.lua +++ b/druid/system/druid_instance.lua @@ -43,8 +43,7 @@ local Druid = class("druid.druid_instance") local function input_init(self) - -- TODO: To custom settings - if not settings.auto_focus_gain then + if not sys.get_config("druid.auto_focus") == "1" then return end diff --git a/druid/system/settings.lua b/druid/system/settings.lua index d7bdfcd..0dfe1a1 100644 --- a/druid/system/settings.lua +++ b/druid/system/settings.lua @@ -4,10 +4,7 @@ local M = {} -M.is_debug = false M.default_style = nil -M.auto_focus_gain = true - function M.get_text(name) return "[Druid]: locales not inited" @@ -18,11 +15,4 @@ function M.play_sound(name) end -function M.log(...) - if M.is_debug then - print("[Druid]: ", ...) - end -end - - return M diff --git a/example/kenney/gui/main/main.gui b/example/kenney/gui/main/main.gui index d707cbf..11a21f8 100644 --- a/example/kenney/gui/main/main.gui +++ b/example/kenney/gui/main/main.gui @@ -3918,6 +3918,61 @@ nodes { text_leading: 1.0 text_tracking: 0.0 } +nodes { + position { + x: 150.0 + y: -260.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 0.7 + y: 0.7 + z: 1.0 + w: 1.0 + } + size { + x: 300.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 0.7019608 + y: 0.7019608 + z: 0.7019608 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "text_max_height_visual" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "text_page" + layer: "" + inherit_alpha: true + slice9 { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 0.7 + template_node_child: false + size_mode: SIZE_MODE_MANUAL +} nodes { position { x: 150.0 @@ -5053,7 +5108,62 @@ nodes { nodes { position { x: 0.0 - y: 150.0 + y: 450.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 600.0 + y: 1900.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "kenney/empty" + id: "scroll_page_content" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_N + adjust_mode: ADJUST_MODE_FIT + parent: "scroll_page" + layer: "" + inherit_alpha: true + slice9 { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 1.0 + template_node_child: false + size_mode: SIZE_MODE_MANUAL +} +nodes { + position { + x: 0.0 + y: -300.0 z: 0.0 w: 1.0 } @@ -5089,7 +5199,7 @@ nodes { yanchor: YANCHOR_NONE pivot: PIVOT_CENTER adjust_mode: ADJUST_MODE_FIT - parent: "scroll_page" + parent: "scroll_page_content" layer: "" inherit_alpha: true slice9 { @@ -5107,7 +5217,7 @@ nodes { } nodes { position { - x: 0.0 + x: 300.0 y: 0.0 z: 0.0 w: 1.0 @@ -5412,6 +5522,234 @@ nodes { text_leading: 1.0 text_tracking: 0.0 } +nodes { + position { + x: 0.0 + y: -630.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 600.0 + y: 300.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "kenney/empty" + id: "scroll_with_grid_size" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "scroll_page_content" + layer: "" + inherit_alpha: true + slice9 { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 + } + clipping_mode: CLIPPING_MODE_STENCIL + clipping_visible: true + clipping_inverted: false + alpha: 1.0 + template_node_child: false + size_mode: SIZE_MODE_MANUAL +} +nodes { + position { + x: -300.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 600.0 + y: 300.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 0.6 + z: 0.4 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "grid_content" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_W + adjust_mode: ADJUST_MODE_FIT + parent: "scroll_with_grid_size" + layer: "" + inherit_alpha: true + slice9 { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 1.0 + template_node_child: false + size_mode: SIZE_MODE_MANUAL +} +nodes { + position { + x: -180.0 + y: -550.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "kenney/button_blue" + id: "grid_prefab" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "scroll_page_content" + layer: "" + inherit_alpha: true + slice9 { + x: 10.0 + y: 10.0 + z: 10.0 + w: 10.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 1.0 + template_node_child: false + size_mode: SIZE_MODE_MANUAL +} +nodes { + position { + x: 0.0 + y: 5.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 180.0 + y: 50.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_TEXT + blend_mode: BLEND_MODE_ALPHA + text: "Just text" + font: "game" + id: "grid_prefab_text" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + outline { + x: 0.2 + y: 0.3019608 + z: 0.7019608 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "grid_prefab" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 0.0 + template_node_child: false + text_leading: 1.0 + text_tracking: 0.0 +} nodes { position { x: 0.0 diff --git a/example/kenney/page/scroll.lua b/example/kenney/page/scroll.lua index f47c818..dd945c4 100644 --- a/example/kenney/page/scroll.lua +++ b/example/kenney/page/scroll.lua @@ -1,8 +1,31 @@ local M = {} +local function init_grid(self) + local prefab = gui.get_node("grid_prefab") + + + local grid = self.druid:new_grid("grid_content", "grid_prefab", 20) + grid:set_anchor(vmath.vector3(0, 0.5, 0)) + grid:set_offset(vmath.vector3(15, 100, 0)) + + for i = 1, 40 do + local clone_prefab = gui.clone_tree(prefab) + + grid:add(clone_prefab["grid_prefab"]) + gui.set_text(clone_prefab["grid_prefab_text"], "Node " .. i) + end + + gui.set_enabled(prefab, false) + local grid_scroll = self.druid:new_scroll("grid_content", "scroll_with_grid_size") + grid_scroll:set_border(grid:get_size()) +end + + function M.setup_page(self) + self.druid:new_scroll("scroll_page_content", "scroll_page") self.druid:new_scroll("simple_scroll_content", "simple_scroll_input") + init_grid(self) end