diff --git a/lib/character/character.lua b/lib/character/character.lua index 323f222..79e6f83 100644 --- a/lib/character/character.lua +++ b/lib/character/character.lua @@ -12,6 +12,7 @@ local characterId = 1 --- @field info Info --- @field graphics Graphics --- @field logic Logic +--- @field cast boolean @todo тестовое поле, которое отвечает за то, кастуется ли перемещение в данный момент local character = {} character.__index = character diff --git a/lib/level/level.lua b/lib/level/level.lua index 5d743fd..e8c38a8 100644 --- a/lib/level/level.lua +++ b/lib/level/level.lua @@ -57,7 +57,7 @@ function level:draw() self.tileGrid:draw() --- Это отрисовка пути персонажа к мышке - if self.selector.id and path then + if self.selector.id and self.characters[self.selector.id].cast and path then love.graphics.setColor(0.6, 0.75, 0.5) for p in path:values() do love.graphics.circle("fill", p.x + 0.45, p.y + 0.45, 0.1) diff --git a/lib/level/selector.lua b/lib/level/selector.lua index ba7829f..3d66af7 100644 --- a/lib/level/selector.lua +++ b/lib/level/selector.lua @@ -29,12 +29,15 @@ function selector:update(dt) if not characterId and self.id then -- временная обработка события "побежать к точке" local char = Tree.level.characters[self.id] - local charPos = char.logic.mapLogic.position - local path = (require "lib.pathfinder")(charPos, mousePosition) - path:pop_front() - print("Following path: ") - for p in path:values() do print(p) end - char:followPath(path) + if char.cast then + char.cast = false + local charPos = char.logic.mapLogic.position + local path = (require "lib.pathfinder")(charPos, mousePosition) + path:pop_front() + print("Following path: ") + for p in path:values() do print(p) end + char:followPath(path) + end end self:select(characterId) diff --git a/lib/ui/layout.lua b/lib/ui/layout.lua index a54f9a0..874adae 100644 --- a/lib/ui/layout.lua +++ b/lib/ui/layout.lua @@ -2,30 +2,46 @@ local Vec3 = require "lib.utils.vec3" local ui = require "lib.ui.core" ---- @type Rectangle -local ReactiveRectangle = ui.Rectangle { +--- @class SkillButton : Rectangle +--- @field owner Character +local SkillButton = ui.Rectangle { size = Vec3 { 100, 100 }, color = { 1, 0, 0 }, - state = { active = false } + owner = nil } -function ReactiveRectangle:update(dt) - getmetatable(self):update(dt) - +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.state.active = not self.state.active - self.color = self.state.active and { 0, 1, 0 } or { 1, 0, 0 } + self.owner.cast = not self.owner.cast end) end -local Layout = ui.Root { - child = ui.Align { - alignment = "bottom_center", - child = ui.Row { - children = { - ReactiveRectangle - } +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 +return layout diff --git a/main.lua b/main.lua index a4716f8..bc6a5b8 100644 --- a/main.lua +++ b/main.lua @@ -1,8 +1,8 @@ -- CameraLoader = require 'lib/camera' -local Widgets = require "lib.ui.layout" local character = require "lib/character/character" require "lib/tree" +local layout = require "lib.ui.layout" function love.conf(t) t.console = true @@ -28,6 +28,7 @@ local lt = "0" function love.update(dt) local t1 = love.timer.getTime() Tree.controls:poll() + Widgets = layout:build() Widgets:update(dt) -- логика UI-слоя должна отработать раньше всех, потому что нужно перехватить жесты и не пустить их дальше Tree.panning:update(dt) Tree.level:update(dt)