local Vec3 = require "lib.utils.vec3" local ui = require "lib.ui.core" --- @class SkillButton : Rectangle --- @field owner Character --- @field spellId number local SkillButton = ui.Rectangle { size = Vec3 { 100, 100 }, color = { 1, 0, 0 }, } 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() print(self.owner.spellbook[self.spellId]) self.owner.cast = self.owner.cast and nil or self.owner.spellbook[self.spellId] 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], spellId = 1 }, { __index = SkillButton }) } } skillRows[id] = r return r end)() } } end return layout