From 46bcbb596d79b80869606a3aa143ab6d578ff22a Mon Sep 17 00:00:00 2001 From: Insality Date: Sun, 17 Jul 2022 18:27:38 +0300 Subject: [PATCH] Fix drag is_enabled, add to example --- druid/base/drag.lua | 3 +- example/examples/general/drag/drag.gui | 163 ++++++++++++++++++ example/examples/general/drag/drag.gui_script | 10 +- 3 files changed, 173 insertions(+), 3 deletions(-) diff --git a/druid/base/drag.lua b/druid/base/drag.lua index 7884ab7..d9f5e19 100644 --- a/druid/base/drag.lua +++ b/druid/base/drag.lua @@ -306,9 +306,8 @@ end -- @tparam Drag self @{Drag} -- @treturn bool function Drag.is_enabled(self) - return self._is_disabled + return not self._is_disabled end - return Drag diff --git a/example/examples/general/drag/drag.gui b/example/examples/general/drag/drag.gui index 4aed380..a0c145a 100644 --- a/example/examples/general/drag/drag.gui +++ b/example/examples/general/drag/drag.gui @@ -308,6 +308,169 @@ nodes { text_tracking: 0.0 custom_type: 0 } +nodes { + position { + x: 0.0 + y: -344.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_TEMPLATE + id: "button_drag" + parent: "root" + layer: "" + inherit_alpha: true + alpha: 1.0 + template: "/example/templates/button.gui" + template_node_child: false + custom_type: 0 +} +nodes { + position { + x: 0.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: 300.0 + y: 60.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: "button_drag/button" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "button_drag" + layer: "image" + inherit_alpha: true + slice9 { + x: 15.0 + y: 15.0 + z: 15.0 + w: 15.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 1.0 + overridden_fields: 4 + template_node_child: true + size_mode: SIZE_MODE_MANUAL + custom_type: 0 +} +nodes { + position { + x: 0.0 + y: 7.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: 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_TEXT + blend_mode: BLEND_MODE_ALPHA + text: "Toggle Drag Enabled" + font: "game" + id: "button_drag/text" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + outline { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + shadow { + x: 0.101960786 + y: 0.2 + z: 0.6 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "button_drag/button" + layer: "text" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 0.0 + shadow_alpha: 0.78 + overridden_fields: 8 + template_node_child: true + text_leading: 1.0 + text_tracking: 0.0 + custom_type: 0 +} layers { name: "image" } diff --git a/example/examples/general/drag/drag.gui_script b/example/examples/general/drag/drag.gui_script index 46c4dcf..06e3584 100644 --- a/example/examples/general/drag/drag.gui_script +++ b/example/examples/general/drag/drag.gui_script @@ -1,9 +1,10 @@ local druid = require("druid.druid") -local function on_drag_callback(self, dx, dy) +local function on_drag_callback(self, dx, dy, total_x, total_y) self.position.x = self.position.x + dx self.position.y = self.position.y + dy + print("Total drag:", total_x, total_y) gui.set_position(self.box, self.position) end @@ -15,6 +16,11 @@ local function on_drag_end(self) end +local function on_drag_toggle(self) + self.drag:set_enabled(not self.drag:is_enabled()) +end + + function init(self) self.druid = druid.new(self) @@ -23,6 +29,8 @@ function init(self) self.drag = self.druid:new_drag("drag_node", on_drag_callback) self.drag.on_drag_end:subscribe(on_drag_end, self) + + self.druid:new_button("button_drag/button", on_drag_toggle) end