2021-08-21 12:45:49 +02:00
|
|
|
local GuiScreen = Object:extend()
|
|
|
|
local ElementList = require "birb.modules.gui.mixins.elements"
|
|
|
|
GuiScreen:implement(ElementList)
|
|
|
|
|
2021-08-26 23:23:22 +02:00
|
|
|
local TweenManager = require "birb.classes.time"
|
2021-12-31 14:27:35 +01:00
|
|
|
local ScreenSet = require "birb.modules.gui.screen.screenset"
|
2021-08-26 23:23:22 +02:00
|
|
|
|
2021-08-31 10:56:11 +02:00
|
|
|
local elementDataStruct = require "birb.structures.elementData"
|
|
|
|
|
2021-12-08 11:26:27 +01:00
|
|
|
function GuiScreen:new(name)
|
2021-08-31 23:47:01 +02:00
|
|
|
self:initWrapper()
|
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()
|
2021-12-08 11:26:27 +01:00
|
|
|
self.gui:addScreen(name, self)
|
2021-12-31 15:39:50 +01:00
|
|
|
|
|
|
|
self.defaultFocus = nil
|
2021-08-26 23:23:22 +02:00
|
|
|
end
|
|
|
|
|
2021-08-31 23:47:01 +02:00
|
|
|
function GuiScreen:initWrapper()
|
|
|
|
local scene = core.scenemanager.nextScene or core.scenemanager.currentScene
|
|
|
|
self.scene = scene
|
|
|
|
self.gui = scene.gui
|
2021-12-08 11:26:27 +01:00
|
|
|
-- Présent pour la compatibilité
|
|
|
|
self.controller = self.gui
|
2021-08-31 23:47:01 +02:00
|
|
|
self.assets = scene.assets
|
|
|
|
end
|
|
|
|
|
2021-08-26 23:23:22 +02:00
|
|
|
function GuiScreen:update(dt)
|
|
|
|
self.tweens:update(dt)
|
|
|
|
end
|
|
|
|
|
2021-12-31 15:39:50 +01:00
|
|
|
function GuiScreen:show(focusElement, widgetId, page)
|
|
|
|
self:showSimple(focusElement, widgetId, page)
|
2021-12-31 14:27:35 +01:00
|
|
|
if (self.set ~= nil) then
|
|
|
|
self.set.owner:show()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-12-31 15:39:50 +01:00
|
|
|
function GuiScreen:showSimple(focusElement, widgetId, page)
|
|
|
|
focusElement = focusElement or self.defaultFocus
|
|
|
|
local time = 0
|
2021-08-26 23:23:22 +02:00
|
|
|
if (not self.isVisible) then
|
|
|
|
self.isVisible = true
|
|
|
|
if (self.transforms["show"] ~= nil) then
|
2021-12-31 15:39:50 +01:00
|
|
|
time = self:playTransform("show")
|
2021-08-26 23:23:22 +02:00
|
|
|
end
|
2021-12-31 14:27:35 +01:00
|
|
|
|
|
|
|
if (self.subscreens ~= nil) then
|
|
|
|
self.subscreens:show()
|
|
|
|
end
|
|
|
|
|
|
|
|
if (self.set ~= nil) then
|
|
|
|
self.set:setCurrentScreen(self.name)
|
|
|
|
end
|
2021-12-31 15:39:50 +01:00
|
|
|
|
|
|
|
if (focusElement) then
|
|
|
|
self.tweens:newFunc(time, "focus", function () self.gui:setFocus(focusElement, widgetId, page) end)
|
|
|
|
end
|
2021-08-26 23:23:22 +02:00
|
|
|
end
|
2021-12-31 14:27:35 +01:00
|
|
|
|
2021-08-26 23:23:22 +02:00
|
|
|
end
|
|
|
|
|
2022-01-02 20:17:03 +01:00
|
|
|
function GuiScreen:setDatas(datas)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2021-08-26 23:23:22 +02:00
|
|
|
function GuiScreen:hide()
|
|
|
|
if (self.isVisible) then
|
|
|
|
if (self.transforms["hide"] ~= nil) then
|
|
|
|
local time = self:playTransform("hide")
|
|
|
|
self.tweens:newFunc(time, "hide", function ()
|
|
|
|
self.isVisible = false
|
|
|
|
end)
|
|
|
|
end
|
2021-12-31 14:27:35 +01:00
|
|
|
|
|
|
|
if (self.subscreens ~= nil) then
|
|
|
|
self.subscreens:hideCurrent()
|
|
|
|
end
|
2021-08-26 23:23:22 +02:00
|
|
|
end
|
2021-12-31 14:27:35 +01:00
|
|
|
|
2021-08-26 23:23:22 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function GuiScreen:addTransform(name, transform)
|
|
|
|
self.transforms[name] = transform
|
|
|
|
end
|
|
|
|
|
|
|
|
function GuiScreen:playTransform(name, delay)
|
2021-08-31 23:47:01 +02:00
|
|
|
return self.gui:transform(self.transforms[name], delay)
|
2021-08-21 12:45:49 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function GuiScreen:reset()
|
|
|
|
self:initElements()
|
|
|
|
end
|
|
|
|
|
|
|
|
function GuiScreen:registerElements()
|
|
|
|
local elementList = self:createElements()
|
2021-08-31 10:56:11 +02:00
|
|
|
for _, rawElement in ipairs(elementList) do
|
|
|
|
if (rawElement.is ~= nil) then
|
|
|
|
self:addElement(rawElement.name, rawElement)
|
|
|
|
rawElement.screen = self
|
2021-08-21 12:45:49 +02:00
|
|
|
else
|
2021-08-31 10:56:11 +02:00
|
|
|
local elemData = utils.table.parse(rawElement, elementDataStruct, 3)
|
|
|
|
local element = elemData.element
|
|
|
|
self:addElement(element.name, element)
|
2021-08-31 18:30:28 +02:00
|
|
|
if (elemData.focus == true) then
|
|
|
|
element:getFocus()
|
|
|
|
end
|
2021-08-31 10:56:11 +02:00
|
|
|
if (elemData.delay > 0) then
|
|
|
|
element.isVisible = false
|
|
|
|
element:newSwitch(elemData.delay, {"isVisible"})
|
2021-08-21 12:45:49 +02:00
|
|
|
end
|
2021-08-31 10:56:11 +02:00
|
|
|
if (elemData.depth ~= nil) then
|
|
|
|
element.depth = elemData.depth
|
|
|
|
end
|
|
|
|
if (elemData.keypress ~= nil) then
|
|
|
|
element:setKeyPressAction(elemData.keypress)
|
|
|
|
end
|
|
|
|
element.screen = self
|
2021-08-21 12:45:49 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function GuiScreen:createElements()
|
|
|
|
-- Empty function
|
|
|
|
end
|
|
|
|
|
2021-12-31 14:27:35 +01:00
|
|
|
function GuiScreen:setParentSet(set)
|
|
|
|
self.set = set
|
|
|
|
end
|
|
|
|
|
|
|
|
function GuiScreen:addSubscreen(screen)
|
|
|
|
self:initSubscreen()
|
|
|
|
self.subscreens:add(screen)
|
|
|
|
end
|
|
|
|
|
|
|
|
function GuiScreen:showSubscreen(screenname)
|
|
|
|
if (self.subscreens ~= nil) then
|
|
|
|
self.subscreens:show(screenname)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function GuiScreen:initSubscreen()
|
|
|
|
if (self.subscreens == nil) then
|
|
|
|
self.subscreens = ScreenSet(self)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-08-21 12:45:49 +02:00
|
|
|
return GuiScreen
|