https://love2d.org/imgmirrur/Q059AYe.mp4
And here's the code that I have so far. This code all works fine with highlighting and such other than this one issue I'm having.
Code: Select all
button = {}
function button.spawn(quad, action, activeState, x, y, w, h)
table.insert(button, {id = #button + 1, type = "button", action = action, activeState = activeState, enabled = enabled, quad = quad, quad_overlay = nil, x = x, y = y, width = w or 194, height = h or 49, highlight = false})
--Center our button according to our width, height
button[#button].x, button[#button].y = button[#button].x - (button[#button].width / 2), button[#button].y - (button[#button].height / 2)
end
function button.update(dt)
for i = 1, #button do
button.detectVisibility(button[i])
if button[i].enabled then
button.highlight(button[i])
end
end
end
function button.detectVisibility(me)
--Checks to make sure buttons are only usable/rendered when they need to be.
if (me.activeState == "pauseButton" and LET_GAME_PAUSED and LET_PANEL_FOCUS == false) or (me.activeState == LET_PANEL_OPEN and LET_GAME_PAUSED) or (me.activeState == LET_CUR_GAME_STATE and not LET_GAME_PAUSED) then
me.enabled = true
else
me.enabled = false
--if a button is selected and then it becomes disabled, this
--ensures that it is unselected
me.highlight = false
end
end
function button.highlight(me)
if mouseX >= me.x and
mouseX <= me.x + me.width and
mouseY >= me.y and
mouseY <= me.y + me.height then
me.highlight = true
else
me.highlight = false
end
--this is the var being printed to console
LET_BUTTON_SELECTED = me.highlight
end