Refonte pour utiliser le systeme de GUI #112

Merged
kazhnuz merged 102 commits from feat/gui into master 2022-01-06 19:15:16 +01:00
4 changed files with 88 additions and 62 deletions
Showing only changes of commit ce1b1044e8 - Show all commits

Binary file not shown.

Before

Width:  |  Height:  |  Size: 444 B

After

Width:  |  Height:  |  Size: 906 B

View file

@ -6,20 +6,15 @@ local gui = require "game.modules.gui"
function BoxedList:new(name, x, y, w, slotNumber, isBoxed, smallborder) function BoxedList:new(name, x, y, w, slotNumber, isBoxed, smallborder)
BoxedList.super.new(self, name, "small", x, y, w, slotNumber, 0) BoxedList.super.new(self, name, "small", x, y, w, slotNumber, 0)
self.paddingLeft = 12 self.paddingLeft = 12
self.paddingRight = 4 self.paddingRight = 6
self.canvas.padding = 24 self.canvas.padding = 24
self.cursorTexture = love.graphics.newImage("assets/gui/cursor-menulist.png") self.cursorTexture = love.graphics.newImage("assets/gui/cursor-menulist.png")
self.cursorTransition = 0 self.cursorTransition = 0
self.isBoxed = isBoxed self.isBoxed = isBoxed
if (isBoxed) then self.border = utils.math.either(smallborder, 8, 16)
local border = self.h + 16 self.box = gui.newTextBox("assets/gui/dialogbox.png", self.w, self.h + self.border)
if (smallborder == true) then
border = self.h + 8
end
self.box = gui.newTextBox("assets/gui/dialogbox.png", w + 8, border)
end
end end
function BoxedList:finalize() function BoxedList:finalize()
@ -32,13 +27,8 @@ end
function BoxedList:drawTexture() function BoxedList:drawTexture()
if (self.isBoxed) then if (self.isBoxed) then
local dy = 8
if (self.smallborder) then
dy = 4
end
local w, h = self.box:getDimensions() local w, h = self.box:getDimensions()
local diff = (w-self.w)/2 love.graphics.draw(self.box, self.canvas.padding, self.canvas.padding - self.border/2)
love.graphics.draw(self.box, self.canvas.padding - diff, self.canvas.padding - dy)
end end
BoxedList.super.drawTexture(self) BoxedList.super.drawTexture(self)
end end

View file

