mirror of
https://github.com/Insality/druid.git
synced 2025-09-28 02:22:18 +02:00
Update example with new brand one
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
local panthera = require("panthera.panthera")
|
||||
local component = require("druid.component")
|
||||
local helper = require("druid.helper")
|
||||
local event = require("druid.event")
|
||||
local lang_text = require("druid.extended.lang_text")
|
||||
local rich_text = require("druid.custom.rich_text.rich_text")
|
||||
|
||||
local character_animation_blend = require("example.examples.panthera.animation_blend.character_animation_blend")
|
||||
|
||||
---@class animation_blend: druid.base_component
|
||||
---@field root node
|
||||
---@field druid druid_instance
|
||||
local M = component.create("animation_blend")
|
||||
|
||||
|
||||
---@param template string
|
||||
---@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_size = gui.get_size(self.root)
|
||||
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_vertical = panthera.create_gui(character_animation_blend, self:get_template(), nodes)
|
||||
self.animation_horizontal = panthera.create_gui(character_animation_blend, self:get_template(), nodes)
|
||||
|
||||
panthera.play(self.animation_idle, "idle", {
|
||||
is_loop = true,
|
||||
})
|
||||
|
||||
self:setup_rich_text()
|
||||
self.on_update = event()
|
||||
end
|
||||
|
||||
|
||||
---@param action_id hash
|
||||
---@param action action
|
||||
function M:on_input(action_id, action)
|
||||
if action_id == nil and gui.pick_node(self.root, action.x, action.y) then
|
||||
local root_screen_pos = gui.get_screen_position(self.root)
|
||||
local gui_scale = helper.get_gui_scale()
|
||||
|
||||
local dx = (action.screen_x - root_screen_pos.x) / gui_scale -- -root_size.x / 2 .. root_size.x / 2
|
||||
local animation_progress_x = (dx + self.root_size.x / 2) / self.root_size.x -- 0 .. 1
|
||||
panthera.set_time(self.animation_horizontal, "horizontal", animation_progress_x)
|
||||
|
||||
local dy = (action.screen_y - root_screen_pos.y) / gui_scale -- -root_size.y / 2 .. root_size.y / 2
|
||||
local animation_progress_y = (dy + self.root_size.y / 2) / self.root_size.y -- 0 .. 1
|
||||
panthera.set_time(self.animation_vertical, "vertical", animation_progress_y)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function M:update()
|
||||
self.on_update:trigger()
|
||||
end
|
||||
|
||||
|
||||
function M:setup_rich_text()
|
||||
self.rich_text = self.druid:new(rich_text, "rich_text_kenney", "Character assets by <color=865BD9><link>Kenney</link></color>")
|
||||
|
||||
local tagged = self.rich_text:tagged("link")
|
||||
for index = 1, #tagged do
|
||||
---@type druid.rich_text.word
|
||||
local word = tagged[index]
|
||||
self.druid:new_button(word.node, function()
|
||||
sys.open_url("https://kenney.nl/")
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return M
|
Reference in New Issue
Block a user