From ce1b1044e89c22940900168cbe997c8b5dc78dcf Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Wed, 5 Jan 2022 18:26:05 +0100 Subject: [PATCH] improvement: better textboxes --- sonic-radiance.love/assets/gui/dialogbox.png | Bin 444 -> 906 bytes .../game/modules/gui/boxedmenu.lua | 18 +-- sonic-radiance.love/game/modules/gui/init.lua | 128 +++++++++++------- .../scenes/menus/titlescreen/menu.lua | 4 +- 4 files changed, 88 insertions(+), 62 deletions(-) diff --git a/sonic-radiance.love/assets/gui/dialogbox.png b/sonic-radiance.love/assets/gui/dialogbox.png index 88c82b0340354ad53e664a8211346a7992fa8936..ec37baa38fe2097a677ffafef4a8e3dd0c8308ca 100644 GIT binary patch literal 906 zcmV;519kj~P)EX>4Tx04R}tkv&MmKpe$iTcsiu5j%(|M5s;{ii$XD6^c+H)C#RSm|Xe=O&XFE z7e~Rh;NZt%)xpJCR|i)?5c~jfb8}L3krMxx6k5c1aNLh~_a1le0DryARI?)nsG4P@ z5^*7uT@`|_2w@m~7(q;8ramW%NqCO0d-(Wz7v)*r=l&c$O3q|}PavLUx?vG-5KnJf zI_G`jFe^$5@j3ChK^G)`x%kia6AAVPqQDoQBBLX=jG6cZ`hk9+tB9luB}nOr3> zax9<%6_Voz|AXJ%n)%5IHz^bcI$v!2V-yJP0*#t&e;?a+;{*si16NwhU#SB#pQP7X zTI2}m-3BhMTbjHFTnGy0}1(0>bbuerT7_i_3Fq^Yaq4RCM> zj1?$*-Q(R|?Y;ebrrF;Q$Qg3U@cwO800006VoOIv02crN04;7@te5}*010qNS#tmY z3ljhU3ljkVnw%H_000McNliru<^cr|Ee%A<4xa!302y>eSad^gZEa<4bO1wgWnpw> zWFU8GbZ8()Nlj2!fese{00Cl2L_t(o!|j+MNCQzE#=rmZg2gZ}ySy^%ieOpWxa1|b zFc=08Oe>m~1_R*?vUVnC8kWI<2$pS4i+Se3g5@!We}lgBykK~HCmy`7UHR_&{r|_~ zzDG#NYjha~G`v2i#AEEqY{VW!-}WLI{?MzUUM+8AeiuCh0H+{~g;!n*LZrh#J~kl`A}!V>?N3lg4stFFU;!+E1+V}X zzyeqR3-DD&3OvK6ztaVtq3w763_z$FSg)1=-^In%y*9*-c){thi~YTKRV_0YnXZ&7 z{OvGO<({*sl&aiQ7NtHBKE9PO4WUXs<^5WP4o-e|eYhn0&!>=(Z?CyNM#a|lZoUER g2J8mx2J*du55Jof`gcdx@v7EBhl3DGmXXzb~WxfkLvGArU3c`MJ5Nc_lzD1A}u>YGO%h zib8p2Nrr;Er*A-tUMf2S1EYeci(`n#@wd|yGY&gQwCgUXBXOD^~d0$x+ z7MZokYSF6IT&+$%ool>9I(e>~IhwnyZkK?duwjw#>rzjjo2kW>1qF|O{QLgnsC9GK zoRdMH*tyENo$tDe{(BP9v({0&V$L3B4^tPDhwJlgnd+Ca&fgVxbpa1hiOIw4djB+= zY~G09)dg>F2{6VynEkf#OvRID-{P_zrX5bJZn)X8(NuwJ@_bpAe_fYvR!*$Xc>mzb zPlpHV4VtI_nl!cKuD0pf&TRf$tGq9$z7Q(mtec$hs_K61gzd#O>cPv_u}@+65^{Ft z;YmBQFN?e9R>aH9+->%3L&()mi}K|mM-S&LiJxiwo~i%PlCXaklb7~93K4U?_{ybF hYxREN$NTr|#xHqr#o@f`ks44Sdb;|#taD0e0s#8_xI_Q| diff --git a/sonic-radiance.love/game/modules/gui/boxedmenu.lua b/sonic-radiance.love/game/modules/gui/boxedmenu.lua index 3789d9c..4ddca2b 100644 --- a/sonic-radiance.love/game/modules/gui/boxedmenu.lua +++ b/sonic-radiance.love/game/modules/gui/boxedmenu.lua @@ -6,20 +6,15 @@ local gui = require "game.modules.gui" function BoxedList:new(name, x, y, w, slotNumber, isBoxed, smallborder) BoxedList.super.new(self, name, "small", x, y, w, slotNumber, 0) self.paddingLeft = 12 - self.paddingRight = 4 + self.paddingRight = 6 self.canvas.padding = 24 self.cursorTexture = love.graphics.newImage("assets/gui/cursor-menulist.png") self.cursorTransition = 0 self.isBoxed = isBoxed - if (isBoxed) then - local border = self.h + 16 - if (smallborder == true) then - border = self.h + 8 - end - self.box = gui.newTextBox("assets/gui/dialogbox.png", w + 8, border) - end + self.border = utils.math.either(smallborder, 8, 16) + self.box = gui.newTextBox("assets/gui/dialogbox.png", self.w, self.h + self.border) end function BoxedList:finalize() @@ -32,13 +27,8 @@ end function BoxedList:drawTexture() if (self.isBoxed) then - local dy = 8 - if (self.smallborder) then - dy = 4 - end local w, h = self.box:getDimensions() - local diff = (w-self.w)/2 - love.graphics.draw(self.box, self.canvas.padding - diff, self.canvas.padding - dy) + love.graphics.draw(self.box, self.canvas.padding, self.canvas.padding - self.border/2) end BoxedList.super.drawTexture(self) end diff --git a/sonic-radiance.love/game/modules/gui/init.lua b/sonic-radiance.love/game/modules/gui/init.lua index 70f8869..5a6aacf 100644 --- a/sonic-radiance.love/game/modules/gui/init.lua +++ b/sonic-radiance.love/game/modules/gui/init.lua @@ -4,6 +4,22 @@ local TileSet = require "birb.modules.assets.types.tileset" local barborder = love.graphics.newImage("assets/gui/barborder.png") 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) local tileset = love.graphics.newImage("assets/gui/borders.png") local tilequad = {} @@ -98,58 +114,78 @@ 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) + width, height = math.floor(width), math.floor(height) + local quad, quad_mask = {}, {} + quad[1] = love.graphics.newQuad(00, 00, 8, 8, 48, 32) + quad[2] = love.graphics.newQuad(00, 08, 8, 8, 48, 32) + quad[3] = love.graphics.newQuad(00, 16, 8, 8, 48, 32) + quad[4] = love.graphics.newQuad(08, 00, 8, 8, 48, 32) + quad[5] = love.graphics.newQuad(08, 08, 8, 8, 48, 32) + quad[6] = love.graphics.newQuad(08, 16, 8, 8, 48, 32) + quad[7] = love.graphics.newQuad(16, 00, 8, 8, 48, 32) + quad[8] = love.graphics.newQuad(16, 08, 8, 8, 48, 32) + quad[9] = love.graphics.newQuad(16, 16, 8, 8, 48, 32) - love.graphics.setCanvas( canvas ) + 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 backCanvas = love.graphics.newCanvas(width, height) + local maskCanvas = love.graphics.newCanvas(width, height) - 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 + love.graphics.setCanvas( backCanvas ) + + for i=1, math.ceil(width/8) do + for j=1, math.ceil(height/8), 1 do + love.graphics.draw(baseimage, back, (i-1)*8, (j-1)*8) 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 + + 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 + + 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( ) local imagedata = canvas:newImageData() diff --git a/sonic-radiance.love/scenes/menus/titlescreen/menu.lua b/sonic-radiance.love/scenes/menus/titlescreen/menu.lua index 5fe321b..ac7531b 100644 --- a/sonic-radiance.love/scenes/menus/titlescreen/menu.lua +++ b/sonic-radiance.love/scenes/menus/titlescreen/menu.lua @@ -9,7 +9,7 @@ local defTransitions = require "birb.modules.transitions" local radTransitions = require "game.modules.transitions" local HPADDING = 68 -local VPADDING = 28 +local VPADDING = 30 function SaveMenu:new() local w, h = 424 - (HPADDING * 2), 240 - (VPADDING * 2) @@ -24,7 +24,7 @@ function SaveMenu:new() for i, save in ipairs(metadata) do SaveWidget(self.scene, i, save) 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 end