@ -4,6 +4,22 @@ local TileSet = require "birb.modules.assets.types.tileset"
local barborder = love.graphics.newImage("assets/gui/barborder.png") local barborder = love.graphics.newImage("assets/gui/barborder.png")
local barSmall = TileSet("assets/gui/bar_small") local barSmall = TileSet("assets/gui/bar_small")
local mask_shader = love.graphics.newShader[[
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) {
if (Texel(texture, texture_coords).rgb == vec3(0.0)) {
// a discarded pixel wont be applied as the stencil.
discard;
}
return vec4(1.0);
}
]]
local function myStencilFunction(mask)
love.graphics.setShader(mask_shader)
love.graphics.draw(mask, 0, 0)
love.graphics.setShader()
end
function gui.newBorder(width, height, middlePosition) function gui.newBorder(width, height, middlePosition)
local tileset = love.graphics.newImage("assets/gui/borders.png") local tileset = love.graphics.newImage("assets/gui/borders.png")
local tilequad = {} local tilequad = {}
@ -98,58 +114,78 @@ end
function gui.newTextBox(filename, width, height) function gui.newTextBox(filename, width, height)
local baseimage = love.graphics.newImage(filename) local baseimage = love.graphics.newImage(filename)
local quad = {} width, height = math.floor(width), math.floor(height)
quad[1] = love.graphics.newQuad(00, 00, 8, 8, 24, 24) local quad, quad_mask = {}, {}
quad[2] = love.graphics.newQuad(00, 08, 8, 8, 24, 24) quad[1] = love.graphics.newQuad(00, 00, 8, 8, 48, 32)
quad[3] = love.graphics.newQuad(00, 16, 8, 8, 24, 24) quad[2] = love.graphics.newQuad(00, 08, 8, 8, 48, 32)
quad[4] = love.graphics.newQuad(08, 00, 8, 8, 24, 24) quad[3] = love.graphics.newQuad(00, 16, 8, 8, 48, 32)
quad[5] = love.graphics.newQuad(08, 08, 8, 8, 24, 24) quad[4] = love.graphics.newQuad(08, 00, 8, 8, 48, 32)
quad[6] = love.graphics.newQuad(08, 16, 8, 8, 24, 24) quad[5] = love.graphics.newQuad(08, 08, 8, 8, 48, 32)
quad[7] = love.graphics.newQuad(16, 00, 8, 8, 24, 24) quad[6] = love.graphics.newQuad(08, 16, 8, 8, 48, 32)
quad[8] = love.graphics.newQuad(16, 08, 8, 8, 24, 24) quad[7] = love.graphics.newQuad(16, 00, 8, 8, 48, 32)
quad[9] = love.graphics.newQuad(16, 16, 8, 8, 24, 24) quad[8] = love.graphics.newQuad(16, 08, 8, 8, 48, 32)
quad[9] = love.graphics.newQuad(16, 16, 8, 8, 48, 32)
quad_mask[1] = love.graphics.newQuad(24+00, 00, 8, 8, 48, 32)
quad_mask[2] = love.graphics.newQuad(24+00, 08, 8, 8, 48, 32)
quad_mask[3] = love.graphics.newQuad(24+00, 16, 8, 8, 48, 32)
quad_mask[4] = love.graphics.newQuad(24+08, 00, 8, 8, 48, 32)
quad_mask[5] = love.graphics.newQuad(24+08, 08, 8, 8, 48, 32)
quad_mask[6] = love.graphics.newQuad(24+08, 16, 8, 8, 48, 32)
quad_mask[7] = love.graphics.newQuad(24+16, 00, 8, 8, 48, 32)
quad_mask[8] = love.graphics.newQuad(24+16, 08, 8, 8, 48, 32)
quad_mask[9] = love.graphics.newQuad(24+16, 16, 8, 8, 48, 32)
local back = love.graphics.newQuad(00, 24, 8, 8, 48, 32)
local canvas = love.graphics.newCanvas(width, height) local canvas = love.graphics.newCanvas(width, height)
local backCanvas = love.graphics.newCanvas(width, height)
love.graphics.setCanvas( canvas ) local maskCanvas = love.graphics.newCanvas(width, height)
for i=1, math.floor(width/8) do love.graphics.setCanvas( backCanvas )
if (i == 1) then
-- first line for i=1, math.ceil(width/8) do
for j=1, math.floor(height/8) do for j=1, math.ceil(height/8), 1 do
if j == 1 then love.graphics.draw(baseimage, back, (i-1)*8, (j-1)*8)
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.setScissor(0, 0, math.floor(width/8)))
love.graphics.setCanvas( maskCanvas )
love.graphics.rectangle("fill", 0, 0, width, height)
love.graphics.draw(baseimage, quad_mask[1], 0, 0)
love.graphics.draw(baseimage, quad_mask[7], width- 8, 0)
love.graphics.draw(baseimage, quad_mask[3], 0, height- 8)
love.graphics.draw(baseimage, quad_mask[9], width - 8, height - 8)
love.graphics.setCanvas( {canvas, stencil = true} )
love.graphics.stencil(function () myStencilFunction(maskCanvas) end, "replace", 1)
love.graphics.setStencilTest("greater", 0)
love.graphics.draw(backCanvas)
love.graphics.setStencilTest()
love.graphics.setScissor(8, 0, width-15, height)
for i = 0, math.floor(width/8), 1 do
love.graphics.draw(baseimage, quad[4], i*8, 0)
love.graphics.draw(baseimage, quad[6], i*8, height - 8)
end end
love.graphics.setScissor(0, 8, width, height-15)
for i = 0, math.floor(height/8), 1 do
love.graphics.draw(baseimage, quad[2], 0, i*8)
love.graphics.draw(baseimage, quad[8], width - 8, i * 8)
end end
love.graphics.setScissor( )
love.graphics.draw(baseimage, quad[1], 0, 0)
love.graphics.draw(baseimage, quad[7], width- 8, 0)
love.graphics.draw(baseimage, quad[3], 0, height- 8)
love.graphics.draw(baseimage, quad[9], width - 8, height - 8)
love.graphics.setCanvas( ) love.graphics.setCanvas( )
local imagedata = canvas:newImageData() local imagedata = canvas:newImageData()

View file

@ -9,7 +9,7 @@ local defTransitions = require "birb.modules.transitions"
local radTransitions = require "game.modules.transitions" local radTransitions = require "game.modules.transitions"
local HPADDING = 68 local HPADDING = 68
local VPADDING = 28 local VPADDING = 30
function SaveMenu:new() function SaveMenu:new()
local w, h = 424 - (HPADDING * 2), 240 - (VPADDING * 2) local w, h = 424 - (HPADDING * 2), 240 - (VPADDING * 2)
@ -24,7 +24,7 @@ function SaveMenu:new()
for i, save in ipairs(metadata) do for i, save in ipairs(metadata) do
SaveWidget(self.scene, i, save) SaveWidget(self.scene, i, save)
end end
self.textBox = gui.newTextBox("assets/gui/dialogbox.png", w - 8, (h / 3)) self.textBox = gui.newTextBox("assets/gui/dialogbox.png", w - 8, self.widgetSize.h - 4)
self.isVisible = true self.isVisible = true
end end