54 lines
1.6 KiB
Lua
54 lines
1.6 KiB
Lua
local Element = require "lib.simple_ui.element"
|
|
local task = require "lib.utils.task"
|
|
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:layout()
|
|
local font = Tree.fonts:getDefaultTheme():getVariant("headline")
|
|
self.text = love.graphics.newText(font, "Завершить ход")
|
|
self.bounds.width = self.text:getWidth() + 32
|
|
self.bounds.height = self.text:getHeight() + 16
|
|
end
|
|
|
|
function endTurnButton:draw()
|
|
love.graphics.setColor(38 / 255, 50 / 255, 56 / 255, 0.9)
|
|
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)
|
|
love.graphics.draw(self.text, self.bounds.x + 16, self.bounds.y + 8)
|
|
|
|
self:drawBorder("outer")
|
|
love.graphics.setColor(1, 1, 1)
|
|
end
|
|
|
|
function endTurnButton:onClick()
|
|
Tree.level.turnOrder:next()
|
|
end
|
|
|
|
return function(values)
|
|
return endTurnButton:new(values)
|
|
end
|