Page 1 of 1

A simple menu lib!

Posted: Sun Sep 18, 2011 10:14 pm
by nkorth
The giant GUI libraries I've been seeing were way overkill for my game, so I made a library for simple menus. It has cool animation and stuff ^^

Edit: I added a scrolling version that works like a Dance Dance Revolution song select screen. It's good for lots of menu items.

Download:
menu.lua
(1.65 KiB) Downloaded 1925 times
menuScroll.lua
(1.73 KiB) Downloaded 1007 times
Notes:
  • This works really well with a gamestate library like hump.gamestate. If you're not already using one, you really should.
  • One of the first things you should do when using this library is open it up and hack the draw function. The whole system is designed to be concise and easily hackable, but also easy to just drop in place.
  • There isn't mouse support because the game I'm working on doesn't even use the mouse, I might add that later.
Examples:
(You can see the library in action in the .love attached.)

Code: Select all

Menu = require 'menu.lua'

fullscreen = false

function love.load()
	testmenu = Menu.new()
	testmenu:addItem{
		name = 'Start Game',
		action = function()
			-- do something
		end
	}
	testmenu:addItem{
		name = 'Options',
		action = function()
			-- do something
		end
	}
	testmenu:addItem{
		name = 'Quit',
		action = function()
			love.event.push('q')
		end
	}
end

function love.update(dt)
	testmenu:update(dt)
end

function love.draw()
	testmenu:draw(10, 10)
end

function love.keypressed(key)
	testmenu:keypressed(key)
end
This is your average title screen, without the actual code that is run when a menu item is selected (because that will vary by game).
Don't forget to add all three of the callbacks!

You can even make items toggle themselves using self:

Code: Select all

testmenu:addItem{
	name = 'Enable fullscreen',
	action = function(self)
		if not fullscreen then
			if love.graphics.setMode(0, 0, true) then
				fullscreen = true
				self.name = 'Disable fullscreen'
			end
		else
			if love.graphics.setMode(800, 600, false) then
					fullscreen = false
				self.name = 'Enable fullscreen'
			end
		end
	end
}
(This assumes the existence of a global variable called fullscreen)

Re: A simple menu lib!

Posted: Sat Dec 13, 2014 8:08 am
by Doctory
this is really old but it works and i love it

Re: A simple menu lib!

Posted: Mon Jul 27, 2015 7:34 am
by nkorth
Doctory wrote:this is really old but it works and i love it
Glad I could help!

I might post a new version pretty soon - I reincarnated this little library for a new project I'm working on.

Re: A simple menu lib!

Posted: Fri Aug 07, 2015 11:28 pm
by duckdotexe
This reminds me a bit of the menu system I'm building which I named Frost. Cool stuff.

EDIT: After looking at the script some, it's actually a lot like it albeit a bit more basic. Mine currently supports rectangles, text, images, buttons, selectors, and tick boxes. It also supports both mouse and keyboard input. Considering releasing it at some point if I happen to remove it's reliance on some of my other classes.