Update examples

This commit is contained in:
Insality 2025-03-27 00:30:37 +02:00
parent 7640e207a4
commit b053b5044b
15 changed files with 125 additions and 146 deletions

View File

@ -1,18 +1,16 @@
local component = require("druid.component")
local helper = require("druid.helper") local helper = require("druid.helper")
local event = require("event.event") local event = require("event.event")
---@class examples.rich_text_tags_custom: druid.component ---@class examples.rich_text_tags_custom: druid.widget
---@field druid druid.instance ---@field rich_text_link druid.rich_text
---@field rich_text druid.rich_text ---@field rich_text_characters druid.rich_text
local M = component.create("rich_text_tags_custom") ---@field rich_text_custom druid.rich_text
---@field position table
---@field on_link_click event
local M = {}
---@param template string function M:init()
---@param nodes table<hash, node>
function M:init(template, nodes)
self.druid = self:get_druid(template, nodes)
do -- Init rich text with links example 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 = 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>") self.rich_text_link:set_text("Hello, I'm a <custom_link><color=A1D7F5>Custom Link</color></custom_link>")

View File

@ -1,17 +1,15 @@
local event = require("event.event") local event = require("event.event")
local component = require("druid.component")
---@class examples.data_list_add_remove_clear: druid.component ---@class examples.data_list_add_remove_clear: druid.widget
---@field druid druid.instance ---@field prefab node
---@field scroll druid.scroll
---@field grid druid.grid
---@field data_list druid.data_list ---@field data_list druid.data_list
local M = component.create("data_list_add_remove_clear") ---@field on_item_click event
local M = {}
---@param template string function M:init()
---@param nodes table<hash, node>
function M:init(template, nodes)
self.druid = self:get_druid(template, nodes)
self.prefab = self:get_node("prefab") self.prefab = self:get_node("prefab")
gui.set_enabled(self.prefab, false) gui.set_enabled(self.prefab, false)

View File

@ -1,16 +1,15 @@
local event = require("event.event") local event = require("event.event")
local component = require("druid.component")
---@class examples.data_list_basic: druid.component ---@class examples.data_list_basic: druid.widget
---@field druid druid.instance ---@field prefab node
local M = component.create("data_list_basic") ---@field scroll druid.scroll
---@field grid druid.grid
---@field data_list druid.data_list
---@field on_item_click event
local M = {}
---@param template string function M:init()
---@param nodes table<hash, node>
function M:init(template, nodes)
self.druid = self:get_druid(template, nodes)
self.prefab = self:get_node("prefab") self.prefab = self:get_node("prefab")
gui.set_enabled(self.prefab, false) gui.set_enabled(self.prefab, false)

View File

@ -1,15 +1,12 @@
local component = require("druid.component") ---@class examples.data_list_horizontal_basic: druid.widget
---@field prefab node
---@class examples.data_list_horizontal_basic: druid.component ---@field scroll druid.scroll
---@field druid druid.instance ---@field grid druid.grid
local M = component.create("data_list_horizontal_basic") ---@field data_list druid.data_list
local M = {}
---@param template string function M:init()
---@param nodes table<hash, node>
function M:init(template, nodes)
self.druid = self:get_druid(template, nodes)
self.prefab = self:get_node("prefab") self.prefab = self:get_node("prefab")
gui.set_enabled(self.prefab, false) gui.set_enabled(self.prefab, false)

View File

@ -1,17 +1,12 @@
local component = require("druid.component") ---@class examples.button_component: druid.widget
---@class examples.button_component: druid.component
---@field root node ---@field root node
---@field druid druid.instance
---@field text druid.text ---@field text druid.text
---@field button druid.button
---@field data any ---@field data any
local M = component.create("button_component") local M = {}
---@param template string function M:init()
---@param nodes table<hash, node>
function M:init(template, nodes)
self.druid = self:get_druid(template, nodes)
self.root = self:get_node("root") self.root = self:get_node("root")
self.button = self.druid:new_button(self.root) self.button = self.druid:new_button(self.root)

View File

