Refonte pour utiliser le systeme de GUI #112
2 changed files with 95 additions and 10 deletions
|
@ -46,48 +46,85 @@ function Gui:update(dt)
|
||||||
element:updateElement(dt)
|
element:updateElement(dt)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
for _, screen in pairs(self.screens) do
|
||||||
|
if (screen ~= nil) then
|
||||||
|
screen:update(dt)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TWEEN FUNCTIONS
|
-- TWEEN FUNCTIONS
|
||||||
-- Handle tweening
|
-- Handle tweening
|
||||||
|
|
||||||
function Gui:transform(data)
|
function Gui:transform(data, delay)
|
||||||
|
delay = delay or 0
|
||||||
|
|
||||||
|
local time = 0
|
||||||
for _, rawTransform in ipairs(data) do
|
for _, rawTransform in ipairs(data) do
|
||||||
self:transformOne(rawTransform)
|
local newTime = self:transformOne(rawTransform, delay)
|
||||||
|
time = math.max(time, newTime)
|
||||||
end
|
end
|
||||||
|
return time
|
||||||
end
|
end
|
||||||
|
|
||||||
function Gui:transformOne(rawTransform)
|
function Gui:playScreenTransform(screenname, name, delay)
|
||||||
|
return self.screens[screenname]:playTransform(name, delay)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Gui:transformOne(rawTransform, delay)
|
||||||
|
delay = delay or 0
|
||||||
|
|
||||||
local struct = TransformDataStruct[rawTransform[2]]
|
local struct = TransformDataStruct[rawTransform[2]]
|
||||||
assert(struct ~= nil, "Structure " .. rawTransform[1] .. " doesn't exists ")
|
assert(struct ~= nil, "Structure " .. rawTransform[1] .. " doesn't exists ")
|
||||||
local transform = utils.table.parse(rawTransform, struct, 0)
|
local transform = utils.table.parse(rawTransform, struct, 0)
|
||||||
|
|
||||||
|
local time = transform.start + delay
|
||||||
|
|
||||||
if transform.type == "tween" then
|
if transform.type == "tween" then
|
||||||
self:newTween(transform.name, transform.start, transform.duration, transform.target, transform.easing)
|
self:newTween(transform.name, time, transform.duration, transform.target, transform.easing)
|
||||||
elseif transform.type == "movement" then
|
elseif transform.type == "movement" then
|
||||||
self:newMovement(transform.name, transform.start, transform.duration, transform.x, transform.y, transform.easing)
|
self:newMovement(transform.name, time, transform.duration, transform.x, transform.y, transform.easing)
|
||||||
elseif transform.type == "switch" then
|
elseif transform.type == "switch" then
|
||||||
self:newSwitch(transform.name, transform.start, transform.bools)
|
self:newSwitch(transform.name, time, transform.bools)
|
||||||
elseif transform.type == "delayFocus" then
|
elseif transform.type == "delayFocus" then
|
||||||
self:delayFocus(transform.name, transform.start)
|
self:delayFocus(transform.name, time)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if (transform.duration ~= nil) then
|
||||||
|
time = time + transform.duration
|
||||||
|
end
|
||||||
|
return time
|
||||||
end
|
end
|
||||||
|
|
||||||
function Gui:newTween(element, start, duration, target, easing)
|
function Gui:newTween(element, start, duration, target, easing)
|
||||||
|
assert(self.elements[element] ~= nil, element .. " does not exists")
|
||||||
self.elements[element]:newTween(start, duration, target, easing)
|
self.elements[element]:newTween(start, duration, target, easing)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Gui:newMovement(element, start, duration, x, y, easing)
|
function Gui:newMovement(element, start, duration, x, y, easing)
|
||||||
|
assert(self.elements[element] ~= nil, element .. " does not exists")
|
||||||
self.elements[element]:newMovement(start, duration, x, y, easing)
|
self.elements[element]:newMovement(start, duration, x, y, easing)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Gui:newSwitch(element, start, bools)
|
function Gui:newSwitch(element, start, bools)
|
||||||
|
assert(self.elements[element] ~= nil, element .. " does not exists")
|
||||||
self.elements[element]:newSwitch(start, bools)
|
self.elements[element]:newSwitch(start, bools)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Gui:delayFocus(element, start)
|
function Gui:delayFocus(element, start)
|
||||||
|
assert(self.elements[element] ~= nil, element .. " does not exists")
|
||||||
self.elements[element]:delayFocus(start)
|
self.elements[element]:delayFocus(start)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Gui:hideScreen(screenname)
|
||||||
|
self.screens[screenname]:hide()
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function Gui:showScreen(screenname)
|
||||||
|
self.screens[screenname]:show()
|
||||||
|
end
|
||||||
|
|
||||||
-- KEYBOARD FUNCTIONS
|
-- KEYBOARD FUNCTIONS
|
||||||
-- Handle keyboard
|
-- Handle keyboard
|
||||||
|
|
||||||
|
|
|
@ -4,15 +4,61 @@ local ScreenList = require "birb.modules.gui.mixins.screens"
|
||||||
GuiScreen:implement(ScreenList)
|
GuiScreen:implement(ScreenList)
|
||||||
GuiScreen:implement(ElementList)
|
GuiScreen:implement(ElementList)
|
||||||
|
|
||||||
function GuiScreen:new(controller, name)
|
local TweenManager = require "birb.classes.time"
|
||||||
self.controller = controller
|
|
||||||
|
function GuiScreen:new(name, controller)
|
||||||
|
self.controller = controller or self:getGui()
|
||||||
self.name = name
|
self.name = name
|
||||||
self.isVisible = false
|
self.isVisible = false
|
||||||
|
self.transforms = {}
|
||||||
|
self.tweens = TweenManager(self)
|
||||||
|
|
||||||
self:reset()
|
self:reset()
|
||||||
|
self:registerElements()
|
||||||
|
self.controller:addScreen(name, self)
|
||||||
|
end
|
||||||
|
|
||||||
|
function GuiScreen:update(dt)
|
||||||
|
self.tweens:update(dt)
|
||||||
|
for _, screen in pairs(self.screens) do
|
||||||
|
if (screen ~= nil) then
|
||||||
|
screen:update(dt)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function GuiScreen:show()
|
||||||
|
if (not self.isVisible) then
|
||||||
|
self.isVisible = true
|
||||||
|
if (self.transforms["show"] ~= nil) then
|
||||||
|
self:playTransform("show")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function GuiScreen:hide()
|
||||||
|
if (self.isVisible) then
|
||||||
|
if (self.transforms["hide"] ~= nil) then
|
||||||
|
local time = self:playTransform("hide")
|
||||||
|
print(time)
|
||||||
|
self.tweens:newFunc(time, "hide", function ()
|
||||||
|
self.isVisible = false
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function GuiScreen:addTransform(name, transform)
|
||||||
|
self.transforms[name] = transform
|
||||||
|
end
|
||||||
|
|
||||||
|
function GuiScreen:playTransform(name, delay)
|
||||||
|
local gui = self:getGui()
|
||||||
|
return gui:transform(self.transforms[name], delay)
|
||||||
end
|
end
|
||||||
|
|
||||||
function GuiScreen:getGui()
|
function GuiScreen:getGui()
|
||||||
local scene = core.scenemanager.currentScene
|
local scene = core.scenemanager.nextScene or core.scenemanager.currentScene
|
||||||
return scene.gui
|
return scene.gui
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -26,11 +72,13 @@ function GuiScreen:registerElements()
|
||||||
for _, element in ipairs(elementList) do
|
for _, element in ipairs(elementList) do
|
||||||
if (element.is ~= nil) then
|
if (element.is ~= nil) then
|
||||||
self:addElement(element.name, element)
|
self:addElement(element.name, element)
|
||||||
|
element.screen = self
|
||||||
else
|
else
|
||||||
self:addElement(element[1].name, element[1])
|
self:addElement(element[1].name, element[1])
|
||||||
if (element[2] == false) then
|
if (element[2] == false) then
|
||||||
element[1].isVisible = false
|
element[1].isVisible = false
|
||||||
end
|
end
|
||||||
|
element[1].screen = self
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue