Add vector3 property

This commit is contained in:
Insality 2024-11-29 00:49:56 +02:00
parent 434dce55ce
commit cb36625836
5 changed files with 784 additions and 6 deletions

View File

@ -22,12 +22,6 @@ function M:init()
end
function M:on_click()
gui.set_alpha(self.selected, 1)
gui.animate(self.selected, "color.w", 0, gui.EASING_INSINE, 0.16)
end
---@param text string
---@return widget.property_input
function M:set_text_property(text)
@ -35,6 +29,7 @@ function M:set_text_property(text)
return self
end
---@param text string
---@return widget.property_input
function M:set_text_value(text)

View File

@ -0,0 +1,490 @@
fonts {
name: "druid_text_bold"
font: "/druid/fonts/druid_text_bold.font"
}
fonts {
name: "druid_text_regular"
font: "/druid/fonts/druid_text_regular.font"
}
textures {
name: "druid"
texture: "/druid/druid.atlas"
}
nodes {
size {
x: 400.0
y: 40.0
}
type: TYPE_BOX
texture: "druid/empty"
id: "root"
adjust_mode: ADJUST_MODE_STRETCH
inherit_alpha: true
visible: false
}
nodes {
position {
x: -200.0
}
scale {
x: 0.5
y: 0.5
}
size {
x: 350.0
y: 50.0
}
color {
x: 0.463
y: 0.475
z: 0.49
}
type: TYPE_TEXT
text: "Vector3"
font: "druid_text_bold"
id: "text_name"
pivot: PIVOT_W
outline {
x: 1.0
y: 1.0
z: 1.0
}
shadow {
x: 1.0
y: 1.0
z: 1.0
}
parent: "root"
inherit_alpha: true
outline_alpha: 0.0
shadow_alpha: 0.0
}
nodes {
position {
x: 200.0
}
size {
x: 200.0
y: 40.0
}
type: TYPE_BOX
id: "E_Anchor"
pivot: PIVOT_E
parent: "root"
inherit_alpha: true
size_mode: SIZE_MODE_AUTO
visible: false
}
nodes {
position {
x: -200.0
}
size {
x: 66.0
y: 40.0
}
type: TYPE_BOX
id: "field_x"
pivot: PIVOT_W
parent: "E_Anchor"
inherit_alpha: true
size_mode: SIZE_MODE_AUTO
visible: false
}
nodes {
position {
x: 7.0
}
scale {
x: 0.5
y: 0.5
}
size {
x: 30.0
y: 40.0
}
color {
x: 0.31
y: 0.318
z: 0.322
}
type: TYPE_TEXT
text: "X"
font: "druid_text_regular"
id: "text_x"
parent: "field_x"
inherit_alpha: true
outline_alpha: 0.0
shadow_alpha: 0.0
}
nodes {
position {
x: 40.0
}
type: TYPE_TEMPLATE
id: "rich_input_x"
parent: "field_x"
inherit_alpha: true
template: "/druid/custom/rich_input/rich_input.gui"
}
nodes {
size {
x: 50.0
y: 40.0
}
type: TYPE_BOX
id: "rich_input_x/root"
parent: "rich_input_x"
overridden_fields: 4
template_node_child: true
}
nodes {
size {
x: 50.0
y: 40.0
}
type: TYPE_BOX
id: "rich_input_x/button"
parent: "rich_input_x/root"
overridden_fields: 4
template_node_child: true
}
nodes {
size {
x: 70.0
y: 50.0
}
type: TYPE_TEXT
id: "rich_input_x/placeholder_text"
parent: "rich_input_x/root"
overridden_fields: 4
overridden_fields: 8
template_node_child: true
}
nodes {
size {
x: 70.0
y: 50.0
}
type: TYPE_TEXT
text: "20.0"
id: "rich_input_x/input_text"
parent: "rich_input_x/root"
overridden_fields: 4
overridden_fields: 8
template_node_child: true
}
nodes {
position {
x: 18.0
}
type: TYPE_BOX
id: "rich_input_x/cursor_node"
parent: "rich_input_x/root"
overridden_fields: 1
template_node_child: true
}
nodes {
type: TYPE_TEXT
id: "rich_input_x/cursor_text"
parent: "rich_input_x/cursor_node"
template_node_child: true
}
nodes {
position {
x: 40.0
y: -20.0
}
size {
x: 50.0
y: 4.0
}
color {
x: 0.894
y: 0.506
z: 0.333
}
type: TYPE_BOX
texture: "druid/pixel"
id: "selected_x"
pivot: PIVOT_S
adjust_mode: ADJUST_MODE_STRETCH
parent: "field_x"
inherit_alpha: true
}
nodes {
position {
x: -132.0
}
size {
x: 66.0
y: 40.0
}
type: TYPE_BOX
id: "field_y"
pivot: PIVOT_W
parent: "E_Anchor"
inherit_alpha: true
size_mode: SIZE_MODE_AUTO
visible: false
}
nodes {
position {
x: 7.0
}
scale {
x: 0.5
y: 0.5
}
size {
x: 30.0
y: 40.0
}
color {
x: 0.31
y: 0.318
z: 0.322
}
type: TYPE_TEXT
text: "Y"
font: "druid_text_regular"
id: "text_y"
parent: "field_y"
inherit_alpha: true
outline_alpha: 0.0
shadow_alpha: 0.0
}
nodes {
position {
x: 40.0
}
type: TYPE_TEMPLATE
id: "rich_input_y"
parent: "field_y"
inherit_alpha: true
template: "/druid/custom/rich_input/rich_input.gui"
}
nodes {
size {
x: 50.0
y: 40.0
}
type: TYPE_BOX
id: "rich_input_y/root"
parent: "rich_input_y"
overridden_fields: 4
template_node_child: true
}
nodes {
size {
x: 50.0
y: 40.0
}
type: TYPE_BOX
id: "rich_input_y/button"
parent: "rich_input_y/root"
overridden_fields: 4
template_node_child: true
}
nodes {
size {
x: 70.0
y: 50.0
}
type: TYPE_TEXT
id: "rich_input_y/placeholder_text"
parent: "rich_input_y/root"
overridden_fields: 4
overridden_fields: 8
template_node_child: true
}
nodes {
size {
x: 70.0
y: 50.0
}
type: TYPE_TEXT
text: "20.0"
id: "rich_input_y/input_text"
parent: "rich_input_y/root"
overridden_fields: 4
overridden_fields: 8
template_node_child: true
}
nodes {
position {
x: 18.0
}
type: TYPE_BOX
id: "rich_input_y/cursor_node"
parent: "rich_input_y/root"
overridden_fields: 1
template_node_child: true
}
nodes {
type: TYPE_TEXT
id: "rich_input_y/cursor_text"
parent: "rich_input_y/cursor_node"
template_node_child: true
}
nodes {
position {
x: 40.0
y: -20.0
}
size {
x: 50.0
y: 4.0
}
color {
x: 0.894
y: 0.506
z: 0.333
}
type: TYPE_BOX
texture: "druid/pixel"
id: "selected_y"
pivot: PIVOT_S
adjust_mode: ADJUST_MODE_STRETCH
parent: "field_y"
inherit_alpha: true
}
nodes {
position {
x: -66.0
}
size {
x: 66.0
y: 40.0
}
type: TYPE_BOX
id: "field_z"
pivot: PIVOT_W
parent: "E_Anchor"
inherit_alpha: true
size_mode: SIZE_MODE_AUTO
visible: false
}
nodes {
position {
x: 7.0
}
scale {
x: 0.5
y: 0.5
}
size {
x: 30.0
y: 40.0
}
color {
x: 0.31
y: 0.318
z: 0.322
}
type: TYPE_TEXT
text: "Z"
font: "druid_text_regular"
id: "text_z"
parent: "field_z"
inherit_alpha: true
outline_alpha: 0.0
shadow_alpha: 0.0
}
nodes {
position {
x: 40.0
}
type: TYPE_TEMPLATE
id: "rich_input_z"
parent: "field_z"
inherit_alpha: true
template: "/druid/custom/rich_input/rich_input.gui"
}
nodes {
size {
x: 50.0
y: 40.0
}
type: TYPE_BOX
id: "rich_input_z/root"
parent: "rich_input_z"
overridden_fields: 4
template_node_child: true
}
nodes {
size {
x: 50.0
y: 40.0
}
type: TYPE_BOX
id: "rich_input_z/button"
parent: "rich_input_z/root"
overridden_fields: 4
template_node_child: true
}
nodes {
size {
x: 70.0
y: 50.0
}
type: TYPE_TEXT
id: "rich_input_z/placeholder_text"
parent: "rich_input_z/root"
overridden_fields: 4
overridden_fields: 8
template_node_child: true
}
nodes {
size {
x: 70.0
y: 50.0
}
type: TYPE_TEXT
text: "20.0"
id: "rich_input_z/input_text"
parent: "rich_input_z/root"
overridden_fields: 4
overridden_fields: 8
template_node_child: true
}
nodes {
position {
x: 18.0
}
type: TYPE_BOX
id: "rich_input_z/cursor_node"
parent: "rich_input_z/root"
overridden_fields: 1
template_node_child: true
}
nodes {
type: TYPE_TEXT
id: "rich_input_z/cursor_text"
parent: "rich_input_z/cursor_node"
template_node_child: true
}
nodes {
position {
x: 40.0
y: -20.0
}
size {
x: 50.0
y: 4.0
}
color {
x: 0.894
y: 0.506
z: 0.333
}
type: TYPE_BOX
texture: "druid/pixel"
id: "selected_z"
pivot: PIVOT_S
adjust_mode: ADJUST_MODE_STRETCH
parent: "field_z"
inherit_alpha: true
}
material: "/builtins/materials/gui.material"
adjust_reference: ADJUST_REFERENCE_PARENT

