105 lines
No EOL
2.8 KiB
Lua
105 lines
No EOL
2.8 KiB
Lua
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)
|
|
|
|
local TweenManager = require "birb.classes.time"
|
|
|
|
local elementDataStruct = require "birb.structures.elementData"
|
|
|
|
|
|
function GuiScreen:new(name, controller)
|
|
self.controller = controller or self:getGui()
|
|
self.name = name
|
|
self.isVisible = false
|
|
self.transforms = {}
|
|
self.tweens = TweenManager(self)
|
|
|
|
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
|
|
|
|
function GuiScreen:getGui()
|
|
local scene = core.scenemanager.nextScene or core.scenemanager.currentScene
|
|
return scene.gui
|
|
end
|
|
|
|
function GuiScreen:reset()
|
|
self:initElements()
|
|
self:initScreens()
|
|
end
|
|
|
|
function GuiScreen:registerElements()
|
|
local elementList = self:createElements()
|
|
for _, rawElement in ipairs(elementList) do
|
|
if (rawElement.is ~= nil) then
|
|
self:addElement(rawElement.name, rawElement)
|
|
rawElement.screen = self
|
|
else
|
|
local elemData = utils.table.parse(rawElement, elementDataStruct, 3)
|
|
local element = elemData.element
|
|
self:addElement(element.name, element)
|
|
if (elemData.focus == true) then
|
|
element:getFocus()
|
|
end
|
|
if (elemData.delay > 0) then
|
|
element.isVisible = false
|
|
element:newSwitch(elemData.delay, {"isVisible"})
|
|
end
|
|
if (elemData.depth ~= nil) then
|
|
element.depth = elemData.depth
|
|
end
|
|
if (elemData.keypress ~= nil) then
|
|
element:setKeyPressAction(elemData.keypress)
|
|
end
|
|
element.screen = self
|
|
end
|
|
end
|
|
end
|
|
|
|
function GuiScreen:createElements()
|
|
-- Empty function
|
|
end
|
|
|
|
return GuiScreen |