Refonte pour utiliser le systeme de GUI #112
2 changed files with 110 additions and 1 deletions
96
sonic-radiance.love/game/modules/gui/overlay.lua
Normal file
96
sonic-radiance.love/game/modules/gui/overlay.lua
Normal file
|
@ -0,0 +1,96 @@
|
||||||
|
local GuiScreen = require "birb.modules.gui.screen"
|
||||||
|
local TextureElement = require "birb.modules.gui.elements.drawable"
|
||||||
|
local ColorElement = require "birb.modules.gui.elements.color"
|
||||||
|
local TextElement = require "birb.modules.gui.elements.text"
|
||||||
|
|
||||||
|
local OverlayScreen = GuiScreen:extend()
|
||||||
|
|
||||||
|
local gui = require "game.modules.gui"
|
||||||
|
local either = utils.math.either
|
||||||
|
|
||||||
|
local OVERLAY_OPACITY = 0.5
|
||||||
|
local wasActive = false
|
||||||
|
local hadVersion = false
|
||||||
|
|
||||||
|
local animateAppear = {
|
||||||
|
{"upBorder", "movement", 0.0, 0.5, 0, 30, "inOutQuart"},
|
||||||
|
{"downBorder", "movement", 0.0, 0.5, 424, 210, "inOutQuart"}
|
||||||
|
}
|
||||||
|
|
||||||
|
local animateDisappear = {
|
||||||
|
{"upBorder", "movement", 0.0, 0.5, 0, 0, "inOutQuart"},
|
||||||
|
{"downBorder", "movement", 0.0, 0.5, 424, 240, "inOutQuart"},
|
||||||
|
{"version", "movement", 0.0, 0.5, 380, 250, "inOutQuart"},
|
||||||
|
{"overlayDarken", "tween", 0.0, 0.4, {opacity = 0}, "outExpo"}
|
||||||
|
}
|
||||||
|
|
||||||
|
local showBackground = {
|
||||||
|
{"overlayDarken", "tween", 0.0, 0.4, {opacity = OVERLAY_OPACITY}, "inExpo"}
|
||||||
|
}
|
||||||
|
|
||||||
|
local hideBackground = {
|
||||||
|
{"overlayDarken", "tween", 0.0, 0.4, {opacity = 0}, "outExpo"}
|
||||||
|
}
|
||||||
|
|
||||||
|
local showVersion = {
|
||||||
|
{"version", "movement", 0.0, 0.5, 380, 220, "inOutQuart"},
|
||||||
|
}
|
||||||
|
|
||||||
|
local hideVersion = {
|
||||||
|
{"version", "movement", 0.0, 0.5, 380, 250, "inOutQuart"},
|
||||||
|
}
|
||||||
|
|
||||||
|
function OverlayScreen:new(active, doShowVersion)
|
||||||
|
self.borders = gui.newBorder(424, 30, 8)
|
||||||
|
self.doShowVersion = doShowVersion
|
||||||
|
|
||||||
|
OverlayScreen.super.new(self, "overlay")
|
||||||
|
|
||||||
|
local transformStuff = false
|
||||||
|
if (active == wasActive) then
|
||||||
|
self.isVisible = active
|
||||||
|
else
|
||||||
|
transformStuff = true
|
||||||
|
end
|
||||||
|
|
||||||
|
self:addTransform("show", animateAppear)
|
||||||
|
self:addTransform("hide", animateDisappear)
|
||||||
|
self:addTransform("showBackground", showBackground)
|
||||||
|
self:addTransform("hideBackground", hideBackground)
|
||||||
|
self:addTransform("showVersion", showVersion)
|
||||||
|
self:addTransform("hideVersion", hideVersion)
|
||||||
|
|
||||||
|
if (transformStuff) then
|
||||||
|
if (active) then
|
||||||
|
self:show()
|
||||||
|
else
|
||||||
|
self:hide()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if (active) then
|
||||||
|
if (self.doShowVersion) then
|
||||||
|
self:playTransform("showVersion")
|
||||||
|
else
|
||||||
|
self:playTransform("hideVersion")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function OverlayScreen:update(dt)
|
||||||
|
wasActive = self.isVisible
|
||||||
|
hadVersion = self.doShowVersion
|
||||||
|
end
|
||||||
|
|
||||||
|
function OverlayScreen:createElements()
|
||||||
|
local d = either(wasActive, 30, 0)
|
||||||
|
local v = either(hadVersion, 30, 0)
|
||||||
|
return {
|
||||||
|
{TextureElement("upBorder", self.borders, 0, d, 0, 1, -1, 0, 0, 1, -1), 0},
|
||||||
|
{TextureElement("downBorder", self.borders, 424, 240 - d, 0, -1, 1, 0, 0, 1, -1), 0},
|
||||||
|
{ColorElement("overlayDarken", 0, 0, 0, 0), 0},
|
||||||
|
{TextElement("version", "small", "v" .. game.version, 380, 250 - v, "left", -1), 0}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
return OverlayScreen
|
|
@ -1,13 +1,26 @@
|
||||||
local BirbScene = require "birb.modules.scenes"
|
local BirbScene = require "birb.modules.scenes"
|
||||||
local RadianceScene = BirbScene:extend()
|
local RadianceScene = BirbScene:extend()
|
||||||
|
|
||||||
function RadianceScene:new()
|
local Overlay = require "game.modules.gui.overlay"
|
||||||
|
|
||||||
|
function RadianceScene:new(haveBorder, showVersion)
|
||||||
RadianceScene.super.new(self)
|
RadianceScene.super.new(self)
|
||||||
|
|
||||||
-- Importation Global des assets
|
-- Importation Global des assets
|
||||||
self.assets:batchImport("assets.commons")
|
self.assets:batchImport("assets.commons")
|
||||||
self.assets.fonts["small"]:setLineHeight(16/18)
|
self.assets.fonts["small"]:setLineHeight(16/18)
|
||||||
self.assets.fonts["small"]:setFilter("shadow")
|
self.assets.fonts["small"]:setFilter("shadow")
|
||||||
|
|
||||||
|
Overlay(haveBorder, showVersion)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function RadianceScene:hideOverlay()
|
||||||
|
self.gui:hideScreen("overlay")
|
||||||
|
end
|
||||||
|
|
||||||
|
function RadianceScene:showOverlay()
|
||||||
|
self.gui:showScreen("overlay")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
return RadianceScene
|
return RadianceScene
|
Loading…
Reference in a new issue