@ -1,18 +1,17 @@
local event = require("event.event") local event = require("event.event")
local component = require("druid.component")
local button_component = require("example.examples.data_list.cache_with_component.button_component") local button_component = require("example.examples.data_list.cache_with_component.button_component")
---@class examples.data_list_cache_with_component: druid.component ---@class examples.data_list_cache_with_component: druid.widget
---@field druid druid.instance ---@field prefab node
local M = component.create("data_list_cache_with_component") ---@field scroll druid.scroll
---@field grid druid.grid
---@field data_list druid.data_list
---@field on_item_click event
local M = {}
---@param template string function M:init()
---@param nodes table<hash, node>
function M:init(template, nodes)
self.druid = self:get_druid(template, nodes)
self.prefab = self:get_node("button_component/root") self.prefab = self:get_node("button_component/root")
gui.set_enabled(self.prefab, false) gui.set_enabled(self.prefab, false)
@ -39,7 +38,7 @@ end
function M:create_item_callback(item_data, index) function M:create_item_callback(item_data, index)
local nodes = gui.clone_tree(self.prefab) local nodes = gui.clone_tree(self.prefab)
local instance = self.druid:new(button_component, "button_component", nodes) local instance = self.druid:new_widget(button_component, "button_component", nodes)
gui.set_enabled(instance.root, true) gui.set_enabled(instance.root, true)
return instance.root, instance return instance.root, instance

View File

@ -1,21 +1,29 @@
local component = require("druid.component") ---@class examples.gamepad_tester: druid.widget
---@class examples.gamepad_tester: druid.component
---@field root node ---@field root node
---@field buttons druid.button ---@field button_left druid.button
---@field buttons_system druid.button ---@field button_right druid.button
---@field button_left_bump druid.button ---@field button_up druid.button
---@field button_right_bump druid.button ---@field button_down druid.button
---@field druid druid.instance ---@field button_x druid.button
local M = component.create("gamepad_tester") ---@field button_b druid.button
---@field button_y druid.button
---@field button_a druid.button
---@field button_l1 druid.button
---@field button_r1 druid.button
---@field button_stick_left druid.button
---@field button_stick_right druid.button
---@field button_start druid.button
---@field button_back druid.button
---@field trigger_l2 druid.progress
---@field trigger_r2 druid.progress
---@field stick_left node
---@field stick_right node
local M = {}
local STICK_DISTANCE = 50 local STICK_DISTANCE = 50
---@param template string
---@param nodes table<hash, node>
function M:init(template, nodes)
self.druid = self:get_druid(template, nodes)
function M:init()
self.root = self:get_node("root") self.root = self:get_node("root")
self.button_left = self.druid:new_button("button_left/button"):set_key_trigger("gamepad_lpad_left") self.button_left = self.druid:new_button("button_left/button"):set_key_trigger("gamepad_lpad_left")

View File

@ -1,25 +1,24 @@
local component = require("druid.component")
local on_screen_input = require("example.examples.gamepad.on_screen_control.on_screen_input") local on_screen_input = require("example.examples.gamepad.on_screen_control.on_screen_input")
---@class examples.on_screen_control: druid.component ---@class examples.on_screen_control: druid.widget
---@field druid druid.instance
---@field on_screen_input examples.on_screen_input ---@field on_screen_input examples.on_screen_input
local M = component.create("on_screen_control") ---@field character node
---@field character_position vector3
---@field character_eye_left node
---@field character_eye_right node
local M = {}
local CHARACTER_SPEED = 700 local CHARACTER_SPEED = 700
---@param template string
---@param nodes table<hash, node>
function M:init(template, nodes)
self.druid = self:get_druid(template, nodes)
function M:init()
self.character = self:get_node("character") self.character = self:get_node("character")
self.character_position = gui.get_position(self.character) self.character_position = gui.get_position(self.character)
self.character_eye_left = self:get_node("eye_left") self.character_eye_left = self:get_node("eye_left")
self.character_eye_right = self:get_node("eye_right") self.character_eye_right = self:get_node("eye_right")
self.on_screen_input = self.druid:new(on_screen_input, "on_screen_input") self.on_screen_input = self.druid:new_widget(on_screen_input, "on_screen_input")
self.on_screen_input.on_action:subscribe(self.on_action_button, self) self.on_screen_input.on_action:subscribe(self.on_action_button, self)
self.on_screen_input.on_movement:subscribe(self.on_movement, self) self.on_screen_input.on_movement:subscribe(self.on_movement, self)

