feat(game/gui): prepare adding textbox support

This commit is contained in:
Kazhnuz 2019-08-31 21:03:17 +02:00
parent d097552298
commit 4abfe43a50
4 changed files with 81 additions and 2 deletions

View file

@ -0,0 +1,6 @@
return {
metadata = {
height = 8,
width = 8,
}
}

View file

@ -52,4 +52,64 @@ function gui.drawBar(x, y, width, height)
end end
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 return gui

View file

@ -29,6 +29,7 @@ return {
}, },
["fonts"] = { ["fonts"] = {
{"small", "assets/gui/fonts/PixelOperator.ttf", 16}, {"small", "assets/gui/fonts/PixelOperator.ttf", 16},
{"victory", "assets/gui/fonts/vipnagorgialla.ttf", 12}
}, },
["imagefonts"] = { ["imagefonts"] = {
{"hudnbrs", "assets/gui/fonts/hudnumbers"}, {"hudnbrs", "assets/gui/fonts/hudnumbers"},

View file

@ -5,6 +5,10 @@ local TweenManager = require "game.modules.tweenmanager"
local BATTLECOMPLETE_START = 2 local BATTLECOMPLETE_START = 2
local BATTLECOMPLETE_STOP = 4 local BATTLECOMPLETE_STOP = 4
local gui = require "game.modules.gui"
local tw, th = 280, 64
function VictoryScreen:new(scene) function VictoryScreen:new(scene)
self.scene = scene self.scene = scene
self.assets = scene.assets 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, 0.6, {labelOpacity=1}, 'inExpo')
self.tweens:newTween(0.9, 0.4, {labelY=32}, '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 end
function VictoryScreen:update(dt) function VictoryScreen:update(dt)
@ -32,11 +41,14 @@ function VictoryScreen:draw()
local width, height = core.screen:getDimensions() local width, height = core.screen:getDimensions()
love.graphics.rectangle("fill", 0, 0, width, height) love.graphics.rectangle("fill", 0, 0, width, height)
love.graphics.setColor(1, 1, 1, self.labelOpacity) love.graphics.setColor(1, 1, 1, self.labelOpacity)
local w, h = self.assets.images["battlecompleted"]:getDimensions() local w, h = self.assets.images["battlecompleted"]:getDimensions()
self.assets.images["battlecompleted"]:draw(width/2, self.labelY, 0, 1, 1, w/2, h/2) 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() utils.graphics.resetColor()
end end