From f1b61c9db7f2de45bb79dc546796aadaa7e0867b Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 22 Aug 2021 13:46:33 +0200 Subject: [PATCH] feat: add basic tweening to guiElements --- .../birb/modules/gui/elements/parent.lua | 20 +++++++++++++++++++ sonic-radiance.love/birb/modules/gui/init.lua | 17 +++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/sonic-radiance.love/birb/modules/gui/elements/parent.lua b/sonic-radiance.love/birb/modules/gui/elements/parent.lua index ad6ee1d..7b5f9e1 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/parent.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/parent.lua @@ -1,6 +1,8 @@ local Rect = require "birb.classes.2D.rect" local GuiElement = Rect:extend() +local TweenManager = require "birb.classes.time" + function GuiElement:new(name, x, y, w, h) GuiElement.super.new(self, x, y, w, h) self.name = name @@ -10,6 +12,8 @@ function GuiElement:new(name, x, y, w, h) self.depth = 0 + self.tweens = TweenManager(self) + self:register() end @@ -73,6 +77,7 @@ end -- External update function function GuiElement:updateElement(dt) self:update(dt) + self.tweens:update(dt) end -- Internal update function @@ -80,6 +85,21 @@ function GuiElement:update(dt) -- Cette fonction ne contient rien par défaut end +-- TWEEN FUNCTIONS +-- Handle tweening + +function GuiElement:newTween(start, duration, target, easing) + self.tweens:newTween(start, duration, target, easing) +end + +function GuiElement:newMovement(start, duration, x, y, easing) + self:newTween(start, duration, {x = x, y = y}, easing) +end + +function GuiElement:newSwitch(start, bools) + self:newSwitch(start, bools) +end + -- DRAW FUNCTIONS -- Draw the menu and its content diff --git a/sonic-radiance.love/birb/modules/gui/init.lua b/sonic-radiance.love/birb/modules/gui/init.lua index 06319f0..ebccac2 100644 --- a/sonic-radiance.love/birb/modules/gui/init.lua +++ b/sonic-radiance.love/birb/modules/gui/init.lua @@ -40,13 +40,28 @@ function Gui:reset() end function Gui:update(dt) - for _, element in ipairs(self.elements) do + for _, element in pairs(self.elements) do if (element ~= nil) then element:updateElement(dt) end end end +-- TWEEN FUNCTIONS +-- Handle tweening + +function Gui:newTween(element, start, duration, target, easing) + self.elements[element]:newTween(start, duration, target, easing) +end + +function Gui:newMovement(element, start, duration, x, y, easing) + self.elements[element]:newMovement(start, duration, x, y, easing) +end + +function Gui:newSwitch(element, start, bools) + self.elements[element]:newSwitch(start, bools) +end + -- DRAW FUNCTIONS -- Draw the menu and its content