View File

@ -1,22 +1,25 @@
local const = require("druid.const") local const = require("druid.const")
local event = require("event.event") local event = require("event.event")
local helper = require("druid.helper") local helper = require("druid.helper")
local component = require("druid.component")
---@class examples.on_screen_input: druid.component ---@class examples.on_screen_input: druid.widget
---@field druid druid.instance ---@field button_action node
---@field on_screen_control node
---@field stick_root node
---@field stick_position vector3
---@field on_action event @() ---@field on_action event @()
---@field on_movement event @(x: number, y: number, dt: number) X/Y values are in range -1..1 ---@field on_movement event @(x: number, y: number, dt: number) X/Y values are in range -1..1
---@field on_movement_stop event @() ---@field on_movement_stop event @()
local M = component.create("on_screen_input") ---@field is_multitouch boolean
---@field _is_stick_drag boolean|number
---@field _prev_x number
---@field _prev_y number
local M = {}
local STICK_DISTANCE = 80 local STICK_DISTANCE = 80
---@param template string
---@param nodes table<hash, node>
function M:init(template, nodes)
self.druid = self:get_druid(template, nodes)
function M:init()
self.button_action = self:get_node("on_screen_button") self.button_action = self:get_node("on_screen_button")
self.on_screen_control = self:get_node("on_screen_stick/root") self.on_screen_control = self:get_node("on_screen_stick/root")

View File

