перемещение персонажа по нажатию на кнопку
- я официально в тильте отэкспериментов с ui, щас возьму и напишу лютейшую императивщину
This commit is contained in:
parent
bd6ec87dd0
commit
bab4b006ca
@ -12,6 +12,7 @@ local characterId = 1
|
|||||||
--- @field info Info
|
--- @field info Info
|
||||||
--- @field graphics Graphics
|
--- @field graphics Graphics
|
||||||
--- @field logic Logic
|
--- @field logic Logic
|
||||||
|
--- @field cast boolean @todo тестовое поле, которое отвечает за то, кастуется ли перемещение в данный момент
|
||||||
local character = {}
|
local character = {}
|
||||||
character.__index = character
|
character.__index = character
|
||||||
|
|
||||||
|
|||||||
@ -57,7 +57,7 @@ function level:draw()
|
|||||||
self.tileGrid: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)
|
love.graphics.setColor(0.6, 0.75, 0.5)
|
||||||
for p in path:values() do
|
for p in path:values() do
|
||||||
love.graphics.circle("fill", p.x + 0.45, p.y + 0.45, 0.1)
|
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 -- временная обработка события "побежать к точке"
|
if not characterId and self.id then -- временная обработка события "побежать к точке"
|
||||||
local char = Tree.level.characters[self.id]
|
local char = Tree.level.characters[self.id]
|
||||||
local charPos = char.logic.mapLogic.position
|
if char.cast then
|
||||||
local path = (require "lib.pathfinder")(charPos, mousePosition)
|
char.cast = false
|
||||||
path:pop_front()
|
local charPos = char.logic.mapLogic.position
|
||||||
print("Following path: ")
|
local path = (require "lib.pathfinder")(charPos, mousePosition)
|
||||||
for p in path:values() do print(p) end
|
path:pop_front()
|
||||||
char:followPath(path)
|
print("Following path: ")
|
||||||
|
for p in path:values() do print(p) end
|
||||||
|
char:followPath(path)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
self:select(characterId)
|
self:select(characterId)
|
||||||
|
|
||||||
|
|||||||
@ -2,30 +2,46 @@ local Vec3 = require "lib.utils.vec3"
|
|||||||
local ui = require "lib.ui.core"
|
local ui = require "lib.ui.core"
|
||||||
|
|
||||||
|
|
||||||
--- @type Rectangle
|
--- @class SkillButton : Rectangle
|
||||||
local ReactiveRectangle = ui.Rectangle {
|
--- @field owner Character
|
||||||
|
local SkillButton = ui.Rectangle {
|
||||||
size = Vec3 { 100, 100 },
|
size = Vec3 { 100, 100 },
|
||||||
color = { 1, 0, 0 },
|
color = { 1, 0, 0 },
|
||||||
state = { active = false }
|
owner = nil
|
||||||
}
|
}
|
||||||
function ReactiveRectangle:update(dt)
|
function SkillButton:update(dt)
|
||||||
getmetatable(self):update(dt)
|
ui.Rectangle.update(self, dt)
|
||||||
|
self.color = self.owner.cast and { 0, 1, 0 } or { 1, 0, 0 }
|
||||||
self:onTap(function()
|
self:onTap(function()
|
||||||
self.state.active = not self.state.active
|
self.owner.cast = not self.owner.cast
|
||||||
self.color = self.state.active and { 0, 1, 0 } or { 1, 0, 0 }
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
local Layout = ui.Root {
|
local skillRows = {}
|
||||||
child = ui.Align {
|
|
||||||
alignment = "bottom_center",
|
local layout = {}
|
||||||
child = ui.Row {
|
function layout:build()
|
||||||
children = {
|
return ui.Root {
|
||||||
ReactiveRectangle
|
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'
|
-- CameraLoader = require 'lib/camera'
|
||||||
|
|
||||||
local Widgets = require "lib.ui.layout"
|
|
||||||
local character = require "lib/character/character"
|
local character = require "lib/character/character"
|
||||||
require "lib/tree"
|
require "lib/tree"
|
||||||
|
local layout = require "lib.ui.layout"
|
||||||
|
|
||||||
function love.conf(t)
|
function love.conf(t)
|
||||||
t.console = true
|
t.console = true
|
||||||
@ -28,6 +28,7 @@ local lt = "0"
|
|||||||
function love.update(dt)
|
function love.update(dt)
|
||||||
local t1 = love.timer.getTime()
|
local t1 = love.timer.getTime()
|
||||||
Tree.controls:poll()
|
Tree.controls:poll()
|
||||||
|
Widgets = layout:build()
|
||||||
Widgets:update(dt) -- логика UI-слоя должна отработать раньше всех, потому что нужно перехватить жесты и не пустить их дальше
|
Widgets:update(dt) -- логика UI-слоя должна отработать раньше всех, потому что нужно перехватить жесты и не пустить их дальше
|
||||||
Tree.panning:update(dt)
|
Tree.panning:update(dt)
|
||||||
Tree.level:update(dt)
|
Tree.level:update(dt)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user