65 lines
2.0 KiB
Lua
65 lines
2.0 KiB
Lua
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
|