View File

@ -0,0 +1,75 @@
local event = require("event.event")
---@class widget.property_vector3: druid.widget
---@field root node
---@field container druid.container
---@field text_name druid.text
---@field button druid.button
---@field druid druid_instance
local M = {}
function M:init()
self.root = self:get_node("root")
self.text_name = self.druid:new_text("text_name")
:set_text_adjust("scale_then_trim", 0.3)
self.selected_x = self:get_node("selected_x")
gui.set_alpha(self.selected_x, 0)
self.selected_y = self:get_node("selected_y")
gui.set_alpha(self.selected_y, 0)
self.selected_z = self:get_node("selected_z")
gui.set_alpha(self.selected_z, 0)
self.rich_input_x = self.druid:new_rich_input("rich_input_x")
self.rich_input_y = self.druid:new_rich_input("rich_input_y")
self.rich_input_z = self.druid:new_rich_input("rich_input_z")
self.value = vmath.vector3(0)
self.rich_input_x.input.on_input_unselect:subscribe(function()
self.value.x = tonumber(self.rich_input_x.input:get_text()) or 0
self.on_change:trigger(self.value)
end)
self.rich_input_y.input.on_input_unselect:subscribe(function()
self.value.y = tonumber(self.rich_input_y.input:get_text()) or 0
self.on_change:trigger(self.value)
end)
self.rich_input_z.input.on_input_unselect:subscribe(function()
self.value.z = tonumber(self.rich_input_z.input:get_text()) or 0
self.on_change:trigger(self.value)
end)
self.container = self.druid:new_container(self.root)
self.container:add_container("text_name")
self.container:add_container("E_Anchor")
self.on_change = event.create()
end
---@param text string
---@return widget.property_vector3
function M:set_text_property(text)
self.text_name:set_text(text)
return self
end
---@param x number
---@param y number
---@param z number
---@return widget.property_vector3
function M:set_value(x, y, z)
self.rich_input_x:set_text(tostring(x))
self.rich_input_y:set_text(tostring(y))
self.rich_input_z:set_text(tostring(z))
return self
end
return M

