Improve skill button animation timing and selection logic
This commit is contained in:
parent
a5c9ca93f6
commit
175062a452
@ -1,4 +1,5 @@
|
||||
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"
|
||||
|
||||
--- @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)
|
||||
end
|
||||
|
||||
--- @class _SkillButton : UIElement
|
||||
--- @class SkillButton : UIElement
|
||||
--- @field showNode AnimationNode?
|
||||
--- @field showT number
|
||||
--- @field hovered boolean
|
||||
@ -43,10 +44,6 @@ function skillButton.new(icon)
|
||||
}, skillButton)
|
||||
end
|
||||
|
||||
local function easeIn(x)
|
||||
return x * x * x
|
||||
end
|
||||
|
||||
function skillButton:update(dt)
|
||||
local mx, my = love.mouse.getPosition()
|
||||
if self:hitTest(mx, my) then
|
||||
@ -59,9 +56,9 @@ function skillButton:update(dt)
|
||||
self.hovered = false
|
||||
end
|
||||
|
||||
if self.showT < 300 then
|
||||
self.showT = self.showT + dt * 1000
|
||||
self.y = 10 * easeIn(-1 + self.showT / 300)
|
||||
if self.showT < 1 then
|
||||
self.showT = self.showT + dt * 1 / 0.3 -- в знаменателе продолжительность анимации в секундах
|
||||
self.y = 10 * easing.easeInCubic(1 - self.showT)
|
||||
return
|
||||
end
|
||||
if self.showNode then
|
||||
@ -82,7 +79,7 @@ end
|
||||
function skillButton:draw()
|
||||
love.graphics.push()
|
||||
love.graphics.applyTransform(self.transform)
|
||||
local alpha = self.showT / 300
|
||||
local alpha = easing.easeInSine(self.showT)
|
||||
|
||||
if self.selected then
|
||||
love.graphics.setColor(0.3, 1, 0.3, alpha)
|
||||
@ -98,9 +95,10 @@ function skillButton:draw()
|
||||
love.graphics.pop()
|
||||
end
|
||||
|
||||
--- @class _SkillRow : UIElement
|
||||
--- @class SkillRow : UIElement
|
||||
--- @field characterId Id
|
||||
--- @field children _SkillButton[]
|
||||
--- @field selected SkillButton?
|
||||
--- @field children SkillButton[]
|
||||
local skillRow = setmetatable({}, uiElement)
|
||||
skillRow.__index = skillRow
|
||||
|
||||
@ -110,12 +108,17 @@ function skillRow.new(characterId)
|
||||
characterId = characterId,
|
||||
children = {}
|
||||
}
|
||||
|
||||
setmetatable(t, skillRow)
|
||||
|
||||
local char = Tree.level.characters[characterId]
|
||||
char:try(Tree.behaviors.spellcaster, function(behavior)
|
||||
for i, spell in ipairs(behavior.spellbook) do
|
||||
local skb = skillButton.new(spell.tag)
|
||||
skb.onClick = function()
|
||||
skb.selected = not skb.selected
|
||||
if t.selected then t.selected.selected = false end
|
||||
t.selected = skb
|
||||
|
||||
if not behavior.cast then
|
||||
behavior.cast = behavior.spellbook[i]
|
||||
@ -129,7 +132,7 @@ function skillRow.new(characterId)
|
||||
end
|
||||
end)
|
||||
|
||||
return setmetatable(t, skillRow)
|
||||
return t
|
||||
end
|
||||
|
||||
function skillRow:show()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user