From 4abfe43a50c3b39b9de0dde32e34bfcf822e42f8 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 31 Aug 2019 21:03:17 +0200 Subject: [PATCH] feat(game/gui): prepare adding textbox support --- sonic-radiance.love/assets/gui/dialogbox.lua | 6 ++ sonic-radiance.love/game/modules/gui/init.lua | 60 +++++++++++++++++++ .../scenes/battlesystem/assets.lua | 1 + .../scenes/battlesystem/screens/victory.lua | 16 ++++- 4 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 sonic-radiance.love/assets/gui/dialogbox.lua diff --git a/sonic-radiance.love/assets/gui/dialogbox.lua b/sonic-radiance.love/assets/gui/dialogbox.lua new file mode 100644 index 0000000..de2295e --- /dev/null +++ b/sonic-radiance.love/assets/gui/dialogbox.lua @@ -0,0 +1,6 @@ +return { + metadata = { + height = 8, + width = 8, + } +} diff --git a/sonic-radiance.love/game/modules/gui/init.lua b/sonic-radiance.love/game/modules/gui/init.lua index 27e3cad..a39e0db 100644 --- a/sonic-radiance.love/game/modules/gui/init.lua +++ b/sonic-radiance.love/game/modules/gui/init.lua @@ -52,4 +52,64 @@ function gui.drawBar(x, y, width, height) end end +function gui.newTextBox(filename, width, height) + local baseimage = love.graphics.newImage(filename) + local quad = {} + quad[1] = love.graphics.newQuad(00, 00, 8, 8, 24, 24) + quad[2] = love.graphics.newQuad(00, 08, 8, 8, 24, 24) + quad[3] = love.graphics.newQuad(00, 16, 8, 8, 24, 24) + quad[4] = love.graphics.newQuad(08, 00, 8, 8, 24, 24) + quad[5] = love.graphics.newQuad(08, 08, 8, 8, 24, 24) + quad[6] = love.graphics.newQuad(08, 16, 8, 8, 24, 24) + quad[7] = love.graphics.newQuad(16, 00, 8, 8, 24, 24) + quad[8] = love.graphics.newQuad(16, 08, 8, 8, 24, 24) + quad[9] = love.graphics.newQuad(16, 16, 8, 8, 24, 24) + local canvas = love.graphics.newCanvas(width, height) + + love.graphics.setCanvas( canvas ) + + + for i=1, math.floor(width/8) do + if (i == 1) then + -- first line + for j=1, math.floor(height/8) do + if j == 1 then + love.graphics.draw(baseimage, quad[1], (i-1)*8, (j-1)*8) + elseif j == math.floor(height/8) then + love.graphics.draw(baseimage, quad[3], (i-1)*8, (j-1)*8) + else + love.graphics.draw(baseimage, quad[2], (i-1)*8, (j-1)*8) + end + end + elseif (i == math.floor(width/8)) then + -- last line + for j=1, math.floor(height/8) do + if j == 1 then + love.graphics.draw(baseimage, quad[7], (i-1)*8, (j-1)*8) + elseif j == math.floor(height/8) then + love.graphics.draw(baseimage, quad[9], (i-1)*8, (j-1)*8) + else + love.graphics.draw(baseimage, quad[8], (i-1)*8, (j-1)*8) + end + end + else + -- middle lines + for j=1, math.floor(height/8) do + if j == 1 then + love.graphics.draw(baseimage, quad[4], (i-1)*8, (j-1)*8) + elseif j == math.floor(height/8) then + love.graphics.draw(baseimage, quad[6], (i-1)*8, (j-1)*8) + else + love.graphics.draw(baseimage, quad[5], (i-1)*8, (j-1)*8) + end + end + end + end + + love.graphics.setCanvas( ) + + return canvas +end + + return gui diff --git a/sonic-radiance.love/scenes/battlesystem/assets.lua b/sonic-radiance.love/scenes/battlesystem/assets.lua index 23ac516..244881b 100644 --- a/sonic-radiance.love/scenes/battlesystem/assets.lua +++ b/sonic-radiance.love/scenes/battlesystem/assets.lua @@ -29,6 +29,7 @@ return { }, ["fonts"] = { {"small", "assets/gui/fonts/PixelOperator.ttf", 16}, + {"victory", "assets/gui/fonts/vipnagorgialla.ttf", 12} }, ["imagefonts"] = { {"hudnbrs", "assets/gui/fonts/hudnumbers"}, diff --git a/sonic-radiance.love/scenes/battlesystem/screens/victory.lua b/sonic-radiance.love/scenes/battlesystem/screens/victory.lua index 6c3410b..28a2382 100644 --- a/sonic-radiance.love/scenes/battlesystem/screens/victory.lua +++ b/sonic-radiance.love/scenes/battlesystem/screens/victory.lua @@ -5,6 +5,10 @@ local TweenManager = require "game.modules.tweenmanager" local BATTLECOMPLETE_START = 2 local BATTLECOMPLETE_STOP = 4 +local gui = require "game.modules.gui" + +local tw, th = 280, 64 + function VictoryScreen:new(scene) self.scene = scene self.assets = scene.assets @@ -21,6 +25,11 @@ function VictoryScreen:new(scene) self.tweens:newTween(0, 0.6, {labelOpacity=1}, 'inExpo') self.tweens:newTween(0.9, 0.4, {labelY=32}, 'inExpo') + self.textBox = gui.newTextBox("assets/gui/dialogbox.png", tw, th) + self.tbSize = 0.6 + self.tbOpacity = 0 + + self.tweens:newTween(1.4, 0.4, {tbSize=1, tbOpacity=1}, 'inExpo') end function VictoryScreen:update(dt) @@ -32,11 +41,14 @@ function VictoryScreen:draw() local width, height = core.screen:getDimensions() love.graphics.rectangle("fill", 0, 0, width, height) + love.graphics.setColor(1, 1, 1, self.labelOpacity) - - local w, h = self.assets.images["battlecompleted"]:getDimensions() self.assets.images["battlecompleted"]:draw(width/2, self.labelY, 0, 1, 1, w/2, h/2) + + --love.graphics.setColor(1, 1, 1, self.tbOpacity) + --love.graphics.draw(self.textBox, width/2, height/2 - 32, 0, self.tbSize, self.tbSize, tw/2, th/2) + utils.graphics.resetColor() end