From 5f1a9d20d0e9b34a8bc6365af9f137ee307fb882 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 26 Aug 2021 23:27:21 +0200 Subject: [PATCH] feat: add overlay --- .../game/modules/gui/overlay.lua | 96 +++++++++++++++++++ sonic-radiance.love/game/scenes/init.lua | 15 ++- 2 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 sonic-radiance.love/game/modules/gui/overlay.lua diff --git a/sonic-radiance.love/game/modules/gui/overlay.lua b/sonic-radiance.love/game/modules/gui/overlay.lua new file mode 100644 index 0000000..ae18c4c --- /dev/null +++ b/sonic-radiance.love/game/modules/gui/overlay.lua @@ -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 \ No newline at end of file diff --git a/sonic-radiance.love/game/scenes/init.lua b/sonic-radiance.love/game/scenes/init.lua index 83c1e81..10bf7d6 100644 --- a/sonic-radiance.love/game/scenes/init.lua +++ b/sonic-radiance.love/game/scenes/init.lua @@ -1,13 +1,26 @@ local BirbScene = require "birb.modules.scenes" local RadianceScene = BirbScene:extend() -function RadianceScene:new() +local Overlay = require "game.modules.gui.overlay" + +function RadianceScene:new(haveBorder, showVersion) RadianceScene.super.new(self) -- Importation Global des assets self.assets:batchImport("assets.commons") self.assets.fonts["small"]:setLineHeight(16/18) self.assets.fonts["small"]:setFilter("shadow") + + Overlay(haveBorder, showVersion) end +function RadianceScene:hideOverlay() + self.gui:hideScreen("overlay") +end + +function RadianceScene:showOverlay() + self.gui:showScreen("overlay") +end + + return RadianceScene \ No newline at end of file