feature/simple_ui #18

Merged
PeaAshMeter merged 25 commits from feature/simple_ui into main 2025-11-08 01:32:47 +03:00
Showing only changes of commit 175062a452 - Show all commits

View File

@ -1,4 +1,5 @@
local icons = require("lib.utils.sprite_atlas").load(Tree.assets.files.dev_icons) local icons = require("lib.utils.sprite_atlas").load(Tree.assets.files.dev_icons)
local easing = require "lib.utils.easing"
local AnimationNode = require "lib.animation_node" local AnimationNode = require "lib.animation_node"
--- @class UIElement --- @class UIElement
@ -27,7 +28,7 @@ function uiElement:hitTest(screenX, screenY)
return belongs(lx, self.x, self.x + self.width) and belongs(ly, self.y, self.y + self.height) return belongs(lx, self.x, self.x + self.width) and belongs(ly, self.y, self.y + self.height)
end end
--- @class _SkillButton : UIElement --- @class SkillButton : UIElement
--- @field showNode AnimationNode? --- @field showNode AnimationNode?
--- @field showT number --- @field showT number
--- @field hovered boolean --- @field hovered boolean
@ -43,10 +44,6 @@ function skillButton.new(icon)
}, skillButton) }, skillButton)
end end
local function easeIn(x)
return x * x * x
end
function skillButton:update(dt) function skillButton:update(dt)
local mx, my = love.mouse.getPosition() local mx, my = love.mouse.getPosition()
if self:hitTest(mx, my) then if self:hitTest(mx, my) then
@ -59,9 +56,9 @@ function skillButton:update(dt)
self.hovered = false self.hovered = false
end end
if self.showT < 300 then if self.showT < 1 then
self.showT = self.showT + dt * 1000 self.showT = self.showT + dt * 1 / 0.3 -- в знаменателе продолжительность анимации в секундах
self.y = 10 * easeIn(-1 + self.showT / 300) self.y = 10 * easing.easeInCubic(1 - self.showT)
return return
end end
if self.showNode then if self.showNode then
@ -82,7 +79,7 @@ end
function skillButton:draw() function skillButton:draw()
love.graphics.push() love.graphics.push()
love.graphics.applyTransform(self.transform) love.graphics.applyTransform(self.transform)
local alpha = self.showT / 300 local alpha = easing.easeInSine(self.showT)
if self.selected then if self.selected then
love.graphics.setColor(0.3, 1, 0.3, alpha) love.graphics.setColor(0.3, 1, 0.3, alpha)
@ -98,9 +95,10 @@ function skillButton:draw()
love.graphics.pop() love.graphics.pop()
end end
--- @class _SkillRow : UIElement --- @class SkillRow : UIElement
--- @field characterId Id --- @field characterId Id
--- @field children _SkillButton[] --- @field selected SkillButton?
--- @field children SkillButton[]
local skillRow = setmetatable({}, uiElement) local skillRow = setmetatable({}, uiElement)
skillRow.__index = skillRow skillRow.__index = skillRow
@ -110,12 +108,17 @@ function skillRow.new(characterId)
characterId = characterId, characterId = characterId,
children = {} children = {}
} }
setmetatable(t, skillRow)
local char = Tree.level.characters[characterId] local char = Tree.level.characters[characterId]
char:try(Tree.behaviors.spellcaster, function(behavior) char:try(Tree.behaviors.spellcaster, function(behavior)
for i, spell in ipairs(behavior.spellbook) do for i, spell in ipairs(behavior.spellbook) do
local skb = skillButton.new(spell.tag) local skb = skillButton.new(spell.tag)
skb.onClick = function() skb.onClick = function()
skb.selected = not skb.selected skb.selected = not skb.selected
if t.selected then t.selected.selected = false end
t.selected = skb
if not behavior.cast then if not behavior.cast then
behavior.cast = behavior.spellbook[i] behavior.cast = behavior.spellbook[i]
@ -129,7 +132,7 @@ function skillRow.new(characterId)
end end
end) end)
return setmetatable(t, skillRow) return t
end end
function skillRow:show() function skillRow:show()