Update example with new brand one

This commit is contained in:
Insality
2024-10-17 01:24:15 +03:00
parent 2c762716bb
commit 91879509a0
197 changed files with 36779 additions and 7 deletions

View File

@@ -0,0 +1,46 @@
fonts {
name: "text_bold"
font: "/example/assets/fonts/text_bold.font"
}
fonts {
name: "text_regular"
font: "/example/assets/fonts/text_regular.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 {
position {
x: -200.0
}
size {
x: 400.0
y: 100.0
}
color {
x: 0.941
y: 0.984
}
type: TYPE_TEXT
text: "Hello I\'m a Rich Text!"
font: "text_regular"
id: "text"
pivot: PIVOT_W
parent: "root"
inherit_alpha: true
outline_alpha: 0.0
shadow_alpha: 0.0
}
material: "/builtins/materials/gui.material"
adjust_reference: ADJUST_REFERENCE_PARENT

View File

@@ -0,0 +1,18 @@
local component = require("druid.component")
local rich_text = require("druid.custom.rich_text.rich_text")
---@class basic_rich_text: druid.base_component
---@field druid druid_instance
---@field rich_text druid.rich_text
local M = component.create("basic_rich_text")
---@param template string
---@param nodes table<hash, node>
function M:init(template, nodes)
self.druid = self:get_druid(template, nodes)
self.druid:new(rich_text, "text", "Hello, I'm a <font=text_bold><color=E48155>Rich Text</font></color>!")
end
return M

View File

@@ -0,0 +1,167 @@
fonts {
name: "text_bold"
font: "/example/assets/fonts/text_bold.font"
}
fonts {
name: "text_regular"
font: "/example/assets/fonts/text_regular.font"
}
textures {
name: "druid"
texture: "/example/assets/druid.atlas"
}
textures {
name: "druid_logo"
texture: "/example/assets/druid_logo.atlas"
}
nodes {
size {
x: 1000.0
y: 1000.0
}
type: TYPE_BOX
id: "root"
inherit_alpha: true
visible: false
}
nodes {
size {
x: 400.0
y: 1000.0
}
color {
x: 0.173
y: 0.184
z: 0.204
}
type: TYPE_BOX
texture: "druid/ui_circle_64"
id: "background"
parent: "root"
inherit_alpha: true
slice9 {
x: 32.0
y: 32.0
z: 32.0
w: 32.0
}
}
nodes {
position {
x: -200.0
y: 400.0
}
size {
x: 400.0
y: 100.0
}
color {
x: 0.941
y: 0.984
}
type: TYPE_TEXT
text: "Rich text"
font: "text_regular"
id: "rich_text_color"
pivot: PIVOT_W
parent: "root"
inherit_alpha: true
outline_alpha: 0.0
shadow_alpha: 0.0
}
nodes {
position {
x: -200.0
y: 200.0
}
size {
x: 400.0
y: 100.0
}
color {
x: 0.941
y: 0.984
}
type: TYPE_TEXT
text: "Rich text"
font: "text_regular"
id: "rich_text_breaks"
pivot: PIVOT_W
line_break: true
parent: "root"
inherit_alpha: true
outline_alpha: 0.0
shadow_alpha: 0.0
}
nodes {
position {
x: 200.0
}
size {
x: 400.0
y: 100.0
}
color {
x: 0.941
y: 0.984
}
type: TYPE_TEXT
text: "Rich text"
font: "text_regular"
id: "rich_text_size"
pivot: PIVOT_SE
line_break: true
parent: "root"
inherit_alpha: true
outline_alpha: 0.0
shadow_alpha: 0.0
}
nodes {
position {
x: -200.0
y: -200.0
}
size {
x: 400.0
y: 100.0
}
color {
x: 0.941
y: 0.984
}
type: TYPE_TEXT
text: "Rich text"
font: "text_regular"
id: "rich_text_font"
pivot: PIVOT_W
line_break: true
parent: "root"
inherit_alpha: true
outline_alpha: 0.0
shadow_alpha: 0.0
}
nodes {
position {
x: -200.0
y: -400.0
}
size {
x: 400.0
y: 100.0
}
color {
x: 0.941
y: 0.984
}
type: TYPE_TEXT
text: "Rich text"
font: "text_regular"
id: "rich_text_image"
pivot: PIVOT_W
parent: "root"
inherit_alpha: true
outline_alpha: 0.0
shadow_alpha: 0.0
}
material: "/builtins/materials/gui.material"
adjust_reference: ADJUST_REFERENCE_PARENT

