Refonte pour utiliser le systeme de GUI #112

Merged
kazhnuz merged 102 commits from feat/gui into master 2022-01-06 19:15:16 +01:00
2 changed files with 36 additions and 1 deletions
Showing only changes of commit f1b61c9db7 - Show all commits

View file

@ -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

View file

@ -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