local love = love local draw = love.draw local update = love.update local mousepressed = love.mousepressed local keypressed = love.keypressed local mousemoved = love.mousemoved local ExitMenu options = options or {} local options = options local optionList = {} local option if not options.initialized then options.initialized = true local keyBindCallback = function(self, code) self.value = code end options.optionValues = { { name = "options", value = "back", callback = function(self) return ExitMenu() end }, { name = "high contrast", value = false, callback = function(self, code) if code == "return" or code == "backspace" then return end self.value = not( self.value ) end }, { name = "volume", value = 1.0, callback = function(self, code) local isIncreasing if (code == "left" or code == "a") then isIncreasing = -1 elseif (code == "right" or code == "d") then isIncreasing = 1 else return false end self.value = math.max( 0, math.min( 1, self.value + (isIncreasing * 0.05 ))) return true end }, { name = "left", value = "a", callback = keyBindCallback }, { name = "right", value = "d", callback = keyBindCallback }, { name = "up", value = "w", callback = keyBindCallback }, { name = "down", value = "s", callback = keyBindCallback } } do for i, ov in ipairs( options.optionValues ) do options[ ov.name ] = ov end end end local optionIdx = 1 local isAwaitingKey = false local font = love.graphics.newFont( 32 ) local function Draw() love.graphics.setColor( 1,1,1,1 ) for i, option in ipairs( options.optionValues ) do love.graphics.printf( option.name, font, 100, i * 50, 1000, "left") love.graphics.printf( tostring( option.value ), font, -100, i * 50, love.graphics.getWidth(), "right") end local w = love.graphics.getWidth() love.graphics.setColor( 1,1,1,0.5 ) if isAwaitingKey then love.graphics.rectangle( "fill", w - 200, optionIdx * 50, 100, 48, 10, 10 ) else love.graphics.rectangle( "fill", 100, optionIdx * 50, 250, 48, 10, 10 ) end end local function SelectNextOption() optionIdx = math.min( #options.optionValues, optionIdx + 1 ) option = options.optionValues[ optionIdx] end local function SelectPreviousOption() optionIdx = math.max( 1, optionIdx - 1 ) option = options.optionValues[ optionIdx] end local function KeyPress(key, code, isRepeat) if code == "backspace" then return ExitMenu() end if isAwaitingKey then if code == "escape" then return end isAwaitingKey = (options.optionValues[optionIdx]):callback( code ) end if code == "return" and optionIdx then isAwaitingKey = true; return end if code == "down" then return SelectNextOption() end if code == "up" then return SelectPreviousOption() end end local function EnterMenu() draw = love.draw update = love.update mousepressed = love.mousepressed keypressed = love.keypressed mousemoved = love.mousemoved love.draw = Draw love.keypressed = KeyPress love.update = function() end end function ExitMenu() love.mousemoved = mousemoved love.keypressed = keypressed love.mousepressed = mousepressed love.update = update love.draw = draw end options.EnterMenu = EnterMenu options.ExitMenu = ExitMenu return options