View File

@@ -0,0 +1,76 @@
local component = require("druid.component")
local rich_text = require("druid.custom.rich_text.rich_text")
local helper = require("druid.helper")
---@class rich_text_tags: druid.base_component
---@field druid druid_instance
---@field rich_text druid.rich_text
local M = component.create("rich_text_tags")
---@param template string
---@param nodes table<hash, node>
function M:init(template, nodes)
self.druid = self:get_druid(template, nodes)
self.rich_text_color = self.druid:new(rich_text, "rich_text_color") --[[@as druid.rich_text]]
self.rich_text_color:set_text("Hello, I'm a <color=E48155>Rich Text</color> and it's <color=8ED59E>nested <color=A1D7F5>color</color> tag</color>")
self.rich_text_font = self.druid:new(rich_text, "rich_text_font") --[[@as druid.rich_text]]
self.rich_text_font:set_text("Hello, I'm a <font=text_bold>Rich Text</font> and this is <font=text_bold><color=8ED59E>bold text</color></font>")
self.rich_text_size = self.druid:new(rich_text, "rich_text_size") --[[@as druid.rich_text]]
self.rich_text_size:set_text("Hello, I'm have <size=1.15><font=text_bold>East Pivot</font></size> and <size=0.85><font=text_bold>different text scale</font></size>")
self.rich_text_breaks = self.druid:new(rich_text, "rich_text_breaks") --[[@as druid.rich_text]]
self.rich_text_breaks:set_text("Hello, I'm Rich Text<br/>With \"<color=E6DF9F>Line Breaks</color>\"\nEnabled in GUI")
self.rich_text_image = self.druid:new(rich_text, "rich_text_image") --[[@as druid.rich_text]]
self.rich_text_image:set_text("Hello, I'm<img=druid:icon_cross,32/>Rich Text <img=druid_logo:icon_druid,48/> <color=8ED59E><img=druid_logo:icon_druid,48/></color> <color=F49B9B><img=druid_logo:icon_druid,48/></color>")
self.position = {
[self.rich_text_color] = gui.get_position(self.rich_text_color.root),
[self.rich_text_font] = gui.get_position(self.rich_text_font.root),
[self.rich_text_size] = gui.get_position(self.rich_text_size.root),
[self.rich_text_breaks] = gui.get_position(self.rich_text_breaks.root),
[self.rich_text_image] = gui.get_position(self.rich_text_image.root),
}
-- Adjust positions with pivots
for rich_text, pos in pairs(self.position) do
local size_x = gui.get(rich_text.root, "size.x")
local size_y = gui.get(rich_text.root, "size.y")
local parent_pivot = gui.get_pivot(rich_text.root)
local pivot_offset = helper.get_pivot_offset(parent_pivot)
local offset_x = size_x * pivot_offset.x
local offset_y = size_y * pivot_offset.y
pos.x = pos.x - offset_x
pos.y = pos.y - offset_y
end
end
function M:set_pivot(pivot)
local rich_texts = {
self.rich_text_color,
self.rich_text_font,
self.rich_text_size,
self.rich_text_breaks,
self.rich_text_image,
}
for _, rich_text in ipairs(rich_texts) do
gui.set_pivot(rich_text.root, pivot)
local pos = self.position[rich_text]
local size_x = gui.get(rich_text.root, "size.x")
local size_y = gui.get(rich_text.root, "size.y")
local parent_pivot = gui.get_pivot(rich_text.root)
local pivot_offset = helper.get_pivot_offset(parent_pivot)
local offset_x = size_x * pivot_offset.x
local offset_y = size_y * pivot_offset.y
gui.set_position(rich_text.root, vmath.vector3(pos.x + offset_x, pos.y + offset_y, pos.z))
rich_text:set_text(rich_text:get_text())
end
end
return M

