feat: add a prompt system to the RadianceScene

This commit is contained in:
Kazhnuz 2021-09-18 21:27:14 +02:00
parent 4a7ad692cb
commit 205028718a
2 changed files with 58 additions and 0 deletions

View file

@ -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

View file

@ -3,6 +3,7 @@ local RadianceScene = BirbScene:extend()
local Overlay = require "game.modules.gui.overlay" local Overlay = require "game.modules.gui.overlay"
local MessageQueue = require "game.modules.messagequeue" local MessageQueue = require "game.modules.messagequeue"
local ActionPrompt = require "game.modules.gui.actionPrompt"
function RadianceScene:new(haveBorder, showVersion) function RadianceScene:new(haveBorder, showVersion)
RadianceScene.super.new(self) RadianceScene.super.new(self)
@ -18,6 +19,7 @@ function RadianceScene:new(haveBorder, showVersion)
Overlay(haveBorder, showVersion) Overlay(haveBorder, showVersion)
MessageQueue(self) MessageQueue(self)
ActionPrompt()
end end
function RadianceScene:hideOverlay() function RadianceScene:hideOverlay()
@ -28,6 +30,10 @@ function RadianceScene:showMessage(message)
self.gui.elements["messageQueue"]:addMessage(message) self.gui.elements["messageQueue"]:addMessage(message)
end end
function RadianceScene:setPrompt(message)
self.gui.elements["actionPrompt"]:setText(message)
end
function RadianceScene:showOverlay(darken) function RadianceScene:showOverlay(darken)
self.gui:showScreen("overlay") self.gui:showScreen("overlay")
if (darken) then if (darken) then