mirror of
https://github.com/Insality/druid
synced 2025-09-27 18:12:21 +02:00
Update example with new brand one
This commit is contained in:
241
example/examples/basic/drag/drag.gui
Normal file
241
example/examples/basic/drag/drag.gui
Normal file
@@ -0,0 +1,241 @@
|
||||
script: ""
|
||||
textures {
|
||||
name: "druid"
|
||||
texture: "/example/assets/druid.atlas"
|
||||
}
|
||||
background_color {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 0.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: 1000.0
|
||||
y: 1000.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: ""
|
||||
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
|
||||
custom_type: 0
|
||||
enabled: true
|
||||
visible: false
|
||||
material: ""
|
||||
}
|
||||
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: 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: "drag"
|
||||
parent: "root"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
alpha: 1.0
|
||||
template: "/example/templates/button_text_blue.gui"
|
||||
template_node_child: false
|
||||
custom_type: 0
|
||||
enabled: true
|
||||
}
|
||||
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: 280.0
|
||||
y: 90.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 0.631
|
||||
y: 0.843
|
||||
z: 0.961
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_BOX
|
||||
blend_mode: BLEND_MODE_ALPHA
|
||||
texture: "druid/ui_circle_32"
|
||||
id: "drag/root"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_CENTER
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
parent: "drag"
|
||||
layer: "druid"
|
||||
inherit_alpha: true
|
||||
slice9 {
|
||||
x: 16.0
|
||||
y: 16.0
|
||||
z: 16.0
|
||||
w: 16.0
|
||||
}
|
||||
clipping_mode: CLIPPING_MODE_NONE
|
||||
clipping_visible: true
|
||||
clipping_inverted: false
|
||||
alpha: 1.0
|
||||
template_node_child: true
|
||||
size_mode: SIZE_MODE_MANUAL
|
||||
custom_type: 0
|
||||
enabled: true
|
||||
visible: true
|
||||
material: ""
|
||||
}
|
||||
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: 245.0
|
||||
y: 50.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 0.31
|
||||
y: 0.318
|
||||
z: 0.322
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_TEXT
|
||||
blend_mode: BLEND_MODE_ALPHA
|
||||
text: "Drag Me"
|
||||
font: "text_bold"
|
||||
id: "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: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
line_break: false
|
||||
parent: "drag/root"
|
||||
layer: "text_bold"
|
||||
inherit_alpha: true
|
||||
alpha: 1.0
|
||||
outline_alpha: 0.0
|
||||
shadow_alpha: 0.0
|
||||
overridden_fields: 8
|
||||
template_node_child: true
|
||||
text_leading: 1.0
|
||||
text_tracking: 0.0
|
||||
custom_type: 0
|
||||
enabled: true
|
||||
visible: true
|
||||
material: ""
|
||||
}
|
||||
material: "/builtins/materials/gui.material"
|
||||
adjust_reference: ADJUST_REFERENCE_PARENT
|
||||
max_nodes: 512
|
29
example/examples/basic/drag/drag.lua
Normal file
29
example/examples/basic/drag/drag.lua
Normal file
@@ -0,0 +1,29 @@
|
||||
local component = require("druid.component")
|
||||
|
||||
---@class drag: druid.base_component
|
||||
---@field druid druid_instance
|
||||
local M = component.create("drag")
|
||||
|
||||
|
||||
---@param template string
|
||||
---@param nodes table<hash, node>
|
||||
function M:init(template, nodes)
|
||||
self.druid = self:get_druid(template, nodes)
|
||||
|
||||
-- Init drag and move the drag node on drag callback
|
||||
self.drag = self.druid:new_drag("drag/root", function(_, dx, dy)
|
||||
local position_x = gui.get(self.drag.node, "position.x")
|
||||
local position_y = gui.get(self.drag.node, "position.y")
|
||||
gui.set(self.drag.node, "position.x", position_x + dx)
|
||||
gui.set(self.drag.node, "position.y", position_y + dy)
|
||||
end)
|
||||
|
||||
-- Save start position for animation
|
||||
self.start_position = gui.get_position(self.drag.node)
|
||||
self.drag.on_drag_end:subscribe(function()
|
||||
gui.animate(self.drag.node, "position", self.start_position, gui.EASING_OUTBACK, 0.3)
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
return M
|
124
example/examples/basic/drag/drag_to_node.gui
Normal file
124
example/examples/basic/drag/drag_to_node.gui
Normal file
@@ -0,0 +1,124 @@
|
||||
fonts {
|
||||
name: "text_bold"
|
||||
font: "/example/assets/fonts/text_bold.font"
|
||||
}
|
||||
textures {
|
||||
name: "druid"
|
||||
texture: "/example/assets/druid.atlas"
|
||||
}
|
||||
nodes {
|
||||
size {
|
||||
x: 1000.0
|
||||
y: 1000.0
|
||||
}
|
||||
type: TYPE_BOX
|
||||
id: "root"
|
||||
inherit_alpha: true
|
||||
visible: false
|
||||
}
|
||||
nodes {
|
||||
type: TYPE_TEMPLATE
|
||||
id: "drag"
|
||||
parent: "root"
|
||||
inherit_alpha: true
|
||||
template: "/example/templates/button_text_blue.gui"
|
||||
}
|
||||
nodes {
|
||||
type: TYPE_BOX
|
||||
id: "drag/root"
|
||||
parent: "drag"
|
||||
template_node_child: true
|
||||
}
|
||||
nodes {
|
||||
type: TYPE_TEXT
|
||||
text: "Drag Me"
|
||||
id: "drag/text"
|
||||
parent: "drag/root"
|
||||
overridden_fields: 8
|
||||
template_node_child: true
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
y: 300.0
|
||||
}
|
||||
size {
|
||||
x: 300.0
|
||||
y: 300.0
|
||||
}
|
||||
color {
|
||||
x: 0.173
|
||||
y: 0.184
|
||||
z: 0.204
|
||||
}
|
||||
type: TYPE_BOX
|
||||
texture: "druid/ui_circle_64"
|
||||
id: "zone"
|
||||
parent: "root"
|
||||
inherit_alpha: true
|
||||
slice9 {
|
||||
x: 32.0
|
||||
y: 32.0
|
||||
z: 32.0
|
||||
w: 32.0
|
||||
}
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
y: 100.0
|
||||
}
|
||||
size {
|
||||
x: 300.0
|
||||
y: 100.0
|
||||
}
|
||||
color {
|
||||
x: 0.31
|
||||
y: 0.318
|
||||
z: 0.322
|
||||
}
|
||||
type: TYPE_TEXT
|
||||
text: "Drop Item Here"
|
||||
font: "text_bold"
|
||||
id: "text_hint"
|
||||
outline {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
}
|
||||
shadow {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
}
|
||||
parent: "zone"
|
||||
outline_alpha: 0.0
|
||||
shadow_alpha: 0.0
|
||||
}
|
||||
nodes {
|
||||
scale {
|
||||
x: 2.0
|
||||
y: 2.0
|
||||
}
|
||||
size {
|
||||
x: 100.0
|
||||
y: 100.0
|
||||
}
|
||||
type: TYPE_TEXT
|
||||
text: "0"
|
||||
font: "text_bold"
|
||||
id: "text_counter"
|
||||
outline {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
}
|
||||
shadow {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
}
|
||||
parent: "zone"
|
||||
outline_alpha: 0.0
|
||||
shadow_alpha: 0.0
|
||||
}
|
||||
material: "/builtins/materials/gui.material"
|
||||
adjust_reference: ADJUST_REFERENCE_PARENT
|
62
example/examples/basic/drag/drag_to_node.lua
Normal file
62
example/examples/basic/drag/drag_to_node.lua
Normal file
@@ -0,0 +1,62 @@
|
||||
local component = require("druid.component")
|
||||
|
||||
---@class drag_to_node: druid.base_component
|
||||
---@field druid druid_instance
|
||||
local M = component.create("drag_to_node")
|
||||
|
||||
|
||||
---@param template string
|
||||
---@param nodes table<hash, node>
|
||||
function M:init(template, nodes)
|
||||
self.druid = self:get_druid(template, nodes)
|
||||
self.zone = self:get_node("zone")
|
||||
self.counter = 0
|
||||
self.text_counter = self:get_node("text_counter")
|
||||
gui.set_text(self.text_counter, self.counter)
|
||||
|
||||
-- Init drag and move the drag node on drag callback
|
||||
self.drag = self.druid:new_drag("drag/root", self.on_drag_start)
|
||||
self.drag.on_drag_end:subscribe(self.on_drag_end)
|
||||
|
||||
-- Save start position for animation
|
||||
self.start_position = gui.get_position(self.drag.node)
|
||||
end
|
||||
|
||||
|
||||
function M:on_drag_start(dx, dy, x, y, touch)
|
||||
local position_x = gui.get(self.drag.node, "position.x")
|
||||
local position_y = gui.get(self.drag.node, "position.y")
|
||||
gui.set(self.drag.node, "position.x", position_x + dx)
|
||||
gui.set(self.drag.node, "position.y", position_y + dy)
|
||||
|
||||
local is_pick_zone = gui.pick_node(self.zone, touch.x, touch.y)
|
||||
self:on_hover_pick_zone(is_pick_zone)
|
||||
end
|
||||
|
||||
|
||||
function M:on_drag_end(x, y, touch)
|
||||
gui.animate(self.drag.node, "position", self.start_position, gui.EASING_OUTBACK, 0.3)
|
||||
|
||||
local is_pick_zone = gui.pick_node(self.zone, touch.x, touch.y)
|
||||
if is_pick_zone then
|
||||
self.counter = self.counter + 1
|
||||
gui.set_text(self.text_counter, self.counter)
|
||||
self:on_drop_to_zone()
|
||||
end
|
||||
self:on_hover_pick_zone(false)
|
||||
end
|
||||
|
||||
|
||||
function M:on_hover_pick_zone(is_pick_zone)
|
||||
local target_alpha = is_pick_zone and 1.5 or 1
|
||||
gui.animate(self.zone, "color.w", target_alpha, gui.EASING_OUTSINE, 0.3)
|
||||
end
|
||||
|
||||
|
||||
function M:on_drop_to_zone()
|
||||
gui.set_scale(self.zone, vmath.vector3(1.2))
|
||||
gui.animate(self.zone, "scale", vmath.vector3(1), gui.EASING_OUTBACK, 0.3)
|
||||
end
|
||||
|
||||
|
||||
return M
|
Reference in New Issue
Block a user