View File

@@ -0,0 +1,92 @@
fonts {
name: "text_bold"
font: "/example/assets/fonts/text_bold.font"
}
fonts {
name: "text_regular"
font: "/example/assets/fonts/text_regular.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 {
position {
y: 200.0
}
size {
x: 400.0
y: 100.0
}
color {
x: 0.941
y: 0.984
}
type: TYPE_TEXT
text: "Rich text"
font: "text_regular"
id: "rich_text_link"
parent: "root"
inherit_alpha: true
outline_alpha: 0.0
shadow_alpha: 0.0
}
nodes {
position {
x: -200.0
}
size {
x: 400.0
y: 100.0
}
color {
x: 0.941
y: 0.984
}
type: TYPE_TEXT
text: "Rich text"
font: "text_regular"
id: "rich_text_characters"
pivot: PIVOT_W
line_break: true
parent: "root"
inherit_alpha: true
outline_alpha: 0.0
shadow_alpha: 0.0
}
nodes {
position {
x: -200.0
y: -200.0
}
size {
x: 400.0
y: 100.0
}
color {
x: 0.941
y: 0.984
}
type: TYPE_TEXT
text: "Rich text"
font: "text_regular"
id: "rich_text_custom"
pivot: PIVOT_W
line_break: true
parent: "root"
inherit_alpha: true
outline_alpha: 0.0
shadow_alpha: 0.0
}
material: "/builtins/materials/gui.material"
adjust_reference: ADJUST_REFERENCE_PARENT

View File

@@ -0,0 +1,67 @@
local component = require("druid.component")
local rich_text = require("druid.custom.rich_text.rich_text")
local helper = require("druid.helper")
local event = require("druid.event")
---@class rich_text_tags_custom: druid.base_component
---@field druid druid_instance
---@field rich_text druid.rich_text
local M = component.create("rich_text_tags_custom")
---@param template string
---@param nodes table<hash, node>
function M:init(template, nodes)
self.druid = self:get_druid(template, nodes)
do -- Init rich text with links example
self.rich_text_link = self.druid:new(rich_text, "rich_text_link") --[[@as druid.rich_text]]
self.rich_text_link:set_text("Hello, I'm a <custom_link><color=A1D7F5>Custom Link</color></custom_link>")
local tagged = self.rich_text_link:tagged("custom_link")
for index = 1, #tagged do
local word = tagged[index]
self.druid:new_button(word.node, function()
self.on_link_click:trigger(word.text)
end)
end
end
self.rich_text_characters = self.druid:new(rich_text, "rich_text_characters") --[[@as druid.rich_text]]
self.rich_text_characters:set_text("Hello, I'm a have a splitted characters")
self.rich_text_custom = self.druid:new(rich_text, "rich_text_custom") --[[@as druid.rich_text]]
self.rich_text_custom:set_text("Hello, I'm have <size=1.25><font=text_bold>South Text Pivot</font></size> to adjust <size=0.75><font=text_bold>different text scale</font></size>")
self.position = {
[self.rich_text_link] = gui.get_position(self.rich_text_link.root),
[self.rich_text_characters] = gui.get_position(self.rich_text_characters.root),
[self.rich_text_custom] = gui.get_position(self.rich_text_custom.root),
}
self.on_link_click = event.create()
end
function M:set_pivot(pivot)
local pivot_offset = helper.get_pivot_offset(pivot)
local rich_texts = {
self.rich_text_link,
self.rich_text_characters,
self.rich_text_custom,
}
for _, rich_text in ipairs(rich_texts) do
gui.set_pivot(rich_text.root, pivot)
local pos = self.position[rich_text]
local size_x = gui.get(rich_text.root, "size.x")
local size_y = gui.get(rich_text.root, "size.y")
local offset_x = size_x * pivot_offset.x
local offset_y = size_y * pivot_offset.y
gui.set_position(rich_text.root, vmath.vector3(pos.x + offset_x, pos.y + offset_y, pos.z))
rich_text:set_text(rich_text:get_text())
end
end
return M