mirror of
https://github.com/Insality/druid.git
synced 2025-06-27 10:27:47 +02:00
Update
This commit is contained in:
parent
e83e5a6c84
commit
65234ec8d2
32
README.md
32
README.md
@ -74,23 +74,23 @@ Create a new `*.gui_script` file and add the following code:
|
|||||||
local druid = require("druid.druid")
|
local druid = require("druid.druid")
|
||||||
|
|
||||||
function init(self)
|
function init(self)
|
||||||
self.druid = druid.new(self)
|
self.druid = druid.new(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
function final(self)
|
function final(self)
|
||||||
self.druid:final()
|
self.druid:final()
|
||||||
end
|
end
|
||||||
|
|
||||||
function update(self, dt)
|
function update(self, dt)
|
||||||
self.druid:update(dt)
|
self.druid:update(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_message(self, message_id, message, sender)
|
function on_message(self, message_id, message, sender)
|
||||||
self.druid:on_message(message_id, message, sender)
|
self.druid:on_message(message_id, message, sender)
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_input(self, action_id, action)
|
function on_input(self, action_id, action)
|
||||||
return self.druid:on_input(action_id, action)
|
return self.druid:on_input(action_id, action)
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -108,29 +108,29 @@ local druid = require("druid.druid")
|
|||||||
-- All component callbacks pass "self" as first argument
|
-- All component callbacks pass "self" as first argument
|
||||||
-- This "self" is a context data passed in `druid.new(context)`
|
-- This "self" is a context data passed in `druid.new(context)`
|
||||||
local function on_button_callback(self)
|
local function on_button_callback(self)
|
||||||
self.text:set_text("The button clicked!")
|
self.text:set_text("The button clicked!")
|
||||||
end
|
end
|
||||||
|
|
||||||
function init(self)
|
function init(self)
|
||||||
self.druid = druid.new(self)
|
self.druid = druid.new(self)
|
||||||
self.button = self.druid:new_button("button_node_id", on_button_callback)
|
self.button = self.druid:new_button("button_node_id", on_button_callback)
|
||||||
self.text = self.druid:new_text("text_node_id", "Hello, Druid!")
|
self.text = self.druid:new_text("text_node_id", "Hello, Druid!")
|
||||||
end
|
end
|
||||||
|
|
||||||
function final(self)
|
function final(self)
|
||||||
self.druid:final()
|
self.druid:final()
|
||||||
end
|
end
|
||||||
|
|
||||||
function update(self, dt)
|
function update(self, dt)
|
||||||
self.druid:update(dt)
|
self.druid:update(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_message(self, message_id, message, sender)
|
function on_message(self, message_id, message, sender)
|
||||||
self.druid:on_message(message_id, message, sender)
|
self.druid:on_message(message_id, message, sender)
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_input(self, action_id, action)
|
function on_input(self, action_id, action)
|
||||||
return self.druid:on_input(action_id, action)
|
return self.druid:on_input(action_id, action)
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -146,12 +146,12 @@ Usually this widget lua file is placed nearby with the `GUI` file it belong to a
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
function M:init()
|
function M:init()
|
||||||
self.root = self:get_node("root")
|
self.root = self:get_node("root")
|
||||||
self.button = self.druid:new_button("button", self.on_click)
|
self.button = self.druid:new_button("button", self.on_click)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M:on_click()
|
function M:on_click()
|
||||||
print("Button clicked!")
|
print("Button clicked!")
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
@ -201,7 +201,7 @@ end
|
|||||||
---@param y1 number First point y
|
---@param y1 number First point y
|
||||||
---@param x2 number Second point x
|
---@param x2 number Second point x
|
||||||
---@param y2 number Second point y
|
---@param y2 number Second point y
|
||||||
---@return number Distance
|
---@return number distance
|
||||||
function M.distance(x1, y1, x2, y2)
|
function M.distance(x1, y1, x2, y2)
|
||||||
return math.sqrt((x2 - x1) ^ 2 + (y2 - y1) ^ 2)
|
return math.sqrt((x2 - x1) ^ 2 + (y2 - y1) ^ 2)
|
||||||
end
|
end
|
||||||
@ -242,6 +242,7 @@ end
|
|||||||
---Check if value contains in array
|
---Check if value contains in array
|
||||||
---@param array any[] Array to check
|
---@param array any[] Array to check
|
||||||
---@param value any Value
|
---@param value any Value
|
||||||
|
---@return number|nil index Index of value in array or nil if value not found
|
||||||
function M.contains(array, value)
|
function M.contains(array, value)
|
||||||
for index = 1, #array do
|
for index = 1, #array do
|
||||||
if array[index] == value then
|
if array[index] == value then
|
||||||
@ -428,10 +429,10 @@ function M.get_border(node, offset)
|
|||||||
local pivot_offset = M.get_pivot_offset(pivot)
|
local pivot_offset = M.get_pivot_offset(pivot)
|
||||||
local size = M.get_scaled_size(node)
|
local size = M.get_scaled_size(node)
|
||||||
local border = vmath.vector4(
|
local border = vmath.vector4(
|
||||||
-size.x*(0.5 + pivot_offset.x),
|
-size.x * (0.5 + pivot_offset.x),
|
||||||
size.y*(0.5 - pivot_offset.y),
|
size.y * (0.5 - pivot_offset.y),
|
||||||
size.x*(0.5 - pivot_offset.x),
|
size.x * (0.5 - pivot_offset.x),
|
||||||
-size.y*(0.5 + pivot_offset.y)
|
-size.y * (0.5 + pivot_offset.y)
|
||||||
)
|
)
|
||||||
|
|
||||||
if offset then
|
if offset then
|
||||||
|
@ -1,266 +1,268 @@
|
|||||||
return {
|
return {
|
||||||
type = "animation_editor",
|
|
||||||
format = "json",
|
|
||||||
data = {
|
data = {
|
||||||
nodes = {
|
|
||||||
},
|
|
||||||
animations = {
|
animations = {
|
||||||
{
|
{
|
||||||
animation_id = "default",
|
animation_id = "default",
|
||||||
duration = 1,
|
|
||||||
animation_keys = {
|
animation_keys = {
|
||||||
},
|
},
|
||||||
|
duration = 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
animation_id = "hold",
|
animation_id = "hold",
|
||||||
duration = 1,
|
|
||||||
animation_keys = {
|
animation_keys = {
|
||||||
{
|
{
|
||||||
|
easing = "outsine",
|
||||||
end_value = -90,
|
end_value = -90,
|
||||||
easing = "outsine",
|
key_type = "tween",
|
||||||
property_id = "rotation_z",
|
|
||||||
node_id = "button_image",
|
node_id = "button_image",
|
||||||
key_type = "tween",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
end_value = 90,
|
|
||||||
easing = "outsine",
|
|
||||||
property_id = "rotation_z",
|
property_id = "rotation_z",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
easing = "outsine",
|
||||||
|
end_value = 90,
|
||||||
|
key_type = "tween",
|
||||||
node_id = "mask",
|
node_id = "mask",
|
||||||
key_type = "tween",
|
property_id = "rotation_z",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
end_value = 1.1,
|
|
||||||
easing = "outsine",
|
|
||||||
property_id = "scale_x",
|
|
||||||
duration = 0.15,
|
duration = 0.15,
|
||||||
|
easing = "outsine",
|
||||||
|
end_value = 1.1,
|
||||||
key_type = "tween",
|
key_type = "tween",
|
||||||
node_id = "button",
|
node_id = "button",
|
||||||
|
property_id = "scale_x",
|
||||||
start_value = 1,
|
start_value = 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
end_value = 1.1,
|
|
||||||
easing = "outsine",
|
|
||||||
property_id = "scale_y",
|
|
||||||
duration = 0.15,
|
duration = 0.15,
|
||||||
|
easing = "outsine",
|
||||||
|
end_value = 1.1,
|
||||||
key_type = "tween",
|
key_type = "tween",
|
||||||
node_id = "button",
|
node_id = "button",
|
||||||
start_value = 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
end_value = 1.3,
|
|
||||||
easing = "outsine",
|
|
||||||
property_id = "scale_x",
|
|
||||||
duration = 0.15,
|
|
||||||
key_type = "tween",
|
|
||||||
node_id = "text",
|
|
||||||
start_value = 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
end_value = 1.3,
|
|
||||||
easing = "outsine",
|
|
||||||
property_id = "scale_y",
|
property_id = "scale_y",
|
||||||
duration = 0.15,
|
|
||||||
key_type = "tween",
|
|
||||||
node_id = "text",
|
|
||||||
start_value = 1,
|
start_value = 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
start_value = 360,
|
duration = 0.15,
|
||||||
easing = "outsine",
|
easing = "outsine",
|
||||||
property_id = "fill_angle",
|
end_value = 1.3,
|
||||||
|
key_type = "tween",
|
||||||
|
node_id = "text",
|
||||||
|
property_id = "scale_x",
|
||||||
|
start_value = 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
duration = 0.15,
|
||||||
|
easing = "outsine",
|
||||||
|
end_value = 1.3,
|
||||||
|
key_type = "tween",
|
||||||
|
node_id = "text",
|
||||||
|
property_id = "scale_y",
|
||||||
|
start_value = 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
duration = 1,
|
duration = 1,
|
||||||
|
easing = "outsine",
|
||||||
|
key_type = "tween",
|
||||||
node_id = "mask",
|
node_id = "mask",
|
||||||
key_type = "tween",
|
property_id = "fill_angle",
|
||||||
|
start_value = 360,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
end_value = 1,
|
|
||||||
easing = "incirc",
|
|
||||||
property_id = "scale_x",
|
|
||||||
duration = 0.85,
|
duration = 0.85,
|
||||||
start_value = 1.1,
|
easing = "incirc",
|
||||||
|
end_value = 1,
|
||||||
key_type = "tween",
|
key_type = "tween",
|
||||||
node_id = "button",
|
node_id = "button",
|
||||||
|
property_id = "scale_x",
|
||||||
start_time = 0.15,
|
start_time = 0.15,
|
||||||
|
start_value = 1.1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
end_value = 1,
|
|
||||||
easing = "incirc",
|
|
||||||
property_id = "scale_y",
|
|
||||||
duration = 0.85,
|
duration = 0.85,
|
||||||
start_value = 1.1,
|
easing = "incirc",
|
||||||
|
end_value = 1,
|
||||||
key_type = "tween",
|
key_type = "tween",
|
||||||
node_id = "button",
|
node_id = "button",
|
||||||
start_time = 0.15,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
end_value = 1,
|
|
||||||
easing = "outsine",
|
|
||||||
property_id = "scale_x",
|
|
||||||
duration = 0.51,
|
|
||||||
start_value = 1.3,
|
|
||||||
key_type = "tween",
|
|
||||||
node_id = "text",
|
|
||||||
start_time = 0.49,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
end_value = 1,
|
|
||||||
easing = "outsine",
|
|
||||||
property_id = "scale_y",
|
property_id = "scale_y",
|
||||||
|
start_time = 0.15,
|
||||||
|
start_value = 1.1,
|
||||||
|
},
|
||||||
|
{
|
||||||
duration = 0.51,
|
duration = 0.51,
|
||||||
start_value = 1.3,
|
easing = "outsine",
|
||||||
|
end_value = 1,
|
||||||
key_type = "tween",
|
key_type = "tween",
|
||||||
node_id = "text",
|
node_id = "text",
|
||||||
|
property_id = "scale_x",
|
||||||
start_time = 0.49,
|
start_time = 0.49,
|
||||||
|
start_value = 1.3,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
duration = 0.51,
|
||||||
|
easing = "outsine",
|
||||||
|
end_value = 1,
|
||||||
|
key_type = "tween",
|
||||||
|
node_id = "text",
|
||||||
|
property_id = "scale_y",
|
||||||
|
start_time = 0.49,
|
||||||
|
start_value = 1.3,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
duration = 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
animation_id = "complete",
|
animation_id = "complete",
|
||||||
duration = 0.4,
|
|
||||||
animation_keys = {
|
animation_keys = {
|
||||||
{
|
{
|
||||||
easing = "linear",
|
|
||||||
property_id = "inherit_alpha",
|
|
||||||
data = "false",
|
data = "false",
|
||||||
|
easing = "linear",
|
||||||
key_type = "trigger",
|
key_type = "trigger",
|
||||||
node_id = "text",
|
node_id = "text",
|
||||||
|
property_id = "inherit_alpha",
|
||||||
start_data = "true",
|
start_data = "true",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
end_value = 0.624,
|
|
||||||
easing = "outsine",
|
easing = "outsine",
|
||||||
property_id = "color_b",
|
end_value = 0.62,
|
||||||
key_type = "tween",
|
key_type = "tween",
|
||||||
node_id = "button_image",
|
node_id = "button_image",
|
||||||
|
property_id = "color_b",
|
||||||
start_value = 0.62,
|
start_value = 0.62,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
end_value = 0.875,
|
|
||||||
easing = "outsine",
|
easing = "outsine",
|
||||||
property_id = "color_g",
|
end_value = 0.88,
|
||||||
key_type = "tween",
|
key_type = "tween",
|
||||||
node_id = "button_image",
|
node_id = "button_image",
|
||||||
|
property_id = "color_g",
|
||||||
start_value = 0.835,
|
start_value = 0.835,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
end_value = 0.902,
|
|
||||||
easing = "outsine",
|
easing = "outsine",
|
||||||
property_id = "color_r",
|
end_value = 0.9,
|
||||||
key_type = "tween",
|
key_type = "tween",
|
||||||
node_id = "button_image",
|
node_id = "button_image",
|
||||||
|
property_id = "color_r",
|
||||||
start_value = 0.557,
|
start_value = 0.557,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
duration = 0.17,
|
||||||
|
easing = "outsine",
|
||||||
end_value = 1.1,
|
end_value = 1.1,
|
||||||
easing = "outsine",
|
key_type = "tween",
|
||||||
|
node_id = "root",
|
||||||
property_id = "color_a",
|
property_id = "color_a",
|
||||||
duration = 0.17,
|
|
||||||
key_type = "tween",
|
|
||||||
node_id = "root",
|
|
||||||
start_value = 1,
|
start_value = 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
end_value = 1.2,
|
duration = 0.17,
|
||||||
easing = "outsine",
|
easing = "outsine",
|
||||||
|
end_value = 1.2,
|
||||||
|
key_type = "tween",
|
||||||
|
node_id = "root",
|
||||||
property_id = "scale_x",
|
property_id = "scale_x",
|
||||||
duration = 0.17,
|
|
||||||
key_type = "tween",
|
|
||||||
node_id = "root",
|
|
||||||
start_value = 1,
|
start_value = 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
duration = 0.17,
|
||||||
|
easing = "outsine",
|
||||||
end_value = 1.2,
|
end_value = 1.2,
|
||||||
easing = "outsine",
|
|
||||||
property_id = "scale_y",
|
|
||||||
duration = 0.17,
|
|
||||||
key_type = "tween",
|
key_type = "tween",
|
||||||
node_id = "root",
|
node_id = "root",
|
||||||
|
property_id = "scale_y",
|
||||||
start_value = 1,
|
start_value = 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
end_value = 0.557,
|
duration = 0.38,
|
||||||
easing = "outsine",
|
easing = "outsine",
|
||||||
|
end_value = 0.56,
|
||||||
|
key_type = "tween",
|
||||||
|
node_id = "button_image",
|
||||||
property_id = "color_r",
|
property_id = "color_r",
|
||||||
duration = 0.38,
|
|
||||||
start_value = 0.902,
|
|
||||||
key_type = "tween",
|
|
||||||
node_id = "button_image",
|
|
||||||
start_time = 0.02,
|
start_time = 0.02,
|
||||||
|
start_value = 0.9,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
duration = 0.38,
|
||||||
|
easing = "outsine",
|
||||||
end_value = 0.62,
|
end_value = 0.62,
|
||||||
easing = "outsine",
|
key_type = "tween",
|
||||||
|
node_id = "button_image",
|
||||||
property_id = "color_b",
|
property_id = "color_b",
|
||||||
duration = 0.38,
|
|
||||||
start_value = 0.624,
|
|
||||||
key_type = "tween",
|
|
||||||
node_id = "button_image",
|
|
||||||
start_time = 0.02,
|
start_time = 0.02,
|
||||||
|
start_value = 0.62,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
end_value = 0.835,
|
duration = 0.38,
|
||||||
easing = "outsine",
|
easing = "outsine",
|
||||||
|
end_value = 0.84,
|
||||||
|
key_type = "tween",
|
||||||
|
node_id = "button_image",
|
||||||
property_id = "color_g",
|
property_id = "color_g",
|
||||||
duration = 0.38,
|
|
||||||
start_value = 0.875,
|
|
||||||
key_type = "tween",
|
|
||||||
node_id = "button_image",
|
|
||||||
start_time = 0.02,
|
start_time = 0.02,
|
||||||
|
start_value = 0.88,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
end_value = 1,
|
duration = 0.22,
|
||||||
easing = "outsine",
|
easing = "outsine",
|
||||||
|
end_value = 1,
|
||||||
|
key_type = "tween",
|
||||||
|
node_id = "root",
|
||||||
property_id = "color_a",
|
property_id = "color_a",
|
||||||
duration = 0.22,
|
start_time = 0.17,
|
||||||
start_value = 1.1,
|
start_value = 1.1,
|
||||||
key_type = "tween",
|
|
||||||
node_id = "root",
|
|
||||||
start_time = 0.17,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
end_value = 1,
|
duration = 0.22,
|
||||||
easing = "outsine",
|
easing = "outsine",
|
||||||
|
end_value = 1,
|
||||||
|
key_type = "tween",
|
||||||
|
node_id = "root",
|
||||||
property_id = "scale_x",
|
property_id = "scale_x",
|
||||||
duration = 0.22,
|
|
||||||
start_value = 1.2,
|
|
||||||
key_type = "tween",
|
|
||||||
node_id = "root",
|
|
||||||
start_time = 0.17,
|
start_time = 0.17,
|
||||||
|
start_value = 1.2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
end_value = 1,
|
duration = 0.22,
|
||||||
easing = "outsine",
|
easing = "outsine",
|
||||||
property_id = "scale_y",
|
end_value = 1,
|
||||||
duration = 0.22,
|
|
||||||
start_value = 1.2,
|
|
||||||
key_type = "tween",
|
key_type = "tween",
|
||||||
node_id = "root",
|
node_id = "root",
|
||||||
|
property_id = "scale_y",
|
||||||
start_time = 0.17,
|
start_time = 0.17,
|
||||||
|
start_value = 1.2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
easing = "linear",
|
|
||||||
property_id = "inherit_alpha",
|
|
||||||
start_data = "false",
|
|
||||||
data = "true",
|
data = "true",
|
||||||
|
easing = "linear",
|
||||||
key_type = "trigger",
|
key_type = "trigger",
|
||||||
node_id = "text",
|
node_id = "text",
|
||||||
|
property_id = "inherit_alpha",
|
||||||
|
start_data = "false",
|
||||||
start_time = 0.39,
|
start_time = 0.39,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
duration = 0.4,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
metadata = {
|
metadata = {
|
||||||
layers = {
|
fps = 60,
|
||||||
|
gizmo_steps = {
|
||||||
},
|
},
|
||||||
gui_path = "/example/examples/basic/button/basic_button_hold.gui",
|
gui_path = "/example/examples/basic/button/basic_button_hold.gui",
|
||||||
gizmo_steps = {
|
layers = {
|
||||||
},
|
},
|
||||||
settings = {
|
settings = {
|
||||||
font_size = 40,
|
font_size = 40,
|
||||||
},
|
},
|
||||||
fps = 60,
|
template_animation_paths = {
|
||||||
|
},
|
||||||
|
},
|
||||||
|
nodes = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
format = "json",
|
||||||
|
type = "animation_editor",
|
||||||
version = 1,
|
version = 1,
|
||||||
}
|
}
|
@ -8,8 +8,8 @@ textures {
|
|||||||
}
|
}
|
||||||
nodes {
|
nodes {
|
||||||
size {
|
size {
|
||||||
x: 12.0
|
x: 250.0
|
||||||
y: 12.0
|
y: 250.0
|
||||||
}
|
}
|
||||||
color {
|
color {
|
||||||
x: 0.31
|
x: 0.31
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
[bootstrap]
|
[bootstrap]
|
||||||
main_collection = /example/other/go_bindings/go_bindings.collectionc
|
main_collection = /example/druid.collectionc
|
||||||
|
|
||||||
[script]
|
[script]
|
||||||
shared_state = 1
|
shared_state = 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user