From 205028718a0e86d84efc6e7298f927fcc5fa9875 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 18 Sep 2021 21:27:14 +0200 Subject: [PATCH] feat: add a prompt system to the RadianceScene --- .../game/modules/gui/actionPrompt.lua | 52 +++++++++++++++++++ sonic-radiance.love/game/scenes/init.lua | 6 +++ 2 files changed, 58 insertions(+) create mode 100644 sonic-radiance.love/game/modules/gui/actionPrompt.lua diff --git a/sonic-radiance.love/game/modules/gui/actionPrompt.lua b/sonic-radiance.love/game/modules/gui/actionPrompt.lua new file mode 100644 index 0000000..da354e9 --- /dev/null +++ b/sonic-radiance.love/game/modules/gui/actionPrompt.lua @@ -0,0 +1,52 @@ +local CanvasElement = require "birb.modules.gui.elements.parent" +local ActionPrompt = CanvasElement:extend() + +function ActionPrompt:new() + self.text = "" + ActionPrompt.super.new(self, "actionPrompt", 0, 0, 424, 240) + self.depth = -2 + self.opacity = 0 + self.isShown = false +end + +function ActionPrompt:setText(text) + if (utils.string.isEmpty(text)) then + self:hide() + else + self.text = text + self:show() + end +end + +function ActionPrompt:hide() + if (self.isShown) then + self.tweens.tweens = {} + self:newTween(0.0, 0.6, {opacity = 0}, "outExpo") + end + self.isShown = false +end + +function ActionPrompt:show() + if (not self.isShown) then + self.tweens.tweens = {} + self:newTween(0.0, 0.6, {opacity = 1}, "outExpo") + end + self.isShown = true +end + +function ActionPrompt:draw() + if (not utils.string.isEmpty(self.text)) then + local w = self.assets.fonts["small"]:getWidth(self.text) + 16 + love.graphics.setColor(0,0,0,0.5 * self.opacity) + local x, y = 424 - w/2 - 4, 240 - 20 + love.graphics.rectangle("fill", x - w/2, y + 1, w, 15, 8, 8) + love.graphics.setColor(1, 1, 1, self.opacity) + self.assets.fonts["small"]:setColor(1, 1, 1, self.opacity) + self.assets.fonts["small"]:draw(self.text, x, y, -1, "center") + self.assets.fonts["small"]:setColor(1, 1, 1, 1) + utils.graphics.resetColor() + end +end + + +return ActionPrompt \ 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 f56775c..3a6fb28 100644 --- a/sonic-radiance.love/game/scenes/init.lua +++ b/sonic-radiance.love/game/scenes/init.lua @@ -3,6 +3,7 @@ local RadianceScene = BirbScene:extend() local Overlay = require "game.modules.gui.overlay" local MessageQueue = require "game.modules.messagequeue" +local ActionPrompt = require "game.modules.gui.actionPrompt" function RadianceScene:new(haveBorder, showVersion) RadianceScene.super.new(self) @@ -18,6 +19,7 @@ function RadianceScene:new(haveBorder, showVersion) Overlay(haveBorder, showVersion) MessageQueue(self) + ActionPrompt() end function RadianceScene:hideOverlay() @@ -28,6 +30,10 @@ function RadianceScene:showMessage(message) self.gui.elements["messageQueue"]:addMessage(message) end +function RadianceScene:setPrompt(message) + self.gui.elements["actionPrompt"]:setText(message) +end + function RadianceScene:showOverlay(darken) self.gui:showScreen("overlay") if (darken) then