A simple menu lib!

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
nkorth
Prole
Posts: 15
Joined: Sun Sep 18, 2011 8:54 pm
Contact:

A simple menu lib!

Post 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 1924 times
menuScroll.lua
(1.73 KiB) Downloaded 1005 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)
Attachments
menutest.love
(1006 Bytes) Downloaded 1410 times
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Re: A simple menu lib!

Post by Doctory »

this is really old but it works and i love it
User avatar
nkorth
Prole
Posts: 15
Joined: Sun Sep 18, 2011 8:54 pm
Contact:

Re: A simple menu lib!

Post 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.
duckdotexe
Prole
Posts: 4
Joined: Sat Apr 25, 2015 2:46 pm

Re: A simple menu lib!

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 48 guests