перемещение персонажа по нажатию на кнопку
- я официально в тильте отэкспериментов с ui, щас возьму и напишу лютейшую императивщину
This commit is contained in:
parent
bd6ec87dd0
commit
bab4b006ca
@ -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
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
3
main.lua
3
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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user