diff --git a/docs_md/changelog.md b/docs_md/changelog.md index 4a8d3671..09dcc01c 100644 --- a/docs_md/changelog.md +++ b/docs_md/changelog.md @@ -149,6 +149,7 @@ And I should note here are several breaking changes, take a look in changelogs. Wanna something more? [Add an issues!](https://github.com/Insality/druid/issues) Have a good day. + **Changelog 0.6.0** --- @@ -202,3 +203,11 @@ Have a good day. - This is basic implementation, it is work not perfect - **#124** Add `Scroll:set_click_zone` function. This is just link to `Drag:set_click_zone` function inside scroll component. - **#127** The `druid:create` is deprecated. Use `druid:new` for creating custom components + + +**Changelog 0.7.0** +--- + +- **#131** [Static Grid] Add style param: IS_DYNAMIC_NODE_POSES (default: false). Always align by content size with node anchor. + - If true - Static Grid will by always align to content anchor. + - If false (currently behaviour) - all poses for static grid is predefined and not depends on element's count (see example: static grid and static grid with dynamic poses) diff --git a/druid/base/static_grid.lua b/druid/base/static_grid.lua index 7c84d0d8..db6fdd5a 100644 --- a/druid/base/static_grid.lua +++ b/druid/base/static_grid.lua @@ -63,6 +63,17 @@ local function _extend_border(border, pos, size, pivot) end +--- Component style params. +-- You can override this component styles params in druid styles table +-- or create your own style +-- @table style +-- @tfield[opt=false] bool IS_DYNAMIC_NODE_POSES If true, always center grid content as grid pivot sets +function StaticGrid.on_style_change(self, style) + self.style = {} + self.style.IS_DYNAMIC_NODE_POSES = style.IS_DYNAMIC_NODE_POSES or false +end + + --- Component init function -- @tparam StaticGrid self -- @tparam node parent The gui node parent, where items will be placed @@ -191,7 +202,7 @@ function StaticGrid.add(self, item, index, shift_policy) self:_update_indexes() self:_update_borders() - gui.set_position(item, self:get_pos(index)) + gui.set_position(item, self:get_pos(index) + self:_get_zero_offset()) self:_update_pos() @@ -385,8 +396,12 @@ end -- @tparam bool is_instant If true, node position update instantly, otherwise with set_position_function callback -- @local function StaticGrid._update_pos(self, is_instant) + local zero_offset = self:_get_zero_offset() + for i, node in pairs(self.nodes) do local pos = self:get_pos(i) + pos.x = pos.x + zero_offset.x + pos.y = pos.y + zero_offset.y if is_instant then gui.set_position(node, pos) @@ -399,4 +414,23 @@ function StaticGrid._update_pos(self, is_instant) end +--- Return elements offset for correct posing nodes. Correct posing at +-- parent pivot node (0:0) with adjusting of node sizes and anchoring +-- @function static_grid:_get_zero_offset +-- @treturn vector3 The offset vector +-- @local +function StaticGrid:_get_zero_offset() + if not self.style.IS_DYNAMIC_NODE_POSES then + return const.VECTOR_ZERO + end + + -- zero offset: center pos - border size * anchor + return vmath.vector3( + -((self.border.x + self.border.z)/2 + (self.border.z - self.border.x) * self.pivot.x), + -((self.border.y + self.border.w)/2 + (self.border.y - self.border.w) * self.pivot.y), + 0 + ) +end + + return StaticGrid diff --git a/druid/const.lua b/druid/const.lua index be167507..047229a3 100644 --- a/druid/const.lua +++ b/druid/const.lua @@ -54,7 +54,8 @@ M.PIVOTS = { [gui.PIVOT_NW] = vmath.vector3(-0.5, 0.5, 0), } - +M.VECTOR_ZERO = vmath.vector3(0) +M.VECTOR_ONE = vmath.vector3(1) M.SYS_INFO = sys.get_sys_info() M.CURRENT_SYSTEM_NAME = M.SYS_INFO.system_name diff --git a/druid/styles/default/style.lua b/druid/styles/default/style.lua index bfc3e983..e6470aac 100644 --- a/druid/styles/default/style.lua +++ b/druid/styles/default/style.lua @@ -56,6 +56,11 @@ M["drag"] = { } +M["static_grid"] = { + IS_DYNAMIC_NODE_POSES = false, -- Always align by content size with node anchor +} + + M["scroll"] = { ANIM_SPEED = 0.2, -- gui.animation speed to point BACK_SPEED = 0.35, -- Lerp speed of return to soft position diff --git a/example/example.collection b/example/example.collection index 4baed061..df722708 100644 --- a/example/example.collection +++ b/example/example.collection @@ -869,6 +869,69 @@ embedded_instances { z: 1.0 } } +embedded_instances { + id: "grid_static_grid" + data: "components {\n" + " id: \"screen_factory\"\n" + " component: \"/monarch/screen_factory.script\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + " properties {\n" + " id: \"screen_id\"\n" + " value: \"grid_static_grid\"\n" + " type: PROPERTY_TYPE_HASH\n" + " }\n" + " properties {\n" + " id: \"popup\"\n" + " value: \"true\"\n" + " type: PROPERTY_TYPE_BOOLEAN\n" + " }\n" + "}\n" + "embedded_components {\n" + " id: \"collectionfactory\"\n" + " type: \"collectionfactory\"\n" + " data: \"prototype: \\\"/example/examples/grid/static_grid/static_grid.collection\\\"\\n" + "load_dynamically: false\\n" + "\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + "}\n" + "" + position { + x: 0.0 + y: 0.0 + z: 0.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale3 { + x: 1.0 + y: 1.0 + z: 1.0 + } +} embedded_instances { id: "grid_animations" data: "components {\n" @@ -932,3 +995,66 @@ embedded_instances { z: 1.0 } } +embedded_instances { + id: "grid_static_grid_dynamic_pos" + data: "components {\n" + " id: \"screen_factory\"\n" + " component: \"/monarch/screen_factory.script\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + " properties {\n" + " id: \"screen_id\"\n" + " value: \"grid_static_grid_dynamic_pos\"\n" + " type: PROPERTY_TYPE_HASH\n" + " }\n" + " properties {\n" + " id: \"popup\"\n" + " value: \"true\"\n" + " type: PROPERTY_TYPE_BOOLEAN\n" + " }\n" + "}\n" + "embedded_components {\n" + " id: \"collectionfactory\"\n" + " type: \"collectionfactory\"\n" + " data: \"prototype: \\\"/example/examples/grid/static_grid_dynamic_pos/static_grid_dynamic_pos.collection\\\"\\n" + "load_dynamically: false\\n" + "\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + "}\n" + "" + position { + x: 0.0 + y: 0.0 + z: 0.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale3 { + x: 1.0 + y: 1.0 + z: 1.0 + } +} diff --git a/example/example.gui_script b/example/example.gui_script index 0c56e516..243da518 100644 --- a/example/example.gui_script +++ b/example/example.gui_script @@ -116,7 +116,8 @@ local function init_lobby(self) self.lobby_grid:add(get_button_disabled(self, "Without inertion", "scroll_scene")) self.lobby_grid:add(get_title(self, "Grids")) - self.lobby_grid:add(get_button_disabled(self, "Static grid", "scroll_scene")) + self.lobby_grid:add(get_button(self, "Static grid", "grid_static_grid")) + self.lobby_grid:add(get_button(self, "Static with dynamic pos", "grid_static_grid_dynamic_pos")) self.lobby_grid:add(get_button_disabled(self, "Dynamic grid", "scroll_scene")) self.lobby_grid:add(get_button_disabled(self, "Scroll binding", "scroll_scene")) self.lobby_grid:add(get_button(self, "Add/Remove animations", "grid_animations")) diff --git a/example/examples/grid/static_grid/static_grid.collection b/example/examples/grid/static_grid/static_grid.collection new file mode 100644 index 00000000..049e652f --- /dev/null +++ b/example/examples/grid/static_grid/static_grid.collection @@ -0,0 +1,37 @@ +name: "static_grid" +scale_along_z: 0 +embedded_instances { + id: "go" + data: "components {\n" + " id: \"static_grid\"\n" + " component: \"/example/examples/grid/static_grid/static_grid.gui\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + "}\n" + "" + position { + x: 0.0 + y: 0.0 + z: 0.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale3 { + x: 1.0 + y: 1.0 + z: 1.0 + } +} diff --git a/example/examples/grid/static_grid/static_grid.gui b/example/examples/grid/static_grid/static_grid.gui new file mode 100644 index 00000000..c7f876f9 --- /dev/null +++ b/example/examples/grid/static_grid/static_grid.gui @@ -0,0 +1,628 @@ +script: "/example/examples/grid/static_grid/static_grid.gui_script" +fonts { + name: "game" + font: "/example/assets/fonts/game.font" +} +textures { + name: "kenney" + texture: "/example/assets/images/kenney.atlas" +} +background_color { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 +} +nodes { + position { + x: 300.0 + y: 415.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: 830.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: "root" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + 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: 409.0 + y: 360.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: 49.0 + y: 49.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_green" + id: "prefab" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "root" + 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.8 + template_node_child: false + size_mode: SIZE_MODE_AUTO +} +nodes { + position { + x: -270.0 + y: 370.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: 100.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 0.7019608 + z: 0.4 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "grid_NW_anchor" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_NW + adjust_mode: ADJUST_MODE_FIT + parent: "root" + 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: 270.0 + y: 370.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: 100.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 0.7019608 + z: 0.4 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "grid_NE_anchor" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_NE + adjust_mode: ADJUST_MODE_FIT + parent: "root" + 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: 370.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: 100.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 0.7019608 + z: 0.4 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "grid_N_anchor" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_N + adjust_mode: ADJUST_MODE_FIT + parent: "root" + 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: -270.0 + y: -130.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: 100.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 0.7019608 + z: 0.4 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "grid_SW_anchor" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_SW + adjust_mode: ADJUST_MODE_FIT + parent: "root" + 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: 270.0 + y: -130.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: 100.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 0.7019608 + z: 0.4 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "grid_SE_anchor" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_SE + adjust_mode: ADJUST_MODE_FIT + parent: "root" + 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: -130.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: 100.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 0.7019608 + z: 0.4 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "grid_S_anchor" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_S + adjust_mode: ADJUST_MODE_FIT + parent: "root" + 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: -270.0 + y: 120.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: 100.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 0.7019608 + z: 0.4 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "grid_W_anchor" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_W + adjust_mode: ADJUST_MODE_FIT + parent: "root" + 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: 120.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: 100.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 0.7019608 + z: 0.4 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "grid_C_anchor" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "root" + 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: 270.0 + y: 120.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: 100.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 0.7019608 + z: 0.4 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "grid_E_anchor" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_E + adjust_mode: ADJUST_MODE_FIT + parent: "root" + 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 +} +layers { + name: "image" +} +layers { + name: "text" +} +material: "/builtins/materials/gui.material" +adjust_reference: ADJUST_REFERENCE_PARENT +max_nodes: 512 diff --git a/example/examples/grid/static_grid/static_grid.gui_script b/example/examples/grid/static_grid/static_grid.gui_script new file mode 100644 index 00000000..f162460b --- /dev/null +++ b/example/examples/grid/static_grid/static_grid.gui_script @@ -0,0 +1,83 @@ +local druid = require("druid.druid") + + +function init(self) + self.druid = druid.new(self) + local prefab = gui.get_node("prefab") + gui.set_enabled(prefab, false) + + local grid_nw = self.druid:new_static_grid("grid_NW_anchor", prefab, 3) + local grid_ne = self.druid:new_static_grid("grid_NE_anchor", prefab, 3) + local grid_n = self.druid:new_static_grid("grid_N_anchor", prefab, 3) + local grid_sw = self.druid:new_static_grid("grid_SW_anchor", prefab, 3) + local grid_se = self.druid:new_static_grid("grid_SE_anchor", prefab, 3) + local grid_s = self.druid:new_static_grid("grid_S_anchor", prefab, 3) + local grid_w = self.druid:new_static_grid("grid_C_anchor", prefab, 3) + local grid_e = self.druid:new_static_grid("grid_W_anchor", prefab, 3) + local grid_c = self.druid:new_static_grid("grid_E_anchor", prefab, 3) + + local update_pos_func = function(node, pos) gui.animate(node, "position", pos, gui.EASING_OUTSINE, 0.2) end + grid_nw:set_position_function(update_pos_func) + grid_ne:set_position_function(update_pos_func) + grid_n:set_position_function(update_pos_func) + grid_sw:set_position_function(update_pos_func) + grid_se:set_position_function(update_pos_func) + grid_s:set_position_function(update_pos_func) + grid_w:set_position_function(update_pos_func) + grid_e:set_position_function(update_pos_func) + grid_c:set_position_function(update_pos_func) + + local grids = { + grid_nw, + grid_ne, + grid_n, + grid_sw, + grid_se, + grid_s, + grid_c, + grid_w, + grid_e, + } + + + local animate_grides = function() + for _, grid in ipairs(grids) do + for i = 1, #grid.nodes do + gui.delete_node(grid.nodes[i]) + end + grid:clear() + + for i = 1, 9 do + timer.delay(i, false, function() + local node = gui.clone(prefab) + gui.set_enabled(node, true) + grid:add(node) + end) + end + end + end + + animate_grides() + timer.delay(10, true, animate_grides) + +end + + +function final(self) + self.druid:final() +end + + +function update(self, dt) + self.druid:update(dt) +end + + +function on_message(self, message_id, message, sender) + self.druid:on_message(message_id, message, sender) +end + + +function on_input(self, action_id, action) + return self.druid:on_input(action_id, action) +end diff --git a/example/examples/grid/static_grid_dynamic_pos/static_grid_dynamic_pos.collection b/example/examples/grid/static_grid_dynamic_pos/static_grid_dynamic_pos.collection new file mode 100644 index 00000000..a6277f55 --- /dev/null +++ b/example/examples/grid/static_grid_dynamic_pos/static_grid_dynamic_pos.collection @@ -0,0 +1,37 @@ +name: "static_grid_dynamic_pos" +scale_along_z: 0 +embedded_instances { + id: "go" + data: "components {\n" + " id: \"static_grid_dynamic_pos\"\n" + " component: \"/example/examples/grid/static_grid_dynamic_pos/static_grid_dynamic_pos.gui\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + "}\n" + "" + position { + x: 0.0 + y: 0.0 + z: 0.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale3 { + x: 1.0 + y: 1.0 + z: 1.0 + } +} diff --git a/example/examples/grid/static_grid_dynamic_pos/static_grid_dynamic_pos.gui b/example/examples/grid/static_grid_dynamic_pos/static_grid_dynamic_pos.gui new file mode 100644 index 00000000..6e975da9 --- /dev/null +++ b/example/examples/grid/static_grid_dynamic_pos/static_grid_dynamic_pos.gui @@ -0,0 +1,628 @@ +script: "/example/examples/grid/static_grid_dynamic_pos/static_grid_dynamic_pos.gui_script" +fonts { + name: "game" + font: "/example/assets/fonts/game.font" +} +textures { + name: "kenney" + texture: "/example/assets/images/kenney.atlas" +} +background_color { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 +} +nodes { + position { + x: 300.0 + y: 415.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: 830.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: "root" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + 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: 409.0 + y: 360.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: 49.0 + y: 49.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_green" + id: "prefab" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "root" + 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.8 + template_node_child: false + size_mode: SIZE_MODE_AUTO +} +nodes { + position { + x: -270.0 + y: 370.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: 100.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 0.7019608 + z: 0.4 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "grid_NW_anchor" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_NW + adjust_mode: ADJUST_MODE_FIT + parent: "root" + 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: 270.0 + y: 370.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: 100.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 0.7019608 + z: 0.4 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "grid_NE_anchor" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_NE + adjust_mode: ADJUST_MODE_FIT + parent: "root" + 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: 370.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: 100.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 0.7019608 + z: 0.4 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "grid_N_anchor" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_N + adjust_mode: ADJUST_MODE_FIT + parent: "root" + 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: -270.0 + y: -130.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: 100.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 0.7019608 + z: 0.4 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "grid_SW_anchor" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_SW + adjust_mode: ADJUST_MODE_FIT + parent: "root" + 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: 270.0 + y: -130.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: 100.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 0.7019608 + z: 0.4 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "grid_SE_anchor" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_SE + adjust_mode: ADJUST_MODE_FIT + parent: "root" + 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: -130.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: 100.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 0.7019608 + z: 0.4 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "grid_S_anchor" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_S + adjust_mode: ADJUST_MODE_FIT + parent: "root" + 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: -270.0 + y: 120.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: 100.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 0.7019608 + z: 0.4 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "grid_W_anchor" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_W + adjust_mode: ADJUST_MODE_FIT + parent: "root" + 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: 120.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: 100.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 0.7019608 + z: 0.4 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "grid_C_anchor" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "root" + 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: 270.0 + y: 120.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: 100.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 0.7019608 + z: 0.4 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "grid_E_anchor" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_E + adjust_mode: ADJUST_MODE_FIT + parent: "root" + 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 +} +layers { + name: "image" +} +layers { + name: "text" +} +material: "/builtins/materials/gui.material" +adjust_reference: ADJUST_REFERENCE_PARENT +max_nodes: 512 diff --git a/example/examples/grid/static_grid_dynamic_pos/static_grid_dynamic_pos.gui_script b/example/examples/grid/static_grid_dynamic_pos/static_grid_dynamic_pos.gui_script new file mode 100644 index 00000000..2112513f --- /dev/null +++ b/example/examples/grid/static_grid_dynamic_pos/static_grid_dynamic_pos.gui_script @@ -0,0 +1,87 @@ +local druid = require("druid.druid") + + +function init(self) + self.druid = druid.new(self) + local prefab = gui.get_node("prefab") + gui.set_enabled(prefab, false) + + local grid_nw = self.druid:new_static_grid("grid_NW_anchor", prefab, 3) + local grid_ne = self.druid:new_static_grid("grid_NE_anchor", prefab, 3) + local grid_n = self.druid:new_static_grid("grid_N_anchor", prefab, 3) + local grid_sw = self.druid:new_static_grid("grid_SW_anchor", prefab, 3) + local grid_se = self.druid:new_static_grid("grid_SE_anchor", prefab, 3) + local grid_s = self.druid:new_static_grid("grid_S_anchor", prefab, 3) + local grid_w = self.druid:new_static_grid("grid_C_anchor", prefab, 3) + local grid_e = self.druid:new_static_grid("grid_W_anchor", prefab, 3) + local grid_c = self.druid:new_static_grid("grid_E_anchor", prefab, 3) + + local update_pos_func = function(node, pos) gui.animate(node, "position", pos, gui.EASING_OUTSINE, 0.2) end + grid_nw:set_position_function(update_pos_func) + grid_ne:set_position_function(update_pos_func) + grid_n:set_position_function(update_pos_func) + grid_sw:set_position_function(update_pos_func) + grid_se:set_position_function(update_pos_func) + grid_s:set_position_function(update_pos_func) + grid_w:set_position_function(update_pos_func) + grid_e:set_position_function(update_pos_func) + grid_c:set_position_function(update_pos_func) + + local grids = { + grid_nw, + grid_ne, + grid_n, + grid_sw, + grid_se, + grid_s, + grid_c, + grid_w, + grid_e, + } + + for i = 1, #grids do + grids[i].style.IS_DYNAMIC_NODE_POSES = true + end + + + local animate_grides = function() + for _, grid in ipairs(grids) do + for i = 1, #grid.nodes do + gui.delete_node(grid.nodes[i]) + end + grid:clear() + + for i = 1, 9 do + timer.delay(i, false, function() + local node = gui.clone(prefab) + gui.set_enabled(node, true) + grid:add(node) + end) + end + end + end + + animate_grides() + timer.delay(10, true, animate_grides) + +end + + +function final(self) + self.druid:final() +end + + +function update(self, dt) + self.druid:update(dt) +end + + +function on_message(self, message_id, message, sender) + self.druid:on_message(message_id, message, sender) +end + + +function on_input(self, action_id, action) + return self.druid:on_input(action_id, action) +end diff --git a/game.project b/game.project index 68e8802c..7140890e 100644 --- a/game.project +++ b/game.project @@ -11,9 +11,10 @@ height = 900 [project] title = druid version = 0.6.0 -dependencies = https://github.com/insalitygames/deftest/archive/master.zip,https://github.com/britzl/monarch/archive/refs/tags/3.3.0.zip publisher = Insality developer = Insality +dependencies#0 = https://github.com/insalitygames/deftest/archive/master.zip +dependencies#1 = https://github.com/britzl/monarch/archive/refs/tags/3.3.0.zip [library] include_dirs = druid diff --git a/settings_deployer b/settings_deployer index c94ea4ba..cbc62f3d 100644 --- a/settings_deployer +++ b/settings_deployer @@ -1,4 +1,4 @@ #!/bin/bash use_latest_bob=false enable_incremental_version=true -bob_sha="180:f34b08dc12af1101ae62c6e880b6373a03206174" +bob_sha="187:581c6439ae93755a8a6bcf58732c39c724fa193c"