View File

@ -490,5 +490,213 @@ nodes {
parent: "property_left_right_selector/E_Anchor"
template_node_child: true
}
nodes {
position {
y: -300.0
}
type: TYPE_TEMPLATE
id: "property_vector3"
parent: "propeties"
inherit_alpha: true
template: "/druid/widget/properties_panel/properties/property_vector3.gui"
}
nodes {
type: TYPE_BOX
id: "property_vector3/root"
parent: "property_vector3"
template_node_child: true
}
nodes {
type: TYPE_TEXT
id: "property_vector3/text_name"
parent: "property_vector3/root"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "property_vector3/E_Anchor"
parent: "property_vector3/root"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "property_vector3/field_x"
parent: "property_vector3/E_Anchor"
template_node_child: true
}
nodes {
type: TYPE_TEXT
id: "property_vector3/text_x"
parent: "property_vector3/field_x"
template_node_child: true
}
nodes {
type: TYPE_TEMPLATE
id: "property_vector3/rich_input_x"
parent: "property_vector3/field_x"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "property_vector3/rich_input_x/root"
parent: "property_vector3/rich_input_x"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "property_vector3/rich_input_x/button"
parent: "property_vector3/rich_input_x/root"
template_node_child: true
}
nodes {
type: TYPE_TEXT
id: "property_vector3/rich_input_x/placeholder_text"
parent: "property_vector3/rich_input_x/root"
template_node_child: true
}
nodes {
type: TYPE_TEXT
id: "property_vector3/rich_input_x/input_text"
parent: "property_vector3/rich_input_x/root"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "property_vector3/rich_input_x/cursor_node"
parent: "property_vector3/rich_input_x/root"
template_node_child: true
}
nodes {
type: TYPE_TEXT
id: "property_vector3/rich_input_x/cursor_text"
parent: "property_vector3/rich_input_x/cursor_node"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "property_vector3/selected_x"
parent: "property_vector3/field_x"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "property_vector3/field_y"
parent: "property_vector3/E_Anchor"
template_node_child: true
}
nodes {
type: TYPE_TEXT
id: "property_vector3/text_y"
parent: "property_vector3/field_y"
template_node_child: true
}
nodes {
type: TYPE_TEMPLATE
id: "property_vector3/rich_input_y"
parent: "property_vector3/field_y"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "property_vector3/rich_input_y/root"
parent: "property_vector3/rich_input_y"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "property_vector3/rich_input_y/button"
parent: "property_vector3/rich_input_y/root"
template_node_child: true
}
nodes {
type: TYPE_TEXT
id: "property_vector3/rich_input_y/placeholder_text"
parent: "property_vector3/rich_input_y/root"
template_node_child: true
}
nodes {
type: TYPE_TEXT
id: "property_vector3/rich_input_y/input_text"
parent: "property_vector3/rich_input_y/root"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "property_vector3/rich_input_y/cursor_node"
parent: "property_vector3/rich_input_y/root"
template_node_child: true
}
nodes {
type: TYPE_TEXT
id: "property_vector3/rich_input_y/cursor_text"
parent: "property_vector3/rich_input_y/cursor_node"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "property_vector3/selected_y"
parent: "property_vector3/field_y"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "property_vector3/field_z"
parent: "property_vector3/E_Anchor"
template_node_child: true
}
nodes {
type: TYPE_TEXT
id: "property_vector3/text_z"
parent: "property_vector3/field_z"
template_node_child: true
}
nodes {
type: TYPE_TEMPLATE
id: "property_vector3/rich_input_z"
parent: "property_vector3/field_z"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "property_vector3/rich_input_z/root"
parent: "property_vector3/rich_input_z"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "property_vector3/rich_input_z/button"
parent: "property_vector3/rich_input_z/root"
template_node_child: true
}
nodes {
type: TYPE_TEXT
id: "property_vector3/rich_input_z/placeholder_text"
parent: "property_vector3/rich_input_z/root"
template_node_child: true
}
nodes {
type: TYPE_TEXT
id: "property_vector3/rich_input_z/input_text"
parent: "property_vector3/rich_input_z/root"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "property_vector3/rich_input_z/cursor_node"
parent: "property_vector3/rich_input_z/root"
template_node_child: true
}
nodes {
type: TYPE_TEXT
id: "property_vector3/rich_input_z/cursor_text"
parent: "property_vector3/rich_input_z/cursor_node"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "property_vector3/selected_z"
parent: "property_vector3/field_z"
template_node_child: true
}
material: "/builtins/materials/gui.material"
adjust_reference: ADJUST_REFERENCE_PARENT

