PeaAshMeter bab4b006ca перемещение персонажа по нажатию на кнопку
- я официально в тильте отэкспериментов с ui, щас возьму и напишу лютейшую императивщину
2025-09-04 02:01:25 +03:00

48 lines
1.5 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

local Vec3 = require "lib.utils.vec3"
local ui = require "lib.ui.core"
--- @class SkillButton : Rectangle
--- @field owner Character
local SkillButton = ui.Rectangle {
size = Vec3 { 100, 100 },
color = { 1, 0, 0 },
owner = nil
}
function SkillButton:update(dt)
ui.Rectangle.update(self, dt)
self.color = self.owner.cast and { 0, 1, 0 } or { 1, 0, 0 }
self:onTap(function()
self.owner.cast = not self.owner.cast
end)
end
local skillRows = {}
local layout = {}
function layout:build()
return ui.Root {
child = ui.Align {
alignment = "bottom_center",
child =
--- для каждого персонажа строим свой ряд скиллов, сохраняем его на потом и возвращаем
--- если персонаж не выделен, не возвращаем ничего
(function()
local id = Tree.level.selector.id
if not id then return nil end
if skillRows[id] then return skillRows[id] end
local r =
ui.Row {
children = {
setmetatable({ owner = Tree.level.characters[id] }, { __index = SkillButton })
}
}
skillRows[id] = r
return r
end)()
}
}
end
return layout