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.owner:try(Tree.behaviors.spellcaster, function(spellcaster) self.color = spellcaster.state == "casting" and { 0, 1, 0 } or { 1, 0, 0 } self:onTap(function() if not spellcaster.cast then spellcaster.cast = spellcaster.spellbook [self.spellId] spellcaster.state = "casting" else spellcaster.state = "idle" spellcaster.cast = nil end end) 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 = { ui.Padding { padding = { left = 4, right = 4 }, child = setmetatable({ owner = Tree.level.characters[id], spellId = 1 }, { __index = SkillButton }) }, ui.Padding { padding = { left = 4, right = 4 }, child = setmetatable({ owner = Tree.level.characters[id], spellId = 2 }, { __index = SkillButton }) }, ui.Padding { padding = { left = 4, right = 4 }, child = setmetatable({ owner = Tree.level.characters[id], spellId = 3 }, { __index = SkillButton }) }, } } skillRows[id] = r return r end)() } } end return layout