2019-01-28 13:13:17 +01:00
|
|
|
local gui = {}
|
|
|
|
|
2019-08-14 22:47:10 +02:00
|
|
|
local barborder = love.graphics.newImage("assets/gui/barborder.png")
|
|
|
|
|
2019-01-28 13:13:17 +01:00
|
|
|
function gui.newBorder(width, height, middlePosition)
|
|
|
|
local tileset = love.graphics.newImage("assets/gui/borders.png")
|
|
|
|
local tilequad = {}
|
|
|
|
local w, h = tileset:getDimensions()
|
2019-08-15 14:06:20 +02:00
|
|
|
tilequad[1] = love.graphics.newQuad(0, 0, 20, 20, w, h)
|
2019-01-28 13:13:17 +01:00
|
|
|
tilequad[2] = love.graphics.newQuad(20, 0, 20, 20, w, h)
|
|
|
|
tilequad[3] = love.graphics.newQuad(40, 0, 20, 20, w, h)
|
|
|
|
tilequad[4] = love.graphics.newQuad(60, 0, 20, 20, w, h)
|
|
|
|
|
2020-08-02 13:29:41 +02:00
|
|
|
local canvas = love.graphics.newCanvas(width, height)
|
2019-01-28 13:13:17 +01:00
|
|
|
|
2020-08-02 13:29:41 +02:00
|
|
|
love.graphics.setCanvas(canvas)
|
2019-01-28 13:13:17 +01:00
|
|
|
utils.graphics.resetColor()
|
|
|
|
|
|
|
|
local height = math.ceil(height / 20)
|
|
|
|
local width = math.ceil(width / 20)
|
|
|
|
|
|
|
|
for i=1, width do
|
|
|
|
if i < middlePosition then
|
|
|
|
love.graphics.draw(tileset, tilequad[1], (i-1) * 20, 0)
|
|
|
|
elseif (i == middlePosition) then
|
|
|
|
love.graphics.draw(tileset, tilequad[2], (i-1) * 20, 0)
|
|
|
|
else
|
|
|
|
love.graphics.draw(tileset, tilequad[3], (i-1) * 20, 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
if height > 1 then
|
|
|
|
for j = 2, height do
|
|
|
|
love.graphics.draw(tileset, tilequad[4], (i-1) * 20, (j-1) * 20)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
love.graphics.setCanvas( )
|
|
|
|
|
2020-08-02 13:29:41 +02:00
|
|
|
local imagedata = canvas:newImageData()
|
|
|
|
local texture = love.graphics.newImage( imagedata )
|
|
|
|
imagedata:release()
|
|
|
|
canvas:release()
|
|
|
|
|
|
|
|
return texture
|
2019-01-28 13:13:17 +01:00
|
|
|
end
|
|
|
|
|
2020-08-18 23:46:11 +02:00
|
|
|
function gui.newChoiceBack(approximateWidth)
|
|
|
|
local asset = love.graphics.newImage("assets/gui/attacklist.png")
|
|
|
|
local sw, sh = asset:getDimensions()
|
|
|
|
local startAsset = love.graphics.newQuad(0, 0, 21, sh, sw, sh)
|
|
|
|
local midAsset = love.graphics.newQuad(21, 0, 12, sh, sw, sh)
|
|
|
|
local endAsset = love.graphics.newQuad(sw-25, 0, 25, sh, sw, sh)
|
|
|
|
|
|
|
|
local iterations = math.floor((approximateWidth / 12) - 4)
|
|
|
|
local width = (iterations * 12)
|
2020-09-13 16:49:50 +02:00
|
|
|
local height = 16
|
2020-08-18 23:46:11 +02:00
|
|
|
local canvasWidth = width + 21 + 25
|
|
|
|
|
|
|
|
local canvas = love.graphics.newCanvas(canvasWidth, height)
|
|
|
|
|
|
|
|
love.graphics.setCanvas(canvas)
|
|
|
|
|
|
|
|
love.graphics.draw(asset, startAsset, 0, 0)
|
|
|
|
love.graphics.draw(asset, endAsset, 21 + width, 0)
|
|
|
|
|
|
|
|
for i=1, (iterations) do
|
|
|
|
love.graphics.draw(asset, midAsset, 21 + ((i-1)*12), 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
love.graphics.setCanvas( )
|
|
|
|
|
|
|
|
local imagedata = canvas:newImageData()
|
|
|
|
local texture = love.graphics.newImage( imagedata )
|
|
|
|
imagedata:release()
|
|
|
|
canvas:release()
|
|
|
|
|
|
|
|
return texture
|
|
|
|
end
|
|
|
|
|
2019-08-14 22:47:10 +02:00
|
|
|
function gui.drawBar(x, y, width, height)
|
2019-08-15 14:06:20 +02:00
|
|
|
if (width > 0) then
|
|
|
|
local height = height or 7
|
2019-08-15 15:09:48 +02:00
|
|
|
core.screen:setScissor(x, y, width, height)
|
2019-08-15 14:06:20 +02:00
|
|
|
love.graphics.draw(barborder, x, y)
|
|
|
|
local barwidth = math.max(width-14, 0)
|
|
|
|
love.graphics.rectangle("fill", x+7, y, barwidth, height)
|
2019-08-16 22:58:12 +02:00
|
|
|
love.graphics.draw(barborder, x+barwidth+7, y, 0, -1, -1, 7, 7)
|
2019-08-15 15:09:48 +02:00
|
|
|
core.screen:resetScissor( )
|
2019-08-15 14:06:20 +02:00
|
|
|
end
|
2019-08-14 22:47:10 +02:00
|
|
|
end
|
|
|
|
|
2019-08-31 21:03:17 +02:00
|
|
|
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( )
|
|
|
|
|
2020-08-02 13:29:41 +02:00
|
|
|
local imagedata = canvas:newImageData()
|
|
|
|
local texture = love.graphics.newImage( imagedata )
|
|
|
|
imagedata:release()
|
|
|
|
canvas:release()
|
|
|
|
return texture
|
2019-08-31 21:03:17 +02:00
|
|
|
end
|
|
|
|
|
2021-04-05 12:05:51 +02:00
|
|
|
function gui.getEmeraldsTexture(number)
|
|
|
|
local canvas = love.graphics.newCanvas(95, 31)
|
|
|
|
local emeralds = love.graphics.newImage("assets/gui/emeralds.png")
|
|
|
|
love.graphics.setCanvas( canvas )
|
|
|
|
for i = 1, 7, 1 do
|
|
|
|
local emerald
|
|
|
|
local x = (i-1)*12
|
|
|
|
if (i > number) then
|
|
|
|
emerald = love.graphics.newQuad(0,0,23,17,23*8, 17)
|
|
|
|
else
|
|
|
|
emerald = love.graphics.newQuad((i*23),0,23,17,23*8, 17)
|
|
|
|
--emerald = love.graphics.newQuad((i*23),0,23,17,23*7, 17)
|
|
|
|
end
|
|
|
|
|
|
|
|
local isPair = (i%2 == 0)
|
|
|
|
local y = 0
|
|
|
|
if (isPair == true) then
|
|
|
|
y = 14
|
|
|
|
end
|
|
|
|
love.graphics.draw(emeralds, emerald,x,y)
|
|
|
|
emerald:release()
|
|
|
|
end
|
|
|
|
|
|
|
|
love.graphics.setCanvas( )
|
|
|
|
local imagedata = canvas:newImageData()
|
|
|
|
local texture = love.graphics.newImage( imagedata )
|
|
|
|
imagedata:release()
|
|
|
|
canvas:release()
|
|
|
|
return texture
|
|
|
|
end
|
|
|
|
|
2021-09-12 09:57:57 +02:00
|
|
|
function gui.drawEmptyIcon(x, y)
|
|
|
|
local outlineLight = 0.15
|
|
|
|
love.graphics.circle("fill", x + 8, y + 8, 2, 8)
|
|
|
|
love.graphics.setColor(outlineLight, outlineLight, outlineLight, 1)
|
|
|
|
love.graphics.circle("line", x + 8, y + 8, 2, 8)
|
|
|
|
utils.graphics.resetColor()
|
|
|
|
end
|
|
|
|
|
2019-08-31 21:03:17 +02:00
|
|
|
|
2019-01-28 13:13:17 +01:00
|
|
|
return gui
|