@ -1,11 +1,12 @@
local helper = require("druid.helper") local helper = require("druid.helper")
local component = require("druid.component")
local layout = require("druid.extended.layout") local layout = require("druid.extended.layout")
---@class examples.basic_layout: druid.component ---@class examples.basic_layout: druid.widget
---@field druid druid.instance
---@field root node ---@field root node
local M = component.create("basic_layout") ---@field layout druid.layout
---@field prefab node
---@field nodes table<number, node>
local M = {}
local PIVOTS = { local PIVOTS = {
gui.PIVOT_CENTER, gui.PIVOT_CENTER,
@ -20,11 +21,7 @@ local PIVOTS = {
} }
---@param template string function M:init()
---@param nodes table<hash, node>
function M:init(template, nodes)
self.druid = self:get_druid(template, nodes)
self.root = self:get_node("root") self.root = self:get_node("root")
self.layout = self.druid:new(layout, "layout", "horizontal_wrap") self.layout = self.druid:new(layout, "layout", "horizontal_wrap")

View File

@ -1,28 +1,28 @@
local panthera = require("panthera.panthera") local panthera = require("panthera.panthera")
local component = require("druid.component")
local helper = require("druid.helper") local helper = require("druid.helper")
local event = require("event.event") local event = require("event.event")
local character_animation_blend = require("example.examples.panthera.animation_blend.character_animation_blend") local character_animation_blend = require("example.examples.panthera.animation_blend.character_animation_blend")
---@class examples.animation_blend: druid.component ---@class examples.animation_blend: druid.widget
---@field root node ---@field root node
---@field druid druid.instance ---@field root_size vector3
local M = component.create("animation_blend") ---@field animation_idle panthera.instance
---@field animation_vertical panthera.instance
---@field animation_horizontal panthera.instance
---@field rich_text druid.rich_text
---@field on_update event
local M = {}
---@param template string function M:init()
---@param nodes table<hash, node>
function M:init(template, nodes)
self.druid = self:get_druid(template, nodes)
self.root = self:get_node("root") self.root = self:get_node("root")
self.root_size = gui.get_size(self.root) self.root_size = gui.get_size(self.root)
self.druid:new_lang_text("text_hint", "ui_example_panthera_animation_blend_hint") self.druid:new_lang_text("text_hint", "ui_example_panthera_animation_blend_hint")
self.animation_idle = panthera.create_gui(character_animation_blend, self:get_template(), nodes) self.animation_idle = panthera.create_gui(character_animation_blend, self:get_template(), self:get_nodes())
self.animation_vertical = panthera.create_gui(character_animation_blend, self:get_template(), nodes) self.animation_vertical = panthera.create_gui(character_animation_blend, self:get_template(), self:get_nodes())
self.animation_horizontal = panthera.create_gui(character_animation_blend, self:get_template(), nodes) self.animation_horizontal = panthera.create_gui(character_animation_blend, self:get_template(), self:get_nodes())
panthera.play(self.animation_idle, "idle", { panthera.play(self.animation_idle, "idle", {
is_loop = true, is_loop = true,

View File

@ -1,19 +1,15 @@
local panthera = require("panthera.panthera") local panthera = require("panthera.panthera")
local component = require("druid.component")
local basic_animation_panthera = require("example.examples.panthera.basic_animation.basic_animation_panthera") local basic_animation_panthera = require("example.examples.panthera.basic_animation.basic_animation_panthera")
---@class examples.basic_animation: druid.component ---@class examples.basic_animation: druid.widget
---@field druid druid.instance ---@field animation panthera.instance
local M = component.create("basic_animation") ---@field button druid.button
local M = {}
---@param template string function M:init()
---@param nodes table<hash, node> self.animation = panthera.create_gui(basic_animation_panthera, self:get_template(), self:get_nodes())
function M:init(template, nodes)
self.druid = self:get_druid(template, nodes)
self.animation = panthera.create_gui(basic_animation_panthera, self:get_template(), nodes)
self.button = self.druid:new_button("button/root", function() self.button = self.druid:new_button("button/root", function()
panthera.play(self.animation, "on_click", { panthera.play(self.animation, "on_click", {

View File

@ -1,23 +1,20 @@
local component = require("druid.component")
local panthera = require("panthera.panthera") local panthera = require("panthera.panthera")
local window_animation_panthera = require("example.examples.windows.window_animation_panthera") local window_animation_panthera = require("example.examples.windows.window_animation_panthera")
---@class examples.window_confirmation: druid.component ---@class examples.window_confirmation: druid.widget
---@field druid druid.instance
---@field text_header druid.lang_text ---@field text_header druid.lang_text
---@field text_button_accept druid.lang_text ---@field text_button_accept druid.lang_text
---@field text_button_decline druid.lang_text ---@field text_button_decline druid.lang_text
---@field text_description druid.lang_text ---@field text_description druid.lang_text
---@field button_close druid.button ---@field button_close druid.button
local M = component.create("window_confirmation") ---@field button_accept druid.button
---@field button_decline druid.button
---@field animation panthera.instance
local M = {}
---@param template string function M:init()
---@param nodes table<hash, node>
function M:init(template, nodes)
self.druid = self:get_druid(template, nodes)
self.text_header = self.druid:new_lang_text("text_header", "ui_confirmation") --[[@as druid.lang_text]] self.text_header = self.druid:new_lang_text("text_header", "ui_confirmation") --[[@as druid.lang_text]]
self.text_button_accept = self.druid:new_lang_text("button_accept/text", "ui_accept") --[[@as druid.lang_text]] self.text_button_accept = self.druid:new_lang_text("button_accept/text", "ui_accept") --[[@as druid.lang_text]]
self.text_button_decline = self.druid:new_lang_text("button_decline/text", "ui_decline") --[[@as druid.lang_text]] self.text_button_decline = self.druid:new_lang_text("button_decline/text", "ui_decline") --[[@as druid.lang_text]]
@ -27,7 +24,7 @@ function M:init(template, nodes)
self.button_accept = self.druid:new_button("button_accept/root") self.button_accept = self.druid:new_button("button_accept/root")
self.button_decline = self.druid:new_button("button_decline/root") self.button_decline = self.druid:new_button("button_decline/root")
self.animation = panthera.create_gui(window_animation_panthera, self:get_template(), nodes) self.animation = panthera.create_gui(window_animation_panthera, self:get_template(), self:get_nodes())
panthera.play(self.animation, "open") panthera.play(self.animation, "open")
end end

View File

@ -1,22 +1,18 @@
local component = require("druid.component")
local panthera = require("panthera.panthera") local panthera = require("panthera.panthera")
local window_animation_panthera = require("example.examples.windows.window_animation_panthera") local window_animation_panthera = require("example.examples.windows.window_animation_panthera")
---@class examples.window_info: druid.component ---@class examples.window_info: druid.widget
---@field text_header druid.lang_text ---@field text_header druid.lang_text
---@field text_button_accept druid.lang_text ---@field text_button_accept druid.lang_text
---@field text_description druid.lang_text ---@field text_description druid.lang_text
---@field button_close druid.button ---@field button_close druid.button
---@field druid druid.instance ---@field button_accept druid.button
local M = component.create("window_info") ---@field animation panthera.instance
local M = {}
---@param template string function M:init()
---@param nodes table<hash, node>
function M:init(template, nodes)
self.druid = self:get_druid(template, nodes)
self.text_header = self.druid:new_lang_text("text_header", "ui_information") --[[@as druid.lang_text]] self.text_header = self.druid:new_lang_text("text_header", "ui_information") --[[@as druid.lang_text]]
self.text_button_accept = self.druid:new_lang_text("button_accept/text", "ui_accept") --[[@as druid.lang_text]] self.text_button_accept = self.druid:new_lang_text("button_accept/text", "ui_accept") --[[@as druid.lang_text]]
self.text_description = self.druid:new_lang_text("text") --[[@as druid.lang_text]] self.text_description = self.druid:new_lang_text("text") --[[@as druid.lang_text]]
@ -24,7 +20,7 @@ function M:init(template, nodes)
self.button_close = self.druid:new_button("button_close", self.on_button_close) self.button_close = self.druid:new_button("button_close", self.on_button_close)
self.button_accept = self.druid:new_button("button_accept/root") self.button_accept = self.druid:new_button("button_accept/root")
self.animation = panthera.create_gui(window_animation_panthera, self:get_template(), nodes) self.animation = panthera.create_gui(window_animation_panthera, self:get_template(), self:get_nodes())
panthera.play(self.animation, "open") panthera.play(self.animation, "open")
end end

View File

@ -1,30 +1,27 @@
local lang = require("lang.lang") local lang = require("lang.lang")
local druid = require("druid.druid") local druid = require("druid.druid")
local event = require("event.event") local event = require("event.event")
local component = require("druid.component")
local panthera = require("panthera.panthera") local panthera = require("panthera.panthera")
local window_animation_panthera = require("example.examples.windows.window_animation_panthera") local window_animation_panthera = require("example.examples.windows.window_animation_panthera")
---@class examples.window_language: druid.component ---@class examples.window_language: druid.widget
---@field text_header druid.text ---@field text_header druid.text
---@field button_close druid.button ---@field button_close druid.button
---@field druid druid.instance
---@field lang_buttons table<string, druid.button> ---@field lang_buttons table<string, druid.button>
---@field grid druid.grid ---@field grid druid.grid
---@field on_language_change event ---@field on_language_change event
local M = component.create("window_language") ---@field animation panthera.instance
local M = {}
---Color: #F0FBFF ---Color: #F0FBFF
local DEFAULT_LANGUAGE_COLOR = vmath.vector4(240/255, 251/255, 255/255, 1.0) local DEFAULT_LANGUAGE_COLOR = vmath.vector4(240/255, 251/255, 255/255, 1.0)
---Color: #E6DF9F ---Color: #E6DF9F
local SELECTED_LANGUAGE_COLOR = vmath.vector4(230/255, 223/255, 159/255, 1.0) local SELECTED_LANGUAGE_COLOR = vmath.vector4(230/255, 223/255, 159/255, 1.0)
---@param template string
---@param nodes table<hash, node>
function M:init(template, nodes)
self.druid = self:get_druid(template, nodes)
function M:init()
self.lang_buttons = {} self.lang_buttons = {}
self.created_nodes = {} self.created_nodes = {}
self.prefab = self:get_node("button_prefab") self.prefab = self:get_node("button_prefab")