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: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() 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