minimal end turn button implementation

This commit is contained in:
PeaAshMeter 2025-12-12 05:20:11 +03:00
parent 2012035eb6
commit 586ea68d2b
8 changed files with 88 additions and 23 deletions

View File

@ -38,7 +38,7 @@ local controlMap = {
}
function camera:update(dt)
if self.animationNode and not (self.animationNode.t >= 1) then
if self.animationNode and self.animationNode.state == "running" then
self.animationNode:update(dt) -- тик анимации
self.position = utils.lerp(self.animationBeginPosition, self.animationEndPosition, self.animationNode:getValue())
return
@ -100,7 +100,7 @@ end
--- @param position Vec3
--- @param animationNode AnimationNode
function camera:animateTo(position, animationNode)
if self.animationNode then self.animationNode:finish() end
if self.animationNode and self.animationNode.state ~= "finished" then self.animationNode:finish() end
self.animationNode = animationNode
self.animationEndPosition = position
self.animationBeginPosition = self.position

View File

@ -35,7 +35,6 @@ function level:update(dt)
el:update(dt)
end)
self.camera:update(dt)
self.selector:update(dt)
end

View File

@ -34,11 +34,8 @@ function selector:update(dt)
char:try(Tree.behaviors.spellcaster, function(b)
if not b.cast then
-- тут какая-то страшная дичь, я даже не уверен что оно работает
-- зато я точно уверен, что это надо было писать не так
if not selectedId then self:select(selectedId) end
if selectedId ~= Tree.level.turnOrder.current and Tree.level.turnOrder.isTurnsEnabled then return end
return self:select(selectedId)
if not selectedId then self:select(nil) end
return
end
if b.cast:cast(char, mousePosition) then
self:lock()

View File

@ -30,7 +30,6 @@ end
---
--- Если в очереди на ход больше никого нет, заканчиваем раунд
function turnOrder:next()
Tree.level.selector:select(nil)
self.actedQueue:insert(self.current)
local next = self.pendingQueue:peek()
if not next then return self:endRound() end

View File

@ -4,13 +4,14 @@ local Element = require "lib.simple_ui.element"
local Rect = require "lib.simple_ui.rect"
local SkillRow = require "lib.simple_ui.level.skill_row"
local Bars = require "lib.simple_ui.level.bottom_bars"
local EndTurnButton = require "lib.simple_ui.level.end_turn"
--- @class CharacterPanel : UIElement
--- @field animationNode AnimationNode
--- @field state "show" | "idle" | "hide"
--- @field skillRow SkillRow
--- @field bars BottomBars
--- @field endTurnButton EndTurnButton
local characterPanel = setmetatable({}, Element)
characterPanel.__index = characterPanel
@ -19,6 +20,7 @@ function characterPanel.new(characterId)
t.state = "show"
t.skillRow = SkillRow(characterId)
t.bars = Bars(characterId)
t.endTurnButton = EndTurnButton {}
return setmetatable(t, characterPanel)
end
@ -69,6 +71,14 @@ function characterPanel:update(dt)
height = self.bars.bounds.height + self.skillRow.bounds.height
}
self.endTurnButton.bounds = Rect {
x = self.bounds.x + self.bounds.width + 32,
y = self.bounds.y + 12,
width = 150,
height = self.bounds.height - 24
}
self.endTurnButton:update(dt)
if not characterPanelCanvas then
characterPanelCanvas = love.graphics.newCanvas(self.bounds.width, self.bounds.height)
end
@ -107,6 +117,8 @@ function characterPanel:draw()
love.graphics.setShader(Tree.assets.files.shaders.reveal)
love.graphics.setColor(1, 1, 1, 1)
self.endTurnButton:draw()
love.graphics.push()
love.graphics.translate(self.bounds.x, self.bounds.y)
love.graphics.draw(characterPanelCanvas)

View File

@ -0,0 +1,64 @@
local Element = require "lib.simple_ui.element"
local AnimationNode = require "lib.animation_node"
local easing = require "lib.utils.easing"
--- @class EndTurnButton : UIElement
--- @field hovered boolean
--- @field onClick function?
local endTurnButton = setmetatable({}, Element)
endTurnButton.__index = endTurnButton
function endTurnButton:update(dt)
local mx, my = love.mouse.getPosition()
if self:hitTest(mx, my) then
self.hovered = true
if Tree.controls:isJustPressed("select") then
if self.onClick then self.onClick() end
Tree.controls:consume("select")
end
else
self.hovered = false
end
end
function endTurnButton:draw()
love.graphics.setColor(38 / 255, 50 / 255, 56 / 255)
love.graphics.rectangle("fill", self.bounds.x, self.bounds.y, self.bounds.width, self.bounds.height)
if self.hovered then
love.graphics.setColor(0.1, 0.1, 0.1)
love.graphics.rectangle("fill", self.bounds.x, self.bounds.y, self.bounds.width, self.bounds.height)
end
love.graphics.setColor(0.95, 0.95, 0.95)
local font = love.graphics.newFont(16)
love.graphics.printf("end_turn", font, self.bounds.x,
(self.bounds.y + self.bounds.height / 2) - (font:getHeight() / 2), self.bounds.width, "center")
love.graphics.setLineWidth(2)
self:drawBorder("outer")
love.graphics.setColor(1, 1, 1)
end
function endTurnButton:onClick()
Tree.level.turnOrder:next()
Tree.level.selector:select(nil)
local cid = Tree.level.turnOrder.current
local playing = Tree.level.characters[cid]
if not playing:has(Tree.behaviors.map) then return end
AnimationNode {
function(node)
Tree.level.camera:animateTo(playing:has(Tree.behaviors.map).displayedPosition, node)
end,
duration = 1500,
easing = easing.easeInOutCubic,
onEnd = function() Tree.level.selector:select(cid) end
}:run()
end
return function(values)
return endTurnButton:new(values)
end

View File

@ -1,15 +1,19 @@
local CPanel = require "lib.simple_ui.level.cpanel"
local build
local layout = {}
function layout:update(dt)
if self.characterPanel then self.characterPanel:update(dt) end
local cid = Tree.level.selector:selected()
if cid then
self.characterPanel = CPanel(cid)
self.characterPanel:show()
self.characterPanel:update(dt)
elseif Tree.level.selector:deselected() then
self.characterPanel:hide()
end
if self.characterPanel then self.characterPanel:update(dt) end
end
function layout:draw()

View File

@ -25,21 +25,11 @@ local lt = "0"
function love.update(dt)
local t1 = love.timer.getTime()
Tree.controls:poll()
testLayout:update(dt) -- логика UI-слоя должна отработать раньше всех, потому что нужно перехватить жесты и не пустить их дальше
Tree.level.camera:update(dt) -- сначала логика камеры, потому что на нее завязан UI
testLayout:update(dt) -- потом UI, потому что нужно перехватить жесты и не пустить их дальше
Tree.panning:update(dt)
Tree.level:update(dt)
-- для тестов очереди ходов
-- удалить как только появится ui для людей
if Tree.controls:isJustPressed("endTurnTest") then
Tree.level.turnOrder:next()
print("Now playing:", Tree.level.turnOrder.current)
end
if Tree.controls:isJustPressed("toggleTurns") then
print('toggle turns')
Tree.level.turnOrder:toggleTurns()
end
Tree.controls:cache()
local t2 = love.timer.getTime()