View File

@ -4,6 +4,7 @@ local property_button = require("druid.widget.properties_panel.properties.proper
local property_input = require("druid.widget.properties_panel.properties.property_input")
local property_text = require("druid.widget.properties_panel.properties.property_text")
local property_left_right_selector = require("druid.widget.properties_panel.properties.property_left_right_selector")
local property_vector3 = require("druid.widget.properties_panel.properties.property_vector3")
---@class widget.properties_panel: druid.widget
---@field root node
@ -67,6 +68,9 @@ function M:init()
self.property_left_right_selector_prefab = self:get_node("property_left_right_selector/root")
gui.set_enabled(self.property_left_right_selector_prefab, false)
self.property_vector3_prefab = self:get_node("property_vector3/root")
gui.set_enabled(self.property_vector3_prefab, false)
-- We not using as a part of properties, since it handled in a way to be paginable
self.paginator = self.druid:new_widget(property_left_right_selector, "property_left_right_selector", self.property_left_right_selector_prefab)
self.paginator:set_text("Page")
@ -194,6 +198,12 @@ function M:add_left_right_selector(on_create)
end
---@param on_create fun(vector3: widget.property_vector3)|nil
function M:add_vector3(on_create)
return self:add_inner_widget(property_vector3, "property_vector3", self.property_vector3_prefab, on_create)
end
---@generic T: druid.widget
---@param widget_class T
---@param template string|nil