2021-08-21 12:45:49 +02:00
|
|
|
local GuiScreen = Object:extend()
|
|
|
|
local ElementList = require "birb.modules.gui.mixins.elements"
|
|
|
|
local ScreenList = require "birb.modules.gui.mixins.screens"
|
|
|
|
GuiScreen:implement(ScreenList)
|
|
|
|
GuiScreen:implement(ElementList)
|
|
|
|
|
2021-08-26 23:23:22 +02:00
|
|
|
local TweenManager = require "birb.classes.time"
|
|
|
|
|
|
|
|
function GuiScreen:new(name, controller)
|
|
|
|
self.controller = controller or self:getGui()
|
2021-08-21 12:45:49 +02:00
|
|
|
self.name = name
|
|
|
|
self.isVisible = false
|
2021-08-26 23:23:22 +02:00
|
|
|
self.transforms = {}
|
|
|
|
self.tweens = TweenManager(self)
|
|
|
|
|
2021-08-21 12:45:49 +02:00
|
|
|
self:reset()
|
2021-08-26 23:23:22 +02:00
|
|
|
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)
|
2021-08-21 12:45:49 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function GuiScreen:getGui()
|
2021-08-26 23:23:22 +02:00
|
|
|
local scene = core.scenemanager.nextScene or core.scenemanager.currentScene
|
2021-08-21 12:45:49 +02:00
|
|
|
return scene.gui
|
|
|
|
end
|
|
|
|
|
|
|
|
function GuiScreen:reset()
|
|
|
|
self:initElements()
|
|
|
|
self:initScreens()
|
|
|
|
end
|
|
|
|
|
|
|
|
function GuiScreen:registerElements()
|
|
|
|
local elementList = self:createElements()
|
|
|
|
for _, element in ipairs(elementList) do
|
|
|
|
if (element.is ~= nil) then
|
|
|
|
self:addElement(element.name, element)
|
2021-08-26 23:23:22 +02:00
|
|
|
element.screen = self
|
2021-08-21 12:45:49 +02:00
|
|
|
else
|
|
|
|
self:addElement(element[1].name, element[1])
|
|
|
|
if (element[2] == false) then
|
|
|
|
element[1].isVisible = false
|
|
|
|
end
|
2021-08-26 23:23:22 +02:00
|
|
|
element[1].screen = self
|
2021-08-21 12:45:49 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function GuiScreen:createElements()
|
|
|
|
-- Empty function
|
|
|
|
end
|
|
|
|
|
|
|
|
return GuiScreen
|