From e39e77258974e760bf8c947c0bce5bec46b645e9 Mon Sep 17 00:00:00 2001 From: wan-may Date: Sun, 28 Apr 2024 23:44:18 -0300 Subject: [PATCH] fix menu bug, integer bitmap coordinates --- button.lua | 47 +++++++++++---- camera.lua | 2 +- icons/save.png | Bin 0 -> 3126 bytes icons/x.png | Bin 0 -> 3126 bytes main.lua | 154 ++----------------------------------------------- mainmenu.lua | 143 +++++++++++++++++++++++++++++++++++++++++++++ modal.lua | 1 + savemodal.lua | 16 +++-- 8 files changed, 198 insertions(+), 165 deletions(-) create mode 100644 icons/save.png create mode 100644 icons/x.png diff --git a/button.lua b/button.lua index adee847..603ff2d 100644 --- a/button.lua +++ b/button.lua @@ -3,7 +3,7 @@ local lg = love.graphics local t = { name = "", tooltip = "button", - icon = lg.newImage( "icons/eye.bmp" ), + icon = false, x = 8, y = 250, w = 176, @@ -19,12 +19,35 @@ function t.contains( button, x, y ) and y < button.y + button.h and y > button.y end +local function debugLoop() + local i = 0 + local j = 0 + local a = t + repeat + i = i + 1 + --print( "BUTTON", i, tostring( a ) ) + a = a.next + until a == t or i > 100 + a = t + repeat + j = j + 1 + --print( "BUTTON", i, tostring( a ) ) + a = a.prev + until a == t or j > 100 + print( i, j, "BUTTONS" ) +end + +local k = 1 function t.new( b ) b = setmetatable( b or {}, t ) b.next = t t.prev.next = b b.prev = t.prev t.prev = b + --nonsense + k = k + 1 + print( "ADD BUTTON", k, tostring( b ) ) + debugLoop() return b end @@ -38,12 +61,14 @@ function t.draw( b ) lg.printf( b.name, b.x, b.y + 0.5 * ( b.h- lg.getFont():getHeight() ), - b.w - 5, - "right" ) - if b.icon then lg.draw( b.icon, - b.x, b.y + 0.5 * (b.h - b.icon:getHeight()), + b.w, + "center" ) + if b.icon then + local h = b.icon:getHeight() + lg.draw( b.icon, + b.x, b.y, 0, - 0.5, 0.5 ) + b.h / h ) end if t.selected == b then lg.rectangle( "fill", b.x, b.y, b.w, b.h, 6 ) @@ -57,11 +82,11 @@ function t.select( b ) end function t.selectNext() - repeat t.selected = t.selected.next until t.selected.visible + repeat t.selected = t.selected.next until (t.selected == t) or t.selected.visible end function t.selectPrev() - repeat t.selected = t.selected.prev until t.selected.visible + repeat t.selected = t.selected.prev until (t.selected == t) or t.selected.visible end function t.selectIn( x, y ) @@ -70,13 +95,15 @@ function t.selectIn( x, y ) end function t.selectNextInGroup() - local group = t.selected and t.selected.group + --make sure our group is visible, otherwise the loop doesn't end + local group = t.selected and t.selected.visible and t.selected.group if not group then return t.selectNext() end repeat t.selectNext() until group == t.selected.group end function t.selectPrevInGroup() - local group = t.selected and t.selected.group + --make sure our group is visible, otherwise the loop doesn't end + local group = t.selected and t.selected.visible and t.selected.group if not group then return t.selectPrev() end repeat t.selectPrev() until group == t.selected.group end diff --git a/camera.lua b/camera.lua index 4f10c8b..3c5c8b4 100644 --- a/camera.lua +++ b/camera.lua @@ -3,7 +3,7 @@ local tfTerritory = love.math.newTransform() local tfNodes = love.math.newTransform() local lg = assert( love.graphics ) local Camera = { - x = 0, y = 0, + x = -90, y = 45, w = 360, h = 200, zoom = 1, tf = tf, tfTerritory = tfTerritory, tfNodes = tfNodes } diff --git a/icons/save.png b/icons/save.png new file mode 100644 index 0000000000000000000000000000000000000000..6ab57de67a8b4b0b3755007951252d8c12b9f711 GIT binary patch literal 3126 zcmeHEK@NZ*4AZ+0@aWMO@Br`r|2f(Sho%TwkSK{Pfvl{nTitdy4OckaE6x(mILycp zq3(gdj~)#;z<;DlE<07xWRVZ`<p3fgE#QL6-x|xsMNRuu*OzGp@E|Otp J^n2+|2TnFXVwL~^ literal 0 HcmV?d00001 diff --git a/icons/x.png b/icons/x.png new file mode 100644 index 0000000000000000000000000000000000000000..bedd29c479b153500754ed602bd10518e8d4780f GIT binary patch literal 3126 zcmeH@K?=iA2t?C;571?nJwXo8eeZvqMrsflb zZ_7g}d5*a@`u+T$>;J&jzq-j6+ljj>yp!#C-~a~iWYr7=(t3EG-*L*)DcncMnRNv4 z=8^mg5;+YAzH;C$5l&75*_03Q$d3@NM1rj#BhK{G6jF&k*sm)Z=zU;x0xE4|YNVu0 z6Gy1ZY&0k;|5OJov{M@RftI!q8MP@e6-QVxrw}goS5zD&R8!UY7LxTrVk294%JVxH p5t@$>xVJ$~QaUn!